esp_gap_ble_api.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #ifndef __ESP_GAP_BLE_API_H__
  2. #define __ESP_GAP_BLE_API_H__
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include "esp_err.h"
  6. #include "esp_bt_defs.h"
  7. #define ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
  8. #define ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
  9. #define ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
  10. #define ESP_GAP_BLE_SCAN_RESULT_EVT 3
  11. typedef uint32_t esp_gap_ble_event_t;
  12. /// Advertising mode
  13. typedef enum {
  14. ADV_TYPE_IND = 0x00,
  15. ADV_TYPE_DIRECT_IND_HIGH = 0x01,
  16. ADV_TYPE_SCAN_IND = 0x02,
  17. ADV_TYPE_NONCONN_IND = 0x03,
  18. ADV_TYPE_DIRECT_IND_LOW = 0x04,
  19. } esp_ble_adv_type_t;
  20. typedef enum {
  21. ADV_CHNL_37 = 0x01,
  22. ADV_CHNL_38 = 0x02,
  23. ADV_CHNL_39 = 0x03,
  24. ADV_CHNL_ALL = 0x07,
  25. } esp_ble_adv_channel_t;
  26. typedef enum {
  27. ///Allow both scan and connection requests from anyone
  28. ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,
  29. ///Allow both scan req from White List devices only and connection req from anyone
  30. ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY,
  31. ///Allow both scan req from anyone and connection req from White List devices only
  32. ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST,
  33. ///Allow scan and connection requests from White List devices only
  34. ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST,
  35. ///Enumeration end value for advertising filter policy value check
  36. } esp_ble_adv_filter_t;
  37. typedef struct {
  38. uint16_t adv_int_min;
  39. uint16_t adv_int_max;
  40. esp_ble_adv_type_t adv_type;
  41. esp_ble_addr_type_t own_addr_type;
  42. esp_bd_addr_t peer_addr;
  43. esp_ble_addr_type_t peer_addr_type;
  44. esp_ble_adv_channel_t channel_map;
  45. esp_ble_adv_filter_t adv_filter_policy;
  46. } esp_ble_adv_params_t;
  47. typedef struct {
  48. bool set_scan_rsp;
  49. bool include_name;
  50. bool include_txpower;
  51. int min_interval;
  52. int max_interval;
  53. int appearance;
  54. uint16_t manufacturer_len;
  55. uint8_t *p_manufacturer_data;
  56. uint16_t service_data_len;
  57. uint8_t *p_service_data;
  58. uint16_t service_uuid_len;
  59. uint8_t *p_service_uuid;
  60. uint8_t flag;
  61. } esp_ble_adv_data_t;
  62. typedef enum {
  63. BLE_SCAN_TYPE_PASSIVE = 0x0,
  64. BLE_SCAN_TYPE_ACTIVE = 0x1,
  65. } esp_ble_scan_type_t;
  66. typedef enum {
  67. BLE_SCAN_FILTER_ALLOW_ALL = 0x0,
  68. BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x1,
  69. BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x2,
  70. BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR = 0x3,
  71. } esp_ble_scan_filter_t;
  72. typedef struct
  73. {
  74. esp_ble_scan_type_t scan_type;
  75. esp_ble_addr_type_t own_addr_type;
  76. esp_ble_scan_filter_t scan_filter_policy;
  77. uint16_t scan_interval;
  78. uint16_t scan_window;
  79. } esp_ble_scan_params_t;
  80. typedef struct {
  81. esp_bd_addr_t bda;
  82. uint16_t min_int;
  83. uint16_t max_int;
  84. uint16_t latency;
  85. uint16_t timeout;
  86. } esp_ble_conn_update_params_t;
  87. typedef void (*esp_gap_ble_cb_t)(esp_gap_ble_event_t event, void *param);
  88. typedef enum {
  89. /* Search callback events */
  90. ESP_GAP_SEARCH_INQ_RES_EVT = 0, /* Inquiry result for a peer device. */
  91. ESP_GAP_SEARCH_INQ_CMPL_EVT = 1, /* Inquiry complete. */
  92. ESP_GAP_SEARCH_DISC_RES_EVT = 2, /* Discovery result for a peer device. */
  93. ESP_GAP_SEARCH_DISC_BLE_RES_EVT = 3, /* Discovery result for BLE GATT based servoce on a peer device. */
  94. ESP_GAP_SEARCH_DISC_CMPL_EVT = 4, /* Discovery complete. */
  95. ESP_GAP_SEARCH_DI_DISC_CMPL_EVT = 5, /* Discovery complete. */
  96. ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT = 6, /* Search cancelled */
  97. } esp_gap_search_evt_t;
  98. typedef union {
  99. //ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
  100. struct ble_adv_data_cmpl_evt_param {
  101. esp_bt_status_t status;
  102. } adv_data_cmpl;
  103. //ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
  104. struct ble_scan_rsp_data_cmpl_evt_param {
  105. esp_bt_status_t status;
  106. } scan_rsp_data_cmpl;
  107. //ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
  108. struct ble_scan_param_cmpl_evt_param {
  109. esp_bt_status_t status;
  110. } scan_param_cmpl;
  111. //ESP_GAP_BLE_SCAN_RESULT_EVT 3
  112. struct ble_scan_result_evt_param {
  113. esp_gap_search_evt_t search_evt;
  114. esp_bd_addr_t bda;
  115. esp_bt_dev_type_t dev_type;
  116. esp_ble_addr_type_t ble_addr_type;
  117. int rssi;
  118. int flag;
  119. int num_resps;
  120. } scan_rst;
  121. } esp_ble_gap_cb_param_t;
  122. /*******************************************************************************
  123. **
  124. ** @function esp_ble_gap_register_callback
  125. **
  126. ** @brief This function is called to occur gap event, such as scan result
  127. **
  128. ** @param[in] callback: callback function
  129. **
  130. ** @return ESP_OK - success, other - failed
  131. **
  132. *******************************************************************************/
  133. esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback);
  134. /*******************************************************************************
  135. **
  136. ** @function esp_ble_gap_config_adv_data
  137. **
  138. ** @brief This function is called to override the BTA default ADV parameters.
  139. **
  140. ** @param[in] adv_data: Pointer to User defined ADV data structure. This
  141. ** memory space can not be freed until p_adv_data_cback
  142. ** is received.
  143. ** @param[in|out] adv_data_cback: set adv data complete callback.
  144. **
  145. ** @return ESP_OK - success, other - failed
  146. **
  147. *******************************************************************************/
  148. esp_err_t esp_ble_gap_config_adv_data (esp_ble_adv_data_t *adv_data);
  149. /*******************************************************************************
  150. **
  151. ** @function esp_ble_gap_set_scan_params
  152. **
  153. ** @brief This function is called to set scan parameters
  154. **
  155. ** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
  156. ** memory space can not be freed until scan_param_setup_cback
  157. **
  158. ** @return ESP_OK - success, other - failed
  159. **
  160. *******************************************************************************/
  161. esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
  162. /*******************************************************************************
  163. **
  164. ** @function esp_ble_gap_start_scanning
  165. **
  166. ** @brief This procedure keep the device scanning the peer device whith advertising on the air
  167. **
  168. ** @param[in] duration: Keeping the scaning time, the unit is second.
  169. **
  170. ** @return ESP_OK - success, other - failed
  171. **
  172. *******************************************************************************/
  173. esp_err_t esp_ble_gap_start_scanning(uint32_t duration);
  174. /*******************************************************************************
  175. **
  176. ** @function esp_ble_gap_start_advertising
  177. **
  178. ** @brief This function is called to start advertising.
  179. **
  180. ** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
  181. **
  182. ** @return ESP_OK - success, other - failed
  183. **
  184. *******************************************************************************/
  185. esp_err_t esp_ble_gap_start_advertising (esp_ble_adv_params_t *adv_params);
  186. /*******************************************************************************
  187. **
  188. ** @function esp_gap_ble_stop_advertising
  189. **
  190. ** @brief This function is called to stop advertising.
  191. **
  192. ** @param None
  193. **
  194. ** @return ESP_OK - success, other - failed
  195. **
  196. *******************************************************************************/
  197. esp_err_t esp_ble_gap_stop_advertising(void);
  198. /*******************************************************************************
  199. **
  200. ** @function esp_ble_update_conn_params
  201. **
  202. ** @brief Update connection parameters, can only be used when connection is up.
  203. **
  204. ** @param[in] param - connection update params
  205. **
  206. ** @return ESP_OK - success, other - failed
  207. **
  208. *******************************************************************************/
  209. esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params);
  210. /*******************************************************************************
  211. **
  212. ** @function esp_ble_gap_set_pkt_data_len
  213. **
  214. ** @brief This function is to set maximum LE data packet size
  215. **
  216. ** @return ESP_OK - success, other - failed
  217. **
  218. *******************************************************************************/
  219. esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
  220. /*******************************************************************************
  221. **
  222. ** @function esp_ble_gap_set_rand_addr
  223. **
  224. ** @brief This function set the random address for the appliction
  225. **
  226. ** @param[in] rand_addr: the random address whith should be setting
  227. **
  228. ** @return ESP_OK - success, other - failed
  229. **
  230. **
  231. *******************************************************************************/
  232. esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr);
  233. /*******************************************************************************
  234. **
  235. ** @function esp_ble_gap_config_local_privacy
  236. **
  237. ** @brief Enable/disable privacy on the local device
  238. **
  239. ** @param[in] privacy_enable - enable/disabe privacy on remote device.
  240. **
  241. ** @return ESP_OK - success, other - failed
  242. **
  243. *******************************************************************************/
  244. esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
  245. /*******************************************************************************
  246. **
  247. ** @function esp_ble_gap_set_device_name
  248. **
  249. ** @brief Set device name to the local device
  250. **
  251. ** @param[in] name - device name.
  252. **
  253. ** @return ESP_OK - success, other - failed
  254. **
  255. *******************************************************************************/
  256. esp_err_t esp_ble_gap_set_device_name(char *name);
  257. #endif /* __ESP_GAP_BLE_API_H__ */