1 /**
2 * Copyright (c) 2019 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 /**
7 * @brief Service C.1
8 *
9 * This code is auto-generated from the Excel Workbook
10 * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3'
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 /**
20 * @brief UUID for the Service C.1
21 */
22 #define BT_UUID_SERVICE_C_1 BT_UUID_DECLARE_128( \
23 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \
24 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00)
25
26 /**
27 * @brief UUID for the Value V9 (128-bit UUID) Characteristic
28 */
29 #define BT_UUID_VALUE_V9__128_BIT_UUID BT_UUID_DECLARE_128( \
30 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \
31 0x00, 0x00, 0x00, 0x00, 0x09, 0xb0, 0x00, 0x00)
32
33 /**
34 * @brief UUID for the Descriptor V9D2 (128-bit UUID) Characteristic
35 */
36 #define BT_UUID_DES_V9D2__128_BIT_UUID BT_UUID_DECLARE_128( \
37 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \
38 0x00, 0x00, 0x00, 0x00, 0xd2, 0xd9, 0x00, 0x00)
39
40 /**
41 * @brief UUID for the Descriptor V9D3 (128-bit UUID) Characteristic
42 */
43 #define BT_UUID_DES_V9D3__128_BIT_UUID BT_UUID_DECLARE_128( \
44 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \
45 0x00, 0x00, 0x00, 0x00, 0xd3, 0xd9, 0x00, 0x00)
46
47 static uint8_t value_v9__128_bit_uuid_value = 0x09;
48 static uint8_t des_v9d2__128_bit_uuid_value = 0x22;
49 static struct bt_gatt_cep cha_ext_pro_value = { 0x0001 };
50 static uint8_t des_v9d3__128_bit_uuid_value = 0x33;
51
52 /**
53 * @brief Attribute read call back for the Value V9 (128-bit UUID) attribute
54 *
55 * @param conn The connection that is requesting to read
56 * @param attr The attribute that's being read
57 * @param buf Buffer to place the read result in
58 * @param len Length of data to read
59 * @param offset Offset to start reading from
60 *
61 * @return Number of bytes read, or in case of an error - BT_GATT_ERR()
62 * with a specific ATT error code.
63 */
read_value_v9__128_bit_uuid(struct bt_conn * conn,const struct bt_gatt_attr * attr,void * buf,uint16_t len,uint16_t offset)64 static ssize_t read_value_v9__128_bit_uuid(struct bt_conn *conn,
65 const struct bt_gatt_attr *attr,
66 void *buf, uint16_t len, uint16_t offset)
67 {
68 const uint8_t *value = attr->user_data;
69
70 return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
71 sizeof(value_v9__128_bit_uuid_value));
72 }
73
74 /**
75 * @brief Attribute write call back for the Value V9 (128-bit UUID) attribute
76 *
77 * @param conn The connection that is requesting to write
78 * @param attr The attribute that's being written
79 * @param buf Buffer with the data to write
80 * @param len Number of bytes in the buffer
81 * @param offset Offset to start writing from
82 * @param flags Flags (BT_GATT_WRITE_*)
83 *
84 * @return Number of bytes written, or in case of an error - BT_GATT_ERR()
85 * with a specific ATT error code.
86 */
write_value_v9__128_bit_uuid(struct bt_conn * conn,const struct bt_gatt_attr * attr,const void * buf,uint16_t len,uint16_t offset,uint8_t flags)87 static ssize_t write_value_v9__128_bit_uuid(struct bt_conn *conn,
88 const struct bt_gatt_attr *attr,
89 const void *buf, uint16_t len,
90 uint16_t offset, uint8_t flags)
91 {
92 uint8_t *value = attr->user_data;
93
94 if (offset >= sizeof(value_v9__128_bit_uuid_value)) {
95 return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
96 }
97 if (offset + len > sizeof(value_v9__128_bit_uuid_value)) {
98 return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
99 }
100
101 memcpy(value + offset, buf, len);
102
103 return len;
104 }
105
106 /**
107 * @brief Attribute read call back for the Descriptor V9D2 (128-bit UUID)
108 * attribute
109 *
110 * @param conn The connection that is requesting to read
111 * @param attr The attribute that's being read
112 * @param buf Buffer to place the read result in
113 * @param len Length of data to read
114 * @param offset Offset to start reading from
115 *
116 * @return Number of bytes read, or in case of an error - BT_GATT_ERR()
117 * with a specific ATT error code.
118 */
read_des_v9d2__128_bit_uuid(struct bt_conn * conn,const struct bt_gatt_attr * attr,void * buf,uint16_t len,uint16_t offset)119 static ssize_t read_des_v9d2__128_bit_uuid(struct bt_conn *conn,
120 const struct bt_gatt_attr *attr,
121 void *buf, uint16_t len, uint16_t offset)
122 {
123 const uint8_t *value = attr->user_data;
124
125 return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
126 sizeof(des_v9d2__128_bit_uuid_value));
127 }
128
129 /**
130 * @brief Attribute write call back for the Descriptor V9D2 (128-bit UUID)
131 * attribute
132 *
133 * @param conn The connection that is requesting to write
134 * @param attr The attribute that's being written
135 * @param buf Buffer with the data to write
136 * @param len Number of bytes in the buffer
137 * @param offset Offset to start writing from
138 * @param flags Flags (BT_GATT_WRITE_*)
139 *
140 * @return Number of bytes written, or in case of an error - BT_GATT_ERR()
141 * with a specific ATT error code.
142 */
write_des_v9d2__128_bit_uuid(struct bt_conn * conn,const struct bt_gatt_attr * attr,const void * buf,uint16_t len,uint16_t offset,uint8_t flags)143 static ssize_t write_des_v9d2__128_bit_uuid(struct bt_conn *conn,
144 const struct bt_gatt_attr *attr,
145 const void *buf, uint16_t len,
146 uint16_t offset, uint8_t flags)
147 {
148 uint8_t *value = attr->user_data;
149
150 if (offset >= sizeof(des_v9d2__128_bit_uuid_value)) {
151 return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
152 }
153 if (offset + len > sizeof(des_v9d2__128_bit_uuid_value)) {
154 return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
155 }
156
157 memcpy(value + offset, buf, len);
158
159 return len;
160 }
161
162 /**
163 * @brief Attribute write call back for the Descriptor V9D3 (128-bit UUID)
164 * attribute
165 *
166 * @param conn The connection that is requesting to write
167 * @param attr The attribute that's being written
168 * @param buf Buffer with the data to write
169 * @param len Number of bytes in the buffer
170 * @param offset Offset to start writing from
171 * @param flags Flags (BT_GATT_WRITE_*)
172 *
173 * @return Number of bytes written, or in case of an error - BT_GATT_ERR()
174 * with a specific ATT error code.
175 */
write_des_v9d3__128_bit_uuid(struct bt_conn * conn,const struct bt_gatt_attr * attr,const void * buf,uint16_t len,uint16_t offset,uint8_t flags)176 static ssize_t write_des_v9d3__128_bit_uuid(struct bt_conn *conn,
177 const struct bt_gatt_attr *attr,
178 const void *buf, uint16_t len,
179 uint16_t offset, uint8_t flags)
180 {
181 uint8_t *value = attr->user_data;
182
183 if (offset >= sizeof(des_v9d3__128_bit_uuid_value)) {
184 return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
185 }
186 if (offset + len > sizeof(des_v9d3__128_bit_uuid_value)) {
187 return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
188 }
189
190 memcpy(value + offset, buf, len);
191
192 return len;
193 }
194
195 struct bt_gatt_attr service_c_1_3_attrs[] = {
196 BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_1, 0x80),
197 BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V9__128_BIT_UUID,
198 BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP,
199 BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
200 read_value_v9__128_bit_uuid, write_value_v9__128_bit_uuid,
201 &value_v9__128_bit_uuid_value, 0x81),
202 BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D2__128_BIT_UUID,
203 BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
204 read_des_v9d2__128_bit_uuid, write_des_v9d2__128_bit_uuid,
205 &des_v9d2__128_bit_uuid_value, 0x83),
206 BT_GATT_H_CEP(&cha_ext_pro_value, 0x84),
207 BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D3__128_BIT_UUID,
208 BT_GATT_PERM_WRITE,
209 NULL, write_des_v9d3__128_bit_uuid,
210 &des_v9d3__128_bit_uuid_value, 0x85)
211 };
212
213 static struct bt_gatt_service service_c_1_3_svc =
214 BT_GATT_SERVICE(service_c_1_3_attrs);
215
216 /**
217 * @brief Register the Service C.1 and all its Characteristics...
218 */
service_c_1_3_init(void)219 void service_c_1_3_init(void)
220 {
221 bt_gatt_service_register(&service_c_1_3_svc);
222 }
223
224 /**
225 * @brief Un-Register the Service C.1 and all its Characteristics...
226 */
service_c_1_3_remove(void)227 void service_c_1_3_remove(void)
228 {
229 bt_gatt_service_unregister(&service_c_1_3_svc);
230 }
231