2 * Copyright (C) 2014 Intel Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "emulator/bthost.h"
21 #include "src/shared/tester.h"
22 #include "src/shared/queue.h"
23 #include "lib/bluetooth.h"
24 #include "android/utils.h"
25 #include "tester-main.h"
27 #define HID_GET_REPORT_PROTOCOL 0x60
28 #define HID_GET_BOOT_PROTOCOL 0x61
29 #define HID_SET_REPORT_PROTOCOL 0x70
30 #define HID_SET_BOOT_PROTOCOL 0x71
32 #define HID_SET_INPUT_REPORT 0x51
33 #define HID_SET_OUTPUT_REPORT 0x52
34 #define HID_SET_FEATURE_REPORT 0x53
36 #define HID_SEND_DATA 0xa2
38 #define HID_GET_INPUT_REPORT 0x49
39 #define HID_GET_OUTPUT_REPORT 0x4a
40 #define HID_GET_FEATURE_REPORT 0x4b
42 #define HID_MODE_DEFAULT 0x00
43 #define HID_MODE_BREDR 0x01
44 #define HID_MODE_LE 0x02
46 #define HID_EXPECTED_REPORT_SIZE 0x02
48 #define HID_VIRTUAL_CABLE_UNPLUG 0x15
50 static struct queue *list; /* List of hidhost test cases */
52 #define did_req_pdu 0x06, \
56 0x19, 0x12, 0x00, 0xff, 0xff, 0x35, 0x05, 0x0a, 0x00, \
57 0x00, 0xff, 0xff, 0x00
59 #define did_rsp_pdu 0x07, \
63 0x35, 0x4a, 0x35, 0x48, 0x09, 0x00, 0x00, 0x0a, 0x00, \
64 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, \
65 0x12, 0x00, 0x09, 0x00, 0x05, 0x35, 0x03, 0x19, 0x10, \
66 0x02, 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, \
67 0x12, 0x00, 0x09, 0x01, 0x03, 0x09, 0x02, 0x00, 0x09, \
68 0x01, 0x03, 0x09, 0x02, 0x01, 0x09, 0x1d, 0x6b, 0x09, \
69 0x02, 0x02, 0x09, 0x02, 0x46, 0x09, 0x02, 0x03, 0x09, \
70 0x05, 0x0e, 0x09, 0x02, 0x04, 0x28, 0x01, 0x09, 0x02, \
71 0x05, 0x09, 0x00, 0x02, \
74 #define hid_req_pdu 0x06, \
78 0x19, 0x11, 0x24, 0xff, 0xff, 0x35, 0x05, 0x0a, 0x00, \
79 0x00, 0xff, 0xff, 0x00
81 #define hid_rsp_pdu 0x07, \
85 0x36, 0x01, 0x6b, 0x36, 0x01, 0x68, 0x09, 0x00, 0x00, \
86 0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, \
87 0x03, 0x19, 0x11, 0x24, 0x09, 0x00, 0x04, 0x35, 0x0d, \
88 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x11, 0x35, \
89 0x03, 0x19, 0x00, 0x11, 0x09, 0x00, 0x05, 0x35, 0x03, \
90 0x19, 0x10, 0x02, 0x09, 0x00, 0x06, 0x35, 0x09, 0x09, \
91 0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, 0x00, 0x09, \
92 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x24, \
93 0x09, 0x01, 0x00, 0x09, 0x00, 0x0d, 0x35, 0x0f, 0x35, \
94 0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x13, \
95 0x35, 0x03, 0x19, 0x00, 0x11, 0x09, 0x01, 0x00, 0x25, \
96 0x1e, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63, 0x68, \
97 0x20, 0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, \
98 0x68, 0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x20, 0x4d, \
99 0x35, 0x35, 0x35, 0x62, 0x09, 0x01, 0x01, 0x25, 0x0f, \
100 0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, 0x68, \
101 0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x09, 0x01, 0x02, \
102 0x25, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63, \
103 0x68, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02, \
104 0x01, 0x09, 0x01, 0x11, 0x09, 0x02, 0x02, 0x08, 0x80, \
105 0x09, 0x02, 0x03, 0x08, 0x21, 0x09, 0x02, 0x04, 0x28, \
106 0x01, 0x09, 0x02, 0x05, 0x28, 0x01, 0x09, 0x02, 0x06, \
107 0x35, 0x74, 0x35, 0x72, 0x08, 0x22, 0x25, 0x6e, 0x05, \
108 0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x02, 0x09, 0x01, \
109 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x08, 0x15, \
110 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, \
111 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x16, 0x01, 0xf8, \
112 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x81, 0x06, \
113 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, \
114 0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x81, \
115 0x06, 0x05, 0x09, 0x19, 0x09, 0x29, 0x10, 0x15, 0x00, \
116 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0xc0, \
117 0xc0, 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85, \
118 0x10, 0x75, 0x08, 0x95, 0x06, 0x15, 0x00, 0x26, 0xff, \
119 0x00, 0x09, 0x01, 0x81, 0x00, 0x09, 0x01, 0x91, 0x00, \
120 0xc0, 0x09, 0x02, 0x07, 0x35, 0x08, 0x35, 0x06, 0x09, \
121 0x04, 0x09, 0x09, 0x01, 0x00, 0x09, 0x02, 0x08, 0x28, \
122 0x00, 0x09, 0x02, 0x09, 0x28, 0x01, 0x09, 0x02, 0x0a, \
123 0x28, 0x01, 0x09, 0x02, 0x0b, 0x09, 0x01, 0x00, 0x09, \
124 0x02, 0x0c, 0x09, 0x0c, 0x80, 0x09, 0x02, 0x0d, 0x28, \
125 0x00, 0x09, 0x02, 0x0e, 0x28, 0x01, \
128 static const struct pdu_set sdp_pdus[] = {
129 { raw_pdu(did_req_pdu), raw_pdu(did_rsp_pdu) },
130 { raw_pdu(hid_req_pdu), raw_pdu(hid_rsp_pdu) },
131 { end_pdu, end_pdu },
134 static struct emu_l2cap_cid_data sdp_cid_data = {
139 #define hid_keyboard_rsp_pdu 0x07, \
143 0x36, 0x01, 0xfe, 0x36, 0x01, 0x93, 0x09, 0x00, 0x00, \
144 0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, \
145 0x03, 0x19, 0x11, 0x24, 0x09, 0x00, 0x04, 0x35, 0x0d, \
146 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x11, 0x35, \
147 0x03, 0x19, 0x00, 0x11, 0x09, 0x00, 0x06, 0x35, 0x09, \
148 0x09, 0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, 0x00, \
149 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, \
150 0x24, 0x09, 0x01, 0x00, 0x09, 0x00, 0x0d, 0x35, 0x0f, \
151 0x35, 0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, \
152 0x13, 0x35, 0x03, 0x19, 0x00, 0x11, 0x09, 0x01, 0x00, \
153 0x25, 0x10, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, \
154 0x20, 0x4b, 0x65, 0x79, 0x62, 0x6f, 0x61, 0x72, 0x64, \
155 0x09, 0x01, 0x01, 0x25, 0x08, 0x4b, 0x65, 0x79, 0x62, \
156 0x6f, 0x61, 0x72, 0x64, 0x09, 0x01, 0x02, 0x25, 0x0d, \
157 0x43, 0x53, 0x52, 0x20, 0x48, 0x49, 0x44, 0x45, 0x6e, \
158 0x67, 0x69, 0x6e, 0x65, 0x09, 0x02, 0x00, 0x09, 0x01, \
159 0x00, 0x09, 0x02, 0x01, 0x09, 0x01, 0x11, 0x09, 0x02, \
160 0x02, 0x08, 0x40, 0x09, 0x02, 0x03, 0x08, 0x23, 0x09, \
161 0x02, 0x04, 0x28, 0x01, 0x09, 0x02, 0x05, 0x28, 0x01, \
162 0x09, 0x02, 0x06, 0x35, 0xb7, 0x35, 0xb5, 0x08, 0x22, \
163 0x25, 0xb1, 0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x05, \
164 0x07, 0x85, 0x01, 0x19, 0xe0, 0x29, 0xe7, 0x15, 0x00, \
165 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x95, \
166 0x01, 0x75, 0x08, 0x81, 0x01, 0x95, 0x05, 0x75, 0x01, \
167 0x05, 0x08, 0x85, 0x01, 0x19, 0x01, 0x29, 0x05, 0x91, \
168 0x02, 0x95, 0x01, 0x75, 0x03, 0x91, 0x03, 0x95, 0x06, \
169 0x75, 0x08, 0x15, 0x00, 0x25, 0x65, 0x05, 0x07, 0x19, \
170 0x00, 0x29, 0x6f, 0x81, 0x00, 0xc0, 0x05, 0x0c, 0x09, \
171 0x01, 0xa1, 0x01, 0x85, 0x02, 0x05, 0x0c, 0x15, 0x00, \
172 0x25, 0x01, 0x75, 0x01, 0x95, 0x18, 0x09, 0xe2, 0x09, \
173 0xea, 0x09, 0xe9, 0x09, 0xb7, 0x09, 0xcd, 0x0a, 0x23, \
174 0x02, 0x0a, 0x8a, 0x01, 0x0a, 0x21, 0x02, 0x75, 0x01, \
175 0x95, 0x03, 0x81, 0x02, 0x75, 0x01, 0x95, 0x05, 0x81, \
176 0x01, 0x05, 0x08, 0x85, 0xff, 0x95, 0x01, 0x75, 0x02, \
177 0x09, 0x24, 0x09, 0x26, 0x81, 0x02, 0x75, 0x06, 0x81, \
178 0x01, 0xc0, 0x06, 0x7f, 0xff, 0x09, 0x01, 0xa1, 0x01, \
179 0x85, 0x03, 0x15, 0x00, 0x25, 0x01, 0x09, 0xb9, 0x09, \
180 0xb5, 0x09, 0xba, 0x09, 0xbb, 0x09, 0xbc, 0x09, 0xbd, \
181 0x09, 0xb6, 0x09, 0xb7, 0x75, 0x01, 0x95, 0x06, 0x81, \
182 0x02, 0x75, 0x01, 0x95, 0x02, 0x81, 0x01, 0xc0, 0x09, \
183 0x02, 0x07, 0x35, 0x08, 0x35, 0x06, 0x09, 0x04, 0x09, \
184 0x09, 0x01, 0x00, 0x09, 0x02, 0x08, 0x28, 0x00, 0x09, \
185 0x02, 0x09, 0x28, 0x01, 0x09, 0x02, 0x0a, 0x28, 0x01, \
186 0x09, 0x02, 0x0b, 0x09, 0x01, 0x00, 0x09, 0x02, 0x0c, \
187 0x09, 0x1f, 0x40, 0x09, 0x02, 0x0d, 0x28, 0x00, 0x09, \
188 0x02, 0x0e, 0x28, 0x01, 0x36, 0x00, 0x65, 0x09, 0x00, \
189 0x00, 0x0a, 0x00, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, \
190 0x35, 0x03, 0x19, 0x12, 0x00, 0x09, 0x00, 0x04, 0x35, \
191 0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x01, \
192 0x35, 0x03, 0x19, 0x00, 0x01, 0x09, 0x00, 0x06, 0x35, \
193 0x09, 0x09, 0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, \
194 0x00, 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, \
195 0x12, 0x00, 0x09, 0x01, 0x00, 0x09, 0x01, 0x01, 0x25, \
196 0x00, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02, \
197 0x01, 0x09, 0x23, 0x3d, 0x09, 0x02, 0x02, 0x09, 0x01, \
198 0x3d, 0x09, 0x02, 0x03, 0x09, 0x00, 0x00, 0x09, 0x02, \
199 0x04, 0x28, 0x01, 0x09, 0x02, 0x05, 0x09, 0x00, 0x02, \
202 static const struct pdu_set sdp_kb_pdus[] = {
203 { raw_pdu(did_req_pdu), raw_pdu(did_rsp_pdu) },
204 { raw_pdu(hid_req_pdu), raw_pdu(hid_keyboard_rsp_pdu) },
205 { end_pdu, end_pdu },
208 static struct emu_l2cap_cid_data sdp_kb_cid_data = {
213 static struct emu_l2cap_cid_data ctrl_cid_data;
214 static struct emu_l2cap_cid_data intr_cid_data;
216 static void hid_prepare_reply_protocol_mode(struct emu_l2cap_cid_data *cid_data)
218 struct test_data *t_data = tester_get_data();
219 struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
220 const struct iovec pdu = raw_pdu(0xa0, 0x00);
222 bthost_send_cid_v(bthost, cid_data->handle, cid_data->cid, &pdu, 1);
225 static void hid_prepare_reply_report(struct emu_l2cap_cid_data *cid_data)
227 struct test_data *t_data = tester_get_data();
228 struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
229 const struct iovec pdu = raw_pdu(0xa2, 0x01, 0x00);
231 bthost_send_cid_v(bthost, cid_data->handle, cid_data->cid, &pdu, 1);
234 static void hid_ctrl_cid_hook_cb(const void *data, uint16_t len,
237 struct emu_l2cap_cid_data *cid_data = user_data;
238 uint8_t header = ((uint8_t *) data)[0];
242 case HID_GET_REPORT_PROTOCOL:
243 case HID_GET_BOOT_PROTOCOL:
244 case HID_SET_REPORT_PROTOCOL:
245 case HID_SET_BOOT_PROTOCOL:
246 hid_prepare_reply_protocol_mode(cid_data);
248 case HID_GET_INPUT_REPORT:
249 case HID_GET_OUTPUT_REPORT:
250 case HID_GET_FEATURE_REPORT:
251 hid_prepare_reply_report(cid_data);
254 * HID device doesnot reply for this commads, so reaching pdu's
255 * to hid device means assuming test passed
257 case HID_SET_INPUT_REPORT:
258 case HID_SET_OUTPUT_REPORT:
259 case HID_SET_FEATURE_REPORT:
261 /* Successfully verify sending data step */
262 step = g_new0(struct step, 1);
264 step->callback = CB_EMU_CONFIRM_SEND_DATA;
266 schedule_callback_verification(step);
268 case HID_VIRTUAL_CABLE_UNPLUG:
269 step = g_new0(struct step, 1);
271 step->callback = CB_EMU_CONNECTION_REJECTED;
273 schedule_callback_verification(step);
277 static void hid_ctrl_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
279 struct test_data *data = tester_get_data();
280 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
281 struct emu_l2cap_cid_data *cid_data = user_data;
283 cid_data->handle = handle;
286 bthost_add_cid_hook(bthost, handle, cid, hid_ctrl_cid_hook_cb,
290 static void hid_intr_cid_hook_cb(const void *data, uint16_t len,
293 uint8_t header = ((uint8_t *) data)[0];
298 /* Successfully verify sending data step */
299 step = g_new0(struct step, 1);
301 step->callback = CB_EMU_CONFIRM_SEND_DATA;
303 schedule_callback_verification(step);
307 static void hid_intr_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
309 struct test_data *data = tester_get_data();
310 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
311 struct emu_l2cap_cid_data *cid_data = user_data;
313 cid_data->handle = handle;
316 bthost_add_cid_hook(bthost, handle, cid, hid_intr_cid_hook_cb,
320 static bt_scan_mode_t setprop_scan_mode_conn_val = BT_SCAN_MODE_CONNECTABLE;
322 static bt_property_t prop_test_scan_mode_conn = {
323 .type = BT_PROPERTY_ADAPTER_SCAN_MODE,
324 .val = &setprop_scan_mode_conn_val,
325 .len = sizeof(setprop_scan_mode_conn_val),
328 /* Emulate SDP (PSM = 1) */
329 static struct emu_set_l2cap_data l2cap_setup_sdp_data = {
331 .func = tester_generic_connect_cb,
332 .user_data = &sdp_cid_data,
335 static struct emu_set_l2cap_data l2cap_setup_kb_sdp_data = {
337 .func = tester_generic_connect_cb,
338 .user_data = &sdp_kb_cid_data,
341 /* Emulate Control Channel (PSM = 17) */
342 static struct emu_set_l2cap_data l2cap_setup_cc_data = {
344 .func = hid_ctrl_connect_cb,
345 .user_data = &ctrl_cid_data,
348 /* Emulate Interrupt Channel (PSM = 19) */
349 static struct emu_set_l2cap_data l2cap_setup_ic_data = {
351 .func = hid_intr_connect_cb,
352 .user_data = &intr_cid_data,
355 static void hidhost_connect_action(void)
357 struct test_data *data = tester_get_data();
358 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
359 struct step *step = g_new0(struct step, 1);
362 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
364 step->action_status = data->if_hid->connect(&bdaddr);
366 schedule_action_verification(step);
369 static void hidhost_disconnect_action(void)
371 struct test_data *data = tester_get_data();
372 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
373 struct step *step = g_new0(struct step, 1);
376 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
378 step->action_status = data->if_hid->disconnect(&bdaddr);
380 schedule_action_verification(step);
383 static void hidhost_virtual_unplug_action(void)
385 struct test_data *data = tester_get_data();
386 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
387 struct step *step = g_new0(struct step, 1);
390 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
392 step->action_status = data->if_hid->virtual_unplug(&bdaddr);
394 schedule_action_verification(step);
397 static void hidhost_get_protocol_action(void)
399 struct test_data *data = tester_get_data();
400 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
401 struct step *step = g_new0(struct step, 1);
404 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
406 step->action_status = data->if_hid->get_protocol(&bdaddr,
409 schedule_action_verification(step);
412 static void hidhost_set_protocol_action(void)
414 struct test_data *data = tester_get_data();
415 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
416 struct step *step = g_new0(struct step, 1);
419 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
421 step->action_status = data->if_hid->set_protocol(&bdaddr,
424 schedule_action_verification(step);
427 static void hidhost_get_report_action(void)
429 struct test_data *data = tester_get_data();
430 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
431 struct step *step = g_new0(struct step, 1);
434 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
436 step->action_status = data->if_hid->get_report(&bdaddr,
437 BTHH_INPUT_REPORT, 1,
440 schedule_action_verification(step);
443 static void hidhost_set_report_action(void)
445 struct test_data *data = tester_get_data();
446 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
447 struct step *step = g_new0(struct step, 1);
448 char *buf = "fe0201";
451 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
453 step->action_status = data->if_hid->send_data(&bdaddr, buf);
454 schedule_action_verification(step);
457 static void hidhost_send_data_action(void)
459 struct test_data *data = tester_get_data();
460 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
461 struct step *step = g_new0(struct step, 1);
462 char *buf = "010101";
465 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
467 step->action_status = data->if_hid->set_report(&bdaddr,
468 BTHH_INPUT_REPORT, buf);
469 schedule_action_verification(step);
472 static void client_l2cap_rsp(uint8_t code, const void *data, uint16_t len,
475 struct test_data *t_data = tester_get_data();
476 struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
477 struct emu_l2cap_cid_data *cid_data = user_data;
478 const uint16_t *psm = data;
479 const struct iovec con_req = raw_pdu(0x13, 0x00, /* PSM */
480 0x41, 0x00); /* Source CID */
482 if (len < sizeof(*psm)) {
483 tester_warn("Invalid l2cap response.");
489 bthost_add_cid_hook(bthost, cid_data->handle, 0x40,
490 hid_ctrl_cid_hook_cb, cid_data);
492 bthost_l2cap_req(bthost, cid_data->handle, 0x02,
493 con_req.iov_base, con_req.iov_len,
494 client_l2cap_rsp, cid_data);
497 bthost_add_cid_hook(bthost, cid_data->handle, 0x41,
498 hid_intr_cid_hook_cb, cid_data);
505 static void hidhost_conn_cb(uint16_t handle, void *user_data)
507 const struct iovec con_req = raw_pdu(0x11, 0x00, /* PSM */
508 0x40, 0x00); /* Source CID */
510 struct test_data *data = tester_get_data();
511 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
513 if (data->hciemu_type == HCIEMU_TYPE_BREDR) {
514 tester_warn("Not handled device type.");
518 ctrl_cid_data.cid = 0x40;
519 ctrl_cid_data.handle = handle;
521 tester_print("Sending L2CAP Request from remote");
523 bthost_l2cap_req(bthost, handle, 0x02, con_req.iov_base,
524 con_req.iov_len, client_l2cap_rsp,
528 static struct test_case test_cases[] = {
529 TEST_CASE_BREDRLE("HidHost Init",
530 ACTION_SUCCESS(dummy_action, NULL),
532 TEST_CASE_BREDRLE("HidHost Connect Success",
533 ACTION_SUCCESS(bluetooth_enable_action, NULL),
534 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
535 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
536 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
537 ACTION_SUCCESS(emu_add_l2cap_server_action,
538 &l2cap_setup_sdp_data),
539 ACTION_SUCCESS(emu_add_l2cap_server_action,
540 &l2cap_setup_cc_data),
541 ACTION_SUCCESS(emu_add_l2cap_server_action,
542 &l2cap_setup_ic_data),
543 ACTION_SUCCESS(hidhost_connect_action, NULL),
544 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
545 BTHH_CONN_STATE_CONNECTED),
546 ACTION_SUCCESS(bluetooth_disable_action, NULL),
547 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
548 BTHH_CONN_STATE_DISCONNECTED),
549 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
551 TEST_CASE_BREDRLE("HidHost Disconnect Success",
552 ACTION_SUCCESS(bluetooth_enable_action, NULL),
553 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
554 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
555 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
556 ACTION_SUCCESS(emu_add_l2cap_server_action,
557 &l2cap_setup_sdp_data),
558 ACTION_SUCCESS(emu_add_l2cap_server_action,
559 &l2cap_setup_cc_data),
560 ACTION_SUCCESS(emu_add_l2cap_server_action,
561 &l2cap_setup_ic_data),
562 ACTION_SUCCESS(hidhost_connect_action, NULL),
563 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
564 BTHH_CONN_STATE_CONNECTED),
565 ACTION_SUCCESS(hidhost_disconnect_action, NULL),
566 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
567 BTHH_CONN_STATE_DISCONNECTED),
569 TEST_CASE_BREDRLE("HidHost VirtualUnplug Success",
570 ACTION_SUCCESS(bluetooth_enable_action, NULL),
571 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
572 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
573 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
574 ACTION_SUCCESS(emu_add_l2cap_server_action,
575 &l2cap_setup_sdp_data),
576 ACTION_SUCCESS(emu_add_l2cap_server_action,
577 &l2cap_setup_cc_data),
578 ACTION_SUCCESS(emu_add_l2cap_server_action,
579 &l2cap_setup_ic_data),
580 ACTION_SUCCESS(hidhost_connect_action, NULL),
581 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
582 BTHH_CONN_STATE_CONNECTED),
583 ACTION_SUCCESS(hidhost_virtual_unplug_action, NULL),
584 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
585 BTHH_CONN_STATE_DISCONNECTED),
587 TEST_CASE_BREDRLE("HidHost GetProtocol Success",
588 ACTION_SUCCESS(bluetooth_enable_action, NULL),
589 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
590 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
591 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
592 ACTION_SUCCESS(emu_add_l2cap_server_action,
593 &l2cap_setup_sdp_data),
594 ACTION_SUCCESS(emu_add_l2cap_server_action,
595 &l2cap_setup_cc_data),
596 ACTION_SUCCESS(emu_add_l2cap_server_action,
597 &l2cap_setup_ic_data),
598 ACTION_SUCCESS(hidhost_connect_action, NULL),
599 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
600 BTHH_CONN_STATE_CONNECTED),
601 ACTION_SUCCESS(hidhost_get_protocol_action, NULL),
602 CALLBACK_HH_MODE(CB_HH_PROTOCOL_MODE, BTHH_OK, HID_MODE_BREDR),
604 TEST_CASE_BREDRLE("HidHost SetProtocol Success",
605 ACTION_SUCCESS(bluetooth_enable_action, NULL),
606 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
607 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
608 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
609 ACTION_SUCCESS(emu_add_l2cap_server_action,
610 &l2cap_setup_sdp_data),
611 ACTION_SUCCESS(emu_add_l2cap_server_action,
612 &l2cap_setup_cc_data),
613 ACTION_SUCCESS(emu_add_l2cap_server_action,
614 &l2cap_setup_ic_data),
615 ACTION_SUCCESS(hidhost_connect_action, NULL),
616 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
617 BTHH_CONN_STATE_CONNECTED),
618 ACTION_SUCCESS(hidhost_set_protocol_action, NULL),
619 CALLBACK_HH_MODE(CB_HH_PROTOCOL_MODE, BTHH_OK, HID_MODE_BREDR),
621 TEST_CASE_BREDRLE("HidHost GetReport Success",
622 ACTION_SUCCESS(bluetooth_enable_action, NULL),
623 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
624 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
625 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
626 ACTION_SUCCESS(emu_add_l2cap_server_action,
627 &l2cap_setup_sdp_data),
628 ACTION_SUCCESS(emu_add_l2cap_server_action,
629 &l2cap_setup_cc_data),
630 ACTION_SUCCESS(emu_add_l2cap_server_action,
631 &l2cap_setup_ic_data),
632 ACTION_SUCCESS(hidhost_connect_action, NULL),
633 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
634 BTHH_CONN_STATE_CONNECTED),
635 ACTION_SUCCESS(hidhost_get_report_action, NULL),
636 CALLBACK_HHREPORT(CB_HH_GET_REPORT, BTHH_OK,
637 HID_EXPECTED_REPORT_SIZE),
639 TEST_CASE_BREDRLE("HidHost SetReport Success",
640 ACTION_SUCCESS(bluetooth_enable_action, NULL),
641 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
642 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
643 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
644 ACTION_SUCCESS(emu_add_l2cap_server_action,
645 &l2cap_setup_sdp_data),
646 ACTION_SUCCESS(emu_add_l2cap_server_action,
647 &l2cap_setup_cc_data),
648 ACTION_SUCCESS(emu_add_l2cap_server_action,
649 &l2cap_setup_ic_data),
650 ACTION_SUCCESS(hidhost_connect_action, NULL),
651 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
652 BTHH_CONN_STATE_CONNECTING),
653 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
654 BTHH_CONN_STATE_CONNECTED),
655 ACTION_SUCCESS(hidhost_set_report_action, NULL),
656 CALLBACK(CB_EMU_CONFIRM_SEND_DATA),
658 TEST_CASE_BREDRLE("HidHost SendData Success",
659 ACTION_SUCCESS(bluetooth_enable_action, NULL),
660 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
661 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
662 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
663 ACTION_SUCCESS(emu_add_l2cap_server_action,
664 &l2cap_setup_sdp_data),
665 ACTION_SUCCESS(emu_add_l2cap_server_action,
666 &l2cap_setup_cc_data),
667 ACTION_SUCCESS(emu_add_l2cap_server_action,
668 &l2cap_setup_ic_data),
669 ACTION_SUCCESS(hidhost_connect_action, NULL),
670 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
671 BTHH_CONN_STATE_CONNECTED),
672 ACTION_SUCCESS(hidhost_send_data_action, NULL),
673 CALLBACK(CB_EMU_CONFIRM_SEND_DATA),
675 TEST_CASE_BREDRLE("HidHost Connect Encrypted Success",
676 ACTION_SUCCESS(bluetooth_enable_action, NULL),
677 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
678 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
679 ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
680 ACTION_SUCCESS(set_default_ssp_request_handler, NULL),
681 ACTION_SUCCESS(emu_add_l2cap_server_action,
682 &l2cap_setup_kb_sdp_data),
683 ACTION_SUCCESS(emu_add_l2cap_server_action,
684 &l2cap_setup_cc_data),
685 ACTION_SUCCESS(emu_add_l2cap_server_action,
686 &l2cap_setup_ic_data),
687 ACTION_SUCCESS(hidhost_connect_action, NULL),
688 CALLBACK(CB_EMU_ENCRYPTION_ENABLED),
689 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
690 BTHH_CONN_STATE_CONNECTED),
691 ACTION_SUCCESS(hidhost_send_data_action, NULL),
692 ACTION_SUCCESS(bluetooth_disable_action, NULL),
693 CALLBACK_STATE(CB_HH_CONNECTION_STATE,
694 BTHH_CONN_STATE_DISCONNECTED),
695 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
697 TEST_CASE_BREDRLE("HidHost Reject Unknown Remote Connection",
698 ACTION_SUCCESS(bluetooth_enable_action, NULL),
699 CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
700 ACTION_SUCCESS(bt_set_property_action,
701 &prop_test_scan_mode_conn),
702 CALLBACK_ADAPTER_PROPS(&prop_test_scan_mode_conn, 1),
703 ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
704 ACTION_SUCCESS(emu_add_l2cap_server_action,
705 &l2cap_setup_kb_sdp_data),
706 ACTION_SUCCESS(emu_add_l2cap_server_action,
707 &l2cap_setup_cc_data),
708 ACTION_SUCCESS(emu_add_l2cap_server_action,
709 &l2cap_setup_ic_data),
710 /* Trigger incoming connection */
711 ACTION_SUCCESS(emu_set_connect_cb_action, hidhost_conn_cb),
712 ACTION_SUCCESS(emu_remote_connect_hci_action, NULL),
713 CALLBACK(CB_EMU_CONNECTION_REJECTED),
717 struct queue *get_hidhost_tests(void)
723 for (; i < sizeof(test_cases) / sizeof(test_cases[0]); ++i)
724 queue_push_tail(list, &test_cases[i]);
729 void remove_hidhost_tests(void)
731 queue_destroy(list, NULL);