esp_wifi.h 45 KB

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