Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | /**
* Copyright (c) 2019 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @brief Service C.2
*
* This code is auto-generated from the Excel Workbook
* 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2'
*/
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/printk.h>
#include <zephyr/bluetooth/gatt.h>
#include "gatt_macs.h"
/** @def BT_UUID_SERVICE_C_2
* @brief UUID for the Service C.2
*/
#define BT_UUID_SERVICE_C_2 BT_UUID_DECLARE_128( \
0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \
0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00)
/** @def BT_UUID_VALUE_V10
* @brief UUID for the Value V10 Characteristic
*/
#define BT_UUID_VALUE_V10 BT_UUID_DECLARE_16(0xb00a)
/** @def BT_UUID_VALUE_V2
* @brief UUID for the Value V2 Characteristic
*/
#define BT_UUID_VALUE_V2 BT_UUID_DECLARE_16(0xb002)
static uint8_t value_v10_value = 0x0A;
static uint8_t value_v2_value[] = {
'1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3',
'3', '3', '4', '4', '4', '4', '4', '5', '\0'
};
static uint8_t value_v2_1_value[] = {
'2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4',
'4', '4', '5', '5', '5', '5', '5', '6', '6', '\0'
};
static uint8_t value_v2_2_value[] = {
'3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5',
'5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '\0'
};
static uint8_t value_v2_3_value[] = {
'1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3',
'3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6',
'6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8',
'8', '9', '9', '9', '\0'
};
static uint8_t value_v2_4_value[] = {
'2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4',
'4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '7',
'7', '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', '9', '9',
'9', '0', '0', '0', '0', '\0'
};
static uint8_t value_v2_5_value[] = {
'3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5',
'5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '8',
'8', '8', '8', '8', '9', '9', '9', '9', '9', '0', '0', '0', '0',
'0', '1', '1', '1', '1', '1', '\0'
};
/**
* @brief Attribute read call back for the Value V10 attribute
*
* @param conn The connection that is requesting to read
* @param attr The attribute that's being read
* @param buf Buffer to place the read result in
* @param len Length of data to read
* @param offset Offset to start reading from
*
* @return Number of bytes read, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t read_value_v10(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset)
{
const uint8_t *value = attr->user_data;
return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
sizeof(value_v10_value));
}
/**
* @brief Attribute read call back for the Value V2 string attribute
*
* @param conn The connection that is requesting to read
* @param attr The attribute that's being read
* @param buf Buffer to place the read result in
* @param len Length of data to read
* @param offset Offset to start reading from
*
* @return Number of bytes read, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t read_str_value(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset)
{
const char *value = attr->user_data;
return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
strlen(value));
}
/**
* @brief Attribute write call back for the Value V2 attribute
*
* @param conn The connection that is requesting to write
* @param attr The attribute that's being written
* @param buf Buffer with the data to write
* @param len Number of bytes in the buffer
* @param offset Offset to start writing from
* @param flags Flags (BT_GATT_WRITE_*)
*
* @return Number of bytes written, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t write_value_v2(struct bt_conn *conn,
const struct bt_gatt_attr *attr, const void *buf,
uint16_t len, uint16_t offset, uint8_t flags)
{
char *value = attr->user_data;
if (offset >= sizeof(value_v2_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
memcpy(value + offset, buf, len);
return len;
}
/**
* @brief Attribute write call back for the Value V2 attribute
*
* @param conn The connection that is requesting to write
* @param attr The attribute that's being written
* @param buf Buffer with the data to write
* @param len Number of bytes in the buffer
* @param offset Offset to start writing from
* @param flags Flags (BT_GATT_WRITE_*)
*
* @return Number of bytes written, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t write_value_v2_1(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
{
char *value = attr->user_data;
if (offset >= sizeof(value_v2_1_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_1_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
memcpy(value + offset, buf, len);
return len;
}
/**
* @brief Attribute write call back for the Value V2 attribute
*
* @param conn The connection that is requesting to write
* @param attr The attribute that's being written
* @param buf Buffer with the data to write
* @param len Number of bytes in the buffer
* @param offset Offset to start writing from
* @param flags Flags (BT_GATT_WRITE_*)
*
* @return Number of bytes written, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t write_value_v2_2(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
{
char *value = attr->user_data;
if (offset >= sizeof(value_v2_2_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_2_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
memcpy(value + offset, buf, len);
return len;
}
/**
* @brief Attribute write call back for the Value V2 attribute
*
* @param conn The connection that is requesting to write
* @param attr The attribute that's being written
* @param buf Buffer with the data to write
* @param len Number of bytes in the buffer
* @param offset Offset to start writing from
* @param flags Flags (BT_GATT_WRITE_*)
*
* @return Number of bytes written, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t write_value_v2_3(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
{
char *value = attr->user_data;
if (offset >= sizeof(value_v2_3_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_3_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
memcpy(value + offset, buf, len);
return len;
}
/**
* @brief Attribute write call back for the Value V2 attribute
*
* @param conn The connection that is requesting to write
* @param attr The attribute that's being written
* @param buf Buffer with the data to write
* @param len Number of bytes in the buffer
* @param offset Offset to start writing from
* @param flags Flags (BT_GATT_WRITE_*)
*
* @return Number of bytes written, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t write_value_v2_4(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
{
char *value = attr->user_data;
if (offset >= sizeof(value_v2_4_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_4_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
memcpy(value + offset, buf, len);
return len;
}
/**
* @brief Attribute write call back for the Value V2 attribute
*
* @param conn The connection that is requesting to write
* @param attr The attribute that's being written
* @param buf Buffer with the data to write
* @param len Number of bytes in the buffer
* @param offset Offset to start writing from
* @param flags Flags (BT_GATT_WRITE_*)
*
* @return Number of bytes written, or in case of an error - BT_GATT_ERR()
* with a specific ATT error code.
*/
static ssize_t write_value_v2_5(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
{
char *value = attr->user_data;
if (offset >= sizeof(value_v2_5_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_5_value))
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
memcpy(value + offset, buf, len);
return len;
}
static struct bt_gatt_attr service_c_2_2_attrs[] = {
BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_2, 0x10),
BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V10,
BT_GATT_CHRC_READ,
BT_GATT_PERM_READ,
read_value_v10, NULL, &value_v10_value, 0x11),
BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_str_value, write_value_v2, &value_v2_value, 0x13),
BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_str_value, write_value_v2_1, &value_v2_1_value, 0x15),
BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_str_value, write_value_v2_2, &value_v2_2_value, 0x17),
BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_str_value, write_value_v2_3, &value_v2_3_value, 0x19),
BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_str_value, write_value_v2_4, &value_v2_4_value, 0x1B),
BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_str_value, write_value_v2_5, &value_v2_5_value, 0x1D)
};
static struct bt_gatt_service service_c_2_2_svc =
BT_GATT_SERVICE(service_c_2_2_attrs);
/**
* @brief Register the Service C.2 and all its Characteristics...
*/
void service_c_2_2_init(void)
{
bt_gatt_service_register(&service_c_2_2_svc);
}
/**
* @brief Un-Register the Service C.2 and all its Characteristics...
*/
void service_c_2_2_remove(void)
{
bt_gatt_service_unregister(&service_c_2_2_svc);
}
|