1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include "bs_bt_utils.h" 8 #include "utils.h" 9 #include <zephyr/bluetooth/addr.h> 10 #include <zephyr/bluetooth/conn.h> 11 12 #include <stdint.h> 13 14 #include <zephyr/bluetooth/bluetooth.h> 15 16 #include "babblekit/testcase.h" 17 18 #include <zephyr/logging/log.h> 19 LOG_MODULE_REGISTER(central, LOG_LEVEL_INF); 20 central(void)21void central(void) 22 { 23 bs_bt_utils_setup(); 24 25 struct bt_conn *conn_a; 26 struct bt_conn *conn_b; 27 28 /* Connect to the first identity of the peripheral. */ 29 LOG_INF("conn first"); 30 scan_connect_to_first_result(); 31 LOG_INF("wait conn"); 32 wait_connected(&conn_a); 33 34 /* Subscribe to battery notifications and wait on the first one. */ 35 LOG_INF("subscribe first"); 36 bas_subscribe(conn_a); 37 wait_bas_notification(); 38 39 /* Connect to the second identity of the peripheral. */ 40 LOG_INF("scan 2nd id"); 41 scan_connect_to_first_result(); 42 wait_connected(&conn_b); 43 44 /* Establish security with the second identity and resolve identity address. */ 45 LOG_INF("set sec"); 46 set_security(conn_b, BT_SECURITY_L2); 47 wait_pairing_completed(); 48 49 /* Wait for notification from the first connection after identity address resolution. */ 50 LOG_INF("wait notif"); 51 wait_bas_notification(); 52 53 /* Disconnect the first identity of the peripheral. */ 54 LOG_INF("discon id first"); 55 disconnect(conn_a); 56 wait_disconnected(); 57 clear_conn(conn_a); 58 59 /* Disconnect the second identity of the peripheral. */ 60 LOG_INF("discon id second"); 61 disconnect(conn_b); 62 wait_disconnected(); 63 clear_conn(conn_b); 64 65 TEST_PASS("PASS"); 66 } 67 68 static const struct bst_test_instance test_to_add[] = { 69 { 70 .test_id = "central", 71 .test_main_f = central, 72 }, 73 BSTEST_END_MARKER, 74 }; 75 install(struct bst_test_list * tests)76static struct bst_test_list *install(struct bst_test_list *tests) 77 { 78 return bst_add_tests(tests, test_to_add); 79 }; 80 81 bst_test_install_t test_installers[] = {install, NULL}; 82 main(void)83int main(void) 84 { 85 bst_main(); 86 return 0; 87 } 88