3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
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.
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.
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
32 #include <sys/socket.h>
36 #include "lib/bluetooth.h"
40 #include "monitor/bt.h"
41 #include "emulator/bthost.h"
42 #include "emulator/hciemu.h"
44 #include "src/shared/crypto.h"
45 #include "src/shared/ecc.h"
46 #include "src/shared/tester.h"
47 #include "src/shared/mgmt.h"
49 #define SMP_CID 0x0006
52 const void *test_data;
55 struct hciemu *hciemu;
56 enum hciemu_type hciemu_type;
65 struct bt_crypto *crypto;
73 uint8_t remote_pk[64];
88 const struct smp_req_rsp *req;
91 uint16_t expect_hci_command;
92 const void *expect_hci_param;
93 uint8_t expect_hci_len;
94 const void * (*expect_hci_func)(uint8_t *len);
98 static void mgmt_debug(const char *str, void *user_data)
100 const char *prefix = user_data;
102 tester_print("%s%s", prefix, str);
105 static void read_info_callback(uint8_t status, uint16_t length,
106 const void *param, void *user_data)
108 struct test_data *data = tester_get_data();
109 const struct mgmt_rp_read_info *rp = param;
111 uint16_t manufacturer;
112 uint32_t supported_settings, current_settings;
114 tester_print("Read Info callback");
115 tester_print(" Status: 0x%02x", status);
117 if (status || !param) {
118 tester_pre_setup_failed();
122 ba2str(&rp->bdaddr, addr);
123 manufacturer = btohs(rp->manufacturer);
124 supported_settings = btohl(rp->supported_settings);
125 current_settings = btohl(rp->current_settings);
127 tester_print(" Address: %s", addr);
128 tester_print(" Version: 0x%02x", rp->version);
129 tester_print(" Manufacturer: 0x%04x", manufacturer);
130 tester_print(" Supported settings: 0x%08x", supported_settings);
131 tester_print(" Current settings: 0x%08x", current_settings);
132 tester_print(" Class: 0x%02x%02x%02x",
133 rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
134 tester_print(" Name: %s", rp->name);
135 tester_print(" Short name: %s", rp->short_name);
137 if (strcmp(hciemu_get_address(data->hciemu), addr)) {
138 tester_pre_setup_failed();
142 tester_pre_setup_complete();
145 static void index_added_callback(uint16_t index, uint16_t length,
146 const void *param, void *user_data)
148 struct test_data *data = tester_get_data();
150 tester_print("Index Added callback");
151 tester_print(" Index: 0x%04x", index);
153 data->mgmt_index = index;
155 mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
156 read_info_callback, NULL, NULL);
159 static void index_removed_callback(uint16_t index, uint16_t length,
160 const void *param, void *user_data)
162 struct test_data *data = tester_get_data();
164 tester_print("Index Removed callback");
165 tester_print(" Index: 0x%04x", index);
167 if (index != data->mgmt_index)
170 mgmt_unregister_index(data->mgmt, data->mgmt_index);
172 mgmt_unref(data->mgmt);
175 tester_post_teardown_complete();
178 static void read_index_list_callback(uint8_t status, uint16_t length,
179 const void *param, void *user_data)
181 struct test_data *data = tester_get_data();
183 tester_print("Read Index List callback");
184 tester_print(" Status: 0x%02x", status);
186 if (status || !param) {
187 tester_pre_setup_failed();
191 mgmt_register(data->mgmt, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
192 index_added_callback, NULL, NULL);
194 mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
195 index_removed_callback, NULL, NULL);
197 data->hciemu = hciemu_new(data->hciemu_type);
199 tester_warn("Failed to setup HCI emulation");
200 tester_pre_setup_failed();
203 tester_print("New hciemu instance created");
206 static void test_pre_setup(const void *test_data)
208 struct test_data *data = tester_get_data();
210 data->crypto = bt_crypto_new();
212 tester_warn("Failed to setup crypto");
213 tester_pre_setup_failed();
217 data->mgmt = mgmt_new_default();
219 tester_warn("Failed to setup management interface");
220 bt_crypto_unref(data->crypto);
221 tester_pre_setup_failed();
225 if (tester_use_debug())
226 mgmt_set_debug(data->mgmt, mgmt_debug, "mgmt: ", NULL);
228 mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0, NULL,
229 read_index_list_callback, NULL, NULL);
232 static void test_post_teardown(const void *test_data)
234 struct test_data *data = tester_get_data();
236 if (data->io_id > 0) {
237 g_source_remove(data->io_id);
242 bt_crypto_unref(data->crypto);
246 hciemu_unref(data->hciemu);
250 static void test_data_free(void *test_data)
252 struct test_data *data = test_data;
257 static void test_add_condition(struct test_data *data)
259 data->unmet_conditions++;
261 tester_print("Test condition added, total %d", data->unmet_conditions);
264 static void test_condition_complete(struct test_data *data)
266 data->unmet_conditions--;
268 tester_print("Test condition complete, %d left",
269 data->unmet_conditions);
271 if (data->unmet_conditions > 0)
274 tester_test_passed();
277 #define test_smp(name, data, setup, func) \
279 struct test_data *user; \
280 user = calloc(1, sizeof(struct test_data)); \
283 user->hciemu_type = HCIEMU_TYPE_BREDRLE; \
284 user->test_data = data; \
285 tester_add_full(name, data, \
286 test_pre_setup, setup, func, NULL, \
287 test_post_teardown, 2, user, test_data_free); \
290 static const uint8_t smp_nval_req_1[] = { 0x0b, 0x00 };
291 static const uint8_t smp_nval_req_1_rsp[] = { 0x05, 0x07 };
293 static const struct smp_req_rsp nval_req_1[] = {
294 { smp_nval_req_1, sizeof(smp_nval_req_1),
295 smp_nval_req_1_rsp, sizeof(smp_nval_req_1_rsp) },
298 static const struct smp_data smp_server_nval_req_1_test = {
300 .req_count = G_N_ELEMENTS(nval_req_1),
303 static const uint8_t smp_nval_req_2[7] = { 0x01 };
304 static const uint8_t smp_nval_req_2_rsp[] = { 0x05, 0x06 };
306 static const struct smp_req_rsp srv_nval_req_1[] = {
307 { smp_nval_req_2, sizeof(smp_nval_req_2),
308 smp_nval_req_2_rsp, sizeof(smp_nval_req_2_rsp) },
311 static const struct smp_data smp_server_nval_req_2_test = {
312 .req = srv_nval_req_1,
313 .req_count = G_N_ELEMENTS(srv_nval_req_1),
316 static const uint8_t smp_nval_req_3[] = { 0x01, 0xff };
317 static const uint8_t smp_nval_req_3_rsp[] = { 0x05, 0x0a };
319 static const struct smp_req_rsp srv_nval_req_2[] = {
320 { smp_nval_req_3, sizeof(smp_nval_req_3),
321 smp_nval_req_3_rsp, sizeof(smp_nval_req_3_rsp) },
324 static const struct smp_data smp_server_nval_req_3_test = {
325 .req = srv_nval_req_2,
326 .req_count = G_N_ELEMENTS(srv_nval_req_2),
329 static const uint8_t smp_nval_req_4[] = { 0xff, 0xff };
330 static const uint8_t smp_nval_req_4_rsp[] = { 0x05, 0x07 };
332 static const struct smp_req_rsp srv_nval_req_3[] = {
333 { smp_nval_req_4, sizeof(smp_nval_req_4), NULL, 0 },
336 static const uint8_t smp_basic_req_1[] = { 0x01, /* Pairing Request */
337 0x03, /* NoInputNoOutput */
339 0x01, /* Bonding - no MITM */
340 0x10, /* Max key size */
341 0x05, /* Init. key dist. */
342 0x05, /* Rsp. key dist. */
344 static const uint8_t smp_basic_req_1_rsp[] = { 0x02, /* Pairing Response */
345 0x03, /* NoInputNoOutput */
347 0x01, /* Bonding - no MITM */
348 0x10, /* Max key size */
349 0x05, /* Init. key dist. */
350 0x05, /* Rsp. key dist. */
353 static const uint8_t smp_confirm_req_1[17] = { 0x03 };
354 static const uint8_t smp_random_req_1[17] = { 0x04 };
356 static const struct smp_req_rsp srv_basic_req_1[] = {
357 { smp_basic_req_1, sizeof(smp_basic_req_1),
358 smp_basic_req_1_rsp, sizeof(smp_basic_req_1_rsp) },
359 { smp_confirm_req_1, sizeof(smp_confirm_req_1),
360 smp_confirm_req_1, sizeof(smp_confirm_req_1) },
361 { smp_random_req_1, sizeof(smp_random_req_1),
362 smp_random_req_1, sizeof(smp_random_req_1) },
365 static const struct smp_data smp_server_basic_req_1_test = {
366 .req = srv_basic_req_1,
367 .req_count = G_N_ELEMENTS(srv_basic_req_1),
370 static const struct smp_req_rsp cli_basic_req_1[] = {
371 { NULL, 0, smp_basic_req_1, sizeof(smp_basic_req_1) },
372 { smp_basic_req_1_rsp, sizeof(smp_basic_req_1_rsp),
373 smp_confirm_req_1, sizeof(smp_confirm_req_1) },
374 { smp_confirm_req_1, sizeof(smp_confirm_req_1),
375 smp_random_req_1, sizeof(smp_random_req_1) },
376 { smp_random_req_1, sizeof(smp_random_req_1), NULL, 0 },
379 static const struct smp_data smp_client_basic_req_1_test = {
380 .req = cli_basic_req_1,
381 .req_count = G_N_ELEMENTS(cli_basic_req_1),
384 static const uint8_t smp_basic_req_2[] = { 0x01, /* Pairing Request */
385 0x04, /* NoInputNoOutput */
387 0x05, /* Bonding - MITM */
388 0x10, /* Max key size */
389 0x05, /* Init. key dist. */
390 0x05, /* Rsp. key dist. */
393 static const struct smp_req_rsp cli_basic_req_2[] = {
394 { NULL, 0, smp_basic_req_2, sizeof(smp_basic_req_2) },
395 { smp_basic_req_1_rsp, sizeof(smp_basic_req_1_rsp),
396 smp_confirm_req_1, sizeof(smp_confirm_req_1) },
397 { smp_confirm_req_1, sizeof(smp_confirm_req_1),
398 smp_random_req_1, sizeof(smp_random_req_1) },
399 { smp_random_req_1, sizeof(smp_random_req_1), NULL, 0 },
402 static const struct smp_data smp_client_basic_req_2_test = {
403 .req = cli_basic_req_2,
404 .req_count = G_N_ELEMENTS(cli_basic_req_1),
408 static void user_confirm_request_callback(uint16_t index, uint16_t length,
412 const struct mgmt_ev_user_confirm_request *ev = param;
413 struct test_data *data = tester_get_data();
414 struct mgmt_cp_user_confirm_reply cp;
416 memset(&cp, 0, sizeof(cp));
417 memcpy(&cp.addr, &ev->addr, sizeof(cp.addr));
419 mgmt_reply(data->mgmt, MGMT_OP_USER_CONFIRM_REPLY,
420 data->mgmt_index, sizeof(cp), &cp, NULL, NULL, NULL);
423 static const uint8_t smp_sc_req_1[] = { 0x01, /* Pairing Request */
424 0x03, /* NoInputNoOutput */
426 0x09, /* Bonding - no MITM, SC */
427 0x10, /* Max key size */
428 0x0d, /* Init. key dist. */
429 0x0d, /* Rsp. key dist. */
432 static const struct smp_req_rsp cli_sc_req_1[] = {
433 { NULL, 0, smp_sc_req_1, sizeof(smp_sc_req_1) },
434 { smp_basic_req_1_rsp, sizeof(smp_basic_req_1_rsp),
435 smp_confirm_req_1, sizeof(smp_confirm_req_1) },
436 { smp_confirm_req_1, sizeof(smp_confirm_req_1),
437 smp_random_req_1, sizeof(smp_random_req_1) },
438 { smp_random_req_1, sizeof(smp_random_req_1), NULL, 0 },
441 static const struct smp_data smp_client_sc_req_1_test = {
443 .req_count = G_N_ELEMENTS(cli_sc_req_1),
447 static const uint8_t smp_sc_rsp_1[] = { 0x02, /* Pairing Response */
448 0x03, /* NoInputNoOutput */
450 0x09, /* Bonding - no MITM, SC */
451 0x10, /* Max key size */
452 0x0d, /* Init. key dist. */
453 0x0d, /* Rsp. key dist. */
456 static const uint8_t smp_sc_pk[65] = { 0x0c };
458 static const uint8_t smp_sc_failed_rsp_1[] = { 0x05, 0x08 };
460 static const struct smp_req_rsp cli_sc_req_2[] = {
461 { NULL, 0, smp_sc_req_1, sizeof(smp_sc_req_1) },
462 { smp_sc_rsp_1, sizeof(smp_sc_rsp_1), smp_sc_pk, sizeof(smp_sc_pk) },
463 { smp_sc_pk, sizeof(smp_sc_pk), NULL, 0 },
464 { smp_confirm_req_1, sizeof(smp_confirm_req_1),
465 smp_random_req_1, sizeof(smp_random_req_1) },
466 { smp_random_req_1, sizeof(smp_random_req_1), NULL, 0 },
469 static const struct smp_data smp_client_sc_req_2_test = {
471 .req_count = G_N_ELEMENTS(cli_sc_req_2),
475 static void client_connectable_complete(uint16_t opcode, uint8_t status,
476 const void *param, uint8_t len,
479 if (opcode != BT_HCI_CMD_LE_SET_ADV_ENABLE)
482 tester_print("Client set connectable status 0x%02x", status);
485 tester_setup_failed();
487 tester_setup_complete();
490 static void setup_powered_client_callback(uint8_t status, uint16_t length,
491 const void *param, void *user_data)
493 struct test_data *data = tester_get_data();
494 struct bthost *bthost;
496 if (status != MGMT_STATUS_SUCCESS) {
497 tester_setup_failed();
501 tester_print("Controller powered on");
503 bthost = hciemu_client_get_host(data->hciemu);
504 bthost_set_cmd_complete_cb(bthost, client_connectable_complete, data);
505 bthost_set_adv_enable(bthost, 0x01, 0x00);
508 static void make_pk(struct test_data *data)
510 if (!ecc_make_key(data->local_pk, data->local_sk)) {
511 tester_print("Failed to general local ECDH keypair");
512 tester_setup_failed();
517 static void setup_powered_client(const void *test_data)
519 struct test_data *data = tester_get_data();
520 const struct smp_data *smp = data->test_data;
521 unsigned char param[] = { 0x01 };
523 tester_print("Powering on controller");
525 mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
526 sizeof(param), param, NULL, NULL, NULL);
527 mgmt_send(data->mgmt, MGMT_OP_SET_BONDABLE, data->mgmt_index,
528 sizeof(param), param, NULL, NULL, NULL);
530 mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index,
531 sizeof(param), param, NULL, NULL, NULL);
532 mgmt_send(data->mgmt, MGMT_OP_SET_SECURE_CONN,
533 data->mgmt_index, sizeof(param), param, NULL,
538 mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
539 sizeof(param), param, setup_powered_client_callback,
543 static void pair_device_complete(uint8_t status, uint16_t length,
544 const void *param, void *user_data)
546 if (status != MGMT_STATUS_SUCCESS) {
547 tester_warn("Pairing failed: %s", mgmt_errstr(status));
551 tester_print("Pairing succeedded");
554 static const void *get_pdu(const uint8_t *pdu)
556 struct test_data *data = tester_get_data();
557 const struct smp_data *smp = data->test_data;
558 uint8_t opcode = pdu[0];
559 static uint8_t buf[65];
562 case 0x01: /* Pairing Request */
563 memcpy(data->preq, pdu, sizeof(data->preq));
565 case 0x02: /* Pairing Response */
566 memcpy(data->prsp, pdu, sizeof(data->prsp));
568 case 0x03: /* Pairing Confirm */
571 bt_crypto_f4(data->crypto, data->local_pk,
572 data->remote_pk, data->prnd, 0,
575 bt_crypto_c1(data->crypto, data->tk, data->prnd,
576 data->prsp, data->preq, data->ia_type,
577 data->ia, data->ra_type, data->ra,
580 case 0x04: /* Pairing Random */
582 memcpy(&buf[1], data->prnd, 16);
584 case 0x0c: /* Public Key */
586 memcpy(&buf[1], data->local_pk, 64);
595 static bool verify_random(const uint8_t rnd[16])
597 struct test_data *data = tester_get_data();
600 if (!bt_crypto_c1(data->crypto, data->tk, data->rrnd, data->prsp,
601 data->preq, data->ia_type, data->ia,
602 data->ra_type, data->ra, confirm))
605 if (memcmp(data->pcnf, confirm, sizeof(data->pcnf) != 0)) {
606 tester_warn("Confirmation values don't match");
611 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
612 bt_crypto_s1(data->crypto, data->tk, data->rrnd, data->prnd,
614 bthost_le_start_encrypt(bthost, data->handle, data->ltk);
616 bt_crypto_s1(data->crypto, data->tk, data->prnd, data->rrnd,
623 static bool sc_random(struct test_data *test_data)
628 static void smp_server(const void *data, uint16_t len, void *user_data)
630 struct test_data *test_data = user_data;
631 struct bthost *bthost = hciemu_client_get_host(test_data->hciemu);
632 const struct smp_data *smp = test_data->test_data;
633 const struct smp_req_rsp *req;
638 tester_warn("Received too small SMP PDU");
642 opcode = *((const uint8_t *) data);
644 tester_print("Received SMP opcode 0x%02x", opcode);
646 if (test_data->counter >= smp->req_count) {
647 test_condition_complete(test_data);
651 req = &smp->req[test_data->counter++];
655 if (req->expect_len != len) {
656 tester_warn("Unexpected SMP PDU length (%u != %u)",
657 len, req->expect_len);
662 case 0x01: /* Pairing Request */
663 memcpy(test_data->preq, data, sizeof(test_data->preq));
665 case 0x02: /* Pairing Response */
666 memcpy(test_data->prsp, data, sizeof(test_data->prsp));
668 case 0x03: /* Pairing Confirm */
669 memcpy(test_data->pcnf, data + 1, 16);
671 case 0x04: /* Pairing Random */
672 memcpy(test_data->rrnd, data + 1, 16);
674 if (!sc_random(test_data))
677 if (!verify_random(data + 1))
681 case 0x0c: /* Public Key */
682 memcpy(test_data->remote_pk, data + 1, 64);
683 ecdh_shared_secret(test_data->remote_pk, test_data->local_sk,
690 if (memcmp(req->expect, data, len) != 0) {
691 tester_warn("Unexpected SMP PDU");
697 if (smp->req_count == test_data->counter) {
698 test_condition_complete(test_data);
702 req = &smp->req[test_data->counter];
704 pdu = get_pdu(req->send);
705 bthost_send_cid(bthost, test_data->handle, SMP_CID, pdu,
710 test_data->counter++;
716 tester_test_failed();
719 static void command_hci_callback(uint16_t opcode, const void *param,
720 uint8_t length, void *user_data)
722 struct test_data *data = user_data;
723 const struct smp_data *smp = data->test_data;
724 const void *expect_hci_param = smp->expect_hci_param;
725 uint8_t expect_hci_len = smp->expect_hci_len;
727 tester_print("HCI Command 0x%04x length %u", opcode, length);
729 if (opcode != smp->expect_hci_command)
732 if (smp->expect_hci_func)
733 expect_hci_param = smp->expect_hci_func(&expect_hci_len);
735 if (length != expect_hci_len) {
736 tester_warn("Invalid parameter size for HCI command");
737 tester_test_failed();
741 if (memcmp(param, expect_hci_param, length) != 0) {
742 tester_warn("Unexpected HCI command parameter value");
743 tester_test_failed();
747 test_condition_complete(data);
750 static void smp_new_conn(uint16_t handle, void *user_data)
752 struct test_data *data = user_data;
753 const struct smp_data *smp = data->test_data;
754 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
755 const struct smp_req_rsp *req;
758 tester_print("New SMP client connection with handle 0x%04x", handle);
760 data->handle = handle;
762 bthost_add_cid_hook(bthost, handle, SMP_CID, smp_server, data);
764 if (smp->req_count == data->counter)
767 req = &smp->req[data->counter];
772 tester_print("Sending SMP PDU");
774 pdu = get_pdu(req->send);
775 bthost_send_cid(bthost, handle, SMP_CID, pdu, req->send_len);
778 test_condition_complete(data);
781 static void init_bdaddr(struct test_data *data)
783 const uint8_t *master_bdaddr, *client_bdaddr;
785 master_bdaddr = hciemu_get_master_bdaddr(data->hciemu);
786 if (!master_bdaddr) {
787 tester_warn("No master bdaddr");
788 tester_test_failed();
792 client_bdaddr = hciemu_get_client_bdaddr(data->hciemu);
793 if (!client_bdaddr) {
794 tester_warn("No client bdaddr");
795 tester_test_failed();
799 data->ia_type = LE_PUBLIC_ADDRESS;
800 data->ra_type = LE_PUBLIC_ADDRESS;
803 memcpy(data->ia, client_bdaddr, sizeof(data->ia));
804 memcpy(data->ra, master_bdaddr, sizeof(data->ra));
806 memcpy(data->ia, master_bdaddr, sizeof(data->ia));
807 memcpy(data->ra, client_bdaddr, sizeof(data->ra));
811 static void test_client(const void *test_data)
813 struct test_data *data = tester_get_data();
814 const struct smp_data *smp = data->test_data;
815 struct mgmt_cp_pair_device cp;
816 struct bthost *bthost;
820 bthost = hciemu_client_get_host(data->hciemu);
821 bthost_set_connect_cb(bthost, smp_new_conn, data);
822 test_add_condition(data);
824 if (smp->expect_hci_command) {
825 tester_print("Registering HCI command callback");
826 hciemu_add_master_post_command_hook(data->hciemu,
827 command_hci_callback, data);
828 test_add_condition(data);
831 memcpy(&cp.addr.bdaddr, data->ra, sizeof(data->ra));
832 cp.addr.type = BDADDR_LE_PUBLIC;
834 cp.io_cap = 0x04; /* KeyboardDisplay */
836 cp.io_cap = 0x03; /* NoInputNoOutput */
838 mgmt_send(data->mgmt, MGMT_OP_PAIR_DEVICE, data->mgmt_index,
839 sizeof(cp), &cp, pair_device_complete, NULL, NULL);
841 tester_print("Pairing in progress");
844 static void setup_powered_server_callback(uint8_t status, uint16_t length,
845 const void *param, void *user_data)
847 if (status != MGMT_STATUS_SUCCESS) {
848 tester_setup_failed();
852 tester_print("Controller powered on");
854 tester_setup_complete();
857 static void setup_powered_server(const void *test_data)
859 struct test_data *data = tester_get_data();
860 const struct smp_data *smp = data->test_data;
861 unsigned char param[] = { 0x01 };
863 mgmt_register(data->mgmt, MGMT_EV_USER_CONFIRM_REQUEST,
864 data->mgmt_index, user_confirm_request_callback,
867 tester_print("Powering on controller");
869 mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
870 sizeof(param), param, NULL, NULL, NULL);
871 mgmt_send(data->mgmt, MGMT_OP_SET_BONDABLE, data->mgmt_index,
872 sizeof(param), param, NULL, NULL, NULL);
873 mgmt_send(data->mgmt, MGMT_OP_SET_CONNECTABLE, data->mgmt_index,
874 sizeof(param), param, NULL, NULL, NULL);
875 mgmt_send(data->mgmt, MGMT_OP_SET_ADVERTISING, data->mgmt_index,
876 sizeof(param), param, NULL, NULL, NULL);
878 mgmt_send(data->mgmt, MGMT_OP_SET_SECURE_CONN,
879 data->mgmt_index, sizeof(param), param, NULL,
884 mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
885 sizeof(param), param, setup_powered_server_callback,
889 static void test_server(const void *test_data)
891 struct test_data *data = tester_get_data();
892 const struct smp_data *smp = data->test_data;
893 struct bthost *bthost;
899 bthost = hciemu_client_get_host(data->hciemu);
900 bthost_set_connect_cb(bthost, smp_new_conn, data);
901 test_add_condition(data);
903 bthost_hci_connect(bthost, data->ra, BDADDR_LE_PUBLIC);
905 if (smp->expect_hci_command) {
906 tester_print("Registering HCI command callback");
907 hciemu_add_master_post_command_hook(data->hciemu,
908 command_hci_callback, data);
909 test_add_condition(data);
913 int main(int argc, char *argv[])
915 tester_init(&argc, &argv);
917 test_smp("SMP Server - Basic Request 1",
918 &smp_server_basic_req_1_test,
919 setup_powered_server, test_server);
920 test_smp("SMP Server - Invalid Request 1",
921 &smp_server_nval_req_1_test,
922 setup_powered_server, test_server);
923 test_smp("SMP Server - Invalid Request 2",
924 &smp_server_nval_req_2_test,
925 setup_powered_server, test_server);
926 test_smp("SMP Server - Invalid Request 3",
927 &smp_server_nval_req_3_test,
928 setup_powered_server, test_server);
930 test_smp("SMP Client - Basic Request 1",
931 &smp_client_basic_req_1_test,
932 setup_powered_client, test_client);
933 test_smp("SMP Client - Basic Request 2",
934 &smp_client_basic_req_2_test,
935 setup_powered_client, test_client);
937 test_smp("SMP Client - SC Request 1",
938 &smp_client_sc_req_1_test,
939 setup_powered_client, test_client);
940 test_smp("SMP Client - SC Request 2",
941 &smp_client_sc_req_2_test,
942 setup_powered_client, test_client);