esp_gattc_api.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_GATTC_API_H__
  14. #define __ESP_GATTC_API_H__
  15. #include "esp_bt_defs.h"
  16. #include "esp_gatt_defs.h"
  17. #include "esp_err.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /// GATT Client callback function events
  22. typedef enum {
  23. ESP_GATTC_REG_EVT = 0, /*!< When GATT client is registered, the event comes */
  24. ESP_GATTC_UNREG_EVT = 1, /*!< When GATT client is unregistered, the event comes */
  25. ESP_GATTC_OPEN_EVT = 2, /*!< When GATT virtual connection is set up, the event comes */
  26. ESP_GATTC_READ_CHAR_EVT = 3, /*!< When GATT characteristic is read, the event comes */
  27. ESP_GATTC_WRITE_CHAR_EVT = 4, /*!< When GATT characteristic write operation completes, the event comes */
  28. ESP_GATTC_CLOSE_EVT = 5, /*!< When GATT virtual connection is closed, the event comes */
  29. ESP_GATTC_SEARCH_CMPL_EVT = 6, /*!< When GATT service discovery is completed, the event comes */
  30. ESP_GATTC_SEARCH_RES_EVT = 7, /*!< When GATT service discovery result is got, the event comes */
  31. ESP_GATTC_READ_DESCR_EVT = 8, /*!< When GATT characteristic descriptor read completes, the event comes */
  32. ESP_GATTC_WRITE_DESCR_EVT = 9, /*!< When GATT characteristic descriptor write completes, the event comes */
  33. ESP_GATTC_NOTIFY_EVT = 10, /*!< When GATT notification or indication arrives, the event comes */
  34. ESP_GATTC_PREP_WRITE_EVT = 11, /*!< When GATT prepare-write operation completes, the event comes */
  35. ESP_GATTC_EXEC_EVT = 12, /*!< When write execution completes, the event comes */
  36. ESP_GATTC_ACL_EVT = 13, /*!< When ACL connection is up, the event comes */
  37. ESP_GATTC_CANCEL_OPEN_EVT = 14, /*!< When GATT client ongoing connection is cancelled, the event comes */
  38. ESP_GATTC_SRVC_CHG_EVT = 15, /*!< When "service changed" occurs, the event comes */
  39. ESP_GATTC_ENC_CMPL_CB_EVT = 17, /*!< When encryption procedure completes, the event comes */
  40. ESP_GATTC_CFG_MTU_EVT = 18, /*!< When configuration of MTU completes, the event comes */
  41. ESP_GATTC_ADV_DATA_EVT = 19, /*!< When advertising of data, the event comes */
  42. ESP_GATTC_MULT_ADV_ENB_EVT = 20, /*!< When multi-advertising is enabled, the event comes */
  43. ESP_GATTC_MULT_ADV_UPD_EVT = 21, /*!< When multi-advertising parameters are updated, the event comes */
  44. ESP_GATTC_MULT_ADV_DATA_EVT = 22, /*!< When multi-advertising data arrives, the event comes */
  45. ESP_GATTC_MULT_ADV_DIS_EVT = 23, /*!< When multi-advertising is disabled, the event comes */
  46. ESP_GATTC_CONGEST_EVT = 24, /*!< When GATT connection congestion comes, the event comes */
  47. ESP_GATTC_BTH_SCAN_ENB_EVT = 25, /*!< When batch scan is enabled, the event comes */
  48. ESP_GATTC_BTH_SCAN_CFG_EVT = 26, /*!< When batch scan storage is configured, the event comes */
  49. ESP_GATTC_BTH_SCAN_RD_EVT = 27, /*!< When Batch scan read event is reported, the event comes */
  50. ESP_GATTC_BTH_SCAN_THR_EVT = 28, /*!< When Batch scan threshold is set, the event comes */
  51. ESP_GATTC_BTH_SCAN_PARAM_EVT = 29, /*!< When Batch scan parameters are set, the event comes */
  52. ESP_GATTC_BTH_SCAN_DIS_EVT = 30, /*!< When Batch scan is disabled, the event comes */
  53. ESP_GATTC_SCAN_FLT_CFG_EVT = 31, /*!< When Scan filter configuration completes, the event comes */
  54. ESP_GATTC_SCAN_FLT_PARAM_EVT = 32, /*!< When Scan filter parameters are set, the event comes */
  55. ESP_GATTC_SCAN_FLT_STATUS_EVT = 33, /*!< When Scan filter status is reported, the event comes */
  56. ESP_GATTC_ADV_VSC_EVT = 34, /*!< When advertising vendor spec content event is reported, the event comes */
  57. ESP_GATTC_REG_FOR_NOTIFY_EVT = 38, /*!< When register for notification of a service completes, the event comes */
  58. ESP_GATTC_UNREG_FOR_NOTIFY_EVT = 39, /*!< When unregister for notification of a service completes, the event comes */
  59. ESP_GATTC_CONNECT_EVT = 40, /*!< When the ble physical connection is set up, the event comes */
  60. ESP_GATTC_DISCONNECT_EVT = 41, /*!< When the ble physical connection disconnected, the event comes */
  61. ESP_GATTC_READ_MULTIPLE_EVT = 42, /*!< When the ble characteristic or descriptor multiple complete, the event comes */
  62. ESP_GATTC_QUEUE_FULL_EVT = 43, /*!< When the gattc command queue full, the event comes */
  63. } esp_gattc_cb_event_t;
  64. /**
  65. * @brief Gatt client callback parameters union
  66. */
  67. typedef union {
  68. /**
  69. * @brief ESP_GATTC_REG_EVT
  70. */
  71. struct gattc_reg_evt_param {
  72. esp_gatt_status_t status; /*!< Operation status */
  73. uint16_t app_id; /*!< Application id which input in register API */
  74. } reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */
  75. /**
  76. * @brief ESP_GATTC_OPEN_EVT
  77. */
  78. struct gattc_open_evt_param {
  79. esp_gatt_status_t status; /*!< Operation status */
  80. uint16_t conn_id; /*!< Connection id */
  81. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  82. uint16_t mtu; /*!< MTU size */
  83. } open; /*!< Gatt client callback param of ESP_GATTC_OPEN_EVT */
  84. /**
  85. * @brief ESP_GATTC_CLOSE_EVT
  86. */
  87. struct gattc_close_evt_param {
  88. esp_gatt_status_t status; /*!< Operation status */
  89. uint16_t conn_id; /*!< Connection id */
  90. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  91. esp_gatt_conn_reason_t reason; /*!< The reason of gatt connection close */
  92. } close; /*!< Gatt client callback param of ESP_GATTC_CLOSE_EVT */
  93. /**
  94. * @brief ESP_GATTC_CFG_MTU_EVT
  95. */
  96. struct gattc_cfg_mtu_evt_param {
  97. esp_gatt_status_t status; /*!< Operation status */
  98. uint16_t conn_id; /*!< Connection id */
  99. uint16_t mtu; /*!< MTU size */
  100. } cfg_mtu; /*!< Gatt client callback param of ESP_GATTC_CFG_MTU_EVT */
  101. /**
  102. * @brief ESP_GATTC_SEARCH_CMPL_EVT
  103. */
  104. struct gattc_search_cmpl_evt_param {
  105. esp_gatt_status_t status; /*!< Operation status */
  106. uint16_t conn_id; /*!< Connection id */
  107. } search_cmpl; /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */
  108. /**
  109. * @brief ESP_GATTC_SEARCH_RES_EVT
  110. */
  111. struct gattc_search_res_evt_param {
  112. uint16_t conn_id; /*!< Connection id */
  113. uint16_t start_handle; /*!< Service start handle */
  114. uint16_t end_handle; /*!< Service end handle */
  115. esp_gatt_id_t srvc_id; /*!< Service id, include service uuid and other information */
  116. } search_res; /*!< Gatt client callback param of ESP_GATTC_SEARCH_RES_EVT */
  117. /**
  118. * @brief ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT
  119. */
  120. struct gattc_read_char_evt_param {
  121. esp_gatt_status_t status; /*!< Operation status */
  122. uint16_t conn_id; /*!< Connection id */
  123. uint16_t handle; /*!< Characteristic handle */
  124. uint8_t *value; /*!< Characteristic value */
  125. uint16_t value_len; /*!< Characteristic value length */
  126. } read; /*!< Gatt client callback param of ESP_GATTC_READ_CHAR_EVT */
  127. /**
  128. * @brief ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT
  129. */
  130. struct gattc_write_evt_param {
  131. esp_gatt_status_t status; /*!< Operation status */
  132. uint16_t conn_id; /*!< Connection id */
  133. uint16_t handle; /*!< The Characteristic or descriptor handle */
  134. uint16_t offset; /*!< The prepare write offset, this value is valid only when prepare write */
  135. } write; /*!< Gatt client callback param of ESP_GATTC_WRITE_DESCR_EVT */
  136. /**
  137. * @brief ESP_GATTC_EXEC_EVT
  138. */
  139. struct gattc_exec_cmpl_evt_param {
  140. esp_gatt_status_t status; /*!< Operation status */
  141. uint16_t conn_id; /*!< Connection id */
  142. } exec_cmpl; /*!< Gatt client callback param of ESP_GATTC_EXEC_EVT */
  143. /**
  144. * @brief ESP_GATTC_NOTIFY_EVT
  145. */
  146. struct gattc_notify_evt_param {
  147. uint16_t conn_id; /*!< Connection id */
  148. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  149. uint16_t handle; /*!< The Characteristic or descriptor handle */
  150. uint16_t value_len; /*!< Notify attribute value */
  151. uint8_t *value; /*!< Notify attribute value */
  152. bool is_notify; /*!< True means notify, false means indicate */
  153. } notify; /*!< Gatt client callback param of ESP_GATTC_NOTIFY_EVT */
  154. /**
  155. * @brief ESP_GATTC_SRVC_CHG_EVT
  156. */
  157. struct gattc_srvc_chg_evt_param {
  158. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  159. } srvc_chg; /*!< Gatt client callback param of ESP_GATTC_SRVC_CHG_EVT */
  160. /**
  161. * @brief ESP_GATTC_CONGEST_EVT
  162. */
  163. struct gattc_congest_evt_param {
  164. uint16_t conn_id; /*!< Connection id */
  165. bool congested; /*!< Congested or not */
  166. } congest; /*!< Gatt client callback param of ESP_GATTC_CONGEST_EVT */
  167. /**
  168. * @brief ESP_GATTC_REG_FOR_NOTIFY_EVT
  169. */
  170. struct gattc_reg_for_notify_evt_param {
  171. esp_gatt_status_t status; /*!< Operation status */
  172. uint16_t handle; /*!< The characteristic or descriptor handle */
  173. } reg_for_notify; /*!< Gatt client callback param of ESP_GATTC_REG_FOR_NOTIFY_EVT */
  174. /**
  175. * @brief ESP_GATTC_UNREG_FOR_NOTIFY_EVT
  176. */
  177. struct gattc_unreg_for_notify_evt_param {
  178. esp_gatt_status_t status; /*!< Operation status */
  179. uint16_t handle; /*!< The characteristic or descriptor handle */
  180. } unreg_for_notify; /*!< Gatt client callback param of ESP_GATTC_UNREG_FOR_NOTIFY_EVT */
  181. /**
  182. * @brief ESP_GATTC_CONNECT_EVT
  183. */
  184. struct gattc_connect_evt_param {
  185. uint16_t conn_id; /*!< Connection id */
  186. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  187. } connect; /*!< Gatt client callback param of ESP_GATTC_CONNECT_EVT */
  188. /**
  189. * @brief ESP_GATTC_DISCONNECT_EVT
  190. */
  191. struct gattc_disconnect_evt_param {
  192. esp_gatt_conn_reason_t reason; /*!< disconnection reason */
  193. uint16_t conn_id; /*!< Connection id */
  194. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  195. } disconnect; /*!< Gatt client callback param of ESP_GATTC_DISCONNECT_EVT */
  196. /**
  197. * @brief ESP_GATTC_QUEUE_FULL_EVT
  198. */
  199. struct gattc_queue_full_evt_param {
  200. esp_gatt_status_t status; /*!< Operation status */
  201. uint16_t conn_id; /*!< Connection id */
  202. bool is_full; /*!< The gattc command queue is full or not */
  203. } queue_full; /*!< Gatt client callback param of ESP_GATTC_QUEUE_FULL_EVT */
  204. } esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */
  205. /**
  206. * @brief GATT Client callback function type
  207. * @param event : Event type
  208. * @param gatts_if : GATT client access interface, normally
  209. * different gattc_if correspond to different profile
  210. * @param param : Point to callback parameter, currently is union type
  211. */
  212. typedef void (* esp_gattc_cb_t)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
  213. /**
  214. * @brief This function is called to register application callbacks
  215. * with GATTC module.
  216. *
  217. * @param[in] callback : pointer to the application callback function.
  218. *
  219. * @return
  220. * - ESP_OK: success
  221. * - other: failed
  222. *
  223. */
  224. esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback);
  225. /**
  226. * @brief This function is called to register application callbacks
  227. * with GATTC module.
  228. *
  229. * @param[in] app_id : Application Identify (UUID), for different application
  230. *
  231. * @return
  232. * - ESP_OK: success
  233. * - other: failed
  234. *
  235. */
  236. esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
  237. /**
  238. * @brief This function is called to unregister an application
  239. * from GATTC module.
  240. *
  241. * @param[in] gattc_if: Gatt client access interface.
  242. *
  243. * @return
  244. * - ESP_OK: success
  245. * - other: failed
  246. *
  247. */
  248. esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
  249. /**
  250. * @brief Open a direct connection or add a background auto connection
  251. *
  252. * @param[in] gattc_if: Gatt client access interface.
  253. * @param[in] remote_bda: remote device bluetooth device address.
  254. * @param[in] remote_addr_type: remote device bluetooth device the address type.
  255. * @param[in] is_direct: direct connection or background auto connection
  256. *
  257. * @return
  258. * - ESP_OK: success
  259. * - other: failed
  260. *
  261. */
  262. esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
  263. /**
  264. * @brief Close a virtual connection to a GATT server. gattc maybe have multiple virtual GATT server connections when multiple app_id registed,
  265. * this API only close one virtual GATT server connection. if there exist other virtual GATT server connections,
  266. * it does not disconnect the physical connection.
  267. * if you want to disconnect the physical connection directly, you can use esp_ble_gap_disconnect(esp_bd_addr_t remote_device).
  268. *
  269. * @param[in] gattc_if: Gatt client access interface.
  270. * @param[in] conn_id: connection ID to be closed.
  271. *
  272. * @return
  273. * - ESP_OK: success
  274. * - other: failed
  275. *
  276. */
  277. esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id);
  278. /**
  279. * @brief Configure the MTU size in the GATT channel. This can be done
  280. * only once per connection. Before using, use esp_ble_gatt_set_local_mtu()
  281. * to configure the local MTU size.
  282. *
  283. *
  284. * @param[in] gattc_if: Gatt client access interface.
  285. * @param[in] conn_id: connection ID.
  286. *
  287. * @return
  288. * - ESP_OK: success
  289. * - other: failed
  290. *
  291. */
  292. esp_err_t esp_ble_gattc_send_mtu_req (esp_gatt_if_t gattc_if, uint16_t conn_id);
  293. /**
  294. * @brief This function is called to request a GATT service discovery
  295. * on a GATT server. This function report service search result
  296. * by a callback event, and followed by a service search complete
  297. * event.
  298. *
  299. * @param[in] gattc_if: Gatt client access interface.
  300. * @param[in] conn_id: connection ID.
  301. * @param[in] filter_uuid: a UUID of the service application is interested in.
  302. * If Null, discover for all services.
  303. *
  304. * @return
  305. * - ESP_OK: success
  306. * - other: failed
  307. *
  308. */
  309. esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
  310. /**
  311. * @brief Find all the service with the given service uuid in the gattc cache, if the svc_uuid is NULL, find all the service.
  312. * Note: It just get service from local cache, won't get from remote devices. If want to get it from remote device, need
  313. * to used the esp_ble_gattc_search_service.
  314. *
  315. * @param[in] gattc_if: Gatt client access interface.
  316. * @param[in] conn_id: connection ID which identify the server.
  317. * @param[in] svc_uuid: the pointer to the service uuid.
  318. * @param[out] result: The pointer to the service whith has been found in the gattc cache.
  319. * @param[inout] count: input the number of service want to find,
  320. * it will output the number of service has been found in the gattc cache with the given service uuid.
  321. * @param[in] offset: Offset of the service position to get.
  322. *
  323. * @return
  324. * - ESP_OK: success
  325. * - other: failed
  326. *
  327. */
  328. esp_gatt_status_t esp_ble_gattc_get_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *svc_uuid,
  329. esp_gattc_service_elem_t *result, uint16_t *count, uint16_t offset);
  330. /**
  331. * @brief Find all the characteristic with the given service in the gattc cache
  332. * Note: It just get characteristic from local cache, won't get from remote devices.
  333. *
  334. * @param[in] gattc_if: Gatt client access interface.
  335. * @param[in] conn_id: connection ID which identify the server.
  336. * @param[in] start_handle: the attribute start handle.
  337. * @param[in] end_handle: the attribute end handle
  338. * @param[out] result: The pointer to the charateristic in the service.
  339. * @param[inout] count: input the number of characteristic want to find,
  340. * it will output the number of characteristic has been found in the gattc cache with the given service.
  341. * @param[in] offset: Offset of the characteristic position to get.
  342. *
  343. * @return
  344. * - ESP_OK: success
  345. * - other: failed
  346. *
  347. */
  348. esp_gatt_status_t esp_ble_gattc_get_all_char(esp_gatt_if_t gattc_if,
  349. uint16_t conn_id,
  350. uint16_t start_handle,
  351. uint16_t end_handle,
  352. esp_gattc_char_elem_t *result,
  353. uint16_t *count, uint16_t offset);
  354. /**
  355. * @brief Find all the descriptor with the given characteristic in the gattc cache
  356. * Note: It just get descriptor from local cache, won't get from remote devices.
  357. *
  358. * @param[in] gattc_if: Gatt client access interface.
  359. * @param[in] conn_id: connection ID which identify the server.
  360. * @param[in] char_handle: the given characteristic handle
  361. * @param[out] result: The pointer to the descriptor in the characteristic.
  362. * @param[inout] count: input the number of descriptor want to find,
  363. * it will output the number of descriptor has been found in the gattc cache with the given characteristic.
  364. * @param[in] offset: Offset of the descriptor position to get.
  365. *
  366. * @return
  367. * - ESP_OK: success
  368. * - other: failed
  369. *
  370. */
  371. esp_gatt_status_t esp_ble_gattc_get_all_descr(esp_gatt_if_t gattc_if,
  372. uint16_t conn_id,
  373. uint16_t char_handle,
  374. esp_gattc_descr_elem_t *result,
  375. uint16_t *count, uint16_t offset);
  376. /**
  377. * @brief Find the characteristic with the given characteristic uuid in the gattc cache
  378. * Note: It just get characteristic from local cache, won't get from remote devices.
  379. *
  380. * @param[in] gattc_if: Gatt client access interface.
  381. * @param[in] conn_id: connection ID which identify the server.
  382. * @param[in] start_handle: the attribute start handle
  383. * @param[in] end_handle: the attribute end handle
  384. * @param[in] char_uuid: the characteristic uuid
  385. * @param[out] result: The pointer to the characteristic in the service.
  386. * @param[inout] count: input the number of characteristic want to find,
  387. * it will output the number of characteristic has been found in the gattc cache with the given service.
  388. *
  389. * @return
  390. * - ESP_OK: success
  391. * - other: failed
  392. *
  393. */
  394. esp_gatt_status_t esp_ble_gattc_get_char_by_uuid(esp_gatt_if_t gattc_if,
  395. uint16_t conn_id,
  396. uint16_t start_handle,
  397. uint16_t end_handle,
  398. esp_bt_uuid_t char_uuid,
  399. esp_gattc_char_elem_t *result,
  400. uint16_t *count);
  401. /**
  402. * @brief Find the descriptor with the given characteristic uuid in the gattc cache
  403. * Note: It just get descriptor from local cache, won't get from remote devices.
  404. *
  405. * @param[in] gattc_if: Gatt client access interface.
  406. * @param[in] conn_id: connection ID which identify the server.
  407. * @param[in] start_handle: the attribute start handle
  408. * @param[in] end_handle: the attribute end handle
  409. * @param[in] char_uuid: the characteristic uuid.
  410. * @param[in] descr_uuid: the descriptor uuid.
  411. * @param[out] result: The pointer to the descriptor in the given characteristic.
  412. * @param[inout] count: input the number of descriptor want to find,
  413. * it will output the number of descriptor has been found in the gattc cache with the given characteristic.
  414. *
  415. * @return
  416. * - ESP_OK: success
  417. * - other: failed
  418. *
  419. */
  420. esp_gatt_status_t esp_ble_gattc_get_descr_by_uuid(esp_gatt_if_t gattc_if,
  421. uint16_t conn_id,
  422. uint16_t start_handle,
  423. uint16_t end_handle,
  424. esp_bt_uuid_t char_uuid,
  425. esp_bt_uuid_t descr_uuid,
  426. esp_gattc_descr_elem_t *result,
  427. uint16_t *count);
  428. /**
  429. * @brief Find the descriptor with the given characteristic handle in the gattc cache
  430. * Note: It just get descriptor from local cache, won't get from remote devices.
  431. *
  432. * @param[in] gattc_if: Gatt client access interface.
  433. * @param[in] conn_id: connection ID which identify the server.
  434. * @param[in] char_handle: the characteristic handle.
  435. * @param[in] descr_uuid: the descriptor uuid.
  436. * @param[out] result: The pointer to the descriptor in the given characteristic.
  437. * @param[inout] count: input the number of descriptor want to find,
  438. * it will output the number of descriptor has been found in the gattc cache with the given characteristic.
  439. *
  440. * @return
  441. * - ESP_OK: success
  442. * - other: failed
  443. *
  444. */
  445. esp_gatt_status_t esp_ble_gattc_get_descr_by_char_handle(esp_gatt_if_t gattc_if,
  446. uint16_t conn_id,
  447. uint16_t char_handle,
  448. esp_bt_uuid_t descr_uuid,
  449. esp_gattc_descr_elem_t *result,
  450. uint16_t *count);
  451. /**
  452. * @brief Find the include service with the given service handle in the gattc cache
  453. * Note: It just get include service from local cache, won't get from remote devices.
  454. *
  455. * @param[in] gattc_if: Gatt client access interface.
  456. * @param[in] conn_id: connection ID which identify the server.
  457. * @param[in] start_handle: the attribute start handle
  458. * @param[in] end_handle: the attribute end handle
  459. * @param[in] incl_uuid: the include service uuid
  460. * @param[out] result: The pointer to the include service in the given service.
  461. * @param[inout] count: input the number of include service want to find,
  462. * it will output the number of include service has been found in the gattc cache with the given service.
  463. *
  464. * @return
  465. * - ESP_OK: success
  466. * - other: failed
  467. *
  468. */
  469. esp_gatt_status_t esp_ble_gattc_get_include_service(esp_gatt_if_t gattc_if,
  470. uint16_t conn_id,
  471. uint16_t start_handle,
  472. uint16_t end_handle,
  473. esp_bt_uuid_t *incl_uuid,
  474. esp_gattc_incl_svc_elem_t *result,
  475. uint16_t *count);
  476. /**
  477. * @brief Find the attribute count with the given service or characteristic in the gattc cache
  478. *
  479. * @param[in] gattc_if: Gatt client access interface.
  480. * @param[in] conn_id: connection ID which identify the server.
  481. * @param[in] type: the attribute type.
  482. * @param[in] start_handle: the attribute start handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore
  483. * @param[in] end_handle: the attribute end handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore
  484. * @param[in] char_handle: the characteristic handle, this parameter valid when the type is ESP_GATT_DB_DESCRIPTOR. If the type
  485. * isn't ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore.
  486. * @param[out] count: output the number of attribute has been found in the gattc cache with the given attribute type.
  487. *
  488. * @return
  489. * - ESP_OK: success
  490. * - other: failed
  491. *
  492. */
  493. esp_gatt_status_t esp_ble_gattc_get_attr_count(esp_gatt_if_t gattc_if,
  494. uint16_t conn_id,
  495. esp_gatt_db_attr_type_t type,
  496. uint16_t start_handle,
  497. uint16_t end_handle,
  498. uint16_t char_handle,
  499. uint16_t *count);
  500. /**
  501. * @brief This function is called to get the GATT database.
  502. * Note: It just get attribute data base from local cache, won't get from remote devices.
  503. *
  504. * @param[in] gattc_if: Gatt client access interface.
  505. * @param[in] start_handle: the attribute start handle
  506. * @param[in] end_handle: the attribute end handle
  507. * @param[in] conn_id: connection ID which identify the server.
  508. * @param[in] db: output parameter which will contain the GATT database copy.
  509. * Caller is responsible for freeing it.
  510. * @param[in] count: number of elements in database.
  511. *
  512. * @return
  513. * - ESP_OK: success
  514. * - other: failed
  515. *
  516. */
  517. esp_gatt_status_t esp_ble_gattc_get_db(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t start_handle, uint16_t end_handle,
  518. esp_gattc_db_elem_t *db, uint16_t *count);
  519. /**
  520. * @brief This function is called to read a service's characteristics of
  521. * the given characteristic handle
  522. *
  523. * @param[in] gattc_if: Gatt client access interface.
  524. * @param[in] conn_id : connection ID.
  525. * @param[in] handle : characteritic handle to read.
  526. * @param[in] auth_req : authenticate request type
  527. *
  528. * @return
  529. * - ESP_OK: success
  530. * - other: failed
  531. *
  532. */
  533. esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if,
  534. uint16_t conn_id,
  535. uint16_t handle,
  536. esp_gatt_auth_req_t auth_req);
  537. /**
  538. * @brief This function is called to read multiple characteristic or
  539. * characteristic descriptors.
  540. *
  541. * @param[in] gattc_if: Gatt client access interface.
  542. * @param[in] conn_id : connection ID.
  543. * @param[in] read_multi : pointer to the read multiple parameter.
  544. * @param[in] auth_req : authenticate request type
  545. *
  546. * @return
  547. * - ESP_OK: success
  548. * - other: failed
  549. *
  550. */
  551. esp_err_t esp_ble_gattc_read_multiple(esp_gatt_if_t gattc_if,
  552. uint16_t conn_id, esp_gattc_multi_t *read_multi,
  553. esp_gatt_auth_req_t auth_req);
  554. /**
  555. * @brief This function is called to read a characteristics descriptor.
  556. *
  557. * @param[in] gattc_if: Gatt client access interface.
  558. * @param[in] conn_id : connection ID.
  559. * @param[in] handle : descriptor handle to read.
  560. * @param[in] auth_req : authenticate request type
  561. *
  562. * @return
  563. * - ESP_OK: success
  564. * - other: failed
  565. *
  566. */
  567. esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
  568. uint16_t conn_id,
  569. uint16_t handle,
  570. esp_gatt_auth_req_t auth_req);
  571. /**
  572. * @brief This function is called to write characteristic value.
  573. *
  574. * @param[in] gattc_if: Gatt client access interface.
  575. * @param[in] conn_id : connection ID.
  576. * @param[in] handle : characteristic handle to write.
  577. * @param[in] value_len: length of the value to be written.
  578. * @param[in] value : the value to be written.
  579. * @param[in] write_type : the type of attribute write operation.
  580. * @param[in] auth_req : authentication request.
  581. *
  582. * @return
  583. * - ESP_OK: success
  584. * - other: failed
  585. *
  586. */
  587. esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if,
  588. uint16_t conn_id,
  589. uint16_t handle,
  590. uint16_t value_len,
  591. uint8_t *value,
  592. esp_gatt_write_type_t write_type,
  593. esp_gatt_auth_req_t auth_req);
  594. /**
  595. * @brief This function is called to write characteristic descriptor value.
  596. *
  597. * @param[in] gattc_if: Gatt client access interface.
  598. * @param[in] conn_id : connection ID
  599. * @param[in] handle : descriptor hadle to write.
  600. * @param[in] value_len: length of the value to be written.
  601. * @param[in] value : the value to be written.
  602. * @param[in] write_type : the type of attribute write operation.
  603. * @param[in] auth_req : authentication request.
  604. *
  605. * @return
  606. * - ESP_OK: success
  607. * - other: failed
  608. *
  609. */
  610. esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if,
  611. uint16_t conn_id,
  612. uint16_t handle,
  613. uint16_t value_len,
  614. uint8_t *value,
  615. esp_gatt_write_type_t write_type,
  616. esp_gatt_auth_req_t auth_req);
  617. /**
  618. * @brief This function is called to prepare write a characteristic value.
  619. *
  620. * @param[in] gattc_if: Gatt client access interface.
  621. * @param[in] conn_id : connection ID.
  622. * @param[in] handle : charateristic handle to prepare write.
  623. * @param[in] offset : offset of the write value.
  624. * @param[in] value_len: length of the value to be written.
  625. * @param[in] value : the value to be written.
  626. * @param[in] auth_req : authentication request.
  627. *
  628. * @return
  629. * - ESP_OK: success
  630. * - other: failed
  631. *
  632. */
  633. esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if,
  634. uint16_t conn_id,
  635. uint16_t handle,
  636. uint16_t offset,
  637. uint16_t value_len,
  638. uint8_t *value,
  639. esp_gatt_auth_req_t auth_req);
  640. /**
  641. * @brief This function is called to prepare write a characteristic descriptor value.
  642. *
  643. * @param[in] gattc_if: Gatt client access interface.
  644. * @param[in] conn_id : connection ID.
  645. * @param[in] handle : characteristic descriptor hanlde to prepare write.
  646. * @param[in] offset : offset of the write value.
  647. * @param[in] value_len: length of the value to be written.
  648. * @param[in] value : the value to be written.
  649. * @param[in] auth_req : authentication request.
  650. *
  651. * @return
  652. * - ESP_OK: success
  653. * - other: failed
  654. *
  655. */
  656. esp_err_t esp_ble_gattc_prepare_write_char_descr(esp_gatt_if_t gattc_if,
  657. uint16_t conn_id,
  658. uint16_t handle,
  659. uint16_t offset,
  660. uint16_t value_len,
  661. uint8_t *value,
  662. esp_gatt_auth_req_t auth_req);
  663. /**
  664. * @brief This function is called to execute write a prepare write sequence.
  665. *
  666. * @param[in] gattc_if: Gatt client access interface.
  667. * @param[in] conn_id : connection ID.
  668. * @param[in] is_execute : execute or cancel.
  669. *
  670. * @return
  671. * - ESP_OK: success
  672. * - other: failed
  673. *
  674. */
  675. esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute);
  676. /**
  677. * @brief This function is called to register for notification of a service.
  678. *
  679. * @param[in] gattc_if: Gatt client access interface.
  680. * @param[in] server_bda : target GATT server.
  681. * @param[in] handle : GATT characteristic handle.
  682. *
  683. * @return
  684. * - ESP_OK: registration succeeds
  685. * - other: failed
  686. *
  687. */
  688. esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
  689. esp_bd_addr_t server_bda,
  690. uint16_t handle);
  691. /**
  692. * @brief This function is called to de-register for notification of a service.
  693. *
  694. * @param[in] gattc_if: Gatt client access interface.
  695. * @param[in] server_bda : target GATT server.
  696. * @param[in] handle : GATT characteristic handle.
  697. *
  698. * @return
  699. * - ESP_OK: unregister succeeds
  700. * - other: failed
  701. *
  702. */
  703. esp_err_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
  704. esp_bd_addr_t server_bda,
  705. uint16_t handle);
  706. /**
  707. * @brief Refresh the server cache store in the gattc stack of the remote device
  708. *
  709. * @param[in] remote_bda: remote device BD address.
  710. *
  711. * @return
  712. * - ESP_OK: success
  713. * - other: failed
  714. *
  715. */
  716. esp_err_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda);
  717. #ifdef __cplusplus
  718. }
  719. #endif
  720. #endif /* __ESP_GATTC_API_H__ */