ble_gattc.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * Copyright (c) 2011 - 2017, 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_GATTC Generic Attribute Profile (GATT) Client
  40. @{
  41. @brief Definitions and prototypes for the GATT Client interface.
  42. */
  43. #ifndef BLE_GATTC_H__
  44. #define BLE_GATTC_H__
  45. #include <stdint.h>
  46. #include "nrf.h"
  47. #include "nrf_svc.h"
  48. #include "nrf_error.h"
  49. #include "ble_ranges.h"
  50. #include "ble_types.h"
  51. #include "ble_err.h"
  52. #include "ble_gatt.h"
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /** @addtogroup BLE_GATTC_ENUMERATIONS Enumerations
  57. * @{ */
  58. /**@brief GATTC API SVC numbers. */
  59. enum BLE_GATTC_SVCS
  60. {
  61. SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER = BLE_GATTC_SVC_BASE, /**< Primary Service Discovery. */
  62. SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, /**< Relationship Discovery. */
  63. SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, /**< Characteristic Discovery. */
  64. SD_BLE_GATTC_DESCRIPTORS_DISCOVER, /**< Characteristic Descriptor Discovery. */
  65. SD_BLE_GATTC_ATTR_INFO_DISCOVER, /**< Attribute Information Discovery. */
  66. SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, /**< Read Characteristic Value by UUID. */
  67. SD_BLE_GATTC_READ, /**< Generic read. */
  68. SD_BLE_GATTC_CHAR_VALUES_READ, /**< Read multiple Characteristic Values. */
  69. SD_BLE_GATTC_WRITE, /**< Generic write. */
  70. SD_BLE_GATTC_HV_CONFIRM, /**< Handle Value Confirmation. */
  71. SD_BLE_GATTC_EXCHANGE_MTU_REQUEST, /**< Exchange MTU Request. */
  72. };
  73. /**
  74. * @brief GATT Client Event IDs.
  75. */
  76. enum BLE_GATTC_EVTS
  77. {
  78. BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP = BLE_GATTC_EVT_BASE, /**< Primary Service Discovery Response event. \n See @ref ble_gattc_evt_prim_srvc_disc_rsp_t. */
  79. BLE_GATTC_EVT_REL_DISC_RSP, /**< Relationship Discovery Response event. \n See @ref ble_gattc_evt_rel_disc_rsp_t. */
  80. BLE_GATTC_EVT_CHAR_DISC_RSP, /**< Characteristic Discovery Response event. \n See @ref ble_gattc_evt_char_disc_rsp_t. */
  81. BLE_GATTC_EVT_DESC_DISC_RSP, /**< Descriptor Discovery Response event. \n See @ref ble_gattc_evt_desc_disc_rsp_t. */
  82. BLE_GATTC_EVT_ATTR_INFO_DISC_RSP, /**< Attribute Information Response event. \n See @ref ble_gattc_evt_attr_info_disc_rsp_t. */
  83. BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP, /**< Read By UUID Response event. \n See @ref ble_gattc_evt_char_val_by_uuid_read_rsp_t. */
  84. BLE_GATTC_EVT_READ_RSP, /**< Read Response event. \n See @ref ble_gattc_evt_read_rsp_t. */
  85. BLE_GATTC_EVT_CHAR_VALS_READ_RSP, /**< Read multiple Response event. \n See @ref ble_gattc_evt_char_vals_read_rsp_t. */
  86. BLE_GATTC_EVT_WRITE_RSP, /**< Write Response event. \n See @ref ble_gattc_evt_write_rsp_t. */
  87. BLE_GATTC_EVT_HVX, /**< Handle Value Notification or Indication event. \n Confirm indication with @ref sd_ble_gattc_hv_confirm. \n See @ref ble_gattc_evt_hvx_t. */
  88. BLE_GATTC_EVT_EXCHANGE_MTU_RSP, /**< Exchange MTU Response event. \n See @ref ble_gattc_evt_exchange_mtu_rsp_t. */
  89. BLE_GATTC_EVT_TIMEOUT, /**< Timeout event. \n See @ref ble_gattc_evt_timeout_t. */
  90. BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE /**< Write without Response transmission complete. \n See @ref ble_gattc_evt_write_cmd_tx_complete_t. */
  91. };
  92. /** @} */
  93. /** @addtogroup BLE_GATTC_DEFINES Defines
  94. * @{ */
  95. /** @defgroup BLE_ERRORS_GATTC SVC return values specific to GATTC
  96. * @{ */
  97. #define BLE_ERROR_GATTC_PROC_NOT_PERMITTED (NRF_GATTC_ERR_BASE + 0x000) /**< Procedure not Permitted. */
  98. /** @} */
  99. /** @defgroup BLE_GATTC_ATTR_INFO_FORMAT Attribute Information Formats
  100. * @{ */
  101. #define BLE_GATTC_ATTR_INFO_FORMAT_16BIT 1 /**< 16-bit Attribute Information Format. */
  102. #define BLE_GATTC_ATTR_INFO_FORMAT_128BIT 2 /**< 128-bit Attribute Information Format. */
  103. /** @} */
  104. /** @defgroup BLE_GATTC_DEFAULTS GATT Client defaults
  105. * @{ */
  106. #define BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT 1 /**< Default number of Write without Response that can be queued for transmission. */
  107. /** @} */
  108. /** @} */
  109. /** @addtogroup BLE_GATTC_STRUCTURES Structures
  110. * @{ */
  111. /**
  112. * @brief BLE GATTC connection configuration parameters, set with @ref sd_ble_cfg_set.
  113. */
  114. typedef struct
  115. {
  116. uint8_t write_cmd_tx_queue_size; /**< The guaranteed minimum number of Write without Response that can be queued for transmission.
  117. The default value is @ref BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT */
  118. } ble_gattc_conn_cfg_t;
  119. /**@brief Operation Handle Range. */
  120. typedef struct
  121. {
  122. uint16_t start_handle; /**< Start Handle. */
  123. uint16_t end_handle; /**< End Handle. */
  124. } ble_gattc_handle_range_t;
  125. /**@brief GATT service. */
  126. typedef struct
  127. {
  128. ble_uuid_t uuid; /**< Service UUID. */
  129. ble_gattc_handle_range_t handle_range; /**< Service Handle Range. */
  130. } ble_gattc_service_t;
  131. /**@brief GATT include. */
  132. typedef struct
  133. {
  134. uint16_t handle; /**< Include Handle. */
  135. ble_gattc_service_t included_srvc; /**< Handle of the included service. */
  136. } ble_gattc_include_t;
  137. /**@brief GATT characteristic. */
  138. typedef struct
  139. {
  140. ble_uuid_t uuid; /**< Characteristic UUID. */
  141. ble_gatt_char_props_t char_props; /**< Characteristic Properties. */
  142. uint8_t char_ext_props : 1; /**< Extended properties present. */
  143. uint16_t handle_decl; /**< Handle of the Characteristic Declaration. */
  144. uint16_t handle_value; /**< Handle of the Characteristic Value. */
  145. } ble_gattc_char_t;
  146. /**@brief GATT descriptor. */
  147. typedef struct
  148. {
  149. uint16_t handle; /**< Descriptor Handle. */
  150. ble_uuid_t uuid; /**< Descriptor UUID. */
  151. } ble_gattc_desc_t;
  152. /**@brief Write Parameters. */
  153. typedef struct
  154. {
  155. uint8_t write_op; /**< Write Operation to be performed, see @ref BLE_GATT_WRITE_OPS. */
  156. uint8_t flags; /**< Flags, see @ref BLE_GATT_EXEC_WRITE_FLAGS. */
  157. uint16_t handle; /**< Handle to the attribute to be written. */
  158. uint16_t offset; /**< Offset in bytes. @note For WRITE_CMD and WRITE_REQ, offset must be 0. */
  159. uint16_t len; /**< Length of data in bytes. */
  160. uint8_t const *p_value; /**< Pointer to the value data. */
  161. } ble_gattc_write_params_t;
  162. /**@brief Attribute Information for 16-bit Attribute UUID. */
  163. typedef struct
  164. {
  165. uint16_t handle; /**< Attribute handle. */
  166. ble_uuid_t uuid; /**< 16-bit Attribute UUID. */
  167. } ble_gattc_attr_info16_t;
  168. /**@brief Attribute Information for 128-bit Attribute UUID. */
  169. typedef struct
  170. {
  171. uint16_t handle; /**< Attribute handle. */
  172. ble_uuid128_t uuid; /**< 128-bit Attribute UUID. */
  173. } ble_gattc_attr_info128_t;
  174. /**@brief Event structure for @ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP. */
  175. typedef struct
  176. {
  177. uint16_t count; /**< Service count. */
  178. ble_gattc_service_t services[1]; /**< Service data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  179. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  180. } ble_gattc_evt_prim_srvc_disc_rsp_t;
  181. /**@brief Event structure for @ref BLE_GATTC_EVT_REL_DISC_RSP. */
  182. typedef struct
  183. {
  184. uint16_t count; /**< Include count. */
  185. ble_gattc_include_t includes[1]; /**< Include data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  186. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  187. } ble_gattc_evt_rel_disc_rsp_t;
  188. /**@brief Event structure for @ref BLE_GATTC_EVT_CHAR_DISC_RSP. */
  189. typedef struct
  190. {
  191. uint16_t count; /**< Characteristic count. */
  192. ble_gattc_char_t chars[1]; /**< Characteristic data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  193. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  194. } ble_gattc_evt_char_disc_rsp_t;
  195. /**@brief Event structure for @ref BLE_GATTC_EVT_DESC_DISC_RSP. */
  196. typedef struct
  197. {
  198. uint16_t count; /**< Descriptor count. */
  199. ble_gattc_desc_t descs[1]; /**< Descriptor data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  200. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  201. } ble_gattc_evt_desc_disc_rsp_t;
  202. /**@brief Event structure for @ref BLE_GATTC_EVT_ATTR_INFO_DISC_RSP. */
  203. typedef struct
  204. {
  205. uint16_t count; /**< Attribute count. */
  206. uint8_t format; /**< Attribute information format, see @ref BLE_GATTC_ATTR_INFO_FORMAT. */
  207. union {
  208. ble_gattc_attr_info16_t attr_info16[1]; /**< Attribute information for 16-bit Attribute UUID.
  209. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  210. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  211. ble_gattc_attr_info128_t attr_info128[1]; /**< Attribute information for 128-bit Attribute UUID.
  212. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  213. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  214. } info; /**< Attribute information union. */
  215. } ble_gattc_evt_attr_info_disc_rsp_t;
  216. /**@brief GATT read by UUID handle value pair. */
  217. typedef struct
  218. {
  219. uint16_t handle; /**< Attribute Handle. */
  220. uint8_t *p_value; /**< Pointer to the Attribute Value, length is available in @ref ble_gattc_evt_char_val_by_uuid_read_rsp_t::value_len. */
  221. } ble_gattc_handle_value_t;
  222. /**@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP. */
  223. typedef struct
  224. {
  225. uint16_t count; /**< Handle-Value Pair Count. */
  226. uint16_t value_len; /**< Length of the value in Handle-Value(s) list. */
  227. uint8_t handle_value[1]; /**< Handle-Value(s) list. To iterate through the list use @ref sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter.
  228. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  229. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  230. } ble_gattc_evt_char_val_by_uuid_read_rsp_t;
  231. /**@brief Event structure for @ref BLE_GATTC_EVT_READ_RSP. */
  232. typedef struct
  233. {
  234. uint16_t handle; /**< Attribute Handle. */
  235. uint16_t offset; /**< Offset of the attribute data. */
  236. uint16_t len; /**< Attribute data length. */
  237. uint8_t data[1]; /**< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  238. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  239. } ble_gattc_evt_read_rsp_t;
  240. /**@brief Event structure for @ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP. */
  241. typedef struct
  242. {
  243. uint16_t len; /**< Concatenated Attribute values length. */
  244. uint8_t values[1]; /**< Attribute values. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  245. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  246. } ble_gattc_evt_char_vals_read_rsp_t;
  247. /**@brief Event structure for @ref BLE_GATTC_EVT_WRITE_RSP. */
  248. typedef struct
  249. {
  250. uint16_t handle; /**< Attribute Handle. */
  251. uint8_t write_op; /**< Type of write operation, see @ref BLE_GATT_WRITE_OPS. */
  252. uint16_t offset; /**< Data offset. */
  253. uint16_t len; /**< Data length. */
  254. uint8_t data[1]; /**< Data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  255. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  256. } ble_gattc_evt_write_rsp_t;
  257. /**@brief Event structure for @ref BLE_GATTC_EVT_HVX. */
  258. typedef struct
  259. {
  260. uint16_t handle; /**< Handle to which the HVx operation applies. */
  261. uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
  262. uint16_t len; /**< Attribute data length. */
  263. uint8_t data[1]; /**< Attribute data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
  264. See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
  265. } ble_gattc_evt_hvx_t;
  266. /**@brief Event structure for @ref BLE_GATTC_EVT_EXCHANGE_MTU_RSP. */
  267. typedef struct
  268. {
  269. uint16_t server_rx_mtu; /**< Server RX MTU size. */
  270. } ble_gattc_evt_exchange_mtu_rsp_t;
  271. /**@brief Event structure for @ref BLE_GATTC_EVT_TIMEOUT. */
  272. typedef struct
  273. {
  274. uint8_t src; /**< Timeout source, see @ref BLE_GATT_TIMEOUT_SOURCES. */
  275. } ble_gattc_evt_timeout_t;
  276. /**@brief Event structure for @ref BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE. */
  277. typedef struct
  278. {
  279. uint8_t count; /**< Number of write without response transmissions completed. */
  280. } ble_gattc_evt_write_cmd_tx_complete_t;
  281. /**@brief GATTC event structure. */
  282. typedef struct
  283. {
  284. uint16_t conn_handle; /**< Connection Handle on which event occurred. */
  285. uint16_t gatt_status; /**< GATT status code for the operation, see @ref BLE_GATT_STATUS_CODES. */
  286. uint16_t error_handle; /**< In case of error: The handle causing the error. In all other cases @ref BLE_GATT_HANDLE_INVALID. */
  287. union
  288. {
  289. ble_gattc_evt_prim_srvc_disc_rsp_t prim_srvc_disc_rsp; /**< Primary Service Discovery Response Event Parameters. */
  290. ble_gattc_evt_rel_disc_rsp_t rel_disc_rsp; /**< Relationship Discovery Response Event Parameters. */
  291. ble_gattc_evt_char_disc_rsp_t char_disc_rsp; /**< Characteristic Discovery Response Event Parameters. */
  292. ble_gattc_evt_desc_disc_rsp_t desc_disc_rsp; /**< Descriptor Discovery Response Event Parameters. */
  293. ble_gattc_evt_char_val_by_uuid_read_rsp_t char_val_by_uuid_read_rsp; /**< Characteristic Value Read by UUID Response Event Parameters. */
  294. ble_gattc_evt_read_rsp_t read_rsp; /**< Read Response Event Parameters. */
  295. ble_gattc_evt_char_vals_read_rsp_t char_vals_read_rsp; /**< Characteristic Values Read Response Event Parameters. */
  296. ble_gattc_evt_write_rsp_t write_rsp; /**< Write Response Event Parameters. */
  297. ble_gattc_evt_hvx_t hvx; /**< Handle Value Notification/Indication Event Parameters. */
  298. ble_gattc_evt_exchange_mtu_rsp_t exchange_mtu_rsp; /**< Exchange MTU Response Event Parameters. */
  299. ble_gattc_evt_timeout_t timeout; /**< Timeout Event Parameters. */
  300. ble_gattc_evt_attr_info_disc_rsp_t attr_info_disc_rsp; /**< Attribute Information Discovery Event Parameters. */
  301. ble_gattc_evt_write_cmd_tx_complete_t write_cmd_tx_complete; /**< Write without Response transmission complete Event Parameters. */
  302. } params; /**< Event Parameters. @note Only valid if @ref gatt_status == @ref BLE_GATT_STATUS_SUCCESS. */
  303. } ble_gattc_evt_t;
  304. /** @} */
  305. /** @addtogroup BLE_GATTC_FUNCTIONS Functions
  306. * @{ */
  307. /**@brief Initiate or continue a GATT Primary Service Discovery procedure.
  308. *
  309. * @details This function initiates or resumes a Primary Service discovery procedure, starting from the supplied handle.
  310. * If the last service has not been reached, this function must be called again with an updated start handle value to continue the search.
  311. *
  312. * @note If any of the discovered services have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with
  313. * type @ref BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
  314. *
  315. * @events
  316. * @event{@ref BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP}
  317. * @endevents
  318. *
  319. * @mscs
  320. * @mmsc{@ref BLE_GATTC_PRIM_SRVC_DISC_MSC}
  321. * @endmscs
  322. *
  323. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  324. * @param[in] start_handle Handle to start searching from.
  325. * @param[in] p_srvc_uuid Pointer to the service UUID to be found. If it is NULL, all primary services will be returned.
  326. *
  327. * @retval ::NRF_SUCCESS Successfully started or resumed the Primary Service Discovery procedure.
  328. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  329. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  330. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  331. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  332. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  333. */
  334. SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_services_discover(uint16_t conn_handle, uint16_t start_handle, ble_uuid_t const *p_srvc_uuid));
  335. /**@brief Initiate or continue a GATT Relationship Discovery procedure.
  336. *
  337. * @details This function initiates or resumes the Find Included Services sub-procedure. If the last included service has not been reached,
  338. * this must be called again with an updated handle range to continue the search.
  339. *
  340. * @events
  341. * @event{@ref BLE_GATTC_EVT_REL_DISC_RSP}
  342. * @endevents
  343. *
  344. * @mscs
  345. * @mmsc{@ref BLE_GATTC_REL_DISC_MSC}
  346. * @endmscs
  347. *
  348. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  349. * @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on.
  350. *
  351. * @retval ::NRF_SUCCESS Successfully started or resumed the Relationship Discovery procedure.
  352. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  353. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  354. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  355. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  356. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  357. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  358. */
  359. SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
  360. /**@brief Initiate or continue a GATT Characteristic Discovery procedure.
  361. *
  362. * @details This function initiates or resumes a Characteristic discovery procedure. If the last Characteristic has not been reached,
  363. * this must be called again with an updated handle range to continue the discovery.
  364. *
  365. * @note If any of the discovered characteristics have 128-bit UUIDs which are not present in the table provided to ble_vs_uuids_assign, a UUID structure with
  366. * type @ref BLE_UUID_TYPE_UNKNOWN will be received in the corresponding event.
  367. *
  368. * @events
  369. * @event{@ref BLE_GATTC_EVT_CHAR_DISC_RSP}
  370. * @endevents
  371. *
  372. * @mscs
  373. * @mmsc{@ref BLE_GATTC_CHAR_DISC_MSC}
  374. * @endmscs
  375. *
  376. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  377. * @param[in] p_handle_range A pointer to the range of handles of the Service to perform this procedure on.
  378. *
  379. * @retval ::NRF_SUCCESS Successfully started or resumed the Characteristic Discovery procedure.
  380. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  381. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  382. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  383. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  384. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  385. */
  386. SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
  387. /**@brief Initiate or continue a GATT Characteristic Descriptor Discovery procedure.
  388. *
  389. * @details This function initiates or resumes a Characteristic Descriptor discovery procedure. If the last Descriptor has not been reached,
  390. * this must be called again with an updated handle range to continue the discovery.
  391. *
  392. * @events
  393. * @event{@ref BLE_GATTC_EVT_DESC_DISC_RSP}
  394. * @endevents
  395. *
  396. * @mscs
  397. * @mmsc{@ref BLE_GATTC_DESC_DISC_MSC}
  398. * @endmscs
  399. *
  400. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  401. * @param[in] p_handle_range A pointer to the range of handles of the Characteristic to perform this procedure on.
  402. *
  403. * @retval ::NRF_SUCCESS Successfully started or resumed the Descriptor Discovery procedure.
  404. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  405. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  406. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  407. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  408. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  409. */
  410. SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
  411. /**@brief Initiate or continue a GATT Read using Characteristic UUID procedure.
  412. *
  413. * @details This function initiates or resumes a Read using Characteristic UUID procedure. If the last Characteristic has not been reached,
  414. * this must be called again with an updated handle range to continue the discovery.
  415. *
  416. * @events
  417. * @event{@ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP}
  418. * @endevents
  419. *
  420. * @mscs
  421. * @mmsc{@ref BLE_GATTC_READ_UUID_MSC}
  422. * @endmscs
  423. *
  424. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  425. * @param[in] p_uuid Pointer to a Characteristic value UUID to read.
  426. * @param[in] p_handle_range A pointer to the range of handles to perform this procedure on.
  427. *
  428. * @retval ::NRF_SUCCESS Successfully started or resumed the Read using Characteristic UUID procedure.
  429. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  430. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  431. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  432. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  433. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  434. */
  435. SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const *p_uuid, ble_gattc_handle_range_t const *p_handle_range));
  436. /**@brief Initiate or continue a GATT Read (Long) Characteristic or Descriptor procedure.
  437. *
  438. * @details This function initiates or resumes a GATT Read (Long) Characteristic or Descriptor procedure. If the Characteristic or Descriptor
  439. * to be read is longer than ATT_MTU - 1, this function must be called multiple times with appropriate offset to read the
  440. * complete value.
  441. *
  442. * @events
  443. * @event{@ref BLE_GATTC_EVT_READ_RSP}
  444. * @endevents
  445. *
  446. * @mscs
  447. * @mmsc{@ref BLE_GATTC_VALUE_READ_MSC}
  448. * @endmscs
  449. *
  450. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  451. * @param[in] handle The handle of the attribute to be read.
  452. * @param[in] offset Offset into the attribute value to be read.
  453. *
  454. * @retval ::NRF_SUCCESS Successfully started or resumed the Read (Long) procedure.
  455. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  456. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  457. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  458. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  459. */
  460. SVCALL(SD_BLE_GATTC_READ, uint32_t, sd_ble_gattc_read(uint16_t conn_handle, uint16_t handle, uint16_t offset));
  461. /**@brief Initiate a GATT Read Multiple Characteristic Values procedure.
  462. *
  463. * @details This function initiates a GATT Read Multiple Characteristic Values procedure.
  464. *
  465. * @events
  466. * @event{@ref BLE_GATTC_EVT_CHAR_VALS_READ_RSP}
  467. * @endevents
  468. *
  469. * @mscs
  470. * @mmsc{@ref BLE_GATTC_READ_MULT_MSC}
  471. * @endmscs
  472. *
  473. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  474. * @param[in] p_handles A pointer to the handle(s) of the attribute(s) to be read.
  475. * @param[in] handle_count The number of handles in p_handles.
  476. *
  477. * @retval ::NRF_SUCCESS Successfully started the Read Multiple Characteristic Values procedure.
  478. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  479. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  480. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  481. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  482. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  483. */
  484. SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(uint16_t conn_handle, uint16_t const *p_handles, uint16_t handle_count));
  485. /**@brief Perform a Write (Characteristic Value or Descriptor, with or without response, signed or not, long or reliable) procedure.
  486. *
  487. * @details This function can perform all write procedures described in GATT.
  488. *
  489. * @note Only one write with response procedure can be ongoing per connection at a time.
  490. * If the application tries to write with response while another write with response procedure is ongoing,
  491. * the function call will return @ref NRF_ERROR_BUSY.
  492. * A @ref BLE_GATTC_EVT_WRITE_RSP event will be issued as soon as the write response arrives from the peer.
  493. *
  494. * @note The number of Write without Response that can be queued is configured by @ref ble_gattc_conn_cfg_t::write_cmd_tx_queue_size
  495. * When the queue is full, the function call will return @ref NRF_ERROR_RESOURCES.
  496. * A @ref BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event will be issued as soon as the transmission of the write without response is complete.
  497. *
  498. * @note The application can keep track of the available queue element count for writes without responses by following the procedure below:
  499. * - Store initial queue element count in a variable.
  500. * - Decrement the variable, which stores the currently available queue element count, by one when a call to this function returns @ref NRF_SUCCESS.
  501. * - Increment the variable, which stores the current available queue element count, by the count variable in @ref BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event.
  502. *
  503. * @events
  504. * @event{@ref BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE, Write without response transmission complete.}
  505. * @event{@ref BLE_GATTC_EVT_WRITE_RSP, Write response received from the peer.}
  506. * @endevents
  507. *
  508. * @mscs
  509. * @mmsc{@ref BLE_GATTC_VALUE_WRITE_WITHOUT_RESP_MSC}
  510. * @mmsc{@ref BLE_GATTC_VALUE_WRITE_MSC}
  511. * @mmsc{@ref BLE_GATTC_VALUE_LONG_WRITE_MSC}
  512. * @mmsc{@ref BLE_GATTC_VALUE_RELIABLE_WRITE_MSC}
  513. * @endmscs
  514. *
  515. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  516. * @param[in] p_write_params A pointer to a write parameters structure.
  517. *
  518. * @retval ::NRF_SUCCESS Successfully started the Write procedure.
  519. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  520. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
  521. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  522. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  523. * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied.
  524. * @retval ::NRF_ERROR_BUSY For write with response, procedure already in progress. Wait for a @ref BLE_GATTC_EVT_WRITE_RSP event and retry.
  525. * @retval ::NRF_ERROR_RESOURCES Too many writes without responses queued.
  526. * Wait for a @ref BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event and retry.
  527. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  528. */
  529. SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, ble_gattc_write_params_t const *p_write_params));
  530. /**@brief Send a Handle Value Confirmation to the GATT Server.
  531. *
  532. * @mscs
  533. * @mmsc{@ref BLE_GATTC_HVI_MSC}
  534. * @endmscs
  535. *
  536. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  537. * @param[in] handle The handle of the attribute in the indication.
  538. *
  539. * @retval ::NRF_SUCCESS Successfully queued the Handle Value Confirmation for transmission.
  540. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  541. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or no Indication pending to be confirmed.
  542. * @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle.
  543. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  544. */
  545. SVCALL(SD_BLE_GATTC_HV_CONFIRM, uint32_t, sd_ble_gattc_hv_confirm(uint16_t conn_handle, uint16_t handle));
  546. /**@brief Discovers information about a range of attributes on a GATT server.
  547. *
  548. * @events
  549. * @event{@ref BLE_GATTC_EVT_ATTR_INFO_DISC_RSP, Generated when information about a range of attributes has been received.}
  550. * @endevents
  551. *
  552. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  553. * @param[in] p_handle_range The range of handles to request information about.
  554. *
  555. * @retval ::NRF_SUCCESS Successfully started an attribute information discovery procedure.
  556. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle.
  557. * @retval ::NRF_ERROR_INVALID_STATE Invalid connection state
  558. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  559. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  560. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  561. */
  562. SVCALL(SD_BLE_GATTC_ATTR_INFO_DISCOVER, uint32_t, sd_ble_gattc_attr_info_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * p_handle_range));
  563. /**@brief Start an ATT_MTU exchange by sending an Exchange MTU Request to the server.
  564. *
  565. * @details The SoftDevice sets ATT_MTU to the minimum of:
  566. * - The Client RX MTU value, and
  567. * - The Server RX MTU value from @ref BLE_GATTC_EVT_EXCHANGE_MTU_RSP.
  568. *
  569. * However, the SoftDevice never sets ATT_MTU lower than @ref BLE_GATT_ATT_MTU_DEFAULT.
  570. *
  571. * @events
  572. * @event{@ref BLE_GATTC_EVT_EXCHANGE_MTU_RSP}
  573. * @endevents
  574. *
  575. * @mscs
  576. * @mmsc{@ref BLE_GATTC_MTU_EXCHANGE}
  577. * @endmscs
  578. *
  579. * @param[in] conn_handle The connection handle identifying the connection to perform this procedure on.
  580. * @param[in] client_rx_mtu Client RX MTU size.
  581. * - The minimum value is @ref BLE_GATT_ATT_MTU_DEFAULT.
  582. * - The maximum value is @ref ble_gatt_conn_cfg_t::att_mtu in the connection configuration
  583. used for this connection.
  584. * - The value must be equal to Server RX MTU size given in @ref sd_ble_gatts_exchange_mtu_reply
  585. * if an ATT_MTU exchange has already been performed in the other direction.
  586. *
  587. * @retval ::NRF_SUCCESS Successfully sent request to the server.
  588. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle.
  589. * @retval ::NRF_ERROR_INVALID_STATE Invalid connection state or an ATT_MTU exchange was already requested once.
  590. * @retval ::NRF_ERROR_INVALID_PARAM Invalid Client RX MTU size supplied.
  591. * @retval ::NRF_ERROR_BUSY Client procedure already in progress.
  592. * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
  593. */
  594. SVCALL(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST, uint32_t, sd_ble_gattc_exchange_mtu_request(uint16_t conn_handle, uint16_t client_rx_mtu));
  595. /**@brief Iterate through Handle-Value(s) list in @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP event.
  596. *
  597. * @param[in] p_gattc_evt Pointer to event buffer containing @ref BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP event.
  598. * @note If the buffer contains different event, behavior is undefined.
  599. * @param[in,out] p_iter Iterator, points to @ref ble_gattc_handle_value_t structure that will be filled in with
  600. * the next Handle-Value pair in each iteration. If the function returns other than
  601. * @ref NRF_SUCCESS, it will not be changed.
  602. * - To start iteration, initialize the structure to zero.
  603. * - To continue, pass the value from previous iteration.
  604. *
  605. * \code
  606. * ble_gattc_handle_value_t iter;
  607. * memset(&iter, 0, sizeof(ble_gattc_handle_value_t));
  608. * while (sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(&ble_evt.evt.gattc_evt, &iter) == NRF_SUCCESS)
  609. * {
  610. * app_handle = iter.handle;
  611. * memcpy(app_value, iter.p_value, ble_evt.evt.gattc_evt.params.char_val_by_uuid_read_rsp.value_len);
  612. * }
  613. * \endcode
  614. *
  615. * @retval ::NRF_SUCCESS Successfully retrieved the next Handle-Value pair.
  616. * @retval ::NRF_ERROR_NOT_FOUND No more Handle-Value pairs available in the list.
  617. */
  618. __STATIC_INLINE uint32_t sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(ble_gattc_evt_t *p_gattc_evt, ble_gattc_handle_value_t *p_iter);
  619. /** @} */
  620. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  621. __STATIC_INLINE uint32_t sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(ble_gattc_evt_t *p_gattc_evt, ble_gattc_handle_value_t *p_iter)
  622. {
  623. uint32_t value_len = p_gattc_evt->params.char_val_by_uuid_read_rsp.value_len;
  624. uint8_t *p_first = p_gattc_evt->params.char_val_by_uuid_read_rsp.handle_value;
  625. uint8_t *p_next = p_iter->p_value ? p_iter->p_value + value_len : p_first;
  626. if ((p_next - p_first) / (sizeof(uint16_t) + value_len) < p_gattc_evt->params.char_val_by_uuid_read_rsp.count)
  627. {
  628. p_iter->handle = (uint16_t)p_next[1] << 8 | p_next[0];
  629. p_iter->p_value = p_next + sizeof(uint16_t);
  630. return NRF_SUCCESS;
  631. }
  632. else
  633. {
  634. return NRF_ERROR_NOT_FOUND;
  635. }
  636. }
  637. #endif /* SUPPRESS_INLINE_IMPLEMENTATION */
  638. #ifdef __cplusplus
  639. }
  640. #endif
  641. #endif /* BLE_GATTC_H__ */
  642. /**
  643. @}
  644. */