esp_wifi.h 51 KB

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