esp_wifi.h 57 KB

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