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 "babblekit/testcase.h"
18 #include "babblekit/flags.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 DEFINE_FLAG_STATIC(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 TEST_PASS("MTU Update test passed");
55 } else {
56 TEST_FAIL("MTU Update test failed");
57 }
58 }
59
60 static const struct bst_test_instance test_def[] = {
61 {
62 .test_id = "central",
63 .test_descr = "Central GATT MTU Update",
64 .test_main_f = test_central_main
65 },
66 BSTEST_END_MARKER
67 };
68
test_mtu_update_install(struct bst_test_list * tests)69 struct bst_test_list *test_mtu_update_install(struct bst_test_list *tests)
70 {
71 return bst_add_tests(tests, test_def);
72 }
73
74 bst_test_install_t test_installers[] = {
75 test_mtu_update_install,
76 NULL
77 };
78
main(void)79 int main(void)
80 {
81 bst_main();
82 return 0;
83 }
84