http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_os_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_os_test.c b/net/nimble/host/test/src/ble_os_test.c new file mode 100644 index 0000000..2b2da51 --- /dev/null +++ b/net/nimble/host/test/src/ble_os_test.c @@ -0,0 +1,401 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <string.h> +#include "os/os.h" +#include "testutil/testutil.h" +#include "nimble/hci_common.h" +#include "nimble/ble_hci_trans.h" +#include "host/ble_hs_test.h" +#include "host/ble_gap.h" +#include "ble_hs_test_util.h" + +#define BLE_OS_TEST_STACK_SIZE 256 +#define BLE_OS_TEST_APP_STACK_SIZE 256 + +#define BLE_OS_TEST_APP_PRIO 9 +#define BLE_OS_TEST_TASK_PRIO 10 + +static struct os_task ble_os_test_task; +static struct os_task ble_os_test_app_task; +static os_stack_t ble_os_test_stack[OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE)]; + +static os_stack_t +ble_os_test_app_stack[OS_STACK_ALIGN(BLE_OS_TEST_APP_STACK_SIZE)]; + +static uint8_t ble_os_test_peer_addr[6] = { 1, 2, 3, 4, 5, 6 }; + +static void ble_os_test_app_task_handler(void *arg); + +static int ble_os_test_gap_event_type; + +static void +ble_os_test_init_app_task(void) +{ + int rc; + + rc = os_task_init(&ble_os_test_app_task, + "ble_gap_terminate_test_task", + ble_os_test_app_task_handler, NULL, + BLE_OS_TEST_APP_PRIO, OS_WAIT_FOREVER, + ble_os_test_app_stack, + OS_STACK_ALIGN(BLE_OS_TEST_APP_STACK_SIZE)); + TEST_ASSERT_FATAL(rc == 0); +} + +static void +ble_os_test_misc_init(void) +{ + ble_hs_test_util_init_no_start(); + + /* Receive acknowledgements for the startup sequence. We sent the + * corresponding requests when the host task was started. + */ + ble_hs_test_util_set_startup_acks(); + + ble_os_test_init_app_task(); +} + +static int +ble_os_test_misc_conn_exists(uint16_t conn_handle) +{ + struct ble_hs_conn *conn; + + ble_hs_lock(); + + if (conn_handle == BLE_HS_CONN_HANDLE_NONE) { + conn = ble_hs_conn_first(); + } else { + conn = ble_hs_conn_find(conn_handle); + } + + ble_hs_unlock(); + + return conn != NULL; +} + +static int +ble_gap_direct_connect_test_connect_cb(struct ble_gap_event *event, void *arg) +{ + struct ble_gap_conn_desc desc; + int *cb_called; + int rc; + + cb_called = arg; + *cb_called = 1; + + TEST_ASSERT(event->type == BLE_GAP_EVENT_CONNECT); + TEST_ASSERT(event->connect.status == 0); + TEST_ASSERT(event->connect.conn_handle == 2); + + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + TEST_ASSERT_FATAL(rc == 0); + TEST_ASSERT(desc.peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC); + TEST_ASSERT(memcmp(desc.peer_id_addr, ble_os_test_peer_addr, 6) == 0); + + return 0; +} + +static void +ble_gap_direct_connect_test_task_handler(void *arg) +{ + struct hci_le_conn_complete evt; + uint8_t addr[6] = { 1, 2, 3, 4, 5, 6 }; + int cb_called; + int rc; + + /* Set the connect callback so we can verify that it gets called with the + * proper arguments. + */ + cb_called = 0; + + /* Make sure there are no created connections and no connections in + * progress. + */ + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + + /* Initiate a direct connection. */ + ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC, + addr, 0, NULL, + ble_gap_direct_connect_test_connect_cb, + &cb_called, 0); + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + TEST_ASSERT(!cb_called); + + /* Receive an HCI connection-complete event. */ + memset(&evt, 0, sizeof evt); + evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE; + evt.status = BLE_ERR_SUCCESS; + evt.connection_handle = 2; + memcpy(evt.peer_addr, addr, 6); + rc = ble_gap_rx_conn_complete(&evt); + TEST_ASSERT(rc == 0); + + /* The connection should now be created. */ + TEST_ASSERT(ble_os_test_misc_conn_exists(2)); + TEST_ASSERT(cb_called); + + tu_restart(); +} + +TEST_CASE(ble_gap_direct_connect_test_case) +{ + ble_os_test_misc_init(); + + os_task_init(&ble_os_test_task, + "ble_gap_direct_connect_test_task", + ble_gap_direct_connect_test_task_handler, NULL, + BLE_OS_TEST_TASK_PRIO, OS_WAIT_FOREVER, ble_os_test_stack, + OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE)); + + os_start(); +} + +static int +ble_os_disc_test_cb(struct ble_gap_event *event, void *arg) +{ + int *cb_called; + + cb_called = arg; + *cb_called = 1; + + TEST_ASSERT(event->type == BLE_GAP_EVENT_DISC_COMPLETE); + + return 0; +} + +static void +ble_os_disc_test_task_handler(void *arg) +{ + struct ble_gap_disc_params disc_params; + int cb_called; + int rc; + + /* Receive acknowledgements for the startup sequence. We sent the + * corresponding requests when the host task was started. + */ + ble_hs_test_util_set_startup_acks(); + + /* Set the connect callback so we can verify that it gets called with the + * proper arguments. + */ + cb_called = 0; + + /* Make sure there are no created connections and no connections in + * progress. + */ + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + TEST_ASSERT(!ble_gap_master_in_progress()); + + /* Initiate the general discovery procedure with a 300 ms timeout. */ + memset(&disc_params, 0, sizeof disc_params); + rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, 300, &disc_params, + ble_os_disc_test_cb, + &cb_called, 0, 0); + TEST_ASSERT(rc == 0); + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + TEST_ASSERT(ble_gap_master_in_progress()); + TEST_ASSERT(!cb_called); + + /* Receive acks from the controller. */ + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + TEST_ASSERT(ble_gap_master_in_progress()); + TEST_ASSERT(!cb_called); + + /* Wait 100 ms; verify scan still in progress. */ + os_time_delay(100 * OS_TICKS_PER_SEC / 1000); + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + TEST_ASSERT(ble_gap_master_in_progress()); + TEST_ASSERT(!cb_called); + + ble_hs_test_util_set_ack( + ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, + BLE_HCI_OCF_LE_SET_SCAN_ENABLE), + 0); + + /* Wait 250 more ms; verify scan completed. */ + os_time_delay(250 * OS_TICKS_PER_SEC / 1000); + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + TEST_ASSERT(!ble_gap_master_in_progress()); + TEST_ASSERT(cb_called); + + tu_restart(); +} + +TEST_CASE(ble_os_disc_test_case) +{ + ble_os_test_misc_init(); + + os_task_init(&ble_os_test_task, + "ble_os_disc_test_task", + ble_os_disc_test_task_handler, NULL, + BLE_OS_TEST_TASK_PRIO, OS_WAIT_FOREVER, ble_os_test_stack, + OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE)); + + os_start(); +} + +static int +ble_gap_terminate_cb(struct ble_gap_event *event, void *arg) +{ + int *disconn_handle; + + ble_os_test_gap_event_type = event->type; + + if (event->type == BLE_GAP_EVENT_DISCONNECT) { + disconn_handle = arg; + *disconn_handle = event->disconnect.conn.conn_handle; + } + + return 0; +} + + +static void +ble_gap_terminate_test_task_handler(void *arg) +{ + struct hci_disconn_complete disconn_evt; + struct hci_le_conn_complete conn_evt; + uint8_t addr1[6] = { 1, 2, 3, 4, 5, 6 }; + uint8_t addr2[6] = { 2, 3, 4, 5, 6, 7 }; + int disconn_handle; + int rc; + + /* Receive acknowledgements for the startup sequence. We sent the + * corresponding requests when the host task was started. + */ + ble_hs_test_util_set_startup_acks(); + + /* Set the connect callback so we can verify that it gets called with the + * proper arguments. + */ + disconn_handle = 0; + + /* Make sure there are no created connections and no connections in + * progress. + */ + TEST_ASSERT(!ble_os_test_misc_conn_exists(BLE_HS_CONN_HANDLE_NONE)); + TEST_ASSERT(!ble_gap_master_in_progress()); + + /* Create two direct connections. */ + ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC, + addr1, 0, NULL, ble_gap_terminate_cb, + &disconn_handle, 0); + memset(&conn_evt, 0, sizeof conn_evt); + conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE; + conn_evt.status = BLE_ERR_SUCCESS; + conn_evt.connection_handle = 1; + memcpy(conn_evt.peer_addr, addr1, 6); + rc = ble_gap_rx_conn_complete(&conn_evt); + TEST_ASSERT(rc == 0); + + ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC, + addr2, 0, NULL, ble_gap_terminate_cb, + &disconn_handle, 0); + memset(&conn_evt, 0, sizeof conn_evt); + conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE; + conn_evt.status = BLE_ERR_SUCCESS; + conn_evt.connection_handle = 2; + memcpy(conn_evt.peer_addr, addr2, 6); + rc = ble_gap_rx_conn_complete(&conn_evt); + TEST_ASSERT(rc == 0); + + TEST_ASSERT_FATAL(ble_os_test_misc_conn_exists(1)); + TEST_ASSERT_FATAL(ble_os_test_misc_conn_exists(2)); + + /* Terminate the first one. */ + rc = ble_hs_test_util_conn_terminate(1, 0); + TEST_ASSERT(rc == 0); + disconn_evt.connection_handle = 1; + disconn_evt.status = 0; + disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM; + ble_hs_test_util_rx_disconn_complete_event(&disconn_evt); + TEST_ASSERT(ble_os_test_gap_event_type == BLE_GAP_EVENT_DISCONNECT); + TEST_ASSERT(disconn_handle == 1); + TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(1)); + TEST_ASSERT_FATAL(ble_os_test_misc_conn_exists(2)); + + /* Terminate the second one. */ + rc = ble_hs_test_util_conn_terminate(2, 0); + TEST_ASSERT(rc == 0); + disconn_evt.connection_handle = 2; + disconn_evt.status = 0; + disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM; + ble_hs_test_util_rx_disconn_complete_event(&disconn_evt); + TEST_ASSERT(ble_os_test_gap_event_type == BLE_GAP_EVENT_DISCONNECT); + TEST_ASSERT(disconn_handle == 2); + TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(1)); + TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(2)); + + tu_restart(); +} + +static void +ble_os_test_app_task_handler(void *arg) +{ + struct os_callout_func *cf; + struct os_event *ev; + int rc; + + rc = ble_hs_start(); + TEST_ASSERT(rc == 0); + + while (1) { + ev = os_eventq_get(&ble_hs_test_util_evq); + switch (ev->ev_type) { + case OS_EVENT_T_TIMER: + cf = (struct os_callout_func *)ev; + assert(cf->cf_func); + cf->cf_func(CF_ARG(cf)); + break; + default: + assert(0); + break; + } + } +} + +TEST_CASE(ble_gap_terminate_test_case) +{ + ble_os_test_misc_init(); + + os_task_init(&ble_os_test_task, + "ble_gap_terminate_test_task", + ble_gap_terminate_test_task_handler, NULL, + BLE_OS_TEST_TASK_PRIO, OS_WAIT_FOREVER, ble_os_test_stack, + OS_STACK_ALIGN(BLE_OS_TEST_STACK_SIZE)); + + os_start(); +} + +TEST_SUITE(ble_os_test_suite) +{ + tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL); + + ble_os_disc_test_case(); + ble_gap_direct_connect_test_case(); + ble_gap_terminate_test_case(); +} + +int +ble_os_test_all(void) +{ + ble_os_test_suite(); + return tu_any_failed; +}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/test/src/ble_sm_lgcy_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_sm_lgcy_test.c b/net/nimble/host/test/src/ble_sm_lgcy_test.c new file mode 100644 index 0000000..4791d7a --- /dev/null +++ b/net/nimble/host/test/src/ble_sm_lgcy_test.c @@ -0,0 +1,839 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stddef.h> +#include <string.h> +#include <errno.h> +#include "testutil/testutil.h" +#include "nimble/hci_common.h" +#include "nimble/nimble_opt.h" +#include "host/ble_sm.h" +#include "host/ble_hs_test.h" +#include "ble_hs_test_util.h" +#include "ble_sm_test_util.h" + +#if NIMBLE_BLE_SM + +/** + * Legacy pairing + * Master: peer + * Pair algorithm: just works + * Initiator IO capabilities: 4 + * Responder IO capabilities: 3 + * Bonding: true + * Initiator address type: BLE_ADDR_TYPE_PUBLIC + * Responder address type: BLE_ADDR_TYPE_PUBLIC + * Initiator key distribution: 7 + * Responder key distribution: 7 + */ +TEST_CASE(ble_sm_lgcy_peer_jw_iio4_rio3_b1_iat0_rat0_ik7_rk7) +{ + struct ble_sm_test_params params; + + params = (struct ble_sm_test_params) { + .init_id_addr = { + 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c, + }, + .resp_id_addr = { + 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a, + }, + .pair_req = { + .io_cap = 0x04, + .oob_data_flag = 0x00, + .authreq = 0x05, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .pair_rsp = { + .io_cap = 0x03, + .oob_data_flag = 0x00, + .authreq = 0x09, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .confirm_req[0] = { + .value = { + 0xcd, 0x5b, 0x79, 0x29, 0x53, 0x31, 0x56, 0x23, + 0x2c, 0x08, 0xed, 0x81, 0x16, 0x55, 0x8e, 0x01, + }, + }, + .confirm_rsp[0] = { + .value = { + 0x49, 0x39, 0x22, 0x0f, 0x7b, 0x1b, 0x80, 0xcd, + 0xbe, 0x89, 0xd1, 0x4c, 0xbd, 0x6f, 0xda, 0x2c, + }, + }, + .random_req[0] = { + .value = { + 0x7f, 0x42, 0xc0, 0x2f, 0x1d, 0x07, 0x37, 0xfc, + 0x04, 0x5b, 0x05, 0x9a, 0xed, 0x67, 0xa5, 0x68, + }, + }, + .random_rsp[0] = { + .value = { + 0x42, 0x1a, 0x58, 0xa2, 0x3b, 0x80, 0xde, 0xef, + 0x95, 0x0d, 0xf7, 0xca, 0x06, 0x05, 0x01, 0x3c, + }, + }, + .enc_info_req = { + .ltk = { + 0x2f, 0x9b, 0x16, 0xff, 0xf3, 0x73, 0x30, 0x08, + 0xa8, 0xe5, 0x01, 0xb1, 0x3b, 0xe1, 0x87, 0x00, + }, + }, + .master_id_req = { + .ediv = 0xf8e0, + .rand_val = 0xef7c818b00000000, + }, + .id_info_req = { + .irk = { + 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, + 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, + }, + }, + .id_addr_info_req = { + .addr_type = 0, + .bd_addr = { + 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a, + }, + }, + .sign_info_req = { + .sig_key = { + 0xc6, 0x17, 0xc0, 0x02, 0x40, 0x0d, 0x27, 0x51, + 0x8a, 0x77, 0xb5, 0xae, 0xd8, 0xa9, 0x7a, 0x7a, + }, + }, + .enc_info_rsp = { + .ltk = { + 0xd7, 0x07, 0x22, 0x79, 0x24, 0xc6, 0xcb, 0x4d, + 0xa3, 0xdd, 0x01, 0xfb, 0x48, 0x87, 0xd4, 0xcf, + }, + }, + .master_id_rsp = { + .ediv = 0x9a39, + .rand_val = 0x8e76d9b00000000, + }, + .id_info_rsp = { + .irk = { + 0xeb, 0x8a, 0x06, 0xc4, 0x93, 0x51, 0x04, 0xb3, + 0x8b, 0xbf, 0xe8, 0x1f, 0x0e, 0x96, 0x2a, 0x54, + }, + }, + .id_addr_info_rsp = { + .addr_type = 0, + .bd_addr = { + 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c, + }, + }, + .sign_info_rsp = { + .sig_key = { + 0x14, 0x55, 0x93, 0xe1, 0xd1, 0xe7, 0xc4, 0x5d, + 0x35, 0x97, 0xd3, 0x05, 0x30, 0xc8, 0x9d, 0x83, + }, + }, + .stk = { + 0x1c, 0xd7, 0xb6, 0x35, 0x48, 0xfc, 0x9f, 0xef, + 0x0e, 0x2f, 0x51, 0x77, 0xed, 0xdd, 0xbc, 0xaf, + }, + .pair_alg = 0, + .authenticated = false, + .passkey_info = { + .passkey = { + .action = BLE_SM_IOACT_NONE, + }, + }, + }; + ble_sm_test_util_peer_lgcy_good(¶ms); +} + +/** + * Legacy pairing + * Master: peer + * Pair algorithm: passkey entry + * Initiator IO capabilities: 4 + * Responder IO capabilities: 0 + * Bonding: true + * Initiator address type: BLE_ADDR_TYPE_PUBLIC + * Responder address type: BLE_ADDR_TYPE_PUBLIC + * Initiator key distribution: 7 + * Responder key distribution: 7 + */ +TEST_CASE(ble_sm_lgcy_peer_pk_iio4_rio0_b1_iat0_rat0_ik7_rk7) +{ + struct ble_sm_test_params params; + + params = (struct ble_sm_test_params) { + .init_id_addr = { + 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c, + }, + .resp_id_addr = { + 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a, + }, + .pair_req = { + .io_cap = 0x04, + .oob_data_flag = 0x00, + .authreq = 0x05, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .pair_rsp = { + .io_cap = 0x00, + .oob_data_flag = 0x00, + .authreq = 0x09, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .confirm_req[0] = { + .value = { + 0xa0, 0x10, 0x4a, 0xaa, 0x8b, 0x53, 0x78, 0xbb, + 0xd2, 0xae, 0x71, 0x1f, 0x4e, 0x00, 0x70, 0x8b, + }, + }, + .confirm_rsp[0] = { + .value = { + 0x62, 0xf3, 0xba, 0x0e, 0xe5, 0xbe, 0x2e, 0xd8, + 0x25, 0xb2, 0xec, 0x4c, 0x28, 0x77, 0x28, 0x60, + }, + }, + .random_req[0] = { + .value = { + 0x84, 0xcf, 0xe4, 0x04, 0x7d, 0xf3, 0xfc, 0xa1, + 0x3f, 0x75, 0xd6, 0x5a, 0x7c, 0xb7, 0xa4, 0x39, + }, + }, + .random_rsp[0] = { + .value = { + 0xef, 0x6a, 0x61, 0x6e, 0x02, 0x60, 0x7f, 0x5d, + 0x7f, 0x0d, 0xa6, 0x3c, 0x06, 0x1a, 0x5d, 0xd6, + }, + }, + .enc_info_req = { + .ltk = { + 0xad, 0x01, 0x6d, 0x76, 0xa9, 0xd0, 0x23, 0xc9, + 0x40, 0x0c, 0xbf, 0x2a, 0x4c, 0x23, 0x31, 0xc5, + }, + }, + .master_id_req = { + .ediv = 0xa74f, + .rand_val = 0x81cab3fd00000000, + }, + .id_info_req = { + .irk = { + 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, + 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, + }, + }, + .id_addr_info_req = { + .addr_type = 0, + .bd_addr = { + 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a, + }, + }, + .sign_info_req = { + .sig_key = { + 0x60, 0x08, 0x49, 0x00, 0x6d, 0x76, 0x98, 0x73, + 0x9c, 0x95, 0xc4, 0xd9, 0xe8, 0x3a, 0x69, 0xbb, + }, + }, + .enc_info_rsp = { + .ltk = { + 0x5b, 0x73, 0x39, 0xd9, 0x51, 0x3d, 0x92, 0xa4, + 0x34, 0x65, 0xa5, 0x70, 0x49, 0xbe, 0x11, 0x28, + }, + }, + .master_id_rsp = { + .ediv = 0x9705, + .rand_val = 0x592f1e8d00000000, + }, + .id_info_rsp = { + .irk = { + 0xeb, 0x8a, 0x06, 0xc4, 0x93, 0x51, 0x04, 0xb3, + 0x8b, 0xbf, 0xe8, 0x1f, 0x0e, 0x96, 0x2a, 0x54, + }, + }, + .id_addr_info_rsp = { + .addr_type = 0, + .bd_addr = { + 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c, + }, + }, + .sign_info_rsp = { + .sig_key = { + 0xc9, 0x9b, 0xf2, 0x75, 0xb7, 0x0d, 0xe8, 0x60, + 0x3d, 0xf0, 0xd6, 0xa8, 0x16, 0xc5, 0x6c, 0x2a, + }, + }, + .stk = { + 0xf2, 0x3c, 0x36, 0xc4, 0xa1, 0xfb, 0x5a, 0xa7, + 0x96, 0x20, 0xe4, 0x29, 0xb7, 0x58, 0x22, 0x7a, + }, + .pair_alg = 1, + .authenticated = true, + .passkey_info = { + .passkey = { + .action = BLE_SM_IOACT_DISP, + .passkey = 46128, + }, + }, + }; + ble_sm_test_util_peer_lgcy_good(¶ms); +} + +/** + * Legacy pairing + * Master: us + * Pair algorithm: just works + * Initiator IO capabilities: 3 + * Responder IO capabilities: 3 + * Bonding: true + * Initiator address type: BLE_ADDR_TYPE_PUBLIC + * Responder address type: BLE_ADDR_TYPE_RANDOM + * Initiator key distribution: 7 + * Responder key distribution: 5 + */ +TEST_CASE(ble_sm_lgcy_us_jw_iio3_rio3_b1_iat0_rat1_ik7_rk5) +{ + struct ble_sm_test_params params; + + params = (struct ble_sm_test_params) { + .init_id_addr = { + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, + }, + .resp_addr_type = BLE_ADDR_TYPE_RANDOM, + .resp_id_addr = { + 0x11, 0x22, 0x11, 0x22, 0x11, 0xcc, + }, + .pair_req = { + .io_cap = 0x03, + .oob_data_flag = 0x00, + .authreq = 0x01, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .pair_rsp = { + .io_cap = 0x03, + .oob_data_flag = 0x00, + .authreq = 0x01, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x05, + }, + .confirm_req[0] = { + .value = { + 0x1c, 0xb6, 0x10, 0xea, 0x02, 0x08, 0x90, 0x64, + 0xc7, 0xf8, 0xe5, 0x9c, 0xb4, 0x3a, 0x18, 0xca, + }, + }, + .confirm_rsp[0] = { + .value = { + 0xb8, 0x6f, 0xd1, 0xc6, 0x74, 0x35, 0xa3, 0x94, + 0x68, 0x2f, 0xf1, 0x4c, 0x78, 0x44, 0xe8, 0x0d, + }, + }, + .random_req[0] = { + .value = { + 0x40, 0x48, 0x17, 0x4d, 0x42, 0xa0, 0xf8, 0xd5, + 0xbf, 0x65, 0x67, 0xb8, 0x5e, 0x57, 0x38, 0xac, + }, + }, + .random_rsp[0] = { + .value = { + 0x2c, 0xa1, 0xb1, 0xf5, 0x54, 0x9b, 0x43, 0xe9, + 0xb0, 0x62, 0x6a, 0xb0, 0x02, 0xb8, 0x6c, 0xca, + }, + }, + .enc_info_req = { + .ltk = { + 0x01, 0x15, 0xb6, 0x93, 0xc9, 0xff, 0xfe, 0x27, + 0x02, 0x41, 0xfd, 0x7b, 0x0e, 0x31, 0xd4, 0xa6, + }, + }, + .master_id_req = { + .ediv = 0xe4fb, + .rand_val = 0x8eee76b100000000, + }, + .sign_info_req = { + .sig_key = { + 0x00, 0x2d, 0xf6, 0x3e, 0x5e, 0x0f, 0xd1, 0xe8, + 0x4e, 0x5f, 0x61, 0x1c, 0x2c, 0x0b, 0xa5, 0x51, + }, + }, + .enc_info_rsp = { + .ltk = { + 0x88, 0xbc, 0x95, 0x8d, 0xaa, 0x26, 0x8d, 0xd5, + 0x18, 0xc9, 0x06, 0x70, 0xc2, 0x30, 0x56, 0x4c, + }, + }, + .master_id_rsp = { + .ediv = 0x4413, + .rand_val = 0xfad1c27300000000, + }, + .id_info_rsp = { + .irk = { + 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, + 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, + }, + }, + .id_addr_info_rsp = { + .addr_type = 0, + .bd_addr = { + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, + }, + }, + .sign_info_rsp = { + .sig_key = { + 0x03, 0xad, 0xa4, 0xe1, 0x34, 0x76, 0x95, 0x54, + 0xe5, 0x8f, 0xa4, 0x06, 0x72, 0xe6, 0xfc, 0x65, + }, + }, + .stk = { + 0x31, 0x54, 0x42, 0x6c, 0x1c, 0x03, 0x36, 0x44, + 0x0b, 0x72, 0x90, 0xa5, 0x1f, 0x79, 0x5b, 0xe9, + }, + .pair_alg = 0, + .authenticated = false, + .passkey_info = { + .passkey = { + .action = BLE_SM_IOACT_NONE, + }, + }, + }; + ble_sm_test_util_us_lgcy_good(¶ms); +} + +/** + * Legacy pairing + * Master: us + * Pair algorithm: passkey entry + * Initiator IO capabilities: 4 + * Responder IO capabilities: 2 + * Bonding: true + * Initiator address type: BLE_ADDR_TYPE_PUBLIC + * Responder address type: BLE_ADDR_TYPE_RANDOM + * Initiator key distribution: 7 + * Responder key distribution: 5 + */ +TEST_CASE(ble_sm_lgcy_us_pk_iio4_rio2_b1_iat0_rat1_ik7_rk5) +{ + struct ble_sm_test_params params; + + params = (struct ble_sm_test_params) { + .init_id_addr = { + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, + }, + .resp_addr_type = BLE_ADDR_TYPE_RANDOM, + .resp_id_addr = { + 0x11, 0x22, 0x11, 0x22, 0x11, 0xcc, + }, + .pair_req = { + .io_cap = 0x04, + .oob_data_flag = 0x00, + .authreq = 0x0d, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .pair_rsp = { + .io_cap = 0x02, + .oob_data_flag = 0x00, + .authreq = 0x05, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x05, + }, + .confirm_req[0] = { + .value = { + 0xb5, 0xd4, 0xc5, 0xe8, 0xef, 0xef, 0xd8, 0xd7, + 0x2b, 0x14, 0x34, 0x35, 0x29, 0x18, 0xda, 0x12, + }, + }, + .confirm_rsp[0] = { + .value = { + 0x1a, 0x03, 0x20, 0xda, 0x60, 0x21, 0x9b, 0x4b, + 0x5d, 0x45, 0x90, 0x64, 0xe1, 0x24, 0x2c, 0xb6, + }, + }, + .random_req[0] = { + .value = { + 0x45, 0xa3, 0x1a, 0x0b, 0xf6, 0x0f, 0x7c, 0xcf, + 0x1a, 0xfb, 0xfc, 0x1a, 0xad, 0x62, 0x0e, 0x76, + }, + }, + .random_rsp[0] = { + .value = { + 0x82, 0xbb, 0x9f, 0x67, 0xc4, 0x88, 0xcb, 0x58, + 0xee, 0xf9, 0x34, 0x35, 0x23, 0xa3, 0xd0, 0x22, + }, + }, + .enc_info_req = { + .ltk = { + 0xfa, 0x43, 0x8f, 0x1f, 0xe6, 0x2a, 0x94, 0x5b, + 0x54, 0x89, 0x2b, 0x0f, 0xd7, 0x23, 0x77, 0x9e, + }, + }, + .master_id_req = { + .ediv = 0x88b3, + .rand_val = 0x7c970e18dec74560, + }, + .sign_info_req = { + .sig_key = { + 0x2e, 0x70, 0x3c, 0xbf, 0x20, 0xbe, 0x7d, 0x2d, + 0xb3, 0x50, 0x46, 0x33, 0x4c, 0x20, 0x0e, 0xc8, + }, + }, + .enc_info_rsp = { + .ltk = { + 0xc1, 0x64, 0x33, 0x10, 0x0f, 0x70, 0x2f, 0x9c, + 0xe7, 0x31, 0xc5, 0x32, 0xdd, 0x98, 0x16, 0x75, + }, + }, + .master_id_rsp = { + .ediv = 0x1c19, + .rand_val = 0xef308872dc2a4cc2, + }, + .id_info_rsp = { + .irk = { + 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, + 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, + }, + }, + .id_addr_info_rsp = { + .addr_type = 0, + .bd_addr = { + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, + }, + }, + .sign_info_rsp = { + .sig_key = { + 0xd7, 0x75, 0xfa, 0xed, 0xd7, 0xdd, 0x7b, 0xb3, + 0xa4, 0x20, 0xea, 0x2f, 0x75, 0x60, 0xb1, 0x84, + }, + }, + .stk = { + 0x9e, 0xe8, 0x35, 0x22, 0xb6, 0xbb, 0x54, 0x0d, + 0x48, 0x1b, 0x25, 0xa0, 0xd8, 0xe2, 0xa5, 0x08, + }, + .pair_alg = 1, + .authenticated = true, + .passkey_info = { + .passkey = { + .action = BLE_SM_IOACT_DISP, + .passkey = 46128, + }, + }, + }; + ble_sm_test_util_us_lgcy_good(¶ms); +} + +/** + * Legacy pairing + * Master: us + * Pair algorithm: out of band + * Initiator IO capabilities: 3 + * Responder IO capabilities: 3 + * Bonding: true + * Initiator address type: BLE_ADDR_TYPE_PUBLIC + * Responder address type: BLE_ADDR_TYPE_PUBLIC + * Initiator key distribution: 7 + * Responder key distribution: 7 + */ +TEST_CASE(ble_sm_lgcy_us_ob_iio3_rio3_b1_iat0_rat0_ik7_rk7) +{ + struct ble_sm_test_params params; + + params = (struct ble_sm_test_params) { + .init_id_addr = { + 0x01, 0x01, 0x01, 0x07, 0x08, 0x01, + }, + .resp_id_addr = { + 0x66, 0x33, 0x22, 0x66, 0x55, 0x11, + }, + .pair_req = { + .io_cap = 0x03, + .oob_data_flag = 0x01, + .authreq = 0x05, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .pair_rsp = { + .io_cap = 0x03, + .oob_data_flag = 0x01, + .authreq = 0x05, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .confirm_req[0] = { + .value = { + 0x2c, 0x3f, 0x3e, 0xf5, 0x39, 0x50, 0x78, 0x4a, + 0x3e, 0x14, 0x1a, 0x51, 0xfb, 0x8d, 0x6c, 0x10, + }, + }, + .confirm_rsp[0] = { + .value = { + 0xa9, 0x5c, 0x18, 0xb1, 0xdb, 0x51, 0x53, 0xa5, + 0xd3, 0xe7, 0x72, 0x17, 0xfb, 0xa8, 0xfb, 0xeb, + }, + }, + .random_req[0] = { + .value = { + 0x40, 0x2f, 0x42, 0xba, 0x10, 0x7b, 0x22, 0x65, + 0x84, 0xef, 0x63, 0xdf, 0x84, 0x7b, 0x04, 0xef, + }, + }, + .random_rsp[0] = { + .value = { + 0x94, 0xdc, 0x3c, 0xef, 0x65, 0xf7, 0x99, 0x2e, + 0x50, 0x29, 0x97, 0x2a, 0x57, 0xfd, 0xe6, 0x6a, + }, + }, + .enc_info_req = { + .ltk = { + 0x8c, 0x8e, 0x57, 0xba, 0x17, 0xbb, 0x04, 0xb5, + 0x16, 0xad, 0x31, 0x37, 0xf8, 0x3e, 0x4f, 0x21, + }, + }, + .master_id_req = { + .ediv = 0xaaa4, + .rand_val = 0xc0c830e300000000, + }, + .id_info_req = { + .irk = { + 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, + 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, + }, + }, + .id_addr_info_req = { + .addr_type = 0, + .bd_addr = { + 0x66, 0x33, 0x22, 0x66, 0x55, 0x11, + }, + }, + .sign_info_req = { + .sig_key = { + 0x5a, 0xe4, 0x2b, 0x40, 0x3a, 0x34, 0x1d, 0x94, + 0x56, 0x7d, 0xf4, 0x41, 0x23, 0x81, 0xc4, 0x11, + }, + }, + .enc_info_rsp = { + .ltk = { + 0xa6, 0x8e, 0xa0, 0xa4, 0x02, 0x64, 0x4c, 0x09, + 0x31, 0x25, 0x8a, 0x4f, 0x49, 0x35, 0xb0, 0x1f, + }, + }, + .master_id_rsp = { + .ediv = 0x57a3, + .rand_val = 0x8276af9000000000, + }, + .id_info_rsp = { + .irk = { + 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, + 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, + }, + }, + .id_addr_info_rsp = { + .addr_type = 0, + .bd_addr = { + 0x01, 0x01, 0x01, 0x07, 0x08, 0x01, + }, + }, + .sign_info_rsp = { + .sig_key = { + 0x8e, 0xef, 0x53, 0x5c, 0x1b, 0x21, 0x67, 0x8d, + 0x07, 0x5e, 0xaa, 0xe8, 0x41, 0xa9, 0x36, 0xcf, + }, + }, + .stk = { + 0x4c, 0xd4, 0xa7, 0xee, 0x83, 0xcd, 0xd1, 0x9e, + 0x84, 0xeb, 0xb8, 0xd2, 0xaf, 0x4a, 0x71, 0x2e, + }, + .pair_alg = 2, + .authenticated = 1, + .passkey_info = { + .passkey = { + .action = BLE_SM_IOACT_OOB, + .oob = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + }, + }, + }, + }; + ble_sm_test_util_us_lgcy_good(¶ms); +} + +/** + * Legacy pairing + * Master: peer + * Pair algorithm: passkey entry + * Initiator IO capabilities: 4 + * Responder IO capabilities: 4 + * Bonding: true + * Initiator address type: BLE_ADDR_TYPE_PUBLIC + * Responder address type: BLE_ADDR_TYPE_PUBLIC + * Initiator key distribution: 7 + * Responder key distribution: 7 + */ +TEST_CASE(ble_sm_lgcy_peer_pk_iio4_rio4_b1_iat0_rat0_ik7_rk7) +{ + struct ble_sm_test_params params; + + params = (struct ble_sm_test_params) { + .init_id_addr = { + 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c, + }, + .resp_id_addr = { + 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a, + }, + .pair_req = { + .io_cap = 0x04, + .oob_data_flag = 0x00, + .authreq = 0x05, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .pair_rsp = { + .io_cap = 0x04, + .oob_data_flag = 0x00, + .authreq = 0x0d, + .max_enc_key_size = 0x10, + .init_key_dist = 0x07, + .resp_key_dist = 0x07, + }, + .confirm_req[0] = { + .value = { + 0x93, 0x64, 0xb1, 0xb0, 0x07, 0x41, 0x22, 0xe7, + 0x3e, 0x5a, 0x87, 0xf5, 0x1f, 0x25, 0x79, 0x11, + }, + }, + .confirm_rsp[0] = { + .value = { + 0x2d, 0x40, 0x15, 0xc4, 0x21, 0xeb, 0xd5, 0x73, + 0xc8, 0x5d, 0xb8, 0xb9, 0x45, 0x31, 0xd5, 0x58, + }, + }, + .random_req[0] = { + .value = { + 0x8c, 0x2c, 0x3b, 0xf3, 0x90, 0xaa, 0x2e, 0xcf, + 0xc7, 0x5b, 0xf6, 0xae, 0xb6, 0x4c, 0xc3, 0x61, + }, + }, + .random_rsp[0] = { + .value = { + 0x7a, 0x94, 0x97, 0x0a, 0xbe, 0xaf, 0xc0, 0x6b, + 0xd4, 0xf4, 0x04, 0xd1, 0x21, 0x46, 0x34, 0xf3, + }, + }, + .enc_info_req = { + .ltk = { + 0x3a, 0x10, 0xd1, 0xab, 0x13, 0xee, 0x16, 0xee, + 0xcf, 0xae, 0xf1, 0x63, 0xf0, 0x6f, 0xb0, 0x89, + }, + }, + .master_id_req = { + .ediv = 0xb634, + .rand_val = 0xa99ac2007b4278a8, + }, + .id_info_req = { + .irk = { + 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d, + 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8, + }, + }, + .id_addr_info_req = { + .addr_type = 0, + .bd_addr = { + 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a, + }, + }, + .sign_info_req = { + .sig_key = { + 0x51, 0x4b, 0x7b, 0x31, 0xf7, 0xa6, 0x8a, 0x60, + 0x4f, 0x10, 0x04, 0x5f, 0xb8, 0xee, 0xf6, 0xb3, + }, + }, + .enc_info_rsp = { + .ltk = { + 0xa1, 0x1d, 0xdd, 0xee, 0x85, 0xcb, 0xe0, 0x48, + 0x1e, 0xdd, 0xa4, 0x9d, 0xed, 0x3f, 0x15, 0x17, + }, + }, + .master_id_rsp = { + .ediv = 0x7e06, + .rand_val = 0xe6077f688c5ca67, + }, + .id_info_rsp = { + .irk = { + 0xeb, 0x8a, 0x06, 0xc4, 0x93, 0x51, 0x04, 0xb3, + 0x8b, 0xbf, 0xe8, 0x1f, 0x0e, 0x96, 0x2a, 0x54, + }, + }, + .id_addr_info_rsp = { + .addr_type = 0, + .bd_addr = { + 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c, + }, + }, + .sign_info_rsp = { + .sig_key = { + 0x16, 0x7a, 0x2e, 0x9d, 0x43, 0x4d, 0x7b, 0x0b, + 0x88, 0xe2, 0x11, 0xb0, 0x4d, 0xa1, 0xed, 0x08, + }, + }, + .stk = { + 0x6c, 0x3e, 0x78, 0x47, 0xe8, 0x57, 0x9f, 0xe9, + 0x3a, 0x8f, 0x0a, 0xbb, 0xd4, 0x60, 0xf6, 0x0d, + }, + .pair_alg = 1, + .authenticated = true, + .passkey_info = { + .passkey = { + .action = BLE_SM_IOACT_INPUT, + .passkey = 449182, + }, + }, + }; + ble_sm_test_util_peer_lgcy_good(¶ms); +} + +TEST_SUITE(ble_sm_lgcy_test_suite) +{ + tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL); + + /*** No privacy. */ + + /* Peer as initiator. */ + ble_sm_lgcy_peer_jw_iio4_rio3_b1_iat0_rat0_ik7_rk7(); + ble_sm_lgcy_peer_pk_iio4_rio0_b1_iat0_rat0_ik7_rk7(); + ble_sm_lgcy_peer_pk_iio4_rio4_b1_iat0_rat0_ik7_rk7(); + + /* Us as initiator. */ + ble_sm_lgcy_us_jw_iio3_rio3_b1_iat0_rat1_ik7_rk5(); + ble_sm_lgcy_us_pk_iio4_rio2_b1_iat0_rat1_ik7_rk5(); + ble_sm_lgcy_us_ob_iio3_rio3_b1_iat0_rat0_ik7_rk7(); +} + +#endif