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