1 /*
2 * Copyright (c) 2023 Nordic Semiconductor
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <string.h>
10
11 #include <zephyr/kernel.h>
12
13 #include <zephyr/sys/printk.h>
14
15 #include <zephyr/bluetooth/gatt.h>
16
17 #include "common.h"
18 #include "time_machine.h"
19
20 #include <zephyr/logging/log.h>
21 LOG_MODULE_REGISTER(bt_bsim_mtu_update, LOG_LEVEL_DBG);
22
23 extern void run_central_sample(void *cb);
24
25 CREATE_FLAG(flag_notification_received);
26 uint8_t notify_data[100] = {};
27 uint8_t is_data_equal;
28
notify_cb(struct bt_conn * conn,struct bt_gatt_subscribe_params * params,const void * data,uint16_t length)29 static uint8_t notify_cb(struct bt_conn *conn, struct bt_gatt_subscribe_params *params,
30 const void *data, uint16_t length)
31 {
32 printk("BSIM NOTIFY_CALLBACK\n");
33
34 is_data_equal = (length == sizeof(notify_data) && !memcmp(notify_data, data, length));
35
36 LOG_HEXDUMP_DBG(data, length, "notification data");
37 LOG_HEXDUMP_DBG(notify_data, sizeof(notify_data), "expected data");
38
39 SET_FLAG(flag_notification_received);
40
41 return 0;
42 }
43
test_central_main(void)44 static void test_central_main(void)
45 {
46 notify_data[13] = 0x7f;
47 notify_data[99] = 0x55;
48
49 run_central_sample(notify_cb);
50
51 WAIT_FOR_FLAG(flag_notification_received);
52
53 if (is_data_equal) {
54 PASS("MTU Update test passed\n");
55 } else {
56 FAIL("MTU Update test failed\n");
57 }
58 }
59
test_tick(bs_time_t HW_device_time)60 void test_tick(bs_time_t HW_device_time)
61 {
62 if (bst_result != Passed) {
63 FAIL("Test failed (not passed after %i seconds)\n", WAIT_TIME);
64 }
65 }
66
test_mtu_update_init(void)67 static void test_mtu_update_init(void)
68 {
69 bst_ticker_set_next_tick_absolute(WAIT_TIME);
70 bst_result = In_progress;
71 }
72
73 static const struct bst_test_instance test_def[] = {
74 {
75 .test_id = "central",
76 .test_descr = "Central GATT MTU Update",
77 .test_pre_init_f = test_mtu_update_init,
78 .test_tick_f = test_tick,
79 .test_main_f = test_central_main
80 },
81 BSTEST_END_MARKER
82 };
83
test_mtu_update_install(struct bst_test_list * tests)84 struct bst_test_list *test_mtu_update_install(struct bst_test_list *tests)
85 {
86 return bst_add_tests(tests, test_def);
87 }
88
89 bst_test_install_t test_installers[] = {
90 test_mtu_update_install,
91 NULL
92 };
93
main(void)94 int main(void)
95 {
96 bst_main();
97 return 0;
98 }
99