1 /**
2 * Copyright (c) 2019 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 /**
7 * @brief Service B.2
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 B.2
21 */
22 #define BT_UUID_SERVICE_B_2 BT_UUID_DECLARE_16(0xa00b)
23
24 /**
25 * @brief UUID for the Value V5 Characteristic
26 */
27 #define BT_UUID_VALUE_V5 BT_UUID_DECLARE_16(0xb005)
28
29 /**
30 * @brief UUID for the Descriptor V5D4 (128-bit UUID) Characteristic
31 */
32 #define BT_UUID_DES_V5D4__128_BIT_UUID BT_UUID_DECLARE_128( \
33 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \
34 0x00, 0x00, 0x00, 0x00, 0xd4, 0xd5, 0x00, 0x00)
35
36 static uint8_t value_v5_value = 0x05;
37 static uint8_t cha_user_des_value[] = {
38 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
39 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
40 '\0'
41 };
42 static struct bt_gatt_cep cha_ext_pro_value = { 0x0003 };
43 static uint8_t des_v5d4__128_bit_uuid_value = 0x44;
44 static const struct bt_gatt_cpf cha_format_value = {
45 0x04, 0x00, 0x3001, 0x01, 0x3111
46 };
47
48 /**
49 * @brief Attribute read call back for the Value V5 attribute
50 *
51 * @param conn The connection that is requesting to read
52 * @param attr The attribute that's being read
53 * @param buf Buffer to place the read result in
54 * @param len Length of data to read
55 * @param offset Offset to start reading from
56 *
57 * @return Number of bytes read, or in case of an error - BT_GATT_ERR()
58 * with a specific ATT error code.
59 */
read_value_v5(struct bt_conn * conn,const struct bt_gatt_attr * attr,void * buf,uint16_t len,uint16_t offset)60 static ssize_t read_value_v5(struct bt_conn *conn,
61 const struct bt_gatt_attr *attr, void *buf,
62 uint16_t len, uint16_t offset)
63 {
64 const uint8_t *value = attr->user_data;
65
66 return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
67 sizeof(value_v5_value));
68 }
69
70 /**
71 * @brief Attribute write call back for the Value V5 attribute
72 *
73 * @param conn The connection that is requesting to write
74 * @param attr The attribute that's being written
75 * @param buf Buffer with the data to write
76 * @param len Number of bytes in the buffer
77 * @param offset Offset to start writing from
78 * @param flags Flags (BT_GATT_WRITE_*)
79 *
80 * @return Number of bytes written, or in case of an error - BT_GATT_ERR()
81 * with a specific ATT error code.
82 */
write_value_v5(struct bt_conn * conn,const struct bt_gatt_attr * attr,const void * buf,uint16_t len,uint16_t offset,uint8_t flags)83 static ssize_t write_value_v5(struct bt_conn *conn,
84 const struct bt_gatt_attr *attr, const void *buf,
85 uint16_t len, uint16_t offset, uint8_t flags)
86 {
87 uint8_t *value = attr->user_data;
88
89 if (offset >= sizeof(value_v5_value)) {
90 return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
91 }
92 if (offset + len > sizeof(value_v5_value)) {
93 return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
94 }
95
96 memcpy(value + offset, buf, len);
97
98 return len;
99 }
100
101 /**
102 * @brief Attribute read call back for the Descriptor V5D4 (128-bit UUID)
103 * attribute
104 *
105 * @param conn The connection that is requesting to read
106 * @param attr The attribute that's being read
107 * @param buf Buffer to place the read result in
108 * @param len Length of data to read
109 * @param offset Offset to start reading from
110 *
111 * @return Number of bytes read, or in case of an error - BT_GATT_ERR()
112 * with a specific ATT error code.
113 */
read_des_v5d4__128_bit_uuid(struct bt_conn * conn,const struct bt_gatt_attr * attr,void * buf,uint16_t len,uint16_t offset)114 static ssize_t read_des_v5d4__128_bit_uuid(struct bt_conn *conn,
115 const struct bt_gatt_attr *attr,
116 void *buf, uint16_t len, uint16_t offset)
117 {
118 const uint8_t *value = attr->user_data;
119
120 return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
121 sizeof(des_v5d4__128_bit_uuid_value));
122 }
123
124 static struct bt_gatt_attr service_b_2_3_attrs[] = {
125 BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_2, 0x90),
126 BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V5,
127 BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP,
128 BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
129 read_value_v5, write_value_v5, &value_v5_value, 0x91),
130 BT_GATT_H_CUD(cha_user_des_value, BT_GATT_PERM_READ, 0x93),
131 BT_GATT_H_CEP(&cha_ext_pro_value, 0x94),
132 BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V5D4__128_BIT_UUID,
133 BT_GATT_PERM_READ,
134 read_des_v5d4__128_bit_uuid, NULL,
135 &des_v5d4__128_bit_uuid_value, 0x95),
136 BT_GATT_H_CPF(&cha_format_value, 0x96)
137 };
138
139 static struct bt_gatt_service service_b_2_3_svc =
140 BT_GATT_SERVICE(service_b_2_3_attrs);
141
142 /**
143 * @brief Register the Service B.2 and all its Characteristics...
144 */
service_b_2_3_init(void)145 void service_b_2_3_init(void)
146 {
147 bt_gatt_service_register(&service_b_2_3_svc);
148 }
149
150 /**
151 * @brief Un-Register the Service B.2 and all its Characteristics...
152 */
service_b_2_3_remove(void)153 void service_b_2_3_remove(void)
154 {
155 bt_gatt_service_unregister(&service_b_2_3_svc);
156 }
157