1 /**
2 * Copyright (c) 2019 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 /**
7 * @brief Service D
8 *
9 * This code is auto-generated from the Excel Workbook
10 * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1'
11 */
12 #include <zephyr/sys/byteorder.h>
13 #include <zephyr/sys/printk.h>
14
15 #include <zephyr/bluetooth/gatt.h>
16
17 #include "gatt_macs.h"
18
19 extern struct bt_gatt_attr service_b_5_1_attrs[];
20
21 /**
22 * @brief UUID for the Service D
23 */
24 #define BT_UUID_SERVICE_D BT_UUID_DECLARE_16(0xa00d)
25
26 /**
27 * @brief UUID for the Value V12 Characteristic
28 */
29 #define BT_UUID_VALUE_V12 BT_UUID_DECLARE_16(0xb00c)
30
31 /**
32 * @brief UUID for the Value V11 (128-bit UUID) Characteristic
33 */
34 #define BT_UUID_VALUE_V11__128_BIT_UUID BT_UUID_DECLARE_128( \
35 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \
36 0x00, 0x00, 0x00, 0x00, 0x0b, 0xb0, 0x00, 0x00)
37
38 static uint8_t value_v12_value = 0x0C;
39 static uint8_t value_v11__128_bit_uuid_value = 0x0B;
40 static bool bAuthorized;
41
42 /**
43 * @brief Attribute read call back for the Value V12 attribute
44 *
45 * @param conn The connection that is requesting to read
46 * @param attr The attribute that's being read
47 * @param buf Buffer to place the read result in
48 * @param len Length of data to read
49 * @param offset Offset to start reading from
50 *
51 * @return Number of bytes read, or in case of an error - BT_GATT_ERR()
52 * with a specific ATT error code.
53 */
read_value_v12(struct bt_conn * conn,const struct bt_gatt_attr * attr,void * buf,uint16_t len,uint16_t offset)54 static ssize_t read_value_v12(struct bt_conn *conn,
55 const struct bt_gatt_attr *attr, void *buf,
56 uint16_t len, uint16_t offset)
57 {
58 const uint8_t *value = attr->user_data;
59
60 return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
61 sizeof(value_v12_value));
62 }
63
64 /**
65 * @brief Attribute read call back for the Value V11 (128-bit UUID) attribute
66 *
67 * @param conn The connection that is requesting to read
68 * @param attr The attribute that's being read
69 * @param buf Buffer to place the read result in
70 * @param len Length of data to read
71 * @param offset Offset to start reading from
72 *
73 * @return Number of bytes read, or in case of an error - BT_GATT_ERR()
74 * with a specific ATT error code.
75 */
read_value_v11__128_bit_uuid(struct bt_conn * conn,const struct bt_gatt_attr * attr,void * buf,uint16_t len,uint16_t offset)76 static ssize_t read_value_v11__128_bit_uuid(struct bt_conn *conn,
77 const struct bt_gatt_attr *attr,
78 void *buf, uint16_t len, uint16_t offset)
79 {
80 const uint8_t *value = attr->user_data;
81
82 if (!bAuthorized) {
83 return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION);
84 }
85
86 return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
87 sizeof(value_v11__128_bit_uuid_value));
88 }
89
90 struct bt_gatt_attr service_d_1_attrs[] = {
91 BT_GATT_H_SECONDARY_SERVICE(BT_UUID_SERVICE_D, 0x10),
92 BT_GATT_H_INCLUDE_SERVICE(service_b_5_1_attrs, 0x11),
93 BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V12,
94 BT_GATT_CHRC_READ,
95 BT_GATT_PERM_READ_AUTHEN,
96 read_value_v12, NULL, &value_v12_value, 0x12),
97 BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V11__128_BIT_UUID,
98 BT_GATT_CHRC_READ,
99 BT_GATT_PERM_READ,
100 read_value_v11__128_bit_uuid, NULL,
101 &value_v11__128_bit_uuid_value, 0x14)
102 };
103
104 static struct bt_gatt_service service_d_1_svc =
105 BT_GATT_SERVICE(service_d_1_attrs);
106
107 /**
108 * @brief Register the Service D and all its Characteristics...
109 */
service_d_1_init(void)110 void service_d_1_init(void)
111 {
112 bt_gatt_service_register(&service_d_1_svc);
113 }
114
115 /**
116 * @brief Un-Register the Service D and all its Characteristics...
117 */
service_d_1_remove(void)118 void service_d_1_remove(void)
119 {
120 bt_gatt_service_unregister(&service_d_1_svc);
121 }
122
123 /**
124 * @brief Set authorization for Characteristics and Descriptors in Service D.
125 */
service_d_1_authorize(bool authorized)126 void service_d_1_authorize(bool authorized)
127 {
128 bAuthorized = authorized;
129 }
130