esp_wifi.h 45 KB

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