esp_gattc_api.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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_MUTIPLE_EVT = 42, /*!< When the ble characteristic or descriptor mutiple 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] is_direct: direct connection or background auto connection
  255. *
  256. * @return
  257. * - ESP_OK: success
  258. * - other: failed
  259. *
  260. */
  261. esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct);
  262. /**
  263. * @brief Close a virtual connection to a GATT server. gattc maybe have multiple virtual GATT server connections when multiple app_id registed,
  264. * this API only close one virtual GATT server connection. if there exist other virtual GATT server connections,
  265. * it does not disconnect the physical connection.
  266. * if you want to disconnect the physical connection directly, you can use esp_ble_gap_disconnect(esp_bd_addr_t remote_device).
  267. *
  268. * @param[in] gattc_if: Gatt client access interface.
  269. * @param[in] conn_id: connection ID to be closed.
  270. *
  271. * @return
  272. * - ESP_OK: success
  273. * - other: failed
  274. *
  275. */
  276. esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id);
  277. /**
  278. * @brief Configure the MTU size in the GATT channel. This can be done
  279. * only once per connection. Before using, use esp_ble_gatt_set_local_mtu()
  280. * to configure the local MTU size.
  281. *
  282. *
  283. * @param[in] gattc_if: Gatt client access interface.
  284. * @param[in] conn_id: connection ID.
  285. *
  286. * @return
  287. * - ESP_OK: success
  288. * - other: failed
  289. *
  290. */
  291. esp_err_t esp_ble_gattc_send_mtu_req (esp_gatt_if_t gattc_if, uint16_t conn_id);
  292. /**
  293. * @brief This function is called to request a GATT service discovery
  294. * on a GATT server. This function report service search result
  295. * by a callback event, and followed by a service search complete
  296. * event.
  297. *
  298. * @param[in] gattc_if: Gatt client access interface.
  299. * @param[in] conn_id: connection ID.
  300. * @param[in] filter_uuid: a UUID of the service application is interested in.
  301. * If Null, discover for all services.
  302. *
  303. * @return
  304. * - ESP_OK: success
  305. * - other: failed
  306. *
  307. */
  308. esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
  309. /**
  310. * @brief Find all the service with the given service uuid in the gattc cache, if the svc_uuid is NULL, find all the service.
  311. * Note: It just get service from local cache, won't get from remote devices. If want to get it from remote device, need
  312. * to used the esp_ble_gattc_search_service.
  313. *
  314. * @param[in] gattc_if: Gatt client access interface.
  315. * @param[in] conn_id: connection ID which identify the server.
  316. * @param[in] svc_uuid: the pointer to the service uuid.
  317. * @param[out] result: The pointer to the service whith has been found in the gattc cache.
  318. * @param[inout] count: input the number of service want to find,
  319. * it will output the number of service has been found in the gattc cache with the given service uuid.
  320. * @param[in] offset: Offset of the service position to get.
  321. *
  322. * @return
  323. * - ESP_OK: success
  324. * - other: failed
  325. *
  326. */
  327. 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,
  328. esp_gattc_service_elem_t *result, uint16_t *count, uint16_t offset);
  329. /**
  330. * @brief Find all the characteristic with the given service in the gattc cache
  331. * Note: It just get characteristic from local cache, won't get from remote devices.
  332. *
  333. * @param[in] gattc_if: Gatt client access interface.
  334. * @param[in] conn_id: connection ID which identify the server.
  335. * @param[in] start_handle: the attribute start handle.
  336. * @param[in] end_handle: the attribute end handle
  337. * @param[out] result: The pointer to the charateristic in the service.
  338. * @param[inout] count: input the number of characteristic want to find,
  339. * it will output the number of characteristic has been found in the gattc cache with the given service.
  340. * @param[in] offset: Offset of the characteristic position to get.
  341. *
  342. * @return
  343. * - ESP_OK: success
  344. * - other: failed
  345. *
  346. */
  347. esp_gatt_status_t esp_ble_gattc_get_all_char(esp_gatt_if_t gattc_if,
  348. uint16_t conn_id,
  349. uint16_t start_handle,
  350. uint16_t end_handle,
  351. esp_gattc_char_elem_t *result,
  352. uint16_t *count, uint16_t offset);
  353. /**
  354. * @brief Find all the descriptor with the given characteristic in the gattc cache
  355. * Note: It just get descriptor from local cache, won't get from remote devices.
  356. *
  357. * @param[in] gattc_if: Gatt client access interface.
  358. * @param[in] conn_id: connection ID which identify the server.
  359. * @param[in] char_handle: the given characteristic handle
  360. * @param[out] result: The pointer to the descriptor in the characteristic.
  361. * @param[inout] count: input the number of descriptor want to find,
  362. * it will output the number of descriptor has been found in the gattc cache with the given characteristic.
  363. * @param[in] offset: Offset of the descriptor position to get.
  364. *
  365. * @return
  366. * - ESP_OK: success
  367. * - other: failed
  368. *
  369. */
  370. esp_gatt_status_t esp_ble_gattc_get_all_descr(esp_gatt_if_t gattc_if,
  371. uint16_t conn_id,
  372. uint16_t char_handle,
  373. esp_gattc_descr_elem_t *result,
  374. uint16_t *count, uint16_t offset);
  375. /**
  376. * @brief Find the characteristic with the given characteristic uuid in the gattc cache
  377. * Note: It just get characteristic from local cache, won't get from remote devices.
  378. *
  379. * @param[in] gattc_if: Gatt client access interface.
  380. * @param[in] conn_id: connection ID which identify the server.
  381. * @param[in] start_handle: the attribute start handle
  382. * @param[in] end_handle: the attribute end handle
  383. * @param[in] char_uuid: the characteristic uuid
  384. * @param[out] result: The pointer to the characteristic in the service.
  385. * @param[inout] count: input the number of characteristic want to find,
  386. * it will output the number of characteristic has been found in the gattc cache with the given service.
  387. *
  388. * @return
  389. * - ESP_OK: success
  390. * - other: failed
  391. *
  392. */
  393. esp_gatt_status_t esp_ble_gattc_get_char_by_uuid(esp_gatt_if_t gattc_if,
  394. uint16_t conn_id,
  395. uint16_t start_handle,
  396. uint16_t end_handle,
  397. esp_bt_uuid_t char_uuid,
  398. esp_gattc_char_elem_t *result,
  399. uint16_t *count);
  400. /**
  401. * @brief Find the descriptor with the given characteristic uuid in the gattc cache
  402. * Note: It just get descriptor from local cache, won't get from remote devices.
  403. *
  404. * @param[in] gattc_if: Gatt client access interface.
  405. * @param[in] conn_id: connection ID which identify the server.
  406. * @param[in] start_handle: the attribute start handle
  407. * @param[in] end_handle: the attribute end handle
  408. * @param[in] char_uuid: the characteristic uuid.
  409. * @param[in] descr_uuid: the descriptor uuid.
  410. * @param[out] result: The pointer to the descriptor in the given characteristic.
  411. * @param[inout] count: input the number of descriptor want to find,
  412. * it will output the number of descriptor has been found in the gattc cache with the given characteristic.
  413. *
  414. * @return
  415. * - ESP_OK: success
  416. * - other: failed
  417. *
  418. */
  419. esp_gatt_status_t esp_ble_gattc_get_descr_by_uuid(esp_gatt_if_t gattc_if,
  420. uint16_t conn_id,
  421. uint16_t start_handle,
  422. uint16_t end_handle,
  423. esp_bt_uuid_t char_uuid,
  424. esp_bt_uuid_t descr_uuid,
  425. esp_gattc_descr_elem_t *result,
  426. uint16_t *count);
  427. /**
  428. * @brief Find the descriptor with the given characteristic handle in the gattc cache
  429. * Note: It just get descriptor from local cache, won't get from remote devices.
  430. *
  431. * @param[in] gattc_if: Gatt client access interface.
  432. * @param[in] conn_id: connection ID which identify the server.
  433. * @param[in] char_handle: the characteristic handle.
  434. * @param[in] descr_uuid: the descriptor uuid.
  435. * @param[out] result: The pointer to the descriptor in the given characteristic.
  436. * @param[inout] count: input the number of descriptor want to find,
  437. * it will output the number of descriptor has been found in the gattc cache with the given characteristic.
  438. *
  439. * @return
  440. * - ESP_OK: success
  441. * - other: failed
  442. *
  443. */
  444. esp_gatt_status_t esp_ble_gattc_get_descr_by_char_handle(esp_gatt_if_t gattc_if,
  445. uint16_t conn_id,
  446. uint16_t char_handle,
  447. esp_bt_uuid_t descr_uuid,
  448. esp_gattc_descr_elem_t *result,
  449. uint16_t *count);
  450. /**
  451. * @brief Find the include service with the given service handle in the gattc cache
  452. * Note: It just get include service from local cache, won't get from remote devices.
  453. *
  454. * @param[in] gattc_if: Gatt client access interface.
  455. * @param[in] conn_id: connection ID which identify the server.
  456. * @param[in] start_handle: the attribute start handle
  457. * @param[in] end_handle: the attribute end handle
  458. * @param[in] incl_uuid: the include service uuid
  459. * @param[out] result: The pointer to the include service in the given service.
  460. * @param[inout] count: input the number of include service want to find,
  461. * it will output the number of include service has been found in the gattc cache with the given service.
  462. *
  463. * @return
  464. * - ESP_OK: success
  465. * - other: failed
  466. *
  467. */
  468. esp_gatt_status_t esp_ble_gattc_get_include_service(esp_gatt_if_t gattc_if,
  469. uint16_t conn_id,
  470. uint16_t start_handle,
  471. uint16_t end_handle,
  472. esp_bt_uuid_t *incl_uuid,
  473. esp_gattc_incl_svc_elem_t *result,
  474. uint16_t *count);
  475. /**
  476. * @brief Find the attribute count with the given service or characteristic in the gattc cache
  477. *
  478. * @param[in] gattc_if: Gatt client access interface.
  479. * @param[in] conn_id: connection ID which identify the server.
  480. * @param[in] type: the attribute type.
  481. * @param[in] start_handle: the attribute start handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore
  482. * @param[in] end_handle: the attribute end handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore
  483. * @param[in] char_handle: the characteristic handle, this parameter valid when the type is ESP_GATT_DB_DESCRIPTOR. If the type
  484. * isn't ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore.
  485. * @param[out] count: output the number of attribute has been found in the gattc cache with the given attribute type.
  486. *
  487. * @return
  488. * - ESP_OK: success
  489. * - other: failed
  490. *
  491. */
  492. esp_gatt_status_t esp_ble_gattc_get_attr_count(esp_gatt_if_t gattc_if,
  493. uint16_t conn_id,
  494. esp_gatt_db_attr_type_t type,
  495. uint16_t start_handle,
  496. uint16_t end_handle,
  497. uint16_t char_handle,
  498. uint16_t *count);
  499. /**
  500. * @brief This function is called to get the GATT database.
  501. * Note: It just get attribute data base from local cache, won't get from remote devices.
  502. *
  503. * @param[in] gattc_if: Gatt client access interface.
  504. * @param[in] start_handle: the attribute start handle
  505. * @param[in] end_handle: the attribute end handle
  506. * @param[in] conn_id: connection ID which identify the server.
  507. * @param[in] db: output parameter which will contain the GATT database copy.
  508. * Caller is responsible for freeing it.
  509. * @param[in] count: number of elements in database.
  510. *
  511. * @return
  512. * - ESP_OK: success
  513. * - other: failed
  514. *
  515. */
  516. 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,
  517. esp_gattc_db_elem_t *db, uint16_t *count);
  518. /**
  519. * @brief This function is called to read a service's characteristics of
  520. * the given characteristic handle
  521. *
  522. * @param[in] gattc_if: Gatt client access interface.
  523. * @param[in] conn_id : connection ID.
  524. * @param[in] handle : characteritic handle to read.
  525. * @param[in] auth_req : authenticate request type
  526. *
  527. * @return
  528. * - ESP_OK: success
  529. * - other: failed
  530. *
  531. */
  532. esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if,
  533. uint16_t conn_id,
  534. uint16_t handle,
  535. esp_gatt_auth_req_t auth_req);
  536. /**
  537. * @brief This function is called to read multiple characteristic or
  538. * characteristic descriptors.
  539. *
  540. * @param[in] gattc_if: Gatt client access interface.
  541. * @param[in] conn_id : connection ID.
  542. * @param[in] read_multi : pointer to the read multiple parameter.
  543. * @param[in] auth_req : authenticate request type
  544. *
  545. * @return
  546. * - ESP_OK: success
  547. * - other: failed
  548. *
  549. */
  550. esp_err_t esp_ble_gattc_read_multiple(esp_gatt_if_t gattc_if,
  551. uint16_t conn_id, esp_gattc_multi_t *read_multi,
  552. esp_gatt_auth_req_t auth_req);
  553. /**
  554. * @brief This function is called to read a characteristics descriptor.
  555. *
  556. * @param[in] gattc_if: Gatt client access interface.
  557. * @param[in] conn_id : connection ID.
  558. * @param[in] handle : descriptor handle to read.
  559. * @param[in] auth_req : authenticate request type
  560. *
  561. * @return
  562. * - ESP_OK: success
  563. * - other: failed
  564. *
  565. */
  566. esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
  567. uint16_t conn_id,
  568. uint16_t handle,
  569. esp_gatt_auth_req_t auth_req);
  570. /**
  571. * @brief This function is called to write characteristic value.
  572. *
  573. * @param[in] gattc_if: Gatt client access interface.
  574. * @param[in] conn_id : connection ID.
  575. * @param[in] handle : characteristic handle to write.
  576. * @param[in] value_len: length of the value to be written.
  577. * @param[in] value : the value to be written.
  578. * @param[in] write_type : the type of attribute write operation.
  579. * @param[in] auth_req : authentication request.
  580. *
  581. * @return
  582. * - ESP_OK: success
  583. * - other: failed
  584. *
  585. */
  586. esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if,
  587. uint16_t conn_id,
  588. uint16_t handle,
  589. uint16_t value_len,
  590. uint8_t *value,
  591. esp_gatt_write_type_t write_type,
  592. esp_gatt_auth_req_t auth_req);
  593. /**
  594. * @brief This function is called to write characteristic descriptor value.
  595. *
  596. * @param[in] gattc_if: Gatt client access interface.
  597. * @param[in] conn_id : connection ID
  598. * @param[in] handle : descriptor hadle to write.
  599. * @param[in] value_len: length of the value to be written.
  600. * @param[in] value : the value to be written.
  601. * @param[in] write_type : the type of attribute write operation.
  602. * @param[in] auth_req : authentication request.
  603. *
  604. * @return
  605. * - ESP_OK: success
  606. * - other: failed
  607. *
  608. */
  609. esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if,
  610. uint16_t conn_id,
  611. uint16_t handle,
  612. uint16_t value_len,
  613. uint8_t *value,
  614. esp_gatt_write_type_t write_type,
  615. esp_gatt_auth_req_t auth_req);
  616. /**
  617. * @brief This function is called to prepare write a characteristic value.
  618. *
  619. * @param[in] gattc_if: Gatt client access interface.
  620. * @param[in] conn_id : connection ID.
  621. * @param[in] handle : charateristic handle to prepare write.
  622. * @param[in] offset : offset of the write value.
  623. * @param[in] value_len: length of the value to be written.
  624. * @param[in] value : the value to be written.
  625. * @param[in] auth_req : authentication request.
  626. *
  627. * @return
  628. * - ESP_OK: success
  629. * - other: failed
  630. *
  631. */
  632. esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if,
  633. uint16_t conn_id,
  634. uint16_t handle,
  635. uint16_t offset,
  636. uint16_t value_len,
  637. uint8_t *value,
  638. esp_gatt_auth_req_t auth_req);
  639. /**
  640. * @brief This function is called to prepare write a characteristic descriptor value.
  641. *
  642. * @param[in] gattc_if: Gatt client access interface.
  643. * @param[in] conn_id : connection ID.
  644. * @param[in] handle : characteristic descriptor hanlde to prepare write.
  645. * @param[in] offset : offset of the write value.
  646. * @param[in] value_len: length of the value to be written.
  647. * @param[in] value : the value to be written.
  648. * @param[in] auth_req : authentication request.
  649. *
  650. * @return
  651. * - ESP_OK: success
  652. * - other: failed
  653. *
  654. */
  655. esp_err_t esp_ble_gattc_prepare_write_char_descr(esp_gatt_if_t gattc_if,
  656. uint16_t conn_id,
  657. uint16_t handle,
  658. uint16_t offset,
  659. uint16_t value_len,
  660. uint8_t *value,
  661. esp_gatt_auth_req_t auth_req);
  662. /**
  663. * @brief This function is called to execute write a prepare write sequence.
  664. *
  665. * @param[in] gattc_if: Gatt client access interface.
  666. * @param[in] conn_id : connection ID.
  667. * @param[in] is_execute : execute or cancel.
  668. *
  669. * @return
  670. * - ESP_OK: success
  671. * - other: failed
  672. *
  673. */
  674. esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute);
  675. /**
  676. * @brief This function is called to register for notification of a service.
  677. *
  678. * @param[in] gattc_if: Gatt client access interface.
  679. * @param[in] server_bda : target GATT server.
  680. * @param[in] handle : GATT characteristic handle.
  681. *
  682. * @return
  683. * - ESP_OK: registration succeeds
  684. * - other: failed
  685. *
  686. */
  687. esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
  688. esp_bd_addr_t server_bda,
  689. uint16_t handle);
  690. /**
  691. * @brief This function is called to de-register for notification of a service.
  692. *
  693. * @param[in] gattc_if: Gatt client access interface.
  694. * @param[in] server_bda : target GATT server.
  695. * @param[in] handle : GATT characteristic handle.
  696. *
  697. * @return
  698. * - ESP_OK: unregister succeeds
  699. * - other: failed
  700. *
  701. */
  702. esp_err_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
  703. esp_bd_addr_t server_bda,
  704. uint16_t handle);
  705. /**
  706. * @brief Refresh the server cache store in the gattc stack of the remote device
  707. *
  708. * @param[in] remote_bda: remote device BD address.
  709. *
  710. * @return
  711. * - ESP_OK: success
  712. * - other: failed
  713. *
  714. */
  715. esp_err_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda);
  716. #ifdef __cplusplus
  717. }
  718. #endif
  719. #endif /* __ESP_GATTC_API_H__ */