tizen 2.3 release
[framework/connectivity/bluez.git] / tools / mgmt-tester.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2012  Intel Corporation. All rights reserved.
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdlib.h>
29 #include <stdbool.h>
30
31 #include <glib.h>
32
33 #include "lib/bluetooth.h"
34 #include "lib/mgmt.h"
35
36 #include "monitor/bt.h"
37 #include "emulator/bthost.h"
38
39 #include "src/shared/tester.h"
40 #include "src/shared/mgmt.h"
41 #include "src/shared/hciemu.h"
42
43 struct test_data {
44         tester_data_func_t test_setup;
45         const void *test_data;
46         uint8_t expected_version;
47         uint16_t expected_manufacturer;
48         uint32_t expected_supported_settings;
49         uint32_t initial_settings;
50         struct mgmt *mgmt;
51         struct mgmt *mgmt_alt;
52         unsigned int mgmt_settings_id;
53         unsigned int mgmt_alt_settings_id;
54         unsigned int mgmt_alt_ev_id;
55         uint8_t mgmt_version;
56         uint16_t mgmt_revision;
57         uint16_t mgmt_index;
58         struct hciemu *hciemu;
59         enum hciemu_type hciemu_type;
60         int unmet_conditions;
61 };
62
63 static void mgmt_debug(const char *str, void *user_data)
64 {
65         const char *prefix = user_data;
66
67         tester_print("%s%s", prefix, str);
68 }
69
70 static void read_version_callback(uint8_t status, uint16_t length,
71                                         const void *param, void *user_data)
72 {
73         struct test_data *data = tester_get_data();
74         const struct mgmt_rp_read_version *rp = param;
75
76         tester_print("Read Version callback");
77         tester_print("  Status: 0x%02x", status);
78
79         if (status || !param) {
80                 tester_pre_setup_failed();
81                 return;
82         }
83
84         data->mgmt_version = rp->version;
85         data->mgmt_revision = btohs(rp->revision);
86
87         tester_print("  Version %u.%u",
88                                 data->mgmt_version, data->mgmt_revision);
89 }
90
91 static void read_commands_callback(uint8_t status, uint16_t length,
92                                         const void *param, void *user_data)
93 {
94         tester_print("Read Commands callback");
95         tester_print("  Status: 0x%02x", status);
96
97         if (status || !param) {
98                 tester_pre_setup_failed();
99                 return;
100         }
101 }
102
103 static void read_info_callback(uint8_t status, uint16_t length,
104                                         const void *param, void *user_data)
105 {
106         struct test_data *data = tester_get_data();
107         const struct mgmt_rp_read_info *rp = param;
108         char addr[18];
109         uint16_t manufacturer;
110         uint32_t supported_settings, current_settings;
111
112         tester_print("Read Info callback");
113         tester_print("  Status: 0x%02x", status);
114
115         if (status || !param) {
116                 tester_pre_setup_failed();
117                 return;
118         }
119
120         ba2str(&rp->bdaddr, addr);
121         manufacturer = btohs(rp->manufacturer);
122         supported_settings = btohl(rp->supported_settings);
123         current_settings = btohl(rp->current_settings);
124
125         tester_print("  Address: %s", addr);
126         tester_print("  Version: 0x%02x", rp->version);
127         tester_print("  Manufacturer: 0x%04x", manufacturer);
128         tester_print("  Supported settings: 0x%08x", supported_settings);
129         tester_print("  Current settings: 0x%08x", current_settings);
130         tester_print("  Class: 0x%02x%02x%02x",
131                         rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
132         tester_print("  Name: %s", rp->name);
133         tester_print("  Short name: %s", rp->short_name);
134
135         if (strcmp(hciemu_get_address(data->hciemu), addr)) {
136                 tester_pre_setup_failed();
137                 return;
138         }
139
140         if (rp->version != data->expected_version) {
141                 tester_pre_setup_failed();
142                 return;
143         }
144
145         if (manufacturer != data->expected_manufacturer) {
146                 tester_pre_setup_failed();
147                 return;
148         }
149
150         if (supported_settings != data->expected_supported_settings) {
151                 tester_pre_setup_failed();
152                 return;
153         }
154
155         if (current_settings != data->initial_settings) {
156                 tester_pre_setup_failed();
157                 return;
158         }
159
160         if (rp->dev_class[0] != 0x00 || rp->dev_class[1] != 0x00 ||
161                                                 rp->dev_class[2] != 0x00) {
162                 tester_pre_setup_failed();
163                 return;
164         }
165
166         tester_pre_setup_complete();
167 }
168
169 static void index_added_callback(uint16_t index, uint16_t length,
170                                         const void *param, void *user_data)
171 {
172         struct test_data *data = tester_get_data();
173
174         tester_print("Index Added callback");
175         tester_print("  Index: 0x%04x", index);
176
177         data->mgmt_index = index;
178
179         mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
180                                         read_info_callback, NULL, NULL);
181 }
182
183 static void index_removed_callback(uint16_t index, uint16_t length,
184                                         const void *param, void *user_data)
185 {
186         struct test_data *data = tester_get_data();
187
188         tester_print("Index Removed callback");
189         tester_print("  Index: 0x%04x", index);
190
191         if (index != data->mgmt_index)
192                 return;
193
194         mgmt_unregister_index(data->mgmt, data->mgmt_index);
195         mgmt_unregister_index(data->mgmt_alt, data->mgmt_index);
196
197         mgmt_unref(data->mgmt);
198         data->mgmt = NULL;
199
200         mgmt_unref(data->mgmt_alt);
201         data->mgmt_alt = NULL;
202
203         tester_post_teardown_complete();
204 }
205
206 static void read_index_list_callback(uint8_t status, uint16_t length,
207                                         const void *param, void *user_data)
208 {
209         struct test_data *data = tester_get_data();
210
211         tester_print("Read Index List callback");
212         tester_print("  Status: 0x%02x", status);
213
214         if (status || !param) {
215                 tester_pre_setup_failed();
216                 return;
217         }
218
219         mgmt_register(data->mgmt, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
220                                         index_added_callback, NULL, NULL);
221
222         mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
223                                         index_removed_callback, NULL, NULL);
224
225         data->hciemu = hciemu_new(data->hciemu_type);
226         if (!data->hciemu) {
227                 tester_warn("Failed to setup HCI emulation");
228                 tester_pre_setup_failed();
229         }
230 }
231
232 static void test_pre_setup(const void *test_data)
233 {
234         struct test_data *data = tester_get_data();
235
236         data->mgmt = mgmt_new_default();
237         if (!data->mgmt) {
238                 tester_warn("Failed to setup management interface");
239                 tester_pre_setup_failed();
240                 return;
241         }
242
243         data->mgmt_alt = mgmt_new_default();
244         if (!data->mgmt_alt) {
245                 tester_warn("Failed to setup alternate management interface");
246                 tester_pre_setup_failed();
247
248                 mgmt_unref(data->mgmt);
249                 data->mgmt = NULL;
250                 return;
251         }
252
253         if (tester_use_debug()) {
254                 mgmt_set_debug(data->mgmt, mgmt_debug, "mgmt: ", NULL);
255                 mgmt_set_debug(data->mgmt_alt, mgmt_debug, "mgmt-alt: ", NULL);
256         }
257
258         mgmt_send(data->mgmt, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
259                                         read_version_callback, NULL, NULL);
260
261         mgmt_send(data->mgmt, MGMT_OP_READ_COMMANDS, MGMT_INDEX_NONE, 0, NULL,
262                                         read_commands_callback, NULL, NULL);
263
264         mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0, NULL,
265                                         read_index_list_callback, NULL, NULL);
266 }
267
268 static void test_post_teardown(const void *test_data)
269 {
270         struct test_data *data = tester_get_data();
271
272         hciemu_unref(data->hciemu);
273         data->hciemu = NULL;
274 }
275
276 static void test_add_condition(struct test_data *data)
277 {
278         data->unmet_conditions++;
279
280         tester_print("Test condition added, total %d", data->unmet_conditions);
281 }
282
283 static void test_condition_complete(struct test_data *data)
284 {
285         data->unmet_conditions--;
286
287         tester_print("Test condition complete, %d left",
288                                                 data->unmet_conditions);
289
290         if (data->unmet_conditions > 0)
291                 return;
292
293         tester_test_passed();
294 }
295
296 #define test_bredrle(name, data, setup, func) \
297         do { \
298                 struct test_data *user; \
299                 user = malloc(sizeof(struct test_data)); \
300                 if (!user) \
301                         break; \
302                 user->hciemu_type = HCIEMU_TYPE_BREDRLE; \
303                 user->test_setup = setup; \
304                 user->test_data = data; \
305                 user->expected_version = 0x06; \
306                 user->expected_manufacturer = 0x003f; \
307                 user->expected_supported_settings = 0x00003fff; \
308                 user->initial_settings = 0x00000080; \
309                 user->unmet_conditions = 0; \
310                 tester_add_full(name, data, \
311                                 test_pre_setup, test_setup, func, NULL, \
312                                 test_post_teardown, 2, user, free); \
313         } while (0)
314
315 #define test_bredr(name, data, setup, func) \
316         do { \
317                 struct test_data *user; \
318                 user = malloc(sizeof(struct test_data)); \
319                 if (!user) \
320                         break; \
321                 user->hciemu_type = HCIEMU_TYPE_BREDR; \
322                 user->test_setup = setup; \
323                 user->test_data = data; \
324                 user->expected_version = 0x05; \
325                 user->expected_manufacturer = 0x003f; \
326                 user->expected_supported_settings = 0x000011ff; \
327                 user->initial_settings = 0x00000080; \
328                 user->unmet_conditions = 0; \
329                 tester_add_full(name, data, \
330                                 test_pre_setup, test_setup, func, NULL, \
331                                 test_post_teardown, 2, user, free); \
332         } while (0)
333
334 #define test_le(name, data, setup, func) \
335         do { \
336                 struct test_data *user; \
337                 user = malloc(sizeof(struct test_data)); \
338                 if (!user) \
339                         break; \
340                 user->hciemu_type = HCIEMU_TYPE_LE; \
341                 user->test_setup = setup; \
342                 user->test_data = data; \
343                 user->expected_version = 0x06; \
344                 user->expected_manufacturer = 0x003f; \
345                 user->expected_supported_settings = 0x00003611; \
346                 user->initial_settings = 0x00000200; \
347                 user->unmet_conditions = 0; \
348                 tester_add_full(name, data, \
349                                 test_pre_setup, test_setup, func, NULL, \
350                                 test_post_teardown, 2, user, free); \
351         } while (0)
352
353 static void controller_setup(const void *test_data)
354 {
355         tester_test_passed();
356 }
357
358 struct generic_data {
359         const uint16_t *setup_settings;
360         bool setup_nobredr;
361         bool setup_limited_discov;
362         uint16_t setup_expect_hci_command;
363         const void *setup_expect_hci_param;
364         uint8_t setup_expect_hci_len;
365         bool send_index_none;
366         uint16_t send_opcode;
367         const void *send_param;
368         uint16_t send_len;
369         const void * (*send_func)(uint16_t *len);
370         uint8_t expect_status;
371         const void *expect_param;
372         uint16_t expect_len;
373         const void * (*expect_func)(uint16_t *len);
374         uint32_t expect_settings_set;
375         uint32_t expect_settings_unset;
376         uint16_t expect_alt_ev;
377         const void *expect_alt_ev_param;
378         uint16_t expect_alt_ev_len;
379         uint16_t expect_hci_command;
380         const void *expect_hci_param;
381         uint8_t expect_hci_len;
382         const void * (*expect_hci_func)(uint8_t *len);
383         bool expect_pin;
384         uint8_t pin_len;
385         const void *pin;
386         uint8_t client_pin_len;
387         const void *client_pin;
388         bool client_enable_ssp;
389         uint8_t io_cap;
390         uint8_t client_io_cap;
391         bool reject_ssp;
392         bool client_reject_ssp;
393 };
394
395 static const char dummy_data[] = { 0x00 };
396
397 static const struct generic_data invalid_command_test = {
398         .send_opcode = 0xffff,
399         .expect_status = MGMT_STATUS_UNKNOWN_COMMAND,
400 };
401
402 static const struct generic_data read_version_success_test = {
403         .send_index_none = true,
404         .send_opcode = MGMT_OP_READ_VERSION,
405         .expect_status = MGMT_STATUS_SUCCESS,
406         .expect_len = 3,
407 };
408
409 static const struct generic_data read_version_invalid_param_test = {
410         .send_index_none = true,
411         .send_opcode = MGMT_OP_READ_VERSION,
412         .send_param = dummy_data,
413         .send_len = sizeof(dummy_data),
414         .expect_status = MGMT_STATUS_INVALID_PARAMS,
415 };
416
417 static const struct generic_data read_version_invalid_index_test = {
418         .send_opcode = MGMT_OP_READ_VERSION,
419         .expect_status = MGMT_STATUS_INVALID_INDEX,
420 };
421
422 static const struct generic_data read_commands_invalid_param_test = {
423         .send_index_none = true,
424         .send_opcode = MGMT_OP_READ_COMMANDS,
425         .send_param = dummy_data,
426         .send_len = sizeof(dummy_data),
427         .expect_status = MGMT_STATUS_INVALID_PARAMS,
428 };
429
430 static const struct generic_data read_commands_invalid_index_test = {
431         .send_opcode = MGMT_OP_READ_COMMANDS,
432         .expect_status = MGMT_STATUS_INVALID_INDEX,
433 };
434
435 static const struct generic_data read_index_list_invalid_param_test = {
436         .send_index_none = true,
437         .send_opcode = MGMT_OP_READ_INDEX_LIST,
438         .send_param = dummy_data,
439         .send_len = sizeof(dummy_data),
440         .expect_status = MGMT_STATUS_INVALID_PARAMS,
441 };
442
443 static const struct generic_data read_index_list_invalid_index_test = {
444         .send_opcode = MGMT_OP_READ_INDEX_LIST,
445         .expect_status = MGMT_STATUS_INVALID_INDEX,
446 };
447
448 static const struct generic_data read_info_invalid_param_test = {
449         .send_opcode = MGMT_OP_READ_INFO,
450         .send_param = dummy_data,
451         .send_len = sizeof(dummy_data),
452         .expect_status = MGMT_STATUS_INVALID_PARAMS,
453 };
454
455 static const struct generic_data read_info_invalid_index_test = {
456         .send_index_none = true,
457         .send_opcode = MGMT_OP_READ_INFO,
458         .expect_status = MGMT_STATUS_INVALID_INDEX,
459 };
460
461 static const char set_powered_on_param[] = { 0x01 };
462 static const char set_powered_invalid_param[] = { 0x02 };
463 static const char set_powered_garbage_param[] = { 0x01, 0x00 };
464 static const char set_powered_settings_param[] = { 0x81, 0x00, 0x00, 0x00 };
465
466 static const struct generic_data set_powered_on_success_test = {
467         .send_opcode = MGMT_OP_SET_POWERED,
468         .send_param = set_powered_on_param,
469         .send_len = sizeof(set_powered_on_param),
470         .expect_status = MGMT_STATUS_SUCCESS,
471         .expect_param = set_powered_settings_param,
472         .expect_len = sizeof(set_powered_settings_param),
473         .expect_settings_set = MGMT_SETTING_POWERED,
474 };
475
476 static const struct generic_data set_powered_on_invalid_param_test_1 = {
477         .send_opcode = MGMT_OP_SET_POWERED,
478         .expect_status = MGMT_STATUS_INVALID_PARAMS,
479 };
480
481 static const struct generic_data set_powered_on_invalid_param_test_2 = {
482         .send_opcode = MGMT_OP_SET_POWERED,
483         .send_param = set_powered_invalid_param,
484         .send_len = sizeof(set_powered_invalid_param),
485         .expect_status = MGMT_STATUS_INVALID_PARAMS,
486 };
487
488 static const struct generic_data set_powered_on_invalid_param_test_3 = {
489         .send_opcode = MGMT_OP_SET_POWERED,
490         .send_param = set_powered_garbage_param,
491         .send_len = sizeof(set_powered_garbage_param),
492         .expect_status = MGMT_STATUS_INVALID_PARAMS,
493 };
494
495 static const struct generic_data set_powered_on_invalid_index_test = {
496         .send_index_none = true,
497         .send_opcode = MGMT_OP_SET_POWERED,
498         .send_param = set_powered_on_param,
499         .send_len = sizeof(set_powered_on_param),
500         .expect_status = MGMT_STATUS_INVALID_INDEX,
501 };
502
503 static const uint16_t settings_powered[] = { MGMT_OP_SET_POWERED, 0 };
504
505 static const char set_powered_off_param[] = { 0x00 };
506 static const char set_powered_off_settings_param[] = { 0x80, 0x00, 0x00, 0x00 };
507 static const char set_powered_off_class_of_dev[] = { 0x00, 0x00, 0x00 };
508
509 static const struct generic_data set_powered_off_success_test = {
510         .setup_settings = settings_powered,
511         .send_opcode = MGMT_OP_SET_POWERED,
512         .send_param = set_powered_off_param,
513         .send_len = sizeof(set_powered_off_param),
514         .expect_status = MGMT_STATUS_SUCCESS,
515         .expect_param = set_powered_off_settings_param,
516         .expect_len = sizeof(set_powered_off_settings_param),
517         .expect_settings_unset = MGMT_SETTING_POWERED,
518 };
519
520 static const struct generic_data set_powered_off_class_test = {
521         .send_opcode = MGMT_OP_SET_POWERED,
522         .send_param = set_powered_off_param,
523         .send_len = sizeof(set_powered_off_param),
524         .expect_status = MGMT_STATUS_SUCCESS,
525         .expect_param = set_powered_off_settings_param,
526         .expect_len = sizeof(set_powered_off_settings_param),
527         .expect_settings_unset = MGMT_SETTING_POWERED,
528         .expect_alt_ev = MGMT_EV_CLASS_OF_DEV_CHANGED,
529         .expect_alt_ev_param = set_powered_off_class_of_dev,
530         .expect_alt_ev_len = sizeof(set_powered_off_class_of_dev),
531 };
532
533 static const struct generic_data set_powered_off_invalid_param_test_1 = {
534         .setup_settings = settings_powered,
535         .send_opcode = MGMT_OP_SET_POWERED,
536         .expect_status = MGMT_STATUS_INVALID_PARAMS,
537 };
538
539 static const struct generic_data set_powered_off_invalid_param_test_2 = {
540         .setup_settings = settings_powered,
541         .send_opcode = MGMT_OP_SET_POWERED,
542         .send_param = set_powered_invalid_param,
543         .send_len = sizeof(set_powered_invalid_param),
544         .expect_status = MGMT_STATUS_INVALID_PARAMS,
545 };
546
547 static const struct generic_data set_powered_off_invalid_param_test_3 = {
548         .setup_settings = settings_powered,
549         .send_opcode = MGMT_OP_SET_POWERED,
550         .send_param = set_powered_garbage_param,
551         .send_len = sizeof(set_powered_garbage_param),
552         .expect_status = MGMT_STATUS_INVALID_PARAMS,
553 };
554
555 static const char set_connectable_on_param[] = { 0x01 };
556 static const char set_connectable_invalid_param[] = { 0x02 };
557 static const char set_connectable_garbage_param[] = { 0x01, 0x00 };
558 static const char set_connectable_settings_param_1[] = { 0x82, 0x00, 0x00, 0x00 };
559 static const char set_connectable_settings_param_2[] = { 0x83, 0x00, 0x00, 0x00 };
560 static const char set_connectable_scan_enable_param[] = { 0x02 };
561
562 static const struct generic_data set_connectable_on_success_test_1 = {
563         .send_opcode = MGMT_OP_SET_CONNECTABLE,
564         .send_param = set_connectable_on_param,
565         .send_len = sizeof(set_connectable_on_param),
566         .expect_status = MGMT_STATUS_SUCCESS,
567         .expect_param = set_connectable_settings_param_1,
568         .expect_len = sizeof(set_connectable_settings_param_1),
569         .expect_settings_set = MGMT_SETTING_CONNECTABLE,
570 };
571
572 static const struct generic_data set_connectable_on_success_test_2 = {
573         .setup_settings = settings_powered,
574         .send_opcode = MGMT_OP_SET_CONNECTABLE,
575         .send_param = set_connectable_on_param,
576         .send_len = sizeof(set_connectable_on_param),
577         .expect_status = MGMT_STATUS_SUCCESS,
578         .expect_param = set_connectable_settings_param_2,
579         .expect_len = sizeof(set_connectable_settings_param_2),
580         .expect_settings_set = MGMT_SETTING_CONNECTABLE,
581         .expect_hci_command = BT_HCI_CMD_WRITE_SCAN_ENABLE,
582         .expect_hci_param = set_connectable_scan_enable_param,
583         .expect_hci_len = sizeof(set_connectable_scan_enable_param),
584 };
585
586 static const struct generic_data set_connectable_on_invalid_param_test_1 = {
587         .send_opcode = MGMT_OP_SET_CONNECTABLE,
588         .expect_status = MGMT_STATUS_INVALID_PARAMS,
589 };
590
591 static const struct generic_data set_connectable_on_invalid_param_test_2 = {
592         .send_opcode = MGMT_OP_SET_CONNECTABLE,
593         .send_param = set_connectable_invalid_param,
594         .send_len = sizeof(set_connectable_invalid_param),
595         .expect_status = MGMT_STATUS_INVALID_PARAMS,
596 };
597
598 static const struct generic_data set_connectable_on_invalid_param_test_3 = {
599         .send_opcode = MGMT_OP_SET_CONNECTABLE,
600         .send_param = set_connectable_garbage_param,
601         .send_len = sizeof(set_connectable_garbage_param),
602         .expect_status = MGMT_STATUS_INVALID_PARAMS,
603 };
604
605 static const struct generic_data set_connectable_on_invalid_index_test = {
606         .send_index_none = true,
607         .send_opcode = MGMT_OP_SET_CONNECTABLE,
608         .send_param = set_connectable_on_param,
609         .send_len = sizeof(set_connectable_on_param),
610         .expect_status = MGMT_STATUS_INVALID_INDEX,
611 };
612
613 static uint16_t settings_powered_advertising[] = { MGMT_OP_SET_ADVERTISING,
614                                                 MGMT_OP_SET_POWERED, 0 };
615
616 static const char set_connectable_le_settings_param_1[] = { 0x02, 0x02, 0x00, 0x00 };
617 static const char set_connectable_le_settings_param_2[] = { 0x03, 0x02, 0x00, 0x00 };
618 static const char set_connectable_le_settings_param_3[] = { 0x03, 0x06, 0x00, 0x00 };
619
620 static const struct generic_data set_connectable_on_le_test_1 = {
621         .send_opcode = MGMT_OP_SET_CONNECTABLE,
622         .send_param = set_connectable_on_param,
623         .send_len = sizeof(set_connectable_on_param),
624         .expect_status = MGMT_STATUS_SUCCESS,
625         .expect_param = set_connectable_le_settings_param_1,
626         .expect_len = sizeof(set_connectable_le_settings_param_1),
627         .expect_settings_set = MGMT_SETTING_CONNECTABLE,
628 };
629
630 static const struct generic_data set_connectable_on_le_test_2 = {
631         .setup_settings = settings_powered,
632         .send_opcode = MGMT_OP_SET_CONNECTABLE,
633         .send_param = set_connectable_on_param,
634         .send_len = sizeof(set_connectable_on_param),
635         .expect_status = MGMT_STATUS_SUCCESS,
636         .expect_param = set_connectable_le_settings_param_2,
637         .expect_len = sizeof(set_connectable_le_settings_param_2),
638         .expect_settings_set = MGMT_SETTING_CONNECTABLE,
639 };
640
641 static uint8_t set_connectable_on_adv_param[] = {
642                 0x00, 0x08,                             /* min_interval */
643                 0x00, 0x08,                             /* max_interval */
644                 0x00,                                   /* type */
645                 0x00,                                   /* own_addr_type */
646                 0x00,                                   /* direct_addr_type */
647                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,     /* direct_addr */
648                 0x07,                                   /* channel_map */
649                 0x00,                                   /* filter_policy */
650 };
651
652 static const struct generic_data set_connectable_on_le_test_3 = {
653         .setup_settings = settings_powered_advertising,
654         .send_opcode = MGMT_OP_SET_CONNECTABLE,
655         .send_param = set_connectable_on_param,
656         .send_len = sizeof(set_connectable_on_param),
657         .expect_status = MGMT_STATUS_SUCCESS,
658         .expect_param = set_connectable_le_settings_param_3,
659         .expect_len = sizeof(set_connectable_le_settings_param_3),
660         .expect_settings_set = MGMT_SETTING_CONNECTABLE,
661         .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_PARAMETERS,
662         .expect_hci_param = set_connectable_on_adv_param,
663         .expect_hci_len = sizeof(set_connectable_on_adv_param),
664 };
665
666 static const uint16_t settings_connectable[] = { MGMT_OP_SET_CONNECTABLE, 0 };
667 static const uint16_t settings_powered_connectable[] = {
668                                                 MGMT_OP_SET_CONNECTABLE,
669                                                 MGMT_OP_SET_POWERED, 0 };
670 static const uint16_t settings_powered_discoverable[] = {
671                                                 MGMT_OP_SET_CONNECTABLE,
672                                                 MGMT_OP_SET_DISCOVERABLE,
673                                                 MGMT_OP_SET_POWERED, 0 };
674
675 static const char set_connectable_off_param[] = { 0x00 };
676 static const char set_connectable_off_settings_1[] = { 0x80, 0x00, 0x00, 0x00 };
677 static const char set_connectable_off_settings_2[] = { 0x81, 0x00, 0x00, 0x00 };
678 static const char set_connectable_off_scan_enable_param[] = { 0x00 };
679
680 static const struct generic_data set_connectable_off_success_test_1 = {
681         .setup_settings = settings_connectable,
682         .send_opcode = MGMT_OP_SET_CONNECTABLE,
683         .send_param = set_connectable_off_param,
684         .send_len = sizeof(set_connectable_off_param),
685         .expect_status = MGMT_STATUS_SUCCESS,
686         .expect_param = set_connectable_off_settings_1,
687         .expect_len = sizeof(set_connectable_off_settings_1),
688         .expect_settings_unset = MGMT_SETTING_CONNECTABLE,
689 };
690
691 static const struct generic_data set_connectable_off_success_test_2 = {
692         .setup_settings = settings_powered_connectable,
693         .send_opcode = MGMT_OP_SET_CONNECTABLE,
694         .send_param = set_connectable_off_param,
695         .send_len = sizeof(set_connectable_off_param),
696         .expect_status = MGMT_STATUS_SUCCESS,
697         .expect_param = set_connectable_off_settings_2,
698         .expect_len = sizeof(set_connectable_off_settings_2),
699         .expect_settings_unset = MGMT_SETTING_CONNECTABLE,
700         .expect_hci_command = BT_HCI_CMD_WRITE_SCAN_ENABLE,
701         .expect_hci_param = set_connectable_off_scan_enable_param,
702         .expect_hci_len = sizeof(set_connectable_off_scan_enable_param),
703 };
704
705 static const struct generic_data set_connectable_off_success_test_3 = {
706         .setup_settings = settings_powered_discoverable,
707         .send_opcode = MGMT_OP_SET_CONNECTABLE,
708         .send_param = set_connectable_off_param,
709         .send_len = sizeof(set_connectable_off_param),
710         .expect_status = MGMT_STATUS_SUCCESS,
711         .expect_param = set_connectable_off_settings_2,
712         .expect_len = sizeof(set_connectable_off_settings_2),
713         .expect_settings_unset = MGMT_SETTING_CONNECTABLE,
714         .expect_hci_command = BT_HCI_CMD_WRITE_SCAN_ENABLE,
715         .expect_hci_param = set_connectable_off_scan_enable_param,
716         .expect_hci_len = sizeof(set_connectable_off_scan_enable_param),
717 };
718
719 static const char set_connectable_off_le_settings_1[] = { 0x00, 0x02, 0x00, 0x00 };
720 static const char set_connectable_off_le_settings_2[] = { 0x01, 0x06, 0x00, 0x00 };
721
722 static uint16_t settings_le_connectable[] = { MGMT_OP_SET_LE,
723                                                 MGMT_OP_SET_CONNECTABLE, 0 };
724
725 static const struct generic_data set_connectable_off_le_test_1 = {
726         .setup_settings = settings_le_connectable,
727         .send_opcode = MGMT_OP_SET_CONNECTABLE,
728         .send_param = set_connectable_off_param,
729         .send_len = sizeof(set_connectable_off_param),
730         .expect_status = MGMT_STATUS_SUCCESS,
731         .expect_param = set_connectable_off_le_settings_1,
732         .expect_len = sizeof(set_connectable_off_le_settings_1),
733         .expect_settings_unset = MGMT_SETTING_CONNECTABLE,
734 };
735
736 static uint16_t settings_powered_le_connectable_advertising[] = {
737                                         MGMT_OP_SET_LE,
738                                         MGMT_OP_SET_CONNECTABLE,
739                                         MGMT_OP_SET_ADVERTISING,
740                                         MGMT_OP_SET_POWERED, 0 };
741
742 static uint8_t set_connectable_off_adv_param[] = {
743                 0x00, 0x08,                             /* min_interval */
744                 0x00, 0x08,                             /* max_interval */
745                 0x03,                                   /* type */
746                 0x01,                                   /* own_addr_type */
747                 0x00,                                   /* direct_addr_type */
748                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,     /* direct_addr */
749                 0x07,                                   /* channel_map */
750                 0x00,                                   /* filter_policy */
751 };
752
753 static const struct generic_data set_connectable_off_le_test_2 = {
754         .setup_settings = settings_powered_le_connectable_advertising,
755         .send_opcode = MGMT_OP_SET_CONNECTABLE,
756         .send_param = set_connectable_off_param,
757         .send_len = sizeof(set_connectable_off_param),
758         .expect_status = MGMT_STATUS_SUCCESS,
759         .expect_param = set_connectable_off_le_settings_2,
760         .expect_len = sizeof(set_connectable_off_le_settings_2),
761         .expect_settings_unset = MGMT_SETTING_CONNECTABLE,
762         .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_PARAMETERS,
763         .expect_hci_param = set_connectable_off_adv_param,
764         .expect_hci_len = sizeof(set_connectable_off_adv_param),
765 };
766
767 static uint16_t settings_powered_le_discoverable_advertising[] = {
768                                         MGMT_OP_SET_LE,
769                                         MGMT_OP_SET_CONNECTABLE,
770                                         MGMT_OP_SET_ADVERTISING,
771                                         MGMT_OP_SET_POWERED,
772                                         MGMT_OP_SET_DISCOVERABLE, 0 };
773
774 static const struct generic_data set_connectable_off_le_test_3 = {
775         .setup_settings = settings_powered_le_discoverable_advertising,
776         .send_opcode = MGMT_OP_SET_CONNECTABLE,
777         .send_param = set_connectable_off_param,
778         .send_len = sizeof(set_connectable_off_param),
779         .expect_status = MGMT_STATUS_SUCCESS,
780         .expect_param = set_connectable_off_le_settings_2,
781         .expect_len = sizeof(set_connectable_off_le_settings_2),
782         .expect_settings_unset = MGMT_SETTING_CONNECTABLE,
783         .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_PARAMETERS,
784         .expect_hci_param = set_connectable_off_adv_param,
785         .expect_hci_len = sizeof(set_connectable_off_adv_param),
786 };
787
788 static const struct generic_data set_connectable_off_le_test_4 = {
789         .setup_settings = settings_powered_le_discoverable_advertising,
790         .setup_limited_discov = true,
791         .send_opcode = MGMT_OP_SET_CONNECTABLE,
792         .send_param = set_connectable_off_param,
793         .send_len = sizeof(set_connectable_off_param),
794         .expect_status = MGMT_STATUS_SUCCESS,
795         .expect_param = set_connectable_off_le_settings_2,
796         .expect_len = sizeof(set_connectable_off_le_settings_2),
797         .expect_settings_unset = MGMT_SETTING_CONNECTABLE,
798         .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_PARAMETERS,
799         .expect_hci_param = set_connectable_off_adv_param,
800         .expect_hci_len = sizeof(set_connectable_off_adv_param),
801 };
802
803 static const char set_fast_conn_on_param[] = { 0x01 };
804 static const char set_fast_conn_on_settings_1[] = { 0x87, 0x00, 0x00, 0x00 };
805
806 static const struct generic_data set_fast_conn_on_success_test_1 = {
807         .setup_settings = settings_powered_connectable,
808         .send_opcode = MGMT_OP_SET_FAST_CONNECTABLE,
809         .send_param = set_fast_conn_on_param,
810         .send_len = sizeof(set_fast_conn_on_param),
811         .expect_status = MGMT_STATUS_SUCCESS,
812         .expect_param = set_fast_conn_on_settings_1,
813         .expect_len = sizeof(set_fast_conn_on_settings_1),
814         .expect_settings_set = MGMT_SETTING_FAST_CONNECTABLE,
815 };
816
817 static const struct generic_data set_fast_conn_on_not_supported_test_1 = {
818         .setup_settings = settings_powered_connectable,
819         .send_opcode = MGMT_OP_SET_FAST_CONNECTABLE,
820         .send_param = set_fast_conn_on_param,
821         .send_len = sizeof(set_fast_conn_on_param),
822         .expect_status = MGMT_STATUS_NOT_SUPPORTED,
823 };
824
825 static const char set_pairable_on_param[] = { 0x01 };
826 static const char set_pairable_invalid_param[] = { 0x02 };
827 static const char set_pairable_garbage_param[] = { 0x01, 0x00 };
828 static const char set_pairable_settings_param[] = { 0x90, 0x00, 0x00, 0x00 };
829
830 static const struct generic_data set_pairable_on_success_test = {
831         .send_opcode = MGMT_OP_SET_PAIRABLE,
832         .send_param = set_pairable_on_param,
833         .send_len = sizeof(set_pairable_on_param),
834         .expect_status = MGMT_STATUS_SUCCESS,
835         .expect_param = set_pairable_settings_param,
836         .expect_len = sizeof(set_pairable_settings_param),
837         .expect_settings_set = MGMT_SETTING_PAIRABLE,
838 };
839
840 static const struct generic_data set_pairable_on_invalid_param_test_1 = {
841         .send_opcode = MGMT_OP_SET_PAIRABLE,
842         .expect_status = MGMT_STATUS_INVALID_PARAMS,
843 };
844
845 static const struct generic_data set_pairable_on_invalid_param_test_2 = {
846         .send_opcode = MGMT_OP_SET_PAIRABLE,
847         .send_param = set_pairable_invalid_param,
848         .send_len = sizeof(set_pairable_invalid_param),
849         .expect_status = MGMT_STATUS_INVALID_PARAMS,
850 };
851
852 static const struct generic_data set_pairable_on_invalid_param_test_3 = {
853         .send_opcode = MGMT_OP_SET_PAIRABLE,
854         .send_param = set_pairable_garbage_param,
855         .send_len = sizeof(set_pairable_garbage_param),
856         .expect_status = MGMT_STATUS_INVALID_PARAMS,
857 };
858
859 static const struct generic_data set_pairable_on_invalid_index_test = {
860         .send_index_none = true,
861         .send_opcode = MGMT_OP_SET_PAIRABLE,
862         .send_param = set_pairable_on_param,
863         .send_len = sizeof(set_pairable_on_param),
864         .expect_status = MGMT_STATUS_INVALID_INDEX,
865 };
866
867 static const uint8_t set_discoverable_on_param[] = { 0x01, 0x00, 0x00 };
868 static const uint8_t set_discoverable_timeout_param[] = { 0x01, 0x0a, 0x00 };
869 static const uint8_t set_discoverable_invalid_param[] = { 0x02, 0x00, 0x00 };
870 static const uint8_t set_discoverable_off_param[] = { 0x00, 0x00, 0x00 };
871 static const uint8_t set_discoverable_offtimeout_param[] = { 0x00, 0x01, 0x00 };
872 static const uint8_t set_discoverable_garbage_param[] = { 0x01, 0x00, 0x00, 0x00 };
873 static const uint8_t set_discoverable_on_settings_param_1[] = { 0x8a, 0x00, 0x00, 0x00 };
874 static const uint8_t set_discoverable_on_settings_param_2[] = { 0x8b, 0x00, 0x00, 0x00 };
875 static const uint8_t set_discoverable_off_settings_param_1[] = { 0x82, 0x00, 0x00, 0x00 };
876 static const uint8_t set_discoverable_off_settings_param_2[] = { 0x83, 0x00, 0x00, 0x00 };
877 static const uint8_t set_discoverable_on_scan_enable_param[] = { 0x03 };
878 static const uint8_t set_discoverable_off_scan_enable_param[] = { 0x02 };
879
880 static const struct generic_data set_discoverable_on_invalid_param_test_1 = {
881         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
882         .expect_status = MGMT_STATUS_INVALID_PARAMS,
883 };
884
885 static const struct generic_data set_discoverable_on_invalid_param_test_2 = {
886         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
887         .send_param = set_discoverable_invalid_param,
888         .send_len = sizeof(set_discoverable_invalid_param),
889         .expect_status = MGMT_STATUS_INVALID_PARAMS,
890 };
891
892 static const struct generic_data set_discoverable_on_invalid_param_test_3 = {
893         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
894         .send_param = set_discoverable_garbage_param,
895         .send_len = sizeof(set_discoverable_garbage_param),
896         .expect_status = MGMT_STATUS_INVALID_PARAMS,
897 };
898
899 static const struct generic_data set_discoverable_on_invalid_param_test_4 = {
900         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
901         .send_param = set_discoverable_offtimeout_param,
902         .send_len = sizeof(set_discoverable_offtimeout_param),
903         .expect_status = MGMT_STATUS_INVALID_PARAMS,
904 };
905
906 static const struct generic_data set_discoverable_on_not_powered_test_1 = {
907         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
908         .send_param = set_discoverable_timeout_param,
909         .send_len = sizeof(set_discoverable_timeout_param),
910         .expect_status = MGMT_STATUS_NOT_POWERED,
911 };
912
913 static const struct generic_data set_discoverable_on_not_powered_test_2 = {
914         .setup_settings = settings_connectable,
915         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
916         .send_param = set_discoverable_timeout_param,
917         .send_len = sizeof(set_discoverable_timeout_param),
918         .expect_status = MGMT_STATUS_NOT_POWERED,
919 };
920
921 static const struct generic_data set_discoverable_on_rejected_test_1 = {
922         .setup_settings = settings_powered,
923         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
924         .send_param = set_discoverable_on_param,
925         .send_len = sizeof(set_discoverable_on_param),
926         .expect_status = MGMT_STATUS_REJECTED,
927 };
928
929 static const struct generic_data set_discoverable_on_rejected_test_2 = {
930         .setup_settings = settings_powered,
931         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
932         .send_param = set_discoverable_on_param,
933         .send_len = sizeof(set_discoverable_on_param),
934         .expect_status = MGMT_STATUS_REJECTED,
935 };
936
937 static const struct generic_data set_discoverable_on_rejected_test_3 = {
938         .setup_settings = settings_powered,
939         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
940         .send_param = set_discoverable_timeout_param,
941         .send_len = sizeof(set_discoverable_timeout_param),
942         .expect_status = MGMT_STATUS_REJECTED,
943 };
944
945 static const struct generic_data set_discoverable_on_success_test_1 = {
946         .setup_settings = settings_connectable,
947         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
948         .send_param = set_discoverable_on_param,
949         .send_len = sizeof(set_discoverable_on_param),
950         .expect_status = MGMT_STATUS_SUCCESS,
951         .expect_param = set_discoverable_on_settings_param_1,
952         .expect_len = sizeof(set_discoverable_on_settings_param_1),
953         .expect_settings_set = MGMT_SETTING_DISCOVERABLE,
954 };
955
956 static const struct generic_data set_discoverable_on_success_test_2 = {
957         .setup_settings = settings_powered_connectable,
958         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
959         .send_param = set_discoverable_on_param,
960         .send_len = sizeof(set_discoverable_on_param),
961         .expect_status = MGMT_STATUS_SUCCESS,
962         .expect_param = set_discoverable_on_settings_param_2,
963         .expect_len = sizeof(set_discoverable_on_settings_param_2),
964         .expect_settings_set = MGMT_SETTING_DISCOVERABLE,
965         .expect_hci_command = BT_HCI_CMD_WRITE_SCAN_ENABLE,
966         .expect_hci_param = set_discoverable_on_scan_enable_param,
967         .expect_hci_len = sizeof(set_discoverable_on_scan_enable_param),
968 };
969
970 static uint8_t set_discov_on_le_param[] = { 0x0b, 0x06, 0x00, 0x00 };
971 static uint8_t set_discov_adv_data[32] = { 0x06, 0x02, 0x01, 0x06,
972                                                                 0x02, 0x0a, };
973
974 static const struct generic_data set_discov_on_le_success_1 = {
975         .setup_settings = settings_powered_le_connectable_advertising,
976         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
977         .send_param = set_discoverable_on_param,
978         .send_len = sizeof(set_discoverable_on_param),
979         .expect_status = MGMT_STATUS_SUCCESS,
980         .expect_param = set_discov_on_le_param,
981         .expect_len = sizeof(set_discov_on_le_param),
982         .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_DATA,
983         .expect_hci_param = set_discov_adv_data,
984         .expect_hci_len = sizeof(set_discov_adv_data),
985 };
986
987 static const struct generic_data set_discoverable_off_success_test_1 = {
988         .setup_settings = settings_connectable,
989         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
990         .send_param = set_discoverable_off_param,
991         .send_len = sizeof(set_discoverable_off_param),
992         .expect_status = MGMT_STATUS_SUCCESS,
993         .expect_param = set_discoverable_off_settings_param_1,
994         .expect_len = sizeof(set_discoverable_off_settings_param_1),
995 };
996
997 static const struct generic_data set_discoverable_off_success_test_2 = {
998         .setup_settings = settings_powered_discoverable,
999         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
1000         .send_param = set_discoverable_off_param,
1001         .send_len = sizeof(set_discoverable_off_param),
1002         .expect_status = MGMT_STATUS_SUCCESS,
1003         .expect_param = set_discoverable_off_settings_param_2,
1004         .expect_len = sizeof(set_discoverable_off_settings_param_2),
1005         .expect_hci_command = BT_HCI_CMD_WRITE_SCAN_ENABLE,
1006         .expect_hci_param = set_discoverable_off_scan_enable_param,
1007         .expect_hci_len = sizeof(set_discoverable_off_scan_enable_param),
1008 };
1009
1010 static const uint8_t set_limited_discov_on_param[] = { 0x02, 0x01, 0x00 };
1011
1012 static const struct generic_data set_limited_discov_on_success_1 = {
1013         .setup_settings = settings_powered_connectable,
1014         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
1015         .send_param = set_limited_discov_on_param,
1016         .send_len = sizeof(set_limited_discov_on_param),
1017         .expect_status = MGMT_STATUS_SUCCESS,
1018         .expect_param = set_discoverable_on_settings_param_2,
1019         .expect_len = sizeof(set_discoverable_on_settings_param_2),
1020         .expect_hci_command = BT_HCI_CMD_WRITE_SCAN_ENABLE,
1021         .expect_hci_param = set_discoverable_on_scan_enable_param,
1022         .expect_hci_len = sizeof(set_discoverable_on_scan_enable_param),
1023 };
1024
1025 static uint8_t write_current_iac_lap_limited[] = { 0x01, 0x00, 0x8b, 0x9e };
1026
1027 static const struct generic_data set_limited_discov_on_success_2 = {
1028         .setup_settings = settings_powered_connectable,
1029         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
1030         .send_param = set_limited_discov_on_param,
1031         .send_len = sizeof(set_limited_discov_on_param),
1032         .expect_status = MGMT_STATUS_SUCCESS,
1033         .expect_param = set_discoverable_on_settings_param_2,
1034         .expect_len = sizeof(set_discoverable_on_settings_param_2),
1035         .expect_hci_command = BT_HCI_CMD_WRITE_CURRENT_IAC_LAP,
1036         .expect_hci_param = write_current_iac_lap_limited,
1037         .expect_hci_len = sizeof(write_current_iac_lap_limited),
1038 };
1039
1040 static uint8_t write_cod_limited[] = { 0x00, 0x20, 0x00 };
1041
1042 static const struct generic_data set_limited_discov_on_success_3 = {
1043         .setup_settings = settings_powered_connectable,
1044         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
1045         .send_param = set_limited_discov_on_param,
1046         .send_len = sizeof(set_limited_discov_on_param),
1047         .expect_status = MGMT_STATUS_SUCCESS,
1048         .expect_param = set_discoverable_on_settings_param_2,
1049         .expect_len = sizeof(set_discoverable_on_settings_param_2),
1050         .expect_hci_command = BT_HCI_CMD_WRITE_CLASS_OF_DEV,
1051         .expect_hci_param = write_cod_limited,
1052         .expect_hci_len = sizeof(write_cod_limited),
1053 };
1054
1055 static uint8_t set_limited_discov_adv_data[32] = { 0x06, 0x02, 0x01, 0x05,
1056                                                                 0x02, 0x0a, };
1057
1058 static const struct generic_data set_limited_discov_on_le_success_1 = {
1059         .setup_settings = settings_powered_le_connectable_advertising,
1060         .send_opcode = MGMT_OP_SET_DISCOVERABLE,
1061         .send_param = set_limited_discov_on_param,
1062         .send_len = sizeof(set_limited_discov_on_param),
1063         .expect_status = MGMT_STATUS_SUCCESS,
1064         .expect_param = set_discov_on_le_param,
1065         .expect_len = sizeof(set_discov_on_le_param),
1066         .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_DATA,
1067         .expect_hci_param = set_limited_discov_adv_data,
1068         .expect_hci_len = sizeof(set_limited_discov_adv_data),
1069 };
1070
1071 static uint16_t settings_link_sec[] = { MGMT_OP_SET_LINK_SECURITY, 0 };
1072
1073 static const char set_link_sec_on_param[] = { 0x01 };
1074 static const char set_link_sec_invalid_param[] = { 0x02 };
1075 static const char set_link_sec_garbage_param[] = { 0x01, 0x00 };
1076 static const char set_link_sec_settings_param_1[] = { 0xa0, 0x00, 0x00, 0x00 };
1077 static const char set_link_sec_settings_param_2[] = { 0xa1, 0x00, 0x00, 0x00 };
1078 static const char set_link_sec_auth_enable_param[] = { 0x01 };
1079
1080 static const struct generic_data set_link_sec_on_success_test_1 = {
1081         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1082         .send_param = set_link_sec_on_param,
1083         .send_len = sizeof(set_link_sec_on_param),
1084         .expect_status = MGMT_STATUS_SUCCESS,
1085         .expect_param = set_link_sec_settings_param_1,
1086         .expect_len = sizeof(set_link_sec_settings_param_1),
1087         .expect_settings_set = MGMT_SETTING_LINK_SECURITY,
1088 };
1089
1090 static const struct generic_data set_link_sec_on_success_test_2 = {
1091         .setup_settings = settings_powered,
1092         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1093         .send_param = set_link_sec_on_param,
1094         .send_len = sizeof(set_link_sec_on_param),
1095         .expect_status = MGMT_STATUS_SUCCESS,
1096         .expect_param = set_link_sec_settings_param_2,
1097         .expect_len = sizeof(set_link_sec_settings_param_2),
1098         .expect_settings_set = MGMT_SETTING_LINK_SECURITY,
1099         .expect_hci_command = BT_HCI_CMD_WRITE_AUTH_ENABLE,
1100         .expect_hci_param = set_link_sec_auth_enable_param,
1101         .expect_hci_len = sizeof(set_link_sec_auth_enable_param),
1102 };
1103
1104 static const struct generic_data set_link_sec_on_success_test_3 = {
1105         .setup_settings = settings_link_sec,
1106         .send_opcode = MGMT_OP_SET_POWERED,
1107         .send_param = set_powered_on_param,
1108         .send_len = sizeof(set_powered_on_param),
1109         .expect_status = MGMT_STATUS_SUCCESS,
1110         .expect_param = set_link_sec_settings_param_2,
1111         .expect_len = sizeof(set_link_sec_settings_param_2),
1112         .expect_settings_set = MGMT_SETTING_LINK_SECURITY,
1113         .expect_hci_command = BT_HCI_CMD_WRITE_AUTH_ENABLE,
1114         .expect_hci_param = set_link_sec_auth_enable_param,
1115         .expect_hci_len = sizeof(set_link_sec_auth_enable_param),
1116 };
1117
1118 static const struct generic_data set_link_sec_on_invalid_param_test_1 = {
1119         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1120         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1121 };
1122
1123 static const struct generic_data set_link_sec_on_invalid_param_test_2 = {
1124         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1125         .send_param = set_link_sec_invalid_param,
1126         .send_len = sizeof(set_link_sec_invalid_param),
1127         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1128 };
1129
1130 static const struct generic_data set_link_sec_on_invalid_param_test_3 = {
1131         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1132         .send_param = set_link_sec_garbage_param,
1133         .send_len = sizeof(set_link_sec_garbage_param),
1134         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1135 };
1136
1137 static const struct generic_data set_link_sec_on_invalid_index_test = {
1138         .send_index_none = true,
1139         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1140         .send_param = set_link_sec_on_param,
1141         .send_len = sizeof(set_link_sec_on_param),
1142         .expect_status = MGMT_STATUS_INVALID_INDEX,
1143 };
1144
1145 static const uint16_t settings_powered_link_sec[] = {
1146                                                 MGMT_OP_SET_LINK_SECURITY,
1147                                                 MGMT_OP_SET_POWERED, 0 };
1148
1149 static const char set_link_sec_off_param[] = { 0x00 };
1150 static const char set_link_sec_off_settings_1[] = { 0x80, 0x00, 0x00, 0x00 };
1151 static const char set_link_sec_off_settings_2[] = { 0x81, 0x00, 0x00, 0x00 };
1152 static const char set_link_sec_off_auth_enable_param[] = { 0x00 };
1153
1154 static const struct generic_data set_link_sec_off_success_test_1 = {
1155         .setup_settings = settings_link_sec,
1156         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1157         .send_param = set_link_sec_off_param,
1158         .send_len = sizeof(set_link_sec_off_param),
1159         .expect_status = MGMT_STATUS_SUCCESS,
1160         .expect_param = set_link_sec_off_settings_1,
1161         .expect_len = sizeof(set_link_sec_off_settings_1),
1162         .expect_settings_unset = MGMT_SETTING_LINK_SECURITY,
1163 };
1164
1165 static const struct generic_data set_link_sec_off_success_test_2 = {
1166         .setup_settings = settings_powered_link_sec,
1167         .send_opcode = MGMT_OP_SET_LINK_SECURITY,
1168         .send_param = set_link_sec_off_param,
1169         .send_len = sizeof(set_link_sec_off_param),
1170         .expect_status = MGMT_STATUS_SUCCESS,
1171         .expect_param = set_link_sec_off_settings_2,
1172         .expect_len = sizeof(set_link_sec_off_settings_2),
1173         .expect_settings_unset = MGMT_SETTING_LINK_SECURITY,
1174         .expect_hci_command = BT_HCI_CMD_WRITE_AUTH_ENABLE,
1175         .expect_hci_param = set_link_sec_off_auth_enable_param,
1176         .expect_hci_len = sizeof(set_link_sec_off_auth_enable_param),
1177 };
1178
1179 static uint16_t settings_ssp[] = { MGMT_OP_SET_SSP, 0 };
1180
1181 static const char set_ssp_on_param[] = { 0x01 };
1182 static const char set_ssp_invalid_param[] = { 0x02 };
1183 static const char set_ssp_garbage_param[] = { 0x01, 0x00 };
1184 static const char set_ssp_settings_param_1[] = { 0xc0, 0x00, 0x00, 0x00 };
1185 static const char set_ssp_settings_param_2[] = { 0xc1, 0x00, 0x00, 0x00 };
1186 static const char set_ssp_on_write_ssp_mode_param[] = { 0x01 };
1187
1188 static const struct generic_data set_ssp_on_success_test_1 = {
1189         .send_opcode = MGMT_OP_SET_SSP,
1190         .send_param = set_ssp_on_param,
1191         .send_len = sizeof(set_ssp_on_param),
1192         .expect_status = MGMT_STATUS_SUCCESS,
1193         .expect_param = set_ssp_settings_param_1,
1194         .expect_len = sizeof(set_ssp_settings_param_1),
1195         .expect_settings_set = MGMT_SETTING_SSP,
1196 };
1197
1198 static const struct generic_data set_ssp_on_success_test_2 = {
1199         .setup_settings = settings_powered,
1200         .send_opcode = MGMT_OP_SET_SSP,
1201         .send_param = set_ssp_on_param,
1202         .send_len = sizeof(set_ssp_on_param),
1203         .expect_status = MGMT_STATUS_SUCCESS,
1204         .expect_param = set_ssp_settings_param_2,
1205         .expect_len = sizeof(set_ssp_settings_param_2),
1206         .expect_settings_set = MGMT_SETTING_SSP,
1207         .expect_hci_command = BT_HCI_CMD_WRITE_SIMPLE_PAIRING_MODE,
1208         .expect_hci_param = set_ssp_on_write_ssp_mode_param,
1209         .expect_hci_len = sizeof(set_ssp_on_write_ssp_mode_param),
1210 };
1211
1212 static const struct generic_data set_ssp_on_success_test_3 = {
1213         .setup_settings = settings_ssp,
1214         .send_opcode = MGMT_OP_SET_POWERED,
1215         .send_param = set_powered_on_param,
1216         .send_len = sizeof(set_powered_on_param),
1217         .expect_status = MGMT_STATUS_SUCCESS,
1218         .expect_param = set_ssp_settings_param_2,
1219         .expect_len = sizeof(set_ssp_settings_param_2),
1220         .expect_settings_set = MGMT_SETTING_SSP,
1221         .expect_hci_command = BT_HCI_CMD_WRITE_SIMPLE_PAIRING_MODE,
1222         .expect_hci_param = set_ssp_on_write_ssp_mode_param,
1223         .expect_hci_len = sizeof(set_ssp_on_write_ssp_mode_param),
1224 };
1225
1226 static const struct generic_data set_ssp_on_invalid_param_test_1 = {
1227         .send_opcode = MGMT_OP_SET_SSP,
1228         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1229 };
1230
1231 static const struct generic_data set_ssp_on_invalid_param_test_2 = {
1232         .send_opcode = MGMT_OP_SET_SSP,
1233         .send_param = set_ssp_invalid_param,
1234         .send_len = sizeof(set_ssp_invalid_param),
1235         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1236 };
1237
1238 static const struct generic_data set_ssp_on_invalid_param_test_3 = {
1239         .send_opcode = MGMT_OP_SET_SSP,
1240         .send_param = set_ssp_garbage_param,
1241         .send_len = sizeof(set_ssp_garbage_param),
1242         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1243 };
1244
1245 static const struct generic_data set_ssp_on_invalid_index_test = {
1246         .send_index_none = true,
1247         .send_opcode = MGMT_OP_SET_SSP,
1248         .send_param = set_ssp_on_param,
1249         .send_len = sizeof(set_ssp_on_param),
1250         .expect_status = MGMT_STATUS_INVALID_INDEX,
1251 };
1252
1253 static uint16_t settings_powered_ssp[] = { MGMT_OP_SET_SSP,
1254                                                 MGMT_OP_SET_POWERED, 0 };
1255
1256 static const char set_sc_on_param[] = { 0x01 };
1257 static const char set_sc_only_on_param[] = { 0x02 };
1258 static const char set_sc_invalid_param[] = { 0x03 };
1259 static const char set_sc_garbage_param[] = { 0x01, 0x00 };
1260 static const char set_sc_settings_param_1[] = { 0xc0, 0x08, 0x00, 0x00 };
1261 static const char set_sc_settings_param_2[] = { 0xc1, 0x08, 0x00, 0x00 };
1262 static const char set_sc_on_write_sc_support_param[] = { 0x01 };
1263
1264 static const struct generic_data set_sc_on_success_test_1 = {
1265         .setup_settings = settings_ssp,
1266         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1267         .send_param = set_sc_on_param,
1268         .send_len = sizeof(set_sc_on_param),
1269         .expect_status = MGMT_STATUS_SUCCESS,
1270         .expect_param = set_sc_settings_param_1,
1271         .expect_len = sizeof(set_sc_settings_param_1),
1272         .expect_settings_set = MGMT_SETTING_SECURE_CONN,
1273 };
1274
1275 static const struct generic_data set_sc_on_success_test_2 = {
1276         .setup_settings = settings_powered_ssp,
1277         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1278         .send_param = set_sc_on_param,
1279         .send_len = sizeof(set_sc_on_param),
1280         .expect_status = MGMT_STATUS_SUCCESS,
1281         .expect_param = set_sc_settings_param_2,
1282         .expect_len = sizeof(set_sc_settings_param_2),
1283         .expect_settings_set = MGMT_SETTING_SECURE_CONN,
1284         .expect_hci_command = BT_HCI_CMD_WRITE_SECURE_CONN_SUPPORT,
1285         .expect_hci_param = set_sc_on_write_sc_support_param,
1286         .expect_hci_len = sizeof(set_sc_on_write_sc_support_param),
1287 };
1288
1289 static const struct generic_data set_sc_on_invalid_param_test_1 = {
1290         .setup_settings = settings_ssp,
1291         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1292         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1293 };
1294
1295 static const struct generic_data set_sc_on_invalid_param_test_2 = {
1296         .setup_settings = settings_ssp,
1297         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1298         .send_param = set_sc_invalid_param,
1299         .send_len = sizeof(set_sc_invalid_param),
1300         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1301 };
1302
1303 static const struct generic_data set_sc_on_invalid_param_test_3 = {
1304         .setup_settings = settings_ssp,
1305         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1306         .send_param = set_sc_garbage_param,
1307         .send_len = sizeof(set_sc_garbage_param),
1308         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1309 };
1310
1311 static const struct generic_data set_sc_on_invalid_index_test = {
1312         .setup_settings = settings_ssp,
1313         .send_index_none = true,
1314         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1315         .send_param = set_sc_on_param,
1316         .send_len = sizeof(set_sc_on_param),
1317         .expect_status = MGMT_STATUS_INVALID_INDEX,
1318 };
1319
1320 static const struct generic_data set_sc_on_not_supported_test_1 = {
1321         .setup_settings = settings_ssp,
1322         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1323         .send_param = set_sc_on_param,
1324         .send_len = sizeof(set_sc_on_param),
1325         .expect_status = MGMT_STATUS_NOT_SUPPORTED,
1326 };
1327
1328 static const struct generic_data set_sc_on_not_supported_test_2 = {
1329         .setup_settings = settings_powered_ssp,
1330         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1331         .send_param = set_sc_on_param,
1332         .send_len = sizeof(set_sc_on_param),
1333         .expect_status = MGMT_STATUS_NOT_SUPPORTED,
1334 };
1335
1336 static const struct generic_data set_sc_only_on_success_test_1 = {
1337         .setup_settings = settings_ssp,
1338         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1339         .send_param = set_sc_only_on_param,
1340         .send_len = sizeof(set_sc_only_on_param),
1341         .expect_status = MGMT_STATUS_SUCCESS,
1342         .expect_param = set_sc_settings_param_1,
1343         .expect_len = sizeof(set_sc_settings_param_1),
1344         .expect_settings_set = MGMT_SETTING_SECURE_CONN,
1345 };
1346
1347 static const struct generic_data set_sc_only_on_success_test_2 = {
1348         .setup_settings = settings_powered_ssp,
1349         .send_opcode = MGMT_OP_SET_SECURE_CONN,
1350         .send_param = set_sc_only_on_param,
1351         .send_len = sizeof(set_sc_only_on_param),
1352         .expect_status = MGMT_STATUS_SUCCESS,
1353         .expect_param = set_sc_settings_param_2,
1354         .expect_len = sizeof(set_sc_settings_param_2),
1355         .expect_settings_set = MGMT_SETTING_SECURE_CONN,
1356         .expect_hci_command = BT_HCI_CMD_WRITE_SECURE_CONN_SUPPORT,
1357         .expect_hci_param = set_sc_on_write_sc_support_param,
1358         .expect_hci_len = sizeof(set_sc_on_write_sc_support_param),
1359 };
1360
1361 static const char set_hs_on_param[] = { 0x01 };
1362 static const char set_hs_invalid_param[] = { 0x02 };
1363 static const char set_hs_garbage_param[] = { 0x01, 0x00 };
1364 static const char set_hs_settings_param_1[] = { 0xc0, 0x01, 0x00, 0x00 };
1365
1366 static const struct generic_data set_hs_on_success_test = {
1367         .setup_settings = settings_ssp,
1368         .send_opcode = MGMT_OP_SET_HS,
1369         .send_param = set_hs_on_param,
1370         .send_len = sizeof(set_hs_on_param),
1371         .expect_status = MGMT_STATUS_SUCCESS,
1372         .expect_param = set_hs_settings_param_1,
1373         .expect_len = sizeof(set_hs_settings_param_1),
1374         .expect_settings_set = MGMT_SETTING_HS,
1375 };
1376
1377 static const struct generic_data set_hs_on_invalid_param_test_1 = {
1378         .setup_settings = settings_ssp,
1379         .send_opcode = MGMT_OP_SET_HS,
1380         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1381 };
1382
1383 static const struct generic_data set_hs_on_invalid_param_test_2 = {
1384         .setup_settings = settings_ssp,
1385         .send_opcode = MGMT_OP_SET_HS,
1386         .send_param = set_hs_invalid_param,
1387         .send_len = sizeof(set_hs_invalid_param),
1388         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1389 };
1390
1391 static const struct generic_data set_hs_on_invalid_param_test_3 = {
1392         .setup_settings = settings_ssp,
1393         .send_opcode = MGMT_OP_SET_HS,
1394         .send_param = set_hs_garbage_param,
1395         .send_len = sizeof(set_hs_garbage_param),
1396         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1397 };
1398
1399 static const struct generic_data set_hs_on_invalid_index_test = {
1400         .setup_settings = settings_ssp,
1401         .send_index_none = true,
1402         .send_opcode = MGMT_OP_SET_HS,
1403         .send_param = set_hs_on_param,
1404         .send_len = sizeof(set_hs_on_param),
1405         .expect_status = MGMT_STATUS_INVALID_INDEX,
1406 };
1407
1408 static uint16_t settings_le[] = { MGMT_OP_SET_LE, 0 };
1409
1410 static const char set_le_on_param[] = { 0x01 };
1411 static const char set_le_invalid_param[] = { 0x02 };
1412 static const char set_le_garbage_param[] = { 0x01, 0x00 };
1413 static const char set_le_settings_param_1[] = { 0x80, 0x02, 0x00, 0x00 };
1414 static const char set_le_settings_param_2[] = { 0x81, 0x02, 0x00, 0x00 };
1415 static const char set_le_on_write_le_host_param[] = { 0x01, 0x01 };
1416
1417 static const struct generic_data set_le_on_success_test_1 = {
1418         .send_opcode = MGMT_OP_SET_LE,
1419         .send_param = set_le_on_param,
1420         .send_len = sizeof(set_le_on_param),
1421         .expect_status = MGMT_STATUS_SUCCESS,
1422         .expect_param = set_le_settings_param_1,
1423         .expect_len = sizeof(set_le_settings_param_1),
1424         .expect_settings_set = MGMT_SETTING_LE,
1425 };
1426
1427 static const struct generic_data set_le_on_success_test_2 = {
1428         .setup_settings = settings_powered,
1429         .send_opcode = MGMT_OP_SET_LE,
1430         .send_param = set_le_on_param,
1431         .send_len = sizeof(set_le_on_param),
1432         .expect_status = MGMT_STATUS_SUCCESS,
1433         .expect_param = set_le_settings_param_2,
1434         .expect_len = sizeof(set_le_settings_param_2),
1435         .expect_settings_set = MGMT_SETTING_LE,
1436         .expect_hci_command = BT_HCI_CMD_WRITE_LE_HOST_SUPPORTED,
1437         .expect_hci_param = set_le_on_write_le_host_param,
1438         .expect_hci_len = sizeof(set_le_on_write_le_host_param),
1439 };
1440
1441 static const struct generic_data set_le_on_success_test_3 = {
1442         .setup_settings = settings_le,
1443         .send_opcode = MGMT_OP_SET_POWERED,
1444         .send_param = set_powered_on_param,
1445         .send_len = sizeof(set_powered_on_param),
1446         .expect_status = MGMT_STATUS_SUCCESS,
1447         .expect_param = set_le_settings_param_2,
1448         .expect_len = sizeof(set_le_settings_param_2),
1449         .expect_settings_set = MGMT_SETTING_LE,
1450         .expect_hci_command = BT_HCI_CMD_WRITE_LE_HOST_SUPPORTED,
1451         .expect_hci_param = set_le_on_write_le_host_param,
1452         .expect_hci_len = sizeof(set_le_on_write_le_host_param),
1453 };
1454
1455 static const struct generic_data set_le_on_invalid_param_test_1 = {
1456         .send_opcode = MGMT_OP_SET_LE,
1457         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1458 };
1459
1460 static const struct generic_data set_le_on_invalid_param_test_2 = {
1461         .send_opcode = MGMT_OP_SET_LE,
1462         .send_param = set_le_invalid_param,
1463         .send_len = sizeof(set_le_invalid_param),
1464         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1465 };
1466
1467 static const struct generic_data set_le_on_invalid_param_test_3 = {
1468         .send_opcode = MGMT_OP_SET_LE,
1469         .send_param = set_le_garbage_param,
1470         .send_len = sizeof(set_le_garbage_param),
1471         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1472 };
1473
1474 static const struct generic_data set_le_on_invalid_index_test = {
1475         .send_index_none = true,
1476         .send_opcode = MGMT_OP_SET_LE,
1477         .send_param = set_le_on_param,
1478         .send_len = sizeof(set_le_on_param),
1479         .expect_status = MGMT_STATUS_INVALID_INDEX,
1480 };
1481
1482 static uint16_t settings_powered_le[] = { MGMT_OP_SET_LE,
1483                                         MGMT_OP_SET_POWERED, 0 };
1484
1485 static const char set_adv_on_param[] = { 0x01 };
1486 static const char set_adv_settings_param_1[] = { 0x80, 0x06, 0x00, 0x00 };
1487 static const char set_adv_settings_param_2[] = { 0x81, 0x06, 0x00, 0x00 };
1488 static const char set_adv_on_set_adv_enable_param[] = { 0x01 };
1489
1490 static const struct generic_data set_adv_on_success_test_1 = {
1491         .setup_settings = settings_le,
1492         .send_opcode = MGMT_OP_SET_ADVERTISING,
1493         .send_param = set_adv_on_param,
1494         .send_len = sizeof(set_adv_on_param),
1495         .expect_status = MGMT_STATUS_SUCCESS,
1496         .expect_param = set_adv_settings_param_1,
1497         .expect_len = sizeof(set_adv_settings_param_1),
1498         .expect_settings_set = MGMT_SETTING_ADVERTISING,
1499 };
1500
1501 static const struct generic_data set_adv_on_success_test_2 = {
1502         .setup_settings = settings_powered_le,
1503         .send_opcode = MGMT_OP_SET_ADVERTISING,
1504         .send_param = set_adv_on_param,
1505         .send_len = sizeof(set_adv_on_param),
1506         .expect_status = MGMT_STATUS_SUCCESS,
1507         .expect_param = set_adv_settings_param_2,
1508         .expect_len = sizeof(set_adv_settings_param_2),
1509         .expect_settings_set = MGMT_SETTING_ADVERTISING,
1510         .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_ENABLE,
1511         .expect_hci_param = set_adv_on_set_adv_enable_param,
1512         .expect_hci_len = sizeof(set_adv_on_set_adv_enable_param),
1513 };
1514
1515 static const struct generic_data set_adv_on_rejected_test_1 = {
1516         .setup_settings = settings_powered,
1517         .send_opcode = MGMT_OP_SET_ADVERTISING,
1518         .send_param = set_adv_on_param,
1519         .send_len = sizeof(set_adv_on_param),
1520         .expect_status = MGMT_STATUS_REJECTED,
1521 };
1522
1523 static const char set_bredr_off_param[] = { 0x00 };
1524 static const char set_bredr_on_param[] = { 0x01 };
1525 static const char set_bredr_invalid_param[] = { 0x02 };
1526 static const char set_bredr_settings_param_1[] = { 0x00, 0x02, 0x00, 0x00 };
1527 static const char set_bredr_settings_param_2[] = { 0x80, 0x02, 0x00, 0x00 };
1528 static const char set_bredr_settings_param_3[] = { 0x81, 0x02, 0x00, 0x00 };
1529
1530 static const struct generic_data set_bredr_off_success_test_1 = {
1531         .setup_settings = settings_le,
1532         .send_opcode = MGMT_OP_SET_BREDR,
1533         .send_param = set_bredr_off_param,
1534         .send_len = sizeof(set_bredr_off_param),
1535         .expect_status = MGMT_STATUS_SUCCESS,
1536         .expect_param = set_bredr_settings_param_1,
1537         .expect_len = sizeof(set_bredr_settings_param_1),
1538         .expect_settings_unset = MGMT_SETTING_BREDR,
1539 };
1540
1541 static const struct generic_data set_bredr_on_success_test_1 = {
1542         .setup_settings = settings_le,
1543         .setup_nobredr = true,
1544         .send_opcode = MGMT_OP_SET_BREDR,
1545         .send_param = set_bredr_on_param,
1546         .send_len = sizeof(set_bredr_on_param),
1547         .expect_status = MGMT_STATUS_SUCCESS,
1548         .expect_param = set_bredr_settings_param_2,
1549         .expect_len = sizeof(set_bredr_settings_param_2),
1550         .expect_settings_set = MGMT_SETTING_BREDR,
1551 };
1552
1553 static const struct generic_data set_bredr_on_success_test_2 = {
1554         .setup_settings = settings_powered_le,
1555         .setup_nobredr = true,
1556         .send_opcode = MGMT_OP_SET_BREDR,
1557         .send_param = set_bredr_on_param,
1558         .send_len = sizeof(set_bredr_on_param),
1559         .expect_status = MGMT_STATUS_SUCCESS,
1560         .expect_param = set_bredr_settings_param_3,
1561         .expect_len = sizeof(set_bredr_settings_param_3),
1562         .expect_settings_set = MGMT_SETTING_BREDR,
1563 };
1564
1565 static const struct generic_data set_bredr_off_notsupp_test = {
1566         .send_opcode = MGMT_OP_SET_BREDR,
1567         .send_param = set_bredr_off_param,
1568         .send_len = sizeof(set_bredr_off_param),
1569         .expect_status = MGMT_STATUS_NOT_SUPPORTED,
1570 };
1571
1572 static const struct generic_data set_bredr_off_failure_test_1 = {
1573         .setup_settings = settings_powered_le,
1574         .send_opcode = MGMT_OP_SET_BREDR,
1575         .send_param = set_bredr_off_param,
1576         .send_len = sizeof(set_bredr_off_param),
1577         .expect_status = MGMT_STATUS_REJECTED,
1578 };
1579
1580 static const struct generic_data set_bredr_off_failure_test_2 = {
1581         .setup_settings = settings_powered,
1582         .send_opcode = MGMT_OP_SET_BREDR,
1583         .send_param = set_bredr_off_param,
1584         .send_len = sizeof(set_bredr_off_param),
1585         .expect_status = MGMT_STATUS_REJECTED,
1586 };
1587
1588 static const struct generic_data set_bredr_off_failure_test_3 = {
1589         .setup_settings = settings_le,
1590         .send_opcode = MGMT_OP_SET_BREDR,
1591         .send_param = set_bredr_invalid_param,
1592         .send_len = sizeof(set_bredr_invalid_param),
1593         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1594 };
1595
1596 static const char set_local_name_param[260] = { 'T', 'e', 's', 't', ' ',
1597                                                 'n', 'a', 'm', 'e' };
1598 static const char write_local_name_hci[248] = { 'T', 'e', 's', 't', ' ',
1599                                                 'n', 'a', 'm', 'e' };
1600 static const char write_eir_local_name_hci_1[241] = { 0x00,
1601                 0x0a, 0x09, 'T', 'e', 's', 't', ' ', 'n', 'a', 'm', 'e',
1602                 0x02, 0x0a, 0x00, };
1603
1604 static const struct generic_data set_local_name_test_1 = {
1605         .send_opcode = MGMT_OP_SET_LOCAL_NAME,
1606         .send_param = set_local_name_param,
1607         .send_len = sizeof(set_local_name_param),
1608         .expect_status = MGMT_STATUS_SUCCESS,
1609         .expect_param = set_local_name_param,
1610         .expect_len = sizeof(set_local_name_param),
1611         .expect_alt_ev = MGMT_EV_LOCAL_NAME_CHANGED,
1612         .expect_alt_ev_param = set_local_name_param,
1613         .expect_alt_ev_len = sizeof(set_local_name_param),
1614 };
1615
1616 static const struct generic_data set_local_name_test_2 = {
1617         .setup_settings = settings_powered,
1618         .send_opcode = MGMT_OP_SET_LOCAL_NAME,
1619         .send_param = set_local_name_param,
1620         .send_len = sizeof(set_local_name_param),
1621         .expect_status = MGMT_STATUS_SUCCESS,
1622         .expect_param = set_local_name_param,
1623         .expect_len = sizeof(set_local_name_param),
1624         .expect_hci_command = BT_HCI_CMD_WRITE_LOCAL_NAME,
1625         .expect_hci_param = write_local_name_hci,
1626         .expect_hci_len = sizeof(write_local_name_hci),
1627         .expect_alt_ev = MGMT_EV_LOCAL_NAME_CHANGED,
1628         .expect_alt_ev_param = set_local_name_param,
1629         .expect_alt_ev_len = sizeof(set_local_name_param),
1630 };
1631
1632 static const struct generic_data set_local_name_test_3 = {
1633         .setup_settings = settings_powered_ssp,
1634         .send_opcode = MGMT_OP_SET_LOCAL_NAME,
1635         .send_param = set_local_name_param,
1636         .send_len = sizeof(set_local_name_param),
1637         .expect_status = MGMT_STATUS_SUCCESS,
1638         .expect_param = set_local_name_param,
1639         .expect_len = sizeof(set_local_name_param),
1640         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
1641         .expect_hci_param = write_eir_local_name_hci_1,
1642         .expect_hci_len = sizeof(write_eir_local_name_hci_1),
1643         .expect_alt_ev = MGMT_EV_LOCAL_NAME_CHANGED,
1644         .expect_alt_ev_param = set_local_name_param,
1645         .expect_alt_ev_len = sizeof(set_local_name_param),
1646 };
1647
1648 static const char start_discovery_invalid_param[] = { 0x00 };
1649 static const char start_discovery_bredr_param[] = { 0x01 };
1650 static const char start_discovery_le_param[] = { 0x06 };
1651 static const char start_discovery_bredrle_param[] = { 0x07 };
1652 static const char start_discovery_valid_hci[] = { 0x01, 0x01 };
1653 static const char start_discovery_evt[] = { 0x07, 0x01 };
1654 static const char start_discovery_le_evt[] = { 0x06, 0x01 };
1655
1656 static const struct generic_data start_discovery_not_powered_test_1 = {
1657         .send_opcode = MGMT_OP_START_DISCOVERY,
1658         .send_param = start_discovery_bredr_param,
1659         .send_len = sizeof(start_discovery_bredr_param),
1660         .expect_status = MGMT_STATUS_NOT_POWERED,
1661 };
1662
1663 static const struct generic_data start_discovery_invalid_param_test_1 = {
1664         .setup_settings = settings_powered,
1665         .send_opcode = MGMT_OP_START_DISCOVERY,
1666         .send_param = start_discovery_invalid_param,
1667         .send_len = sizeof(start_discovery_invalid_param),
1668         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1669 };
1670
1671 static const struct generic_data start_discovery_not_supported_test_1 = {
1672         .setup_settings = settings_powered,
1673         .send_opcode = MGMT_OP_START_DISCOVERY,
1674         .send_param = start_discovery_le_param,
1675         .send_len = sizeof(start_discovery_le_param),
1676         .expect_status = MGMT_STATUS_REJECTED,
1677 };
1678
1679 static const struct generic_data start_discovery_valid_param_test_1 = {
1680         .setup_settings = settings_powered_le,
1681         .send_opcode = MGMT_OP_START_DISCOVERY,
1682         .send_param = start_discovery_bredrle_param,
1683         .send_len = sizeof(start_discovery_bredrle_param),
1684         .expect_status = MGMT_STATUS_SUCCESS,
1685         .expect_param = start_discovery_bredrle_param,
1686         .expect_len = sizeof(start_discovery_bredrle_param),
1687         .expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
1688         .expect_hci_param = start_discovery_valid_hci,
1689         .expect_hci_len = sizeof(start_discovery_valid_hci),
1690         .expect_alt_ev = MGMT_EV_DISCOVERING,
1691         .expect_alt_ev_param = start_discovery_evt,
1692         .expect_alt_ev_len = sizeof(start_discovery_evt),
1693 };
1694
1695 static const struct generic_data start_discovery_valid_param_test_2 = {
1696         .setup_settings = settings_powered,
1697         .send_opcode = MGMT_OP_START_DISCOVERY,
1698         .send_param = start_discovery_le_param,
1699         .send_len = sizeof(start_discovery_le_param),
1700         .expect_status = MGMT_STATUS_SUCCESS,
1701         .expect_param = start_discovery_le_param,
1702         .expect_len = sizeof(start_discovery_le_param),
1703         .expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
1704         .expect_hci_param = start_discovery_valid_hci,
1705         .expect_hci_len = sizeof(start_discovery_valid_hci),
1706         .expect_alt_ev = MGMT_EV_DISCOVERING,
1707         .expect_alt_ev_param = start_discovery_le_evt,
1708         .expect_alt_ev_len = sizeof(start_discovery_le_evt),
1709 };
1710
1711 static const char stop_discovery_bredrle_param[] = { 0x07 };
1712 static const char stop_discovery_bredrle_invalid_param[] = { 0x06 };
1713 static const char stop_discovery_valid_hci[] = { 0x00, 0x00 };
1714 static const char stop_discovery_evt[] = { 0x07, 0x00 };
1715 static const char stop_discovery_bredr_param[] = { 0x01 };
1716 static const char stop_discovery_bredr_discovering[] = { 0x01, 0x00 };
1717 static const char stop_discovery_inq_param[] = { 0x33, 0x8b, 0x9e, 0x08, 0x00 };
1718
1719 static const struct generic_data stop_discovery_success_test_1 = {
1720         .setup_settings = settings_powered_le,
1721         .send_opcode = MGMT_OP_STOP_DISCOVERY,
1722         .send_param = stop_discovery_bredrle_param,
1723         .send_len = sizeof(stop_discovery_bredrle_param),
1724         .expect_status = MGMT_STATUS_SUCCESS,
1725         .expect_param = stop_discovery_bredrle_param,
1726         .expect_len = sizeof(stop_discovery_bredrle_param),
1727         .expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_ENABLE,
1728         .expect_hci_param = stop_discovery_valid_hci,
1729         .expect_hci_len = sizeof(stop_discovery_valid_hci),
1730         .expect_alt_ev = MGMT_EV_DISCOVERING,
1731         .expect_alt_ev_param = stop_discovery_evt,
1732         .expect_alt_ev_len = sizeof(stop_discovery_evt),
1733 };
1734
1735 static const struct generic_data stop_discovery_bredr_success_test_1 = {
1736         .setup_settings = settings_powered_le,
1737         .setup_expect_hci_command = BT_HCI_CMD_INQUIRY,
1738         .setup_expect_hci_param = stop_discovery_inq_param,
1739         .setup_expect_hci_len = sizeof(stop_discovery_inq_param),
1740         .send_opcode = MGMT_OP_STOP_DISCOVERY,
1741         .send_param = stop_discovery_bredr_param,
1742         .send_len = sizeof(stop_discovery_bredr_param),
1743         .expect_status = MGMT_STATUS_SUCCESS,
1744         .expect_param = stop_discovery_bredr_param,
1745         .expect_len = sizeof(stop_discovery_bredr_param),
1746         .expect_hci_command = BT_HCI_CMD_INQUIRY_CANCEL,
1747         .expect_alt_ev = MGMT_EV_DISCOVERING,
1748         .expect_alt_ev_param = stop_discovery_bredr_discovering,
1749         .expect_alt_ev_len = sizeof(stop_discovery_bredr_discovering),
1750 };
1751
1752 static const struct generic_data stop_discovery_rejected_test_1 = {
1753         .setup_settings = settings_powered_le,
1754         .send_opcode = MGMT_OP_STOP_DISCOVERY,
1755         .send_param = stop_discovery_bredrle_param,
1756         .send_len = sizeof(stop_discovery_bredrle_param),
1757         .expect_status = MGMT_STATUS_REJECTED,
1758         .expect_param = stop_discovery_bredrle_param,
1759         .expect_len = sizeof(stop_discovery_bredrle_param),
1760 };
1761
1762 static const struct generic_data stop_discovery_invalid_param_test_1 = {
1763         .setup_settings = settings_powered_le,
1764         .send_opcode = MGMT_OP_STOP_DISCOVERY,
1765         .send_param = stop_discovery_bredrle_invalid_param,
1766         .send_len = sizeof(stop_discovery_bredrle_invalid_param),
1767         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1768         .expect_param = stop_discovery_bredrle_invalid_param,
1769         .expect_len = sizeof(stop_discovery_bredrle_invalid_param),
1770 };
1771
1772 static const char set_dev_class_valid_param[] = { 0x01, 0x0c };
1773 static const char set_dev_class_zero_rsp[] = { 0x00, 0x00, 0x00 };
1774 static const char set_dev_class_valid_rsp[] = { 0x0c, 0x01, 0x00 };
1775 static const char set_dev_class_valid_hci[] = { 0x0c, 0x01, 0x00 };
1776 static const char set_dev_class_invalid_param[] = { 0x01, 0x01 };
1777
1778 static const struct generic_data set_dev_class_valid_param_test_1 = {
1779         .send_opcode = MGMT_OP_SET_DEV_CLASS,
1780         .send_param = set_dev_class_valid_param,
1781         .send_len = sizeof(set_dev_class_valid_param),
1782         .expect_status = MGMT_STATUS_SUCCESS,
1783         .expect_param = set_dev_class_zero_rsp,
1784         .expect_len = sizeof(set_dev_class_zero_rsp),
1785 };
1786
1787 static const struct generic_data set_dev_class_valid_param_test_2 = {
1788         .setup_settings = settings_powered,
1789         .send_opcode = MGMT_OP_SET_DEV_CLASS,
1790         .send_param = set_dev_class_valid_param,
1791         .send_len = sizeof(set_dev_class_valid_param),
1792         .expect_status = MGMT_STATUS_SUCCESS,
1793         .expect_param = set_dev_class_valid_rsp,
1794         .expect_len = sizeof(set_dev_class_valid_rsp),
1795         .expect_alt_ev = MGMT_EV_CLASS_OF_DEV_CHANGED,
1796         .expect_alt_ev_param = set_dev_class_valid_rsp,
1797         .expect_alt_ev_len = sizeof(set_dev_class_valid_rsp),
1798         .expect_hci_command = BT_HCI_CMD_WRITE_CLASS_OF_DEV,
1799         .expect_hci_param = set_dev_class_valid_hci,
1800         .expect_hci_len = sizeof(set_dev_class_valid_hci),
1801 };
1802
1803 static const struct generic_data set_dev_class_invalid_param_test_1 = {
1804         .send_opcode = MGMT_OP_SET_DEV_CLASS,
1805         .send_param = set_dev_class_invalid_param,
1806         .send_len = sizeof(set_dev_class_invalid_param),
1807         .expect_status = MGMT_STATUS_INVALID_PARAMS,
1808 };
1809
1810 static const char add_spp_uuid_param[] = {
1811                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1812                         0x00, 0x10, 0x00, 0x00, 0x01, 0x11, 0x00, 0x00,
1813                         0x00 };
1814 static const char add_dun_uuid_param[] = {
1815                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1816                         0x00, 0x10, 0x00, 0x00, 0x03, 0x11, 0x00, 0x00,
1817                         0x00 };
1818 static const char add_sync_uuid_param[] = {
1819                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1820                         0x00, 0x10, 0x00, 0x00, 0x04, 0x11, 0x00, 0x00,
1821                         0x00 };
1822 static const char add_opp_uuid_param[] = {
1823                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1824                         0x00, 0x10, 0x00, 0x00, 0x05, 0x11, 0x00, 0x00,
1825                         0x00 };
1826 static const char write_eir_uuid16_hci[241] = { 0x00,
1827                         0x02, 0x0a, 0x00, 0x03, 0x03, 0x01, 0x11 };
1828 static const char write_eir_multi_uuid16_hci_1[241] = { 0x00,
1829                         0x02, 0x0a, 0x00, 0x09, 0x03, 0x01, 0x11, 0x03,
1830                         0x11, 0x04, 0x11, 0x05, 0x11 };
1831 static const char write_eir_multi_uuid16_hci_2[241] = { 0x00,
1832                         0x02, 0x0a, 0x00, 0xeb, 0x02, 0x00, 0x20, 0x01,
1833                         0x20, 0x02, 0x20, 0x03, 0x20, 0x04, 0x20, 0x05,
1834                         0x20, 0x06, 0x20, 0x07, 0x20, 0x08, 0x20, 0x09,
1835                         0x20, 0x0a, 0x20, 0x0b, 0x20, 0x0c, 0x20, 0x0d,
1836                         0x20, 0x0e, 0x20, 0x0f, 0x20, 0x10, 0x20, 0x11,
1837                         0x20, 0x12, 0x20, 0x13, 0x20, 0x14, 0x20, 0x15,
1838                         0x20, 0x16, 0x20, 0x17, 0x20, 0x18, 0x20, 0x19,
1839                         0x20, 0x1a, 0x20, 0x1b, 0x20, 0x1c, 0x20, 0x1d,
1840                         0x20, 0x1e, 0x20, 0x1f, 0x20, 0x20, 0x20, 0x21,
1841                         0x20, 0x22, 0x20, 0x23, 0x20, 0x24, 0x20, 0x25,
1842                         0x20, 0x26, 0x20, 0x27, 0x20, 0x28, 0x20, 0x29,
1843                         0x20, 0x2a, 0x20, 0x2b, 0x20, 0x2c, 0x20, 0x2d,
1844                         0x20, 0x2e, 0x20, 0x2f, 0x20, 0x30, 0x20, 0x31,
1845                         0x20, 0x32, 0x20, 0x33, 0x20, 0x34, 0x20, 0x35,
1846                         0x20, 0x36, 0x20, 0x37, 0x20, 0x38, 0x20, 0x39,
1847                         0x20, 0x3a, 0x20, 0x3b, 0x20, 0x3c, 0x20, 0x3d,
1848                         0x20, 0x3e, 0x20, 0x3f, 0x20, 0x40, 0x20, 0x41,
1849                         0x20, 0x42, 0x20, 0x43, 0x20, 0x44, 0x20, 0x45,
1850                         0x20, 0x46, 0x20, 0x47, 0x20, 0x48, 0x20, 0x49,
1851                         0x20, 0x4a, 0x20, 0x4b, 0x20, 0x4c, 0x20, 0x4d,
1852                         0x20, 0x4e, 0x20, 0x4f, 0x20, 0x50, 0x20, 0x51,
1853                         0x20, 0x52, 0x20, 0x53, 0x20, 0x54, 0x20, 0x55,
1854                         0x20, 0x56, 0x20, 0x57, 0x20, 0x58, 0x20, 0x59,
1855                         0x20, 0x5a, 0x20, 0x5b, 0x20, 0x5c, 0x20, 0x5d,
1856                         0x20, 0x5e, 0x20, 0x5f, 0x20, 0x60, 0x20, 0x61,
1857                         0x20, 0x62, 0x20, 0x63, 0x20, 0x64, 0x20, 0x65,
1858                         0x20, 0x66, 0x20, 0x67, 0x20, 0x68, 0x20, 0x69,
1859                         0x20, 0x6a, 0x20, 0x6b, 0x20, 0x6c, 0x20, 0x6d,
1860                         0x20, 0x6e, 0x20, 0x6f, 0x20, 0x70, 0x20, 0x71,
1861                         0x20, 0x72, 0x20, 0x73, 0x20, 0x74, 0x20, 0x00 };
1862 static const char add_uuid32_param_1[] = {
1863                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1864                         0x00, 0x10, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12,
1865                         0x00 };
1866 static const char add_uuid32_param_2[] = {
1867                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1868                         0x00, 0x10, 0x00, 0x00, 0xef, 0xcd, 0xbc, 0x9a,
1869                         0x00 };
1870 static const char add_uuid32_param_3[] = {
1871                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1872                         0x00, 0x10, 0x00, 0x00, 0xff, 0xee, 0xdd, 0xcc,
1873                         0x00 };
1874 static const char add_uuid32_param_4[] = {
1875                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1876                         0x00, 0x10, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44,
1877                         0x00 };
1878 static const char write_eir_uuid32_hci[241] = { 0x00,
1879                         0x02, 0x0a, 0x00, 0x05, 0x05, 0x78, 0x56, 0x34,
1880                         0x12 };
1881 static const char write_eir_uuid32_multi_hci[241] = { 0x00,
1882                         0x02, 0x0a, 0x00, 0x11, 0x05, 0x78, 0x56, 0x34,
1883                         0x12, 0xef, 0xcd, 0xbc, 0x9a, 0xff, 0xee, 0xdd,
1884                         0xcc, 0x11, 0x22, 0x33, 0x44 };
1885 static const char write_eir_uuid32_multi_hci_2[] = { 0x00,
1886                         0x02, 0x0a, 0x00, 0xe9, 0x04, 0xff, 0xff, 0xff,
1887                         0xff, 0xfe, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff,
1888                         0xff, 0xfc, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff,
1889                         0xff, 0xfa, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff,
1890                         0xff, 0xf8, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff,
1891                         0xff, 0xf6, 0xff, 0xff, 0xff, 0xf5, 0xff, 0xff,
1892                         0xff, 0xf4, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff,
1893                         0xff, 0xf2, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff,
1894                         0xff, 0xf0, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff,
1895                         0xff, 0xee, 0xff, 0xff, 0xff, 0xed, 0xff, 0xff,
1896                         0xff, 0xec, 0xff, 0xff, 0xff, 0xeb, 0xff, 0xff,
1897                         0xff, 0xea, 0xff, 0xff, 0xff, 0xe9, 0xff, 0xff,
1898                         0xff, 0xe8, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff,
1899                         0xff, 0xe6, 0xff, 0xff, 0xff, 0xe5, 0xff, 0xff,
1900                         0xff, 0xe4, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff,
1901                         0xff, 0xe2, 0xff, 0xff, 0xff, 0xe1, 0xff, 0xff,
1902                         0xff, 0xe0, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff,
1903                         0xff, 0xde, 0xff, 0xff, 0xff, 0xdd, 0xff, 0xff,
1904                         0xff, 0xdc, 0xff, 0xff, 0xff, 0xdb, 0xff, 0xff,
1905                         0xff, 0xda, 0xff, 0xff, 0xff, 0xd9, 0xff, 0xff,
1906                         0xff, 0xd8, 0xff, 0xff, 0xff, 0xd7, 0xff, 0xff,
1907                         0xff, 0xd6, 0xff, 0xff, 0xff, 0xd5, 0xff, 0xff,
1908                         0xff, 0xd4, 0xff, 0xff, 0xff, 0xd3, 0xff, 0xff,
1909                         0xff, 0xd2, 0xff, 0xff, 0xff, 0xd1, 0xff, 0xff,
1910                         0xff, 0xd0, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff,
1911                         0xff, 0xce, 0xff, 0xff, 0xff, 0xcd, 0xff, 0xff,
1912                         0xff, 0xcc, 0xff, 0xff, 0xff, 0xcb, 0xff, 0xff,
1913                         0xff, 0xca, 0xff, 0xff, 0xff, 0xc9, 0xff, 0xff,
1914                         0xff, 0xc8, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff,
1915                         0xff, 0xc6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 };
1916 static const char add_uuid128_param_1[] = {
1917                         0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
1918                         0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
1919                         0x00 };
1920 static const char add_uuid128_param_2[] = {
1921                         0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
1922                         0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
1923                         0x00 };
1924 static const char write_eir_uuid128_hci[241] = { 0x00,
1925                         0x02, 0x0a, 0x00, 0x11, 0x07, 0x00, 0x11, 0x22,
1926                         0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
1927                         0xbb, 0xcc, 0xdd, 0xee, 0xff };
1928 static const char write_eir_uuid128_multi_hci[241] = { 0x00,
1929                         0x02, 0x0a, 0x00, 0x21, 0x07, 0x00, 0x11, 0x22,
1930                         0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
1931                         0xbb, 0xcc, 0xdd, 0xee, 0xff, 0xff, 0xee, 0xdd,
1932                         0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55,
1933                         0x44, 0x33, 0x22, 0x11 };
1934 static const char write_eir_uuid128_multi_hci_2[] = { 0x00,
1935                         0x02, 0x0a, 0x00, 0xe1, 0x07, 0x11, 0x22, 0x33,
1936                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1937                         0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33,
1938                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1939                         0xcc, 0xdd, 0xee, 0xff, 0x01, 0x11, 0x22, 0x33,
1940                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1941                         0xcc, 0xdd, 0xee, 0xff, 0x02, 0x11, 0x22, 0x33,
1942                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1943                         0xcc, 0xdd, 0xee, 0xff, 0x03, 0x11, 0x22, 0x33,
1944                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1945                         0xcc, 0xdd, 0xee, 0xff, 0x04, 0x11, 0x22, 0x33,
1946                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1947                         0xcc, 0xdd, 0xee, 0xff, 0x05, 0x11, 0x22, 0x33,
1948                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1949                         0xcc, 0xdd, 0xee, 0xff, 0x06, 0x11, 0x22, 0x33,
1950                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1951                         0xcc, 0xdd, 0xee, 0xff, 0x07, 0x11, 0x22, 0x33,
1952                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1953                         0xcc, 0xdd, 0xee, 0xff, 0x08, 0x11, 0x22, 0x33,
1954                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1955                         0xcc, 0xdd, 0xee, 0xff, 0x09, 0x11, 0x22, 0x33,
1956                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1957                         0xcc, 0xdd, 0xee, 0xff, 0x0a, 0x11, 0x22, 0x33,
1958                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1959                         0xcc, 0xdd, 0xee, 0xff, 0x0b, 0x11, 0x22, 0x33,
1960                         0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
1961                         0xcc, 0xdd, 0xee, 0xff, 0x0c, 0xff, 0xee, 0xdd,
1962                         0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55,
1963                         0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x00, 0x00,
1964                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1965 static const char write_eir_uuid_mix_hci[241] = { 0x00,
1966                         0x02, 0x0a, 0x00, 0x05, 0x03, 0x01, 0x11, 0x03,
1967                         0x11, 0x09, 0x05, 0x78, 0x56, 0x34, 0x12, 0xef,
1968                         0xcd, 0xbc, 0x9a, 0x21, 0x07, 0x00, 0x11, 0x22,
1969                         0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
1970                         0xbb, 0xcc, 0xdd, 0xee, 0xff, 0xff, 0xee, 0xdd,
1971                         0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55,
1972                         0x44, 0x33, 0x22, 0x11 };
1973
1974 static const struct generic_data add_uuid16_test_1 = {
1975         .setup_settings = settings_powered_ssp,
1976         .send_opcode = MGMT_OP_ADD_UUID,
1977         .send_param = add_spp_uuid_param,
1978         .send_len = sizeof(add_spp_uuid_param),
1979         .expect_status = MGMT_STATUS_SUCCESS,
1980         .expect_param = set_dev_class_zero_rsp,
1981         .expect_len = sizeof(set_dev_class_zero_rsp),
1982         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
1983         .expect_hci_param = write_eir_uuid16_hci,
1984         .expect_hci_len = sizeof(write_eir_uuid16_hci),
1985 };
1986
1987 static const struct generic_data add_multi_uuid16_test_1 = {
1988         .send_opcode = MGMT_OP_ADD_UUID,
1989         .send_param = add_opp_uuid_param,
1990         .send_len = sizeof(add_opp_uuid_param),
1991         .expect_status = MGMT_STATUS_SUCCESS,
1992         .expect_param = set_dev_class_zero_rsp,
1993         .expect_len = sizeof(set_dev_class_zero_rsp),
1994         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
1995         .expect_hci_param = write_eir_multi_uuid16_hci_1,
1996         .expect_hci_len = sizeof(write_eir_multi_uuid16_hci_1),
1997 };
1998
1999 static const struct generic_data add_multi_uuid16_test_2 = {
2000         .send_opcode = MGMT_OP_ADD_UUID,
2001         .send_param = add_opp_uuid_param,
2002         .send_len = sizeof(add_opp_uuid_param),
2003         .expect_status = MGMT_STATUS_SUCCESS,
2004         .expect_param = set_dev_class_zero_rsp,
2005         .expect_len = sizeof(set_dev_class_zero_rsp),
2006         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2007         .expect_hci_param = write_eir_multi_uuid16_hci_2,
2008         .expect_hci_len = sizeof(write_eir_multi_uuid16_hci_2),
2009 };
2010
2011 static const struct generic_data add_uuid32_test_1 = {
2012         .setup_settings = settings_powered_ssp,
2013         .send_opcode = MGMT_OP_ADD_UUID,
2014         .send_param = add_uuid32_param_1,
2015         .send_len = sizeof(add_uuid32_param_1),
2016         .expect_status = MGMT_STATUS_SUCCESS,
2017         .expect_param = set_dev_class_zero_rsp,
2018         .expect_len = sizeof(set_dev_class_zero_rsp),
2019         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2020         .expect_hci_param = write_eir_uuid32_hci,
2021         .expect_hci_len = sizeof(write_eir_uuid32_hci),
2022 };
2023
2024 static const struct generic_data add_uuid32_multi_test_1 = {
2025         .send_opcode = MGMT_OP_ADD_UUID,
2026         .send_param = add_uuid32_param_4,
2027         .send_len = sizeof(add_uuid32_param_4),
2028         .expect_status = MGMT_STATUS_SUCCESS,
2029         .expect_param = set_dev_class_zero_rsp,
2030         .expect_len = sizeof(set_dev_class_zero_rsp),
2031         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2032         .expect_hci_param = write_eir_uuid32_multi_hci,
2033         .expect_hci_len = sizeof(write_eir_uuid32_multi_hci),
2034 };
2035
2036 static const struct generic_data add_uuid32_multi_test_2 = {
2037         .send_opcode = MGMT_OP_ADD_UUID,
2038         .send_param = add_uuid32_param_4,
2039         .send_len = sizeof(add_uuid32_param_4),
2040         .expect_status = MGMT_STATUS_SUCCESS,
2041         .expect_param = set_dev_class_zero_rsp,
2042         .expect_len = sizeof(set_dev_class_zero_rsp),
2043         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2044         .expect_hci_param = write_eir_uuid32_multi_hci_2,
2045         .expect_hci_len = sizeof(write_eir_uuid32_multi_hci_2),
2046 };
2047
2048 static const struct generic_data add_uuid128_test_1 = {
2049         .setup_settings = settings_powered_ssp,
2050         .send_opcode = MGMT_OP_ADD_UUID,
2051         .send_param = add_uuid128_param_1,
2052         .send_len = sizeof(add_uuid128_param_1),
2053         .expect_status = MGMT_STATUS_SUCCESS,
2054         .expect_param = set_dev_class_zero_rsp,
2055         .expect_len = sizeof(set_dev_class_zero_rsp),
2056         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2057         .expect_hci_param = write_eir_uuid128_hci,
2058         .expect_hci_len = sizeof(write_eir_uuid128_hci),
2059 };
2060
2061 static const struct generic_data add_uuid128_multi_test_1 = {
2062         .send_opcode = MGMT_OP_ADD_UUID,
2063         .send_param = add_uuid128_param_2,
2064         .send_len = sizeof(add_uuid32_param_2),
2065         .expect_status = MGMT_STATUS_SUCCESS,
2066         .expect_param = set_dev_class_zero_rsp,
2067         .expect_len = sizeof(set_dev_class_zero_rsp),
2068         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2069         .expect_hci_param = write_eir_uuid128_multi_hci,
2070         .expect_hci_len = sizeof(write_eir_uuid128_multi_hci),
2071 };
2072
2073 static const struct generic_data add_uuid128_multi_test_2 = {
2074         .send_opcode = MGMT_OP_ADD_UUID,
2075         .send_param = add_uuid128_param_2,
2076         .send_len = sizeof(add_uuid128_param_2),
2077         .expect_status = MGMT_STATUS_SUCCESS,
2078         .expect_param = set_dev_class_zero_rsp,
2079         .expect_len = sizeof(set_dev_class_zero_rsp),
2080         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2081         .expect_hci_param = write_eir_uuid128_multi_hci_2,
2082         .expect_hci_len = sizeof(write_eir_uuid128_multi_hci_2),
2083 };
2084
2085 static const struct generic_data add_uuid_mix_test_1 = {
2086         .send_opcode = MGMT_OP_ADD_UUID,
2087         .send_param = add_uuid128_param_2,
2088         .send_len = sizeof(add_uuid128_param_2),
2089         .expect_status = MGMT_STATUS_SUCCESS,
2090         .expect_param = set_dev_class_zero_rsp,
2091         .expect_len = sizeof(set_dev_class_zero_rsp),
2092         .expect_hci_command = BT_HCI_CMD_WRITE_EXT_INQUIRY_RESPONSE,
2093         .expect_hci_param = write_eir_uuid_mix_hci,
2094         .expect_hci_len = sizeof(write_eir_uuid_mix_hci),
2095 };
2096
2097 static const char load_link_keys_valid_param_1[] = { 0x00, 0x00, 0x00 };
2098 static const char load_link_keys_valid_param_2[] = { 0x01, 0x00, 0x00 };
2099 static const char load_link_keys_invalid_param_1[] = { 0x02, 0x00, 0x00 };
2100 static const char load_link_keys_invalid_param_2[] = { 0x00, 0x01, 0x00 };
2101 /* Invalid bdaddr type */
2102 static const char load_link_keys_invalid_param_3[] = { 0x00, 0x01, 0x00,
2103         0x00, 0x01, 0x02, 0x03, 0x04, 0x05,             /* addr */
2104         0x01,                                           /* addr type */
2105         0x00,                                           /* key type */
2106         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* value (1/2) */
2107         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* value (2/2) */
2108         0x04,                                           /* PIN length */
2109 };
2110
2111 static const struct generic_data load_link_keys_success_test_1 = {
2112         .send_opcode = MGMT_OP_LOAD_LINK_KEYS,
2113         .send_param = load_link_keys_valid_param_1,
2114         .send_len = sizeof(load_link_keys_valid_param_1),
2115         .expect_status = MGMT_STATUS_SUCCESS,
2116 };
2117
2118 static const struct generic_data load_link_keys_success_test_2 = {
2119         .send_opcode = MGMT_OP_LOAD_LINK_KEYS,
2120         .send_param = load_link_keys_valid_param_2,
2121         .send_len = sizeof(load_link_keys_valid_param_2),
2122         .expect_status = MGMT_STATUS_SUCCESS,
2123 };
2124
2125 static const struct generic_data load_link_keys_invalid_params_test_1 = {
2126         .send_opcode = MGMT_OP_LOAD_LINK_KEYS,
2127         .send_param = load_link_keys_invalid_param_1,
2128         .send_len = sizeof(load_link_keys_invalid_param_1),
2129         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2130 };
2131
2132 static const struct generic_data load_link_keys_invalid_params_test_2 = {
2133         .send_opcode = MGMT_OP_LOAD_LINK_KEYS,
2134         .send_param = load_link_keys_invalid_param_2,
2135         .send_len = sizeof(load_link_keys_invalid_param_2),
2136         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2137 };
2138
2139 static const struct generic_data load_link_keys_invalid_params_test_3 = {
2140         .send_opcode = MGMT_OP_LOAD_LINK_KEYS,
2141         .send_param = load_link_keys_invalid_param_3,
2142         .send_len = sizeof(load_link_keys_invalid_param_3),
2143         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2144 };
2145
2146 static const char load_ltks_valid_param_1[] = { 0x00, 0x00 };
2147 /* Invalid key count */
2148 static const char load_ltks_invalid_param_1[] = { 0x01, 0x00 };
2149 /* Invalid addr type */
2150 static const char load_ltks_invalid_param_2[] = {
2151         0x01, 0x00,                                     /* count */
2152         0x00, 0x01, 0x02, 0x03, 0x04, 0x05,             /* bdaddr */
2153         0x00,                                           /* addr type */
2154         0x00,                                           /* authenticated */
2155         0x00,                                           /* master */
2156         0x00,                                           /* encryption size */
2157         0x00, 0x00,                                     /* diversifier */
2158         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* rand */
2159         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* value (1/2) */
2160         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* value (2/2) */
2161 };
2162 /* Invalid master value */
2163 static const char load_ltks_invalid_param_3[] = {
2164         0x01, 0x00,                                     /* count */
2165         0x00, 0x01, 0x02, 0x03, 0x04, 0x05,             /* bdaddr */
2166         0x01,                                           /* addr type */
2167         0x00,                                           /* authenticated */
2168         0x02,                                           /* master */
2169         0x00,                                           /* encryption size */
2170         0x00, 0x00,                                     /* diversifier */
2171         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* rand */
2172         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* value (1/2) */
2173         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* value (2/2) */
2174 };
2175
2176 static const struct generic_data load_ltks_success_test_1 = {
2177         .send_opcode = MGMT_OP_LOAD_LONG_TERM_KEYS,
2178         .send_param = load_ltks_valid_param_1,
2179         .send_len = sizeof(load_ltks_valid_param_1),
2180         .expect_status = MGMT_STATUS_SUCCESS,
2181 };
2182
2183 static const struct generic_data load_ltks_invalid_params_test_1 = {
2184         .send_opcode = MGMT_OP_LOAD_LONG_TERM_KEYS,
2185         .send_param = load_ltks_invalid_param_1,
2186         .send_len = sizeof(load_ltks_invalid_param_1),
2187         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2188 };
2189
2190 static const struct generic_data load_ltks_invalid_params_test_2 = {
2191         .send_opcode = MGMT_OP_LOAD_LONG_TERM_KEYS,
2192         .send_param = load_ltks_invalid_param_2,
2193         .send_len = sizeof(load_ltks_invalid_param_2),
2194         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2195 };
2196
2197 static const struct generic_data load_ltks_invalid_params_test_3 = {
2198         .send_opcode = MGMT_OP_LOAD_LONG_TERM_KEYS,
2199         .send_param = load_ltks_invalid_param_3,
2200         .send_len = sizeof(load_ltks_invalid_param_3),
2201         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2202 };
2203
2204 static const char pair_device_param[] = {
2205                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00 };
2206 static const char pair_device_rsp[] = {
2207                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
2208 static const char pair_device_invalid_param_1[] = {
2209                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff, 0x00 };
2210 static const char pair_device_invalid_param_rsp_1[] = {
2211                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2212
2213 static const struct generic_data pair_device_not_powered_test_1 = {
2214         .send_opcode = MGMT_OP_PAIR_DEVICE,
2215         .send_param = pair_device_param,
2216         .send_len = sizeof(pair_device_param),
2217         .expect_status = MGMT_STATUS_NOT_POWERED,
2218         .expect_param = pair_device_rsp,
2219         .expect_len = sizeof(pair_device_rsp),
2220 };
2221
2222 static const struct generic_data pair_device_invalid_param_test_1 = {
2223         .send_opcode = MGMT_OP_PAIR_DEVICE,
2224         .send_param = pair_device_invalid_param_1,
2225         .send_len = sizeof(pair_device_invalid_param_1),
2226         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2227         .expect_param = pair_device_invalid_param_rsp_1,
2228         .expect_len = sizeof(pair_device_invalid_param_rsp_1),
2229 };
2230
2231 static const void *pair_device_send_param_func(uint16_t *len)
2232 {
2233         struct test_data *data = tester_get_data();
2234         const struct generic_data *test = data->test_data;
2235         static uint8_t param[8];
2236
2237         memcpy(param, hciemu_get_client_bdaddr(data->hciemu), 6);
2238         param[6] = 0x00; /* Address type */
2239         param[7] = test->io_cap;
2240
2241         *len = sizeof(param);
2242
2243         return param;
2244 }
2245
2246 static const void *pair_device_expect_param_func(uint16_t *len)
2247 {
2248         struct test_data *data = tester_get_data();
2249         static uint8_t param[7];
2250
2251         memcpy(param, hciemu_get_client_bdaddr(data->hciemu), 6);
2252         param[6] = 0x00; /* Address type */
2253
2254         *len = sizeof(param);
2255
2256         return param;
2257 }
2258
2259 static uint16_t settings_powered_pairable[] = { MGMT_OP_SET_PAIRABLE,
2260                                                 MGMT_OP_SET_POWERED, 0 };
2261 static uint8_t auth_req_param[] = { 0x2a, 0x00 };
2262 static uint8_t pair_device_pin[] = { 0x30, 0x30, 0x30, 0x30 }; /* "0000" */
2263
2264 static const struct generic_data pair_device_success_test_1 = {
2265         .setup_settings = settings_powered_pairable,
2266         .send_opcode = MGMT_OP_PAIR_DEVICE,
2267         .send_func = pair_device_send_param_func,
2268         .expect_status = MGMT_STATUS_SUCCESS,
2269         .expect_func = pair_device_expect_param_func,
2270         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2271         .expect_alt_ev_len = 26,
2272         .expect_hci_command = BT_HCI_CMD_AUTH_REQUESTED,
2273         .expect_hci_param = auth_req_param,
2274         .expect_hci_len = sizeof(auth_req_param),
2275         .pin = pair_device_pin,
2276         .pin_len = sizeof(pair_device_pin),
2277         .client_pin = pair_device_pin,
2278         .client_pin_len = sizeof(pair_device_pin),
2279 };
2280
2281 static uint16_t settings_powered_pairable_linksec[] = { MGMT_OP_SET_PAIRABLE,
2282                                                         MGMT_OP_SET_POWERED,
2283                                                         MGMT_OP_SET_LINK_SECURITY,
2284                                                         0 };
2285
2286 static const struct generic_data pair_device_success_test_2 = {
2287         .setup_settings = settings_powered_pairable_linksec,
2288         .send_opcode = MGMT_OP_PAIR_DEVICE,
2289         .send_func = pair_device_send_param_func,
2290         .expect_status = MGMT_STATUS_SUCCESS,
2291         .expect_func = pair_device_expect_param_func,
2292         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2293         .expect_alt_ev_len = 26,
2294         .expect_hci_command = BT_HCI_CMD_AUTH_REQUESTED,
2295         .expect_hci_param = auth_req_param,
2296         .expect_hci_len = sizeof(auth_req_param),
2297         .pin = pair_device_pin,
2298         .pin_len = sizeof(pair_device_pin),
2299         .client_pin = pair_device_pin,
2300         .client_pin_len = sizeof(pair_device_pin),
2301 };
2302
2303 static const void *client_bdaddr_param_func(uint8_t *len)
2304 {
2305         struct test_data *data = tester_get_data();
2306         static uint8_t bdaddr[6];
2307
2308         memcpy(bdaddr, hciemu_get_client_bdaddr(data->hciemu), 6);
2309
2310         *len = sizeof(bdaddr);
2311
2312         return bdaddr;
2313 }
2314
2315 static const struct generic_data pair_device_reject_test_1 = {
2316         .setup_settings = settings_powered_pairable,
2317         .send_opcode = MGMT_OP_PAIR_DEVICE,
2318         .send_func = pair_device_send_param_func,
2319         .expect_status = MGMT_STATUS_AUTH_FAILED,
2320         .expect_func = pair_device_expect_param_func,
2321         .expect_alt_ev = MGMT_EV_AUTH_FAILED,
2322         .expect_alt_ev_len = 8,
2323         .expect_hci_command = BT_HCI_CMD_PIN_CODE_REQUEST_NEG_REPLY,
2324         .expect_hci_func = client_bdaddr_param_func,
2325         .expect_pin = true,
2326         .client_pin = pair_device_pin,
2327         .client_pin_len = sizeof(pair_device_pin),
2328 };
2329
2330 static const struct generic_data pair_device_reject_test_2 = {
2331         .setup_settings = settings_powered_pairable,
2332         .send_opcode = MGMT_OP_PAIR_DEVICE,
2333         .send_func = pair_device_send_param_func,
2334         .expect_status = MGMT_STATUS_AUTH_FAILED,
2335         .expect_func = pair_device_expect_param_func,
2336         .expect_alt_ev = MGMT_EV_AUTH_FAILED,
2337         .expect_alt_ev_len = 8,
2338         .expect_hci_command = BT_HCI_CMD_AUTH_REQUESTED,
2339         .expect_hci_param = auth_req_param,
2340         .expect_hci_len = sizeof(auth_req_param),
2341         .pin = pair_device_pin,
2342         .pin_len = sizeof(pair_device_pin),
2343 };
2344
2345 static const struct generic_data pair_device_reject_test_3 = {
2346         .setup_settings = settings_powered_pairable_linksec,
2347         .send_opcode = MGMT_OP_PAIR_DEVICE,
2348         .send_func = pair_device_send_param_func,
2349         .expect_status = MGMT_STATUS_AUTH_FAILED,
2350         .expect_func = pair_device_expect_param_func,
2351         .expect_hci_command = BT_HCI_CMD_PIN_CODE_REQUEST_NEG_REPLY,
2352         .expect_hci_func = client_bdaddr_param_func,
2353         .expect_pin = true,
2354         .client_pin = pair_device_pin,
2355         .client_pin_len = sizeof(pair_device_pin),
2356 };
2357
2358 static const struct generic_data pair_device_reject_test_4 = {
2359         .setup_settings = settings_powered_pairable_linksec,
2360         .send_opcode = MGMT_OP_PAIR_DEVICE,
2361         .send_func = pair_device_send_param_func,
2362         .expect_status = MGMT_STATUS_AUTH_FAILED,
2363         .expect_func = pair_device_expect_param_func,
2364         .pin = pair_device_pin,
2365         .pin_len = sizeof(pair_device_pin),
2366 };
2367
2368 static uint16_t settings_powered_pairable_ssp[] = {     MGMT_OP_SET_PAIRABLE,
2369                                                         MGMT_OP_SET_SSP,
2370                                                         MGMT_OP_SET_POWERED,
2371                                                         0 };
2372
2373 static const struct generic_data pair_device_ssp_test_1 = {
2374         .setup_settings = settings_powered_pairable_ssp,
2375         .client_enable_ssp = true,
2376         .send_opcode = MGMT_OP_PAIR_DEVICE,
2377         .send_func = pair_device_send_param_func,
2378         .expect_status = MGMT_STATUS_SUCCESS,
2379         .expect_func = pair_device_expect_param_func,
2380         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2381         .expect_alt_ev_len = 26,
2382         .expect_hci_command = BT_HCI_CMD_USER_CONFIRM_REQUEST_REPLY,
2383         .expect_hci_func = client_bdaddr_param_func,
2384         .io_cap = 0x03, /* NoInputNoOutput */
2385         .client_io_cap = 0x03, /* NoInputNoOutput */
2386 };
2387
2388 static const struct generic_data pair_device_ssp_test_2 = {
2389         .setup_settings = settings_powered_pairable_ssp,
2390         .client_enable_ssp = true,
2391         .send_opcode = MGMT_OP_PAIR_DEVICE,
2392         .send_func = pair_device_send_param_func,
2393         .expect_status = MGMT_STATUS_SUCCESS,
2394         .expect_func = pair_device_expect_param_func,
2395         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2396         .expect_alt_ev_len = 26,
2397         .expect_hci_command = BT_HCI_CMD_USER_CONFIRM_REQUEST_REPLY,
2398         .expect_hci_func = client_bdaddr_param_func,
2399         .io_cap = 0x01, /* DisplayYesNo */
2400         .client_io_cap = 0x01, /* DisplayYesNo */
2401 };
2402
2403 static const struct generic_data pair_device_ssp_reject_1 = {
2404         .setup_settings = settings_powered_pairable_ssp,
2405         .client_enable_ssp = true,
2406         .send_opcode = MGMT_OP_PAIR_DEVICE,
2407         .send_func = pair_device_send_param_func,
2408         .expect_status = MGMT_STATUS_AUTH_FAILED,
2409         .expect_func = pair_device_expect_param_func,
2410         .expect_alt_ev = MGMT_EV_AUTH_FAILED,
2411         .expect_alt_ev_len = 8,
2412         .expect_hci_command = BT_HCI_CMD_USER_CONFIRM_REQUEST_NEG_REPLY,
2413         .expect_hci_func = client_bdaddr_param_func,
2414         .io_cap = 0x01, /* DisplayYesNo */
2415         .client_io_cap = 0x01, /* DisplayYesNo */
2416         .reject_ssp = true,
2417 };
2418
2419 static const struct generic_data pair_device_ssp_reject_2 = {
2420         .setup_settings = settings_powered_pairable_ssp,
2421         .client_enable_ssp = true,
2422         .send_opcode = MGMT_OP_PAIR_DEVICE,
2423         .send_func = pair_device_send_param_func,
2424         .expect_status = MGMT_STATUS_AUTH_FAILED,
2425         .expect_func = pair_device_expect_param_func,
2426         .expect_alt_ev = MGMT_EV_AUTH_FAILED,
2427         .expect_alt_ev_len = 8,
2428         .expect_hci_command = BT_HCI_CMD_USER_CONFIRM_REQUEST_REPLY,
2429         .expect_hci_func = client_bdaddr_param_func,
2430         .io_cap = 0x01, /* DisplayYesNo */
2431         .client_io_cap = 0x01, /* DisplayYesNo */
2432         .client_reject_ssp = true,
2433 };
2434
2435 static const struct generic_data pair_device_ssp_nonpairable_1 = {
2436         .setup_settings = settings_powered_ssp,
2437         .client_enable_ssp = true,
2438         .send_opcode = MGMT_OP_PAIR_DEVICE,
2439         .send_func = pair_device_send_param_func,
2440         .expect_status = MGMT_STATUS_AUTH_FAILED,
2441         .expect_func = pair_device_expect_param_func,
2442         .expect_alt_ev = MGMT_EV_AUTH_FAILED,
2443         .expect_alt_ev_len = 8,
2444         .io_cap = 0x01, /* DisplayYesNo */
2445         .client_io_cap = 0x01, /* DisplayYesNo */
2446 };
2447
2448 static uint16_t settings_powered_connectable_pairable[] = {
2449                                                 MGMT_OP_SET_PAIRABLE,
2450                                                 MGMT_OP_SET_CONNECTABLE,
2451                                                 MGMT_OP_SET_POWERED, 0 };
2452
2453 static const struct generic_data pairing_acceptor_legacy_1 = {
2454         .setup_settings = settings_powered_connectable_pairable,
2455         .pin = pair_device_pin,
2456         .pin_len = sizeof(pair_device_pin),
2457         .client_pin = pair_device_pin,
2458         .client_pin_len = sizeof(pair_device_pin),
2459         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2460         .expect_alt_ev_len = 26,
2461 };
2462
2463 static const struct generic_data pairing_acceptor_legacy_2 = {
2464         .setup_settings = settings_powered_connectable_pairable,
2465         .expect_pin = true,
2466         .client_pin = pair_device_pin,
2467         .client_pin_len = sizeof(pair_device_pin),
2468         .expect_alt_ev = MGMT_EV_AUTH_FAILED,
2469         .expect_alt_ev_len = 8,
2470 };
2471
2472 static uint16_t settings_powered_connectable_pairable_linksec[] = {
2473                                                 MGMT_OP_SET_PAIRABLE,
2474                                                 MGMT_OP_SET_CONNECTABLE,
2475                                                 MGMT_OP_SET_LINK_SECURITY,
2476                                                 MGMT_OP_SET_POWERED, 0 };
2477
2478 static const struct generic_data pairing_acceptor_linksec_1 = {
2479         .setup_settings = settings_powered_connectable_pairable_linksec,
2480         .pin = pair_device_pin,
2481         .pin_len = sizeof(pair_device_pin),
2482         .client_pin = pair_device_pin,
2483         .client_pin_len = sizeof(pair_device_pin),
2484         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2485         .expect_alt_ev_len = 26,
2486 };
2487
2488 static const struct generic_data pairing_acceptor_linksec_2 = {
2489         .setup_settings = settings_powered_connectable_pairable_linksec,
2490         .expect_pin = true,
2491         .client_pin = pair_device_pin,
2492         .client_pin_len = sizeof(pair_device_pin),
2493         .expect_alt_ev = MGMT_EV_CONNECT_FAILED,
2494         .expect_alt_ev_len = 8,
2495 };
2496
2497 static uint16_t settings_powered_connectable_pairable_ssp[] = {
2498                                                 MGMT_OP_SET_PAIRABLE,
2499                                                 MGMT_OP_SET_CONNECTABLE,
2500                                                 MGMT_OP_SET_SSP,
2501                                                 MGMT_OP_SET_POWERED, 0 };
2502
2503 static const struct generic_data pairing_acceptor_ssp_1 = {
2504         .setup_settings = settings_powered_connectable_pairable_ssp,
2505         .client_enable_ssp = true,
2506         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2507         .expect_alt_ev_len = 26,
2508         .expect_hci_command = BT_HCI_CMD_USER_CONFIRM_REQUEST_REPLY,
2509         .expect_hci_func = client_bdaddr_param_func,
2510         .io_cap = 0x03, /* NoInputNoOutput */
2511         .client_io_cap = 0x03, /* NoInputNoOutput */
2512 };
2513
2514 static const struct generic_data pairing_acceptor_ssp_2 = {
2515         .setup_settings = settings_powered_connectable_pairable_ssp,
2516         .client_enable_ssp = true,
2517         .expect_alt_ev = MGMT_EV_NEW_LINK_KEY,
2518         .expect_alt_ev_len = 26,
2519         .expect_hci_command = BT_HCI_CMD_USER_CONFIRM_REQUEST_REPLY,
2520         .expect_hci_func = client_bdaddr_param_func,
2521         .io_cap = 0x01, /* DisplayYesNo */
2522         .client_io_cap = 0x01, /* DisplayYesNo */
2523 };
2524
2525 static const char unpair_device_param[] = {
2526                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00 };
2527 static const char unpair_device_rsp[] = {
2528                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
2529 static const char unpair_device_invalid_param_1[] = {
2530                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff, 0x00 };
2531 static const char unpair_device_invalid_param_rsp_1[] = {
2532                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2533 static const char unpair_device_invalid_param_2[] = {
2534                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x02 };
2535 static const char unpair_device_invalid_param_rsp_2[] = {
2536                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
2537
2538 static const struct generic_data unpair_device_not_powered_test_1 = {
2539         .send_opcode = MGMT_OP_UNPAIR_DEVICE,
2540         .send_param = unpair_device_param,
2541         .send_len = sizeof(unpair_device_param),
2542         .expect_status = MGMT_STATUS_NOT_POWERED,
2543         .expect_param = unpair_device_rsp,
2544         .expect_len = sizeof(unpair_device_rsp),
2545 };
2546
2547 static const struct generic_data unpair_device_invalid_param_test_1 = {
2548         .send_opcode = MGMT_OP_UNPAIR_DEVICE,
2549         .send_param = unpair_device_invalid_param_1,
2550         .send_len = sizeof(unpair_device_invalid_param_1),
2551         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2552         .expect_param = unpair_device_invalid_param_rsp_1,
2553         .expect_len = sizeof(unpair_device_invalid_param_rsp_1),
2554 };
2555
2556 static const struct generic_data unpair_device_invalid_param_test_2 = {
2557         .send_opcode = MGMT_OP_UNPAIR_DEVICE,
2558         .send_param = unpair_device_invalid_param_2,
2559         .send_len = sizeof(unpair_device_invalid_param_2),
2560         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2561         .expect_param = unpair_device_invalid_param_rsp_2,
2562         .expect_len = sizeof(unpair_device_invalid_param_rsp_2),
2563 };
2564
2565 static const char disconnect_invalid_param_1[] = {
2566                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2567 static const char disconnect_invalid_param_rsp_1[] = {
2568                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2569
2570 static const struct generic_data disconnect_invalid_param_test_1 = {
2571         .send_opcode = MGMT_OP_DISCONNECT,
2572         .send_param = disconnect_invalid_param_1,
2573         .send_len = sizeof(disconnect_invalid_param_1),
2574         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2575         .expect_param = disconnect_invalid_param_rsp_1,
2576         .expect_len = sizeof(disconnect_invalid_param_rsp_1),
2577 };
2578
2579 static const char block_device_invalid_param_1[] = {
2580                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2581 static const char block_device_invalid_param_rsp_1[] = {
2582                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2583
2584 static const struct generic_data block_device_invalid_param_test_1 = {
2585         .send_opcode = MGMT_OP_BLOCK_DEVICE,
2586         .send_param = block_device_invalid_param_1,
2587         .send_len = sizeof(block_device_invalid_param_1),
2588         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2589         .expect_param = block_device_invalid_param_rsp_1,
2590         .expect_len = sizeof(block_device_invalid_param_rsp_1),
2591 };
2592
2593 static const char unblock_device_invalid_param_1[] = {
2594                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2595 static const char unblock_device_invalid_param_rsp_1[] = {
2596                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff };
2597
2598 static const struct generic_data unblock_device_invalid_param_test_1 = {
2599         .send_opcode = MGMT_OP_UNBLOCK_DEVICE,
2600         .send_param = unblock_device_invalid_param_1,
2601         .send_len = sizeof(unblock_device_invalid_param_1),
2602         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2603         .expect_param = unblock_device_invalid_param_rsp_1,
2604         .expect_len = sizeof(unblock_device_invalid_param_rsp_1),
2605 };
2606
2607 static const char set_static_addr_valid_param[] = {
2608                         0x11, 0x22, 0x33, 0x44, 0x55, 0xc0 };
2609
2610 static const struct generic_data set_static_addr_success_test = {
2611         .send_opcode = MGMT_OP_SET_STATIC_ADDRESS,
2612         .send_param = set_static_addr_valid_param,
2613         .send_len = sizeof(set_static_addr_valid_param),
2614         .expect_status = MGMT_STATUS_SUCCESS,
2615 };
2616
2617 static const struct generic_data set_static_addr_failure_test = {
2618         .setup_settings = settings_powered,
2619         .send_opcode = MGMT_OP_SET_STATIC_ADDRESS,
2620         .send_param = set_static_addr_valid_param,
2621         .send_len = sizeof(set_static_addr_valid_param),
2622         .expect_status = MGMT_STATUS_REJECTED,
2623 };
2624
2625 static const char set_scan_params_valid_param[] = { 0x60, 0x00, 0x30, 0x00 };
2626
2627 static const struct generic_data set_scan_params_success_test = {
2628         .send_opcode = MGMT_OP_SET_SCAN_PARAMS,
2629         .send_param = set_scan_params_valid_param,
2630         .send_len = sizeof(set_scan_params_valid_param),
2631         .expect_status = MGMT_STATUS_SUCCESS,
2632 };
2633
2634 static const char load_irks_empty_list[] = { 0x00, 0x00 };
2635
2636 static const struct generic_data load_irks_success1_test = {
2637         .send_opcode = MGMT_OP_LOAD_IRKS,
2638         .send_param = load_irks_empty_list,
2639         .send_len = sizeof(load_irks_empty_list),
2640         .expect_status = MGMT_STATUS_SUCCESS,
2641 };
2642
2643 static const char load_irks_one_irk[] = { 0x01, 0x00,
2644                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x01,
2645                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
2646                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
2647
2648 static const struct generic_data load_irks_success2_test = {
2649         .send_opcode = MGMT_OP_LOAD_IRKS,
2650         .send_param = load_irks_one_irk,
2651         .send_len = sizeof(load_irks_one_irk),
2652         .expect_status = MGMT_STATUS_SUCCESS,
2653 };
2654
2655 static const char load_irks_nval_addr_type[] = { 0x01, 0x00,
2656                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00,
2657                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
2658                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
2659
2660 static const struct generic_data load_irks_nval_param1_test = {
2661         .send_opcode = MGMT_OP_LOAD_IRKS,
2662         .send_param = load_irks_nval_addr_type,
2663         .send_len = sizeof(load_irks_nval_addr_type),
2664         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2665 };
2666
2667 static const char load_irks_nval_rand_addr[] = { 0x01, 0x00,
2668                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x02,
2669                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
2670                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
2671
2672 static const struct generic_data load_irks_nval_param2_test = {
2673         .send_opcode = MGMT_OP_LOAD_IRKS,
2674         .send_param = load_irks_nval_rand_addr,
2675         .send_len = sizeof(load_irks_nval_rand_addr),
2676         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2677 };
2678
2679 static const char load_irks_nval_len[] = { 0x02, 0x00, 0xff, 0xff };
2680
2681 static const struct generic_data load_irks_nval_param3_test = {
2682         .send_opcode = MGMT_OP_LOAD_IRKS,
2683         .send_param = load_irks_nval_len,
2684         .send_len = sizeof(load_irks_nval_len),
2685         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2686 };
2687
2688 static const struct generic_data load_irks_not_supported_test = {
2689         .send_opcode = MGMT_OP_LOAD_IRKS,
2690         .send_param = load_irks_empty_list,
2691         .send_len = sizeof(load_irks_empty_list),
2692         .expect_status = MGMT_STATUS_NOT_SUPPORTED,
2693 };
2694
2695 static const char set_privacy_valid_param[] = { 0x01,
2696                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
2697                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
2698 static const char set_privacy_settings_param[] = { 0x80, 0x20, 0x00, 0x00 };
2699
2700 static const struct generic_data set_privacy_success_test = {
2701         .send_opcode = MGMT_OP_SET_PRIVACY,
2702         .send_param = set_privacy_valid_param,
2703         .send_len = sizeof(set_privacy_valid_param),
2704         .expect_status = MGMT_STATUS_SUCCESS,
2705         .expect_param = set_privacy_settings_param,
2706         .expect_len = sizeof(set_privacy_settings_param),
2707         .expect_settings_set = MGMT_SETTING_PRIVACY,
2708 };
2709
2710 static const struct generic_data set_privacy_powered_test = {
2711         .setup_settings = settings_powered,
2712         .send_opcode = MGMT_OP_SET_PRIVACY,
2713         .send_param = set_privacy_valid_param,
2714         .send_len = sizeof(set_privacy_valid_param),
2715         .expect_status = MGMT_STATUS_REJECTED,
2716 };
2717
2718 static const char set_privacy_nval_param[] = { 0xff,
2719                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
2720                         0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
2721 static const struct generic_data set_privacy_nval_param_test = {
2722         .send_opcode = MGMT_OP_SET_PRIVACY,
2723         .send_param = set_privacy_nval_param,
2724         .send_len = sizeof(set_privacy_nval_param),
2725         .expect_status = MGMT_STATUS_INVALID_PARAMS,
2726 };
2727
2728 static void client_cmd_complete(uint16_t opcode, uint8_t status,
2729                                         const void *param, uint8_t len,
2730                                         void *user_data)
2731 {
2732         struct test_data *data = tester_get_data();
2733         const struct generic_data *test = data->test_data;
2734         struct bthost *bthost;
2735
2736         bthost = hciemu_client_get_host(data->hciemu);
2737
2738         switch (opcode) {
2739         case BT_HCI_CMD_WRITE_SCAN_ENABLE:
2740         case BT_HCI_CMD_LE_SET_ADV_ENABLE:
2741                 tester_print("Client set connectable status 0x%02x", status);
2742                 if (!status && test->client_enable_ssp) {
2743                         bthost_write_ssp_mode(bthost, 0x01);
2744                         return;
2745                 }
2746                 break;
2747         case BT_HCI_CMD_WRITE_SIMPLE_PAIRING_MODE:
2748                 tester_print("Client enable SSP status 0x%02x", status);
2749                 break;
2750         default:
2751                 return;
2752         }
2753
2754         if (status)
2755                 tester_setup_failed();
2756         else
2757                 tester_setup_complete();
2758 }
2759
2760 static void setup_bthost(void)
2761 {
2762         struct test_data *data = tester_get_data();
2763         struct bthost *bthost;
2764
2765         bthost = hciemu_client_get_host(data->hciemu);
2766         bthost_set_cmd_complete_cb(bthost, client_cmd_complete, data);
2767         if (data->hciemu_type == HCIEMU_TYPE_LE)
2768                 bthost_set_adv_enable(bthost, 0x01);
2769         else
2770                 bthost_write_scan_enable(bthost, 0x03);
2771 }
2772
2773 static void setup_ssp_acceptor(const void *test_data)
2774 {
2775         struct test_data *data = tester_get_data();
2776         const struct generic_data *test = data->test_data;
2777
2778         if (!test->io_cap)
2779                 return;
2780
2781         mgmt_send(data->mgmt, MGMT_OP_SET_IO_CAPABILITY, data->mgmt_index,
2782                                         sizeof(test->io_cap), &test->io_cap,
2783                                         NULL, NULL, NULL);
2784
2785         setup_bthost();
2786 }
2787
2788 static void setup_powered_callback(uint8_t status, uint16_t length,
2789                                         const void *param, void *user_data)
2790 {
2791         if (status != MGMT_STATUS_SUCCESS) {
2792                 tester_setup_failed();
2793                 return;
2794         }
2795
2796         tester_print("Controller powered on");
2797
2798         setup_bthost();
2799 }
2800
2801 static void setup_class(const void *test_data)
2802 {
2803         struct test_data *data = tester_get_data();
2804         unsigned char param[] = { 0x01 };
2805         unsigned char class_param[] = { 0x01, 0x0c };
2806
2807         tester_print("Setting device class and powering on");
2808
2809         mgmt_send(data->mgmt, MGMT_OP_SET_DEV_CLASS, data->mgmt_index,
2810                                 sizeof(class_param), class_param,
2811                                 NULL, NULL, NULL);
2812
2813         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
2814                                         sizeof(param), param,
2815                                         setup_powered_callback, NULL, NULL);
2816 }
2817
2818 static void setup_discovery_callback(uint8_t status, uint16_t length,
2819                                         const void *param, void *user_data)
2820 {
2821         if (status != MGMT_STATUS_SUCCESS) {
2822                 tester_setup_failed();
2823                 return;
2824         }
2825
2826         tester_print("Discovery started");
2827         tester_setup_complete();
2828 }
2829
2830 static bool setup_command_hci_callback(const void *data, uint16_t len,
2831                                                                 void *user_data)
2832 {
2833         struct test_data *tdata = tester_get_data();
2834         const struct generic_data *test = tdata->test_data;
2835
2836         tester_print("HCI Command 0x%04x length %u (setup)",
2837                                         test->setup_expect_hci_command, len);
2838
2839         if (len != test->setup_expect_hci_len) {
2840                 tester_warn("Invalid parameter size for HCI command (setup)");
2841                 tester_setup_failed();
2842                 goto done;
2843         }
2844
2845         if (memcmp(data, test->setup_expect_hci_param, len) != 0) {
2846                 tester_warn("Unexpected HCI command parameter value (setup)");
2847                 tester_setup_failed();
2848                 goto done;
2849         }
2850
2851         tester_setup_complete();
2852
2853 done:
2854         hciemu_del_hook(tdata->hciemu, HCIEMU_HOOK_PRE_EVT,
2855                         test->setup_expect_hci_command);
2856
2857         return false;
2858 }
2859
2860 static void setup_start_discovery(const void *test_data)
2861 {
2862         struct test_data *data = tester_get_data();
2863         const struct generic_data *test = data->test_data;
2864         const void *send_param = test->send_param;
2865         uint16_t send_len = test->send_len;
2866
2867         if (test->setup_expect_hci_command) {
2868                 tester_print("Registering HCI command callback (setup)");
2869                 hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT,
2870                                 test->setup_expect_hci_command,
2871                                 setup_command_hci_callback,
2872                                 NULL);
2873
2874                 if (test->send_func)
2875                         send_param = test->send_func(&send_len);
2876
2877                 mgmt_send(data->mgmt, MGMT_OP_START_DISCOVERY, data->mgmt_index,
2878                                 send_len, send_param, NULL, NULL, NULL);
2879         } else {
2880                 unsigned char disc_param[] = { 0x07 };
2881
2882                 mgmt_send(data->mgmt, MGMT_OP_START_DISCOVERY, data->mgmt_index,
2883                                         sizeof(disc_param), disc_param,
2884                                         setup_discovery_callback, NULL, NULL);
2885         }
2886 }
2887
2888 static void setup_multi_uuid32(const void *test_data)
2889 {
2890         struct test_data *data = tester_get_data();
2891         unsigned char param[] = { 0x01 };
2892
2893         tester_print("Powering on controller (with 32-bit UUID)");
2894
2895         mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
2896                                 sizeof(param), param, NULL, NULL, NULL);
2897
2898         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
2899                                 sizeof(add_uuid32_param_1), add_uuid32_param_1,
2900                                 NULL, NULL, NULL);
2901         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
2902                                 sizeof(add_uuid32_param_2), add_uuid32_param_2,
2903                                 NULL, NULL, NULL);
2904         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
2905                                 sizeof(add_uuid32_param_3), add_uuid32_param_3,
2906                                 NULL, NULL, NULL);
2907
2908         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
2909                                         sizeof(param), param,
2910                                         setup_powered_callback, NULL, NULL);
2911 }
2912
2913 static void setup_multi_uuid32_2(const void *test_data)
2914 {
2915         struct test_data *data = tester_get_data();
2916         unsigned char param[] = { 0x01 };
2917         unsigned char uuid_param[] = {
2918                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
2919                         0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2920                         0x00 };
2921         int i;
2922
2923         tester_print("Powering on controller (with many 32-bit UUIDs)");
2924
2925         mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
2926                                 sizeof(param), param, NULL, NULL, NULL);
2927
2928         for (i = 0; i < 58; i++) {
2929                 uint32_t val = htobl(0xffffffff - i);
2930                 memcpy(&uuid_param[12], &val, sizeof(val));
2931                 mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
2932                                 sizeof(uuid_param), uuid_param,
2933                                 NULL, NULL, NULL);
2934         }
2935
2936         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
2937                                         sizeof(param), param,
2938                                         setup_powered_callback, NULL, NULL);
2939 }
2940
2941 static void setup_multi_uuid128(const void *test_data)
2942 {
2943         struct test_data *data = tester_get_data();
2944         unsigned char param[] = { 0x01 };
2945
2946         tester_print("Powering on controller (with 128-bit UUID)");
2947
2948         mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
2949                                 sizeof(param), param, NULL, NULL, NULL);
2950
2951         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
2952                         sizeof(add_uuid128_param_1), add_uuid128_param_1,
2953                         NULL, NULL, NULL);
2954
2955         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
2956                                         sizeof(param), param,
2957                                         setup_powered_callback, NULL, NULL);
2958 }
2959
2960 static void setup_multi_uuid128_2(const void *test_data)
2961 {
2962         struct test_data *data = tester_get_data();
2963         unsigned char param[] = { 0x01 };
2964         unsigned char uuid_param[] = {
2965                         0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
2966                         0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00,
2967                         0x00 };
2968         int i;
2969
2970         tester_print("Powering on controller (with many 128-bit UUIDs)");
2971
2972         mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
2973                                 sizeof(param), param, NULL, NULL, NULL);
2974
2975         for (i = 0; i < 13; i++) {
2976                 uuid_param[15] = i;
2977                 mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
2978                                 sizeof(uuid_param), uuid_param,
2979                                 NULL, NULL, NULL);
2980         }
2981
2982         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
2983                                         sizeof(param), param,
2984                                         setup_powered_callback, NULL, NULL);
2985 }
2986
2987 static void setup_multi_uuid16(const void *test_data)
2988 {
2989         struct test_data *data = tester_get_data();
2990         unsigned char param[] = { 0x01 };
2991
2992         tester_print("Powering on controller (with SPP UUID)");
2993
2994         mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
2995                                 sizeof(param), param, NULL, NULL, NULL);
2996
2997         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
2998                                 sizeof(add_spp_uuid_param), add_spp_uuid_param,
2999                                 NULL, NULL, NULL);
3000         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3001                                 sizeof(add_dun_uuid_param), add_dun_uuid_param,
3002                                 NULL, NULL, NULL);
3003         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3004                         sizeof(add_sync_uuid_param), add_sync_uuid_param,
3005                         NULL, NULL, NULL);
3006
3007         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
3008                                         sizeof(param), param,
3009                                         setup_powered_callback, NULL, NULL);
3010 }
3011
3012 static void setup_multi_uuid16_2(const void *test_data)
3013 {
3014         struct test_data *data = tester_get_data();
3015         unsigned char param[] = { 0x01 };
3016         unsigned char uuid_param[] = {
3017                         0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
3018                         0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3019                         0x00 };
3020         int i;
3021
3022         tester_print("Powering on controller (with many 16-bit UUIDs)");
3023
3024         mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
3025                                 sizeof(param), param, NULL, NULL, NULL);
3026
3027         for (i = 0; i < 117; i++) {
3028                 uint16_t val = htobs(i + 0x2000);
3029                 memcpy(&uuid_param[12], &val, sizeof(val));
3030                 mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3031                                 sizeof(uuid_param), uuid_param,
3032                                 NULL, NULL, NULL);
3033         }
3034
3035         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
3036                                         sizeof(param), param,
3037                                         setup_powered_callback, NULL, NULL);
3038 }
3039
3040 static void setup_uuid_mix(const void *test_data)
3041 {
3042         struct test_data *data = tester_get_data();
3043         unsigned char param[] = { 0x01 };
3044
3045         tester_print("Powering on controller (with mixed UUIDs)");
3046
3047         mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
3048                                 sizeof(param), param, NULL, NULL, NULL);
3049
3050         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3051                                 sizeof(add_spp_uuid_param), add_spp_uuid_param,
3052                                 NULL, NULL, NULL);
3053         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3054                                 sizeof(add_uuid32_param_1), add_uuid32_param_1,
3055                                 NULL, NULL, NULL);
3056         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3057                         sizeof(add_uuid128_param_1), add_uuid128_param_1,
3058                         NULL, NULL, NULL);
3059
3060         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3061                                 sizeof(add_dun_uuid_param), add_dun_uuid_param,
3062                                 NULL, NULL, NULL);
3063         mgmt_send(data->mgmt, MGMT_OP_ADD_UUID, data->mgmt_index,
3064                                 sizeof(add_uuid32_param_2), add_uuid32_param_2,
3065                                 NULL, NULL, NULL);
3066
3067         mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
3068                                         sizeof(param), param,
3069                                         setup_powered_callback, NULL, NULL);
3070 }
3071
3072 static void setup_complete(uint8_t status, uint16_t length,
3073                                         const void *param, void *user_data)
3074 {
3075         struct test_data *data = tester_get_data();
3076
3077         if (status != MGMT_STATUS_SUCCESS) {
3078                 tester_setup_failed();
3079                 return;
3080         }
3081
3082         tester_print("Initial settings completed");
3083
3084         if (data->test_setup)
3085                 data->test_setup(data);
3086         else
3087                 setup_bthost();
3088 }
3089
3090 static void pin_code_request_callback(uint16_t index, uint16_t length,
3091                                         const void *param, void *user_data)
3092 {
3093         const struct mgmt_ev_pin_code_request *ev = param;
3094         struct test_data *data = user_data;
3095         const struct generic_data *test = data->test_data;
3096         struct mgmt_cp_pin_code_reply cp;
3097
3098         test_condition_complete(data);
3099
3100         memset(&cp, 0, sizeof(cp));
3101         memcpy(&cp.addr, &ev->addr, sizeof(cp.addr));
3102
3103         if (!test->pin) {
3104                 mgmt_reply(data->mgmt, MGMT_OP_PIN_CODE_NEG_REPLY,
3105                                 data->mgmt_index, sizeof(cp.addr), &cp.addr,
3106                                 NULL, NULL, NULL);
3107                 return;
3108         }
3109
3110         cp.pin_len = test->pin_len;
3111         memcpy(cp.pin_code, test->pin, test->pin_len);
3112
3113         mgmt_reply(data->mgmt, MGMT_OP_PIN_CODE_REPLY, data->mgmt_index,
3114                         sizeof(cp), &cp, NULL, NULL, NULL);
3115 }
3116
3117 static void user_confirm_request_callback(uint16_t index, uint16_t length,
3118                                                         const void *param,
3119                                                         void *user_data)
3120 {
3121         const struct mgmt_ev_user_confirm_request *ev = param;
3122         struct test_data *data = user_data;
3123         const struct generic_data *test = data->test_data;
3124         struct mgmt_cp_user_confirm_reply cp;
3125         uint16_t opcode;
3126
3127         memset(&cp, 0, sizeof(cp));
3128         memcpy(&cp.addr, &ev->addr, sizeof(cp.addr));
3129
3130         if (test->reject_ssp)
3131                 opcode = MGMT_OP_USER_CONFIRM_NEG_REPLY;
3132         else
3133                 opcode = MGMT_OP_USER_CONFIRM_REPLY;
3134
3135         mgmt_reply(data->mgmt, opcode, data->mgmt_index, sizeof(cp), &cp,
3136                                                         NULL, NULL, NULL);
3137 }
3138
3139 static void test_setup(const void *test_data)
3140 {
3141         struct test_data *data = tester_get_data();
3142         const struct generic_data *test = data->test_data;
3143         struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3144         const uint16_t *cmd;
3145
3146         if (!test)
3147                 goto proceed;
3148
3149         if (test->pin || test->expect_pin) {
3150                 mgmt_register(data->mgmt, MGMT_EV_PIN_CODE_REQUEST,
3151                                 data->mgmt_index, pin_code_request_callback,
3152                                 data, NULL);
3153                 test_add_condition(data);
3154         }
3155
3156         mgmt_register(data->mgmt, MGMT_EV_USER_CONFIRM_REQUEST,
3157                         data->mgmt_index, user_confirm_request_callback,
3158                         data, NULL);
3159
3160         if (test->client_pin)
3161                 bthost_set_pin_code(bthost, test->client_pin,
3162                                                         test->client_pin_len);
3163
3164         if (test->client_io_cap)
3165                 bthost_set_io_capability(bthost, test->client_io_cap);
3166
3167         if (test->client_reject_ssp)
3168                 bthost_set_reject_user_confirm(bthost, true);
3169
3170 proceed:
3171         if (!test || !test->setup_settings) {
3172                 if (data->test_setup)
3173                         data->test_setup(data);
3174                 else
3175                         tester_setup_complete();
3176                 return;
3177         }
3178
3179         for (cmd = test->setup_settings; *cmd; cmd++) {
3180                 unsigned char simple_param[] = { 0x01 };
3181                 unsigned char discov_param[] = { 0x01, 0x00, 0x00 };
3182                 unsigned char *param = simple_param;
3183                 size_t param_size = sizeof(simple_param);
3184                 mgmt_request_func_t func = NULL;
3185
3186                 /* If this is the last command (next one is 0) request
3187                  * for a callback. */
3188                 if (!cmd[1])
3189                         func = setup_complete;
3190
3191                 if (*cmd == MGMT_OP_SET_DISCOVERABLE) {
3192                         if (test->setup_limited_discov) {
3193                                 discov_param[0] = 0x02;
3194                                 discov_param[1] = 0x01;
3195                         }
3196                         param_size = sizeof(discov_param);
3197                         param = discov_param;
3198                 }
3199
3200                 if (*cmd == MGMT_OP_SET_LE && test->setup_nobredr) {
3201                         unsigned char off[] = { 0x00 };
3202                         mgmt_send(data->mgmt, *cmd, data->mgmt_index,
3203                                         param_size, param, NULL, NULL, NULL);
3204                         mgmt_send(data->mgmt, MGMT_OP_SET_BREDR,
3205                                         data->mgmt_index, sizeof(off), off,
3206                                         func, data, NULL);
3207                 } else {
3208                         mgmt_send(data->mgmt, *cmd, data->mgmt_index,
3209                                         param_size, param, func, data, NULL);
3210                 }
3211         }
3212 }
3213
3214 static void command_generic_new_settings(uint16_t index, uint16_t length,
3215                                         const void *param, void *user_data)
3216 {
3217         struct test_data *data = tester_get_data();
3218
3219         tester_print("New settings event received");
3220
3221         mgmt_unregister(data->mgmt, data->mgmt_settings_id);
3222
3223         tester_test_failed();
3224 }
3225
3226 static void command_generic_new_settings_alt(uint16_t index, uint16_t length,
3227                                         const void *param, void *user_data)
3228 {
3229         struct test_data *data = tester_get_data();
3230         const struct generic_data *test = data->test_data;
3231         uint32_t settings;
3232
3233         if (length != 4) {
3234                 tester_warn("Invalid parameter size for new settings event");
3235                 tester_test_failed();
3236                 return;
3237         }
3238
3239         settings = bt_get_le32(param);
3240
3241         tester_print("New settings 0x%08x received", settings);
3242
3243         if (test->expect_settings_unset) {
3244                 if ((settings & test->expect_settings_unset) != 0)
3245                         return;
3246                 goto done;
3247         }
3248
3249         if (!test->expect_settings_set)
3250                 return;
3251
3252         if ((settings & test->expect_settings_set) != test->expect_settings_set)
3253                 return;
3254
3255 done:
3256         tester_print("Unregistering new settings notification");
3257
3258         mgmt_unregister(data->mgmt_alt, data->mgmt_alt_settings_id);
3259
3260         test_condition_complete(data);
3261 }
3262
3263 static void command_generic_event_alt(uint16_t index, uint16_t length,
3264                                                         const void *param,
3265                                                         void *user_data)
3266 {
3267         struct test_data *data = tester_get_data();
3268         const struct generic_data *test = data->test_data;
3269
3270         if (length != test->expect_alt_ev_len) {
3271                 tester_warn("Invalid length %s event",
3272                                         mgmt_evstr(test->expect_alt_ev));
3273                 tester_test_failed();
3274                 return;
3275         }
3276
3277         tester_print("New %s event received", mgmt_evstr(test->expect_alt_ev));
3278
3279         if (test->expect_alt_ev_param &&
3280                         memcmp(param, test->expect_alt_ev_param,
3281                                                 test->expect_alt_ev_len) != 0)
3282                 return;
3283
3284         tester_print("Unregistering %s notification",
3285                                         mgmt_evstr(test->expect_alt_ev));
3286
3287         mgmt_unregister(data->mgmt_alt, data->mgmt_alt_ev_id);
3288
3289         test_condition_complete(data);
3290 }
3291
3292 static void command_generic_callback(uint8_t status, uint16_t length,
3293                                         const void *param, void *user_data)
3294 {
3295         struct test_data *data = tester_get_data();
3296         const struct generic_data *test = data->test_data;
3297         const void *expect_param = test->expect_param;
3298         uint16_t expect_len = test->expect_len;
3299
3300         tester_print("Command 0x%04x finished with status 0x%02x",
3301                                                 test->send_opcode, status);
3302
3303         if (status != test->expect_status) {
3304                 tester_test_failed();
3305                 return;
3306         }
3307
3308         if (test->expect_func)
3309                 expect_param = test->expect_func(&expect_len);
3310
3311         if (length != expect_len) {
3312                 tester_test_failed();
3313                 return;
3314         }
3315
3316         if (expect_param && expect_len > 0 &&
3317                                 memcmp(param, expect_param, length)) {
3318                 tester_test_failed();
3319                 return;
3320         }
3321
3322         test_condition_complete(data);
3323 }
3324
3325 static void command_hci_callback(uint16_t opcode, const void *param,
3326                                         uint8_t length, void *user_data)
3327 {
3328         struct test_data *data = user_data;
3329         const struct generic_data *test = data->test_data;
3330         const void *expect_hci_param = test->expect_hci_param;
3331         uint8_t expect_hci_len = test->expect_hci_len;
3332
3333         tester_print("HCI Command 0x%04x length %u", opcode, length);
3334
3335         if (opcode != test->expect_hci_command)
3336                 return;
3337
3338         if (test->expect_hci_func)
3339                 expect_hci_param = test->expect_hci_func(&expect_hci_len);
3340
3341         if (length != expect_hci_len) {
3342                 tester_warn("Invalid parameter size for HCI command");
3343                 tester_test_failed();
3344                 return;
3345         }
3346
3347         if (memcmp(param, expect_hci_param, length) != 0) {
3348                 tester_warn("Unexpected HCI command parameter value");
3349                 tester_test_failed();
3350                 return;
3351         }
3352
3353         test_condition_complete(data);
3354 }
3355
3356 static void test_command_generic(const void *test_data)
3357 {
3358         struct test_data *data = tester_get_data();
3359         const struct generic_data *test = data->test_data;
3360         const void *send_param = test->send_param;
3361         uint16_t send_len = test->send_len;
3362         unsigned int id;
3363         uint16_t index;
3364
3365         index = test->send_index_none ? MGMT_INDEX_NONE : data->mgmt_index;
3366
3367         if (test->expect_settings_set || test->expect_settings_unset) {
3368                 tester_print("Registering new settings notification");
3369
3370                 id = mgmt_register(data->mgmt, MGMT_EV_NEW_SETTINGS, index,
3371                                 command_generic_new_settings, NULL, NULL);
3372                 data->mgmt_settings_id = id;
3373
3374                 id = mgmt_register(data->mgmt_alt, MGMT_EV_NEW_SETTINGS, index,
3375                                 command_generic_new_settings_alt, NULL, NULL);
3376                 data->mgmt_alt_settings_id = id;
3377                 test_add_condition(data);
3378         }
3379
3380         if (test->expect_alt_ev) {
3381                 tester_print("Registering %s notification",
3382                                         mgmt_evstr(test->expect_alt_ev));
3383                 id = mgmt_register(data->mgmt_alt, test->expect_alt_ev, index,
3384                                         command_generic_event_alt, NULL, NULL);
3385                 data->mgmt_alt_ev_id = id;
3386                 test_add_condition(data);
3387         }
3388
3389         if (test->expect_hci_command) {
3390                 tester_print("Registering HCI command callback");
3391                 hciemu_add_master_post_command_hook(data->hciemu,
3392                                                 command_hci_callback, data);
3393                 test_add_condition(data);
3394         }
3395
3396         tester_print("Sending command 0x%04x", test->send_opcode);
3397
3398         if (test->send_func)
3399                 send_param = test->send_func(&send_len);
3400
3401         mgmt_send(data->mgmt, test->send_opcode, index, send_len, send_param,
3402                                         command_generic_callback, NULL, NULL);
3403         test_add_condition(data);
3404 }
3405
3406 static void pairing_new_conn(uint16_t handle, void *user_data)
3407 {
3408         struct test_data *data = tester_get_data();
3409         struct bthost *bthost;
3410
3411         tester_print("New connection with handle 0x%04x", handle);
3412
3413         bthost = hciemu_client_get_host(data->hciemu);
3414
3415         bthost_request_auth(bthost, handle);
3416 }
3417
3418 static void test_pairing_acceptor(const void *test_data)
3419 {
3420         struct test_data *data = tester_get_data();
3421         const struct generic_data *test = data->test_data;
3422         const uint8_t *master_bdaddr;
3423         struct bthost *bthost;
3424         uint8_t addr_type;
3425
3426         if (test->expect_alt_ev) {
3427                 unsigned int id;
3428
3429                 tester_print("Registering %s notification",
3430                                         mgmt_evstr(test->expect_alt_ev));
3431                 id = mgmt_register(data->mgmt_alt, test->expect_alt_ev,
3432                                         data->mgmt_index,
3433                                         command_generic_event_alt, NULL, NULL);
3434                 data->mgmt_alt_ev_id = id;
3435                 test_add_condition(data);
3436         }
3437
3438         master_bdaddr = hciemu_get_master_bdaddr(data->hciemu);
3439         if (!master_bdaddr) {
3440                 tester_warn("No master bdaddr");
3441                 tester_test_failed();
3442                 return;
3443         }
3444
3445         bthost = hciemu_client_get_host(data->hciemu);
3446         bthost_set_connect_cb(bthost, pairing_new_conn, data);
3447
3448         if (data->hciemu_type == HCIEMU_TYPE_BREDRLE)
3449                 addr_type = BDADDR_BREDR;
3450         else
3451                 addr_type = BDADDR_LE_PUBLIC;
3452
3453         bthost_hci_connect(bthost, master_bdaddr, addr_type);
3454 }
3455
3456 int main(int argc, char *argv[])
3457 {
3458         tester_init(&argc, &argv);
3459
3460         test_bredrle("Controller setup",
3461                                 NULL, NULL, controller_setup);
3462         test_bredr("Controller setup (BR/EDR-only)",
3463                                 NULL, NULL, controller_setup);
3464         test_le("Controller setup (LE)",
3465                                 NULL, NULL, controller_setup);
3466
3467         test_bredrle("Invalid command",
3468                                 &invalid_command_test,
3469                                 NULL, test_command_generic);
3470
3471         test_bredrle("Read version - Success",
3472                                 &read_version_success_test,
3473                                 NULL, test_command_generic);
3474         test_bredrle("Read version - Invalid parameters",
3475                                 &read_version_invalid_param_test,
3476                                 NULL, test_command_generic);
3477         test_bredrle("Read version - Invalid index",
3478                                 &read_version_invalid_index_test,
3479                                 NULL, test_command_generic);
3480         test_bredrle("Read commands - Invalid parameters",
3481                                 &read_commands_invalid_param_test,
3482                                 NULL, test_command_generic);
3483         test_bredrle("Read commands - Invalid index",
3484                                 &read_commands_invalid_index_test,
3485                                 NULL, test_command_generic);
3486         test_bredrle("Read index list - Invalid parameters",
3487                                 &read_index_list_invalid_param_test,
3488                                 NULL, test_command_generic);
3489         test_bredrle("Read index list - Invalid index",
3490                                 &read_index_list_invalid_index_test,
3491                                 NULL, test_command_generic);
3492         test_bredrle("Read info - Invalid parameters",
3493                                 &read_info_invalid_param_test,
3494                                 NULL, test_command_generic);
3495         test_bredrle("Read info - Invalid index",
3496                                 &read_info_invalid_index_test,
3497                                 NULL, test_command_generic);
3498
3499         test_bredrle("Set powered on - Success",
3500                                 &set_powered_on_success_test,
3501                                 NULL, test_command_generic);
3502         test_bredrle("Set powered on - Invalid parameters 1",
3503                                 &set_powered_on_invalid_param_test_1,
3504                                 NULL, test_command_generic);
3505         test_bredrle("Set powered on - Invalid parameters 2",
3506                                 &set_powered_on_invalid_param_test_2,
3507                                 NULL, test_command_generic);
3508         test_bredrle("Set powered on - Invalid parameters 3",
3509                                 &set_powered_on_invalid_param_test_3,
3510                                 NULL, test_command_generic);
3511         test_bredrle("Set powered on - Invalid index",
3512                                 &set_powered_on_invalid_index_test,
3513                                 NULL, test_command_generic);
3514
3515         test_bredrle("Set powered off - Success",
3516                                 &set_powered_off_success_test,
3517                                 NULL, test_command_generic);
3518         test_bredrle("Set powered off - Class of Device",
3519                                 &set_powered_off_class_test,
3520                                 setup_class, test_command_generic);
3521         test_bredrle("Set powered off - Invalid parameters 1",
3522                                 &set_powered_off_invalid_param_test_1,
3523                                 NULL, test_command_generic);
3524         test_bredrle("Set powered off - Invalid parameters 2",
3525                                 &set_powered_off_invalid_param_test_2,
3526                                 NULL, test_command_generic);
3527         test_bredrle("Set powered off - Invalid parameters 3",
3528                                 &set_powered_off_invalid_param_test_3,
3529                                 NULL, test_command_generic);
3530
3531         test_bredrle("Set connectable on - Success 1",
3532                                 &set_connectable_on_success_test_1,
3533                                 NULL, test_command_generic);
3534         test_bredrle("Set connectable on - Success 2",
3535                                 &set_connectable_on_success_test_2,
3536                                 NULL, test_command_generic);
3537         test_bredrle("Set connectable on - Invalid parameters 1",
3538                                 &set_connectable_on_invalid_param_test_1,
3539                                 NULL, test_command_generic);
3540         test_bredrle("Set connectable on - Invalid parameters 2",
3541                                 &set_connectable_on_invalid_param_test_2,
3542                                 NULL, test_command_generic);
3543         test_bredrle("Set connectable on - Invalid parameters 3",
3544                                 &set_connectable_on_invalid_param_test_3,
3545                                 NULL, test_command_generic);
3546         test_bredrle("Set connectable on - Invalid index",
3547                                 &set_connectable_on_invalid_index_test,
3548                                 NULL, test_command_generic);
3549
3550         test_le("Set connectable on (LE) - Success 1",
3551                                 &set_connectable_on_le_test_1,
3552                                 NULL, test_command_generic);
3553         test_le("Set connectable on (LE) - Success 2",
3554                                 &set_connectable_on_le_test_2,
3555                                 NULL, test_command_generic);
3556         test_le("Set connectable on (LE) - Success 3",
3557                                 &set_connectable_on_le_test_3,
3558                                 NULL, test_command_generic);
3559
3560         test_bredrle("Set connectable off - Success 1",
3561                                 &set_connectable_off_success_test_1,
3562                                 NULL, test_command_generic);
3563         test_bredrle("Set connectable off - Success 2",
3564                                 &set_connectable_off_success_test_2,
3565                                 NULL, test_command_generic);
3566         test_bredrle("Set connectable off - Success 3",
3567                                 &set_connectable_off_success_test_3,
3568                                 NULL, test_command_generic);
3569
3570         test_le("Set connectable off (LE) - Success 1",
3571                                 &set_connectable_off_le_test_1,
3572                                 NULL, test_command_generic);
3573         test_le("Set connectable off (LE) - Success 2",
3574                                 &set_connectable_off_le_test_2,
3575                                 NULL, test_command_generic);
3576         test_le("Set connectable off (LE) - Success 3",
3577                                 &set_connectable_off_le_test_3,
3578                                 NULL, test_command_generic);
3579         test_le("Set connectable off (LE) - Success 4",
3580                                 &set_connectable_off_le_test_4,
3581                                 NULL, test_command_generic);
3582
3583         test_bredrle("Set fast connectable on - Success 1",
3584                                 &set_fast_conn_on_success_test_1,
3585                                 NULL, test_command_generic);
3586         test_le("Set fast connectable on - Not Supported 1",
3587                                 &set_fast_conn_on_not_supported_test_1,
3588                                 NULL, test_command_generic);
3589
3590         test_bredrle("Set pairable on - Success",
3591                                 &set_pairable_on_success_test,
3592                                 NULL, test_command_generic);
3593         test_bredrle("Set pairable on - Invalid parameters 1",
3594                                 &set_pairable_on_invalid_param_test_1,
3595                                 NULL, test_command_generic);
3596         test_bredrle("Set pairable on - Invalid parameters 2",
3597                                 &set_pairable_on_invalid_param_test_2,
3598                                 NULL, test_command_generic);
3599         test_bredrle("Set pairable on - Invalid parameters 3",
3600                                 &set_pairable_on_invalid_param_test_3,
3601                                 NULL, test_command_generic);
3602         test_bredrle("Set pairable on - Invalid index",
3603                                 &set_pairable_on_invalid_index_test,
3604                                 NULL, test_command_generic);
3605
3606         test_bredrle("Set discoverable on - Invalid parameters 1",
3607                                 &set_discoverable_on_invalid_param_test_1,
3608                                 NULL, test_command_generic);
3609         test_bredrle("Set discoverable on - Invalid parameters 2",
3610                                 &set_discoverable_on_invalid_param_test_2,
3611                                 NULL, test_command_generic);
3612         test_bredrle("Set discoverable on - Invalid parameters 3",
3613                                 &set_discoverable_on_invalid_param_test_3,
3614                                 NULL, test_command_generic);
3615         test_bredrle("Set discoverable on - Invalid parameters 4",
3616                                 &set_discoverable_on_invalid_param_test_4,
3617                                 NULL, test_command_generic);
3618         test_bredrle("Set discoverable on - Not powered 1",
3619                                 &set_discoverable_on_not_powered_test_1,
3620                                 NULL, test_command_generic);
3621         test_bredrle("Set discoverable on - Not powered 2",
3622                                 &set_discoverable_on_not_powered_test_2,
3623                                 NULL, test_command_generic);
3624         test_bredrle("Set discoverable on - Rejected 1",
3625                                 &set_discoverable_on_rejected_test_1,
3626                                 NULL, test_command_generic);
3627         test_bredrle("Set discoverable on - Rejected 2",
3628                                 &set_discoverable_on_rejected_test_2,
3629                                 NULL, test_command_generic);
3630         test_bredrle("Set discoverable on - Rejected 3",
3631                                 &set_discoverable_on_rejected_test_3,
3632                                 NULL, test_command_generic);
3633         test_bredrle("Set discoverable on - Success 1",
3634                                 &set_discoverable_on_success_test_1,
3635                                 NULL, test_command_generic);
3636         test_bredrle("Set discoverable on - Success 2",
3637                                 &set_discoverable_on_success_test_2,
3638                                 NULL, test_command_generic);
3639         test_le("Set discoverable on (LE) - Success 1",
3640                                 &set_discov_on_le_success_1,
3641                                 NULL, test_command_generic);
3642         test_bredrle("Set discoverable off - Success 1",
3643                                 &set_discoverable_off_success_test_1,
3644                                 NULL, test_command_generic);
3645         test_bredrle("Set discoverable off - Success 2",
3646                                 &set_discoverable_off_success_test_2,
3647                                 NULL, test_command_generic);
3648         test_bredrle("Set limited discoverable on - Success 1",
3649                                 &set_limited_discov_on_success_1,
3650                                 NULL, test_command_generic);
3651         test_bredrle("Set limited discoverable on - Success 2",
3652                                 &set_limited_discov_on_success_2,
3653                                 NULL, test_command_generic);
3654         test_bredrle("Set limited discoverable on - Success 3",
3655                                 &set_limited_discov_on_success_3,
3656                                 NULL, test_command_generic);
3657         test_le("Set limited discoverable on (LE) - Success 1",
3658                                 &set_limited_discov_on_le_success_1,
3659                                 NULL, test_command_generic);
3660
3661         test_bredrle("Set link security on - Success 1",
3662                                 &set_link_sec_on_success_test_1,
3663                                 NULL, test_command_generic);
3664         test_bredrle("Set link security on - Success 2",
3665                                 &set_link_sec_on_success_test_2,
3666                                 NULL, test_command_generic);
3667         test_bredrle("Set link security on - Success 3",
3668                                 &set_link_sec_on_success_test_3,
3669                                 NULL, test_command_generic);
3670         test_bredrle("Set link security on - Invalid parameters 1",
3671                                 &set_link_sec_on_invalid_param_test_1,
3672                                 NULL, test_command_generic);
3673         test_bredrle("Set link security on - Invalid parameters 2",
3674                                 &set_link_sec_on_invalid_param_test_2,
3675                                 NULL, test_command_generic);
3676         test_bredrle("Set link security on - Invalid parameters 3",
3677                                 &set_link_sec_on_invalid_param_test_3,
3678                                 NULL, test_command_generic);
3679         test_bredrle("Set link security on - Invalid index",
3680                                 &set_link_sec_on_invalid_index_test,
3681                                 NULL, test_command_generic);
3682
3683         test_bredrle("Set link security off - Success 1",
3684                                 &set_link_sec_off_success_test_1,
3685                                 NULL, test_command_generic);
3686         test_bredrle("Set link security off - Success 2",
3687                                 &set_link_sec_off_success_test_2,
3688                                 NULL, test_command_generic);
3689
3690         test_bredrle("Set SSP on - Success 1",
3691                                 &set_ssp_on_success_test_1,
3692                                 NULL, test_command_generic);
3693         test_bredrle("Set SSP on - Success 2",
3694                                 &set_ssp_on_success_test_2,
3695                                 NULL, test_command_generic);
3696         test_bredrle("Set SSP on - Success 3",
3697                                 &set_ssp_on_success_test_3,
3698                                 NULL, test_command_generic);
3699         test_bredrle("Set SSP on - Invalid parameters 1",
3700                                 &set_ssp_on_invalid_param_test_1,
3701                                 NULL, test_command_generic);
3702         test_bredrle("Set SSP on - Invalid parameters 2",
3703                                 &set_ssp_on_invalid_param_test_2,
3704                                 NULL, test_command_generic);
3705         test_bredrle("Set SSP on - Invalid parameters 3",
3706                                 &set_ssp_on_invalid_param_test_3,
3707                                 NULL, test_command_generic);
3708         test_bredrle("Set SSP on - Invalid index",
3709                                 &set_ssp_on_invalid_index_test,
3710                                 NULL, test_command_generic);
3711
3712         test_bredrle("Set Secure Connections on - Success 1",
3713                                 &set_sc_on_success_test_1,
3714                                 NULL, test_command_generic);
3715         test_bredrle("Set Secure Connections on - Success 2",
3716                                 &set_sc_on_success_test_2,
3717                                 NULL, test_command_generic);
3718         test_bredrle("Set Secure Connections on - Invalid params 1",
3719                                 &set_sc_on_invalid_param_test_1,
3720                                 NULL, test_command_generic);
3721         test_bredrle("Set Secure Connections on - Invalid params 2",
3722                                 &set_sc_on_invalid_param_test_2,
3723                                 NULL, test_command_generic);
3724         test_bredrle("Set Secure Connections on - Invalid params 3",
3725                                 &set_sc_on_invalid_param_test_3,
3726                                 NULL, test_command_generic);
3727         test_bredrle("Set Secure Connections on - Invalid index",
3728                                 &set_sc_on_invalid_index_test,
3729                                 NULL, test_command_generic);
3730         test_bredr("Set Secure Connections on - Not supported 1",
3731                                 &set_sc_on_not_supported_test_1,
3732                                 NULL, test_command_generic);
3733         test_bredr("Set Secure Connections on - Not supported 2",
3734                                 &set_sc_on_not_supported_test_2,
3735                                 NULL, test_command_generic);
3736
3737         test_bredrle("Set Secure Connections Only on - Success 1",
3738                                 &set_sc_only_on_success_test_1,
3739                                 NULL, test_command_generic);
3740         test_bredrle("Set Secure Connections Only on - Success 2",
3741                                 &set_sc_only_on_success_test_2,
3742                                 NULL, test_command_generic);
3743
3744         test_bredrle("Set High Speed on - Success",
3745                                 &set_hs_on_success_test,
3746                                 NULL, test_command_generic);
3747         test_bredrle("Set High Speed on - Invalid parameters 1",
3748                                 &set_hs_on_invalid_param_test_1,
3749                                 NULL, test_command_generic);
3750         test_bredrle("Set High Speed on - Invalid parameters 2",
3751                                 &set_hs_on_invalid_param_test_2,
3752                                 NULL, test_command_generic);
3753         test_bredrle("Set High Speed on - Invalid parameters 3",
3754                                 &set_hs_on_invalid_param_test_3,
3755                                 NULL, test_command_generic);
3756         test_bredrle("Set High Speed on - Invalid index",
3757                                 &set_hs_on_invalid_index_test,
3758                                 NULL, test_command_generic);
3759
3760         test_bredrle("Set Low Energy on - Success 1",
3761                                 &set_le_on_success_test_1,
3762                                 NULL, test_command_generic);
3763         test_bredrle("Set Low Energy on - Success 2",
3764                                 &set_le_on_success_test_2,
3765                                 NULL, test_command_generic);
3766         test_bredrle("Set Low Energy on - Success 3",
3767                                 &set_le_on_success_test_3,
3768                                 NULL, test_command_generic);
3769         test_bredrle("Set Low Energy on - Invalid parameters 1",
3770                                 &set_le_on_invalid_param_test_1,
3771                                 NULL, test_command_generic);
3772         test_bredrle("Set Low Energy on - Invalid parameters 2",
3773                                 &set_le_on_invalid_param_test_2,
3774                                 NULL, test_command_generic);
3775         test_bredrle("Set Low Energy on - Invalid parameters 3",
3776                                 &set_le_on_invalid_param_test_3,
3777                                 NULL, test_command_generic);
3778         test_bredrle("Set Low Energy on - Invalid index",
3779                                 &set_le_on_invalid_index_test,
3780                                 NULL, test_command_generic);
3781
3782         test_bredrle("Set Advertising on - Success 1",
3783                                 &set_adv_on_success_test_1,
3784                                 NULL, test_command_generic);
3785         test_bredrle("Set Advertising on - Success 2",
3786                                 &set_adv_on_success_test_2,
3787                                 NULL, test_command_generic);
3788         test_bredrle("Set Advertising on - Rejected 1",
3789                                 &set_adv_on_rejected_test_1,
3790                                 NULL, test_command_generic);
3791
3792         test_bredrle("Set BR/EDR off - Success 1",
3793                                 &set_bredr_off_success_test_1,
3794                                 NULL, test_command_generic);
3795         test_bredrle("Set BR/EDR on - Success 1",
3796                                 &set_bredr_on_success_test_1,
3797                                 NULL, test_command_generic);
3798         test_bredrle("Set BR/EDR on - Success 2",
3799                                 &set_bredr_on_success_test_2,
3800                                 NULL, test_command_generic);
3801         test_bredr("Set BR/EDR off - Not Supported 1",
3802                                 &set_bredr_off_notsupp_test,
3803                                 NULL, test_command_generic);
3804         test_le("Set BR/EDR off - Not Supported 2",
3805                                 &set_bredr_off_notsupp_test,
3806                                 NULL, test_command_generic);
3807         test_bredrle("Set BR/EDR off - Rejected 1",
3808                                 &set_bredr_off_failure_test_1,
3809                                 NULL, test_command_generic);
3810         test_bredrle("Set BR/EDR off - Rejected 2",
3811                                 &set_bredr_off_failure_test_2,
3812                                 NULL, test_command_generic);
3813         test_bredrle("Set BR/EDR off - Invalid Parameters 1",
3814                                 &set_bredr_off_failure_test_3,
3815                                 NULL, test_command_generic);
3816
3817         test_bredr("Set Local Name - Success 1",
3818                                 &set_local_name_test_1,
3819                                 NULL, test_command_generic);
3820         test_bredr("Set Local Name - Success 2",
3821                                 &set_local_name_test_2,
3822                                 NULL, test_command_generic);
3823         test_bredr("Set Local Name - Success 3",
3824                                 &set_local_name_test_3,
3825                                 NULL, test_command_generic);
3826
3827         test_bredrle("Start Discovery - Not powered 1",
3828                                 &start_discovery_not_powered_test_1,
3829                                 NULL, test_command_generic);
3830         test_bredrle("Start Discovery - Invalid parameters 1",
3831                                 &start_discovery_invalid_param_test_1,
3832                                 NULL, test_command_generic);
3833         test_bredrle("Start Discovery - Not supported 1",
3834                                 &start_discovery_not_supported_test_1,
3835                                 NULL, test_command_generic);
3836         test_bredrle("Start Discovery - Success 1",
3837                                 &start_discovery_valid_param_test_1,
3838                                 NULL, test_command_generic);
3839         test_le("Start Discovery - Success 2",
3840                                 &start_discovery_valid_param_test_2,
3841                                 NULL, test_command_generic);
3842
3843         test_bredrle("Stop Discovery - Success 1",
3844                                 &stop_discovery_success_test_1,
3845                                 setup_start_discovery, test_command_generic);
3846         test_bredr("Stop Discovery - BR/EDR (Inquiry) Success 1",
3847                                 &stop_discovery_bredr_success_test_1,
3848                                 setup_start_discovery, test_command_generic);
3849         test_bredrle("Stop Discovery - Rejected 1",
3850                                 &stop_discovery_rejected_test_1,
3851                                 NULL, test_command_generic);
3852         test_bredrle("Stop Discovery - Invalid parameters 1",
3853                                 &stop_discovery_invalid_param_test_1,
3854                                 setup_start_discovery, test_command_generic);
3855
3856         test_bredrle("Set Device Class - Success 1",
3857                                 &set_dev_class_valid_param_test_1,
3858                                 NULL, test_command_generic);
3859         test_bredrle("Set Device Class - Success 2",
3860                                 &set_dev_class_valid_param_test_2,
3861                                 NULL, test_command_generic);
3862         test_bredrle("Set Device Class - Invalid parameters 1",
3863                                 &set_dev_class_invalid_param_test_1,
3864                                 NULL, test_command_generic);
3865
3866         test_bredrle("Add UUID - UUID-16 1",
3867                                 &add_uuid16_test_1,
3868                                 NULL, test_command_generic);
3869         test_bredrle("Add UUID - UUID-16 multiple 1",
3870                                 &add_multi_uuid16_test_1,
3871                                 setup_multi_uuid16, test_command_generic);
3872         test_bredrle("Add UUID - UUID-16 partial 1",
3873                                 &add_multi_uuid16_test_2,
3874                                 setup_multi_uuid16_2, test_command_generic);
3875         test_bredrle("Add UUID - UUID-32 1",
3876                                 &add_uuid32_test_1,
3877                                 NULL, test_command_generic);
3878         test_bredrle("Add UUID - UUID-32 multiple 1",
3879                                 &add_uuid32_multi_test_1,
3880                                 setup_multi_uuid32, test_command_generic);
3881         test_bredrle("Add UUID - UUID-32 partial 1",
3882                                 &add_uuid32_multi_test_2,
3883                                 setup_multi_uuid32_2, test_command_generic);
3884         test_bredrle("Add UUID - UUID-128 1",
3885                                 &add_uuid128_test_1,
3886                                 NULL, test_command_generic);
3887         test_bredrle("Add UUID - UUID-128 multiple 1",
3888                                 &add_uuid128_multi_test_1,
3889                                 setup_multi_uuid128, test_command_generic);
3890         test_bredrle("Add UUID - UUID-128 partial 1",
3891                                 &add_uuid128_multi_test_2,
3892                                 setup_multi_uuid128_2, test_command_generic);
3893         test_bredrle("Add UUID - UUID mix",
3894                                 &add_uuid_mix_test_1,
3895                                 setup_uuid_mix, test_command_generic);
3896
3897         test_bredrle("Load Link Keys - Empty List Success 1",
3898                                 &load_link_keys_success_test_1,
3899                                 NULL, test_command_generic);
3900         test_bredrle("Load Link Keys - Empty List Success 2",
3901                                 &load_link_keys_success_test_2,
3902                                 NULL, test_command_generic);
3903         test_bredrle("Load Link Keys - Invalid Parameters 1",
3904                                 &load_link_keys_invalid_params_test_1,
3905                                 NULL, test_command_generic);
3906         test_bredrle("Load Link Keys - Invalid Parameters 2",
3907                                 &load_link_keys_invalid_params_test_2,
3908                                 NULL, test_command_generic);
3909         test_bredrle("Load Link Keys - Invalid Parameters 3",
3910                                 &load_link_keys_invalid_params_test_3,
3911                                 NULL, test_command_generic);
3912
3913         test_bredrle("Load Long Term Keys - Success 1",
3914                                 &load_ltks_success_test_1,
3915                                 NULL, test_command_generic);
3916         test_bredrle("Load Long Term Keys - Invalid Parameters 1",
3917                                 &load_ltks_invalid_params_test_1,
3918                                 NULL, test_command_generic);
3919         test_bredrle("Load Long Term Keys - Invalid Parameters 2",
3920                                 &load_ltks_invalid_params_test_2,
3921                                 NULL, test_command_generic);
3922         test_bredrle("Load Long Term Keys - Invalid Parameters 3",
3923                                 &load_ltks_invalid_params_test_3,
3924                                 NULL, test_command_generic);
3925
3926         test_bredrle("Pair Device - Not Powered 1",
3927                                 &pair_device_not_powered_test_1,
3928                                 NULL, test_command_generic);
3929         test_bredrle("Pair Device - Invalid Parameters 1",
3930                                 &pair_device_invalid_param_test_1,
3931                                 NULL, test_command_generic);
3932         test_bredrle("Pair Device - Legacy Success 1",
3933                                 &pair_device_success_test_1,
3934                                 NULL, test_command_generic);
3935         test_bredrle("Pair Device - Sec Mode 3 Success 1",
3936                                 &pair_device_success_test_2,
3937                                 NULL, test_command_generic);
3938         test_bredrle("Pair Device - Legacy Reject 1",
3939                                 &pair_device_reject_test_1,
3940                                 NULL, test_command_generic);
3941         test_bredrle("Pair Device - Legacy Reject 2",
3942                                 &pair_device_reject_test_2,
3943                                 NULL, test_command_generic);
3944         test_bredrle("Pair Device - Sec Mode 3 Reject 1",
3945                                 &pair_device_reject_test_3,
3946                                 NULL, test_command_generic);
3947         test_bredrle("Pair Device - Sec Mode 3 Reject 2",
3948                                 &pair_device_reject_test_4,
3949                                 NULL, test_command_generic);
3950         test_bredrle("Pair Device - SSP Just-Works Success 1",
3951                                 &pair_device_ssp_test_1,
3952                                 NULL, test_command_generic);
3953         test_bredrle("Pair Device - SSP Confirm Success 1",
3954                                 &pair_device_ssp_test_2,
3955                                 NULL, test_command_generic);
3956         test_bredrle("Pair Device - SSP Confirm Reject 1",
3957                                 &pair_device_ssp_reject_1,
3958                                 NULL, test_command_generic);
3959         test_bredrle("Pair Device - SSP Confirm Reject 2",
3960                                 &pair_device_ssp_reject_2,
3961                                 NULL, test_command_generic);
3962         test_bredrle("Pair Device - SSP Non-pairable 1",
3963                                 &pair_device_ssp_nonpairable_1,
3964                                 NULL, test_command_generic);
3965
3966         test_bredrle("Pairing Acceptor - Legacy 1",
3967                                 &pairing_acceptor_legacy_1, NULL,
3968                                 test_pairing_acceptor);
3969         test_bredrle("Pairing Acceptor - Legacy 2",
3970                                 &pairing_acceptor_legacy_2, NULL,
3971                                 test_pairing_acceptor);
3972         test_bredrle("Pairing Acceptor - Link Sec 1",
3973                                 &pairing_acceptor_linksec_1, NULL,
3974                                 test_pairing_acceptor);
3975         test_bredrle("Pairing Acceptor - Link Sec 2",
3976                                 &pairing_acceptor_linksec_2, NULL,
3977                                 test_pairing_acceptor);
3978         test_bredrle("Pairing Acceptor - SSP 1",
3979                                 &pairing_acceptor_ssp_1, setup_ssp_acceptor,
3980                                 test_pairing_acceptor);
3981         test_bredrle("Pairing Acceptor - SSP 2",
3982                                 &pairing_acceptor_ssp_2, setup_ssp_acceptor,
3983                                 test_pairing_acceptor);
3984
3985         test_bredrle("Unpair Device - Not Powered 1",
3986                                 &unpair_device_not_powered_test_1,
3987                                 NULL, test_command_generic);
3988         test_bredrle("Unpair Device - Invalid Parameters 1",
3989                                 &unpair_device_invalid_param_test_1,
3990                                 NULL, test_command_generic);
3991         test_bredrle("Unpair Device - Invalid Parameters 2",
3992                                 &unpair_device_invalid_param_test_2,
3993                                 NULL, test_command_generic);
3994
3995         test_bredrle("Disconnect - Invalid Parameters 1",
3996                                 &disconnect_invalid_param_test_1,
3997                                 NULL, test_command_generic);
3998
3999         test_bredrle("Block Device - Invalid Parameters 1",
4000                                 &block_device_invalid_param_test_1,
4001                                 NULL, test_command_generic);
4002
4003         test_bredrle("Unblock Device - Invalid Parameters 1",
4004                                 &unblock_device_invalid_param_test_1,
4005                                 NULL, test_command_generic);
4006
4007         test_bredrle("Set Static Address - Success",
4008                                 &set_static_addr_success_test,
4009                                 NULL, test_command_generic);
4010         test_bredrle("Set Static Address - Failure",
4011                                 &set_static_addr_failure_test,
4012                                 NULL, test_command_generic);
4013
4014         test_bredrle("Set Scan Parameters - Success",
4015                                 &set_scan_params_success_test,
4016                                 NULL, test_command_generic);
4017
4018         test_bredrle("Load IRKs - Success 1",
4019                                 &load_irks_success1_test,
4020                                 NULL, test_command_generic);
4021         test_bredrle("Load IRKs - Success 2",
4022                                 &load_irks_success2_test,
4023                                 NULL, test_command_generic);
4024         test_bredrle("Load IRKs - Invalid Parameters 1",
4025                                 &load_irks_nval_param1_test,
4026                                 NULL, test_command_generic);
4027         test_bredrle("Load IRKs - Invalid Parameters 2",
4028                                 &load_irks_nval_param2_test,
4029                                 NULL, test_command_generic);
4030         test_bredrle("Load IRKs - Invalid Parameters 3",
4031                                 &load_irks_nval_param3_test,
4032                                 NULL, test_command_generic);
4033         test_bredr("Load IRKs - Not Supported",
4034                                 &load_irks_not_supported_test,
4035                                 NULL, test_command_generic);
4036
4037         test_bredrle("Set Privacy - Success",
4038                                 &set_privacy_success_test,
4039                                 NULL, test_command_generic);
4040         test_bredrle("Set Privacy - Rejected",
4041                                 &set_privacy_powered_test,
4042                                 NULL, test_command_generic);
4043         test_bredrle("Set Privacy - Invalid Parameters",
4044                                 &set_privacy_nval_param_test,
4045                                 NULL, test_command_generic);
4046
4047         return tester_run();
4048 }