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 <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
23 id_a = bt_id_create(NULL, NULL);
24 ASSERT(id_a >= 0, "bt_id_create id_a failed (err %d)\n", id_a);
25
26 id_b = bt_id_create(NULL, NULL);
27 ASSERT(id_b >= 0, "bt_id_create id_b failed (err %d)\n", id_b);
28
29 printk("== Bonding id a - global bondable mode ==\n");
30 BUILD_ASSERT(CONFIG_BT_BONDABLE, "CONFIG_BT_BONDABLE must be enabled by default.");
31 enable_bt_conn_set_bondable(false);
32 advertise_connectable(id_a, NULL);
33 wait_connected();
34 /* Central should bond here and trigger a disconnect. */
35 wait_disconnected();
36 TAKE_FLAG(flag_pairing_complete);
37 TAKE_FLAG(flag_bonded);
38 unpair(id_a);
39 clear_g_conn();
40
41 printk("== Bonding id a - bond per-connection true ==\n");
42 enable_bt_conn_set_bondable(true);
43 set_bondable(true);
44 advertise_connectable(id_a, NULL);
45 wait_connected();
46 /* Central should bond here and trigger a disconnect. */
47 wait_disconnected();
48 TAKE_FLAG(flag_pairing_complete);
49 TAKE_FLAG(flag_bonded);
50 clear_g_conn();
51
52 printk("== Bonding id b - bond per-connection false ==\n");
53 set_bondable(false);
54 advertise_connectable(id_b, NULL);
55 wait_connected();
56 /* Central should pair without bond here and trigger a disconnect. */
57 wait_disconnected();
58 TAKE_FLAG(flag_pairing_complete);
59 TAKE_FLAG(flag_not_bonded);
60
61 PASS("PASS\n");
62 }
63