1 /**
2  * Common functions and helpers for BSIM GATT tests
3  *
4  * Copyright (c) 2024 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <zephyr/kernel.h>
10 
11 #include "bs_types.h"
12 #include "bs_tracing.h"
13 #include "time_machine.h"
14 #include "bstests.h"
15 
16 #include <zephyr/types.h>
17 #include <stddef.h>
18 #include <errno.h>
19 
20 #include <zephyr/bluetooth/bluetooth.h>
21 #include <zephyr/bluetooth/hci.h>
22 #include <zephyr/bluetooth/conn.h>
23 #include <zephyr/bluetooth/uuid.h>
24 #include <zephyr/bluetooth/gatt.h>
25 
26 extern enum bst_result_t bst_result;
27 
28 #define WAIT_TIME (30 * 1e6) /*seconds*/
29 
30 #define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
31 #define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true)
32 #define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false)
33 #define WAIT_FOR_FLAG(flag) \
34 	while (!(bool)atomic_get(&flag)) { \
35 		(void)k_sleep(K_MSEC(1)); \
36 	}
37 
38 #define FAIL(...) \
39 	do { \
40 		bst_result = Failed; \
41 		bs_trace_error_time_line(__VA_ARGS__); \
42 	} while (0)
43 
44 #define PASS(...) \
45 	do { \
46 		bst_result = Passed; \
47 		bs_trace_info_time(1, __VA_ARGS__); \
48 	} while (0)
49 
50 #define CHRC_SIZE 10
51 
52 #define TEST_SERVICE_UUID \
53 	BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
54 			    0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00)
55 
56 #define TEST_UNHANDLED_CHRC_UUID \
57 	BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
58 			    0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFD, 0x00)
59 
60 #define TEST_UNAUTHORIZED_CHRC_UUID \
61 	BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
62 			    0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFE, 0x00)
63 
64 #define TEST_AUTHORIZED_CHRC_UUID \
65 	BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
66 			    0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x00)
67 
68 #define TEST_CP_CHRC_UUID \
69 	BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
70 			    0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xF0, 0x00)
71 
72 void test_tick(bs_time_t HW_device_time);
73 void test_init(void);
74