1 /* Copyright (c) 2023 Nordic Semiconductor ASA
2 * SPDX-License-Identifier: Apache-2.0
3 */
4
5 #include <argparse.h>
6 #include <zephyr/bluetooth/gatt.h>
7 #include <zephyr/logging/log.h>
8 #include <zephyr/sys/__assert.h>
9 #include <zephyr/sys/byteorder.h>
10
11 #include <testlib/adv.h>
12
13 #include "../bs_macro.h"
14 #include "../common_defs.h"
15
16 LOG_MODULE_REGISTER(server, LOG_LEVEL_DBG);
17
read_mtu_validation_chrc(struct bt_conn * conn,const struct bt_gatt_attr * attr,void * buf,uint16_t buf_len,uint16_t offset)18 static ssize_t read_mtu_validation_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
19 void *buf, uint16_t buf_len, uint16_t offset)
20 {
21 LOG_INF("buf_len %u", buf_len);
22
23 /* Fill the requested read size. */
24 memset(buf, 0, buf_len);
25
26 /* Echo back the requested read size in the first two bytes. */
27 sys_put_le16(buf_len, buf);
28
29 return buf_len;
30 }
31
32 BT_GATT_SERVICE_DEFINE(long_attr_svc, BT_GATT_PRIMARY_SERVICE(MTU_VALIDATION_SVC),
33 BT_GATT_CHARACTERISTIC(MTU_VALIDATION_CHRC, BT_GATT_CHRC_READ,
34 BT_GATT_PERM_READ, read_mtu_validation_chrc, NULL,
35 NULL));
36
the_test(void)37 void the_test(void)
38 {
39 int err;
40
41 err = bt_enable(NULL);
42 __ASSERT_NO_MSG(!err);
43
44 __ASSERT_NO_MSG(get_device_nbr() == 1);
45 err = bt_set_name("d1");
46 __ASSERT_NO_MSG(!err);
47
48 err = bt_testlib_adv_conn(NULL, BT_ID_DEFAULT, bt_get_name());
49 __ASSERT_NO_MSG(!err);
50
51 PASS("PASS\n");
52 }
53