esp_wifi.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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. /* Notes about WiFi Programming
  14. *
  15. * The esp32 WiFi programming model can be depicted as following picture:
  16. *
  17. *
  18. * default handler user handler
  19. * ------------- --------------- ---------------
  20. * | | event | | callback or | |
  21. * | tcpip | ---------> | event | ----------> | application |
  22. * | stack | | task | event | task |
  23. * |-----------| |-------------| |-------------|
  24. * /|\ |
  25. * | |
  26. * event | |
  27. * | |
  28. * | |
  29. * --------------- |
  30. * | | |
  31. * | WiFi Driver |/__________________|
  32. * | |\ API call
  33. * | |
  34. * |-------------|
  35. *
  36. * The WiFi driver can be consider as black box, it knows nothing about the high layer code, such as
  37. * TCPIP stack, application task, event task etc, all it can do is to receive API call from high layer
  38. * or post event queue to a specified Queue, which is initialized by API esp_wifi_init().
  39. *
  40. * The event task is a daemon task, which receives events from WiFi driver or from other subsystem, such
  41. * as TCPIP stack, event task will call the default callback function on receiving the event. For example,
  42. * on receiving event SYSTEM_EVENT_STA_CONNECTED, it will call tcpip_adapter_start() to start the DHCP
  43. * client in it's default handler.
  44. *
  45. * Application can register it's own event callback function by API esp_event_init, then the application callback
  46. * function will be called after the default callback. Also, if application doesn't want to execute the callback
  47. * in the event task, what it needs to do is to post the related event to application task in the application callback function.
  48. *
  49. * The application task (code) generally mixes all these thing together, it calls APIs to init the system/WiFi and
  50. * handle the events when necessary.
  51. *
  52. */
  53. #ifndef __ESP_WIFI_H__
  54. #define __ESP_WIFI_H__
  55. #include <stdint.h>
  56. #include <stdbool.h>
  57. #include "freertos/FreeRTOS.h"
  58. #include "freertos/queue.h"
  59. #include "rom/queue.h"
  60. #include "sdkconfig.h"
  61. #include "esp_err.h"
  62. #include "esp_wifi_types.h"
  63. #include "esp_wifi_crypto_types.h"
  64. #include "esp_event.h"
  65. #include "esp_wifi_os_adapter.h"
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. #define ESP_ERR_WIFI_NOT_INIT (ESP_ERR_WIFI_BASE + 1) /*!< WiFi driver was not installed by esp_wifi_init */
  70. #define ESP_ERR_WIFI_NOT_STARTED (ESP_ERR_WIFI_BASE + 2) /*!< WiFi driver was not started by esp_wifi_start */
  71. #define ESP_ERR_WIFI_NOT_STOPPED (ESP_ERR_WIFI_BASE + 3) /*!< WiFi driver was not stopped by esp_wifi_stop */
  72. #define ESP_ERR_WIFI_IF (ESP_ERR_WIFI_BASE + 4) /*!< WiFi interface error */
  73. #define ESP_ERR_WIFI_MODE (ESP_ERR_WIFI_BASE + 5) /*!< WiFi mode error */
  74. #define ESP_ERR_WIFI_STATE (ESP_ERR_WIFI_BASE + 6) /*!< WiFi internal state error */
  75. #define ESP_ERR_WIFI_CONN (ESP_ERR_WIFI_BASE + 7) /*!< WiFi internal control block of station or soft-AP error */
  76. #define ESP_ERR_WIFI_NVS (ESP_ERR_WIFI_BASE + 8) /*!< WiFi internal NVS module error */
  77. #define ESP_ERR_WIFI_MAC (ESP_ERR_WIFI_BASE + 9) /*!< MAC address is invalid */
  78. #define ESP_ERR_WIFI_SSID (ESP_ERR_WIFI_BASE + 10) /*!< SSID is invalid */
  79. #define ESP_ERR_WIFI_PASSWORD (ESP_ERR_WIFI_BASE + 11) /*!< Password is invalid */
  80. #define ESP_ERR_WIFI_TIMEOUT (ESP_ERR_WIFI_BASE + 12) /*!< Timeout error */
  81. #define ESP_ERR_WIFI_WAKE_FAIL (ESP_ERR_WIFI_BASE + 13) /*!< WiFi is in sleep state(RF closed) and wakeup fail */
  82. #define ESP_ERR_WIFI_WOULD_BLOCK (ESP_ERR_WIFI_BASE + 14) /*!< The caller would block */
  83. #define ESP_ERR_WIFI_NOT_CONNECT (ESP_ERR_WIFI_BASE + 15) /*!< Station still in disconnect status */
  84. /**
  85. * @brief WiFi stack configuration parameters passed to esp_wifi_init call.
  86. */
  87. typedef struct {
  88. system_event_handler_t event_handler; /**< WiFi event handler */
  89. wifi_osi_funcs_t* osi_funcs; /**< WiFi OS functions */
  90. wpa_crypto_funcs_t wpa_crypto_funcs; /**< WiFi station crypto functions when connect */
  91. int static_rx_buf_num; /**< WiFi static RX buffer number */
  92. int dynamic_rx_buf_num; /**< WiFi dynamic RX buffer number */
  93. int tx_buf_type; /**< WiFi TX buffer type */
  94. int static_tx_buf_num; /**< WiFi static TX buffer number */
  95. int dynamic_tx_buf_num; /**< WiFi dynamic TX buffer number */
  96. int csi_enable; /**< WiFi channel state information enable flag */
  97. int ampdu_rx_enable; /**< WiFi AMPDU RX feature enable flag */
  98. int ampdu_tx_enable; /**< WiFi AMPDU TX feature enable flag */
  99. int nvs_enable; /**< WiFi NVS flash enable flag */
  100. int nano_enable; /**< Nano option for printf/scan family enable flag */
  101. int tx_ba_win; /**< WiFi Block Ack TX window size */
  102. int rx_ba_win; /**< WiFi Block Ack RX window size */
  103. int wifi_task_core_id; /**< WiFi Task Core ID */
  104. int beacon_max_len; /**< WiFi softAP maximum length of the beacon */
  105. int magic; /**< WiFi init magic number, it should be the last field */
  106. } wifi_init_config_t;
  107. #ifdef CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM
  108. #define WIFI_STATIC_TX_BUFFER_NUM CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM
  109. #else
  110. #define WIFI_STATIC_TX_BUFFER_NUM 0
  111. #endif
  112. #ifdef CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM
  113. #define WIFI_DYNAMIC_TX_BUFFER_NUM CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM
  114. #else
  115. #define WIFI_DYNAMIC_TX_BUFFER_NUM 0
  116. #endif
  117. #if CONFIG_ESP32_WIFI_CSI_ENABLED
  118. #define WIFI_CSI_ENABLED 1
  119. #else
  120. #define WIFI_CSI_ENABLED 0
  121. #endif
  122. #if CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED
  123. #define WIFI_AMPDU_RX_ENABLED 1
  124. #else
  125. #define WIFI_AMPDU_RX_ENABLED 0
  126. #endif
  127. #if CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED
  128. #define WIFI_AMPDU_TX_ENABLED 1
  129. #else
  130. #define WIFI_AMPDU_TX_ENABLED 0
  131. #endif
  132. #if CONFIG_ESP32_WIFI_NVS_ENABLED
  133. #define WIFI_NVS_ENABLED 1
  134. #else
  135. #define WIFI_NVS_ENABLED 0
  136. #endif
  137. #if CONFIG_NEWLIB_NANO_FORMAT
  138. #define WIFI_NANO_FORMAT_ENABLED 1
  139. #else
  140. #define WIFI_NANO_FORMAT_ENABLED 0
  141. #endif
  142. extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
  143. #define WIFI_INIT_CONFIG_MAGIC 0x1F2F3F4F
  144. #ifdef CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED
  145. #define WIFI_DEFAULT_TX_BA_WIN CONFIG_ESP32_WIFI_TX_BA_WIN
  146. #else
  147. #define WIFI_DEFAULT_TX_BA_WIN 0 /* unused if ampdu_tx_enable == false */
  148. #endif
  149. #ifdef CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED
  150. #define WIFI_DEFAULT_RX_BA_WIN CONFIG_ESP32_WIFI_RX_BA_WIN
  151. #else
  152. #define WIFI_DEFAULT_RX_BA_WIN 0 /* unused if ampdu_rx_enable == false */
  153. #endif
  154. #if CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1
  155. #define WIFI_TASK_CORE_ID 1
  156. #else
  157. #define WIFI_TASK_CORE_ID 0
  158. #endif
  159. #ifdef CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN
  160. #define WIFI_SOFTAP_BEACON_MAX_LEN CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN
  161. #else
  162. #define WIFI_SOFTAP_BEACON_MAX_LEN 752
  163. #endif
  164. #define WIFI_INIT_CONFIG_DEFAULT() { \
  165. .event_handler = &esp_event_send, \
  166. .osi_funcs = &g_wifi_osi_funcs, \
  167. .wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
  168. .static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\
  169. .dynamic_rx_buf_num = CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM,\
  170. .tx_buf_type = CONFIG_ESP32_WIFI_TX_BUFFER_TYPE,\
  171. .static_tx_buf_num = WIFI_STATIC_TX_BUFFER_NUM,\
  172. .dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\
  173. .csi_enable = WIFI_CSI_ENABLED,\
  174. .ampdu_rx_enable = WIFI_AMPDU_RX_ENABLED,\
  175. .ampdu_tx_enable = WIFI_AMPDU_TX_ENABLED,\
  176. .nvs_enable = WIFI_NVS_ENABLED,\
  177. .nano_enable = WIFI_NANO_FORMAT_ENABLED,\
  178. .tx_ba_win = WIFI_DEFAULT_TX_BA_WIN,\
  179. .rx_ba_win = WIFI_DEFAULT_RX_BA_WIN,\
  180. .wifi_task_core_id = WIFI_TASK_CORE_ID,\
  181. .beacon_max_len = WIFI_SOFTAP_BEACON_MAX_LEN, \
  182. .magic = WIFI_INIT_CONFIG_MAGIC\
  183. };
  184. /**
  185. * @brief Init WiFi
  186. * Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
  187. * WiFi NVS structure etc, this WiFi also start WiFi task
  188. *
  189. * @attention 1. This API must be called before all other WiFi API can be called
  190. * @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values, this can
  191. * guarantee all the fields got correct value when more fields are added into wifi_init_config_t
  192. * in future release. If you want to set your owner initial values, overwrite the default values
  193. * which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of
  194. * wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC!
  195. *
  196. * @param config pointer to WiFi init configuration structure; can point to a temporary variable.
  197. *
  198. * @return
  199. * - ESP_OK: succeed
  200. * - ESP_ERR_NO_MEM: out of memory
  201. * - others: refer to error code esp_err.h
  202. */
  203. esp_err_t esp_wifi_init(const wifi_init_config_t *config);
  204. /**
  205. * @brief Deinit WiFi
  206. * Free all resource allocated in esp_wifi_init and stop WiFi task
  207. *
  208. * @attention 1. This API should be called if you want to remove WiFi driver from the system
  209. *
  210. * @return
  211. * - ESP_OK: succeed
  212. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  213. */
  214. esp_err_t esp_wifi_deinit(void);
  215. /**
  216. * @brief Set the WiFi operating mode
  217. *
  218. * Set the WiFi operating mode as station, soft-AP or station+soft-AP,
  219. * The default mode is soft-AP mode.
  220. *
  221. * @param mode WiFi operating mode
  222. *
  223. * @return
  224. * - ESP_OK: succeed
  225. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  226. * - ESP_ERR_INVALID_ARG: invalid argument
  227. * - others: refer to error code in esp_err.h
  228. */
  229. esp_err_t esp_wifi_set_mode(wifi_mode_t mode);
  230. /**
  231. * @brief Get current operating mode of WiFi
  232. *
  233. * @param[out] mode store current WiFi mode
  234. *
  235. * @return
  236. * - ESP_OK: succeed
  237. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  238. * - ESP_ERR_INVALID_ARG: invalid argument
  239. */
  240. esp_err_t esp_wifi_get_mode(wifi_mode_t *mode);
  241. /**
  242. * @brief Start WiFi according to current configuration
  243. * If mode is WIFI_MODE_STA, it create station control block and start station
  244. * If mode is WIFI_MODE_AP, it create soft-AP control block and start soft-AP
  245. * If mode is WIFI_MODE_APSTA, it create soft-AP and station control block and start soft-AP and station
  246. *
  247. * @return
  248. * - ESP_OK: succeed
  249. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  250. * - ESP_ERR_INVALID_ARG: invalid argument
  251. * - ESP_ERR_NO_MEM: out of memory
  252. * - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
  253. * - ESP_FAIL: other WiFi internal errors
  254. */
  255. esp_err_t esp_wifi_start(void);
  256. /**
  257. * @brief Stop WiFi
  258. * If mode is WIFI_MODE_STA, it stop station and free station control block
  259. * If mode is WIFI_MODE_AP, it stop soft-AP and free soft-AP control block
  260. * If mode is WIFI_MODE_APSTA, it stop station/soft-AP and free station/soft-AP control block
  261. *
  262. * @return
  263. * - ESP_OK: succeed
  264. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  265. */
  266. esp_err_t esp_wifi_stop(void);
  267. /**
  268. * @brief Restore WiFi stack persistent settings to default values
  269. *
  270. * This function will reset settings made using the following APIs:
  271. * - esp_wifi_get_auto_connect,
  272. * - esp_wifi_set_protocol,
  273. * - esp_wifi_set_config related
  274. * - esp_wifi_set_mode
  275. *
  276. * @return
  277. * - ESP_OK: succeed
  278. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  279. */
  280. esp_err_t esp_wifi_restore(void);
  281. /**
  282. * @brief Connect the ESP32 WiFi station to the AP.
  283. *
  284. * @attention 1. This API only impact WIFI_MODE_STA or WIFI_MODE_APSTA mode
  285. * @attention 2. If the ESP32 is connected to an AP, call esp_wifi_disconnect to disconnect.
  286. * @attention 3. The scanning triggered by esp_wifi_start_scan() will not be effective until connection between ESP32 and the AP is established.
  287. * If ESP32 is scanning and connecting at the same time, ESP32 will abort scanning and return a warning message and error
  288. * number ESP_ERR_WIFI_STATE.
  289. * If you want to do reconnection after ESP32 received disconnect event, remember to add the maximum retry time, otherwise the called
  290. * scan will not work. This is especially true when the AP doesn't exist, and you still try reconnection after ESP32 received disconnect
  291. * event with the reason code WIFI_REASON_NO_AP_FOUND.
  292. *
  293. * @return
  294. * - ESP_OK: succeed
  295. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  296. * - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
  297. * - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
  298. * - ESP_ERR_WIFI_SSID: SSID of AP which station connects is invalid
  299. */
  300. esp_err_t esp_wifi_connect(void);
  301. /**
  302. * @brief Disconnect the ESP32 WiFi station from the AP.
  303. *
  304. * @return
  305. * - ESP_OK: succeed
  306. * - ESP_ERR_WIFI_NOT_INIT: WiFi was not initialized by esp_wifi_init
  307. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  308. * - ESP_FAIL: other WiFi internal errors
  309. */
  310. esp_err_t esp_wifi_disconnect(void);
  311. /**
  312. * @brief Currently this API is just an stub API
  313. *
  314. * @return
  315. * - ESP_OK: succeed
  316. * - others: fail
  317. */
  318. esp_err_t esp_wifi_clear_fast_connect(void);
  319. /**
  320. * @brief deauthenticate all stations or associated id equals to aid
  321. *
  322. * @param aid when aid is 0, deauthenticate all stations, otherwise deauthenticate station whose associated id is aid
  323. *
  324. * @return
  325. * - ESP_OK: succeed
  326. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  327. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  328. * - ESP_ERR_INVALID_ARG: invalid argument
  329. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  330. */
  331. esp_err_t esp_wifi_deauth_sta(uint16_t aid);
  332. /**
  333. * @brief Scan all available APs.
  334. *
  335. * @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the
  336. * will be freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause
  337. * the memory to be freed once the scan is done
  338. * @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds.
  339. * Values above 1500ms may cause station to disconnect from AP and are not recommended.
  340. *
  341. * @param config configuration of scanning
  342. * @param block if block is true, this API will block the caller until the scan is done, otherwise
  343. * it will return immediately
  344. *
  345. * @return
  346. * - ESP_OK: succeed
  347. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  348. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  349. * - ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout
  350. * - ESP_ERR_WIFI_STATE: wifi still connecting when invoke esp_wifi_scan_start
  351. * - others: refer to error code in esp_err.h
  352. */
  353. esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, bool block);
  354. /**
  355. * @brief Stop the scan in process
  356. *
  357. * @return
  358. * - ESP_OK: succeed
  359. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  360. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  361. */
  362. esp_err_t esp_wifi_scan_stop(void);
  363. /**
  364. * @brief Get number of APs found in last scan
  365. *
  366. * @param[out] number store number of APIs found in last scan
  367. *
  368. * @attention This API can only be called when the scan is completed, otherwise it may get wrong value.
  369. *
  370. * @return
  371. * - ESP_OK: succeed
  372. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  373. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  374. * - ESP_ERR_INVALID_ARG: invalid argument
  375. */
  376. esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);
  377. /**
  378. * @brief Get AP list found in last scan
  379. *
  380. * @param[inout] number As input param, it stores max AP number ap_records can hold.
  381. * As output param, it receives the actual AP number this API returns.
  382. * @param ap_records wifi_ap_record_t array to hold the found APs
  383. *
  384. * @return
  385. * - ESP_OK: succeed
  386. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  387. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  388. * - ESP_ERR_INVALID_ARG: invalid argument
  389. * - ESP_ERR_NO_MEM: out of memory
  390. */
  391. esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records);
  392. /**
  393. * @brief Get information of AP which the ESP32 station is associated with
  394. *
  395. * @param ap_info the wifi_ap_record_t to hold AP information
  396. * sta can get the connected ap's phy mode info through the struct member
  397. * phy_11b,phy_11g,phy_11n,phy_lr in the wifi_ap_record_t struct.
  398. * For example, phy_11b = 1 imply that ap support 802.11b mode
  399. *
  400. * @return
  401. * - ESP_OK: succeed
  402. * - ESP_ERR_WIFI_CONN: The station interface don't initialized
  403. * - ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status
  404. */
  405. esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info);
  406. /**
  407. * @brief Set current WiFi power save type
  408. *
  409. * @attention Default power save type is WIFI_PS_MIN_MODEM.
  410. *
  411. * @param type power save type
  412. *
  413. * @return ESP_OK: succeed
  414. */
  415. esp_err_t esp_wifi_set_ps(wifi_ps_type_t type);
  416. /**
  417. * @brief Get current WiFi power save type
  418. *
  419. * @attention Default power save type is WIFI_PS_MIN_MODEM.
  420. *
  421. * @param[out] type: store current power save type
  422. *
  423. * @return ESP_OK: succeed
  424. */
  425. esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type);
  426. /**
  427. * @brief Set protocol type of specified interface
  428. * The default protocol is (WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)
  429. *
  430. * @attention Currently we only support 802.11b or 802.11bg or 802.11bgn mode
  431. *
  432. * @param ifx interfaces
  433. * @param protocol_bitmap WiFi protocol bitmap
  434. *
  435. * @return
  436. * - ESP_OK: succeed
  437. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  438. * - ESP_ERR_WIFI_IF: invalid interface
  439. * - others: refer to error codes in esp_err.h
  440. */
  441. esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap);
  442. /**
  443. * @brief Get the current protocol bitmap of the specified interface
  444. *
  445. * @param ifx interface
  446. * @param[out] protocol_bitmap store current WiFi protocol bitmap of interface ifx
  447. *
  448. * @return
  449. * - ESP_OK: succeed
  450. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  451. * - ESP_ERR_WIFI_IF: invalid interface
  452. * - ESP_ERR_INVALID_ARG: invalid argument
  453. * - others: refer to error codes in esp_err.h
  454. */
  455. esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap);
  456. /**
  457. * @brief Set the bandwidth of ESP32 specified interface
  458. *
  459. * @attention 1. API return false if try to configure an interface that is not enabled
  460. * @attention 2. WIFI_BW_HT40 is supported only when the interface support 11N
  461. *
  462. * @param ifx interface to be configured
  463. * @param bw bandwidth
  464. *
  465. * @return
  466. * - ESP_OK: succeed
  467. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  468. * - ESP_ERR_WIFI_IF: invalid interface
  469. * - ESP_ERR_INVALID_ARG: invalid argument
  470. * - others: refer to error codes in esp_err.h
  471. */
  472. esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw);
  473. /**
  474. * @brief Get the bandwidth of ESP32 specified interface
  475. *
  476. * @attention 1. API return false if try to get a interface that is not enable
  477. *
  478. * @param ifx interface to be configured
  479. * @param[out] bw store bandwidth of interface ifx
  480. *
  481. * @return
  482. * - ESP_OK: succeed
  483. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  484. * - ESP_ERR_WIFI_IF: invalid interface
  485. * - ESP_ERR_INVALID_ARG: invalid argument
  486. */
  487. esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw);
  488. /**
  489. * @brief Set primary/secondary channel of ESP32
  490. *
  491. * @attention 1. This is a special API for sniffer
  492. * @attention 2. This API should be called after esp_wifi_start() or esp_wifi_set_promiscuous()
  493. *
  494. * @param primary for HT20, primary is the channel number, for HT40, primary is the primary channel
  495. * @param second for HT20, second is ignored, for HT40, second is the second channel
  496. *
  497. * @return
  498. * - ESP_OK: succeed
  499. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  500. * - ESP_ERR_WIFI_IF: invalid interface
  501. * - ESP_ERR_INVALID_ARG: invalid argument
  502. */
  503. esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second);
  504. /**
  505. * @brief Get the primary/secondary channel of ESP32
  506. *
  507. * @attention 1. API return false if try to get a interface that is not enable
  508. *
  509. * @param primary store current primary channel
  510. * @param[out] second store current second channel
  511. *
  512. * @return
  513. * - ESP_OK: succeed
  514. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  515. * - ESP_ERR_INVALID_ARG: invalid argument
  516. */
  517. esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second);
  518. /**
  519. * @brief configure country info
  520. *
  521. * @attention 1. The default country is {.cc="CN", .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO}
  522. * @attention 2. When the country policy is WIFI_COUNTRY_POLICY_AUTO, the country info of the AP to which
  523. * the station is connected is used. E.g. if the configured country info is {.cc="USA", .schan=1, .nchan=11}
  524. * and the country info of the AP to which the station is connected is {.cc="JP", .schan=1, .nchan=14}
  525. * then the country info that will be used is {.cc="JP", .schan=1, .nchan=14}. If the station disconnected
  526. * from the AP the country info is set back back to the country info of the station automatically,
  527. * {.cc="USA", .schan=1, .nchan=11} in the example.
  528. * @attention 3. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, always use the configured country info.
  529. * @attention 4. When the country info is changed because of configuration or because the station connects to a different
  530. * external AP, the country IE in probe response/beacon of the soft-AP is changed also.
  531. * @attention 5. The country configuration is not stored into flash
  532. * @attention 6. This API doesn't validate the per-country rules, it's up to the user to fill in all fields according to
  533. * local regulations.
  534. *
  535. * @param country the configured country info
  536. *
  537. * @return
  538. * - ESP_OK: succeed
  539. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  540. * - ESP_ERR_INVALID_ARG: invalid argument
  541. */
  542. esp_err_t esp_wifi_set_country(const wifi_country_t *country);
  543. /**
  544. * @brief get the current country info
  545. *
  546. * @param country country info
  547. *
  548. * @return
  549. * - ESP_OK: succeed
  550. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  551. * - ESP_ERR_INVALID_ARG: invalid argument
  552. */
  553. esp_err_t esp_wifi_get_country(wifi_country_t *country);
  554. /**
  555. * @brief Set MAC address of the ESP32 WiFi station or the soft-AP interface.
  556. *
  557. * @attention 1. This API can only be called when the interface is disabled
  558. * @attention 2. ESP32 soft-AP and station have different MAC addresses, do not set them to be the same.
  559. * @attention 3. The bit 0 of the first byte of ESP32 MAC address can not be 1. For example, the MAC address
  560. * can set to be "1a:XX:XX:XX:XX:XX", but can not be "15:XX:XX:XX:XX:XX".
  561. *
  562. * @param ifx interface
  563. * @param mac the MAC address
  564. *
  565. * @return
  566. * - ESP_OK: succeed
  567. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  568. * - ESP_ERR_INVALID_ARG: invalid argument
  569. * - ESP_ERR_WIFI_IF: invalid interface
  570. * - ESP_ERR_WIFI_MAC: invalid mac address
  571. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  572. * - others: refer to error codes in esp_err.h
  573. */
  574. esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, const uint8_t mac[6]);
  575. /**
  576. * @brief Get mac of specified interface
  577. *
  578. * @param ifx interface
  579. * @param[out] mac store mac of the interface ifx
  580. *
  581. * @return
  582. * - ESP_OK: succeed
  583. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  584. * - ESP_ERR_INVALID_ARG: invalid argument
  585. * - ESP_ERR_WIFI_IF: invalid interface
  586. */
  587. esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]);
  588. /**
  589. * @brief The RX callback function in the promiscuous mode.
  590. * Each time a packet is received, the callback function will be called.
  591. *
  592. * @param buf Data received. Type of data in buffer (wifi_promiscuous_pkt_t or wifi_pkt_rx_ctrl_t) indicated by 'type' parameter.
  593. * @param type promiscuous packet type.
  594. *
  595. */
  596. typedef void (* wifi_promiscuous_cb_t)(void *buf, wifi_promiscuous_pkt_type_t type);
  597. /**
  598. * @brief Register the RX callback function in the promiscuous mode.
  599. *
  600. * Each time a packet is received, the registered callback function will be called.
  601. *
  602. * @param cb callback
  603. *
  604. * @return
  605. * - ESP_OK: succeed
  606. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  607. */
  608. esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
  609. /**
  610. * @brief Enable the promiscuous mode.
  611. *
  612. * @param en false - disable, true - enable
  613. *
  614. * @return
  615. * - ESP_OK: succeed
  616. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  617. */
  618. esp_err_t esp_wifi_set_promiscuous(bool en);
  619. /**
  620. * @brief Get the promiscuous mode.
  621. *
  622. * @param[out] en store the current status of promiscuous mode
  623. *
  624. * @return
  625. * - ESP_OK: succeed
  626. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  627. * - ESP_ERR_INVALID_ARG: invalid argument
  628. */
  629. esp_err_t esp_wifi_get_promiscuous(bool *en);
  630. /**
  631. * @brief Enable the promiscuous mode packet type filter.
  632. *
  633. * @note The default filter is to filter all packets except WIFI_PKT_MISC
  634. *
  635. * @param filter the packet type filtered in promiscuous mode.
  636. *
  637. * @return
  638. * - ESP_OK: succeed
  639. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  640. */
  641. esp_err_t esp_wifi_set_promiscuous_filter(const wifi_promiscuous_filter_t *filter);
  642. /**
  643. * @brief Get the promiscuous filter.
  644. *
  645. * @param[out] filter store the current status of promiscuous filter
  646. *
  647. * @return
  648. * - ESP_OK: succeed
  649. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  650. * - ESP_ERR_INVALID_ARG: invalid argument
  651. */
  652. esp_err_t esp_wifi_get_promiscuous_filter(wifi_promiscuous_filter_t *filter);
  653. /**
  654. * @brief Enable subtype filter of the control packet in promiscuous mode.
  655. *
  656. * @note The default filter is to filter none control packet.
  657. *
  658. * @param filter the subtype of the control packet filtered in promiscuous mode.
  659. *
  660. * @return
  661. * - ESP_OK: succeed
  662. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  663. */
  664. esp_err_t esp_wifi_set_promiscuous_ctrl_filter(const wifi_promiscuous_filter_t *filter);
  665. /**
  666. * @brief Get the subtype filter of the control packet in promiscuous mode.
  667. *
  668. * @param[out] filter store the current status of subtype filter of the control packet in promiscuous mode
  669. *
  670. * @return
  671. * - ESP_OK: succeed
  672. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  673. * - ESP_ERR_WIFI_ARG: invalid argument
  674. */
  675. esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter);
  676. /**
  677. * @brief Set the configuration of the ESP32 STA or AP
  678. *
  679. * @attention 1. This API can be called only when specified interface is enabled, otherwise, API fail
  680. * @attention 2. For station configuration, bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.
  681. * @attention 3. ESP32 is limited to only one channel, so when in the soft-AP+station mode, the soft-AP will adjust its channel automatically to be the same as
  682. * the channel of the ESP32 station.
  683. *
  684. * @param interface interface
  685. * @param conf station or soft-AP configuration
  686. *
  687. * @return
  688. * - ESP_OK: succeed
  689. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  690. * - ESP_ERR_INVALID_ARG: invalid argument
  691. * - ESP_ERR_WIFI_IF: invalid interface
  692. * - ESP_ERR_WIFI_MODE: invalid mode
  693. * - ESP_ERR_WIFI_PASSWORD: invalid password
  694. * - ESP_ERR_WIFI_NVS: WiFi internal NVS error
  695. * - others: refer to the erro code in esp_err.h
  696. */
  697. esp_err_t esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf);
  698. /**
  699. * @brief Get configuration of specified interface
  700. *
  701. * @param interface interface
  702. * @param[out] conf station or soft-AP configuration
  703. *
  704. * @return
  705. * - ESP_OK: succeed
  706. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  707. * - ESP_ERR_INVALID_ARG: invalid argument
  708. * - ESP_ERR_WIFI_IF: invalid interface
  709. */
  710. esp_err_t esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf);
  711. /**
  712. * @brief Get STAs associated with soft-AP
  713. *
  714. * @attention SSC only API
  715. *
  716. * @param[out] sta station list
  717. * ap can get the connected sta's phy mode info through the struct member
  718. * phy_11b,phy_11g,phy_11n,phy_lr in the wifi_sta_info_t struct.
  719. * For example, phy_11b = 1 imply that sta support 802.11b mode
  720. *
  721. * @return
  722. * - ESP_OK: succeed
  723. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  724. * - ESP_ERR_INVALID_ARG: invalid argument
  725. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  726. * - ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid
  727. */
  728. esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta);
  729. /**
  730. * @brief Set the WiFi API configuration storage type
  731. *
  732. * @attention 1. The default value is WIFI_STORAGE_FLASH
  733. *
  734. * @param storage : storage type
  735. *
  736. * @return
  737. * - ESP_OK: succeed
  738. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  739. * - ESP_ERR_INVALID_ARG: invalid argument
  740. */
  741. esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
  742. /**
  743. * @brief Set auto connect
  744. * The default value is true
  745. *
  746. * @param en : true - enable auto connect / false - disable auto connect
  747. *
  748. * @return
  749. * - ESP_OK: succeed
  750. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  751. * - ESP_ERR_WIFI_MODE: WiFi internal error, the station/soft-AP control block is invalid
  752. * - others: refer to error code in esp_err.h
  753. */
  754. esp_err_t esp_wifi_set_auto_connect(bool en) __attribute__ ((deprecated));
  755. /**
  756. * @brief Get the auto connect flag
  757. *
  758. * @param[out] en store current auto connect configuration
  759. *
  760. * @return
  761. * - ESP_OK: succeed
  762. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  763. * - ESP_ERR_INVALID_ARG: invalid argument
  764. */
  765. esp_err_t esp_wifi_get_auto_connect(bool *en) __attribute__ ((deprecated));
  766. /**
  767. * @brief Set 802.11 Vendor-Specific Information Element
  768. *
  769. * @param enable If true, specified IE is enabled. If false, specified IE is removed.
  770. * @param type Information Element type. Determines the frame type to associate with the IE.
  771. * @param idx Index to set or clear. Each IE type can be associated with up to two elements (indices 0 & 1).
  772. * @param vnd_ie Pointer to vendor specific element data. First 6 bytes should be a header with fields matching vendor_ie_data_t.
  773. * If enable is false, this argument is ignored and can be NULL. Data does not need to remain valid after the function returns.
  774. *
  775. * @return
  776. * - ESP_OK: succeed
  777. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init()
  778. * - ESP_ERR_INVALID_ARG: Invalid argument, including if first byte of vnd_ie is not WIFI_VENDOR_IE_ELEMENT_ID (0xDD)
  779. * or second byte is an invalid length.
  780. * - ESP_ERR_NO_MEM: Out of memory
  781. */
  782. esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, const void *vnd_ie);
  783. /**
  784. * @brief Function signature for received Vendor-Specific Information Element callback.
  785. * @param ctx Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback.
  786. * @param type Information element type, based on frame type received.
  787. * @param sa Source 802.11 address.
  788. * @param vnd_ie Pointer to the vendor specific element data received.
  789. * @param rssi Received signal strength indication.
  790. */
  791. typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const vendor_ie_data_t *vnd_ie, int rssi);
  792. /**
  793. * @brief Register Vendor-Specific Information Element monitoring callback.
  794. *
  795. * @param cb Callback function
  796. * @param ctx Context argument, passed to callback function.
  797. *
  798. * @return
  799. * - ESP_OK: succeed
  800. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  801. */
  802. esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
  803. /**
  804. * @brief Set maximum WiFi transmiting power
  805. *
  806. * @attention WiFi transmiting power is divided to six levels in phy init data.
  807. * Level0 represents highest transmiting power and level5 represents lowest
  808. * transmiting power. Packets of different rates are transmitted in
  809. * different powers according to the configuration in phy init data.
  810. * This API only sets maximum WiFi transmiting power. If this API is called,
  811. * the transmiting power of every packet will be less than or equal to the
  812. * value set by this API. If this API is not called, the value of maximum
  813. * transmitting power set in phy_init_data.bin or menuconfig (depend on
  814. * whether to use phy init data in partition or not) will be used. Default
  815. * value is level0. Values passed in power are mapped to transmit power
  816. * levels as follows:
  817. * - [78, 127]: level0
  818. * - [76, 77]: level1
  819. * - [74, 75]: level2
  820. * - [68, 73]: level3
  821. * - [60, 67]: level4
  822. * - [52, 59]: level5
  823. * - [44, 51]: level5 - 2dBm
  824. * - [34, 43]: level5 - 4.5dBm
  825. * - [28, 33]: level5 - 6dBm
  826. * - [20, 27]: level5 - 8dBm
  827. * - [8, 19]: level5 - 11dBm
  828. * - [-128, 7]: level5 - 14dBm
  829. *
  830. * @param power Maximum WiFi transmiting power.
  831. *
  832. * @return
  833. * - ESP_OK: succeed
  834. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  835. * - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
  836. */
  837. esp_err_t esp_wifi_set_max_tx_power(int8_t power);
  838. /**
  839. * @brief Get maximum WiFi transmiting power
  840. *
  841. * @attention This API gets maximum WiFi transmiting power. Values got
  842. * from power are mapped to transmit power levels as follows:
  843. * - 78: 19.5dBm
  844. * - 76: 19dBm
  845. * - 74: 18.5dBm
  846. * - 68: 17dBm
  847. * - 60: 15dBm
  848. * - 52: 13dBm
  849. * - 44: 11dBm
  850. * - 34: 8.5dBm
  851. * - 28: 7dBm
  852. * - 20: 5dBm
  853. * - 8: 2dBm
  854. * - -4: -1dBm
  855. *
  856. * @param power Maximum WiFi transmiting power.
  857. *
  858. * @return
  859. * - ESP_OK: succeed
  860. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  861. * - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
  862. * - ESP_ERR_INVALID_ARG: invalid argument
  863. */
  864. esp_err_t esp_wifi_get_max_tx_power(int8_t *power);
  865. /**
  866. * @brief Set mask to enable or disable some WiFi events
  867. *
  868. * @attention 1. Mask can be created by logical OR of various WIFI_EVENT_MASK_ constants.
  869. * Events which have corresponding bit set in the mask will not be delivered to the system event handler.
  870. * @attention 2. Default WiFi event mask is WIFI_EVENT_MASK_AP_PROBEREQRECVED.
  871. * @attention 3. There may be lots of stations sending probe request data around.
  872. * Don't unmask this event unless you need to receive probe request data.
  873. *
  874. * @param mask WiFi event mask.
  875. *
  876. * @return
  877. * - ESP_OK: succeed
  878. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  879. */
  880. esp_err_t esp_wifi_set_event_mask(uint32_t mask);
  881. /**
  882. * @brief Get mask of WiFi events
  883. *
  884. * @param mask WiFi event mask.
  885. *
  886. * @return
  887. * - ESP_OK: succeed
  888. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  889. * - ESP_ERR_WIFI_ARG: invalid argument
  890. */
  891. esp_err_t esp_wifi_get_event_mask(uint32_t *mask);
  892. /**
  893. * @brief Send raw ieee80211 data
  894. *
  895. * @attention Currently only support for sending beacon/probe request/probe response/action and non-QoS
  896. * data frame
  897. *
  898. * @param ifx interface if the Wi-Fi mode is Station, the ifx should be WIFI_IF_STA. If the Wi-Fi
  899. * mode is SoftAP, the ifx should be WIFI_IF_AP. If the Wi-Fi mode is Station+SoftAP, the
  900. * ifx should be WIFI_IF_STA or WIFI_IF_AP. If the ifx is wrong, the API returns ESP_ERR_WIFI_IF.
  901. * @param buffer raw ieee80211 buffer
  902. * @param len the length of raw buffer, the len must be <= 1500 Bytes and >= 24 Bytes
  903. * @param en_sys_seq indicate whether use the internal sequence number. If en_sys_seq is false, the
  904. * sequence in raw buffer is unchanged, otherwise it will be overwritten by WiFi driver with
  905. * the system sequence number.
  906. * Generally, if esp_wifi_80211_tx is called before the Wi-Fi connection has been set up, both
  907. * en_sys_seq==true and en_sys_seq==false are fine. However, if the API is called after the Wi-Fi
  908. * connection has been set up, en_sys_seq must be true, otherwise ESP_ERR_WIFI_ARG is returned.
  909. *
  910. * @return
  911. * - ESP_OK: success
  912. * - ESP_ERR_WIFI_IF: Invalid interface
  913. * - ESP_ERR_INVALID_ARG: Invalid parameter
  914. * - ESP_ERR_WIFI_NO_MEM: out of memory
  915. */
  916. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  917. /**
  918. * @brief The RX callback function of Channel State Information(CSI) data.
  919. *
  920. * Each time a CSI data is received, the callback function will be called.
  921. *
  922. * @param ctx context argument, passed to esp_wifi_set_csi_rx_cb() when registering callback function.
  923. * @param data CSI data received. The memory that it points to will be deallocated after callback function returns.
  924. *
  925. */
  926. typedef void (* wifi_csi_cb_t)(void *ctx, wifi_csi_info_t *data);
  927. /**
  928. * @brief Register the RX callback function of CSI data.
  929. *
  930. * Each time a CSI data is received, the callback function will be called.
  931. *
  932. * @param cb callback
  933. * @param ctx context argument, passed to callback function
  934. *
  935. * @return
  936. * - ESP_OK: succeed
  937. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  938. */
  939. esp_err_t esp_wifi_set_csi_rx_cb(wifi_csi_cb_t cb, void *ctx);
  940. /**
  941. * @brief Set CSI data configuration
  942. *
  943. * @param config configuration
  944. *
  945. * return
  946. * - ESP_OK: succeed
  947. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  948. * - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
  949. * - ESP_ERR_INVALID_ARG: invalid argument
  950. */
  951. esp_err_t esp_wifi_set_csi_config(const wifi_csi_config_t *config);
  952. /**
  953. * @brief Enable or disable CSI
  954. *
  955. * @param en true - enable, false - disable
  956. *
  957. * return
  958. * - ESP_OK: succeed
  959. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  960. * - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
  961. * - ESP_ERR_INVALID_ARG: invalid argument
  962. */
  963. esp_err_t esp_wifi_set_csi(bool en);
  964. /**
  965. * @brief Set antenna GPIO configuration
  966. *
  967. * @param config Antenna GPIO configuration.
  968. *
  969. * @return
  970. * - ESP_OK: succeed
  971. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  972. * - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid GPIO number etc
  973. */
  974. esp_err_t esp_wifi_set_ant_gpio(const wifi_ant_gpio_config_t *config);
  975. /**
  976. * @brief Get current antenna GPIO configuration
  977. *
  978. * @param config Antenna GPIO configuration.
  979. *
  980. * @return
  981. * - ESP_OK: succeed
  982. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  983. * - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL
  984. */
  985. esp_err_t esp_wifi_get_ant_gpio(wifi_ant_gpio_config_t *config);
  986. /**
  987. * @brief Set antenna configuration
  988. *
  989. * @param config Antenna configuration.
  990. *
  991. * @return
  992. * - ESP_OK: succeed
  993. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  994. * - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid antenna mode or invalid GPIO number
  995. */
  996. esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config);
  997. /**
  998. * @brief Get current antenna configuration
  999. *
  1000. * @param config Antenna configuration.
  1001. *
  1002. * @return
  1003. * - ESP_OK: succeed
  1004. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1005. * - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL
  1006. */
  1007. esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config);
  1008. #ifdef __cplusplus
  1009. }
  1010. #endif
  1011. #endif /* __ESP_WIFI_H__ */