esp_gattc_api.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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 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 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_GET_CHAR_EVT = 35, /*!< When characteristic is got from GATT server, the event comes */
  58. ESP_GATTC_GET_DESCR_EVT = 36, /*!< When characteristic descriptor is got from GATT server, the event comes */
  59. ESP_GATTC_GET_INCL_SRVC_EVT = 37, /*!< When included service is got from GATT server, the event comes */
  60. ESP_GATTC_REG_FOR_NOTIFY_EVT = 38, /*!< When register for notification of a service completes, the event comes */
  61. ESP_GATTC_UNREG_FOR_NOTIFY_EVT = 39, /*!< When unregister for notification of a service completes, the event comes */
  62. } esp_gattc_cb_event_t;
  63. /// Maximum Transmission Unit used in GATT
  64. #define ESP_GATT_DEF_BLE_MTU_SIZE 23
  65. /// Maximum Transmission Unit allowed in GATT
  66. #define ESP_GATT_MAX_MTU_SIZE 517
  67. /**
  68. * @brief Gatt client callback parameters union
  69. */
  70. typedef union {
  71. /**
  72. * @brief ESP_GATTC_REG_EVT
  73. */
  74. struct gattc_reg_evt_param {
  75. esp_gatt_status_t status; /*!< Operation status */
  76. uint16_t app_id; /*!< Application id which input in register API */
  77. } reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */
  78. /**
  79. * @brief ESP_GATTC_OPEN_EVT
  80. */
  81. struct gattc_open_evt_param {
  82. esp_gatt_status_t status; /*!< Operation status */
  83. uint16_t conn_id; /*!< Connection id */
  84. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  85. uint16_t mtu; /*!< MTU size */
  86. } open; /*!< Gatt client callback param of ESP_GATTC_OPEN_EVT */
  87. /**
  88. * @brief ESP_GATTC_CLOSE_EVT
  89. */
  90. struct gattc_close_evt_param {
  91. esp_gatt_status_t status; /*!< Operation status */
  92. uint16_t conn_id; /*!< Connection id */
  93. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  94. esp_gatt_conn_reason_t reason; /*!< The reason of gatt connection close */
  95. } close; /*!< Gatt client callback param of ESP_GATTC_CLOSE_EVT */
  96. /**
  97. * @brief ESP_GATTC_CFG_MTU_EVT
  98. */
  99. struct gattc_cfg_mtu_evt_param {
  100. esp_gatt_status_t status; /*!< Operation status */
  101. uint16_t conn_id; /*!< Connection id */
  102. uint16_t mtu; /*!< MTU size */
  103. } cfg_mtu; /*!< Gatt client callback param of ESP_GATTC_CFG_MTU_EVT */
  104. /**
  105. * @brief ESP_GATTC_SEARCH_CMPL_EVT
  106. */
  107. struct gattc_search_cmpl_evt_param {
  108. esp_gatt_status_t status; /*!< Operation status */
  109. uint16_t conn_id; /*!< Connection id */
  110. } search_cmpl; /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */
  111. /**
  112. * @brief ESP_GATTC_SEARCH_RES_EVT
  113. */
  114. struct gattc_search_res_evt_param {
  115. uint16_t conn_id; /*!< Connection id */
  116. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  117. } search_res; /*!< Gatt client callback param of ESP_GATTC_SEARCH_RES_EVT */
  118. /**
  119. * @brief ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT
  120. */
  121. struct gattc_read_char_evt_param {
  122. esp_gatt_status_t status; /*!< Operation status */
  123. uint16_t conn_id; /*!< Connection id */
  124. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  125. esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
  126. esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
  127. uint8_t *value; /*!< Characteristic value */
  128. uint16_t value_type; /*!< Characteristic value type */
  129. uint16_t value_len; /*!< Characteristic value length */
  130. } read; /*!< Gatt client callback param of ESP_GATTC_READ_CHAR_EVT */
  131. /**
  132. * @brief ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT
  133. */
  134. struct gattc_write_evt_param {
  135. esp_gatt_status_t status; /*!< Operation status */
  136. uint16_t conn_id; /*!< Connection id */
  137. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  138. esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
  139. esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
  140. } write; /*!< Gatt client callback param of ESP_GATTC_WRITE_DESCR_EVT */
  141. /**
  142. * @brief ESP_GATTC_EXEC_EVT
  143. */
  144. struct gattc_exec_cmpl_evt_param {
  145. esp_gatt_status_t status; /*!< Operation status */
  146. uint16_t conn_id; /*!< Connection id */
  147. } exec_cmpl; /*!< Gatt client callback param of ESP_GATTC_EXEC_EVT */
  148. /**
  149. * @brief ESP_GATTC_NOTIFY_EVT
  150. */
  151. struct gattc_notify_evt_param {
  152. uint16_t conn_id; /*!< Connection id */
  153. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  154. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  155. esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
  156. esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
  157. uint16_t value_len; /*!< Notify attribute value */
  158. uint8_t *value; /*!< Notify attribute value */
  159. bool is_notify; /*!< True means notify, false means indicate */
  160. } notify; /*!< Gatt client callback param of ESP_GATTC_NOTIFY_EVT */
  161. /**
  162. * @brief ESP_GATTC_SRVC_CHG_EVT
  163. */
  164. struct gattc_srvc_chg_evt_param {
  165. esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
  166. } srvc_chg; /*!< Gatt client callback param of ESP_GATTC_SRVC_CHG_EVT */
  167. /**
  168. * @brief ESP_GATTC_CONGEST_EVT
  169. */
  170. struct gattc_congest_evt_param {
  171. uint16_t conn_id; /*!< Connection id */
  172. bool congested; /*!< Congested or not */
  173. } congest; /*!< Gatt client callback param of ESP_GATTC_CONGEST_EVT */
  174. /**
  175. * @brief ESP_GATTC_GET_CHAR_EVT
  176. */
  177. struct gattc_get_char_evt_param {
  178. esp_gatt_status_t status; /*!< Operation status */
  179. uint16_t conn_id; /*!< Connection id */
  180. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  181. esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
  182. esp_gatt_char_prop_t char_prop; /*!< Characteristic property */
  183. } get_char; /*!< Gatt client callback param of ESP_GATTC_GET_CHAR_EVT */
  184. /**
  185. * @brief ESP_GATTC_GET_DESCR_EVT
  186. */
  187. struct gattc_get_descr_evt_param {
  188. esp_gatt_status_t status; /*!< Operation status */
  189. uint16_t conn_id; /*!< Connection id */
  190. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  191. esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
  192. esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
  193. } get_descr; /*!< Gatt client callback param of ESP_GATTC_GET_DESCR_EVT */
  194. /**
  195. * @brief ESP_GATTC_GET_INCL_SRVC_EVT
  196. */
  197. struct gattc_get_incl_srvc_evt_param {
  198. esp_gatt_status_t status; /*!< Operation status */
  199. uint16_t conn_id; /*!< Connection id */
  200. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  201. esp_gatt_srvc_id_t incl_srvc_id;/*!< Included service id, include service uuid and other information */
  202. } get_incl_srvc; /*!< Gatt client callback param of ESP_GATTC_GET_INCL_SRVC_EVT */
  203. /**
  204. * @brief ESP_GATTC_REG_FOR_NOTIFY_EVT
  205. */
  206. struct gattc_reg_for_notify_evt_param {
  207. esp_gatt_status_t status; /*!< Operation status */
  208. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  209. esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
  210. } reg_for_notify; /*!< Gatt client callback param of ESP_GATTC_REG_FOR_NOTIFY_EVT */
  211. /**
  212. * @brief ESP_GATTC_UNREG_FOR_NOTIFY_EVT
  213. */
  214. struct gattc_unreg_for_notify_evt_param {
  215. esp_gatt_status_t status; /*!< Operation status */
  216. esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
  217. esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
  218. } unreg_for_notify; /*!< Gatt client callback param of ESP_GATTC_UNREG_FOR_NOTIFY_EVT */
  219. } esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */
  220. /**
  221. * @brief GATT Client callback function type
  222. * @param event : Event type
  223. * @param gatts_if : GATT client access interface, normally
  224. * different gattc_if correspond to different profile
  225. * @param param : Point to callback parameter, currently is union type
  226. */
  227. 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);
  228. /**
  229. * @brief This function is called to register application callbacks
  230. * with GATTC module.
  231. *
  232. * @param[in] callback : pointer to the application callback function.
  233. *
  234. * @return
  235. * - ESP_OK: success
  236. * - other: failed
  237. *
  238. */
  239. esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback);
  240. /**
  241. * @brief This function is called to register application callbacks
  242. * with GATTC module.
  243. *
  244. * @param[in] app_id : Application Identify (UUID), for different application
  245. *
  246. * @return
  247. * - ESP_OK: success
  248. * - other: failed
  249. *
  250. */
  251. esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
  252. /**
  253. * @brief This function is called to unregister an application
  254. * from GATTC module.
  255. *
  256. * @param[in] gattc_if: Gatt client access interface.
  257. *
  258. * @return
  259. * - ESP_OK: success
  260. * - other: failed
  261. *
  262. */
  263. esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
  264. /**
  265. * @brief Open a direct connection or add a background auto connection
  266. *
  267. * @param[in] gattc_if: Gatt client access interface.
  268. * @param[in] remote_bda: remote device bluetooth device address.
  269. * @param[in] is_direct: direct connection or background auto connection
  270. *
  271. * @return
  272. * - ESP_OK: success
  273. * - other: failed
  274. *
  275. */
  276. esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct);
  277. /**
  278. * @brief Close a connection to a GATT server.
  279. *
  280. * @param[in] gattc_if: Gatt client access interface.
  281. * @param[in] conn_id: connection ID to be closed.
  282. *
  283. * @return
  284. * - ESP_OK: success
  285. * - other: failed
  286. *
  287. */
  288. esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id);
  289. /**
  290. * @brief Configure the MTU size in the GATT channel. This can be done
  291. * only once per connection.
  292. *
  293. * @param[in] gattc_if: Gatt client access interface.
  294. * @param[in] conn_id: connection ID.
  295. * @param[in] mtu: desired MTU size to use.
  296. *
  297. * @return
  298. * - ESP_OK: success
  299. * - other: failed
  300. *
  301. */
  302. esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu);
  303. /**
  304. * @brief This function is called to request a GATT service discovery
  305. * on a GATT server. This function report service search result
  306. * by a callback event, and followed by a service search complete
  307. * event.
  308. *
  309. * @param[in] gattc_if: Gatt client access interface.
  310. * @param[in] conn_id: connection ID.
  311. * @param[in] filter_uuid: a UUID of the service application is interested in.
  312. * If Null, discover for all services.
  313. *
  314. * @return
  315. * - ESP_OK: success
  316. * - other: failed
  317. *
  318. */
  319. esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
  320. /**
  321. * @brief This function is called to find the first characteristic of the
  322. * service on the given server.
  323. *
  324. * @param[in] gattc_if: Gatt client access interface.
  325. * @param[in] conn_id: connection ID which identify the server.
  326. * @param[in] srvc_id: service ID
  327. * @param[in] start_char_id: the start characteristic ID
  328. * @return
  329. * - ESP_OK: success
  330. * - other: failed
  331. *
  332. */
  333. esp_err_t esp_ble_gattc_get_characteristic(esp_gatt_if_t gattc_if,
  334. uint16_t conn_id,
  335. esp_gatt_srvc_id_t *srvc_id,
  336. esp_gatt_id_t *start_char_id);
  337. /**
  338. * @brief This function is called to find the descriptor of the
  339. * service on the given server.
  340. *
  341. * @param[in] gattc_if: Gatt client access interface.
  342. * @param[in] conn_id: connection ID which identify the server.
  343. * @param[in] srvc_id: the service ID of which the characteristic is belonged to.
  344. * @param[in] char_id: Characteristic ID, if NULL find the first available
  345. * characteristic.
  346. * @param[in] start_descr_id: the start descriptor id
  347. *
  348. * @return
  349. * - ESP_OK: success
  350. * - other: failed
  351. *
  352. */
  353. esp_err_t esp_ble_gattc_get_descriptor(esp_gatt_if_t gattc_if,
  354. uint16_t conn_id,
  355. esp_gatt_srvc_id_t *srvc_id,
  356. esp_gatt_id_t *char_id,
  357. esp_gatt_id_t *start_descr_id);
  358. /**
  359. * @brief This function is called to find the first characteristic of the
  360. * service on the given server.
  361. *
  362. * @param[in] gattc_if: Gatt client access interface.
  363. * @param[in] conn_id: connection ID which identify the server.
  364. * @param[in] srvc_id: the service ID of which the characteristic is belonged to.
  365. * @param[in] start_incl_srvc_id: the start include service id
  366. *
  367. * @return
  368. * - ESP_OK: success
  369. * - other: failed
  370. *
  371. */
  372. esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if,
  373. uint16_t conn_id,
  374. esp_gatt_srvc_id_t *srvc_id,
  375. esp_gatt_srvc_id_t *start_incl_srvc_id);
  376. /**
  377. * @brief This function is called to read a service's characteristics of
  378. * the given characteristic ID
  379. *
  380. * @param[in] gattc_if: Gatt client access interface.
  381. * @param[in] conn_id : connection ID.
  382. * @param[in] srvc_id : service ID.
  383. * @param[in] char_id : characteristic ID to read.
  384. * @param[in] auth_req : authenticate request type
  385. *
  386. * @return
  387. * - ESP_OK: success
  388. * - other: failed
  389. *
  390. */
  391. esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if,
  392. uint16_t conn_id,
  393. esp_gatt_srvc_id_t *srvc_id,
  394. esp_gatt_id_t *char_id,
  395. esp_gatt_auth_req_t auth_req);
  396. /**
  397. * @brief This function is called to read a characteristics descriptor.
  398. *
  399. * @param[in] gattc_if: Gatt client access interface.
  400. * @param[in] conn_id : connection ID.
  401. * @param[in] srvc_id : service ID.
  402. * @param[in] char_id : characteristic ID to read.
  403. * @param[in] descr_id : characteristic descriptor ID to read.
  404. * @param[in] auth_req : authenticate request type
  405. *
  406. * @return
  407. * - ESP_OK: success
  408. * - other: failed
  409. *
  410. */
  411. esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
  412. uint16_t conn_id,
  413. esp_gatt_srvc_id_t *srvc_id,
  414. esp_gatt_id_t *char_id,
  415. esp_gatt_id_t *descr_id,
  416. esp_gatt_auth_req_t auth_req);
  417. /**
  418. * @brief This function is called to write characteristic value.
  419. *
  420. * @param[in] gattc_if: Gatt client access interface.
  421. * @param[in] conn_id : connection ID.
  422. * @param[in] srvc_id : service ID.
  423. * @param[in] char_id : characteristic ID to write.
  424. * @param[in] value_len: length of the value to be written.
  425. * @param[in] value : the value to be written.
  426. * @param[in] write_type : the type of attribute write operation.
  427. * @param[in] auth_req : authentication request.
  428. *
  429. * @return
  430. * - ESP_OK: success
  431. * - other: failed
  432. *
  433. */
  434. esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if,
  435. uint16_t conn_id,
  436. esp_gatt_srvc_id_t *srvc_id,
  437. esp_gatt_id_t *char_id,
  438. uint16_t value_len,
  439. uint8_t *value,
  440. esp_gatt_write_type_t write_type,
  441. esp_gatt_auth_req_t auth_req);
  442. /**
  443. * @brief This function is called to write characteristic descriptor value.
  444. *
  445. * @param[in] gattc_if: Gatt client access interface.
  446. * @param[in] conn_id : connection ID
  447. * @param[in] srvc_id : service ID.
  448. * @param[in] char_id : characteristic ID.
  449. * @param[in] descr_id : characteristic descriptor ID to write.
  450. * @param[in] value_len: length of the value to be written.
  451. * @param[in] value : the value to be written.
  452. * @param[in] write_type : the type of attribute write operation.
  453. * @param[in] auth_req : authentication request.
  454. *
  455. * @return
  456. * - ESP_OK: success
  457. * - other: failed
  458. *
  459. */
  460. esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if,
  461. uint16_t conn_id,
  462. esp_gatt_srvc_id_t *srvc_id,
  463. esp_gatt_id_t *char_id,
  464. esp_gatt_id_t *descr_id,
  465. uint16_t value_len,
  466. uint8_t *value,
  467. esp_gatt_write_type_t write_type,
  468. esp_gatt_auth_req_t auth_req);
  469. /**
  470. * @brief This function is called to prepare write a characteristic value.
  471. *
  472. * @param[in] gattc_if: Gatt client access interface.
  473. * @param[in] conn_id : connection ID.
  474. * @param[in] srvc_id : service ID.
  475. * @param[in] char_id : GATT characteristic ID of the service.
  476. * @param[in] offset : offset of the write value.
  477. * @param[in] value_len: length of the value to be written.
  478. * @param[in] value : the value to be written.
  479. * @param[in] auth_req : authentication request.
  480. *
  481. * @return
  482. * - ESP_OK: success
  483. * - other: failed
  484. *
  485. */
  486. esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if,
  487. uint16_t conn_id,
  488. esp_gatt_srvc_id_t *srvc_id,
  489. esp_gatt_id_t *char_id,
  490. uint16_t offset,
  491. uint16_t value_len,
  492. uint8_t *value,
  493. esp_gatt_auth_req_t auth_req);
  494. /**
  495. * @brief This function is called to execute write a prepare write sequence.
  496. *
  497. * @param[in] gattc_if: Gatt client access interface.
  498. * @param[in] conn_id : connection ID.
  499. * @param[in] is_execute : execute or cancel.
  500. *
  501. * @return
  502. * - ESP_OK: success
  503. * - other: failed
  504. *
  505. */
  506. esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute);
  507. /**
  508. * @brief This function is called to register for notification of a service.
  509. *
  510. * @param[in] gattc_if: Gatt client access interface.
  511. * @param[in] server_bda : target GATT server.
  512. * @param[in] srvc_id : pointer to GATT service ID.
  513. * @param[in] char_id : pointer to GATT characteristic ID.
  514. *
  515. * @return
  516. * - ESP_OK: registration succeeds
  517. * - other: failed
  518. *
  519. */
  520. esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
  521. esp_bd_addr_t server_bda,
  522. esp_gatt_srvc_id_t *srvc_id,
  523. esp_gatt_id_t *char_id);
  524. /**
  525. * @brief This function is called to de-register for notification of a service.
  526. *
  527. * @param[in] gattc_if: Gatt client access interface.
  528. * @param[in] server_bda : target GATT server.
  529. * @param[in] srvc_id : pointer to GATT service ID.
  530. * @param[in] char_id : pointer to GATT characteristic ID.
  531. *
  532. * @return
  533. * - ESP_OK: unregister succeeds
  534. * - other: failed
  535. *
  536. */
  537. esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
  538. esp_bd_addr_t server_bda,
  539. esp_gatt_srvc_id_t *srvc_id,
  540. esp_gatt_id_t *char_id);
  541. #ifdef __cplusplus
  542. }
  543. #endif
  544. #endif /* __ESP_GATTC_API_H__ */