1 /**
2  * Copyright (c) 2019 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 /**
7  * @brief Service B.4
8  *
9  *  This code is auto-generated from the Excel Workbook
10  *  'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2'
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.4
21  */
22 #define BT_UUID_SERVICE_B_4             BT_UUID_DECLARE_16(0xa00b)
23 
24 /**
25  *  @brief UUID for the Value V7 Characteristic
26  */
27 #define BT_UUID_VALUE_V7                BT_UUID_DECLARE_16(0xb007)
28 
29 static uint8_t   value_v7_value = 0x07;
30 
31 /**
32  * @brief Attribute write call back for the Value V7 attribute
33  *
34  * @param conn   The connection that is requesting to write
35  * @param attr   The attribute that's being written
36  * @param buf    Buffer with the data to write
37  * @param len    Number of bytes in the buffer
38  * @param offset Offset to start writing from
39  * @param flags  Flags (BT_GATT_WRITE_*)
40  *
41  * @return       Number of bytes written, or in case of an error - BT_GATT_ERR()
42  *               with a specific ATT error code.
43  */
write_value_v7(struct bt_conn * conn,const struct bt_gatt_attr * attr,const void * buf,uint16_t len,uint16_t offset,uint8_t flags)44 static ssize_t write_value_v7(struct bt_conn *conn,
45 			      const struct bt_gatt_attr *attr, const void *buf,
46 			      uint16_t len, uint16_t offset, uint8_t flags)
47 {
48 	uint8_t *value = attr->user_data;
49 
50 	if (offset >= sizeof(value_v7_value)) {
51 		return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
52 	}
53 	if (offset + len > sizeof(value_v7_value)) {
54 		return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
55 	}
56 
57 	memcpy(value + offset, buf, len);
58 
59 	return len;
60 }
61 
62 static struct bt_gatt_attr service_b_4_2_attrs[] = {
63 	BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_4, 0x30),
64 	BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V7,
65 		BT_GATT_CHRC_WRITE,
66 		BT_GATT_PERM_WRITE,
67 		NULL, write_value_v7, &value_v7_value, 0x31)
68 };
69 
70 static struct bt_gatt_service service_b_4_2_svc =
71 		    BT_GATT_SERVICE(service_b_4_2_attrs);
72 
73 /**
74  * @brief Register the Service B.4 and all its Characteristics...
75  */
service_b_4_2_init(void)76 void service_b_4_2_init(void)
77 {
78 	bt_gatt_service_register(&service_b_4_2_svc);
79 }
80 
81 /**
82  * @brief Un-Register the Service B.4 and all its Characteristics...
83  */
service_b_4_2_remove(void)84 void service_b_4_2_remove(void)
85 {
86 	bt_gatt_service_unregister(&service_b_4_2_svc);
87 }
88