1 /*
2  * Copyright (c) 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "bs_bt_utils.h"
8 #include <zephyr/bluetooth/addr.h>
9 #include <zephyr/bluetooth/bluetooth.h>
10 #include <zephyr/bluetooth/conn.h>
11 #include <zephyr/toolchain.h>
12 
13 #include <stdint.h>
14 #include <string.h>
15 
peripheral(void)16 void peripheral(void)
17 {
18 	bs_bt_utils_setup();
19 
20 	int id_a;
21 	int id_b;
22 	bt_addr_le_t central;
23 
24 	id_a = bt_id_create(NULL, NULL);
25 	ASSERT(id_a >= 0, "bt_id_create id_a failed (err %d)\n", id_a);
26 
27 	id_b = bt_id_create(NULL, NULL);
28 	ASSERT(id_b >= 0, "bt_id_create id_b failed (err %d)\n", id_b);
29 
30 	printk("== Bonding id a ==\n");
31 	advertise_connectable(id_a, NULL);
32 	wait_connected();
33 	/* Central should bond here, and trigger a disconnect. */
34 	wait_disconnected();
35 	central = *bt_conn_get_dst(g_conn);
36 	clear_g_conn();
37 
38 	printk("== Bonding id b ==\n");
39 	advertise_connectable(id_b, NULL);
40 	wait_connected();
41 	/* Central should bond here. */
42 	BUILD_ASSERT(IS_ENABLED(CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE), "");
43 	BUILD_ASSERT(IS_ENABLED(CONFIG_BT_ID_UNPAIR_MATCHING_BONDS), "");
44 	TAKE_FLAG(flag_pairing_complete);
45 	ASSERT(bt_addr_le_eq(bt_conn_get_dst(g_conn), &central),
46 	       "Test requires that central uses the same identity in both bonds.");
47 	/* Central should disconnect here. */
48 	wait_disconnected();
49 	clear_g_conn();
50 
51 	printk("== Directed connect id b ==\n");
52 	advertise_connectable(id_b, &central);
53 	wait_connected();
54 	/* Central should verify that its bond with id_b works as expected. */
55 
56 	PASS("PASS\n");
57 }
58