User | Revision | Line number | New contents of line |
jinu |
0:6ba9b94b8997
|
1
|
/* Copyright (c) Nordic Semiconductor ASA
|
jinu |
0:6ba9b94b8997
|
2
|
* All rights reserved.
|
jinu |
0:6ba9b94b8997
|
3
|
*
|
jinu |
0:6ba9b94b8997
|
4
|
* Redistribution and use in source and binary forms, with or without modification,
|
jinu |
0:6ba9b94b8997
|
5
|
* are permitted provided that the following conditions are met:
|
jinu |
0:6ba9b94b8997
|
6
|
*
|
jinu |
0:6ba9b94b8997
|
7
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
jinu |
0:6ba9b94b8997
|
8
|
* list of conditions and the following disclaimer.
|
jinu |
0:6ba9b94b8997
|
9
|
*
|
jinu |
0:6ba9b94b8997
|
10
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this
|
jinu |
0:6ba9b94b8997
|
11
|
* list of conditions and the following disclaimer in the documentation and/or
|
jinu |
0:6ba9b94b8997
|
12
|
* other materials provided with the distribution.
|
jinu |
0:6ba9b94b8997
|
13
|
*
|
jinu |
0:6ba9b94b8997
|
14
|
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
|
jinu |
0:6ba9b94b8997
|
15
|
* contributors to this software may be used to endorse or promote products
|
jinu |
0:6ba9b94b8997
|
16
|
* derived from this software without specific prior written permission.
|
jinu |
0:6ba9b94b8997
|
17
|
*
|
jinu |
0:6ba9b94b8997
|
18
|
* 4. This software must only be used in a processor manufactured by Nordic
|
jinu |
0:6ba9b94b8997
|
19
|
* Semiconductor ASA, or in a processor manufactured by a third party that
|
jinu |
0:6ba9b94b8997
|
20
|
* is used in combination with a processor manufactured by Nordic Semiconductor.
|
jinu |
0:6ba9b94b8997
|
21
|
*
|
jinu |
0:6ba9b94b8997
|
22
|
*
|
jinu |
0:6ba9b94b8997
|
23
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
jinu |
0:6ba9b94b8997
|
24
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
jinu |
0:6ba9b94b8997
|
25
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
jinu |
0:6ba9b94b8997
|
26
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
jinu |
0:6ba9b94b8997
|
27
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
jinu |
0:6ba9b94b8997
|
28
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
jinu |
0:6ba9b94b8997
|
29
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
jinu |
0:6ba9b94b8997
|
30
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
jinu |
0:6ba9b94b8997
|
31
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
jinu |
0:6ba9b94b8997
|
32
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
jinu |
0:6ba9b94b8997
|
33
|
*/
|
jinu |
0:6ba9b94b8997
|
34
|
/**
|
jinu |
0:6ba9b94b8997
|
35
|
@addtogroup BLE_GATTS Generic Attribute Profile (GATT) Server
|
jinu |
0:6ba9b94b8997
|
36
|
@{
|
jinu |
0:6ba9b94b8997
|
37
|
@brief Definitions and prototypes for the GATTS interface.
|
jinu |
0:6ba9b94b8997
|
38
|
*/
|
jinu |
0:6ba9b94b8997
|
39
|
|
jinu |
0:6ba9b94b8997
|
40
|
#ifndef BLE_GATTS_H__
|
jinu |
0:6ba9b94b8997
|
41
|
#define BLE_GATTS_H__
|
jinu |
0:6ba9b94b8997
|
42
|
|
jinu |
0:6ba9b94b8997
|
43
|
#include "ble_types.h"
|
jinu |
0:6ba9b94b8997
|
44
|
#include "ble_ranges.h"
|
jinu |
0:6ba9b94b8997
|
45
|
#include "ble_l2cap.h"
|
jinu |
0:6ba9b94b8997
|
46
|
#include "ble_gap.h"
|
jinu |
0:6ba9b94b8997
|
47
|
#include "ble_gatt.h"
|
jinu |
0:6ba9b94b8997
|
48
|
#include "nrf_svc.h"
|
jinu |
0:6ba9b94b8997
|
49
|
|
jinu |
0:6ba9b94b8997
|
50
|
/** @addtogroup BLE_GATTS_ENUMERATIONS Enumerations
|
jinu |
0:6ba9b94b8997
|
51
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
52
|
|
jinu |
0:6ba9b94b8997
|
53
|
/**
|
jinu |
0:6ba9b94b8997
|
54
|
* @brief GATTS API SVC numbers.
|
jinu |
0:6ba9b94b8997
|
55
|
*/
|
jinu |
0:6ba9b94b8997
|
56
|
enum BLE_GATTS_SVCS
|
jinu |
0:6ba9b94b8997
|
57
|
{
|
jinu |
0:6ba9b94b8997
|
58
|
SD_BLE_GATTS_SERVICE_ADD = BLE_GATTS_SVC_BASE, /**< Add a service. */
|
jinu |
0:6ba9b94b8997
|
59
|
SD_BLE_GATTS_INCLUDE_ADD, /**< Add an included service. */
|
jinu |
0:6ba9b94b8997
|
60
|
SD_BLE_GATTS_CHARACTERISTIC_ADD, /**< Add a characteristic. */
|
jinu |
0:6ba9b94b8997
|
61
|
SD_BLE_GATTS_DESCRIPTOR_ADD, /**< Add a generic attribute. */
|
jinu |
0:6ba9b94b8997
|
62
|
SD_BLE_GATTS_VALUE_SET, /**< Set an attribute value. */
|
jinu |
0:6ba9b94b8997
|
63
|
SD_BLE_GATTS_VALUE_GET, /**< Get an attribute value. */
|
jinu |
0:6ba9b94b8997
|
64
|
SD_BLE_GATTS_HVX, /**< Handle Value Notification or Indication. */
|
jinu |
0:6ba9b94b8997
|
65
|
SD_BLE_GATTS_SERVICE_CHANGED, /**< Perform a Service Changed Indication to one or more peers. */
|
jinu |
0:6ba9b94b8997
|
66
|
SD_BLE_GATTS_RW_AUTHORIZE_REPLY, /**< Reply to an authorization request for a read or write operation on one or more attributes. */
|
jinu |
0:6ba9b94b8997
|
67
|
SD_BLE_GATTS_SYS_ATTR_SET, /**< Set the persistent system attributes for a connection. */
|
jinu |
0:6ba9b94b8997
|
68
|
SD_BLE_GATTS_SYS_ATTR_GET, /**< Get updated persistent system attributes after terminating a connection. */
|
jinu |
0:6ba9b94b8997
|
69
|
};
|
jinu |
0:6ba9b94b8997
|
70
|
|
jinu |
0:6ba9b94b8997
|
71
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
72
|
|
jinu |
0:6ba9b94b8997
|
73
|
/** @addtogroup BLE_GATTS_DEFINES Defines
|
jinu |
0:6ba9b94b8997
|
74
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
75
|
|
jinu |
0:6ba9b94b8997
|
76
|
/** @brief Only the default MTU size of 23 is currently supported. */
|
jinu |
0:6ba9b94b8997
|
77
|
#define GATT_RX_MTU 23
|
jinu |
0:6ba9b94b8997
|
78
|
|
jinu |
0:6ba9b94b8997
|
79
|
/** @defgroup BLE_ERRORS_GATTS SVC return values specific to GATTS
|
jinu |
0:6ba9b94b8997
|
80
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
81
|
#define BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000) /**< Invalid attribute type. */
|
jinu |
0:6ba9b94b8997
|
82
|
#define BLE_ERROR_GATTS_SYS_ATTR_MISSING (NRF_GATTS_ERR_BASE + 0x001) /**< System Attributes missing. */
|
jinu |
0:6ba9b94b8997
|
83
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
84
|
|
jinu |
0:6ba9b94b8997
|
85
|
/** @defgroup BLE_GATTS_ATTR_LENS_MAX Maximum attribute lengths
|
jinu |
0:6ba9b94b8997
|
86
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
87
|
#define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */
|
jinu |
0:6ba9b94b8997
|
88
|
#define BLE_GATTS_VAR_ATTR_LEN_MAX (512) /**< Maximum length for variable length Attribute Values. */
|
jinu |
0:6ba9b94b8997
|
89
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
90
|
|
jinu |
0:6ba9b94b8997
|
91
|
/** @defgroup BLE_GATTS_SRVC_TYPES GATT Server Service Types
|
jinu |
0:6ba9b94b8997
|
92
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
93
|
#define BLE_GATTS_SRVC_TYPE_INVALID 0x00 /**< Invalid Service Type. */
|
jinu |
0:6ba9b94b8997
|
94
|
#define BLE_GATTS_SRVC_TYPE_PRIMARY 0x01 /**< Primary Service. */
|
jinu |
0:6ba9b94b8997
|
95
|
#define BLE_GATTS_SRVC_TYPE_SECONDARY 0x02 /**< Secondary Type. */
|
jinu |
0:6ba9b94b8997
|
96
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
97
|
|
jinu |
0:6ba9b94b8997
|
98
|
|
jinu |
0:6ba9b94b8997
|
99
|
/** @defgroup BLE_GATTS_ATTR_TYPES GATT Server Attribute Types
|
jinu |
0:6ba9b94b8997
|
100
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
101
|
#define BLE_GATTS_ATTR_TYPE_INVALID 0x00 /**< Invalid Attribute Type. */
|
jinu |
0:6ba9b94b8997
|
102
|
#define BLE_GATTS_ATTR_TYPE_PRIM_SRVC_DECL 0x01 /**< Primary Service Declaration. */
|
jinu |
0:6ba9b94b8997
|
103
|
#define BLE_GATTS_ATTR_TYPE_SEC_SRVC_DECL 0x02 /**< Secondary Service Declaration. */
|
jinu |
0:6ba9b94b8997
|
104
|
#define BLE_GATTS_ATTR_TYPE_INC_DECL 0x03 /**< Include Declaration. */
|
jinu |
0:6ba9b94b8997
|
105
|
#define BLE_GATTS_ATTR_TYPE_CHAR_DECL 0x04 /**< Characteristic Declaration. */
|
jinu |
0:6ba9b94b8997
|
106
|
#define BLE_GATTS_ATTR_TYPE_CHAR_VAL 0x05 /**< Characteristic Value. */
|
jinu |
0:6ba9b94b8997
|
107
|
#define BLE_GATTS_ATTR_TYPE_DESC 0x06 /**< Descriptor. */
|
jinu |
0:6ba9b94b8997
|
108
|
#define BLE_GATTS_ATTR_TYPE_OTHER 0x07 /**< Other, non-GATT specific type. */
|
jinu |
0:6ba9b94b8997
|
109
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
110
|
|
jinu |
0:6ba9b94b8997
|
111
|
|
jinu |
0:6ba9b94b8997
|
112
|
/** @defgroup BLE_GATTS_OPS GATT Server Operations
|
jinu |
0:6ba9b94b8997
|
113
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
114
|
#define BLE_GATTS_OP_INVALID 0x00 /**< Invalid Operation. */
|
jinu |
0:6ba9b94b8997
|
115
|
#define BLE_GATTS_OP_WRITE_REQ 0x01 /**< Write Request. */
|
jinu |
0:6ba9b94b8997
|
116
|
#define BLE_GATTS_OP_WRITE_CMD 0x02 /**< Write Command. */
|
jinu |
0:6ba9b94b8997
|
117
|
#define BLE_GATTS_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */
|
jinu |
0:6ba9b94b8997
|
118
|
#define BLE_GATTS_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */
|
jinu |
0:6ba9b94b8997
|
119
|
#define BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL 0x05 /**< Execute Write Request: Cancel all prepared writes. */
|
jinu |
0:6ba9b94b8997
|
120
|
#define BLE_GATTS_OP_EXEC_WRITE_REQ_NOW 0x06 /**< Execute Write Request: Immediately execute all prepared writes. */
|
jinu |
0:6ba9b94b8997
|
121
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
122
|
|
jinu |
0:6ba9b94b8997
|
123
|
/** @defgroup BLE_GATTS_VLOCS GATT Value Locations
|
jinu |
0:6ba9b94b8997
|
124
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
125
|
#define BLE_GATTS_VLOC_INVALID 0x00 /**< Invalid Location. */
|
jinu |
0:6ba9b94b8997
|
126
|
#define BLE_GATTS_VLOC_STACK 0x01 /**< Attribute Value is located in stack memory, no user memory is required. */
|
jinu |
0:6ba9b94b8997
|
127
|
#define BLE_GATTS_VLOC_USER 0x02 /**< Attribute Value is located in user memory. This requires the user to maintain a valid buffer through the lifetime of the attribute, since the stack
|
jinu |
0:6ba9b94b8997
|
128
|
will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */
|
jinu |
0:6ba9b94b8997
|
129
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
130
|
|
jinu |
0:6ba9b94b8997
|
131
|
/** @defgroup BLE_GATTS_AUTHORIZE_TYPES GATT Server Authorization Types
|
jinu |
0:6ba9b94b8997
|
132
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
133
|
#define BLE_GATTS_AUTHORIZE_TYPE_INVALID 0x00 /**< Invalid Type. */
|
jinu |
0:6ba9b94b8997
|
134
|
#define BLE_GATTS_AUTHORIZE_TYPE_READ 0x01 /**< Authorize a Read Operation. */
|
jinu |
0:6ba9b94b8997
|
135
|
#define BLE_GATTS_AUTHORIZE_TYPE_WRITE 0x02 /**< Authorize a Write Request Operation. */
|
jinu |
0:6ba9b94b8997
|
136
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
137
|
|
jinu |
0:6ba9b94b8997
|
138
|
|
jinu |
0:6ba9b94b8997
|
139
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
140
|
|
jinu |
0:6ba9b94b8997
|
141
|
/** @addtogroup BLE_GATTS_STRUCTURES Structures
|
jinu |
0:6ba9b94b8997
|
142
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
143
|
|
jinu |
0:6ba9b94b8997
|
144
|
/**
|
jinu |
0:6ba9b94b8997
|
145
|
* @brief BLE GATTS init options
|
jinu |
0:6ba9b94b8997
|
146
|
*/
|
jinu |
0:6ba9b94b8997
|
147
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
148
|
{
|
jinu |
0:6ba9b94b8997
|
149
|
uint8_t service_changed:1; /**< Include the Service Changed characteristic in the local attributes. */
|
jinu |
0:6ba9b94b8997
|
150
|
} ble_gatts_enable_params_t;
|
jinu |
0:6ba9b94b8997
|
151
|
|
jinu |
0:6ba9b94b8997
|
152
|
/**@brief Attribute metadata. */
|
jinu |
0:6ba9b94b8997
|
153
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
154
|
{
|
jinu |
0:6ba9b94b8997
|
155
|
ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */
|
jinu |
0:6ba9b94b8997
|
156
|
ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */
|
jinu |
0:6ba9b94b8997
|
157
|
uint8_t vlen :1; /**< Variable length attribute. */
|
jinu |
0:6ba9b94b8997
|
158
|
uint8_t vloc :2; /**< Value location, see @ref BLE_GATTS_VLOCS.*/
|
jinu |
0:6ba9b94b8997
|
159
|
uint8_t rd_auth :1; /**< Read Authorization and value will be requested from the application on every read operation. */
|
jinu |
0:6ba9b94b8997
|
160
|
uint8_t wr_auth :1; /**< Write Authorization will be requested from the application on every Write Request operation (but not Write Command). */
|
jinu |
0:6ba9b94b8997
|
161
|
} ble_gatts_attr_md_t;
|
jinu |
0:6ba9b94b8997
|
162
|
|
jinu |
0:6ba9b94b8997
|
163
|
|
jinu |
0:6ba9b94b8997
|
164
|
/**@brief GATT Attribute. */
|
jinu |
0:6ba9b94b8997
|
165
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
166
|
{
|
jinu |
0:6ba9b94b8997
|
167
|
ble_uuid_t* p_uuid; /**< Pointer to the attribute UUID. */
|
jinu |
0:6ba9b94b8997
|
168
|
ble_gatts_attr_md_t* p_attr_md; /**< Pointer to the attribute metadata structure. */
|
jinu |
0:6ba9b94b8997
|
169
|
uint16_t init_len; /**< Initial attribute value length in bytes. */
|
jinu |
0:6ba9b94b8997
|
170
|
uint16_t init_offs; /**< Initial attribute value offset in bytes. If different from zero, the first init_offs bytes of the attribute value will be left uninitialized. */
|
jinu |
0:6ba9b94b8997
|
171
|
uint16_t max_len; /**< Maximum attribute value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */
|
jinu |
0:6ba9b94b8997
|
172
|
uint8_t* p_value; /**< Pointer to the attribute data. Please note that if the @ref BLE_GATTS_VLOC_USER value location is selected in the attribute metadata, this will have to point to a buffer
|
jinu |
0:6ba9b94b8997
|
173
|
that remains valid through the lifetime of the attribute. This excludes usage of automatic variables that may go out of scope or any other temporary location.
|
jinu |
0:6ba9b94b8997
|
174
|
The stack may access that memory directly without the application's knowledge. */
|
jinu |
0:6ba9b94b8997
|
175
|
} ble_gatts_attr_t;
|
jinu |
0:6ba9b94b8997
|
176
|
|
jinu |
0:6ba9b94b8997
|
177
|
|
jinu |
0:6ba9b94b8997
|
178
|
/**@brief GATT Attribute Context. */
|
jinu |
0:6ba9b94b8997
|
179
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
180
|
{
|
jinu |
0:6ba9b94b8997
|
181
|
ble_uuid_t srvc_uuid; /**< Service UUID. */
|
jinu |
0:6ba9b94b8997
|
182
|
ble_uuid_t char_uuid; /**< Characteristic UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
|
jinu |
0:6ba9b94b8997
|
183
|
ble_uuid_t desc_uuid; /**< Descriptor UUID if applicable (BLE_UUID_TYPE_UNKNOWN if N/A). */
|
jinu |
0:6ba9b94b8997
|
184
|
uint16_t srvc_handle; /**< Service Handle. */
|
jinu |
0:6ba9b94b8997
|
185
|
uint16_t value_handle; /**< Characteristic Handle if applicable (BLE_GATT_HANDLE_INVALID if N/A). */
|
jinu |
0:6ba9b94b8997
|
186
|
uint8_t type; /**< Attribute Type, see @ref BLE_GATTS_ATTR_TYPES. */
|
jinu |
0:6ba9b94b8997
|
187
|
} ble_gatts_attr_context_t;
|
jinu |
0:6ba9b94b8997
|
188
|
|
jinu |
0:6ba9b94b8997
|
189
|
|
jinu |
0:6ba9b94b8997
|
190
|
/**@brief GATT Characteristic Presentation Format. */
|
jinu |
0:6ba9b94b8997
|
191
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
192
|
{
|
jinu |
0:6ba9b94b8997
|
193
|
uint8_t format; /**< Format of the value, see @ref BLE_GATT_CPF_FORMATS. */
|
jinu |
0:6ba9b94b8997
|
194
|
int8_t exponent; /**< Exponent for integer data types. */
|
jinu |
0:6ba9b94b8997
|
195
|
uint16_t unit; /**< UUID from Bluetooth Assigned Numbers. */
|
jinu |
0:6ba9b94b8997
|
196
|
uint8_t name_space; /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
|
jinu |
0:6ba9b94b8997
|
197
|
uint16_t desc; /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
|
jinu |
0:6ba9b94b8997
|
198
|
} ble_gatts_char_pf_t;
|
jinu |
0:6ba9b94b8997
|
199
|
|
jinu |
0:6ba9b94b8997
|
200
|
|
jinu |
0:6ba9b94b8997
|
201
|
/**@brief GATT Characteristic metadata. */
|
jinu |
0:6ba9b94b8997
|
202
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
203
|
{
|
jinu |
0:6ba9b94b8997
|
204
|
ble_gatt_char_props_t char_props; /**< Characteristic Properties. */
|
jinu |
0:6ba9b94b8997
|
205
|
ble_gatt_char_ext_props_t char_ext_props; /**< Characteristic Extended Properties. */
|
jinu |
0:6ba9b94b8997
|
206
|
uint8_t* p_char_user_desc; /**< Pointer to a UTF-8, NULL if the descriptor is not required. */
|
jinu |
0:6ba9b94b8997
|
207
|
uint16_t char_user_desc_max_size; /**< The maximum size in bytes of the user description descriptor. */
|
jinu |
0:6ba9b94b8997
|
208
|
uint16_t char_user_desc_size; /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */
|
jinu |
0:6ba9b94b8997
|
209
|
ble_gatts_char_pf_t* p_char_pf; /**< Pointer to a presentation format structure or NULL if the descriptor is not required. */
|
jinu |
0:6ba9b94b8997
|
210
|
ble_gatts_attr_md_t* p_user_desc_md; /**< Attribute metadata for the User Description descriptor, or NULL for default values. */
|
jinu |
0:6ba9b94b8997
|
211
|
ble_gatts_attr_md_t* p_cccd_md; /**< Attribute metadata for the Client Characteristic Configuration Descriptor, or NULL for default values. */
|
jinu |
0:6ba9b94b8997
|
212
|
ble_gatts_attr_md_t* p_sccd_md; /**< Attribute metadata for the Server Characteristic Configuration Descriptor, or NULL for default values. */
|
jinu |
0:6ba9b94b8997
|
213
|
} ble_gatts_char_md_t;
|
jinu |
0:6ba9b94b8997
|
214
|
|
jinu |
0:6ba9b94b8997
|
215
|
|
jinu |
0:6ba9b94b8997
|
216
|
/**@brief GATT Characteristic Definition Handles. */
|
jinu |
0:6ba9b94b8997
|
217
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
218
|
{
|
jinu |
0:6ba9b94b8997
|
219
|
uint16_t value_handle; /**< Handle to the characteristic value. */
|
jinu |
0:6ba9b94b8997
|
220
|
uint16_t user_desc_handle; /**< Handle to the User Description descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
|
jinu |
0:6ba9b94b8997
|
221
|
uint16_t cccd_handle; /**< Handle to the Client Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
|
jinu |
0:6ba9b94b8997
|
222
|
uint16_t sccd_handle; /**< Handle to the Server Characteristic Configuration Descriptor, or BLE_GATT_HANDLE_INVALID if not present. */
|
jinu |
0:6ba9b94b8997
|
223
|
} ble_gatts_char_handles_t;
|
jinu |
0:6ba9b94b8997
|
224
|
|
jinu |
0:6ba9b94b8997
|
225
|
|
jinu |
0:6ba9b94b8997
|
226
|
/**@brief GATT HVx parameters. */
|
jinu |
0:6ba9b94b8997
|
227
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
228
|
{
|
jinu |
0:6ba9b94b8997
|
229
|
uint16_t handle; /**< Characteristic Value Handle. */
|
jinu |
0:6ba9b94b8997
|
230
|
uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
|
jinu |
0:6ba9b94b8997
|
231
|
uint16_t offset; /**< Offset within the attribute value. */
|
jinu |
0:6ba9b94b8997
|
232
|
uint16_t* p_len; /**< Length in bytes to be written, length in bytes written after successful return. */
|
jinu |
0:6ba9b94b8997
|
233
|
uint8_t* p_data; /**< Actual data content, use NULL to use the current attribute value. */
|
jinu |
0:6ba9b94b8997
|
234
|
} ble_gatts_hvx_params_t;
|
jinu |
0:6ba9b94b8997
|
235
|
|
jinu |
0:6ba9b94b8997
|
236
|
/**@brief GATT Read Authorization parameters. */
|
jinu |
0:6ba9b94b8997
|
237
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
238
|
{
|
jinu |
0:6ba9b94b8997
|
239
|
uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
|
jinu |
0:6ba9b94b8997
|
240
|
uint8_t update : 1; /**< If set, data supplied in p_data will be used in the ATT response. */
|
jinu |
0:6ba9b94b8997
|
241
|
uint16_t offset; /**< Offset of the attribute value being updated. */
|
jinu |
0:6ba9b94b8997
|
242
|
uint16_t len; /**< Length in bytes of the value in p_data pointer, see @ref BLE_GATTS_ATTR_LENS_MAX. */
|
jinu |
0:6ba9b94b8997
|
243
|
uint8_t* p_data; /**< Pointer to new value used to update the attribute value. */
|
jinu |
0:6ba9b94b8997
|
244
|
} ble_gatts_read_authorize_params_t;
|
jinu |
0:6ba9b94b8997
|
245
|
|
jinu |
0:6ba9b94b8997
|
246
|
/**@brief GATT Write Authorisation parameters. */
|
jinu |
0:6ba9b94b8997
|
247
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
248
|
{
|
jinu |
0:6ba9b94b8997
|
249
|
uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
|
jinu |
0:6ba9b94b8997
|
250
|
} ble_gatts_write_authorize_params_t;
|
jinu |
0:6ba9b94b8997
|
251
|
|
jinu |
0:6ba9b94b8997
|
252
|
/**@brief GATT Read or Write Authorize Reply parameters. */
|
jinu |
0:6ba9b94b8997
|
253
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
254
|
{
|
jinu |
0:6ba9b94b8997
|
255
|
uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
|
jinu |
0:6ba9b94b8997
|
256
|
union {
|
jinu |
0:6ba9b94b8997
|
257
|
ble_gatts_read_authorize_params_t read; /**< Read authorization parameters. */
|
jinu |
0:6ba9b94b8997
|
258
|
ble_gatts_write_authorize_params_t write; /**< Write authorization parameters. */
|
jinu |
0:6ba9b94b8997
|
259
|
} params;
|
jinu |
0:6ba9b94b8997
|
260
|
} ble_gatts_rw_authorize_reply_params_t;
|
jinu |
0:6ba9b94b8997
|
261
|
|
jinu |
0:6ba9b94b8997
|
262
|
|
jinu |
0:6ba9b94b8997
|
263
|
/**
|
jinu |
0:6ba9b94b8997
|
264
|
* @brief GATT Server Event IDs.
|
jinu |
0:6ba9b94b8997
|
265
|
*/
|
jinu |
0:6ba9b94b8997
|
266
|
enum BLE_GATTS_EVTS
|
jinu |
0:6ba9b94b8997
|
267
|
{
|
jinu |
0:6ba9b94b8997
|
268
|
BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE, /**< Write operation performed. */
|
jinu |
0:6ba9b94b8997
|
269
|
BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, /**< Read/Write Authorization request. */
|
jinu |
0:6ba9b94b8997
|
270
|
BLE_GATTS_EVT_SYS_ATTR_MISSING, /**< A persistent system attribute access is pending, awaiting a sd_ble_gatts_sys_attr_set(). */
|
jinu |
0:6ba9b94b8997
|
271
|
BLE_GATTS_EVT_HVC, /**< Handle Value Confirmation. */
|
jinu |
0:6ba9b94b8997
|
272
|
BLE_GATTS_EVT_SC_CONFIRM, /**< Service Changed Confirmation. */
|
jinu |
0:6ba9b94b8997
|
273
|
BLE_GATTS_EVT_TIMEOUT /**< Timeout. */
|
jinu |
0:6ba9b94b8997
|
274
|
};
|
jinu |
0:6ba9b94b8997
|
275
|
|
jinu |
0:6ba9b94b8997
|
276
|
|
jinu |
0:6ba9b94b8997
|
277
|
/**@brief Event structure for BLE_GATTS_EVT_WRITE. */
|
jinu |
0:6ba9b94b8997
|
278
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
279
|
{
|
jinu |
0:6ba9b94b8997
|
280
|
uint16_t handle; /**< Attribute Handle. */
|
jinu |
0:6ba9b94b8997
|
281
|
uint8_t op; /**< Type of write operation, see @ref BLE_GATTS_OPS. */
|
jinu |
0:6ba9b94b8997
|
282
|
ble_gatts_attr_context_t context; /**< Attribute Context. */
|
jinu |
0:6ba9b94b8997
|
283
|
uint16_t offset; /**< Offset for the write operation. */
|
jinu |
0:6ba9b94b8997
|
284
|
uint16_t len; /**< Length of the incoming data. */
|
jinu |
0:6ba9b94b8997
|
285
|
uint8_t data[1]; /**< Incoming data, variable length. */
|
jinu |
0:6ba9b94b8997
|
286
|
} ble_gatts_evt_write_t;
|
jinu |
0:6ba9b94b8997
|
287
|
|
jinu |
0:6ba9b94b8997
|
288
|
/**@brief Event structure for authorize read request. */
|
jinu |
0:6ba9b94b8997
|
289
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
290
|
{
|
jinu |
0:6ba9b94b8997
|
291
|
uint16_t handle; /**< Attribute Handle. */
|
jinu |
0:6ba9b94b8997
|
292
|
ble_gatts_attr_context_t context; /**< Attribute Context. */
|
jinu |
0:6ba9b94b8997
|
293
|
uint16_t offset; /**< Offset for the read operation. */
|
jinu |
0:6ba9b94b8997
|
294
|
} ble_gatts_evt_read_t;
|
jinu |
0:6ba9b94b8997
|
295
|
|
jinu |
0:6ba9b94b8997
|
296
|
/**@brief Event structure for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */
|
jinu |
0:6ba9b94b8997
|
297
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
298
|
{
|
jinu |
0:6ba9b94b8997
|
299
|
uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
|
jinu |
0:6ba9b94b8997
|
300
|
union {
|
jinu |
0:6ba9b94b8997
|
301
|
ble_gatts_evt_read_t read; /**< Attribute Read Parameters. */
|
jinu |
0:6ba9b94b8997
|
302
|
ble_gatts_evt_write_t write; /**< Attribute Write Parameters. */
|
jinu |
0:6ba9b94b8997
|
303
|
} request;
|
jinu |
0:6ba9b94b8997
|
304
|
} ble_gatts_evt_rw_authorize_request_t;
|
jinu |
0:6ba9b94b8997
|
305
|
|
jinu |
0:6ba9b94b8997
|
306
|
/**@brief Event structure for BLE_GATTS_EVT_SYS_ATTR_MISSING. */
|
jinu |
0:6ba9b94b8997
|
307
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
308
|
{
|
jinu |
0:6ba9b94b8997
|
309
|
uint8_t hint;
|
jinu |
0:6ba9b94b8997
|
310
|
} ble_gatts_evt_sys_attr_missing_t;
|
jinu |
0:6ba9b94b8997
|
311
|
|
jinu |
0:6ba9b94b8997
|
312
|
|
jinu |
0:6ba9b94b8997
|
313
|
/**@brief Event structure for BLE_GATTS_EVT_HVC. */
|
jinu |
0:6ba9b94b8997
|
314
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
315
|
{
|
jinu |
0:6ba9b94b8997
|
316
|
uint16_t handle; /**< Attribute Handle. */
|
jinu |
0:6ba9b94b8997
|
317
|
} ble_gatts_evt_hvc_t;
|
jinu |
0:6ba9b94b8997
|
318
|
|
jinu |
0:6ba9b94b8997
|
319
|
/**@brief Event structure for BLE_GATTS_EVT_TIMEOUT. */
|
jinu |
0:6ba9b94b8997
|
320
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
321
|
{
|
jinu |
0:6ba9b94b8997
|
322
|
uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
|
jinu |
0:6ba9b94b8997
|
323
|
} ble_gatts_evt_timeout_t;
|
jinu |
0:6ba9b94b8997
|
324
|
|
jinu |
0:6ba9b94b8997
|
325
|
|
jinu |
0:6ba9b94b8997
|
326
|
/**@brief GATT Server event callback event structure. */
|
jinu |
0:6ba9b94b8997
|
327
|
typedef struct
|
jinu |
0:6ba9b94b8997
|
328
|
{
|
jinu |
0:6ba9b94b8997
|
329
|
uint16_t conn_handle; /**< Connection Handle on which event occurred. */
|
jinu |
0:6ba9b94b8997
|
330
|
union
|
jinu |
0:6ba9b94b8997
|
331
|
{
|
jinu |
0:6ba9b94b8997
|
332
|
ble_gatts_evt_write_t write; /**< Write Event Parameters. */
|
jinu |
0:6ba9b94b8997
|
333
|
ble_gatts_evt_rw_authorize_request_t authorize_request; /**< Read or Write Authorize Request Parameters. */
|
jinu |
0:6ba9b94b8997
|
334
|
ble_gatts_evt_sys_attr_missing_t sys_attr_missing; /**< System attributes missing. */
|
jinu |
0:6ba9b94b8997
|
335
|
ble_gatts_evt_hvc_t hvc; /**< Handle Value Confirmation Event Parameters. */
|
jinu |
0:6ba9b94b8997
|
336
|
ble_gatts_evt_timeout_t timeout; /**< Timeout Event. */
|
jinu |
0:6ba9b94b8997
|
337
|
} params;
|
jinu |
0:6ba9b94b8997
|
338
|
} ble_gatts_evt_t;
|
jinu |
0:6ba9b94b8997
|
339
|
|
jinu |
0:6ba9b94b8997
|
340
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
341
|
|
jinu |
0:6ba9b94b8997
|
342
|
/** @addtogroup BLE_GATTS_FUNCTIONS Functions
|
jinu |
0:6ba9b94b8997
|
343
|
* @{ */
|
jinu |
0:6ba9b94b8997
|
344
|
|
jinu |
0:6ba9b94b8997
|
345
|
/**@brief Add a service declaration to the local server ATT table.
|
jinu |
0:6ba9b94b8997
|
346
|
*
|
jinu |
0:6ba9b94b8997
|
347
|
* @param[in] type Toggles between primary and secondary services, see @ref BLE_GATTS_SRVC_TYPES.
|
jinu |
0:6ba9b94b8997
|
348
|
* @param[in] p_uuid Pointer to service UUID.
|
jinu |
0:6ba9b94b8997
|
349
|
* @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
|
jinu |
0:6ba9b94b8997
|
350
|
*
|
jinu |
0:6ba9b94b8997
|
351
|
* @note Secondary Services are only relevant in the context of the entity that references them, it is therefore forbidden to
|
jinu |
0:6ba9b94b8997
|
352
|
* add a secondary service declaration that is not referenced by another service later in the ATT table.
|
jinu |
0:6ba9b94b8997
|
353
|
*
|
jinu |
0:6ba9b94b8997
|
354
|
* @return @ref NRF_SUCCESS Successfully added a service declaration.
|
jinu |
0:6ba9b94b8997
|
355
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
356
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table.
|
jinu |
0:6ba9b94b8997
|
357
|
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
|
jinu |
0:6ba9b94b8997
|
358
|
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
|
jinu |
0:6ba9b94b8997
|
359
|
*/
|
jinu |
0:6ba9b94b8997
|
360
|
SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const*const p_uuid, uint16_t *const p_handle));
|
jinu |
0:6ba9b94b8997
|
361
|
|
jinu |
0:6ba9b94b8997
|
362
|
|
jinu |
0:6ba9b94b8997
|
363
|
/**@brief Add an include declaration to the local server ATT table.
|
jinu |
0:6ba9b94b8997
|
364
|
*
|
jinu |
0:6ba9b94b8997
|
365
|
* @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential addition is supported at this time).
|
jinu |
0:6ba9b94b8997
|
366
|
*
|
jinu |
0:6ba9b94b8997
|
367
|
* @note The included service must already be present in the ATT table prior to this call.
|
jinu |
0:6ba9b94b8997
|
368
|
*
|
jinu |
0:6ba9b94b8997
|
369
|
* @param[in] service_handle Handle of the service where the included service is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
|
jinu |
0:6ba9b94b8997
|
370
|
* @param[in] inc_srvc_handle Handle of the included service.
|
jinu |
0:6ba9b94b8997
|
371
|
* @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored.
|
jinu |
0:6ba9b94b8997
|
372
|
*
|
jinu |
0:6ba9b94b8997
|
373
|
* @return @ref NRF_SUCCESS Successfully added an include declaration.
|
jinu |
0:6ba9b94b8997
|
374
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
375
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services.
|
jinu |
0:6ba9b94b8997
|
376
|
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
|
jinu |
0:6ba9b94b8997
|
377
|
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed.
|
jinu |
0:6ba9b94b8997
|
378
|
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
|
jinu |
0:6ba9b94b8997
|
379
|
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
|
jinu |
0:6ba9b94b8997
|
380
|
*/
|
jinu |
0:6ba9b94b8997
|
381
|
SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *const p_include_handle));
|
jinu |
0:6ba9b94b8997
|
382
|
|
jinu |
0:6ba9b94b8997
|
383
|
|
jinu |
0:6ba9b94b8997
|
384
|
/**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the local server ATT table.
|
jinu |
0:6ba9b94b8997
|
385
|
*
|
jinu |
0:6ba9b94b8997
|
386
|
* @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential addition is supported at this time).
|
jinu |
0:6ba9b94b8997
|
387
|
*
|
jinu |
0:6ba9b94b8997
|
388
|
* @note Several restrictions apply to the parameters, such as matching permissions between the user description descriptor and the writeable auxiliaries bits,
|
jinu |
0:6ba9b94b8997
|
389
|
* readable (no security) and writeable (selectable) CCCDs and SCCDs and valid presentation format values.
|
jinu |
0:6ba9b94b8997
|
390
|
*
|
jinu |
0:6ba9b94b8997
|
391
|
* @note If no metadata is provided for the optional descriptors, their permissions will be derived from the characteristic permissions.
|
jinu |
0:6ba9b94b8997
|
392
|
*
|
jinu |
0:6ba9b94b8997
|
393
|
* @param[in] service_handle Handle of the service where the characteristic is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
|
jinu |
0:6ba9b94b8997
|
394
|
* @param[in] p_char_md Characteristic metadata.
|
jinu |
0:6ba9b94b8997
|
395
|
* @param[in] p_attr_char_value Pointer to the attribute structure corresponding to the characteristic value.
|
jinu |
0:6ba9b94b8997
|
396
|
* @param[out] p_handles Pointer to the structure where the assigned handles will be stored.
|
jinu |
0:6ba9b94b8997
|
397
|
*
|
jinu |
0:6ba9b94b8997
|
398
|
* @return @ref NRF_SUCCESS Successfully added a characteristic.
|
jinu |
0:6ba9b94b8997
|
399
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
400
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
|
jinu |
0:6ba9b94b8997
|
401
|
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required.
|
jinu |
0:6ba9b94b8997
|
402
|
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
|
jinu |
0:6ba9b94b8997
|
403
|
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
|
jinu |
0:6ba9b94b8997
|
404
|
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
|
jinu |
0:6ba9b94b8997
|
405
|
*/
|
jinu |
0:6ba9b94b8997
|
406
|
SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const*const p_char_md, ble_gatts_attr_t const*const p_attr_char_value, ble_gatts_char_handles_t *const p_handles));
|
jinu |
0:6ba9b94b8997
|
407
|
|
jinu |
0:6ba9b94b8997
|
408
|
|
jinu |
0:6ba9b94b8997
|
409
|
/**@brief Add a descriptor to the local server ATT table.
|
jinu |
0:6ba9b94b8997
|
410
|
*
|
jinu |
0:6ba9b94b8997
|
411
|
* @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential addition is supported at this time).
|
jinu |
0:6ba9b94b8997
|
412
|
*
|
jinu |
0:6ba9b94b8997
|
413
|
* @param[in] char_handle Handle of the characteristic where the descriptor is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
|
jinu |
0:6ba9b94b8997
|
414
|
* @param[in] p_attr Pointer to the attribute structure.
|
jinu |
0:6ba9b94b8997
|
415
|
* @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
|
jinu |
0:6ba9b94b8997
|
416
|
*
|
jinu |
0:6ba9b94b8997
|
417
|
* @return @ref NRF_SUCCESS Successfully added a descriptor.
|
jinu |
0:6ba9b94b8997
|
418
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
419
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
|
jinu |
0:6ba9b94b8997
|
420
|
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required.
|
jinu |
0:6ba9b94b8997
|
421
|
* @return @ref NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
|
jinu |
0:6ba9b94b8997
|
422
|
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
|
jinu |
0:6ba9b94b8997
|
423
|
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
|
jinu |
0:6ba9b94b8997
|
424
|
*/
|
jinu |
0:6ba9b94b8997
|
425
|
SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const * const p_attr, uint16_t* const p_handle));
|
jinu |
0:6ba9b94b8997
|
426
|
|
jinu |
0:6ba9b94b8997
|
427
|
/**@brief Set the value of a given attribute.
|
jinu |
0:6ba9b94b8997
|
428
|
*
|
jinu |
0:6ba9b94b8997
|
429
|
* @param[in] handle Attribute handle.
|
jinu |
0:6ba9b94b8997
|
430
|
* @param[in] offset Offset in bytes to write from.
|
jinu |
0:6ba9b94b8997
|
431
|
* @param[in,out] p_len Length in bytes to be written, length in bytes written after successful return.
|
jinu |
0:6ba9b94b8997
|
432
|
* @param[in] p_value Pointer to a buffer (at least len bytes long) containing the desired attribute value. If value is stored in user memory, only the attribute length is updated when p_value == NULL.
|
jinu |
0:6ba9b94b8997
|
433
|
*
|
jinu |
0:6ba9b94b8997
|
434
|
* @return @ref NRF_SUCCESS Successfully set the value of the attribute.
|
jinu |
0:6ba9b94b8997
|
435
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
436
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
|
jinu |
0:6ba9b94b8997
|
437
|
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
|
jinu |
0:6ba9b94b8997
|
438
|
* @return @ref NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application.
|
jinu |
0:6ba9b94b8997
|
439
|
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
|
jinu |
0:6ba9b94b8997
|
440
|
*/
|
jinu |
0:6ba9b94b8997
|
441
|
SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t handle, uint16_t offset, uint16_t* const p_len, uint8_t const * const p_value));
|
jinu |
0:6ba9b94b8997
|
442
|
|
jinu |
0:6ba9b94b8997
|
443
|
/**@brief Get the value of a given attribute.
|
jinu |
0:6ba9b94b8997
|
444
|
*
|
jinu |
0:6ba9b94b8997
|
445
|
* @param[in] handle Attribute handle.
|
jinu |
0:6ba9b94b8997
|
446
|
* @param[in] offset Offset in bytes to read from.
|
jinu |
0:6ba9b94b8997
|
447
|
* @param[in,out] p_len Length in bytes to be read, total length of attribute value (in bytes, starting from offset) after successful return.
|
jinu |
0:6ba9b94b8997
|
448
|
* @param[in,out] p_data Pointer to a buffer (at least len bytes long) where to store the attribute value. Set to NULL to obtain the complete length of attribute value.
|
jinu |
0:6ba9b94b8997
|
449
|
*
|
jinu |
0:6ba9b94b8997
|
450
|
* @note If the attribute value is longer than the size of the supplied buffer,
|
jinu |
0:6ba9b94b8997
|
451
|
* p_len will return the total attribute value length (excluding offset),
|
jinu |
0:6ba9b94b8997
|
452
|
* and not the number of bytes actually returned in p_data.
|
jinu |
0:6ba9b94b8997
|
453
|
* The application may use this information to allocate a suitable buffer size.
|
jinu |
0:6ba9b94b8997
|
454
|
*
|
jinu |
0:6ba9b94b8997
|
455
|
* @return @ref NRF_SUCCESS Successfully retrieved the value of the attribute.
|
jinu |
0:6ba9b94b8997
|
456
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
457
|
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
|
jinu |
0:6ba9b94b8997
|
458
|
*/
|
jinu |
0:6ba9b94b8997
|
459
|
SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t handle, uint16_t offset, uint16_t *const p_len, uint8_t* const p_data));
|
jinu |
0:6ba9b94b8997
|
460
|
|
jinu |
0:6ba9b94b8997
|
461
|
/**@brief Notify or Indicate an attribute value.
|
jinu |
0:6ba9b94b8997
|
462
|
*
|
jinu |
0:6ba9b94b8997
|
463
|
* @details This function checks for the relevant Client Characteristic Configuration descriptor value to verify that the relevant operation
|
jinu |
0:6ba9b94b8997
|
464
|
* (notification or indication) has been enabled by the client. It is also able to update the attribute value before issuing the PDU, so that
|
jinu |
0:6ba9b94b8997
|
465
|
* the application can atomically perform a value update and a server initiated transaction with a single API call.
|
jinu |
0:6ba9b94b8997
|
466
|
* If the application chooses to indicate an attribute value, a @ref BLE_GATTS_EVT_HVC will be sent up as soon as the confirmation arrives from
|
jinu |
0:6ba9b94b8997
|
467
|
* the peer.
|
jinu |
0:6ba9b94b8997
|
468
|
*
|
jinu |
0:6ba9b94b8997
|
469
|
* @note The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution.
|
jinu |
0:6ba9b94b8997
|
470
|
* When receiveing the error codes @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and
|
jinu |
0:6ba9b94b8997
|
471
|
* @ref BLE_ERROR_NO_TX_BUFFERS the ATT table has been updated.
|
jinu |
0:6ba9b94b8997
|
472
|
* The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params->p_len).
|
jinu |
0:6ba9b94b8997
|
473
|
*
|
jinu |
0:6ba9b94b8997
|
474
|
* @note It is important to note that a notification will <b>consume an application buffer</b>, and will therefore
|
jinu |
0:6ba9b94b8997
|
475
|
* generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. An indication on the other hand will use the
|
jinu |
0:6ba9b94b8997
|
476
|
* standard server internal buffer and thus will only generate a @ref BLE_GATTS_EVT_HVC event as soon as the confirmation
|
jinu |
0:6ba9b94b8997
|
477
|
* has been received from the peer. Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
|
jinu |
0:6ba9b94b8997
|
478
|
*
|
jinu |
0:6ba9b94b8997
|
479
|
* @param[in] conn_handle Connection handle.
|
jinu |
0:6ba9b94b8997
|
480
|
* @param[in] p_hvx_params Pointer to an HVx parameters structure. If the p_data member contains a non-NULL pointer the attribute value will be updated with
|
jinu |
0:6ba9b94b8997
|
481
|
* the contents pointed by it before sending the notification or indication.
|
jinu |
0:6ba9b94b8997
|
482
|
*
|
jinu |
0:6ba9b94b8997
|
483
|
* @return @ref NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value.
|
jinu |
0:6ba9b94b8997
|
484
|
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
485
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
486
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
|
jinu |
0:6ba9b94b8997
|
487
|
* @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate.
|
jinu |
0:6ba9b94b8997
|
488
|
* @return @ref BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated.
|
jinu |
0:6ba9b94b8997
|
489
|
* @return @ref NRF_ERROR_NOT_FOUND Attribute not found.
|
jinu |
0:6ba9b94b8997
|
490
|
* @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
|
jinu |
0:6ba9b94b8997
|
491
|
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
|
jinu |
0:6ba9b94b8997
|
492
|
* @return @ref NRF_ERROR_BUSY Procedure already in progress.
|
jinu |
0:6ba9b94b8997
|
493
|
* @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
|
jinu |
0:6ba9b94b8997
|
494
|
* @return @ref BLE_ERROR_NO_TX_BUFFERS There are no available buffers to send the data, applies only to notifications.
|
jinu |
0:6ba9b94b8997
|
495
|
*/
|
jinu |
0:6ba9b94b8997
|
496
|
SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const*const p_hvx_params));
|
jinu |
0:6ba9b94b8997
|
497
|
|
jinu |
0:6ba9b94b8997
|
498
|
/**@brief Indicate the Service Changed attribute value.
|
jinu |
0:6ba9b94b8997
|
499
|
*
|
jinu |
0:6ba9b94b8997
|
500
|
* @details This call will send a Handle Value Indication to one or more peers connected to inform them that the attribute
|
jinu |
0:6ba9b94b8997
|
501
|
* table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will
|
jinu |
0:6ba9b94b8997
|
502
|
* be issued.
|
jinu |
0:6ba9b94b8997
|
503
|
*
|
jinu |
0:6ba9b94b8997
|
504
|
* @note Some of the restrictions and limitations that apply to @ref sd_ble_gatts_hvx also apply here.
|
jinu |
0:6ba9b94b8997
|
505
|
*
|
jinu |
0:6ba9b94b8997
|
506
|
* @param[in] conn_handle Connection handle.
|
jinu |
0:6ba9b94b8997
|
507
|
* @param[in] start_handle Start of affected attribute handle range.
|
jinu |
0:6ba9b94b8997
|
508
|
* @param[in] end_handle End of affected attribute handle range.
|
jinu |
0:6ba9b94b8997
|
509
|
*
|
jinu |
0:6ba9b94b8997
|
510
|
* @return @ref NRF_SUCCESS Successfully queued the Service Changed indication for transmission.
|
jinu |
0:6ba9b94b8997
|
511
|
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
512
|
* @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
|
jinu |
0:6ba9b94b8997
|
513
|
* @return @ref BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application.
|
jinu |
0:6ba9b94b8997
|
514
|
* @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation, notifications or indications must be enabled in the CCCD.
|
jinu |
0:6ba9b94b8997
|
515
|
* @return @ref NRF_ERROR_BUSY Procedure already in progress.
|
jinu |
0:6ba9b94b8997
|
516
|
* @return @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
|
jinu |
0:6ba9b94b8997
|
517
|
*/
|
jinu |
0:6ba9b94b8997
|
518
|
SVCALL(SD_BLE_GATTS_SERVICE_CHANGED, uint32_t, sd_ble_gatts_service_changed(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle));
|
jinu |
0:6ba9b94b8997
|
519
|
|
jinu |
0:6ba9b94b8997
|
520
|
/**@brief Respond to a Read/Write authorization request.
|
jinu |
0:6ba9b94b8997
|
521
|
*
|
jinu |
0:6ba9b94b8997
|
522
|
* @note This call should only be used as a response to a @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event issued to the application.
|
jinu |
0:6ba9b94b8997
|
523
|
*
|
jinu |
0:6ba9b94b8997
|
524
|
* @param[in] conn_handle Connection handle.
|
jinu |
0:6ba9b94b8997
|
525
|
* @param[in] p_rw_authorize_reply_params Pointer to a structure with the attribute provided by the application.
|
jinu |
0:6ba9b94b8997
|
526
|
*
|
jinu |
0:6ba9b94b8997
|
527
|
* @return @ref NRF_SUCCESS Successfully queued a response to the peer, and in the case of a write operation, ATT table updated.
|
jinu |
0:6ba9b94b8997
|
528
|
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
529
|
* @return @ref NRF_ERROR_INVALID_STATE No authorization request pending.
|
jinu |
0:6ba9b94b8997
|
530
|
* @return @ref NRF_ERROR_INVALID_PARAM Authorization op invalid,
|
jinu |
0:6ba9b94b8997
|
531
|
* or for Read Authorization reply: requested handles not replied with,
|
jinu |
0:6ba9b94b8997
|
532
|
* or for Write Authorization reply: handle supplied does not match requested handle.
|
jinu |
0:6ba9b94b8997
|
533
|
*/
|
jinu |
0:6ba9b94b8997
|
534
|
SVCALL(SD_BLE_GATTS_RW_AUTHORIZE_REPLY, uint32_t, sd_ble_gatts_rw_authorize_reply(uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const*const p_rw_authorize_reply_params));
|
jinu |
0:6ba9b94b8997
|
535
|
|
jinu |
0:6ba9b94b8997
|
536
|
|
jinu |
0:6ba9b94b8997
|
537
|
/**@brief Update persistent system attribute information.
|
jinu |
0:6ba9b94b8997
|
538
|
*
|
jinu |
0:6ba9b94b8997
|
539
|
* @details Supply to the stack information about persistent system attributes.
|
jinu |
0:6ba9b94b8997
|
540
|
* This call is legal in the connected state only, and is usually
|
jinu |
0:6ba9b94b8997
|
541
|
* made immediately after a connection is established and the bond identified.
|
jinu |
0:6ba9b94b8997
|
542
|
* usually as a response to a BLE_GATTS_EVT_SYS_ATTR_MISSING.
|
jinu |
0:6ba9b94b8997
|
543
|
*
|
jinu |
0:6ba9b94b8997
|
544
|
* p_sysattrs may point directly to the application's stored copy of the struct.
|
jinu |
0:6ba9b94b8997
|
545
|
* If the pointer is NULL, the system attribute info is initialized, assuming that
|
jinu |
0:6ba9b94b8997
|
546
|
* the application does not have any previously saved data for this bond.
|
jinu |
0:6ba9b94b8997
|
547
|
*
|
jinu |
0:6ba9b94b8997
|
548
|
* @note The state of persistent system attributes is reset upon connection and then remembered for its duration.
|
jinu |
0:6ba9b94b8997
|
549
|
*
|
jinu |
0:6ba9b94b8997
|
550
|
* @note If this call returns with an error code different from @ref NRF_SUCCESS, the storage of persistent system attributes may have been completed only partially.
|
jinu |
0:6ba9b94b8997
|
551
|
* This means that the state of the attribute table is undefined, and the application should either provide a new set of attributes using this same call or
|
jinu |
0:6ba9b94b8997
|
552
|
* reset the SoftDevice to return to a known state.
|
jinu |
0:6ba9b94b8997
|
553
|
*
|
jinu |
0:6ba9b94b8997
|
554
|
* @param[in] conn_handle Connection handle.
|
jinu |
0:6ba9b94b8997
|
555
|
* @param[in] p_sys_attr_data Pointer to a saved copy of system attributes supplied to the stack, or NULL.
|
jinu |
0:6ba9b94b8997
|
556
|
* @param[in] len Size of data pointed by p_sys_attr_data, in octets.
|
jinu |
0:6ba9b94b8997
|
557
|
*
|
jinu |
0:6ba9b94b8997
|
558
|
* @return @ref NRF_SUCCESS Successfully set the system attribute information.
|
jinu |
0:6ba9b94b8997
|
559
|
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
560
|
* @return @ref NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get.
|
jinu |
0:6ba9b94b8997
|
561
|
* @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
|
jinu |
0:6ba9b94b8997
|
562
|
*/
|
jinu |
0:6ba9b94b8997
|
563
|
SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const*const p_sys_attr_data, uint16_t len));
|
jinu |
0:6ba9b94b8997
|
564
|
|
jinu |
0:6ba9b94b8997
|
565
|
|
jinu |
0:6ba9b94b8997
|
566
|
/**@brief Retrieve persistent system attribute information from the stack.
|
jinu |
0:6ba9b94b8997
|
567
|
*
|
jinu |
0:6ba9b94b8997
|
568
|
* @details This call is used to retrieve information about values to be stored perisistently by the application
|
jinu |
0:6ba9b94b8997
|
569
|
* after a connection has been terminated. When a new connection is made to the same bond, the values
|
jinu |
0:6ba9b94b8997
|
570
|
* should be restored using @ref sd_ble_gatts_sys_attr_set.
|
jinu |
0:6ba9b94b8997
|
571
|
* The data should be read before any new advertising is started, or any new connection established. The connection handle for
|
jinu |
0:6ba9b94b8997
|
572
|
* the previous now defunct connection will remain valid until a new one is created to allow this API call to refer to it.
|
jinu |
0:6ba9b94b8997
|
573
|
*
|
jinu |
0:6ba9b94b8997
|
574
|
* @param[in] conn_handle Connection handle of the recently terminated connection.
|
jinu |
0:6ba9b94b8997
|
575
|
* @param[in] p_sys_attr_data Pointer to a buffer where updated information about system attributes will be filled in. NULL can be provided to
|
jinu |
0:6ba9b94b8997
|
576
|
* obtain the length of the data
|
jinu |
0:6ba9b94b8997
|
577
|
* @param[in,out] p_len Size of application buffer if p_sys_attr_data is not NULL. Unconditially updated to actual length of system attribute data.
|
jinu |
0:6ba9b94b8997
|
578
|
*
|
jinu |
0:6ba9b94b8997
|
579
|
* @return @ref NRF_SUCCESS Successfully retrieved the system attribute information.
|
jinu |
0:6ba9b94b8997
|
580
|
* @return @ref BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
|
jinu |
0:6ba9b94b8997
|
581
|
* @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
|
jinu |
0:6ba9b94b8997
|
582
|
* @return @ref NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer.
|
jinu |
0:6ba9b94b8997
|
583
|
*/
|
jinu |
0:6ba9b94b8997
|
584
|
SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t * const p_sys_attr_data, uint16_t* const p_len));
|
jinu |
0:6ba9b94b8997
|
585
|
|
jinu |
0:6ba9b94b8997
|
586
|
/** @} */
|
jinu |
0:6ba9b94b8997
|
587
|
|
jinu |
0:6ba9b94b8997
|
588
|
#endif // BLE_GATTS_H__
|
jinu |
0:6ba9b94b8997
|
589
|
|
jinu |
0:6ba9b94b8997
|
590
|
/**
|
jinu |
0:6ba9b94b8997
|
591
|
@}
|
jinu |
0:6ba9b94b8997
|
592
|
*/
|
jinu |
0:6ba9b94b8997
|
593
|
|