esp_wifi.h 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /* Notes about WiFi Programming
  7. *
  8. * The esp32 WiFi programming model can be depicted as following picture:
  9. *
  10. *
  11. * default handler user handler
  12. * ------------- --------------- ---------------
  13. * | | event | | callback or | |
  14. * | tcpip | ---------> | event | ----------> | application |
  15. * | stack | | task | event | task |
  16. * |-----------| |-------------| |-------------|
  17. * /|\ |
  18. * | |
  19. * event | |
  20. * | |
  21. * | |
  22. * --------------- |
  23. * | | |
  24. * | WiFi Driver |/__________________|
  25. * | |\ API call
  26. * | |
  27. * |-------------|
  28. *
  29. * The WiFi driver can be consider as black box, it knows nothing about the high layer code, such as
  30. * TCPIP stack, application task, event task etc, all it can do is to receive API call from high layer
  31. * or post event queue to a specified Queue, which is initialized by API esp_wifi_init().
  32. *
  33. * The event task is a daemon task, which receives events from WiFi driver or from other subsystem, such
  34. * as TCPIP stack, event task will call the default callback function on receiving the event. For example,
  35. * on receiving event WIFI_EVENT_STA_CONNECTED, it will call esp_netif API to start the DHCP
  36. * client in it's default handler.
  37. *
  38. * Application can register it's own event callback function by API esp_event_init, then the application callback
  39. * function will be called after the default callback. Also, if application doesn't want to execute the callback
  40. * in the event task, what it needs to do is to post the related event to application task in the application callback function.
  41. *
  42. * The application task (code) generally mixes all these thing together, it calls APIs to init the system/WiFi and
  43. * handle the events when necessary.
  44. *
  45. */
  46. #ifndef __ESP_WIFI_H__
  47. #define __ESP_WIFI_H__
  48. #include <stdint.h>
  49. #include <stdbool.h>
  50. #include "esp_err.h"
  51. #include "esp_wifi_types.h"
  52. #include "esp_event.h"
  53. #include "esp_private/esp_wifi_private.h"
  54. #if !defined(CONFIG_IDF_RTOS_RTTHREAD) || defined(BSP_USING_BLE)
  55. /*
  56. * 这里由于wifi组件和ble组件使用的不同的lwip库,wifi使用的是RT-Thread所提
  57. * 供的LWIP库,无需使用esp-idf的neiif层;而ble使用的是ESP-IDF所提供的LWIP
  58. * 库(只是依赖,并未使用lwip库进行操作),所以使用了netif层
  59. */
  60. #include "esp_wifi_default.h"
  61. #endif
  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. wifi_osi_funcs_t* osi_funcs; /**< WiFi OS functions */
  90. wpa_crypto_funcs_t wpa_crypto_funcs; /**< WiFi station crypto functions when connect */
  91. int static_rx_buf_num; /**< WiFi static RX buffer number */
  92. int dynamic_rx_buf_num; /**< WiFi dynamic RX buffer number */
  93. int tx_buf_type; /**< WiFi TX buffer type */
  94. int static_tx_buf_num; /**< WiFi static TX buffer number */
  95. int dynamic_tx_buf_num; /**< WiFi dynamic TX buffer number */
  96. int cache_tx_buf_num; /**< WiFi TX cache buffer number */
  97. int csi_enable; /**< WiFi channel state information enable flag */
  98. int ampdu_rx_enable; /**< WiFi AMPDU RX feature enable flag */
  99. int ampdu_tx_enable; /**< WiFi AMPDU TX feature enable flag */
  100. int amsdu_tx_enable; /**< WiFi AMSDU 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. bool sta_disconnected_pm; /**< WiFi Power Management for station at disconnected status */
  109. int magic; /**< WiFi init magic number, it should be the last field */
  110. } wifi_init_config_t;
  111. #ifdef CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM
  112. #define WIFI_STATIC_TX_BUFFER_NUM CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM
  113. #else
  114. #define WIFI_STATIC_TX_BUFFER_NUM 0
  115. #endif
  116. #if (CONFIG_ESP32_SPIRAM_SUPPORT || CONFIG_ESP32S2_SPIRAM_SUPPORT || CONFIG_ESP32S3_SPIRAM_SUPPORT)
  117. #define WIFI_CACHE_TX_BUFFER_NUM CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM
  118. #else
  119. #define WIFI_CACHE_TX_BUFFER_NUM 0
  120. #endif
  121. #ifdef CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM
  122. #define WIFI_DYNAMIC_TX_BUFFER_NUM CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM
  123. #else
  124. #define WIFI_DYNAMIC_TX_BUFFER_NUM 0
  125. #endif
  126. #if CONFIG_ESP32_WIFI_CSI_ENABLED
  127. #define WIFI_CSI_ENABLED 1
  128. #else
  129. #define WIFI_CSI_ENABLED 0
  130. #endif
  131. #if CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED
  132. #define WIFI_AMPDU_RX_ENABLED 1
  133. #else
  134. #define WIFI_AMPDU_RX_ENABLED 0
  135. #endif
  136. #if CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED
  137. #define WIFI_AMPDU_TX_ENABLED 1
  138. #else
  139. #define WIFI_AMPDU_TX_ENABLED 0
  140. #endif
  141. #if CONFIG_ESP32_WIFI_AMSDU_TX_ENABLED
  142. #define WIFI_AMSDU_TX_ENABLED 1
  143. #else
  144. #define WIFI_AMSDU_TX_ENABLED 0
  145. #endif
  146. #if CONFIG_ESP32_WIFI_NVS_ENABLED
  147. #define WIFI_NVS_ENABLED 1
  148. #else
  149. #define WIFI_NVS_ENABLED 0
  150. #endif
  151. #if CONFIG_NEWLIB_NANO_FORMAT
  152. #define WIFI_NANO_FORMAT_ENABLED 1
  153. #else
  154. #define WIFI_NANO_FORMAT_ENABLED 0
  155. #endif
  156. extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
  157. extern uint64_t g_wifi_feature_caps;
  158. #define WIFI_INIT_CONFIG_MAGIC 0x1F2F3F4F
  159. #ifdef CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED
  160. #define WIFI_DEFAULT_RX_BA_WIN CONFIG_ESP32_WIFI_RX_BA_WIN
  161. #else
  162. #define WIFI_DEFAULT_RX_BA_WIN 0 /* unused if ampdu_rx_enable == false */
  163. #endif
  164. #if CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1
  165. #define WIFI_TASK_CORE_ID 1
  166. #else
  167. #define WIFI_TASK_CORE_ID 0
  168. #endif
  169. #ifdef CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN
  170. #define WIFI_SOFTAP_BEACON_MAX_LEN CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN
  171. #else
  172. #define WIFI_SOFTAP_BEACON_MAX_LEN 752
  173. #endif
  174. #ifdef CONFIG_ESP32_WIFI_MGMT_SBUF_NUM
  175. #define WIFI_MGMT_SBUF_NUM CONFIG_ESP32_WIFI_MGMT_SBUF_NUM
  176. #else
  177. #define WIFI_MGMT_SBUF_NUM 32
  178. #endif
  179. #if CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE
  180. #define WIFI_STA_DISCONNECTED_PM_ENABLED true
  181. #else
  182. #define WIFI_STA_DISCONNECTED_PM_ENABLED false
  183. #endif
  184. #define CONFIG_FEATURE_WPA3_SAE_BIT (1<<0)
  185. #define CONFIG_FEATURE_CACHE_TX_BUF_BIT (1<<1)
  186. #define CONFIG_FEATURE_FTM_INITIATOR_BIT (1<<2)
  187. #define CONFIG_FEATURE_FTM_RESPONDER_BIT (1<<3)
  188. #define WIFI_INIT_CONFIG_DEFAULT() { \
  189. .osi_funcs = &g_wifi_osi_funcs, \
  190. .wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
  191. .static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\
  192. .dynamic_rx_buf_num = CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM,\
  193. .tx_buf_type = CONFIG_ESP32_WIFI_TX_BUFFER_TYPE,\
  194. .static_tx_buf_num = WIFI_STATIC_TX_BUFFER_NUM,\
  195. .dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\
  196. .cache_tx_buf_num = WIFI_CACHE_TX_BUFFER_NUM,\
  197. .csi_enable = WIFI_CSI_ENABLED,\
  198. .ampdu_rx_enable = WIFI_AMPDU_RX_ENABLED,\
  199. .ampdu_tx_enable = WIFI_AMPDU_TX_ENABLED,\
  200. .amsdu_tx_enable = WIFI_AMSDU_TX_ENABLED,\
  201. .nvs_enable = WIFI_NVS_ENABLED,\
  202. .nano_enable = WIFI_NANO_FORMAT_ENABLED,\
  203. .rx_ba_win = WIFI_DEFAULT_RX_BA_WIN,\
  204. .wifi_task_core_id = WIFI_TASK_CORE_ID,\
  205. .beacon_max_len = WIFI_SOFTAP_BEACON_MAX_LEN, \
  206. .mgmt_sbuf_num = WIFI_MGMT_SBUF_NUM, \
  207. .feature_caps = g_wifi_feature_caps, \
  208. .sta_disconnected_pm = WIFI_STA_DISCONNECTED_PM_ENABLED, \
  209. .magic = WIFI_INIT_CONFIG_MAGIC\
  210. }
  211. /**
  212. * @brief Initialize WiFi
  213. * Allocate resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
  214. * WiFi NVS structure etc. This WiFi also starts WiFi task
  215. *
  216. * @attention 1. This API must be called before all other WiFi API can be called
  217. * @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to initialize the configuration to default values, this can
  218. * guarantee all the fields get correct value when more fields are added into wifi_init_config_t
  219. * in future release. If you want to set your own initial values, overwrite the default values
  220. * which are set by WIFI_INIT_CONFIG_DEFAULT. Please be notified that the field 'magic' of
  221. * wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC!
  222. *
  223. * @param config pointer to WiFi initialized configuration structure; can point to a temporary variable.
  224. *
  225. * @return
  226. * - ESP_OK: succeed
  227. * - ESP_ERR_NO_MEM: out of memory
  228. * - others: refer to error code esp_err.h
  229. */
  230. esp_err_t esp_wifi_init(const wifi_init_config_t *config);
  231. /**
  232. * @brief Deinit WiFi
  233. * Free all resource allocated in esp_wifi_init and stop WiFi task
  234. *
  235. * @attention 1. This API should be called if you want to remove WiFi driver from the system
  236. *
  237. * @return
  238. * - ESP_OK: succeed
  239. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  240. */
  241. esp_err_t esp_wifi_deinit(void);
  242. /**
  243. * @brief Set the WiFi operating mode
  244. *
  245. * Set the WiFi operating mode as station, soft-AP or station+soft-AP,
  246. * The default mode is station mode.
  247. *
  248. * @param mode WiFi operating mode
  249. *
  250. * @return
  251. * - ESP_OK: succeed
  252. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  253. * - ESP_ERR_INVALID_ARG: invalid argument
  254. * - others: refer to error code in esp_err.h
  255. */
  256. esp_err_t esp_wifi_set_mode(wifi_mode_t mode);
  257. /**
  258. * @brief Get current operating mode of WiFi
  259. *
  260. * @param[out] mode store current WiFi mode
  261. *
  262. * @return
  263. * - ESP_OK: succeed
  264. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  265. * - ESP_ERR_INVALID_ARG: invalid argument
  266. */
  267. esp_err_t esp_wifi_get_mode(wifi_mode_t *mode);
  268. /**
  269. * @brief Start WiFi according to current configuration
  270. * If mode is WIFI_MODE_STA, it create station control block and start station
  271. * If mode is WIFI_MODE_AP, it create soft-AP control block and start soft-AP
  272. * If mode is WIFI_MODE_APSTA, it create soft-AP and station control block and start soft-AP and station
  273. *
  274. * @return
  275. * - ESP_OK: succeed
  276. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  277. * - ESP_ERR_INVALID_ARG: invalid argument
  278. * - ESP_ERR_NO_MEM: out of memory
  279. * - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
  280. * - ESP_FAIL: other WiFi internal errors
  281. */
  282. esp_err_t esp_wifi_start(void);
  283. /**
  284. * @brief Stop WiFi
  285. * If mode is WIFI_MODE_STA, it stop station and free station control block
  286. * If mode is WIFI_MODE_AP, it stop soft-AP and free soft-AP control block
  287. * If mode is WIFI_MODE_APSTA, it stop station/soft-AP and free station/soft-AP control block
  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_stop(void);
  294. /**
  295. * @brief Restore WiFi stack persistent settings to default values
  296. *
  297. * This function will reset settings made using the following APIs:
  298. * - esp_wifi_set_bandwidth,
  299. * - esp_wifi_set_protocol,
  300. * - esp_wifi_set_config related
  301. * - esp_wifi_set_mode
  302. *
  303. * @return
  304. * - ESP_OK: succeed
  305. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  306. */
  307. esp_err_t esp_wifi_restore(void);
  308. /**
  309. * @brief Connect the ESP32 WiFi station to the AP.
  310. *
  311. * @attention 1. This API only impact WIFI_MODE_STA or WIFI_MODE_APSTA mode
  312. * @attention 2. If the ESP32 is connected to an AP, call esp_wifi_disconnect to disconnect.
  313. * @attention 3. The scanning triggered by esp_wifi_scan_start() will not be effective until connection between ESP32 and the AP is established.
  314. * If ESP32 is scanning and connecting at the same time, ESP32 will abort scanning and return a warning message and error
  315. * number ESP_ERR_WIFI_STATE.
  316. * If you want to do reconnection after ESP32 received disconnect event, remember to add the maximum retry time, otherwise the called
  317. * scan will not work. This is especially true when the AP doesn't exist, and you still try reconnection after ESP32 received disconnect
  318. * event with the reason code WIFI_REASON_NO_AP_FOUND.
  319. *
  320. * @return
  321. * - ESP_OK: succeed
  322. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  323. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  324. * - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
  325. * - ESP_ERR_WIFI_SSID: SSID of AP which station connects is invalid
  326. */
  327. esp_err_t esp_wifi_connect(void);
  328. /**
  329. * @brief Disconnect the ESP32 WiFi station from the AP.
  330. *
  331. * @return
  332. * - ESP_OK: succeed
  333. * - ESP_ERR_WIFI_NOT_INIT: WiFi was not initialized by esp_wifi_init
  334. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  335. * - ESP_FAIL: other WiFi internal errors
  336. */
  337. esp_err_t esp_wifi_disconnect(void);
  338. /**
  339. * @brief Currently this API is just an stub API
  340. *
  341. * @return
  342. * - ESP_OK: succeed
  343. * - others: fail
  344. */
  345. esp_err_t esp_wifi_clear_fast_connect(void);
  346. /**
  347. * @brief deauthenticate all stations or associated id equals to aid
  348. *
  349. * @param aid when aid is 0, deauthenticate all stations, otherwise deauthenticate station whose associated id is aid
  350. *
  351. * @return
  352. * - ESP_OK: succeed
  353. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  354. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  355. * - ESP_ERR_INVALID_ARG: invalid argument
  356. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  357. */
  358. esp_err_t esp_wifi_deauth_sta(uint16_t aid);
  359. /**
  360. * @brief Scan all available APs.
  361. *
  362. * @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the
  363. * will be freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause
  364. * the memory to be freed once the scan is done
  365. * @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds.
  366. * Values above 1500ms may cause station to disconnect from AP and are not recommended.
  367. *
  368. * @param config configuration of scanning
  369. * @param block if block is true, this API will block the caller until the scan is done, otherwise
  370. * it will return immediately
  371. *
  372. * @return
  373. * - ESP_OK: succeed
  374. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  375. * - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start
  376. * - ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout
  377. * - ESP_ERR_WIFI_STATE: wifi still connecting when invoke esp_wifi_scan_start
  378. * - others: refer to error code in esp_err.h
  379. */
  380. esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, bool block);
  381. /**
  382. * @brief Stop the scan in process
  383. *
  384. * @return
  385. * - ESP_OK: succeed
  386. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  387. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  388. */
  389. esp_err_t esp_wifi_scan_stop(void);
  390. /**
  391. * @brief Get number of APs found in last scan
  392. *
  393. * @param[out] number store number of APIs found in last scan
  394. *
  395. * @attention This API can only be called when the scan is completed, otherwise it may get wrong value.
  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. */
  403. esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);
  404. /**
  405. * @brief Get AP list found in last scan
  406. *
  407. * @param[inout] number As input param, it stores max AP number ap_records can hold.
  408. * As output param, it receives the actual AP number this API returns.
  409. * @param ap_records wifi_ap_record_t array to hold the found APs
  410. *
  411. * @return
  412. * - ESP_OK: succeed
  413. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  414. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  415. * - ESP_ERR_INVALID_ARG: invalid argument
  416. * - ESP_ERR_NO_MEM: out of memory
  417. */
  418. esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records);
  419. /**
  420. * @brief Clear AP list found in last scan
  421. *
  422. * @attention When the obtained ap list fails,bss info must be cleared,otherwise it may cause memory leakage.
  423. *
  424. * @return
  425. * - ESP_OK: succeed
  426. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  427. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  428. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  429. * - ESP_ERR_INVALID_ARG: invalid argument
  430. */
  431. esp_err_t esp_wifi_clear_ap_list(void);
  432. /**
  433. * @brief Get information of AP which the ESP32 station is associated with
  434. *
  435. * @attention When the obtained country information is empty, it means that the AP does not carry country information
  436. *
  437. * @param ap_info the wifi_ap_record_t to hold AP information
  438. * sta can get the connected ap's phy mode info through the struct member
  439. * phy_11b,phy_11g,phy_11n,phy_lr in the wifi_ap_record_t struct.
  440. * For example, phy_11b = 1 imply that ap support 802.11b mode
  441. *
  442. * @return
  443. * - ESP_OK: succeed
  444. * - ESP_ERR_WIFI_CONN: The station interface don't initialized
  445. * - ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status
  446. */
  447. esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info);
  448. /**
  449. * @brief Set current WiFi power save type
  450. *
  451. * @attention Default power save type is WIFI_PS_MIN_MODEM.
  452. *
  453. * @param type power save type
  454. *
  455. * @return ESP_OK: succeed
  456. */
  457. esp_err_t esp_wifi_set_ps(wifi_ps_type_t type);
  458. /**
  459. * @brief Get current WiFi power save type
  460. *
  461. * @attention Default power save type is WIFI_PS_MIN_MODEM.
  462. *
  463. * @param[out] type: store current power save type
  464. *
  465. * @return ESP_OK: succeed
  466. */
  467. esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type);
  468. /**
  469. * @brief Set protocol type of specified interface
  470. * The default protocol is (WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)
  471. *
  472. * @attention Support 802.11b or 802.11bg or 802.11bgn or LR mode
  473. *
  474. * @param ifx interfaces
  475. * @param protocol_bitmap WiFi protocol bitmap
  476. *
  477. * @return
  478. * - ESP_OK: succeed
  479. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  480. * - ESP_ERR_WIFI_IF: invalid interface
  481. * - others: refer to error codes in esp_err.h
  482. */
  483. esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap);
  484. /**
  485. * @brief Get the current protocol bitmap of the specified interface
  486. *
  487. * @param ifx interface
  488. * @param[out] protocol_bitmap store current WiFi protocol bitmap of interface ifx
  489. *
  490. * @return
  491. * - ESP_OK: succeed
  492. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  493. * - ESP_ERR_WIFI_IF: invalid interface
  494. * - ESP_ERR_INVALID_ARG: invalid argument
  495. * - others: refer to error codes in esp_err.h
  496. */
  497. esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap);
  498. /**
  499. * @brief Set the bandwidth of ESP32 specified interface
  500. *
  501. * @attention 1. API return false if try to configure an interface that is not enabled
  502. * @attention 2. WIFI_BW_HT40 is supported only when the interface support 11N
  503. *
  504. * @param ifx interface to be configured
  505. * @param bw bandwidth
  506. *
  507. * @return
  508. * - ESP_OK: succeed
  509. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  510. * - ESP_ERR_WIFI_IF: invalid interface
  511. * - ESP_ERR_INVALID_ARG: invalid argument
  512. * - others: refer to error codes in esp_err.h
  513. */
  514. esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw);
  515. /**
  516. * @brief Get the bandwidth of ESP32 specified interface
  517. *
  518. * @attention 1. API return false if try to get a interface that is not enable
  519. *
  520. * @param ifx interface to be configured
  521. * @param[out] bw store bandwidth of interface ifx
  522. *
  523. * @return
  524. * - ESP_OK: succeed
  525. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  526. * - ESP_ERR_WIFI_IF: invalid interface
  527. * - ESP_ERR_INVALID_ARG: invalid argument
  528. */
  529. esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw);
  530. /**
  531. * @brief Set primary/secondary channel of ESP32
  532. *
  533. * @attention 1. This API should be called after esp_wifi_start()
  534. * @attention 2. When ESP32 is in STA mode, this API should not be called when STA is scanning or connecting to an external AP
  535. * @attention 3. When ESP32 is in softAP mode, this API should not be called when softAP has connected to external STAs
  536. * @attention 4. When ESP32 is in STA+softAP mode, this API should not be called when in the scenarios described above
  537. *
  538. * @param primary for HT20, primary is the channel number, for HT40, primary is the primary channel
  539. * @param second for HT20, second is ignored, for HT40, second is the second channel
  540. *
  541. * @return
  542. * - ESP_OK: succeed
  543. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  544. * - ESP_ERR_WIFI_IF: invalid interface
  545. * - ESP_ERR_INVALID_ARG: invalid argument
  546. */
  547. esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second);
  548. /**
  549. * @brief Get the primary/secondary channel of ESP32
  550. *
  551. * @attention 1. API return false if try to get a interface that is not enable
  552. *
  553. * @param primary store current primary channel
  554. * @param[out] second store current second channel
  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_get_channel(uint8_t *primary, wifi_second_chan_t *second);
  562. /**
  563. * @brief configure country info
  564. *
  565. * @attention 1. It is discouraged to call this API since this doesn't validate the per-country rules,
  566. * it's up to the user to fill in all fields according to local regulations.
  567. * Please use esp_wifi_set_country_code instead.
  568. * @attention 2. The default country is CHINA {.cc="CN", .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO}
  569. * @attention 3. When the country policy is WIFI_COUNTRY_POLICY_AUTO, the country info of the AP to which
  570. * the station is connected is used. E.g. if the configured country info is {.cc="USA", .schan=1, .nchan=11}
  571. * and the country info of the AP to which the station is connected is {.cc="JP", .schan=1, .nchan=14}
  572. * then the country info that will be used is {.cc="JP", .schan=1, .nchan=14}. If the station disconnected
  573. * from the AP the country info is set back to the country info of the station automatically,
  574. * {.cc="US", .schan=1, .nchan=11} in the example.
  575. * @attention 4. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, then the configured country info is used always.
  576. * @attention 5. When the country info is changed because of configuration or because the station connects to a different
  577. * external AP, the country IE in probe response/beacon of the soft-AP is also changed.
  578. * @attention 6. The country configuration is stored into flash.
  579. * @attention 7. When this API is called, the PHY init data will switch to the PHY init data type corresponding to the
  580. * country info.
  581. *
  582. * @param country the configured country info
  583. *
  584. * @return
  585. * - ESP_OK: succeed
  586. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  587. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  588. * - ESP_ERR_INVALID_ARG: invalid argument
  589. */
  590. esp_err_t esp_wifi_set_country(const wifi_country_t *country);
  591. /**
  592. * @brief get the current country info
  593. *
  594. * @param country country info
  595. *
  596. * @return
  597. * - ESP_OK: succeed
  598. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  599. * - ESP_ERR_INVALID_ARG: invalid argument
  600. */
  601. esp_err_t esp_wifi_get_country(wifi_country_t *country);
  602. /**
  603. * @brief Set MAC address of the ESP32 WiFi station or the soft-AP interface.
  604. *
  605. * @attention 1. This API can only be called when the interface is disabled
  606. * @attention 2. ESP32 soft-AP and station have different MAC addresses, do not set them to be the same.
  607. * @attention 3. The bit 0 of the first byte of ESP32 MAC address can not be 1. For example, the MAC address
  608. * can set to be "1a:XX:XX:XX:XX:XX", but can not be "15:XX:XX:XX:XX:XX".
  609. *
  610. * @param ifx interface
  611. * @param mac the MAC address
  612. *
  613. * @return
  614. * - ESP_OK: succeed
  615. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  616. * - ESP_ERR_INVALID_ARG: invalid argument
  617. * - ESP_ERR_WIFI_IF: invalid interface
  618. * - ESP_ERR_WIFI_MAC: invalid mac address
  619. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  620. * - others: refer to error codes in esp_err.h
  621. */
  622. esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, const uint8_t mac[6]);
  623. /**
  624. * @brief Get mac of specified interface
  625. *
  626. * @param ifx interface
  627. * @param[out] mac store mac of the interface ifx
  628. *
  629. * @return
  630. * - ESP_OK: succeed
  631. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  632. * - ESP_ERR_INVALID_ARG: invalid argument
  633. * - ESP_ERR_WIFI_IF: invalid interface
  634. */
  635. esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]);
  636. /**
  637. * @brief The RX callback function in the promiscuous mode.
  638. * Each time a packet is received, the callback function will be called.
  639. *
  640. * @param buf Data received. Type of data in buffer (wifi_promiscuous_pkt_t or wifi_pkt_rx_ctrl_t) indicated by 'type' parameter.
  641. * @param type promiscuous packet type.
  642. *
  643. */
  644. typedef void (* wifi_promiscuous_cb_t)(void *buf, wifi_promiscuous_pkt_type_t type);
  645. /**
  646. * @brief Register the RX callback function in the promiscuous mode.
  647. *
  648. * Each time a packet is received, the registered callback function will be called.
  649. *
  650. * @param cb callback
  651. *
  652. * @return
  653. * - ESP_OK: succeed
  654. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  655. */
  656. esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
  657. /**
  658. * @brief Enable the promiscuous mode.
  659. *
  660. * @param en false - disable, true - enable
  661. *
  662. * @return
  663. * - ESP_OK: succeed
  664. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  665. */
  666. esp_err_t esp_wifi_set_promiscuous(bool en);
  667. /**
  668. * @brief Get the promiscuous mode.
  669. *
  670. * @param[out] en store the current status of promiscuous mode
  671. *
  672. * @return
  673. * - ESP_OK: succeed
  674. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  675. * - ESP_ERR_INVALID_ARG: invalid argument
  676. */
  677. esp_err_t esp_wifi_get_promiscuous(bool *en);
  678. /**
  679. * @brief Enable the promiscuous mode packet type filter.
  680. *
  681. * @note The default filter is to filter all packets except WIFI_PKT_MISC
  682. *
  683. * @param filter the packet type filtered in promiscuous mode.
  684. *
  685. * @return
  686. * - ESP_OK: succeed
  687. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  688. */
  689. esp_err_t esp_wifi_set_promiscuous_filter(const wifi_promiscuous_filter_t *filter);
  690. /**
  691. * @brief Get the promiscuous filter.
  692. *
  693. * @param[out] filter store the current status of promiscuous filter
  694. *
  695. * @return
  696. * - ESP_OK: succeed
  697. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  698. * - ESP_ERR_INVALID_ARG: invalid argument
  699. */
  700. esp_err_t esp_wifi_get_promiscuous_filter(wifi_promiscuous_filter_t *filter);
  701. /**
  702. * @brief Enable subtype filter of the control packet in promiscuous mode.
  703. *
  704. * @note The default filter is to filter none control packet.
  705. *
  706. * @param filter the subtype of the control packet filtered in promiscuous mode.
  707. *
  708. * @return
  709. * - ESP_OK: succeed
  710. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  711. */
  712. esp_err_t esp_wifi_set_promiscuous_ctrl_filter(const wifi_promiscuous_filter_t *filter);
  713. /**
  714. * @brief Get the subtype filter of the control packet in promiscuous mode.
  715. *
  716. * @param[out] filter store the current status of subtype filter of the control packet in promiscuous mode
  717. *
  718. * @return
  719. * - ESP_OK: succeed
  720. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  721. * - ESP_ERR_WIFI_ARG: invalid argument
  722. */
  723. esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter);
  724. /**
  725. * @brief Set the configuration of the ESP32 STA or AP
  726. *
  727. * @attention 1. This API can be called only when specified interface is enabled, otherwise, API fail
  728. * @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.
  729. * @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
  730. * the channel of the ESP32 station.
  731. *
  732. * @param interface interface
  733. * @param conf station or soft-AP configuration
  734. *
  735. * @return
  736. * - ESP_OK: succeed
  737. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  738. * - ESP_ERR_INVALID_ARG: invalid argument
  739. * - ESP_ERR_WIFI_IF: invalid interface
  740. * - ESP_ERR_WIFI_MODE: invalid mode
  741. * - ESP_ERR_WIFI_PASSWORD: invalid password
  742. * - ESP_ERR_WIFI_NVS: WiFi internal NVS error
  743. * - others: refer to the erro code in esp_err.h
  744. */
  745. esp_err_t esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf);
  746. /**
  747. * @brief Get configuration of specified interface
  748. *
  749. * @param interface interface
  750. * @param[out] conf station or soft-AP configuration
  751. *
  752. * @return
  753. * - ESP_OK: succeed
  754. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  755. * - ESP_ERR_INVALID_ARG: invalid argument
  756. * - ESP_ERR_WIFI_IF: invalid interface
  757. */
  758. esp_err_t esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf);
  759. /**
  760. * @brief Get STAs associated with soft-AP
  761. *
  762. * @attention SSC only API
  763. *
  764. * @param[out] sta station list
  765. * ap can get the connected sta's phy mode info through the struct member
  766. * phy_11b,phy_11g,phy_11n,phy_lr in the wifi_sta_info_t struct.
  767. * For example, phy_11b = 1 imply that sta support 802.11b mode
  768. *
  769. * @return
  770. * - ESP_OK: succeed
  771. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  772. * - ESP_ERR_INVALID_ARG: invalid argument
  773. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  774. * - ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid
  775. */
  776. esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta);
  777. /**
  778. * @brief Get AID of STA connected with soft-AP
  779. *
  780. * @param mac STA's mac address
  781. * @param[out] aid Store the AID corresponding to STA mac
  782. *
  783. * @return
  784. * - ESP_OK: succeed
  785. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  786. * - ESP_ERR_INVALID_ARG: invalid argument
  787. * - ESP_ERR_NOT_FOUND: Requested resource not found
  788. * - ESP_ERR_WIFI_MODE: WiFi mode is wrong
  789. * - ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid
  790. */
  791. esp_err_t esp_wifi_ap_get_sta_aid(const uint8_t mac[6], uint16_t *aid);
  792. /**
  793. * @brief Set the WiFi API configuration storage type
  794. *
  795. * @attention 1. The default value is WIFI_STORAGE_FLASH
  796. *
  797. * @param storage : storage type
  798. *
  799. * @return
  800. * - ESP_OK: succeed
  801. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  802. * - ESP_ERR_INVALID_ARG: invalid argument
  803. */
  804. esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
  805. /**
  806. * @brief Function signature for received Vendor-Specific Information Element callback.
  807. * @param ctx Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback.
  808. * @param type Information element type, based on frame type received.
  809. * @param sa Source 802.11 address.
  810. * @param vnd_ie Pointer to the vendor specific element data received.
  811. * @param rssi Received signal strength indication.
  812. */
  813. 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);
  814. /**
  815. * @brief Set 802.11 Vendor-Specific Information Element
  816. *
  817. * @param enable If true, specified IE is enabled. If false, specified IE is removed.
  818. * @param type Information Element type. Determines the frame type to associate with the IE.
  819. * @param idx Index to set or clear. Each IE type can be associated with up to two elements (indices 0 & 1).
  820. * @param vnd_ie Pointer to vendor specific element data. First 6 bytes should be a header with fields matching vendor_ie_data_t.
  821. * If enable is false, this argument is ignored and can be NULL. Data does not need to remain valid after the function returns.
  822. *
  823. * @return
  824. * - ESP_OK: succeed
  825. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init()
  826. * - ESP_ERR_INVALID_ARG: Invalid argument, including if first byte of vnd_ie is not WIFI_VENDOR_IE_ELEMENT_ID (0xDD)
  827. * or second byte is an invalid length.
  828. * - ESP_ERR_NO_MEM: Out of memory
  829. */
  830. 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);
  831. /**
  832. * @brief Register Vendor-Specific Information Element monitoring callback.
  833. *
  834. * @param cb Callback function
  835. * @param ctx Context argument, passed to callback function.
  836. *
  837. * @return
  838. * - ESP_OK: succeed
  839. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  840. */
  841. esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
  842. /**
  843. * @brief Set maximum transmitting power after WiFi start.
  844. *
  845. * @attention 1. Maximum power before wifi startup is limited by PHY init data bin.
  846. * @attention 2. The value set by this API will be mapped to the max_tx_power of the structure wifi_country_t variable.
  847. * @attention 3. Mapping Table {Power, max_tx_power} = {{8, 2}, {20, 5}, {28, 7}, {34, 8}, {44, 11},
  848. * {52, 13}, {56, 14}, {60, 15}, {66, 16}, {72, 18}, {80, 20}}.
  849. * @attention 4. Param power unit is 0.25dBm, range is [8, 84] corresponding to 2dBm - 20dBm.
  850. * @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}}.
  851. *
  852. * @param power Maximum WiFi transmitting power.
  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_STARTED: WiFi is not started by esp_wifi_start
  858. * - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is out of range
  859. */
  860. esp_err_t esp_wifi_set_max_tx_power(int8_t power);
  861. /**
  862. * @brief Get maximum transmiting power after WiFi start
  863. *
  864. * @param power Maximum WiFi transmitting power, unit is 0.25dBm.
  865. *
  866. * @return
  867. * - ESP_OK: succeed
  868. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  869. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  870. * - ESP_ERR_WIFI_ARG: invalid argument
  871. */
  872. esp_err_t esp_wifi_get_max_tx_power(int8_t *power);
  873. /**
  874. * @brief Set mask to enable or disable some WiFi events
  875. *
  876. * @attention 1. Mask can be created by logical OR of various WIFI_EVENT_MASK_ constants.
  877. * Events which have corresponding bit set in the mask will not be delivered to the system event handler.
  878. * @attention 2. Default WiFi event mask is WIFI_EVENT_MASK_AP_PROBEREQRECVED.
  879. * @attention 3. There may be lots of stations sending probe request data around.
  880. * Don't unmask this event unless you need to receive probe request data.
  881. *
  882. * @param mask WiFi event mask.
  883. *
  884. * @return
  885. * - ESP_OK: succeed
  886. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  887. */
  888. esp_err_t esp_wifi_set_event_mask(uint32_t mask);
  889. /**
  890. * @brief Get mask of WiFi events
  891. *
  892. * @param mask WiFi event mask.
  893. *
  894. * @return
  895. * - ESP_OK: succeed
  896. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  897. * - ESP_ERR_WIFI_ARG: invalid argument
  898. */
  899. esp_err_t esp_wifi_get_event_mask(uint32_t *mask);
  900. /**
  901. * @brief Send raw ieee80211 data
  902. *
  903. * @attention Currently only support for sending beacon/probe request/probe response/action and non-QoS
  904. * data frame
  905. *
  906. * @param ifx interface if the Wi-Fi mode is Station, the ifx should be WIFI_IF_STA. If the Wi-Fi
  907. * mode is SoftAP, the ifx should be WIFI_IF_AP. If the Wi-Fi mode is Station+SoftAP, the
  908. * ifx should be WIFI_IF_STA or WIFI_IF_AP. If the ifx is wrong, the API returns ESP_ERR_WIFI_IF.
  909. * @param buffer raw ieee80211 buffer
  910. * @param len the length of raw buffer, the len must be <= 1500 Bytes and >= 24 Bytes
  911. * @param en_sys_seq indicate whether use the internal sequence number. If en_sys_seq is false, the
  912. * sequence in raw buffer is unchanged, otherwise it will be overwritten by WiFi driver with
  913. * the system sequence number.
  914. * Generally, if esp_wifi_80211_tx is called before the Wi-Fi connection has been set up, both
  915. * en_sys_seq==true and en_sys_seq==false are fine. However, if the API is called after the Wi-Fi
  916. * connection has been set up, en_sys_seq must be true, otherwise ESP_ERR_WIFI_ARG is returned.
  917. *
  918. * @return
  919. * - ESP_OK: success
  920. * - ESP_ERR_WIFI_IF: Invalid interface
  921. * - ESP_ERR_INVALID_ARG: Invalid parameter
  922. * - ESP_ERR_WIFI_NO_MEM: out of memory
  923. */
  924. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  925. /**
  926. * @brief The RX callback function of Channel State Information(CSI) data.
  927. *
  928. * Each time a CSI data is received, the callback function will be called.
  929. *
  930. * @param ctx context argument, passed to esp_wifi_set_csi_rx_cb() when registering callback function.
  931. * @param data CSI data received. The memory that it points to will be deallocated after callback function returns.
  932. *
  933. */
  934. typedef void (* wifi_csi_cb_t)(void *ctx, wifi_csi_info_t *data);
  935. /**
  936. * @brief Register the RX callback function of CSI data.
  937. *
  938. * Each time a CSI data is received, the callback function will be called.
  939. *
  940. * @param cb callback
  941. * @param ctx context argument, passed to callback function
  942. *
  943. * @return
  944. * - ESP_OK: succeed
  945. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  946. */
  947. esp_err_t esp_wifi_set_csi_rx_cb(wifi_csi_cb_t cb, void *ctx);
  948. /**
  949. * @brief Set CSI data configuration
  950. *
  951. * @param config configuration
  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_STARTED: 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_config(const wifi_csi_config_t *config);
  960. /**
  961. * @brief Enable or disable CSI
  962. *
  963. * @param en true - enable, false - disable
  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_NOT_STARTED: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
  969. * - ESP_ERR_INVALID_ARG: invalid argument
  970. */
  971. esp_err_t esp_wifi_set_csi(bool en);
  972. /**
  973. * @brief Set antenna GPIO configuration
  974. *
  975. * @param config Antenna GPIO configuration.
  976. *
  977. * @return
  978. * - ESP_OK: succeed
  979. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  980. * - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid GPIO number etc
  981. */
  982. esp_err_t esp_wifi_set_ant_gpio(const wifi_ant_gpio_config_t *config);
  983. /**
  984. * @brief Get current antenna GPIO configuration
  985. *
  986. * @param config Antenna GPIO configuration.
  987. *
  988. * @return
  989. * - ESP_OK: succeed
  990. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  991. * - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL
  992. */
  993. esp_err_t esp_wifi_get_ant_gpio(wifi_ant_gpio_config_t *config);
  994. /**
  995. * @brief Set antenna configuration
  996. *
  997. * @param config Antenna configuration.
  998. *
  999. * @return
  1000. * - ESP_OK: succeed
  1001. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1002. * - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid antenna mode or invalid GPIO number
  1003. */
  1004. esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config);
  1005. /**
  1006. * @brief Get current antenna configuration
  1007. *
  1008. * @param config Antenna configuration.
  1009. *
  1010. * @return
  1011. * - ESP_OK: succeed
  1012. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1013. * - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL
  1014. */
  1015. esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config);
  1016. /**
  1017. * @brief Get the TSF time
  1018. * In Station mode or SoftAP+Station mode if station is not connected or station doesn't receive at least
  1019. * one beacon after connected, will return 0
  1020. *
  1021. * @attention Enabling power save may cause the return value inaccurate, except WiFi modem sleep
  1022. *
  1023. * @param interface The interface whose tsf_time is to be retrieved.
  1024. *
  1025. * @return 0 or the TSF time
  1026. */
  1027. int64_t esp_wifi_get_tsf_time(wifi_interface_t interface);
  1028. /**
  1029. * @brief Set the inactive time of the ESP32 STA or AP
  1030. *
  1031. * @attention 1. For Station, If the station does not receive a beacon frame from the connected SoftAP during the inactive time,
  1032. * disconnect from SoftAP. Default 6s.
  1033. * @attention 2. For SoftAP, If the softAP doesn't receive any data from the connected STA during inactive time,
  1034. * the softAP will force deauth the STA. Default is 300s.
  1035. * @attention 3. The inactive time configuration is not stored into flash
  1036. *
  1037. * @param ifx interface to be configured.
  1038. * @param sec Inactive time. Unit seconds.
  1039. *
  1040. * @return
  1041. * - ESP_OK: succeed
  1042. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1043. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  1044. * - ESP_ERR_WIFI_ARG: invalid argument, For Station, if sec is less than 3. For SoftAP, if sec is less than 10.
  1045. */
  1046. esp_err_t esp_wifi_set_inactive_time(wifi_interface_t ifx, uint16_t sec);
  1047. /**
  1048. * @brief Get inactive time of specified interface
  1049. *
  1050. * @param ifx Interface to be configured.
  1051. * @param sec Inactive time. Unit seconds.
  1052. *
  1053. * @return
  1054. * - ESP_OK: succeed
  1055. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1056. * - ESP_ERR_WIFI_ARG: invalid argument
  1057. */
  1058. esp_err_t esp_wifi_get_inactive_time(wifi_interface_t ifx, uint16_t *sec);
  1059. /**
  1060. * @brief Dump WiFi statistics
  1061. *
  1062. * @param modules statistic modules to be dumped
  1063. *
  1064. * @return
  1065. * - ESP_OK: succeed
  1066. * - others: failed
  1067. */
  1068. esp_err_t esp_wifi_statis_dump(uint32_t modules);
  1069. /**
  1070. * @brief Set RSSI threshold below which APP will get an event
  1071. *
  1072. * @attention This API needs to be called every time after WIFI_EVENT_STA_BSS_RSSI_LOW event is received.
  1073. *
  1074. * @param rssi threshold value in dbm between -100 to 0
  1075. *
  1076. * @return
  1077. * - ESP_OK: succeed
  1078. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1079. * - ESP_ERR_WIFI_ARG: invalid argument
  1080. */
  1081. esp_err_t esp_wifi_set_rssi_threshold(int32_t rssi);
  1082. /**
  1083. * @brief Start an FTM Initiator session by sending FTM request
  1084. * If successful, event WIFI_EVENT_FTM_REPORT is generated with the result of the FTM procedure
  1085. *
  1086. * @attention Use this API only in Station mode
  1087. *
  1088. * @param cfg FTM Initiator session configuration
  1089. *
  1090. * @return
  1091. * - ESP_OK: succeed
  1092. * - others: failed
  1093. */
  1094. esp_err_t esp_wifi_ftm_initiate_session(wifi_ftm_initiator_cfg_t *cfg);
  1095. /**
  1096. * @brief End the ongoing FTM Initiator session
  1097. *
  1098. * @attention This API works only on FTM Initiator
  1099. *
  1100. * @return
  1101. * - ESP_OK: succeed
  1102. * - others: failed
  1103. */
  1104. esp_err_t esp_wifi_ftm_end_session(void);
  1105. /**
  1106. * @brief Set offset in cm for FTM Responder. An equivalent offset is calculated in picoseconds
  1107. * and added in TOD of FTM Measurement frame (T1).
  1108. *
  1109. * @attention Use this API only in AP mode before performing FTM as responder
  1110. *
  1111. * @param offset_cm T1 Offset to be added in centimeters
  1112. *
  1113. * @return
  1114. * - ESP_OK: succeed
  1115. * - others: failed
  1116. */
  1117. esp_err_t esp_wifi_ftm_resp_set_offset(int16_t offset_cm);
  1118. /**
  1119. * @brief Enable or disable 11b rate of specified interface
  1120. *
  1121. * @attention 1. This API should be called after esp_wifi_init() and before esp_wifi_start().
  1122. * @attention 2. Only when really need to disable 11b rate call this API otherwise don't call this.
  1123. *
  1124. * @param ifx Interface to be configured.
  1125. * @param disable true means disable 11b rate while false means enable 11b rate.
  1126. *
  1127. * @return
  1128. * - ESP_OK: succeed
  1129. * - others: failed
  1130. */
  1131. esp_err_t esp_wifi_config_11b_rate(wifi_interface_t ifx, bool disable);
  1132. /**
  1133. * @brief Set wake interval for connectionless modules to wake up periodically.
  1134. *
  1135. * @attention 1. Only one wake interval for all connectionless modules.
  1136. * @attention 2. This configuration could work at connected status.
  1137. * When ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is enabled, this configuration could work at disconnected status.
  1138. * @attention 3. Event WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START would be posted each time wake interval starts.
  1139. * @attention 4. Recommend to configure interval in multiples of hundred. (e.g. 100ms)
  1140. *
  1141. * @param wake_interval Milliseconds after would the chip wake up, from 1 to 65535.
  1142. */
  1143. esp_err_t esp_wifi_connectionless_module_set_wake_interval(uint16_t wake_interval);
  1144. /**
  1145. * @brief configure country
  1146. *
  1147. * @attention 1. When ieee80211d_enabled, the country info of the AP to which
  1148. * the station is connected is used. E.g. if the configured country is US
  1149. * and the country info of the AP to which the station is connected is JP
  1150. * then the country info that will be used is JP. If the station disconnected
  1151. * from the AP the country info is set back to the country info of the station automatically,
  1152. * US in the example.
  1153. * @attention 2. When ieee80211d_enabled is disabled, then the configured country info is used always.
  1154. * @attention 3. When the country info is changed because of configuration or because the station connects to a different
  1155. * external AP, the country IE in probe response/beacon of the soft-AP is also changed.
  1156. * @attention 4. The country configuration is stored into flash.
  1157. * @attention 5. When this API is called, the PHY init data will switch to the PHY init data type corresponding to the
  1158. * country info.
  1159. * @attention 6. Supported country codes are "01"(world safe mode) "AT","AU","BE","BG","BR",
  1160. * "CA","CH","CN","CY","CZ","DE","DK","EE","ES","FI","FR","GB","GR","HK","HR","HU",
  1161. * "IE","IN","IS","IT","JP","KR","LI","LT","LU","LV","MT","MX","NL","NO","NZ","PL","PT",
  1162. * "RO","SE","SI","SK","TW","US"
  1163. *
  1164. * @attention 7. When country code "01" (world safe mode) is set, SoftAP mode won't contain country IE.
  1165. * @attention 8. The default country is "01" (world safe mode) and ieee80211d_enabled is TRUE.
  1166. *
  1167. * @param country the configured country ISO code
  1168. * @param ieee80211d_enabled 802.11d is enabled or not
  1169. *
  1170. * @return
  1171. * - ESP_OK: succeed
  1172. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1173. * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
  1174. * - ESP_ERR_INVALID_ARG: invalid argument
  1175. */
  1176. esp_err_t esp_wifi_set_country_code(const char *country, bool ieee80211d_enabled);
  1177. /**
  1178. * @brief get the current country code
  1179. *
  1180. * @param country country code
  1181. *
  1182. * @return
  1183. * - ESP_OK: succeed
  1184. * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
  1185. * - ESP_ERR_INVALID_ARG: invalid argument
  1186. */
  1187. esp_err_t esp_wifi_get_country_code(char *country);
  1188. /**
  1189. * @brief Config 80211 tx rate of specified interface
  1190. *
  1191. * @attention 1. This API should be called after esp_wifi_init() and before esp_wifi_start().
  1192. *
  1193. * @param ifx Interface to be configured.
  1194. * @param rate Phy rate to be configured.
  1195. *
  1196. * @return
  1197. * - ESP_OK: succeed
  1198. * - others: failed
  1199. */
  1200. esp_err_t esp_wifi_config_80211_tx_rate(wifi_interface_t ifx, wifi_phy_rate_t rate);
  1201. /**
  1202. * @brief Disable PMF configuration for specified interface
  1203. *
  1204. * @attention This API should be called after esp_wifi_set_config() and before esp_wifi_start().
  1205. *
  1206. * @param ifx Interface to be configured.
  1207. *
  1208. * @return
  1209. * - ESP_OK: succeed
  1210. * - others: failed
  1211. */
  1212. esp_err_t esp_wifi_disable_pmf_config(wifi_interface_t ifx);
  1213. #ifdef __cplusplus
  1214. }
  1215. #endif
  1216. #endif /* __ESP_WIFI_H__ */