ble_gatts.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. /*
  2. * Copyright (c) 2011 - 2018, Nordic Semiconductor ASA
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form, except as embedded into a Nordic
  12. * Semiconductor ASA integrated circuit in a product or a software update for
  13. * such product, must reproduce the above copyright notice, this list of
  14. * conditions and the following disclaimer in the documentation and/or other
  15. * materials provided with the distribution.
  16. *
  17. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * 4. This software, with or without modification, must only be used with a
  22. * Nordic Semiconductor ASA integrated circuit.
  23. *
  24. * 5. Any software provided in binary form under this license must not be reverse
  25. * engineered, decompiled, modified and/or disassembled.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  28. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  33. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  36. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. /**
  39. @addtogroup BLE_GATTS Generic Attribute Profile (GATT) Server
  40. @{
  41. @brief Definitions and prototypes for the GATTS interface.
  42. */
  43. #ifndef BLE_GATTS_H__
  44. #define BLE_GATTS_H__
  45. #include <stdint.h>
  46. #include "nrf_svc.h"
  47. #include "nrf_error.h"
  48. #include "ble_hci.h"
  49. #include "ble_ranges.h"
  50. #include "ble_types.h"
  51. #include "ble_err.h"
  52. #include "ble_gatt.h"
  53. #include "ble_gap.h"
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. /** @addtogroup BLE_GATTS_ENUMERATIONS Enumerations
  58. * @{ */
  59. /**
  60. * @brief GATTS API SVC numbers.
  61. */
  62. enum BLE_GATTS_SVCS
  63. {
  64. SD_BLE_GATTS_SERVICE_ADD = BLE_GATTS_SVC_BASE, /**< Add a service. */
  65. SD_BLE_GATTS_INCLUDE_ADD, /**< Add an included service. */
  66. SD_BLE_GATTS_CHARACTERISTIC_ADD, /**< Add a characteristic. */
  67. SD_BLE_GATTS_DESCRIPTOR_ADD, /**< Add a generic attribute. */
  68. SD_BLE_GATTS_VALUE_SET, /**< Set an attribute value. */
  69. SD_BLE_GATTS_VALUE_GET, /**< Get an attribute value. */
  70. SD_BLE_GATTS_HVX, /**< Handle Value Notification or Indication. */
  71. SD_BLE_GATTS_SERVICE_CHANGED, /**< Perform a Service Changed Indication to one or more peers. */
  72. SD_BLE_GATTS_RW_AUTHORIZE_REPLY, /**< Reply to an authorization request for a read or write operation on one or more attributes. */
  73. SD_BLE_GATTS_SYS_ATTR_SET, /**< Set the persistent system attributes for a connection. */
  74. SD_BLE_GATTS_SYS_ATTR_GET, /**< Retrieve the persistent system attributes. */
  75. SD_BLE_GATTS_INITIAL_USER_HANDLE_GET, /**< Retrieve the first valid user handle. */
  76. SD_BLE_GATTS_ATTR_GET, /**< Retrieve the UUID and/or metadata of an attribute. */
  77. SD_BLE_GATTS_EXCHANGE_MTU_REPLY /**< Reply to Exchange MTU Request. */
  78. };
  79. /**
  80. * @brief GATT Server Event IDs.
  81. */
  82. enum BLE_GATTS_EVTS
  83. {
  84. BLE_GATTS_EVT_WRITE = BLE_GATTS_EVT_BASE, /**< Write operation performed. \n See @ref ble_gatts_evt_write_t. */
  85. BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST, /**< Read/Write Authorization request. \n Reply with @ref sd_ble_gatts_rw_authorize_reply. \n See @ref ble_gatts_evt_rw_authorize_request_t. */
  86. BLE_GATTS_EVT_SYS_ATTR_MISSING, /**< A persistent system attribute access is pending. \n Respond with @ref sd_ble_gatts_sys_attr_set. \n See @ref ble_gatts_evt_sys_attr_missing_t. */
  87. BLE_GATTS_EVT_HVC, /**< Handle Value Confirmation. \n See @ref ble_gatts_evt_hvc_t. */
  88. BLE_GATTS_EVT_SC_CONFIRM, /**< Service Changed Confirmation. \n No additional event structure applies. */
  89. BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST, /**< Exchange MTU Request. \n Reply with @ref sd_ble_gatts_exchange_mtu_reply. \n See @ref ble_gatts_evt_exchange_mtu_request_t. */
  90. BLE_GATTS_EVT_TIMEOUT, /**< Peer failed to respond to an ATT request in time. \n See @ref ble_gatts_evt_timeout_t. */
  91. BLE_GATTS_EVT_HVN_TX_COMPLETE /**< Handle Value Notification transmission complete. \n See @ref ble_gatts_evt_hvn_tx_complete_t. */
  92. };
  93. /**@brief GATTS Configuration IDs.
  94. *
  95. * IDs that uniquely identify a GATTS configuration.
  96. */
  97. enum BLE_GATTS_CFGS
  98. {
  99. BLE_GATTS_CFG_SERVICE_CHANGED = BLE_GATTS_CFG_BASE, /**< Service changed configuration. */
  100. BLE_GATTS_CFG_ATTR_TAB_SIZE, /**< Attribute table size configuration. */
  101. };
  102. /** @} */
  103. /** @addtogroup BLE_GATTS_DEFINES Defines
  104. * @{ */
  105. /** @defgroup BLE_ERRORS_GATTS SVC return values specific to GATTS
  106. * @{ */
  107. #define BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000) /**< Invalid attribute type. */
  108. #define BLE_ERROR_GATTS_SYS_ATTR_MISSING (NRF_GATTS_ERR_BASE + 0x001) /**< System Attributes missing. */
  109. /** @} */
  110. /** @defgroup BLE_GATTS_ATTR_LENS_MAX Maximum attribute lengths
  111. * @{ */
  112. #define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */
  113. #define BLE_GATTS_VAR_ATTR_LEN_MAX (512) /**< Maximum length for variable length Attribute Values. */
  114. /** @} */
  115. /** @defgroup BLE_GATTS_SRVC_TYPES GATT Server Service Types
  116. * @{ */
  117. #define BLE_GATTS_SRVC_TYPE_INVALID 0x00 /**< Invalid Service Type. */
  118. #define BLE_GATTS_SRVC_TYPE_PRIMARY 0x01 /**< Primary Service. */
  119. #define BLE_GATTS_SRVC_TYPE_SECONDARY 0x02 /**< Secondary Type. */
  120. /** @} */
  121. /** @defgroup BLE_GATTS_ATTR_TYPES GATT Server Attribute Types
  122. * @{ */
  123. #define BLE_GATTS_ATTR_TYPE_INVALID 0x00 /**< Invalid Attribute Type. */
  124. #define BLE_GATTS_ATTR_TYPE_PRIM_SRVC_DECL 0x01 /**< Primary Service Declaration. */
  125. #define BLE_GATTS_ATTR_TYPE_SEC_SRVC_DECL 0x02 /**< Secondary Service Declaration. */
  126. #define BLE_GATTS_ATTR_TYPE_INC_DECL 0x03 /**< Include Declaration. */
  127. #define BLE_GATTS_ATTR_TYPE_CHAR_DECL 0x04 /**< Characteristic Declaration. */
  128. #define BLE_GATTS_ATTR_TYPE_CHAR_VAL 0x05 /**< Characteristic Value. */
  129. #define BLE_GATTS_ATTR_TYPE_DESC 0x06 /**< Descriptor. */
  130. #define BLE_GATTS_ATTR_TYPE_OTHER 0x07 /**< Other, non-GATT specific type. */
  131. /** @} */
  132. /** @defgroup BLE_GATTS_OPS GATT Server Operations
  133. * @{ */
  134. #define BLE_GATTS_OP_INVALID 0x00 /**< Invalid Operation. */
  135. #define BLE_GATTS_OP_WRITE_REQ 0x01 /**< Write Request. */
  136. #define BLE_GATTS_OP_WRITE_CMD 0x02 /**< Write Command. */
  137. #define BLE_GATTS_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */
  138. #define BLE_GATTS_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */
  139. #define BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL 0x05 /**< Execute Write Request: Cancel all prepared writes. */
  140. #define BLE_GATTS_OP_EXEC_WRITE_REQ_NOW 0x06 /**< Execute Write Request: Immediately execute all prepared writes. */
  141. /** @} */
  142. /** @defgroup BLE_GATTS_VLOCS GATT Value Locations
  143. * @{ */
  144. #define BLE_GATTS_VLOC_INVALID 0x00 /**< Invalid Location. */
  145. #define BLE_GATTS_VLOC_STACK 0x01 /**< Attribute Value is located in stack memory, no user memory is required. */
  146. #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
  147. will read and write directly to the memory using the pointer provided in the APIs. There are no alignment requirements for the buffer. */
  148. /** @} */
  149. /** @defgroup BLE_GATTS_AUTHORIZE_TYPES GATT Server Authorization Types
  150. * @{ */
  151. #define BLE_GATTS_AUTHORIZE_TYPE_INVALID 0x00 /**< Invalid Type. */
  152. #define BLE_GATTS_AUTHORIZE_TYPE_READ 0x01 /**< Authorize a Read Operation. */
  153. #define BLE_GATTS_AUTHORIZE_TYPE_WRITE 0x02 /**< Authorize a Write Request Operation. */
  154. /** @} */
  155. /** @defgroup BLE_GATTS_SYS_ATTR_FLAGS System Attribute Flags
  156. * @{ */
  157. #define BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS (1 << 0) /**< Restrict system attributes to system services only. */
  158. #define BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS (1 << 1) /**< Restrict system attributes to user services only. */
  159. /** @} */
  160. /** @defgroup BLE_GATTS_SERVICE_CHANGED Service Changed Inclusion Values
  161. * @{
  162. */
  163. #define BLE_GATTS_SERVICE_CHANGED_DEFAULT (1) /**< Default is to include the Service Changed characteristic in the Attribute Table. */
  164. /** @} */
  165. /** @defgroup BLE_GATTS_ATTR_TAB_SIZE Attribute Table size
  166. * @{
  167. */
  168. #define BLE_GATTS_ATTR_TAB_SIZE_MIN (248) /**< Minimum Attribute Table size */
  169. #define BLE_GATTS_ATTR_TAB_SIZE_DEFAULT (1408) /**< Default Attribute Table size. */
  170. /** @} */
  171. /** @defgroup BLE_GATTS_DEFAULTS GATT Server defaults
  172. * @{
  173. */
  174. #define BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT 1 /**< Default number of Handle Value Notifications that can be queued for transmission. */
  175. /** @} */
  176. /** @} */
  177. /** @addtogroup BLE_GATTS_STRUCTURES Structures
  178. * @{ */
  179. /**
  180. * @brief BLE GATTS connection configuration parameters, set with @ref sd_ble_cfg_set.
  181. */
  182. typedef struct
  183. {
  184. uint8_t hvn_tx_queue_size; /**< Minimum guaranteed number of Handle Value Notifications that can be queued for transmission.
  185. The default value is @ref BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT */
  186. } ble_gatts_conn_cfg_t;
  187. /**@brief Attribute metadata. */
  188. typedef struct
  189. {
  190. ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */
  191. ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */
  192. uint8_t vlen :1; /**< Variable length attribute. */
  193. uint8_t vloc :2; /**< Value location, see @ref BLE_GATTS_VLOCS.*/
  194. uint8_t rd_auth :1; /**< Read authorization and value will be requested from the application on every read operation. */
  195. uint8_t wr_auth :1; /**< Write authorization will be requested from the application on every Write Request operation (but not Write Command). */
  196. } ble_gatts_attr_md_t;
  197. /**@brief GATT Attribute. */
  198. typedef struct
  199. {
  200. ble_uuid_t const *p_uuid; /**< Pointer to the attribute UUID. */
  201. ble_gatts_attr_md_t const *p_attr_md; /**< Pointer to the attribute metadata structure. */
  202. uint16_t init_len; /**< Initial attribute value length in bytes. */
  203. 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. */
  204. uint16_t max_len; /**< Maximum attribute value length in bytes, see @ref BLE_GATTS_ATTR_LENS_MAX for maximum values. */
  205. 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
  206. 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.
  207. The stack may access that memory directly without the application's knowledge. For writable characteristics, this value must not be a location in flash memory.*/
  208. } ble_gatts_attr_t;
  209. /**@brief GATT Attribute Value. */
  210. typedef struct
  211. {
  212. uint16_t len; /**< Length in bytes to be written or read. Length in bytes written or read after successful return.*/
  213. uint16_t offset; /**< Attribute value offset. */
  214. uint8_t *p_value; /**< Pointer to where value is stored or will be stored.
  215. If value is stored in user memory, only the attribute length is updated when p_value == NULL.
  216. Set to NULL when reading to obtain the complete length of the attribute value */
  217. } ble_gatts_value_t;
  218. /**@brief GATT Characteristic Presentation Format. */
  219. typedef struct
  220. {
  221. uint8_t format; /**< Format of the value, see @ref BLE_GATT_CPF_FORMATS. */
  222. int8_t exponent; /**< Exponent for integer data types. */
  223. uint16_t unit; /**< Unit from Bluetooth Assigned Numbers. */
  224. uint8_t name_space; /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
  225. uint16_t desc; /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
  226. } ble_gatts_char_pf_t;
  227. /**@brief GATT Characteristic metadata. */
  228. typedef struct
  229. {
  230. ble_gatt_char_props_t char_props; /**< Characteristic Properties. */
  231. ble_gatt_char_ext_props_t char_ext_props; /**< Characteristic Extended Properties. */
  232. uint8_t const *p_char_user_desc; /**< Pointer to a UTF-8 encoded string (non-NULL terminated), NULL if the descriptor is not required. */
  233. uint16_t char_user_desc_max_size; /**< The maximum size in bytes of the user description descriptor. */
  234. uint16_t char_user_desc_size; /**< The size of the user description, must be smaller or equal to char_user_desc_max_size. */
  235. ble_gatts_char_pf_t const *p_char_pf; /**< Pointer to a presentation format structure or NULL if the CPF descriptor is not required. */
  236. ble_gatts_attr_md_t const *p_user_desc_md; /**< Attribute metadata for the User Description descriptor, or NULL for default values. */
  237. ble_gatts_attr_md_t const *p_cccd_md; /**< Attribute metadata for the Client Characteristic Configuration Descriptor, or NULL for default values. */
  238. ble_gatts_attr_md_t const *p_sccd_md; /**< Attribute metadata for the Server Characteristic Configuration Descriptor, or NULL for default values. */
  239. } ble_gatts_char_md_t;
  240. /**@brief GATT Characteristic Definition Handles. */
  241. typedef struct
  242. {
  243. uint16_t value_handle; /**< Handle to the characteristic value. */
  244. uint16_t user_desc_handle; /**< Handle to the User Description descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */
  245. uint16_t cccd_handle; /**< Handle to the Client Characteristic Configuration Descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */
  246. uint16_t sccd_handle; /**< Handle to the Server Characteristic Configuration Descriptor, or @ref BLE_GATT_HANDLE_INVALID if not present. */
  247. } ble_gatts_char_handles_t;
  248. /**@brief GATT HVx parameters. */
  249. typedef struct
  250. {
  251. uint16_t handle; /**< Characteristic Value Handle. */
  252. uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
  253. uint16_t offset; /**< Offset within the attribute value. */
  254. uint16_t *p_len; /**< Length in bytes to be written, length in bytes written after return. */
  255. uint8_t const *p_data; /**< Actual data content, use NULL to use the current attribute value. */
  256. } ble_gatts_hvx_params_t;
  257. /**@brief GATT Authorization parameters. */
  258. typedef struct
  259. {
  260. uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
  261. uint8_t update : 1; /**< If set, data supplied in p_data will be used to update the attribute value.
  262. Please note that for @ref BLE_GATTS_AUTHORIZE_TYPE_WRITE operations this bit must always be set,
  263. as the data to be written needs to be stored and later provided by the application. */
  264. uint16_t offset; /**< Offset of the attribute value being updated. */
  265. uint16_t len; /**< Length in bytes of the value in p_data pointer, see @ref BLE_GATTS_ATTR_LENS_MAX. */
  266. uint8_t const *p_data; /**< Pointer to new value used to update the attribute value. */
  267. } ble_gatts_authorize_params_t;
  268. /**@brief GATT Read or Write Authorize Reply parameters. */
  269. typedef struct
  270. {
  271. uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
  272. union {
  273. ble_gatts_authorize_params_t read; /**< Read authorization parameters. */
  274. ble_gatts_authorize_params_t write; /**< Write authorization parameters. */
  275. } params; /**< Reply Parameters. */
  276. } ble_gatts_rw_authorize_reply_params_t;
  277. /**@brief Service Changed Inclusion configuration parameters, set with @ref sd_ble_cfg_set. */
  278. typedef struct
  279. {
  280. uint8_t service_changed : 1; /**< If 1, include the Service Changed characteristic in the Attribute Table. Default is @ref BLE_GATTS_SERVICE_CHANGED_DEFAULT. */
  281. } ble_gatts_cfg_service_changed_t;
  282. /**@brief Attribute table size configuration parameters, set with @ref sd_ble_cfg_set.
  283. *
  284. * @retval ::NRF_ERROR_INVALID_LENGTH One or more of the following is true:
  285. * - The specified Attribute Table size is too small.
  286. * The minimum acceptable size is defined by @ref BLE_GATTS_ATTR_TAB_SIZE_MIN.
  287. * - The specified Attribute Table size is not a multiple of 4.
  288. */
  289. typedef struct
  290. {
  291. uint32_t attr_tab_size; /**< Attribute table size. Default is @ref BLE_GATTS_ATTR_TAB_SIZE_DEFAULT, minimum is @ref BLE_GATTS_ATTR_TAB_SIZE_MIN. */
  292. } ble_gatts_cfg_attr_tab_size_t;
  293. /**@brief Config structure for GATTS configurations. */
  294. typedef union
  295. {
  296. ble_gatts_cfg_service_changed_t service_changed; /**< Include service changed characteristic, cfg_id is @ref BLE_GATTS_CFG_SERVICE_CHANGED. */
  297. ble_gatts_cfg_attr_tab_size_t attr_tab_size; /**< Attribute table size, cfg_id is @ref BLE_GATTS_CFG_ATTR_TAB_SIZE. */
  298. } ble_gatts_cfg_t;
  299. /**@brief Event structure for @ref BLE_GATTS_EVT_WRITE. */
  300. typedef struct
  301. {
  302. uint16_t handle; /**< Attribute Handle. */
  303. ble_uuid_t uuid; /**< Attribute UUID. */
  304. uint8_t op; /**< Type of write operation, see @ref BLE_GATTS_OPS. */
  305. uint8_t auth_required; /**< Writing operation deferred due to authorization requirement. Application may use @ref sd_ble_gatts_value_set to finalize the writing operation. */
  306. uint16_t offset; /**< Offset for the write operation. */
  307. uint16_t len; /**< Length of the received data. */
  308. uint8_t data[1]; /**< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  309. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  310. } ble_gatts_evt_write_t;
  311. /**@brief Event substructure for authorized read requests, see @ref ble_gatts_evt_rw_authorize_request_t. */
  312. typedef struct
  313. {
  314. uint16_t handle; /**< Attribute Handle. */
  315. ble_uuid_t uuid; /**< Attribute UUID. */
  316. uint16_t offset; /**< Offset for the read operation. */
  317. } ble_gatts_evt_read_t;
  318. /**@brief Event structure for @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. */
  319. typedef struct
  320. {
  321. uint8_t type; /**< Type of authorize operation, see @ref BLE_GATTS_AUTHORIZE_TYPES. */
  322. union {
  323. ble_gatts_evt_read_t read; /**< Attribute Read Parameters. */
  324. ble_gatts_evt_write_t write; /**< Attribute Write Parameters. */
  325. } request; /**< Request Parameters. */
  326. } ble_gatts_evt_rw_authorize_request_t;
  327. /**@brief Event structure for @ref BLE_GATTS_EVT_SYS_ATTR_MISSING. */
  328. typedef struct
  329. {
  330. uint8_t hint; /**< Hint (currently unused). */
  331. } ble_gatts_evt_sys_attr_missing_t;
  332. /**@brief Event structure for @ref BLE_GATTS_EVT_HVC. */
  333. typedef struct
  334. {
  335. uint16_t handle; /**< Attribute Handle. */
  336. } ble_gatts_evt_hvc_t;
  337. /**@brief Event structure for @ref BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST. */
  338. typedef struct
  339. {
  340. uint16_t client_rx_mtu; /**< Client RX MTU size. */
  341. } ble_gatts_evt_exchange_mtu_request_t;
  342. /**@brief Event structure for @ref BLE_GATTS_EVT_TIMEOUT. */
  343. typedef struct
  344. {
  345. uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
  346. } ble_gatts_evt_timeout_t;
  347. /**@brief Event structure for @ref BLE_GATTS_EVT_HVN_TX_COMPLETE. */
  348. typedef struct
  349. {
  350. uint8_t count; /**< Number of notification transmissions completed. */
  351. } ble_gatts_evt_hvn_tx_complete_t;
  352. /**@brief GATTS event structure. */
  353. typedef struct
  354. {
  355. uint16_t conn_handle; /**< Connection Handle on which the event occurred. */
  356. union
  357. {
  358. ble_gatts_evt_write_t write; /**< Write Event Parameters. */
  359. ble_gatts_evt_rw_authorize_request_t authorize_request; /**< Read or Write Authorize Request Parameters. */
  360. ble_gatts_evt_sys_attr_missing_t sys_attr_missing; /**< System attributes missing. */
  361. ble_gatts_evt_hvc_t hvc; /**< Handle Value Confirmation Event Parameters. */
  362. ble_gatts_evt_exchange_mtu_request_t exchange_mtu_request; /**< Exchange MTU Request Event Parameters. */
  363. ble_gatts_evt_timeout_t timeout; /**< Timeout Event. */
  364. ble_gatts_evt_hvn_tx_complete_t hvn_tx_complete; /**< Handle Value Notification transmission complete Event Parameters. */
  365. } params; /**< Event Parameters. */
  366. } ble_gatts_evt_t;
  367. /** @} */
  368. /** @addtogroup BLE_GATTS_FUNCTIONS Functions
  369. * @{ */
  370. /**@brief Add a service declaration to the Attribute Table.
  371. *
  372. * @note Secondary Services are only relevant in the context of the entity that references them, it is therefore forbidden to
  373. * add a secondary service declaration that is not referenced by another service later in the Attribute Table.
  374. *
  375. * @mscs
  376. * @mmsc{@ref BLE_GATTS_ATT_TABLE_POP_MSC}
  377. * @endmscs
  378. *
  379. * @param[in] type Toggles between primary and secondary services, see @ref BLE_GATTS_SRVC_TYPES.
  380. * @param[in] p_uuid Pointer to service UUID.
  381. * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
  382. *
  383. * @retval ::NRF_SUCCESS Successfully added a service declaration.
  384. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  385. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, Vendor Specific UUIDs need to be present in the table.
  386. * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
  387. * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  388. */
  389. SVCALL(SD_BLE_GATTS_SERVICE_ADD, uint32_t, sd_ble_gatts_service_add(uint8_t type, ble_uuid_t const *p_uuid, uint16_t *p_handle));
  390. /**@brief Add an include declaration to the Attribute Table.
  391. *
  392. * @note It is currently only possible to add an include declaration to the last added service (i.e. only sequential population is supported at this time).
  393. *
  394. * @note The included service must already be present in the Attribute Table prior to this call.
  395. *
  396. * @mscs
  397. * @mmsc{@ref BLE_GATTS_ATT_TABLE_POP_MSC}
  398. * @endmscs
  399. *
  400. * @param[in] service_handle Handle of the service where the included service is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
  401. * @param[in] inc_srvc_handle Handle of the included service.
  402. * @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored.
  403. *
  404. * @retval ::NRF_SUCCESS Successfully added an include declaration.
  405. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  406. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, handle values need to match previously added services.
  407. * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required.
  408. * @retval ::NRF_ERROR_NOT_SUPPORTED Feature is not supported, service_handle must be that of the last added service.
  409. * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, self inclusions are not allowed.
  410. * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  411. * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
  412. */
  413. SVCALL(SD_BLE_GATTS_INCLUDE_ADD, uint32_t, sd_ble_gatts_include_add(uint16_t service_handle, uint16_t inc_srvc_handle, uint16_t *p_include_handle));
  414. /**@brief Add a characteristic declaration, a characteristic value declaration and optional characteristic descriptor declarations to the Attribute Table.
  415. *
  416. * @note It is currently only possible to add a characteristic to the last added service (i.e. only sequential population is supported at this time).
  417. *
  418. * @note Several restrictions apply to the parameters, such as matching permissions between the user description descriptor and the writable auxiliaries bits,
  419. * readable (no security) and writable (selectable) CCCDs and SCCDs and valid presentation format values.
  420. *
  421. * @note If no metadata is provided for the optional descriptors, their permissions will be derived from the characteristic permissions.
  422. *
  423. * @mscs
  424. * @mmsc{@ref BLE_GATTS_ATT_TABLE_POP_MSC}
  425. * @endmscs
  426. *
  427. * @param[in] service_handle Handle of the service where the characteristic is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
  428. * @param[in] p_char_md Characteristic metadata.
  429. * @param[in] p_attr_char_value Pointer to the attribute structure corresponding to the characteristic value.
  430. * @param[out] p_handles Pointer to the structure where the assigned handles will be stored.
  431. *
  432. * @retval ::NRF_SUCCESS Successfully added a characteristic.
  433. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  434. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
  435. * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, a service context is required.
  436. * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
  437. * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  438. * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
  439. */
  440. SVCALL(SD_BLE_GATTS_CHARACTERISTIC_ADD, uint32_t, sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const *p_char_md, ble_gatts_attr_t const *p_attr_char_value, ble_gatts_char_handles_t *p_handles));
  441. /**@brief Add a descriptor to the Attribute Table.
  442. *
  443. * @note It is currently only possible to add a descriptor to the last added characteristic (i.e. only sequential population is supported at this time).
  444. *
  445. * @mscs
  446. * @mmsc{@ref BLE_GATTS_ATT_TABLE_POP_MSC}
  447. * @endmscs
  448. *
  449. * @param[in] char_handle Handle of the characteristic where the descriptor is to be placed, if @ref BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.
  450. * @param[in] p_attr Pointer to the attribute structure.
  451. * @param[out] p_handle Pointer to a 16-bit word where the assigned handle will be stored.
  452. *
  453. * @retval ::NRF_SUCCESS Successfully added a descriptor.
  454. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  455. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, characteristic handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
  456. * @retval ::NRF_ERROR_INVALID_STATE Invalid state to perform operation, a characteristic context is required.
  457. * @retval ::NRF_ERROR_FORBIDDEN Forbidden value supplied, certain UUIDs are reserved for the stack.
  458. * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  459. * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
  460. */
  461. SVCALL(SD_BLE_GATTS_DESCRIPTOR_ADD, uint32_t, sd_ble_gatts_descriptor_add(uint16_t char_handle, ble_gatts_attr_t const *p_attr, uint16_t *p_handle));
  462. /**@brief Set the value of a given attribute.
  463. *
  464. * @note Values other than system attributes can be set at any time, regardless of whether any active connections exist.
  465. *
  466. * @mscs
  467. * @mmsc{@ref BLE_GATTS_QUEUED_WRITE_QUEUE_FULL_MSC}
  468. * @mmsc{@ref BLE_GATTS_QUEUED_WRITE_NOBUF_NOAUTH_MSC}
  469. * @endmscs
  470. *
  471. * @param[in] conn_handle Connection handle. Ignored if the value does not belong to a system attribute.
  472. * @param[in] handle Attribute handle.
  473. * @param[in,out] p_value Attribute value information.
  474. *
  475. * @retval ::NRF_SUCCESS Successfully set the value of the attribute.
  476. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  477. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  478. * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
  479. * @retval ::NRF_ERROR_FORBIDDEN Forbidden handle supplied, certain attributes are not modifiable by the application.
  480. * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, attribute lengths are restricted by @ref BLE_GATTS_ATTR_LENS_MAX.
  481. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied on a system attribute.
  482. */
  483. SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value));
  484. /**@brief Get the value of a given attribute.
  485. *
  486. * @note If the attribute value is longer than the size of the supplied buffer,
  487. * @ref ble_gatts_value_t::len will return the total attribute value length (excluding offset),
  488. * and not the number of bytes actually returned in @ref ble_gatts_value_t::p_value.
  489. * The application may use this information to allocate a suitable buffer size.
  490. *
  491. * @note When retrieving system attribute values with this function, the connection handle
  492. * may refer to an already disconnected connection. Refer to the documentation of
  493. * @ref sd_ble_gatts_sys_attr_get for further information.
  494. *
  495. * @param[in] conn_handle Connection handle. Ignored if the value does not belong to a system attribute.
  496. * @param[in] handle Attribute handle.
  497. * @param[in,out] p_value Attribute value information.
  498. *
  499. * @retval ::NRF_SUCCESS Successfully retrieved the value of the attribute.
  500. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  501. * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
  502. * @retval ::NRF_ERROR_INVALID_PARAM Invalid attribute offset supplied.
  503. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied on a system attribute.
  504. * @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
  505. */
  506. SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value));
  507. /**@brief Notify or Indicate an attribute value.
  508. *
  509. * @details This function checks for the relevant Client Characteristic Configuration descriptor value to verify that the relevant operation
  510. * (notification or indication) has been enabled by the client. It is also able to update the attribute value before issuing the PDU, so that
  511. * the application can atomically perform a value update and a server initiated transaction with a single API call.
  512. *
  513. * @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.
  514. * The Attribute Table has been updated if one of the following error codes is returned: @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY,
  515. * @ref NRF_ERROR_FORBIDDEN, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and @ref NRF_ERROR_RESOURCES.
  516. * The caller can check whether the value has been updated by looking at the contents of *(@ref ble_gatts_hvx_params_t::p_len).
  517. *
  518. * @note Only one indication procedure can be ongoing per connection at a time.
  519. * If the application tries to indicate an attribute value while another indication procedure is ongoing,
  520. * the function call will return @ref NRF_ERROR_BUSY.
  521. * A @ref BLE_GATTS_EVT_HVC event will be issued as soon as the confirmation arrives from the peer.
  522. *
  523. * @note The number of Handle Value Notifications that can be queued is configured by @ref ble_gatts_conn_cfg_t::hvn_tx_queue_size
  524. * When the queue is full, the function call will return @ref NRF_ERROR_RESOURCES.
  525. * A @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event will be issued as soon as the transmission of the notification is complete.
  526. *
  527. * @note The application can keep track of the available queue element count for notifications by following the procedure below:
  528. * - Store initial queue element count in a variable.
  529. * - Decrement the variable, which stores the currently available queue element count, by one when a call to this function returns @ref NRF_SUCCESS.
  530. * - Increment the variable, which stores the current available queue element count, by the count variable in @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event.
  531. *
  532. * @events
  533. * @event{@ref BLE_GATTS_EVT_HVN_TX_COMPLETE, Notification transmission complete.}
  534. * @event{@ref BLE_GATTS_EVT_HVC, Confirmation received from the peer.}
  535. * @endevents
  536. *
  537. * @mscs
  538. * @mmsc{@ref BLE_GATTS_HVX_SYS_ATTRS_MISSING_MSC}
  539. * @mmsc{@ref BLE_GATTS_HVN_MSC}
  540. * @mmsc{@ref BLE_GATTS_HVI_MSC}
  541. * @mmsc{@ref BLE_GATTS_HVX_DISABLED_MSC}
  542. * @endmscs
  543. *
  544. * @param[in] conn_handle Connection handle.
  545. * @param[in,out] p_hvx_params Pointer to an HVx parameters structure. If @ref ble_gatts_hvx_params_t::p_data
  546. * contains a non-NULL pointer the attribute value will be updated with the contents
  547. * pointed by it before sending the notification or indication. If the attribute value
  548. * is updated, @ref ble_gatts_hvx_params_t::p_len is updated by the SoftDevice to
  549. * contain the number of actual bytes written, else it will be set to 0.
  550. *
  551. * @retval ::NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value.
  552. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  553. * @retval ::NRF_ERROR_INVALID_STATE One or more of the following is true:
  554. * - Invalid Connection State
  555. * - Notifications and/or indications not enabled in the CCCD
  556. * - An ATT_MTU exchange is ongoing
  557. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  558. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  559. * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate.
  560. * @retval ::BLE_ERROR_GATTS_INVALID_ATTR_TYPE Invalid attribute type(s) supplied, only characteristic values may be notified and indicated.
  561. * @retval ::NRF_ERROR_NOT_FOUND Attribute not found.
  562. * @retval ::NRF_ERROR_FORBIDDEN The connection's current security level is lower than the one required by the write permissions of the CCCD associated with this characteristic.
  563. * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
  564. * @retval ::NRF_ERROR_BUSY For @ref BLE_GATT_HVX_INDICATION Procedure already in progress. Wait for a @ref BLE_GATTS_EVT_HVC event and retry.
  565. * @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
  566. * @retval ::NRF_ERROR_RESOURCES Too many notifications queued.
  567. * Wait for a @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event and retry.
  568. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  569. */
  570. SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const *p_hvx_params));
  571. /**@brief Indicate the Service Changed attribute value.
  572. *
  573. * @details This call will send a Handle Value Indication to one or more peers connected to inform them that the Attribute
  574. * Table layout has changed. As soon as the peer has confirmed the indication, a @ref BLE_GATTS_EVT_SC_CONFIRM event will
  575. * be issued.
  576. *
  577. * @note Some of the restrictions and limitations that apply to @ref sd_ble_gatts_hvx also apply here.
  578. *
  579. * @events
  580. * @event{@ref BLE_GATTS_EVT_SC_CONFIRM, Confirmation of attribute table change received from peer.}
  581. * @endevents
  582. *
  583. * @mscs
  584. * @mmsc{@ref BLE_GATTS_SC_MSC}
  585. * @endmscs
  586. *
  587. * @param[in] conn_handle Connection handle.
  588. * @param[in] start_handle Start of affected attribute handle range.
  589. * @param[in] end_handle End of affected attribute handle range.
  590. *
  591. * @retval ::NRF_SUCCESS Successfully queued the Service Changed indication for transmission.
  592. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  593. * @retval ::NRF_ERROR_NOT_SUPPORTED Service Changed not enabled at initialization. See @ref
  594. * sd_ble_cfg_set and @ref ble_gatts_cfg_service_changed_t.
  595. * @retval ::NRF_ERROR_INVALID_STATE One or more of the following is true:
  596. * - Invalid Connection State
  597. * - Notifications and/or indications not enabled in the CCCD
  598. * - An ATT_MTU exchange is ongoing
  599. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  600. * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application.
  601. * @retval ::NRF_ERROR_BUSY Procedure already in progress.
  602. * @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
  603. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  604. */
  605. 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));
  606. /**@brief Respond to a Read/Write authorization request.
  607. *
  608. * @note This call should only be used as a response to a @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event issued to the application.
  609. *
  610. * @mscs
  611. * @mmsc{@ref BLE_GATTS_QUEUED_WRITE_NOBUF_AUTH_MSC}
  612. * @mmsc{@ref BLE_GATTS_QUEUED_WRITE_BUF_AUTH_MSC}
  613. * @mmsc{@ref BLE_GATTS_QUEUED_WRITE_NOBUF_NOAUTH_MSC}
  614. * @mmsc{@ref BLE_GATTS_READ_REQ_AUTH_MSC}
  615. * @mmsc{@ref BLE_GATTS_WRITE_REQ_AUTH_MSC}
  616. * @mmsc{@ref BLE_GATTS_QUEUED_WRITE_QUEUE_FULL_MSC}
  617. * @mmsc{@ref BLE_GATTS_QUEUED_WRITE_PEER_CANCEL_MSC}
  618. * @endmscs
  619. *
  620. * @param[in] conn_handle Connection handle.
  621. * @param[in] p_rw_authorize_reply_params Pointer to a structure with the attribute provided by the application.
  622. *
  623. * @note @ref ble_gatts_authorize_params_t::p_data is ignored when this function is used to respond
  624. * to a @ref BLE_GATTS_AUTHORIZE_TYPE_READ event if @ref ble_gatts_authorize_params_t::update
  625. * is set to 0.
  626. *
  627. * @retval ::NRF_SUCCESS Successfully queued a response to the peer, and in the case of a write operation, Attribute Table updated.
  628. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  629. * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
  630. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  631. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or no authorization request pending.
  632. * @retval ::NRF_ERROR_INVALID_PARAM Authorization op invalid,
  633. * handle supplied does not match requested handle,
  634. * or invalid data to be written provided by the application.
  635. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  636. */
  637. 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 *p_rw_authorize_reply_params));
  638. /**@brief Update persistent system attribute information.
  639. *
  640. * @details Supply information about persistent system attributes to the stack,
  641. * previously obtained using @ref sd_ble_gatts_sys_attr_get.
  642. * This call is only allowed for active connections, and is usually
  643. * made immediately after a connection is established with an known bonded device,
  644. * often as a response to a @ref BLE_GATTS_EVT_SYS_ATTR_MISSING.
  645. *
  646. * p_sysattrs may point directly to the application's stored copy of the system attributes
  647. * obtained using @ref sd_ble_gatts_sys_attr_get.
  648. * If the pointer is NULL, the system attribute info is initialized, assuming that
  649. * the application does not have any previously saved system attribute data for this device.
  650. *
  651. * @note The state of persistent system attributes is reset upon connection establishment and then remembered for its duration.
  652. *
  653. * @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.
  654. * 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
  655. * reset the SoftDevice to return to a known state.
  656. *
  657. * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS is used with this function, only the system attributes included in system services will be modified.
  658. * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS is used with this function, only the system attributes included in user services will be modified.
  659. *
  660. * @mscs
  661. * @mmsc{@ref BLE_GATTS_HVX_SYS_ATTRS_MISSING_MSC}
  662. * @mmsc{@ref BLE_GATTS_SYS_ATTRS_UNK_PEER_MSC}
  663. * @mmsc{@ref BLE_GATTS_SYS_ATTRS_BONDED_PEER_MSC}
  664. * @endmscs
  665. *
  666. * @param[in] conn_handle Connection handle.
  667. * @param[in] p_sys_attr_data Pointer to a saved copy of system attributes supplied to the stack, or NULL.
  668. * @param[in] len Size of data pointed by p_sys_attr_data, in octets.
  669. * @param[in] flags Optional additional flags, see @ref BLE_GATTS_SYS_ATTR_FLAGS
  670. *
  671. * @retval ::NRF_SUCCESS Successfully set the system attribute information.
  672. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  673. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  674. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  675. * @retval ::NRF_ERROR_INVALID_PARAM Invalid flags supplied.
  676. * @retval ::NRF_ERROR_INVALID_DATA Invalid data supplied, the data should be exactly the same as retrieved with @ref sd_ble_gatts_sys_attr_get.
  677. * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
  678. */
  679. SVCALL(SD_BLE_GATTS_SYS_ATTR_SET, uint32_t, sd_ble_gatts_sys_attr_set(uint16_t conn_handle, uint8_t const *p_sys_attr_data, uint16_t len, uint32_t flags));
  680. /**@brief Retrieve persistent system attribute information from the stack.
  681. *
  682. * @details This call is used to retrieve information about values to be stored persistently by the application
  683. * during the lifetime of a connection or after it has been terminated. When a new connection is established with the same bonded device,
  684. * the system attribute information retrieved with this function should be restored using using @ref sd_ble_gatts_sys_attr_set.
  685. * If retrieved after disconnection, the data should be read before a new connection established. The connection handle for
  686. * the previous, now disconnected, connection will remain valid until a new one is created to allow this API call to refer to it.
  687. * Connection handles belonging to active connections can be used as well, but care should be taken since the system attributes
  688. * may be written to at any time by the peer during a connection's lifetime.
  689. *
  690. * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS is used with this function, only the system attributes included in system services will be returned.
  691. * @note When the @ref BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS is used with this function, only the system attributes included in user services will be returned.
  692. *
  693. * @mscs
  694. * @mmsc{@ref BLE_GATTS_SYS_ATTRS_BONDED_PEER_MSC}
  695. * @endmscs
  696. *
  697. * @param[in] conn_handle Connection handle of the recently terminated connection.
  698. * @param[out] p_sys_attr_data Pointer to a buffer where updated information about system attributes will be filled in. The format of the data is described
  699. * in @ref BLE_GATTS_SYS_ATTRS_FORMAT. NULL can be provided to obtain the length of the data.
  700. * @param[in,out] p_len Size of application buffer if p_sys_attr_data is not NULL. Unconditionally updated to actual length of system attribute data.
  701. * @param[in] flags Optional additional flags, see @ref BLE_GATTS_SYS_ATTR_FLAGS
  702. *
  703. * @retval ::NRF_SUCCESS Successfully retrieved the system attribute information.
  704. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  705. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  706. * @retval ::NRF_ERROR_INVALID_PARAM Invalid flags supplied.
  707. * @retval ::NRF_ERROR_DATA_SIZE The system attribute information did not fit into the provided buffer.
  708. * @retval ::NRF_ERROR_NOT_FOUND No system attributes found.
  709. */
  710. SVCALL(SD_BLE_GATTS_SYS_ATTR_GET, uint32_t, sd_ble_gatts_sys_attr_get(uint16_t conn_handle, uint8_t *p_sys_attr_data, uint16_t *p_len, uint32_t flags));
  711. /**@brief Retrieve the first valid user attribute handle.
  712. *
  713. * @param[out] p_handle Pointer to an integer where the handle will be stored.
  714. *
  715. * @retval ::NRF_SUCCESS Successfully retrieved the handle.
  716. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  717. */
  718. SVCALL(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET, uint32_t, sd_ble_gatts_initial_user_handle_get(uint16_t *p_handle));
  719. /**@brief Retrieve the attribute UUID and/or metadata.
  720. *
  721. * @param[in] handle Attribute handle
  722. * @param[out] p_uuid UUID of the attribute. Use NULL to omit this field.
  723. * @param[out] p_md Metadata of the attribute. Use NULL to omit this field.
  724. *
  725. * @retval ::NRF_SUCCESS Successfully retrieved the attribute metadata,
  726. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  727. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameters supplied. Returned when both @c p_uuid and @c p_md are NULL.
  728. * @retval ::NRF_ERROR_NOT_FOUND Attribute was not found.
  729. */
  730. SVCALL(SD_BLE_GATTS_ATTR_GET, uint32_t, sd_ble_gatts_attr_get(uint16_t handle, ble_uuid_t * p_uuid, ble_gatts_attr_md_t * p_md));
  731. /**@brief Reply to an ATT_MTU exchange request by sending an Exchange MTU Response to the client.
  732. *
  733. * @details This function is only used to reply to a @ref BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event.
  734. *
  735. * @details The SoftDevice sets ATT_MTU to the minimum of:
  736. * - The Client RX MTU value from @ref BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST, and
  737. * - The Server RX MTU value.
  738. *
  739. * However, the SoftDevice never sets ATT_MTU lower than @ref BLE_GATT_ATT_MTU_DEFAULT.
  740. *
  741. * @mscs
  742. * @mmsc{@ref BLE_GATTS_MTU_EXCHANGE}
  743. * @endmscs
  744. *
  745. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  746. * @param[in] server_rx_mtu Server RX MTU size.
  747. * - The minimum value is @ref BLE_GATT_ATT_MTU_DEFAULT.
  748. * - The maximum value is @ref ble_gatt_conn_cfg_t::att_mtu in the connection configuration
  749. * used for this connection.
  750. * - The value must be equal to Client RX MTU size given in @ref sd_ble_gattc_exchange_mtu_request
  751. * if an ATT_MTU exchange has already been performed in the other direction.
  752. *
  753. * @retval ::NRF_SUCCESS Successfully sent response to the client.
  754. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  755. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or no ATT_MTU exchange request pending.
  756. * @retval ::NRF_ERROR_INVALID_PARAM Invalid Server RX MTU size supplied.
  757. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  758. */
  759. SVCALL(SD_BLE_GATTS_EXCHANGE_MTU_REPLY, uint32_t, sd_ble_gatts_exchange_mtu_reply(uint16_t conn_handle, uint16_t server_rx_mtu));
  760. /** @} */
  761. #ifdef __cplusplus
  762. }
  763. #endif
  764. #endif // BLE_GATTS_H__
  765. /**
  766. @}
  767. */