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