wifi.rst 173 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710
  1. Wi-Fi Driver
  2. =============
  3. :link_to_translation:`zh_CN:[中文]`
  4. {IDF_TARGET_MAX_CONN_STA_NUM:default="15", esp32c2="4", esp32c3="10", esp32c6="10"}
  5. {IDF_TARGET_SUB_MAX_NUM_FROM_KEYS:default="2", esp32c3="7", esp32c6="7"}
  6. {IDF_TARGET_NAME} Wi-Fi Feature List
  7. ------------------------------------
  8. The following features are supported:
  9. .. only:: esp32 or esp32s2 or esp32c3 or esp32s3
  10. - 4 virtual Wi-Fi interfaces, which are STA, AP, Sniffer and reserved.
  11. - Station-only mode, AP-only mode, station/AP-coexistence mode
  12. - IEEE 802.11b, IEEE 802.11g, IEEE 802.11n, and APIs to configure the protocol mode
  13. - WPA/WPA2/WPA3/WPA2-Enterprise/WPA3-Enterprise/WAPI/WPS and DPP
  14. - AMSDU, AMPDU, HT40, QoS, and other key features
  15. - Modem-sleep
  16. - The Espressif-specific ESP-NOW protocol and Long Range mode, which supports up to **1 km** of data traffic
  17. - Up to 20 MBit/s TCP throughput and 30 MBit/s UDP throughput over the air
  18. - Sniffer
  19. - Both fast scan and all-channel scan
  20. - Multiple antennas
  21. - Channel state information
  22. .. only:: SOC_WIFI_NAN_SUPPORT
  23. - Wi-Fi Aware (NAN)
  24. .. only:: esp32c6
  25. - 4 virtual Wi-Fi interfaces, which are STA, AP, Sniffer and reserved.
  26. - Station-only mode, AP-only mode, station/AP-coexistence mode
  27. - IEEE 802.11b, IEEE 802.11g, IEEE 802.11n, IEEE 802.11ax, and APIs to configure the protocol mode
  28. - WPA/WPA2/WPA3/WPA2-Enterprise/WPA3-Enterprise/WAPI/WPS and DPP
  29. - AMSDU, AMPDU, HT40, QoS, and other key features
  30. - Modem-sleep
  31. - The Espressif-specific ESP-NOW protocol and Long Range mode, which supports up to **1 km** of data traffic
  32. - Up to 20 MBit/s TCP throughput and 30 MBit/s UDP throughput over the air
  33. - Sniffer
  34. - Both fast scan and all-channel scan
  35. - Multiple antennas
  36. - Channel state information
  37. - TWT
  38. - Downlink MU-MIMO
  39. - OFDMA
  40. - BSS Color
  41. .. only:: esp32c2
  42. - 3 virtual Wi-Fi interfaces, which are STA, AP and Sniffer.
  43. - Station-only mode, AP-only mode, station/AP-coexistence mode
  44. - IEEE 802.11b, IEEE 802.11g, IEEE 802.11n, and APIs to configure the protocol mode
  45. - WPA/WPA2/WPA3/WPA2-Enterprise/WPA3-Enterprise/WPS and DPP
  46. - AMPDU, QoS, and other key features
  47. - Modem-sleep
  48. - Up to 20 MBit/s TCP throughput and 30 MBit/s UDP throughput over the air
  49. - Sniffer
  50. - Both fast scan and all-channel scan
  51. - Multiple antennas
  52. How To Write a Wi-Fi Application
  53. ----------------------------------
  54. Preparation
  55. +++++++++++
  56. Generally, the most effective way to begin your own Wi-Fi application is to select an example which is similar to your own application, and port the useful part into your project. It is not a MUST, but it is strongly recommended that you take some time to read this article first, especially if you want to program a robust Wi-Fi application.
  57. This article is supplementary to the Wi-Fi APIs/Examples. It describes the principles of using the Wi-Fi APIs, the limitations of the current Wi-Fi API implementation, and the most common pitfalls in using Wi-Fi. This article also reveals some design details of the Wi-Fi driver. We recommend you to select an :example:`example <wifi>`.
  58. Setting Wi-Fi Compile-time Options
  59. ++++++++++++++++++++++++++++++++++++
  60. Refer to `Wi-Fi Menuconfig`_.
  61. Init Wi-Fi
  62. +++++++++++
  63. Refer to `{IDF_TARGET_NAME} Wi-Fi station General Scenario`_ and `{IDF_TARGET_NAME} Wi-Fi AP General Scenario`_.
  64. Start/Connect Wi-Fi
  65. ++++++++++++++++++++
  66. Refer to `{IDF_TARGET_NAME} Wi-Fi station General Scenario`_ and `{IDF_TARGET_NAME} Wi-Fi AP General Scenario`_.
  67. Event-Handling
  68. ++++++++++++++
  69. Generally, it is easy to write code in "sunny-day" scenarios, such as `WIFI_EVENT_STA_START`_ and `WIFI_EVENT_STA_CONNECTED`_. The hard part is to write routines in "rainy-day" scenarios, such as `WIFI_EVENT_STA_DISCONNECTED`_. Good handling of "rainy-day" scenarios is fundamental to robust Wi-Fi applications. Refer to `{IDF_TARGET_NAME} Wi-Fi Event Description`_, `{IDF_TARGET_NAME} Wi-Fi station General Scenario`_, and `{IDF_TARGET_NAME} Wi-Fi AP General Scenario`_. See also the :doc:`overview of the Event Loop Library in ESP-IDF <../api-reference/system/esp_event>`.
  70. Write Error-Recovery Routines Correctly at All Times
  71. ++++++++++++++++++++++++++++++++++++++++++++++++++++
  72. Just like the handling of "rainy-day" scenarios, a good error-recovery routine is also fundamental to robust Wi-Fi applications. Refer to `{IDF_TARGET_NAME} Wi-Fi API Error Code`_.
  73. {IDF_TARGET_NAME} Wi-Fi API Error Code
  74. --------------------------------------
  75. All of the {IDF_TARGET_NAME} Wi-Fi APIs have well-defined return values, namely, the error code. The error code can be categorized into:
  76. - No errors, e.g., :c:macro:`ESP_OK` means that the API returns successfully.
  77. - Recoverable errors, such as :c:macro:`ESP_ERR_NO_MEM`.
  78. - Non-recoverable, non-critical errors.
  79. - Non-recoverable, critical errors.
  80. Whether the error is critical or not depends on the API and the application scenario, and it is defined by the API user.
  81. **The primary principle to write a robust application with Wi-Fi API is to always check the error code and write the error-handling code.** Generally, the error-handling code can be used:
  82. - For recoverable errors, in which case you can write a recoverable-error code. For example, when :cpp:func:`esp_wifi_start()` returns :c:macro:`ESP_ERR_NO_MEM`, the recoverable-error code vTaskDelay can be called in order to get a microseconds' delay for another try.
  83. - For non-recoverable, yet non-critical errors, in which case printing the error code is a good method for error handling.
  84. - For non-recoverable and also critical errors, in which case "assert" may be a good method for error handling. For example, if :cpp:func:`esp_wifi_set_mode()` returns ``ESP_ERR_WIFI_NOT_INIT``, it means that the Wi-Fi driver is not initialized by :cpp:func:`esp_wifi_init()` successfully. You can detect this kind of error very quickly in the application development phase.
  85. In :component_file:`esp_common/include/esp_err.h`, ``ESP_ERROR_CHECK`` checks the return values. It is a rather commonplace error-handling code and can be used as the default error-handling code in the application development phase. However, it is strongly recommended that API users write their own error-handling code.
  86. {IDF_TARGET_NAME} Wi-Fi API Parameter Initialization
  87. ----------------------------------------------------
  88. When initializing struct parameters for the API, one of two approaches should be followed:
  89. - Explicitly set all fields of the parameter.
  90. - Use get API to get current configuration first, then set application specific fields.
  91. Initializing or getting the entire structure is very important, because most of the time the value 0 indicates that the default value is used. More fields may be added to the struct in the future and initializing these to zero ensures the application will still work correctly after ESP-IDF is updated to a new release.
  92. .. _wifi-programming-model:
  93. {IDF_TARGET_NAME} Wi-Fi Programming Model
  94. -----------------------------------------
  95. The {IDF_TARGET_NAME} Wi-Fi programming model is depicted as follows:
  96. .. blockdiag::
  97. :caption: Wi-Fi Programming Model
  98. :align: center
  99. blockdiag wifi-programming-model {
  100. # global attributes
  101. node_height = 60;
  102. node_width = 100;
  103. span_width = 100;
  104. span_height = 60;
  105. default_shape = roundedbox;
  106. default_group_color = none;
  107. # node labels
  108. TCP_STACK [label="TCP\n stack", fontsize=12];
  109. EVNT_TASK [label="Event\n task", fontsize=12];
  110. APPL_TASK [label="Application\n task", width = 120, fontsize=12];
  111. WIFI_DRV [label="Wi-Fi\n Driver", width = 120, fontsize=12];
  112. KNOT [shape=none];
  113. # node connections + labels
  114. TCP_STACK -> EVNT_TASK [label=event];
  115. EVNT_TASK -> APPL_TASK [label="callback\n or event"];
  116. # arrange nodes vertically
  117. group {
  118. label = "default handler";
  119. orientation = portrait;
  120. EVNT_TASK <- WIFI_DRV [label=event];
  121. }
  122. # intermediate node
  123. group {
  124. label = "user handler";
  125. orientation = portrait;
  126. APPL_TASK -- KNOT;
  127. }
  128. WIFI_DRV <- KNOT [label="API\n call"];
  129. }
  130. The Wi-Fi driver can be considered a black box that knows nothing about high-layer code, such as the TCP/IP stack, application task, and event task. The application task (code) generally calls :doc:`Wi-Fi driver APIs <../api-reference/network/esp_wifi>` to initialize Wi-Fi and handles Wi-Fi events when necessary. Wi-Fi driver receives API calls, handles them, and posts events to the application.
  131. Wi-Fi event handling is based on the :doc:`esp_event library <../api-reference/system/esp_event>`. Events are sent by the Wi-Fi driver to the :ref:`default event loop <esp-event-default-loops>`. Application may handle these events in callbacks registered using :cpp:func:`esp_event_handler_register()`. Wi-Fi events are also handled by :doc:`esp_netif component <../api-reference/network/esp_netif>` to provide a set of default behaviors. For example, when Wi-Fi station connects to an AP, esp_netif will automatically start the DHCP client by default.
  132. {IDF_TARGET_NAME} Wi-Fi Event Description
  133. -----------------------------------------
  134. WIFI_EVENT_WIFI_READY
  135. ++++++++++++++++++++++++++++++++++++
  136. The Wi-Fi driver will never generate this event, which, as a result, can be ignored by the application event callback. This event may be removed in future releases.
  137. WIFI_EVENT_SCAN_DONE
  138. ++++++++++++++++++++++++++++++++++++
  139. The scan-done event is triggered by :cpp:func:`esp_wifi_scan_start()` and will arise in the following scenarios:
  140. - The scan is completed, e.g., the target AP is found successfully, or all channels have been scanned.
  141. - The scan is stopped by :cpp:func:`esp_wifi_scan_stop()`.
  142. - The :cpp:func:`esp_wifi_scan_start()` is called before the scan is completed. A new scan will override the current scan and a scan-done event will be generated.
  143. The scan-done event will not arise in the following scenarios:
  144. - It is a blocked scan.
  145. - The scan is caused by :cpp:func:`esp_wifi_connect()`.
  146. Upon receiving this event, the event task does nothing. The application event callback needs to call :cpp:func:`esp_wifi_scan_get_ap_num()` and :cpp:func:`esp_wifi_scan_get_ap_records()` to fetch the scanned AP list and trigger the Wi-Fi driver to free the internal memory which is allocated during the scan **(do not forget to do this!)**.
  147. Refer to `{IDF_TARGET_NAME} Wi-Fi Scan`_ for a more detailed description.
  148. WIFI_EVENT_STA_START
  149. ++++++++++++++++++++++++++++++++++++
  150. If :cpp:func:`esp_wifi_start()` returns :c:macro:`ESP_OK` and the current Wi-Fi mode is station or station/AP, then this event will arise. Upon receiving this event, the event task will initialize the LwIP network interface (netif). Generally, the application event callback needs to call :cpp:func:`esp_wifi_connect()` to connect to the configured AP.
  151. WIFI_EVENT_STA_STOP
  152. ++++++++++++++++++++++++++++++++++++
  153. If :cpp:func:`esp_wifi_stop()` returns :c:macro:`ESP_OK` and the current Wi-Fi mode is station or station/AP, then this event will arise. Upon receiving this event, the event task will release the station's IP address, stop the DHCP client, remove TCP/UDP-related connections, and clear the LwIP station netif, etc. The application event callback generally does not need to do anything.
  154. WIFI_EVENT_STA_CONNECTED
  155. ++++++++++++++++++++++++++++++++++++
  156. If :cpp:func:`esp_wifi_connect()` returns :c:macro:`ESP_OK` and the station successfully connects to the target AP, the connection event will arise. Upon receiving this event, the event task starts the DHCP client and begins the DHCP process of getting the IP address. Then, the Wi-Fi driver is ready for sending and receiving data. This moment is good for beginning the application work, provided that the application does not depend on LwIP, namely the IP address. However, if the application is LwIP-based, then you need to wait until the *got ip* event comes in.
  157. WIFI_EVENT_STA_DISCONNECTED
  158. ++++++++++++++++++++++++++++++++++++
  159. This event can be generated in the following scenarios:
  160. - When :cpp:func:`esp_wifi_disconnect()` or :cpp:func:`esp_wifi_stop()` is called and the station is already connected to the AP.
  161. - When :cpp:func:`esp_wifi_connect()` is called, but the Wi-Fi driver fails to set up a connection with the AP due to certain reasons, e.g., the scan fails to find the target AP or the authentication times out. If there are more than one AP with the same SSID, the disconnected event will be raised after the station fails to connect all of the found APs.
  162. - When the Wi-Fi connection is disrupted because of specific reasons, e.g., the station continuously loses N beacons, the AP kicks off the station, or the AP's authentication mode is changed.
  163. Upon receiving this event, the default behaviors of the event task are:
  164. - Shutting down the station's LwIP netif.
  165. - Notifying the LwIP task to clear the UDP/TCP connections which cause the wrong status to all sockets. For socket-based applications, the application callback can choose to close all sockets and re-create them, if necessary, upon receiving this event.
  166. The most common event handle code for this event in application is to call :cpp:func:`esp_wifi_connect()` to reconnect the Wi-Fi. However, if the event is raised because :cpp:func:`esp_wifi_disconnect()` is called, the application should not call :cpp:func:`esp_wifi_connect()` to reconnect. It is the application's responsibility to distinguish whether the event is caused by :cpp:func:`esp_wifi_disconnect()` or other reasons. Sometimes a better reconnection strategy is required. Refer to `Wi-Fi Reconnect`_ and `Scan When Wi-Fi Is Connecting`_.
  167. Another thing that deserves attention is that the default behavior of LwIP is to abort all TCP socket connections on receiving the disconnect. In most cases, it is not a problem. However, for some special applications, this may not be what they want. Consider the following scenarios:
  168. - The application creates a TCP connection to maintain the application-level keep-alive data that is sent out every 60 seconds.
  169. - Due to certain reasons, the Wi-Fi connection is cut off, and the `WIFI_EVENT_STA_DISCONNECTED`_ is raised. According to the current implementation, all TCP connections will be removed and the keep-alive socket will be in a wrong status. However, since the application designer believes that the network layer should **ignore** this error at the Wi-Fi layer, the application does not close the socket.
  170. - Five seconds later, the Wi-Fi connection is restored because :cpp:func:`esp_wifi_connect()` is called in the application event callback function. **Moreover, the station connects to the same AP and gets the same IPV4 address as before**.
  171. - Sixty seconds later, when the application sends out data with the keep-alive socket, the socket returns an error and the application closes the socket and re-creates it when necessary.
  172. In above scenarios, ideally, the application sockets and the network layer should not be affected, since the Wi-Fi connection only fails temporarily and recovers very quickly. The application can enable "Keep TCP connections when IP changed" via LwIP menuconfig.
  173. IP_EVENT_STA_GOT_IP
  174. ++++++++++++++++++++++++++++++++++++
  175. This event arises when the DHCP client successfully gets the IPV4 address from the DHCP server, or when the IPV4 address is changed. The event means that everything is ready and the application can begin its tasks (e.g., creating sockets).
  176. The IPV4 may be changed because of the following reasons:
  177. - The DHCP client fails to renew/rebind the IPV4 address, and the station's IPV4 is reset to 0.
  178. - The DHCP client rebinds to a different address.
  179. - The static-configured IPV4 address is changed.
  180. Whether the IPV4 address is changed or not is indicated by the field ``ip_change`` of ``ip_event_got_ip_t``.
  181. The socket is based on the IPV4 address, which means that, if the IPV4 changes, all sockets relating to this IPV4 will become abnormal. Upon receiving this event, the application needs to close all sockets and recreate the application when the IPV4 changes to a valid one.
  182. IP_EVENT_GOT_IP6
  183. ++++++++++++++++++++++++++++++++++++
  184. This event arises when the IPV6 SLAAC support auto-configures an address for the {IDF_TARGET_NAME}, or when this address changes. The event means that everything is ready and the application can begin its tasks, e.g., creating sockets.
  185. IP_EVENT_STA_LOST_IP
  186. ++++++++++++++++++++++++++++++++++++
  187. This event arises when the IPV4 address becomes invalid.
  188. IP_EVENT_STA_LOST_IP does not arise immediately after the Wi-Fi disconnects. Instead, it starts an IPV4 address lost timer. If the IPV4 address is got before ip lost timer expires, IP_EVENT_STA_LOST_IP does not happen. Otherwise, the event arises when the IPV4 address lost timer expires.
  189. Generally, the application can ignore this event, because it is just a debug event to inform that the IPV4 address is lost.
  190. WIFI_EVENT_AP_START
  191. ++++++++++++++++++++++++++++++++++++
  192. Similar to `WIFI_EVENT_STA_START`_.
  193. WIFI_EVENT_AP_STOP
  194. ++++++++++++++++++++++++++++++++++++
  195. Similar to `WIFI_EVENT_STA_STOP`_.
  196. WIFI_EVENT_AP_STACONNECTED
  197. ++++++++++++++++++++++++++++++++++++
  198. Every time a station is connected to {IDF_TARGET_NAME} AP, the `WIFI_EVENT_AP_STACONNECTED`_ will arise. Upon receiving this event, the event task will do nothing, and the application callback can also ignore it. However, you may want to do something, for example, to get the info of the connected STA.
  199. WIFI_EVENT_AP_STADISCONNECTED
  200. ++++++++++++++++++++++++++++++++++++
  201. This event can happen in the following scenarios:
  202. - The application calls :cpp:func:`esp_wifi_disconnect()`, or :cpp:func:`esp_wifi_deauth_sta()`, to manually disconnect the station.
  203. - The Wi-Fi driver kicks off the station, e.g., because the AP has not received any packets in the past five minutes. The time can be modified by :cpp:func:`esp_wifi_set_inactive_time()`.
  204. - The station kicks off the AP.
  205. When this event happens, the event task will do nothing, but the application event callback needs to do something, e.g., close the socket which is related to this station.
  206. WIFI_EVENT_AP_PROBEREQRECVED
  207. ++++++++++++++++++++++++++++++++++++
  208. This event is disabled by default. The application can enable it via API :cpp:func:`esp_wifi_set_event_mask()`.
  209. When this event is enabled, it will be raised each time the AP receives a probe request.
  210. WIFI_EVENT_STA_BEACON_TIMEOUT
  211. ++++++++++++++++++++++++++++++++++++
  212. If the station does not receive the beacon of the connected AP within the inactive time, the beacon timeout happens, the `WIFI_EVENT_STA_BEACON_TIMEOUT`_ will arise. The application can set inactive time via API :cpp:func:`esp_wifi_set_inactive_time()`.
  213. WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START
  214. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  215. The `WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START`_ will arise at the start of connectionless module `Interval`. See :ref:`connectionless module power save <connectionless-module-power-save>`.
  216. {IDF_TARGET_NAME} Wi-Fi Station General Scenario
  217. ------------------------------------------------
  218. Below is a "big scenario" which describes some small scenarios in station mode:
  219. .. seqdiag::
  220. :caption: Sample Wi-Fi Event Scenarios in Station Mode
  221. :align: center
  222. seqdiag sample-scenarios-station-mode {
  223. activation = none;
  224. node_width = 80;
  225. node_height = 60;
  226. edge_length = 140;
  227. span_height = 5;
  228. default_shape = roundedbox;
  229. default_fontsize = 12;
  230. MAIN_TASK [label = "Main\ntask"];
  231. APP_TASK [label = "App\ntask"];
  232. EVENT_TASK [label = "Event\ntask"];
  233. LwIP_TASK [label = "LwIP\ntask"];
  234. WIFI_TASK [label = "Wi-Fi\ntask"];
  235. === 1. Init Phase ===
  236. MAIN_TASK -> LwIP_TASK [label="1.1> Create / init LwIP"];
  237. MAIN_TASK -> EVENT_TASK [label="1.2> Create / init event"];
  238. MAIN_TASK -> WIFI_TASK [label="1.3> Create / init Wi-Fi"];
  239. MAIN_TASK -> APP_TASK [label="1.4> Create app task"];
  240. === 2. Configure Phase ===
  241. MAIN_TASK -> WIFI_TASK [label="2> Configure Wi-Fi"];
  242. === 3. Start Phase ===
  243. MAIN_TASK -> WIFI_TASK [label="3.1> Start Wi-Fi"];
  244. EVENT_TASK <- WIFI_TASK [label="3.2> WIFI_EVENT_STA_START"];
  245. APP_TASK <- EVENT_TASK [label="3.3> WIFI_EVENT_STA_START"];
  246. === 4. Connect Phase ===
  247. APP_TASK -> WIFI_TASK [label="4.1> Connect Wi-Fi"];
  248. EVENT_TASK <- WIFI_TASK [label="4.2> WIFI_EVENT_STA_CONNECTED"];
  249. APP_TASK <- EVENT_TASK [label="4.3> WIFI_EVENT_STA_CONNECTED"];
  250. === 5. Got IP Phase ===
  251. EVENT_TASK -> LwIP_TASK [label="5.1> Start DHCP client"];
  252. EVENT_TASK <- LwIP_TASK [label="5.2> IP_EVENT_STA_GOT_IP"];
  253. APP_TASK <- EVENT_TASK [label="5.3> IP_EVENT_STA_GOT_IP"];
  254. APP_TASK -> APP_TASK [label="5.4> socket related init"];
  255. === 6. Disconnect Phase ===
  256. EVENT_TASK <- WIFI_TASK [label="6.1> WIFI_EVENT_STA_DISCONNECTED"];
  257. APP_TASK <- EVENT_TASK [label="6.2> WIFI_EVENT_STA_DISCONNECTED"];
  258. APP_TASK -> APP_TASK [label="6.3> disconnect handling"];
  259. === 7. IP Change Phase ===
  260. EVENT_TASK <- LwIP_TASK [label="7.1> IP_EVENT_STA_GOT_IP"];
  261. APP_TASK <- EVENT_TASK [label="7.2> IP_EVENT_STA_GOT_IP"];
  262. APP_TASK -> APP_TASK [label="7.3> Socket error handling"];
  263. === 8. Deinit Phase ===
  264. APP_TASK -> WIFI_TASK [label="8.1> Disconnect Wi-Fi"];
  265. APP_TASK -> WIFI_TASK [label="8.2> Stop Wi-Fi"];
  266. APP_TASK -> WIFI_TASK [label="8.3> Deinit Wi-Fi"];
  267. }
  268. 1. Wi-Fi/LwIP Init Phase
  269. ++++++++++++++++++++++++++++++
  270. - s1.1: The main task calls :cpp:func:`esp_netif_init()` to create an LwIP core task and initialize LwIP-related work.
  271. - s1.2: The main task calls :cpp:func:`esp_event_loop_create()` to create a system Event task and initialize an application event's callback function. In the scenario above, the application event's callback function does nothing but relaying the event to the application task.
  272. - s1.3: The main task calls :cpp:func:`esp_netif_create_default_wifi_ap()` or :cpp:func:`esp_netif_create_default_wifi_sta()` to create default network interface instance binding station or AP with TCP/IP stack.
  273. - s1.4: The main task calls :cpp:func:`esp_wifi_init()` to create the Wi-Fi driver task and initialize the Wi-Fi driver.
  274. - s1.5: The main task calls OS API to create the application task.
  275. Step 1.1 ~ 1.5 is a recommended sequence that initializes a Wi-Fi-/LwIP-based application. However, it is **NOT** a must-follow sequence, which means that you can create the application task in step 1.1 and put all other initialization in the application task. Moreover, you may not want to create the application task in the initialization phase if the application task depends on the sockets. Rather, you can defer the task creation until the IP is obtained.
  276. 2. Wi-Fi Configuration Phase
  277. +++++++++++++++++++++++++++++++
  278. Once the Wi-Fi driver is initialized, you can start configuring the Wi-Fi driver. In this scenario, the mode is station, so you may need to call :cpp:func:`esp_wifi_set_mode` (WIFI_MODE_STA) to configure the Wi-Fi mode as station. You can call other `esp_wifi_set_xxx` APIs to configure more settings, such as the protocol mode, the country code, and the bandwidth. Refer to `{IDF_TARGET_NAME} Wi-Fi Configuration`_.
  279. Generally, the Wi-Fi driver should be configured before the Wi-Fi connection is set up. But this is **NOT** mandatory, which means that you can configure the Wi-Fi connection anytime, provided that the Wi-Fi driver is initialized successfully. However, if the configuration does not need to change after the Wi-Fi connection is set up, you should configure the Wi-Fi driver at this stage, because the configuration APIs (such as :cpp:func:`esp_wifi_set_protocol()`) will cause the Wi-Fi to reconnect, which may not be desirable.
  280. If the Wi-Fi NVS flash is enabled by menuconfig, all Wi-Fi configuration in this phase, or later phases, will be stored into flash. When the board powers on/reboots, you do not need to configure the Wi-Fi driver from scratch. You only need to call ``esp_wifi_get_xxx`` APIs to fetch the configuration stored in flash previously. You can also configure the Wi-Fi driver if the previous configuration is not what you want.
  281. 3. Wi-Fi Start Phase
  282. ++++++++++++++++++++++++++++++++
  283. - s3.1: Call :cpp:func:`esp_wifi_start()` to start the Wi-Fi driver.
  284. - s3.2: The Wi-Fi driver posts `WIFI_EVENT_STA_START`_ to the event task; then, the event task will do some common things and will call the application event callback function.
  285. - s3.3: The application event callback function relays the `WIFI_EVENT_STA_START`_ to the application task. We recommend that you call :cpp:func:`esp_wifi_connect()`. However, you can also call :cpp:func:`esp_wifi_connect()` in other phrases after the `WIFI_EVENT_STA_START`_ arises.
  286. 4. Wi-Fi Connect Phase
  287. +++++++++++++++++++++++++++++++++
  288. - s4.1: Once :cpp:func:`esp_wifi_connect()` is called, the Wi-Fi driver will start the internal scan/connection process.
  289. - s4.2: If the internal scan/connection process is successful, the `WIFI_EVENT_STA_CONNECTED`_ will be generated. In the event task, it starts the DHCP client, which will finally trigger the DHCP process.
  290. - s4.3: In the above-mentioned scenario, the application event callback will relay the event to the application task. Generally, the application needs to do nothing, and you can do whatever you want, e.g., print a log.
  291. In step 4.2, the Wi-Fi connection may fail because, for example, the password is wrong, or the AP is not found. In a case like this, `WIFI_EVENT_STA_DISCONNECTED`_ will arise and the reason for such a failure will be provided. For handling events that disrupt Wi-Fi connection, please refer to phase 6.
  292. 5. Wi-Fi 'Got IP' Phase
  293. +++++++++++++++++++++++++++++++++
  294. - s5.1: Once the DHCP client is initialized in step 4.2, the *got IP* phase will begin.
  295. - s5.2: If the IP address is successfully received from the DHCP server, then `IP_EVENT_STA_GOT_IP`_ will arise and the event task will perform common handling.
  296. - s5.3: In the application event callback, `IP_EVENT_STA_GOT_IP`_ is relayed to the application task. For LwIP-based applications, this event is very special and means that everything is ready for the application to begin its tasks, e.g., creating the TCP/UDP socket. A very common mistake is to initialize the socket before `IP_EVENT_STA_GOT_IP`_ is received. **DO NOT start the socket-related work before the IP is received.**
  297. 6. Wi-Fi Disconnect Phase
  298. +++++++++++++++++++++++++++++++++
  299. - s6.1: When the Wi-Fi connection is disrupted, e.g., the AP is powered off or the RSSI is poor, `WIFI_EVENT_STA_DISCONNECTED`_ will arise. This event may also arise in phase 3. Here, the event task will notify the LwIP task to clear/remove all UDP/TCP connections. Then, all application sockets will be in a wrong status. In other words, no socket can work properly when this event happens.
  300. - s6.2: In the scenario described above, the application event callback function relays `WIFI_EVENT_STA_DISCONNECTED`_ to the application task. The recommended actions are: 1) call :cpp:func:`esp_wifi_connect()` to reconnect the Wi-Fi, 2) close all sockets, and 3) re-create them if necessary. For details, please refer to `WIFI_EVENT_STA_DISCONNECTED`_.
  301. 7. Wi-Fi IP Change Phase
  302. ++++++++++++++++++++++++++++++++++
  303. - s7.1: If the IP address is changed, the `IP_EVENT_STA_GOT_IP`_ will arise with "ip_change" set to true.
  304. - s7.2: **This event is important to the application. When it occurs, the timing is good for closing all created sockets and recreating them.**
  305. 8. Wi-Fi Deinit Phase
  306. ++++++++++++++++++++++++++++
  307. - s8.1: Call :cpp:func:`esp_wifi_disconnect()` to disconnect the Wi-Fi connectivity.
  308. - s8.2: Call :cpp:func:`esp_wifi_stop()` to stop the Wi-Fi driver.
  309. - s8.3: Call :cpp:func:`esp_wifi_deinit()` to unload the Wi-Fi driver.
  310. {IDF_TARGET_NAME} Wi-Fi AP General Scenario
  311. ---------------------------------------------
  312. Below is a "big scenario" which describes some small scenarios in AP mode:
  313. .. seqdiag::
  314. :caption: Sample Wi-Fi Event Scenarios in AP Mode
  315. :align: center
  316. seqdiag sample-scenarios-soft-ap-mode {
  317. activation = none;
  318. node_width = 80;
  319. node_height = 60;
  320. edge_length = 140;
  321. span_height = 5;
  322. default_shape = roundedbox;
  323. default_fontsize = 12;
  324. MAIN_TASK [label = "Main\ntask"];
  325. APP_TASK [label = "App\ntask"];
  326. EVENT_TASK [label = "Event\ntask"];
  327. LwIP_TASK [label = "LwIP\ntask"];
  328. WIFI_TASK [label = "Wi-Fi\ntask"];
  329. === 1. Init Phase ===
  330. MAIN_TASK -> LwIP_TASK [label="1.1> Create / init LwIP"];
  331. MAIN_TASK -> EVENT_TASK [label="1.2> Create / init event"];
  332. MAIN_TASK -> WIFI_TASK [label="1.3> Create / init Wi-Fi"];
  333. MAIN_TASK -> APP_TASK [label="1.4> Create app task"];
  334. === 2. Configure Phase ===
  335. MAIN_TASK -> WIFI_TASK [label="2> Configure Wi-Fi"];
  336. === 3. Start Phase ===
  337. MAIN_TASK -> WIFI_TASK [label="3.1> Start Wi-Fi"];
  338. EVENT_TASK <- WIFI_TASK [label="3.2> WIFI_EVENT_AP_START"];
  339. APP_TASK <- EVENT_TASK [label="3.3> WIFI_EVENT_AP_START"];
  340. === 4. Connect Phase ===
  341. EVENT_TASK <- WIFI_TASK [label="4.1> WIFI_EVENT_AP_STACONNECTED"];
  342. APP_TASK <- EVENT_TASK [label="4.2> WIFI_EVENT_AP_STACONNECTED"];
  343. === 5. Disconnect Phase ===
  344. EVENT_TASK <- WIFI_TASK [label="5.1> WIFI_EVENT_AP_STADISCONNECTED"];
  345. APP_TASK <- EVENT_TASK [label="5.2> WIFI_EVENT_AP_STADISCONNECTED"];
  346. APP_TASK -> APP_TASK [label="5.3> disconnect handling"];
  347. === 6. Deinit Phase ===
  348. APP_TASK -> WIFI_TASK [label="6.1> Disconnect Wi-Fi"];
  349. APP_TASK -> WIFI_TASK [label="6.2> Stop Wi-Fi"];
  350. APP_TASK -> WIFI_TASK [label="6.3> Deinit Wi-Fi"];
  351. }
  352. {IDF_TARGET_NAME} Wi-Fi Scan
  353. ----------------------------
  354. Currently, the :cpp:func:`esp_wifi_scan_start()` API is supported only in station or station/AP mode.
  355. Scan Type
  356. +++++++++++++++++++++++++
  357. .. list-table::
  358. :header-rows: 1
  359. :widths: 15 50
  360. * - Mode
  361. - Description
  362. * - Active Scan
  363. - Scan by sending a probe request. The default scan is an active scan.
  364. * - Passive Scan
  365. - No probe request is sent out. Just switch to the specific channel and wait for a beacon. Application can enable it via the scan_type field of :cpp:type:`wifi_scan_config_t`.
  366. * - Foreground Scan
  367. - This scan is applicable when there is no Wi-Fi connection in station mode. Foreground or background scanning is controlled by the Wi-Fi driver and cannot be configured by the application.
  368. * - Background Scan
  369. - This scan is applicable when there is a Wi-Fi connection in station mode or in station/AP mode. Whether it is a foreground scan or background scan depends on the Wi-Fi driver and cannot be configured by the application.
  370. * - All-Channel Scan
  371. - It scans all of the channels. If the channel field of :cpp:type:`wifi_scan_config_t` is set to 0, it is an all-channel scan.
  372. * - Specific Channel Scan
  373. - It scans specific channels only. If the channel field of :cpp:type:`wifi_scan_config_t` set to 1-14, it is a specific-channel scan.
  374. The scan modes in above table can be combined arbitrarily, so there are in total 8 different scans:
  375. - All-Channel Background Active Scan
  376. - All-Channel Background Passive Scan
  377. - All-Channel Foreground Active Scan
  378. - All-Channel Foreground Passive Scan
  379. - Specific-Channel Background Active Scan
  380. - Specific-Channel Background Passive Scan
  381. - Specific-Channel Foreground Active Scan
  382. - Specific-Channel Foreground Passive Scan
  383. Scan Configuration
  384. +++++++++++++++++++++++++++++++++++++++
  385. The scan type and other per-scan attributes are configured by :cpp:func:`esp_wifi_scan_start()`. The table below provides a detailed description of :cpp:type:`wifi_scan_config_t`.
  386. .. list-table::
  387. :header-rows: 1
  388. :widths: 15 50
  389. * - Field
  390. - Description
  391. * - ssid
  392. - If the SSID is not NULL, it is only the AP with the same SSID that can be scanned.
  393. * - bssid
  394. - If the BSSID is not NULL, it is only the AP with the same BSSID that can be scanned.
  395. * - channel
  396. - If “channel” is 0, there will be an all-channel scan; otherwise, there will be a specific-channel scan.
  397. * - show_hidden
  398. - If “show_hidden” is 0, the scan ignores the AP with a hidden SSID; otherwise, the scan considers the hidden AP a normal one.
  399. * - scan_type
  400. - If “scan_type” is WIFI_SCAN_TYPE_ACTIVE, the scan is “active”; otherwise, it is a “passive” one.
  401. * - scan_time
  402. - This field is used to control how long the scan dwells on each channel.
  403. For passive scans, scan_time.passive designates the dwell time for each channel.
  404. For active scans, dwell times for each channel are listed in the table below. Here, min is short for scan time.active.min and max is short for scan_time.active.max.
  405. - min=0, max=0: scan dwells on each channel for 120 ms.
  406. - min>0, max=0: scan dwells on each channel for 120 ms.
  407. - min=0, max>0: scan dwells on each channel for ``max`` ms.
  408. - min>0, max>0: the minimum time the scan dwells on each channel is ``min`` ms. If no AP is found during this time frame, the scan switches to the next channel. Otherwise, the scan dwells on the channel for ``max`` ms.
  409. If you want to improve the performance of the scan, you can try to modify these two parameters.
  410. There are also some global scan attributes which are configured by API :cpp:func:`esp_wifi_set_config()`, refer to `Station Basic Configuration`_
  411. Scan All APs on All Channels (Foreground)
  412. +++++++++++++++++++++++++++++++++++++++++++++
  413. Scenario:
  414. .. seqdiag::
  415. :caption: Foreground Scan of all Wi-Fi Channels
  416. :align: center
  417. seqdiag foreground-scan-all-channels {
  418. activation = none;
  419. node_width = 80;
  420. node_height = 60;
  421. edge_length = 160;
  422. span_height = 5;
  423. default_shape = roundedbox;
  424. default_fontsize = 12;
  425. APP_TASK [label = "App\ntask"];
  426. EVENT_TASK [label = "Event\ntask"];
  427. WIFI_TASK [label = "Wi-Fi\ntask"];
  428. APP_TASK -> WIFI_TASK [label="1.1 > Configure country code"];
  429. APP_TASK -> WIFI_TASK [label="1.2 > Scan configuration"];
  430. WIFI_TASK -> WIFI_TASK [label="2.1 > Scan channel 1"];
  431. WIFI_TASK -> WIFI_TASK [label="2.2 > Scan channel 2"];
  432. WIFI_TASK -> WIFI_TASK [label="..."];
  433. WIFI_TASK -> WIFI_TASK [label="2.x > Scan channel N"];
  434. EVENT_TASK <- WIFI_TASK [label="3.1 > WIFI_EVENT_SCAN_DONE"];
  435. APP_TASK <- EVENT_TASK [label="3.2 > WIFI_EVENT_SCAN_DONE"];
  436. }
  437. The scenario above describes an all-channel, foreground scan. The foreground scan can only occur in station mode where the station does not connect to any AP. Whether it is a foreground or background scan is totally determined by the Wi-Fi driver, and cannot be configured by the application.
  438. Detailed scenario description:
  439. Scan Configuration Phase
  440. **************************
  441. - s1.1: Call :cpp:func:`esp_wifi_set_country()` to set the country info if the default country info is not what you want. Refer to `Wi-Fi Country Code`_.
  442. - s1.2: Call :cpp:func:`esp_wifi_scan_start()` to configure the scan. To do so, you can refer to `Scan Configuration`_. Since this is an all-channel scan, just set the SSID/BSSID/channel to 0.
  443. Wi-Fi Driver's Internal Scan Phase
  444. **************************************
  445. - s2.1: The Wi-Fi driver switches to channel 1. In this case, the scan type is WIFI_SCAN_TYPE_ACTIVE, and a probe request is broadcasted. Otherwise, the Wi-Fi will wait for a beacon from the APs. The Wi-Fi driver will stay in channel 1 for some time. The dwell time is configured in min/max time, with the default value being 120 ms.
  446. - s2.2: The Wi-Fi driver switches to channel 2 and performs the same operation as in step 2.1.
  447. - s2.3: The Wi-Fi driver scans the last channel N, where N is determined by the country code which is configured in step 1.1.
  448. Scan-Done Event Handling Phase
  449. *********************************
  450. - s3.1: When all channels are scanned, `WIFI_EVENT_SCAN_DONE`_ will arise.
  451. - s3.2: The application's event callback function notifies the application task that `WIFI_EVENT_SCAN_DONE`_ is received. :cpp:func:`esp_wifi_scan_get_ap_num()` is called to get the number of APs that have been found in this scan. Then, it allocates enough entries and calls :cpp:func:`esp_wifi_scan_get_ap_records()` to get the AP records. Please note that the AP records in the Wi-Fi driver will be freed once :cpp:func:`esp_wifi_scan_get_ap_records()` is called. Do not call :cpp:func:`esp_wifi_scan_get_ap_records()` twice for a single scan-done event. If :cpp:func:`esp_wifi_scan_get_ap_records()` is not called when the scan-done event occurs, the AP records allocated by the Wi-Fi driver will not be freed. So, make sure you call :cpp:func:`esp_wifi_scan_get_ap_records()`, yet only once.
  452. Scan All APs on All Channels (Background)
  453. ++++++++++++++++++++++++++++++++++++++++++
  454. Scenario:
  455. .. seqdiag::
  456. :caption: Background Scan of all Wi-Fi Channels
  457. :align: center
  458. seqdiag background-scan-all-channels {
  459. activation = none;
  460. node_width = 80;
  461. node_height = 60;
  462. edge_length = 160;
  463. span_height = 5;
  464. default_shape = roundedbox;
  465. default_fontsize = 12;
  466. APP_TASK [label = "App\ntask"];
  467. EVENT_TASK [label = "Event\ntask"];
  468. WIFI_TASK [label = "Wi-Fi\ntask"];
  469. APP_TASK -> WIFI_TASK [label="1.1 > Configure country code"];
  470. APP_TASK -> WIFI_TASK [label="1.2 > Scan configuration"];
  471. WIFI_TASK -> WIFI_TASK [label="2.1 > Scan channel 1"];
  472. WIFI_TASK -> WIFI_TASK [label="2.2 > Back to home channel H"];
  473. WIFI_TASK -> WIFI_TASK [label="2.3 > Scan channel 2"];
  474. WIFI_TASK -> WIFI_TASK [label="2.4 > Back to home channel H"];
  475. WIFI_TASK -> WIFI_TASK [label="..."];
  476. WIFI_TASK -> WIFI_TASK [label="2.x-1 > Scan channel N"];
  477. WIFI_TASK -> WIFI_TASK [label="2.x > Back to home channel H"];
  478. EVENT_TASK <- WIFI_TASK [label="3.1 > WIFI_EVENT_SCAN_DONE"];
  479. APP_TASK <- EVENT_TASK [label="3.2 > WIFI_EVENT_SCAN_DONE"];
  480. }
  481. The scenario above is an all-channel background scan. Compared to `Scan All APs on All Channels (Foreground)`_ , the difference in the all-channel background scan is that the Wi-Fi driver will scan the back-to-home channel for 30 ms before it switches to the next channel to give the Wi-Fi connection a chance to transmit/receive data.
  482. Scan for Specific AP on All Channels
  483. +++++++++++++++++++++++++++++++++++++++
  484. Scenario:
  485. .. seqdiag::
  486. :caption: Scan of specific Wi-Fi Channels
  487. :align: center
  488. seqdiag scan-specific-channels {
  489. activation = none;
  490. node_width = 80;
  491. node_height = 60;
  492. edge_length = 160;
  493. span_height = 5;
  494. default_shape = roundedbox;
  495. default_fontsize = 12;
  496. APP_TASK [label = "App\ntask"];
  497. EVENT_TASK [label = "Event\ntask"];
  498. WIFI_TASK [label = "Wi-Fi\ntask"];
  499. APP_TASK -> WIFI_TASK [label="1.1 > Configure country code"];
  500. APP_TASK -> WIFI_TASK [label="1.2 > Scan configuration"];
  501. WIFI_TASK -> WIFI_TASK [label="2.1 > Scan channel C1"];
  502. WIFI_TASK -> WIFI_TASK [label="2.2 > Scan channel C2"];
  503. WIFI_TASK -> WIFI_TASK [label="..."];
  504. WIFI_TASK -> WIFI_TASK [label="2.x > Scan channel CN, or the AP is found"];
  505. EVENT_TASK <- WIFI_TASK [label="3.1 > WIFI_EVENT_SCAN_DONE"];
  506. APP_TASK <- EVENT_TASK [label="3.2 > WIFI_EVENT_SCAN_DONE"];
  507. }
  508. This scan is similar to `Scan All APs on All Channels (Foreground)`_. The differences are:
  509. - s1.1: In step 1.2, the target AP will be configured to SSID/BSSID.
  510. - s2.1 ~ s2.N: Each time the Wi-Fi driver scans an AP, it will check whether it is a target AP or not. If the scan is ``WIFI_FAST_SCAN`` scan and the target AP is found, then the scan-done event will arise and scanning will end; otherwise, the scan will continue. Please note that the first scanned channel may not be channel 1, because the Wi-Fi driver optimizes the scanning sequence.
  511. It is a possible situation that there are multiple APs that match the target AP info, e.g., two APs with the SSID of "ap" are scanned. In this case, if the scan is ``WIFI_FAST_SCAN``, then only the first scanned "ap" will be found. If the scan is ``WIFI_ALL_CHANNEL_SCAN``, both "ap" will be found and the station will connect the "ap" according to the configured strategy. Refer to `Station Basic Configuration`_.
  512. You can scan a specific AP, or all of them, in any given channel. These two scenarios are very similar.
  513. Scan in Wi-Fi Connect
  514. +++++++++++++++++++++++++
  515. When :cpp:func:`esp_wifi_connect()` is called, the Wi-Fi driver will try to scan the configured AP first. The scan in "Wi-Fi Connect" is the same as `Scan for Specific AP On All Channels`_, except that no scan-done event will be generated when the scan is completed. If the target AP is found, the Wi-Fi driver will start the Wi-Fi connection; otherwise, `WIFI_EVENT_STA_DISCONNECTED`_ will be generated. Refer to `Scan for Specific AP On All Channels`_.
  516. Scan in Blocked Mode
  517. ++++++++++++++++++++
  518. If the block parameter of :cpp:func:`esp_wifi_scan_start()` is true, then the scan is a blocked one, and the application task will be blocked until the scan is done. The blocked scan is similar to an unblocked one, except that no scan-done event will arise when the blocked scan is completed.
  519. Parallel Scan
  520. +++++++++++++
  521. Two application tasks may call :cpp:func:`esp_wifi_scan_start()` at the same time, or the same application task calls :cpp:func:`esp_wifi_scan_start()` before it gets a scan-done event. Both scenarios can happen. **However, the Wi-Fi driver does not support multiple concurrent scans adequately. As a result, concurrent scans should be avoided.** Support for concurrent scan will be enhanced in future releases, as the {IDF_TARGET_NAME}'s Wi-Fi functionality improves continuously.
  522. Scan When Wi-Fi Is Connecting
  523. +++++++++++++++++++++++++++++++
  524. The :cpp:func:`esp_wifi_scan_start()` fails immediately if the Wi-Fi is connecting, because the connecting has higher priority than the scan. If scan fails because of connecting, the recommended strategy is to delay for some time and retry scan again. The scan will succeed once the connecting is completed.
  525. However, the retry/delay strategy may not work all the time. Considering the following scenarios:
  526. - The station is connecting a non-existing AP or it connects the existing AP with a wrong password, it always raises the event `WIFI_EVENT_STA_DISCONNECTED`_.
  527. - The application calls :cpp:func:`esp_wifi_connect()` to reconnect on receiving the disconnect event.
  528. - Another application task, e.g., the console task, calls :cpp:func:`esp_wifi_scan_start()` to do scan, the scan always fails immediately because the station keeps connecting.
  529. - When scan fails, the application simply delays for some time and retries the scan.
  530. In the above scenarios, the scan will never succeed because the connecting is in process. So if the application supports similar scenario, it needs to implement a better reconnection strategy. For example:
  531. - The application can choose to define a maximum continuous reconnection counter and stop reconnecting once the counter reaches the maximum.
  532. - The application can choose to reconnect immediately in the first N continuous reconnection, then give a delay sometime and reconnect again.
  533. The application can define its own reconnection strategy to avoid the scan starve to death. Refer to <`Wi-Fi Reconnect`_>.
  534. {IDF_TARGET_NAME} Wi-Fi Station Connecting Scenario
  535. ---------------------------------------------------
  536. This scenario depicts the case if only one target AP is found in the scan phase. For scenarios where more than one AP with the same SSID is found, refer to `{IDF_TARGET_NAME} Wi-Fi Station Connecting When Multiple APs Are Found`_.
  537. Generally, the application can ignore the connecting process. Below is a brief introduction to the process for those who are really interested.
  538. Scenario:
  539. .. seqdiag::
  540. :caption: Wi-Fi Station Connecting Process
  541. :align: center
  542. seqdiag station-connecting-process {
  543. activation = none;
  544. node_width = 80;
  545. node_height = 60;
  546. edge_length = 160;
  547. span_height = 5;
  548. default_shape = roundedbox;
  549. default_fontsize = 12;
  550. EVENT_TASK [label = "Event\ntask"];
  551. WIFI_TASK [label = "Wi-Fi\ntask"];
  552. AP [label = "AP"];
  553. === 1. Scan Phase ===
  554. WIFI_TASK -> WIFI_TASK [label="1.1 > Scan"];
  555. EVENT_TASK <- WIFI_TASK [label="1.2 > WIFI_EVENT_STA_DISCONNECTED"];
  556. === 2. Auth Phase ===
  557. WIFI_TASK -> AP [label="2.1 > Auth request"];
  558. EVENT_TASK <- WIFI_TASK [label="2.2 > WIFI_EVENT_STA_DISCONNECTED"];
  559. WIFI_TASK <- AP [label="2.3 > Auth response"];
  560. EVENT_TASK <- WIFI_TASK [label="2.4 > WIFI_EVENT_STA_DISCONNECTED"];
  561. === 3. Assoc Phase ===
  562. WIFI_TASK -> AP [label="3.1 > Assoc request"];
  563. EVENT_TASK <- WIFI_TASK [label="3.2 > WIFI_EVENT_STA_DISCONNECTED"];
  564. WIFI_TASK <- AP [label="3.3 > Assoc response"];
  565. EVENT_TASK <- WIFI_TASK [label="3.4 > WIFI_EVENT_STA_DISCONNECTED"];
  566. === 4. 4-way Handshake Phase ===
  567. EVENT_TASK <- WIFI_TASK [label="4.1 > WIFI_EVENT_STA_DISCONNECTED"];
  568. WIFI_TASK <- AP [label="4.2 > 1/4 EAPOL"];
  569. WIFI_TASK -> AP [label="4.3 > 2/4 EAPOL"];
  570. EVENT_TASK <- WIFI_TASK [label="4.4 > WIFI_EVENT_STA_DISCONNECTED"];
  571. WIFI_TASK <- AP [label="4.5 > 3/4 EAPOL"];
  572. WIFI_TASK -> AP [label="4.6 > 4/4 EAPOL"];
  573. EVENT_TASK <- WIFI_TASK [label="4.7 > WIFI_EVENT_STA_CONNECTED"];
  574. }
  575. Scan Phase
  576. +++++++++++++++++++++
  577. - s1.1: The Wi-Fi driver begins scanning in "Wi-Fi Connect". Refer to `Scan in Wi-Fi Connect`_ for more details.
  578. - s1.2: If the scan fails to find the target AP, `WIFI_EVENT_STA_DISCONNECTED`_ will arise and the reason code will be ``WIFI_REASON_NO_AP_FOUND``. Refer to `Wi-Fi Reason Code`_.
  579. Auth Phase
  580. +++++++++++++++++++++
  581. - s2.1: The authentication request packet is sent and the auth timer is enabled.
  582. - s2.2: If the authentication response packet is not received before the authentication timer times out, `WIFI_EVENT_STA_DISCONNECTED`_ will arise and the reason code will be ``WIFI_REASON_AUTH_EXPIRE``. Refer to `Wi-Fi Reason Code`_.
  583. - s2.3: The auth-response packet is received and the auth-timer is stopped.
  584. - s2.4: The AP rejects authentication in the response and `WIFI_EVENT_STA_DISCONNECTED`_ arises, while the reason code is ``WIFI_REASON_AUTH_FAIL`` or the reasons specified by the AP. Refer to `Wi-Fi Reason Code`_.
  585. Association Phase
  586. +++++++++++++++++++++
  587. - s3.1: The association request is sent and the association timer is enabled.
  588. - s3.2: If the association response is not received before the association timer times out, `WIFI_EVENT_STA_DISCONNECTED`_ will arise and the reason code will be ``WIFI_REASON_ASSOC_EXPIRE``. Refer to `Wi-Fi Reason Code`_.
  589. - s3.3: The association response is received and the association timer is stopped.
  590. - s3.4: The AP rejects the association in the response and `WIFI_EVENT_STA_DISCONNECTED`_ arises, while the reason code is the one specified in the association response. Refer to `Wi-Fi Reason Code`_.
  591. Four-way Handshake Phase
  592. ++++++++++++++++++++++++++
  593. - s4.1: The handshake timer is enabled, and the 1/4 EAPOL is not received before the handshake timer expires. `WIFI_EVENT_STA_DISCONNECTED`_ will arise and the reason code will be ``WIFI_REASON_HANDSHAKE_TIMEOUT``. Refer to `Wi-Fi Reason Code`_.
  594. - s4.2: The 1/4 EAPOL is received.
  595. - s4.3: The station replies 2/4 EAPOL.
  596. - s4.4: If the 3/4 EAPOL is not received before the handshake timer expires, `WIFI_EVENT_STA_DISCONNECTED`_ will arise and the reason code will be ``WIFI_REASON_HANDSHAKE_TIMEOUT``. Refer to `Wi-Fi Reason Code`_.
  597. - s4.5: The 3/4 EAPOL is received.
  598. - s4.6: The station replies 4/4 EAPOL.
  599. - s4.7: The station raises `WIFI_EVENT_STA_CONNECTED`_.
  600. Wi-Fi Reason Code
  601. +++++++++++++++++++++
  602. The table below shows the reason-code defined in {IDF_TARGET_NAME}. The first column is the macro name defined in :component_file:`esp_wifi/include/esp_wifi_types.h`. The common prefix ``WIFI_REASON`` is removed, which means that ``UNSPECIFIED`` actually stands for ``WIFI_REASON_UNSPECIFIED`` and so on. The second column is the value of the reason. The third column is the standard value to which this reason is mapped in section 9.4.1.7 of IEEE 802.11-2020. (For more information, refer to the standard mentioned above.) The last column describes the reason.
  603. .. list-table::
  604. :header-rows: 1
  605. :widths: 5 10 12 40
  606. * - Reason code
  607. - Value
  608. - Mapped To
  609. - Description
  610. * - UNSPECIFIED
  611. - 1
  612. - 1
  613. - Generally, it means an internal failure, e.g., the memory runs out, the internal TX fails, or the reason is received from the remote side.
  614. * - AUTH_EXPIRE
  615. - 2
  616. - 2
  617. - The previous authentication is no longer valid.
  618. For the ESP station, this reason is reported when:
  619. - auth is timed out.
  620. - the reason is received from the AP.
  621. For the ESP AP, this reason is reported when:
  622. - the AP has not received any packets from the station in the past five minutes.
  623. - the AP is stopped by calling :cpp:func:`esp_wifi_stop()`.
  624. - the station is de-authed by calling :cpp:func:`esp_wifi_deauth_sta()`.
  625. * - AUTH_LEAVE
  626. - 3
  627. - 3
  628. - De-authenticated, because the sending station is leaving (or has left).
  629. For the ESP station, this reason is reported when:
  630. - it is received from the AP.
  631. * - ASSOC_EXPIRE
  632. - 4
  633. - 4
  634. - Disassociated due to inactivity.
  635. For the ESP station, this reason is reported when:
  636. - it is received from the AP.
  637. For the ESP AP, this reason is reported when:
  638. - the AP has not received any packets from the station in the past five minutes.
  639. - the AP is stopped by calling :cpp:func:`esp_wifi_stop()`.
  640. - the station is de-authed by calling :cpp:func:`esp_wifi_deauth_sta()`.
  641. * - ASSOC_TOOMANY
  642. - 5
  643. - 5
  644. - Disassociated, because the AP is unable to handle all currently associated STAs at the same time.
  645. For the ESP station, this reason is reported when:
  646. - it is received from the AP.
  647. For the ESP AP, this reason is reported when:
  648. - the stations associated with the AP reach the maximum number that the AP can support.
  649. * - NOT_AUTHED
  650. - 6
  651. - 6
  652. - Class-2 frame received from a non-authenticated STA.
  653. For the ESP station, this reason is reported when:
  654. - it is received from the AP.
  655. For the ESP AP, this reason is reported when:
  656. - the AP receives a packet with data from a non-authenticated station.
  657. * - NOT_ASSOCED
  658. - 7
  659. - 7
  660. - Class-3 frame received from a non-associated STA.
  661. For the ESP station, this reason is reported when:
  662. - it is received from the AP.
  663. For the ESP AP, this reason is reported when:
  664. - the AP receives a packet with data from a non-associated station.
  665. * - ASSOC_LEAVE
  666. - 8
  667. - 8
  668. - Disassociated, because the sending station is leaving (or has left) BSS.
  669. For the ESP station, this reason is reported when:
  670. - it is received from the AP.
  671. - the station is disconnected by :cpp:func:`esp_wifi_disconnect()` and other APIs.
  672. * - ASSOC_NOT_AUTHED
  673. - 9
  674. - 9
  675. - station requesting (re)association is not authenticated by the responding STA.
  676. For the ESP station, this reason is reported when:
  677. - it is received from the AP.
  678. For the ESP AP, this reason is reported when:
  679. - the AP receives packets with data from an associated, yet not authenticated, station.
  680. * - DISASSOC_PWRCAP_BAD
  681. - 10
  682. - 10
  683. - Disassociated, because the information in the Power Capability element is unacceptable.
  684. For the ESP station, this reason is reported when:
  685. - it is received from the AP.
  686. * - DISASSOC_SUPCHAN_BAD
  687. - 11
  688. - 11
  689. - Disassociated, because the information in the Supported Channels element is unacceptable.
  690. For the ESP station, this reason is reported when:
  691. - it is received from the AP.
  692. * - IE_INVALID
  693. - 13
  694. - 13
  695. - Invalid element, i.e., an element whose content does not meet the specifications of the Standard in frame formats clause.
  696. For the ESP station, this reason is reported when:
  697. - it is received from the AP.
  698. For the ESP AP, this reason is reported when:
  699. - the AP parses a wrong WPA or RSN IE.
  700. * - MIC_FAILURE
  701. - 14
  702. - 14
  703. - Message integrity code (MIC) failure.
  704. For the ESP station, this reason is reported when:
  705. - it is received from the AP.
  706. * - 4WAY_HANDSHAKE_TIMEOUT
  707. - 15
  708. - 15
  709. - Four-way handshake times out. For legacy reasons, in ESP this reason code is replaced with ``WIFI_REASON_HANDSHAKE_TIMEOUT``.
  710. For the ESP station, this reason is reported when:
  711. - the handshake times out.
  712. - it is received from the AP.
  713. * - GROUP_KEY_UPDATE_TIMEOUT
  714. - 16
  715. - 16
  716. - Group-Key Handshake times out.
  717. For the ESP station, this reason is reported when:
  718. - it is received from the AP.
  719. * - IE_IN_4WAY_DIFFERS
  720. - 17
  721. - 17
  722. - The element in the four-way handshake is different from the (Re-)Association Request/Probe and Response/Beacon frame.
  723. For the ESP station, this reason is reported when:
  724. - it is received from the AP.
  725. - the station finds that the four-way handshake IE differs from the IE in the (Re-)Association Request/Probe and Response/Beacon frame.
  726. * - GROUP_CIPHER_INVALID
  727. - 18
  728. - 18
  729. - Invalid group cipher.
  730. For the ESP station, this reason is reported when:
  731. - it is received from the AP.
  732. * - PAIRWISE_CIPHER_INVALID
  733. - 19
  734. - 19
  735. - Invalid pairwise cipher.
  736. For the ESP station, this reason is reported when:
  737. - it is received from the AP.
  738. * - AKMP_INVALID
  739. - 20
  740. - 20
  741. - Invalid AKMP.
  742. For the ESP station, this reason is reported when:
  743. - it is received from the AP.
  744. * - UNSUPP_RSN_IE_VERSION
  745. - 21
  746. - 21
  747. - Unsupported RSNE version.
  748. For the ESP station, this reason is reported when:
  749. - it is received from the AP.
  750. * - INVALID_RSN_IE_CAP
  751. - 22
  752. - 22
  753. - Invalid RSNE capabilities.
  754. For the ESP station, this reason is reported when:
  755. - it is received from the AP.
  756. * - 802_1X_AUTH_FAILED
  757. - 23
  758. - 23
  759. - IEEE 802.1X. authentication failed.
  760. For the ESP station, this reason is reported when:
  761. - it is received from the AP.
  762. For the ESP AP, this reason is reported when:
  763. - IEEE 802.1X. authentication fails.
  764. * - CIPHER_SUITE_REJECTED
  765. - 24
  766. - 24
  767. - Cipher suite rejected due to security policies.
  768. For the ESP station, this reason is reported when:
  769. - it is received from the AP.
  770. * - TDLS_PEER_UNREACHABLE
  771. - 25
  772. - 25
  773. - TDLS direct-link teardown due to TDLS peer STA unreachable via the TDLS direct link.
  774. * - TDLS_UNSPECIFIED
  775. - 26
  776. - 26
  777. - TDLS direct-link teardown for unspecified reason.
  778. * - SSP_REQUESTED_DISASSOC
  779. - 27
  780. - 27
  781. - Disassociated because session terminated by SSP request.
  782. * - NO_SSP_ROAMING_AGREEMENT
  783. - 28
  784. - 28
  785. - Disassociated because of lack of SSP roaming agreement.
  786. * - BAD_CIPHER_OR_AKM
  787. - 29
  788. - 29
  789. - Requested service rejected because of SSP cipher suite or AKM requirement.
  790. * - NOT_AUTHORIZED_THIS_LOCATION
  791. - 30
  792. - 30
  793. - Requested service not authorized in this location.
  794. * - SERVICE_CHANGE_PRECLUDES_TS
  795. - 31
  796. - 31
  797. - TS deleted because QoS AP lacks sufficient bandwidth for this QoS STA due to a change in BSS service characteristics or operational mode (e.g., an HT BSS change from 40 MHz channel to 20 MHz channel).
  798. * - UNSPECIFIED_QOS
  799. - 32
  800. - 32
  801. - Disassociated for unspecified, QoS-related reason.
  802. * - NOT_ENOUGH_BANDWIDTH
  803. - 33
  804. - 33
  805. - Disassociated because QoS AP lacks sufficient bandwidth for this QoS STA.
  806. * - MISSING_ACKS
  807. - 34
  808. - 34
  809. - Disassociated because excessive number of frames need to be acknowledged, but are not acknowledged due to AP transmissions and/or poor channel conditions.
  810. * - EXCEEDED_TXOP
  811. - 35
  812. - 35
  813. - Disassociated because STA is transmitting outside the limits of its TXOPs.
  814. * - STA_LEAVING
  815. - 36
  816. - 36
  817. - Requesting STA is leaving the BSS (or resetting).
  818. * - END_BA
  819. - 37
  820. - 37
  821. - Requesting STA is no longer using the stream or session.
  822. * - UNKNOWN_BA
  823. - 38
  824. - 38
  825. - Requesting STA received frames using a mechanism for which a setup has not been completed.
  826. * - TIMEOUT
  827. - 39
  828. - 39
  829. - Requested from peer STA due to timeout
  830. * - Reserved
  831. - 40 ~ 45
  832. - 40 ~ 45
  833. -
  834. * - PEER_INITIATED
  835. - 46
  836. - 46
  837. - In a Disassociation frame: Disassociated because authorized access limit reached.
  838. * - AP_INITIATED
  839. - 47
  840. - 47
  841. - In a Disassociation frame: Disassociated due to external service requirements.
  842. * - INVALID_FT_ACTION_FRAME_COUNT
  843. - 48
  844. - 48
  845. - Invalid FT Action frame count.
  846. * - INVALID_PMKID
  847. - 49
  848. - 49
  849. - Invalid pairwise master key identifier (PMKID).
  850. * - INVALID_MDE
  851. - 50
  852. - 50
  853. - Invalid MDE.
  854. * - INVALID_FTE
  855. - 51
  856. - 51
  857. - Invalid FTE
  858. * - TRANSMISSION_LINK_ESTABLISHMENT_FAILED
  859. - 67
  860. - 67
  861. - Transmission link establishment in alternative channel failed.
  862. * - ALTERATIVE_CHANNEL_OCCUPIED
  863. - 68
  864. - 68
  865. - The alternative channel is occupied.
  866. * - BEACON_TIMEOUT
  867. - 200
  868. - reserved
  869. - Espressif-specific Wi-Fi reason code: when the station loses N beacons continuously, it will disrupt the connection and report this reason.
  870. * - NO_AP_FOUND
  871. - 201
  872. - reserved
  873. - Espressif-specific Wi-Fi reason code: when the station fails to scan the target AP, this reason code will be reported.
  874. * - AUTH_FAIL
  875. - 202
  876. - reserved
  877. - Espressif-specific Wi-Fi reason code: the authentication fails, but not because of a timeout.
  878. * - ASSOC_FAIL
  879. - 203
  880. - reserved
  881. - Espressif-specific Wi-Fi reason code: the association fails, but not because of ASSOC_EXPIRE or ASSOC_TOOMANY.
  882. * - HANDSHAKE_TIMEOUT
  883. - 204
  884. - reserved
  885. - Espressif-specific Wi-Fi reason code: the handshake fails for the same reason as that in WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT.
  886. * - CONNECTION_FAIL
  887. - 205
  888. - reserved
  889. - Espressif-specific Wi-Fi reason code: the connection to the AP has failed.
  890. Wi-Fi Reason code related to wrong password
  891. ++++++++++++++++++++++++++++++++++++++++++++++
  892. The table below shows the Wi-Fi reason-code may related to wrong password.
  893. .. list-table::
  894. :header-rows: 1
  895. :widths: 5 10 40
  896. * - Reason code
  897. - Value
  898. - Description
  899. * - 4WAY_HANDSHAKE_TIMEOUT
  900. - 15
  901. - Four-way handshake times out. Setting wrong password when STA connecting to an encrpyted AP.
  902. * - NO_AP_FOUND
  903. - 201
  904. - This may related to wrong password in the two scenarios:
  905. - Setting password when STA connecting to an unencrypted AP.
  906. - Does not set password when STA connecting to an encrypted AP.
  907. * - HANDSHAKE_TIMEOUT
  908. - 204
  909. - Four-way handshake fails.
  910. Wi-Fi Reason code related to low RSSI
  911. ++++++++++++++++++++++++++++++++++++++++++++++
  912. The table below shows the Wi-Fi reason-code may related to low RSSI.
  913. .. list-table::
  914. :header-rows: 1
  915. :widths: 5 10 40
  916. * - Reason code
  917. - Value
  918. - Description
  919. * - NO_AP_FOUND
  920. - 201
  921. - The station fails to scan the target AP due to low RSSI
  922. * - HANDSHAKE_TIMEOUT
  923. - 204
  924. - Four-way handshake fails.
  925. {IDF_TARGET_NAME} Wi-Fi Station Connecting When Multiple APs Are Found
  926. ----------------------------------------------------------------------
  927. This scenario is similar as `{IDF_TARGET_NAME} Wi-Fi Station Connecting Scenario`_. The difference is that the station will not raise the event `WIFI_EVENT_STA_DISCONNECTED`_ unless it fails to connect all of the found APs.
  928. Wi-Fi Reconnect
  929. ---------------------------
  930. The station may disconnect due to many reasons, e.g., the connected AP is restarted. It is the application's responsibility to reconnect. The recommended reconnection strategy is to call :cpp:func:`esp_wifi_connect()` on receiving event `WIFI_EVENT_STA_DISCONNECTED`_.
  931. Sometimes the application needs more complex reconnection strategy:
  932. - If the disconnect event is raised because the :cpp:func:`esp_wifi_disconnect()` is called, the application may not want to do the reconnection.
  933. - If the :cpp:func:`esp_wifi_scan_start()` may be called at anytime, a better reconnection strategy is necessary. Refer to `Scan When Wi-Fi Is Connecting`_.
  934. Another thing that need to be considered is that the reconnection may not connect the same AP if there are more than one APs with the same SSID. The reconnection always select current best APs to connect.
  935. Wi-Fi Beacon Timeout
  936. ---------------------------
  937. The beacon timeout mechanism is used by {IDF_TARGET_NAME} station to detect whether the AP is alive or not. If the station does not receive the beacon of the connected AP within the inactive time, the beacon timeout happens. The application can set inactive time via API :cpp:func:`esp_wifi_set_inactive_time()`.
  938. After the beacon times out, the station sends 5 probe requests to the AP. If still no probe response or beacon is received from AP, the station disconnects from the AP and raises the event `WIFI_EVENT_STA_DISCONNECTED`_.
  939. It should be considered that the timer used for beacon timeout will be reset during the scanning process. It means that the scan process will affect the triggering of the event `WIFI_EVENT_STA_BEACON_TIMEOUT`_.
  940. {IDF_TARGET_NAME} Wi-Fi Configuration
  941. -------------------------------------
  942. All configurations will be stored into flash when the Wi-Fi NVS is enabled; otherwise, refer to `Wi-Fi NVS Flash`_.
  943. Wi-Fi Mode
  944. +++++++++++++++++++++++++
  945. Call :cpp:func:`esp_wifi_set_mode()` to set the Wi-Fi mode.
  946. .. list-table::
  947. :header-rows: 1
  948. :widths: 15 50
  949. * - Mode
  950. - Description
  951. * - ``WIFI_MODE_NULL``
  952. - NULL mode: in this mode, the internal data struct is not allocated to the station and the AP, while both the station and AP interfaces are not initialized for RX/TX Wi-Fi data. Generally, this mode is used for Sniffer, or when you only want to stop both the station and the AP without calling :cpp:func:`esp_wifi_deinit()` to unload the whole Wi-Fi driver.
  953. * - ``WIFI_MODE_STA``
  954. - Station mode: in this mode, :cpp:func:`esp_wifi_start()` will init the internal station data, while the station’s interface is ready for the RX and TX Wi-Fi data. After :cpp:func:`esp_wifi_connect()`, the station will connect to the target AP.
  955. * - ``WIFI_MODE_AP``
  956. - AP mode: in this mode, :cpp:func:`esp_wifi_start()` will init the internal AP data, while the AP’s interface is ready for RX/TX Wi-Fi data. Then, the Wi-Fi driver starts broad-casting beacons, and the AP is ready to get connected to other stations.
  957. * - ``WIFI_MODE_APSTA``
  958. - Station/AP coexistence mode: in this mode, :cpp:func:`esp_wifi_start()` will simultaneously initialize both the station and the AP. This is done in station mode and AP mode. Please note that the channel of the external AP, which the ESP station is connected to, has higher priority over the ESP AP channel.
  959. Station Basic Configuration
  960. +++++++++++++++++++++++++++++++++++++
  961. API :cpp:func:`esp_wifi_set_config()` can be used to configure the station. And the configuration will be stored in NVS. The table below describes the fields in detail.
  962. .. list-table::
  963. :header-rows: 1
  964. :widths: 15 50
  965. * - Field
  966. - Description
  967. * - ssid
  968. - This is the SSID of the target AP, to which the station wants to connect.
  969. * - password
  970. - Password of the target AP.
  971. * - scan_method
  972. - For ``WIFI_FAST_SCAN`` scan, the scan ends when the first matched AP is found. For ``WIFI_ALL_CHANNEL_SCAN``, the scan finds all matched APs on all channels. The default scan is ``WIFI_FAST_SCAN``.
  973. * - bssid_set
  974. - If bssid_set is 0, the station connects to the AP whose SSID is the same as the field “ssid”, while the field “bssid” is ignored. In all other cases, the station connects to the AP whose SSID is the same as the “ssid” field, while its BSSID is the same the “bssid” field .
  975. * - bssid
  976. - This is valid only when bssid_set is 1; see field “bssid_set”.
  977. * - channel
  978. - If the channel is 0, the station scans the channel 1 ~ N to search for the target AP; otherwise, the station starts by scanning the channel whose value is the same as that of the “channel” field, and then scans the channel 1 ~ N but skip the specific channel to find the target AP. For example, if the channel is 3, the scan order will be 3, 1, 2, 4,..., N. If you do not know which channel the target AP is running on, set it to 0.
  979. * - sort_method
  980. - This field is only for ``WIFI_ALL_CHANNEL_SCAN``.
  981. If the sort_method is ``WIFI_CONNECT_AP_BY_SIGNAL``, all matched APs are sorted by signal, and the AP with the best signal will be connected firstly. For example, the station wants to connect an AP whose SSID is “apxx”. If the scan finds two APs whose SSID equals to “apxx”, and the first AP’s signal is -90 dBm while the second AP’s signal is -30 dBm, the station connects the second AP firstly, and it would not connect the first one unless it fails to connect the second one.
  982. If the sort_method is ``WIFI_CONNECT_AP_BY_SECURITY``, all matched APs are sorted by security. For example, the station wants to connect an AP whose SSID is “apxx”. If the scan finds two APs whose SSID is “apxx”, and the security of the first found AP is open while the second one is WPA2, the station connects to the second AP firstly, and it would not connect the first one unless it fails to connect the second one.
  983. * - threshold
  984. - The threshold is used to filter the found AP. If the RSSI or security mode is less than the configured threshold, the AP will be discarded.
  985. If the RSSI is set to 0, it means the default threshold and the default RSSI threshold are -127 dBm. If the authmode threshold is set to 0, it means the default threshold and the default authmode threshold are open.
  986. .. attention::
  987. WEP/WPA security modes are deprecated in IEEE 802.11-2016 specifications and are recommended not to be used. These modes can be rejected using authmode threshold by setting threshold as WPA2 by threshold.authmode as ``WIFI_AUTH_WPA2_PSK``.
  988. AP Basic Configuration
  989. +++++++++++++++++++++++++++++++++++++
  990. API :cpp:func:`esp_wifi_set_config()` can be used to configure the AP. And the configuration will be stored in NVS. The table below describes the fields in detail.
  991. .. only:: esp32 or esp32s2 or esp32s3 or esp32c3 or esp32c6
  992. .. list-table::
  993. :header-rows: 1
  994. :widths: 15 55
  995. * - Field
  996. - Description
  997. * - ssid
  998. - SSID of AP; if the ssid[0] is 0xFF and ssid[1] is 0xFF, the AP defaults the SSID to ``ESP_aabbcc``, where “aabbcc” is the last three bytes of the AP MAC.
  999. * - password
  1000. - Password of AP; if the auth mode is ``WIFI_AUTH_OPEN``, this field will be ignored.
  1001. * - ssid_len
  1002. - Length of SSID; if ssid_len is 0, check the SSID until there is a termination character. If ssid_len > 32, change it to 32; otherwise, set the SSID length according to ssid_len.
  1003. * - channel
  1004. - Channel of AP; if the channel is out of range, the Wi-Fi driver defaults to channel 1. So, please make sure the channel is within the required range. For more details, refer to `Wi-Fi Country Code`_.
  1005. * - authmode
  1006. - Auth mode of ESP AP; currently, ESP AP does not support AUTH_WEP. If the authmode is an invalid value, AP defaults the value to ``WIFI_AUTH_OPEN``.
  1007. * - ssid_hidden
  1008. - If ssid_hidden is 1, AP does not broadcast the SSID; otherwise, it does broadcast the SSID.
  1009. * - max_connection
  1010. - The max number of stations allowed to connect in, the default value is 10. ESP Wi-Fi supports up to {IDF_TARGET_MAX_CONN_STA_NUM} (``ESP_WIFI_MAX_CONN_NUM``) Wi-Fi connections. Please note that ESP AP and ESP-NOW share the same encryption hardware keys, so the max_connection parameter will be affected by the :ref:`CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM`. The total number of encryption hardware keys is 17, if :ref:`CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM` <= {IDF_TARGET_SUB_MAX_NUM_FROM_KEYS}, the max_connection can be set up to {IDF_TARGET_MAX_CONN_STA_NUM}, otherwise the max_connection can be set up to (17 - :ref:`CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM`).
  1011. * - beacon_interval
  1012. - Beacon interval; the value is 100 ~ 60000 ms, with default value being 100 ms. If the value is out of range, AP defaults it to 100 ms.
  1013. .. only:: esp32c2
  1014. .. list-table::
  1015. :header-rows: 1
  1016. :widths: 15 55
  1017. * - Field
  1018. - Description
  1019. * - ssid
  1020. - SSID of AP; if the ssid[0] is 0xFF and ssid[1] is 0xFF, the AP defaults the SSID to ``ESP_aabbcc``, where “aabbcc” is the last three bytes of the AP MAC.
  1021. * - password
  1022. - Password of AP; if the auth mode is ``WIFI_AUTH_OPEN``, this field will be ignored.
  1023. * - ssid_len
  1024. - Length of SSID; if ssid_len is 0, check the SSID until there is a termination character. If ssid_len > 32, change it to 32; otherwise, set the SSID length according to ssid_len.
  1025. * - channel
  1026. - Channel of AP; if the channel is out of range, the Wi-Fi driver defaults to channel 1. So, please make sure the channel is within the required range. For more details, refer to `Wi-Fi Country Code`_.
  1027. * - authmode
  1028. - Auth mode of ESP AP; currently, ESP AP does not support AUTH_WEP. If the authmode is an invalid value, AP defaults the value to ``WIFI_AUTH_OPEN``.
  1029. * - ssid_hidden
  1030. - If ssid_hidden is 1, AP does not broadcast the SSID; otherwise, it does broadcast the SSID.
  1031. * - max_connection
  1032. - The max number of stations allowed to connect in, the default value is 2. ESP Wi-Fi supports up to {IDF_TARGET_MAX_CONN_STA_NUM} (``ESP_WIFI_MAX_CONN_NUM``) Wi-Fi connections. Please note that ESP AP and ESP-NOW share the same encryption hardware keys, so the max_connection parameter will be affected by the :ref:`CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM`. The total number of encryption hardware keys is {IDF_TARGET_MAX_CONN_STA_NUM}, the max_connection can be set up to ({IDF_TARGET_MAX_CONN_STA_NUM} - :ref:`CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM`).
  1033. * - beacon_interval
  1034. - Beacon interval; the value is 100 ~ 60000 ms, with default value being 100 ms. If the value is out of range, AP defaults it to 100 ms.
  1035. Wi-Fi Protocol Mode
  1036. +++++++++++++++++++++++++
  1037. Currently, the ESP-IDF supports the following protocol modes:
  1038. .. only:: esp32 or esp32s2 or esp32c3 or esp32s3
  1039. .. list-table::
  1040. :header-rows: 1
  1041. :widths: 15 55
  1042. * - Protocol Mode
  1043. - Description
  1044. * - 802.11b
  1045. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B)`` to set the station/AP to 802.11b-only mode.
  1046. * - 802.11bg
  1047. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G)`` to set the station/AP to 802.11bg mode.
  1048. * - 802.11g
  1049. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G)`` and esp_wifi_config_11b_rate(ifx, true) to set the station/AP to 802.11g mode.
  1050. * - 802.11bgn
  1051. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)`` to set the station/ AP to BGN mode.
  1052. * - 802.11gn
  1053. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)`` and esp_wifi_config_11b_rate(ifx, true) to set the station/AP to 802.11gn mode.
  1054. * - 802.11 BGNLR
  1055. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR)`` to set the station/AP to BGN and the LR mode.
  1056. * - 802.11 LR
  1057. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_LR)`` to set the station/AP only to the LR mode.
  1058. **This mode is an Espressif-patented mode which can achieve a one-kilometer line of sight range. Please make sure both the station and the AP are connected to an ESP device.**
  1059. .. only:: esp32c6
  1060. .. list-table::
  1061. :header-rows: 1
  1062. :widths: 15 55
  1063. * - Protocol Mode
  1064. - Description
  1065. * - 802.11b
  1066. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B)`` to set the station/AP to 802.11b-only mode.
  1067. * - 802.11bg
  1068. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G)`` to set the station/AP to 802.11bg mode.
  1069. * - 802.11g
  1070. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G)`` and ``esp_wifi_config_11b_rate(ifx, true)`` to set the station/AP to 802.11g mode.
  1071. * - 802.11bgn
  1072. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)`` to set the station/ AP to BGN mode.
  1073. * - 802.11gn
  1074. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)`` and esp_wifi_config_11b_rate(ifx, true) to set the station/AP to 802.11gn mode.
  1075. * - 802.11 BGNLR
  1076. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR)`` to set the station/AP to BGN and the LR mode.
  1077. * - 802.11bgnax
  1078. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_11AX)`` to set the station/ AP to 802.11bgnax mode.
  1079. * - 802.11 BGNAXLR
  1080. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_11AX|WIFI_PROTOCOL_LR)`` to set the station/ AP to 802.11bgnax and LR mode.
  1081. * - 802.11 LR
  1082. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_LR)`` to set the station/AP only to the LR mode.
  1083. **This mode is an Espressif-patented mode which can achieve a one-kilometer line of sight range. Please make sure both the station and the AP are connected to an ESP device.**
  1084. .. only:: esp32c2
  1085. .. list-table::
  1086. :header-rows: 1
  1087. :widths: 15 55
  1088. * - Protocol Mode
  1089. - Description
  1090. * - 802.11b
  1091. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B)`` to set the station/AP to 802.11b-only mode.
  1092. * - 802.11bg
  1093. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G)`` to set the station/AP to 802.11bg mode.
  1094. * - 802.11g
  1095. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G) and esp_wifi_config_11b_rate(ifx, true)`` to set the station/AP to 802.11g mode.
  1096. * - 802.11bgn
  1097. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)`` to set the station/ AP to BGN mode.
  1098. * - 802.11gn
  1099. - Call ``esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)`` and ``esp_wifi_config_11b_rate(ifx, true)`` to set the station/AP to 802.11gn mode.
  1100. .. only:: esp32 or esp32s2 or esp32c3 or esp32s3 or esp32c6
  1101. Long Range (LR)
  1102. +++++++++++++++++++++++++
  1103. Long Range (LR) mode is an Espressif-patented Wi-Fi mode which can achieve a one-kilometer line of sight range. Compared to the traditional 802.11b mode, it has better reception sensitivity, stronger anti-interference ability, and longer transmission distance.
  1104. LR Compatibility
  1105. *************************
  1106. Since LR is Espressif-unique Wi-Fi mode, only ESP32 chip series devices (except ESP32-C2) can transmit and receive the LR data. In other words, the ESP32 chip series devices (except ESP32-C2) should NOT transmit the data in LR data rate if the connected device does not support LR. The application can achieve this by configuring a suitable Wi-Fi mode. If the negotiated mode supports LR, the ESP32 chip series devices (except ESP32-C2) may transmit data in LR rate. Otherwise, ESP32 chip series devices (except ESP32-C2) will transmit all data in the traditional Wi-Fi data rate.
  1107. The following table depicts the Wi-Fi mode negotiation:
  1108. .. only:: esp32 or esp32s2 or esp32c3 or esp32s3
  1109. +-------+-----+----+---+-------+------+-----+----+
  1110. |AP\STA | BGN | BG | B | BGNLR | BGLR | BLR | LR |
  1111. +=======+=====+====+===+=======+======+=====+====+
  1112. | BGN | BGN | BG | B | BGN | BG | B | - |
  1113. +-------+-----+----+---+-------+------+-----+----+
  1114. | BG | BG | BG | B | BG | BG | B | - |
  1115. +-------+-----+----+---+-------+------+-----+----+
  1116. | B | B | B | B | B | B | B | - |
  1117. +-------+-----+----+---+-------+------+-----+----+
  1118. | BGNLR | - | - | - | BGNLR | BGLR | BLR | LR |
  1119. +-------+-----+----+---+-------+------+-----+----+
  1120. | BGLR | - | - | - | BGLR | BGLR | BLR | LR |
  1121. +-------+-----+----+---+-------+------+-----+----+
  1122. | BLR | - | - | - | BLR | BLR | BLR | LR |
  1123. +-------+-----+----+---+-------+------+-----+----+
  1124. | LR | - | - | - | LR | LR | LR | LR |
  1125. +-------+-----+----+---+-------+------+-----+----+
  1126. .. only:: esp32c6
  1127. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1128. | AP\STA | BGNAX | BGN | BG | B | BGNAXLR | BGNLR | BGLR | BLR | LR |
  1129. +=========+=======+=====+====+===+=========+=======+======+=====+====+
  1130. | BGNAX | BGAX | BGN | BG | B | BGAX | BGN | BG | B | - |
  1131. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1132. | BGN | BGN | BGN | BG | B | BGN | BGN | BG | B | - |
  1133. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1134. | BG | BG | BG | BG | B | BG | BG | BG | B | - |
  1135. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1136. | B | B | B | B | B | B | B | B | B | - |
  1137. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1138. | BGNAXLR | - | - | - | - | BGAXLR | BGNLR | BGLR | BLR | LR |
  1139. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1140. | BGNLR | - | - | - | - | BGNLR | BGNLR | BGLR | BLR | LR |
  1141. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1142. | BGLR | - | - | - | - | BGLR | BGLR | BGLR | BLR | LR |
  1143. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1144. | BLR | - | - | - | - | BLR | BLR | BLR | BLR | LR |
  1145. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1146. | LR | - | - | - | - | LR | LR | LR | LR | LR |
  1147. +---------+-------+-----+----+---+---------+-------+------+-----+----+
  1148. In the above table, the row is the Wi-Fi mode of AP and the column is the Wi-Fi mode of station. The "-" indicates Wi-Fi mode of the AP and station are not compatible.
  1149. According to the table, the following conclusions can be drawn:
  1150. - For LR-enabled AP of {IDF_TARGET_NAME}, it is incompatible with traditional 802.11 mode, because the beacon is sent in LR mode.
  1151. - For LR-enabled station of {IDF_TARGET_NAME} whose mode is NOT LR-only mode, it is compatible with traditional 802.11 mode.
  1152. - If both station and AP are ESP32 series chips devices (except ESP32-C2) and both of them have enabled LR mode, the negotiated mode supports LR.
  1153. If the negotiated Wi-Fi mode supports both traditional 802.11 mode and LR mode, it is the Wi-Fi driver's responsibility to automatically select the best data rate in different Wi-Fi modes and the application can ignore it.
  1154. LR Impacts to Traditional Wi-Fi Device
  1155. ***************************************
  1156. The data transmission in LR rate has no impacts on the traditional Wi-Fi device because:
  1157. - The CCA and backoff process in LR mode are consistent with 802.11 specification.
  1158. - The traditional Wi-Fi device can detect the LR signal via CCA and do backoff.
  1159. In other words, the transmission impact in LR mode is similar to that in 802.11b mode.
  1160. LR Transmission Distance
  1161. *************************
  1162. The reception sensitivity gain of LR is about 4 dB larger than that of the traditional 802.11b mode. Theoretically, the transmission distance is about 2 to 2.5 times the distance of 11B.
  1163. LR Throughput
  1164. *************************
  1165. The LR rate has very limited throughput, because the raw PHY data rate LR is 1/2 Mbps and 1/4 Mbps.
  1166. When to Use LR
  1167. *************************
  1168. The general conditions for using LR are:
  1169. - Both the AP and station are Espressif devices.
  1170. - Long distance Wi-Fi connection and data transmission is required.
  1171. - Data throughput requirements are very small, such as remote device control.
  1172. Wi-Fi Country Code
  1173. +++++++++++++++++++++++++
  1174. Call :cpp:func:`esp_wifi_set_country()` to set the country info. The table below describes the fields in detail. Please consult local 2.4 GHz RF operating regulations before configuring these fields.
  1175. .. list-table::
  1176. :header-rows: 1
  1177. :widths: 15 55
  1178. * - Field
  1179. - Description
  1180. * - cc[3]
  1181. - Country code string. This attribute identifies the country or noncountry entity in which the station/AP is operating. If it is a country, the first two octets of this string is the two-character country info as described in the document ISO/IEC3166-1. The third octet is one of the following:
  1182. - an ASCII space character, which means the regulations under which the station/AP is operating encompass all environments for the current frequency band in the country.
  1183. - an ASCII ‘O’ character, which means the regulations under which the station/AP is operating are for an outdoor environment only.
  1184. - an ASCII ‘I’ character, which means the regulations under which the station/AP is operating are for an indoor environment only.
  1185. - an ASCII ‘X’ character, which means the station/AP is operating under a noncountry entity. The first two octets of the noncountry entity is two ASCII ‘XX’ characters.
  1186. - the binary representation of the Operating Class table number currently in use. Refer to Annex E of IEEE Std 802.11-2020.
  1187. * - schan
  1188. - Start channel. It is the minimum channel number of the regulations under which the station/AP can operate.
  1189. * - nchan
  1190. - Total number of channels as per the regulations. For example, if the schan=1, nchan=13, then the station/AP can send data from channel 1 to 13.
  1191. * - policy
  1192. - Country policy. This field controls which country info will be used if the configured country info is in conflict with the connected AP’s. For more details on related policies, see the following section.
  1193. The default country info is::
  1194. wifi_country_t config = {
  1195. .cc = "01",
  1196. .schan = 1,
  1197. .nchan = 11,
  1198. .policy = WIFI_COUNTRY_POLICY_AUTO,
  1199. };
  1200. If the Wi-Fi Mode is station/AP coexist mode, they share the same configured country info. Sometimes, the country info of AP, to which the station is connected, is different from the country info of configured. For example, the configured station has country info::
  1201. wifi_country_t config = {
  1202. .cc = "JP",
  1203. .schan = 1,
  1204. .nchan = 14,
  1205. .policy = WIFI_COUNTRY_POLICY_AUTO,
  1206. };
  1207. but the connected AP has country info::
  1208. wifi_country_t config = {
  1209. .cc = "CN",
  1210. .schan = 1,
  1211. .nchan = 13,
  1212. };
  1213. then country info of connected AP's is used.
  1214. The following table depicts which country info is used in different Wi-Fi modes and different country policies, and it also describes the impact on active scan.
  1215. .. list-table::
  1216. :header-rows: 1
  1217. :widths: 15 15 35
  1218. * - Wi-Fi Mode
  1219. - Policy
  1220. - Description
  1221. * - Station
  1222. - WIFI_COUNTRY_POLICY_AUTO
  1223. - If the connected AP has country IE in its beacon, the country info equals to the country info in beacon. Otherwise, use the default country info.
  1224. For scan:
  1225. Use active scan from 1 to 11 and use passive scan from 12 to 14.
  1226. Always keep in mind that if an AP with hidden SSID and station is set to a passive scan channel, the passive scan will not find it. In other words, if the application hopes to find the AP with hidden SSID in every channel, the policy of country info should be configured to WIFI_COUNTRY_POLICY_MANUAL.
  1227. * - Station
  1228. - WIFI_COUNTRY_POLICY_MANUAL
  1229. - Always use the configured country info.
  1230. For scan:
  1231. Use active scan from schan to schan+nchan-1.
  1232. * - AP
  1233. - WIFI_COUNTRY_POLICY_AUTO
  1234. - Always use the configured country info.
  1235. * - AP
  1236. - WIFI_COUNTRY_POLICY_MANUAL
  1237. - Always use the configured country info.
  1238. * - Station/AP-coexistence
  1239. - WIFI_COUNTRY_POLICY_AUTO
  1240. - Station: Same as station mode with policy WIFI_COUNTRY_POLICY_AUTO.
  1241. AP: If the station does not connect to any external AP, the AP uses the configured country info. If the station connects to an external AP, the AP has the same country info as the station.
  1242. * - Station/AP-coexistence
  1243. - WIFI_COUNTRY_POLICY_MANUAL
  1244. - Station: Same as station mode with policy WIFI_COUNTRY_POLICY_MANUAL.
  1245. AP: Same as AP mode with policy WIFI_COUNTRY_POLICY_MANUAL.
  1246. Home Channel
  1247. *************************
  1248. In AP mode, the home channel is defined as the AP channel. In station mode, home channel is defined as the channel of AP which the station is connected to. In station/AP-coexistence mode, the home channel of AP and station must be the same, and if they are different, the station's home channel is always in priority. For example, assume that the AP is on channel 6, and the station connects to an AP whose channel is 9. Since the station's home channel has higher priority, the AP needs to switch its channel from 6 to 9 to make sure that it has the same home channel as the station. While switching channel, the {IDF_TARGET_NAME} in AP mode will notify the connected stations about the channel migration using a Channel Switch Announcement (CSA). Station that supports channel switching will transit without disconnecting and reconnecting to the AP.
  1249. Wi-Fi Vendor IE Configuration
  1250. +++++++++++++++++++++++++++++++++++
  1251. By default, all Wi-Fi management frames are processed by the Wi-Fi driver, and the application can ignore them. However, some applications may have to handle the beacon, probe request, probe response, and other management frames. For example, if you insert some vendor-specific IE into the management frames, it is only the management frames which contain this vendor-specific IE that will be processed. In {IDF_TARGET_NAME}, :cpp:func:`esp_wifi_set_vendor_ie()` and :cpp:func:`esp_wifi_set_vendor_ie_cb()` are responsible for this kind of tasks.
  1252. Wi-Fi Easy Connect™ (DPP)
  1253. --------------------------
  1254. Wi-Fi Easy Connect\ :sup:`TM` (or Device Provisioning Protocol) is a secure and standardized provisioning protocol for configuring Wi-Fi devices. More information can be found in :doc:`esp_dpp <../api-reference/network/esp_dpp>`.
  1255. WPA2-Enterprise
  1256. +++++++++++++++++++++++++++++++++
  1257. WPA2-Enterprise is the secure authentication mechanism for enterprise wireless networks. It uses RADIUS server for authentication of network users before connecting to the Access Point. The authentication process is based on 802.1X policy and comes with different Extended Authentication Protocol (EAP) methods such as TLS, TTLS, and PEAP. RADIUS server authenticates the users based on their credentials (username and password), digital certificates, or both. When {IDF_TARGET_NAME} in station mode tries to connect an AP in enterprise mode, it sends authentication request to AP which is sent to RADIUS server by AP for authenticating the station. Based on different EAP methods, the parameters can be set in configuration which can be opened using ``idf.py menuconfig``. WPA2_Enterprise is supported by {IDF_TARGET_NAME} only in station mode.
  1258. For establishing a secure connection, AP and station negotiate and agree on the best possible cipher suite to be used. {IDF_TARGET_NAME} supports 802.1X/EAP (WPA) method of AKM and Advanced encryption standard with Counter Mode Cipher Block Chaining Message Authentication protocol (AES-CCM) cipher suite. It also supports the cipher suites supported by mbedtls if `USE_MBEDTLS_CRYPTO` flag is set.
  1259. {IDF_TARGET_NAME} currently supports the following EAP methods:
  1260. - EAP-TLS: This is a certificate-based method and only requires SSID and EAP-IDF.
  1261. - PEAP: This is a Protected EAP method. Username and Password are mandatory.
  1262. - EAP-TTLS: This is a credential-based method. Only server authentication is mandatory while user authentication is optional. Username and Password are mandatory. It supports different Phase2 methods, such as:
  1263. - PAP: Password Authentication Protocol.
  1264. - CHAP: Challenge Handshake Authentication Protocol.
  1265. - MSCHAP and MSCHAP-V2.
  1266. - EAP-FAST: This is an authentication method based on Protected Access Credentials (PAC) which also uses identity and password. Currently, USE_MBEDTLS_CRYPTO flag should be disabled to use this feature.
  1267. Detailed information on creating certificates and how to run wpa2_enterprise example on {IDF_TARGET_NAME} can be found in :example:`wifi/wifi_enterprise`.
  1268. .. only:: SOC_WIFI_NAN_SUPPORT
  1269. Wi-Fi Aware\ :sup:`TM` (NAN)
  1270. ----------------------------
  1271. Wi-Fi Aware\ :sup:`TM` or NAN (Neighbor Awareness Networking) is a protocol that allows Wi-Fi devices to discover services in their proximity. NAN uses direct device-to-device communication and does not require any Internet or AP connection.
  1272. Multiple NAN devices in the vicinity will form a NAN cluster which allows them to communicate with each other. NAN devices in a cluster synchronise their clocks and listen to each other periodically on Channel 6. Devices can advertise (Publish) or seek for (Subscribe) services within their NAN Cluster using Service Discovery protocols. Matching of services is done by service name and optionally matching filters. Once a Subscriber gets a match with a Publisher, it can either send a message (Follow-up) or establish a datapath (NDP) with the Publisher. After NDP is setup both devices will obtain an IPv6 address and can use it for communication.
  1273. Please note that NAN Datapath security is not supported i.e., the data packets will go out unencrypted. NAN uses a separate interface for Discovery and Datapath, which is other than that used for STA and AP. NAN operates in standalone mode, which means co-existence with STA or AP interface is not supported.
  1274. Refer to ESP-IDF examples :idf_file:`examples/wifi/wifi_aware/nan_publisher/README.md` and :idf_file:`examples/wifi/wifi_aware/nan_subscriber/README.md` to setup a NAN Publisher and Subscriber.
  1275. Wireless Network Management
  1276. ----------------------------
  1277. Wireless Network Management allows client devices to exchange information about the network topology, including information related to RF environment. This makes each client network-aware, facilitating overall improvement in the performance of the wireless network. It is part of 802.11v specification. It also enables the client to support Network assisted Roaming.
  1278. - Network assisted Roaming: Enables WLAN to send messages to associated clients, resulting clients to associate with APs with better link metrics. This is useful for both load balancing and in directing poorly connected clients.
  1279. Current implementation of 802.11v includes support for BSS transition management frames.
  1280. Radio Resource Measurement
  1281. ---------------------------
  1282. Radio Resource Measurement (802.11k) is intended to improve the way traffic is distributed within a network. In a WLAN, each device normally connects to the access point (AP) that provides the strongest signal. Depending on the number and geographic locations of the subscribers, this arrangement can sometimes lead to excessive demand on one AP and underutilization of others, resulting in degradation of overall network performance. In a network conforming to 802.11k, if the AP having the strongest signal is loaded to its full capacity, a wireless device can be moved to one of the underutilized APs. Even though the signal may be weaker, the overall throughput is greater because more efficient use is made of the network resources.
  1283. Current implementation of 802.11k includes support for beacon measurement report, link measurement report, and neighbor request.
  1284. Refer ESP-IDF example :idf_file:`examples/wifi/roaming/README.md` to set up and use these APIs. Example code only demonstrates how these APIs can be used, and the application should define its own algorithm and cases as required.
  1285. Fast BSS Transition
  1286. ---------------------------
  1287. Fast BSS transition (802.11R FT), is a standard to permit continuous connectivity aboard wireless devices in motion, with fast and secure client transitions from one Basic Service Set (abbreviated BSS, and also known as a base station or more colloquially, an access point) to another performed in a nearly seamless manner **avoiding 802.1i 4 way handshake** . 802.11R specifies transitions between access points by redefining the security key negotiation protocol, allowing both the negotiation and requests for wireless resources to occur in parallel. The key derived from the server to be cached in the wireless network, so that a reasonable number of future connections can be based on the cached key, avoiding the 802.1X process
  1288. {IDF_TARGET_NAME} station supports FT for WPA2-PSK networks. Do note that {IDF_TARGET_NAME} station only support FT over the air protocol only.
  1289. A config option :ref:`CONFIG_ESP_WIFI_11R_SUPPORT` and configuration parameter :cpp:type:`ft_enabled` in :cpp:type:`wifi_sta_config_t` is provided to enable 802.11R support for station. Refer ESP-IDF example :idf_file:`examples/wifi/roaming/README.md` for further details.
  1290. .. only:: SOC_WIFI_FTM_SUPPORT
  1291. Wi-Fi Location
  1292. -------------------------------
  1293. Wi-Fi Location will improve the accuracy of a device's location data beyond the Access Point, which will enable creation of new and feature-rich applications and services such as geo-fencing, network management, and navigation. One of the protocols used to determine the device location with respect to the Access Point is Fine Timing Measurement which calculates Time-of-Flight of a Wi-Fi frame.
  1294. Fine Timing Measurement (FTM)
  1295. +++++++++++++++++++++++++++++
  1296. FTM is used to measure Wi-Fi Round Trip Time (Wi-Fi RTT) which is the time a Wi-Fi signal takes to travel from a device to another device and back again. Using Wi-Fi RTT, the distance between the devices can be calculated with a simple formula of `RTT * c / 2`, where c is the speed of light.
  1297. FTM uses timestamps given by Wi-Fi interface hardware at the time of arrival or departure of frames exchanged between a pair of devices. One entity called FTM Initiator (mostly a station device) discovers the FTM Responder (can be a station or an Access Point) and negotiates to start an FTM procedure. The procedure uses multiple Action frames sent in bursts and its ACK's to gather the timestamps data. FTM Initiator gathers the data in the end to calculate an average Round-Trip-Time.
  1298. {IDF_TARGET_NAME} supports FTM in below configuration:
  1299. - {IDF_TARGET_NAME} as FTM Initiator in station mode.
  1300. - {IDF_TARGET_NAME} as FTM Responder in AP mode.
  1301. Distance measurement using RTT is not accurate, and factors such as RF interference, multi-path travel, antenna orientation, and lack of calibration increase these inaccuracies. For better results, it is suggested to perform FTM between two ESP32 chip series devices (except ESP32-C2) as station and AP.
  1302. Refer to ESP-IDF example :idf_file:`examples/wifi/ftm/README.md` for steps on how to set up and perform FTM.
  1303. {IDF_TARGET_NAME} Wi-Fi Power-saving Mode
  1304. -----------------------------------------
  1305. Station Sleep
  1306. ++++++++++++++++++++++
  1307. Currently, {IDF_TARGET_NAME} Wi-Fi supports the Modem-sleep mode which refers to the legacy power-saving mode in the IEEE 802.11 protocol. Modem-sleep mode works in station-only mode and the station must connect to the AP first. If the Modem-sleep mode is enabled, station will switch between active and sleep state periodically. In sleep state, RF, PHY and BB are turned off in order to reduce power consumption. Station can keep connection with AP in modem-sleep mode.
  1308. Modem-sleep mode includes minimum and maximum power-saving modes. In minimum power-saving mode, station wakes up every DTIM to receive beacon. Broadcast data will not be lost because it is transmitted after DTIM. However, it cannot save much more power if DTIM is short for DTIM is determined by AP.
  1309. In maximum power-saving mode, station wakes up in every listen interval to receive beacon. This listen interval can be set to be longer than the AP DTIM period. Broadcast data may be lost because station may be in sleep state at DTIM time. If listen interval is longer, more power is saved, but broadcast data is more easy to lose. Listen interval can be configured by calling API :cpp:func:`esp_wifi_set_config()` before connecting to AP.
  1310. Call ``esp_wifi_set_ps(WIFI_PS_MIN_MODEM)`` to enable Modem-sleep minimum power-saving mode or ``esp_wifi_set_ps(WIFI_PS_MAX_MODEM)`` to enable Modem-sleep maximum power-saving mode after calling :cpp:func:`esp_wifi_init()`. When station connects to AP, Modem-sleep will start. When station disconnects from AP, Modem-sleep will stop.
  1311. Call ``esp_wifi_set_ps(WIFI_PS_NONE)`` to disable Modem-sleep mode entirely. Disabling it increases power consumption, but minimizes the delay in receiving Wi-Fi data in real time. When Modem-sleep mode is enabled, the delay in receiving Wi-Fi data may be the same as the DTIM cycle (minimum power-saving mode) or the listening interval (maximum power-saving mode).
  1312. .. only:: SOC_SUPPORT_COEXISTENCE
  1313. Note that in coexist mode, Wi-Fi will remain active only during Wi-Fi time slice, and sleep during non Wi-Fi time slice even if ``esp_wifi_set_ps(WIFI_PS_NONE)`` is called. Please refer to :ref:`coexist policy <coexist_policy>`.
  1314. The default Modem-sleep mode is WIFI_PS_MIN_MODEM.
  1315. AP Sleep
  1316. +++++++++++++++++++++++++++++++
  1317. Currently, {IDF_TARGET_NAME} AP does not support all of the power-saving feature defined in Wi-Fi specification. To be specific, the AP only caches unicast data for the stations connect to this AP, but does not cache the multicast data for the stations. If stations connected to the {IDF_TARGET_NAME} AP are power-saving enabled, they may experience multicast packet loss.
  1318. In the future, all power-saving features will be supported on {IDF_TARGET_NAME} AP.
  1319. Disconnected State Sleep
  1320. +++++++++++++++++++++++++++++++
  1321. Disconnected state is the duration without Wi-Fi connection between :cpp:func:`esp_wifi_start` to :cpp:func:`esp_wifi_stop`.
  1322. Currently, {IDF_TARGET_NAME} Wi-Fi supports sleep mode in disconnected state if running at station mode. This feature could be configured by Menuconfig choice :ref:`CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE`.
  1323. If :ref:`CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE` is enabled, RF, PHY and BB would be turned off in disconnected state when IDLE. The current would be same with current at modem-sleep.
  1324. The choice :ref:`CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE` would be selected by default, while it would be selected forcefully in Menuconfig at coexistence mode.
  1325. .. _connectionless-module-power-save:
  1326. Connectionless Modules Power-saving
  1327. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1328. Connectionless modules are those Wi-Fi modules not relying on Wi-Fi connection, e.g ESP-NOW, DPP, FTM. These modules start from :cpp:func:`esp_wifi_start`, working until :cpp:func:`esp_wifi_stop`.
  1329. Currently, if ESP-NOW works at station mode, its supported to sleep at both connected state and disconnected state.
  1330. Connectionless Modules TX
  1331. *******************************
  1332. For each connectionless module, its supported to TX at any sleeping time without any extra configuration.
  1333. Meanwhile, :cpp:func:`esp_wifi_80211_tx` is supported at sleep as well.
  1334. Connectionless Modules RX
  1335. *******************************
  1336. For each connectionless module, two parameters shall be configured to RX at sleep, which are `Window` and `Interval`.
  1337. At the start of `Interval` time, RF, PHY, BB would be turned on and kept for `Window` time. Connectionless Module could RX in the duration.
  1338. **Interval**
  1339. - There is only one `Interval`. Its configured by :cpp:func:`esp_wifi_set_connectionless_interval`. The unit is milliseconds.
  1340. - The default value of `Interval` is `ESP_WIFI_CONNECTIONLESS_INTERVAL_DEFAULT_MODE`.
  1341. - Event `WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START`_ would be posted at the start of `Interval`. Since `Window` also starts at that moment, its recommended to TX in that event.
  1342. - At connected state, the start of `Interval` would be aligned with TBTT.
  1343. **Window**
  1344. - Each connectionless module has its own `Window` after start. Connectionless Modules Power-saving would work with the max one among them.
  1345. - `Window` is configured by :cpp:func:`module_name_set_wake_window`. The unit is milliseconds.
  1346. - The default value of `Window` is the maximum.
  1347. .. table:: RF, PHY and BB usage under different circumstances
  1348. +----------------------+-----------------------------------------------------+---------------------------------------------------------------------------+
  1349. | | Interval |
  1350. + +-----------------------------------------------------+---------------------------------------------------------------------------+
  1351. | | ``ESP_WIFI_CONNECTIONLESS_INTERVAL_DEFAULT_MODE`` | 1 - maximum |
  1352. +--------+-------------+-----------------------------------------------------+---------------------------------------------------------------------------+
  1353. | Window | 0 | not used |
  1354. + +-------------+-----------------------------------------------------+---------------------------------------------------------------------------+
  1355. | | 1 - maximum | default mode | used periodically (Window < Interval) / used all time (Window ≥ Interval) |
  1356. +--------+-------------+-----------------------------------------------------+---------------------------------------------------------------------------+
  1357. Default Mode
  1358. *******************************
  1359. If `Interval` is ``ESP_WIFI_CONNECTIONLESS_INTERVAL_DEFAULT_MODE`` with non-zero `Window`, Connectionless Modules Power-saving would work in default mode.
  1360. In default mode, RF, PHY, BB would be kept on if no coexistence with non-Wi-Fi protocol.
  1361. With coexistence, RF, PHY, BB resources are allocated by coexistence module to Wi-Fi connectionless module and non-Wi-Fi module, using time-division method. In default mode, Wi-Fi connectionless module is allowed to use RF, BB, PHY periodically under a stable performance.
  1362. Its recommended to configure Connectionless Modules Power-saving to default mode if there is Wi-Fi connectionless module coexists with non-Wi-Fi module.
  1363. {IDF_TARGET_NAME} Wi-Fi Throughput
  1364. -----------------------------------
  1365. The table below shows the best throughput results gained in Espressif's lab and in a shielded box.
  1366. .. only:: esp32
  1367. .. list-table::
  1368. :header-rows: 1
  1369. :widths: 10 10 10 10 25
  1370. * - Type/Throughput
  1371. - Air In Lab
  1372. - Shield-box
  1373. - Test Tool
  1374. - IDF Version (commit ID)
  1375. * - Raw 802.11 Packet RX
  1376. - N/A
  1377. - **130 MBit/s**
  1378. - Internal tool
  1379. - NA
  1380. * - Raw 802.11 Packet TX
  1381. - N/A
  1382. - **130 MBit/s**
  1383. - Internal tool
  1384. - NA
  1385. * - UDP RX
  1386. - 30 MBit/s
  1387. - 85 MBit/s
  1388. - iperf example
  1389. - 15575346
  1390. * - UDP TX
  1391. - 30 MBit/s
  1392. - 75 MBit/s
  1393. - iperf example
  1394. - 15575346
  1395. * - TCP RX
  1396. - 20 MBit/s
  1397. - 65 MBit/s
  1398. - iperf example
  1399. - 15575346
  1400. * - TCP TX
  1401. - 20 MBit/s
  1402. - 75 MBit/s
  1403. - iperf example
  1404. - 15575346
  1405. When the throughput is tested by iperf example, the sdkconfig is :idf_file:`examples/wifi/iperf/sdkconfig.defaults.esp32`.
  1406. .. only:: esp32s2
  1407. .. list-table::
  1408. :header-rows: 1
  1409. :widths: 10 10 10 10 25
  1410. * - Type/Throughput
  1411. - Air In Lab
  1412. - Shield-box
  1413. - Test Tool
  1414. - IDF Version (commit ID)
  1415. * - Raw 802.11 Packet RX
  1416. - N/A
  1417. - **130 MBit/s**
  1418. - Internal tool
  1419. - NA
  1420. * - Raw 802.11 Packet TX
  1421. - N/A
  1422. - **130 MBit/s**
  1423. - Internal tool
  1424. - NA
  1425. * - UDP RX
  1426. - 30 MBit/s
  1427. - 70 MBit/s
  1428. - iperf example
  1429. - 15575346
  1430. * - UDP TX
  1431. - 30 MBit/s
  1432. - 50 MBit/s
  1433. - iperf example
  1434. - 15575346
  1435. * - TCP RX
  1436. - 20 MBit/s
  1437. - 32 MBit/s
  1438. - iperf example
  1439. - 15575346
  1440. * - TCP TX
  1441. - 20 MBit/s
  1442. - 37 MBit/s
  1443. - iperf example
  1444. - 15575346
  1445. When the throughput is tested by iperf example, the sdkconfig is :idf_file:`examples/wifi/iperf/sdkconfig.defaults.esp32s2`.
  1446. .. only:: esp32c3
  1447. .. list-table::
  1448. :header-rows: 1
  1449. :widths: 10 10 10 15 20
  1450. * - Type/Throughput
  1451. - Air In Lab
  1452. - Shield-box
  1453. - Test Tool
  1454. - IDF Version (commit ID)
  1455. * - Raw 802.11 Packet RX
  1456. - N/A
  1457. - **130 MBit/s**
  1458. - Internal tool
  1459. - NA
  1460. * - Raw 802.11 Packet TX
  1461. - N/A
  1462. - **130 MBit/s**
  1463. - Internal tool
  1464. - NA
  1465. * - UDP RX
  1466. - 30 MBit/s
  1467. - 50 MBit/s
  1468. - iperf example
  1469. - 15575346
  1470. * - UDP TX
  1471. - 30 MBit/s
  1472. - 40 MBit/s
  1473. - iperf example
  1474. - 15575346
  1475. * - TCP RX
  1476. - 20 MBit/s
  1477. - 35 MBit/s
  1478. - iperf example
  1479. - 15575346
  1480. * - TCP TX
  1481. - 20 MBit/s
  1482. - 37 MBit/s
  1483. - iperf example
  1484. - 15575346
  1485. When the throughput is tested by iperf example, the sdkconfig is :idf_file:`examples/wifi/iperf/sdkconfig.defaults.esp32c3`.
  1486. .. only:: esp32c6
  1487. .. list-table::
  1488. :header-rows: 1
  1489. :widths: 10 10 10 15 20
  1490. * - Type/Throughput
  1491. - Air In Lab
  1492. - Shield-box
  1493. - Test Tool
  1494. - IDF Version (commit ID)
  1495. * - Raw 802.11 Packet RX
  1496. - N/A
  1497. - **130 MBit/s**
  1498. - Internal tool
  1499. - NA
  1500. * - Raw 802.11 Packet TX
  1501. - N/A
  1502. - **130 MBit/s**
  1503. - Internal tool
  1504. - NA
  1505. * - UDP RX
  1506. - 30 MBit/s
  1507. - 45 MBit/s
  1508. - iperf example
  1509. - 420ebd20
  1510. * - UDP TX
  1511. - 30 MBit/s
  1512. - 40 MBit/s
  1513. - iperf example
  1514. - 420ebd20
  1515. * - TCP RX
  1516. - 20 MBit/s
  1517. - 30 MBit/s
  1518. - iperf example
  1519. - 420ebd20
  1520. * - TCP TX
  1521. - 20 MBit/s
  1522. - 31 MBit/s
  1523. - iperf example
  1524. - 420ebd20
  1525. When the throughput is tested by iperf example, the sdkconfig is :idf_file:`examples/wifi/iperf/sdkconfig.defaults.esp32c6`.
  1526. .. only:: esp32s3
  1527. .. list-table::
  1528. :header-rows: 1
  1529. :widths: 10 10 10 15 20
  1530. * - Type/Throughput
  1531. - Air In Lab
  1532. - Shield-box
  1533. - Test Tool
  1534. - IDF Version (commit ID)
  1535. * - Raw 802.11 Packet RX
  1536. - N/A
  1537. - **130 MBit/s**
  1538. - Internal tool
  1539. - NA
  1540. * - Raw 802.11 Packet TX
  1541. - N/A
  1542. - **130 MBit/s**
  1543. - Internal tool
  1544. - NA
  1545. * - UDP RX
  1546. - 30 MBit/s
  1547. - 88 MBit/s
  1548. - iperf example
  1549. - 15575346
  1550. * - UDP TX
  1551. - 30 MBit/s
  1552. - 98 MBit/s
  1553. - iperf example
  1554. - 15575346
  1555. * - TCP RX
  1556. - 20 MBit/s
  1557. - 73 MBit/s
  1558. - iperf example
  1559. - 15575346
  1560. * - TCP TX
  1561. - 20 MBit/s
  1562. - 83 MBit/s
  1563. - iperf example
  1564. - 15575346
  1565. When the throughput is tested by iperf example, the sdkconfig is :idf_file:`examples/wifi/iperf/sdkconfig.defaults.esp32s3`.
  1566. Wi-Fi 80211 Packet Send
  1567. ---------------------------
  1568. The :cpp:func:`esp_wifi_80211_tx()` API can be used to:
  1569. - Send the beacon, probe request, probe response, and action frame.
  1570. - Send the non-QoS data frame.
  1571. It cannot be used for sending encrypted or QoS frames.
  1572. Preconditions of Using :cpp:func:`esp_wifi_80211_tx()`
  1573. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1574. - The Wi-Fi mode is station, or AP, or station/AP.
  1575. - Either ``esp_wifi_set_promiscuous(true)``, or :cpp:func:`esp_wifi_start()`, or both of these APIs return :c:macro:`ESP_OK`. This is because Wi-Fi hardware must be initialized before :cpp:func:`esp_wifi_80211_tx()` is called. In {IDF_TARGET_NAME}, both ``esp_wifi_set_promiscuous(true)`` and :cpp:func:`esp_wifi_start()` can trigger the initialization of Wi-Fi hardware.
  1576. - The parameters of :cpp:func:`esp_wifi_80211_tx()` are hereby correctly provided.
  1577. Data Rate
  1578. +++++++++++++++++++++++++++++++++++++++++++++++
  1579. - The default data rate is 1 Mbps.
  1580. - Can set any rate through :cpp:func:`esp_wifi_config_80211_tx_rate()` API.
  1581. - Can set any bandwidth through :cpp:func:`esp_wifi_set_bandwidth()` API.
  1582. Side-Effects to Avoid in Different Scenarios
  1583. +++++++++++++++++++++++++++++++++++++++++++++++++++++
  1584. Theoretically, if the side-effects the API imposes on the Wi-Fi driver or other stations/APs are not considered, a raw 802.11 packet can be sent over the air with any destination MAC, any source MAC, any BSSID, or any other types of packet. However, robust or useful applications should avoid such side-effects. The table below provides some tips and recommendations on how to avoid the side-effects of :cpp:func:`esp_wifi_80211_tx()` in different scenarios.
  1585. .. list-table::
  1586. :header-rows: 1
  1587. :widths: 10 50
  1588. * - Scenario
  1589. - Description
  1590. * - No Wi-Fi connection
  1591. - In this scenario, no Wi-Fi connection is set up, so there are no side-effects on the Wi-Fi driver. If ``en_sys_seq==true``, the Wi-Fi driver is responsible for the sequence control. If ``en_sys_seq==false``, the application needs to ensure that the buffer has the correct sequence.
  1592. Theoretically, the MAC address can be any address. However, this may impact other stations/APs with the same MAC/BSSID.
  1593. Side-effect example#1 The application calls :cpp:func:`esp_wifi_80211_tx()` to send a beacon with BSSID == mac_x in AP mode, but the mac_x is not the MAC of the AP interface. Moreover, there is another AP, e.g., “other-AP”, whose BSSID is mac_x. If this happens, an “unexpected behavior” may occur, because the stations which connect to the “other-AP” cannot figure out whether the beacon is from the “other-AP” or the :cpp:func:`esp_wifi_80211_tx()`.
  1594. To avoid the above-mentioned side-effects, it is recommended that:
  1595. - If :cpp:func:`esp_wifi_80211_tx` is called in station mode, the first MAC should be a multicast MAC or the exact target-device’s MAC, while the second MAC should be that of the station interface.
  1596. - If :cpp:func:`esp_wifi_80211_tx` is called in AP mode, the first MAC should be a multicast MAC or the exact target-device’s MAC, while the second MAC should be that of the AP interface.
  1597. The recommendations above are only for avoiding side-effects and can be ignored when there are good reasons.
  1598. * - Have Wi-Fi connection
  1599. - When the Wi-Fi connection is already set up, and the sequence is controlled by the application, the latter may impact the sequence control of the Wi-Fi connection as a whole. So, the ``en_sys_seq`` need to be true, otherwise ``ESP_ERR_INVALID_ARG`` is returned.
  1600. The MAC-address recommendations in the “No Wi-Fi connection” scenario also apply to this scenario.
  1601. If the Wi-Fi mode is station mode, the MAC address1 is the MAC of AP to which the station is connected, and the MAC address2 is the MAC of station interface, it is said that the packet is sent from the station to AP. Otherwise, if the Wi-Fi is in AP mode, the MAC address1 is the MAC of the station that connects to this AP, and the MAC address2 is the MAC of AP interface, it is said that the packet is sent from the AP to station. To avoid conflicting with Wi-Fi connections, the following checks are applied:
  1602. - If the packet type is data and is sent from the station to AP, the ToDS bit in IEEE 80211 frame control should be 1 and the FromDS bit should be 0. Otherwise, the packet will be discarded by Wi-Fi driver.
  1603. - If the packet type is data and is sent from the AP to station, the ToDS bit in IEEE 80211 frame control should be 0 and the FromDS bit should be 1. Otherwise, the packet will be discarded by Wi-Fi driver.
  1604. - If the packet is sent from station to AP or from AP to station, the Power Management, More Data, and Re-Transmission bits should be 0. Otherwise, the packet will be discarded by Wi-Fi driver.
  1605. ``ESP_ERR_INVALID_ARG`` is returned if any check fails.
  1606. Wi-Fi Sniffer Mode
  1607. ---------------------------
  1608. The Wi-Fi sniffer mode can be enabled by :cpp:func:`esp_wifi_set_promiscuous`. If the sniffer mode is enabled, the following packets **can** be dumped to the application:
  1609. - 802.11 Management frame.
  1610. - 802.11 Data frame, including MPDU, AMPDU, and AMSDU.
  1611. - 802.11 MIMO frame, for MIMO frame, the sniffer only dumps the length of the frame.
  1612. - 802.11 Control frame.
  1613. - 802.11 CRC error frame.
  1614. The following packets will **NOT** be dumped to the application:
  1615. - Other 802.11 error frames.
  1616. For frames that the sniffer **can** dump, the application can additionally decide which specific type of packets can be filtered to the application by using :cpp:func:`esp_wifi_set_promiscuous_filter()` and :cpp:func:`esp_wifi_set_promiscuous_ctrl_filter()`. By default, it will filter all 802.11 data and management frames to the application.
  1617. The Wi-Fi sniffer mode can be enabled in the Wi-Fi mode of :cpp:enumerator:`WIFI_MODE_NULL`, :cpp:enumerator:`WIFI_MODE_STA`, :cpp:enumerator:`WIFI_MODE_AP`, or :cpp:enumerator:`WIFI_MODE_APSTA`. In other words, the sniffer mode is active when the station is connected to the AP, or when the AP has a Wi-Fi connection. Please note that the sniffer has a **great impact** on the throughput of the station or AP Wi-Fi connection. Generally, the sniffer should be enabled **only if** the station/AP Wi-Fi connection does not experience heavy traffic.
  1618. Another noteworthy issue about the sniffer is the callback :cpp:type:`wifi_promiscuous_cb_t`. The callback will be called directly in the Wi-Fi driver task, so if the application has a lot of work to do for each filtered packet, the recommendation is to post an event to the application task in the callback and defer the real work to the application task.
  1619. Wi-Fi Multiple Antennas
  1620. --------------------------
  1621. The Wi-Fi multiple antennas selecting can be depicted as following picture::
  1622. __________
  1623. |Enabled |
  1624. ___|Antenna 0 |\\ _________
  1625. |__________| \\ GPIO[0] <----> antenna_select[0] ---| | --- antenna 0
  1626. RX/TX ___ \\____\ GPIO[1] <----> antenna_select[1] ---| Antenna | --- antenna 1
  1627. \ __________ // / GPIO[2] <----> antenna_select[2] ---| Switch | ... ...
  1628. \ ___|Enabled | // GPIO[3] <----> antenna_select[3] ---|_________| --- antenna 15
  1629. \ |Antenna 1 |//
  1630. |__________|
  1631. {IDF_TARGET_NAME} supports up to sixteen antennas through external antenna switch. The antenna switch can be controlled by up to four address pins - antenna_select[0:3]. Different input value of antenna_select[0:3] means selecting different antenna. For example, the value '0b1011' means the antenna 11 is selected. The default value of antenna_select[3:0] is '0b0000', which means the antenna 0 is selected by default.
  1632. Up to four GPIOs are connected to the four active high antenna_select pins. {IDF_TARGET_NAME} can select the antenna by control the GPIO[0:3]. The API :cpp:func:`esp_wifi_set_ant_gpio()` is used to configure which GPIOs are connected to antenna_selects. If GPIO[x] is connected to antenna_select[x], then gpio_config->gpio_cfg[x].gpio_select should be set to 1 and gpio_config->gpio_cfg[x].gpio_num should be provided.
  1633. For the specific implementation of the antenna switch, there may be illegal values in `antenna_select[0:3]`. It means that {IDF_TARGET_NAME} may support less than sixteen antennas through the switch. For example, ESP32-WROOM-DA which uses RTC6603SP as the antenna switch, supports two antennas. Two GPIOs are connected to two active high antenna selection inputs. The value '0b01' means the antenna 0 is selected, the value '0b10' means the antenna 1 is selected. Values '0b00' and '0b11' are illegal.
  1634. Although up to sixteen antennas are supported, only one or two antennas can be simultaneously enabled for RX/TX. The API :cpp:func:`esp_wifi_set_ant()` is used to configure which antennas are enabled.
  1635. The enabled antennas selecting algorithm is also configured by :cpp:func:`esp_wifi_set_ant()`. The RX/TX antenna mode can be :cpp:enumerator:`WIFI_ANT_MODE_ANT0`, :cpp:enumerator:`WIFI_ANT_MODE_ANT1`, or :cpp:enumerator:`WIFI_ANT_MODE_AUTO`. If the antenna mode is :cpp:enumerator:`WIFI_ANT_MODE_ANT0`, the enabled antenna 0 is selected for RX/TX data. If the antenna mode is :cpp:enumerator:`WIFI_ANT_MODE_ANT1`, the enabled antenna 1 is selected for RX/TX data. Otherwise, Wi-Fi automatically selects the enabled antenna that has better signal.
  1636. If the RX antenna mode is :cpp:enumerator:`WIFI_ANT_MODE_AUTO`, the default antenna mode also needs to be set, because the RX antenna switching only happens when some conditions are met. For example, the RX antenna starts to switch if the RSSI is lower than -65 dBm or another antenna has better signal. RX uses the default antenna if the conditions are not met. If the default antenna mode is :cpp:enumerator:`WIFI_ANT_MODE_ANT1`, the enabled antenna 1 is used as the default RX antenna, otherwise the enabled antenna 0 is used.
  1637. Some limitations need to be considered:
  1638. - The TX antenna can be set to :cpp:enumerator:`WIFI_ANT_MODE_AUTO` only if the RX antenna mode is :cpp:enumerator:`WIFI_ANT_MODE_AUTO`, because TX antenna selecting algorithm is based on RX antenna in :cpp:enumerator:`WIFI_ANT_MODE_AUTO` type.
  1639. - When the TX antenna mode or RX antenna mode is configured to :cpp:enumerator:`WIFI_ANT_MODE_AUTO` the switching mode will easily trigger the switching phase, as long as there is deterioration of the RF signal. So in situations where the RF signal is not stable, the antenna switching will occur frequently, resulting in an RF performance that may not meet expectations.
  1640. - Currently, Bluetooth® does not support the multiple antennas feature, so please do not use multiple antennas related APIs.
  1641. Following is the recommended scenarios to use the multiple antennas:
  1642. - The applications can always choose to select a specified antenna or implement their own antenna selecting algorithm, e.g., selecting the antenna mode based on the information collected by the application. Refer to ESP-IDF example :idf_file:`examples/wifi/antenna/README.md` for the antenna selecting algorithm design.
  1643. - Both RX/TX antenna modes are configured to WIFI_ANT_MODE_ANT0 or WIFI_ANT_MODE_ANT1.
  1644. Wi-Fi Multiple Antennas Configuration
  1645. +++++++++++++++++++++++++++++++++++++
  1646. Generally, following steps can be taken to configure the multiple antennas:
  1647. - Configure which GPIOs are connected to the antenna_selects. For example, if four antennas are supported and GPIO20/GPIO21 are connected to antenna_select[0]/antenna_select[1], the configurations look like:
  1648. .. code-block:: c
  1649. wifi_ant_gpio_config_t ant_gpio_config = {
  1650. .gpio_cfg[0] = { .gpio_select = 1, .gpio_num = 20 },
  1651. .gpio_cfg[1] = { .gpio_select = 1, .gpio_num = 21 }
  1652. };
  1653. - Configure which antennas are enabled and how RX/TX use the enabled antennas. For example, if antenna1 and antenna3 are enabled, the RX needs to select the better antenna automatically and uses antenna1 as its default antenna, the TX always selects the antenna3. The configuration looks like:
  1654. .. code-block:: c
  1655. wifi_ant_config_t config = {
  1656. .rx_ant_mode = WIFI_ANT_MODE_AUTO,
  1657. .rx_ant_default = WIFI_ANT_ANT0,
  1658. .tx_ant_mode = WIFI_ANT_MODE_ANT1,
  1659. .enabled_ant0 = 1,
  1660. .enabled_ant1 = 3
  1661. };
  1662. .. only:: SOC_WIFI_CSI_SUPPORT
  1663. Wi-Fi Channel State Information
  1664. ------------------------------------
  1665. Channel state information (CSI) refers to the channel information of a Wi-Fi connection. In {IDF_TARGET_NAME}, this information consists of channel frequency responses of sub-carriers and is estimated when packets are received from the transmitter. Each channel frequency response of sub-carrier is recorded by two bytes of signed characters. The first one is imaginary part and the second one is real part. There are up to three fields of channel frequency responses according to the type of received packet. They are legacy long training field (LLTF), high throughput LTF (HT-LTF), and space time block code HT-LTF (STBC-HT-LTF). For different types of packets which are received on channels with different state, the sub-carrier index and total bytes of signed characters of CSI are shown in the following table.
  1666. +-------------+--------------------+-----------------------------------------+--------------------------------------------------------+----------------------------------------------------------+
  1667. | channel | secondary channel | none | below | above |
  1668. +-------------+--------------------+-------------+---------------------------+----------+---------------------------------------------+----------+-----------------------------------------------+
  1669. | packet | signal mode | non HT | HT | non HT | HT | non HT | HT |
  1670. + +--------------------+-------------+---------------------------+----------+-----------------+---------------------------+----------+-------------------+---------------------------+
  1671. | information | channel bandwidth | 20 MHz | 20 MHz | 20 MHz | 20 MHz | 40 MHz | 20 MHz | 20 MHz | 40 MHz |
  1672. + +--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
  1673. | | STBC | non STBC | non STBC | STBC | non STBC | non STBC | STBC | non STBC | STBC | non STBC | non STBC | STBC | non STBC | STBC |
  1674. +-------------+--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
  1675. | sub-carrier | LLTF | 0~31, -32~-1| 0~31, -32~-1| 0~31, -32~-1| 0~63 | 0~63 | 0~63 | 0~63 | 0~63 | -64~-1 | -64~-1 | -64~-1 | -64~-1 | -64~-1 |
  1676. + +--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
  1677. | index | HT-LTF | - | 0~31, -32~-1| 0~31, -32~-1| - | 0~63 | 0~62 | 0~63, -64~-1| 0~60, -60~-1| - | -64~-1 | -62~-1 | 0~63, -64~-1| 0~60, -60~-1|
  1678. + +--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
  1679. | | STBC-HT-LTF | - | - | 0~31, -32~-1| - | - | 0~62 | - | 0~60, -60~-1| - | - | -62~-1 | - | 0~60, -60~-1|
  1680. +-------------+--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
  1681. | total bytes | 128 | 256 | 384 | 128 | 256 | 380 | 384 | 612 | 128 | 256 | 376 | 384 | 612 |
  1682. +----------------------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
  1683. All of the information in the table can be found in the structure wifi_csi_info_t.
  1684. - Secondary channel refers to secondary_channel field of rx_ctrl field.
  1685. - Signal mode of packet refers to sig_mode field of rx_ctrl field.
  1686. - Channel bandwidth refers to cwb field of rx_ctrl field.
  1687. - STBC refers to stbc field of rx_ctrl field.
  1688. - Total bytes refers to len field.
  1689. - The CSI data corresponding to each Long Training Field (LTF) type is stored in a buffer starting from the buf field. Each item is stored as two bytes: imaginary part followed by real part. The order of each item is the same as the sub-carrier in the table. The order of LTF is: LLTF, HT-LTF, STBC-HT-LTF. However, all 3 LTFs may not be present, depending on the channel and packet information (see above).
  1690. - If first_word_invalid field of :cpp:type:`wifi_csi_info_t` is true, it means that the first four bytes of CSI data is invalid due to a hardware limitation in {IDF_TARGET_NAME}.
  1691. - More information like RSSI, noise floor of RF, receiving time and antenna is in the rx_ctrl field.
  1692. When imaginary part and real part data of sub-carrier are used, please refer to the table below.
  1693. +-----------------+-------------------+------------------------------+--------------------------+
  1694. | PHY standard | Sub-carrier range | Pilot sub-carrier | Sub-carrier (total/data) |
  1695. +=================+===================+==============================+==========================+
  1696. | 802.11a/g | -26 to +26 | -21, -7, +7, +21 | 52 total, 48 usable |
  1697. +-----------------+-------------------+------------------------------+--------------------------+
  1698. | 802.11n, 20 MHz | -28 to +28 | -21, -7, +7, +21 | 56 total, 52 usable |
  1699. +-----------------+-------------------+------------------------------+--------------------------+
  1700. | 802.11n, 40 MHz | -57 to +57 | -53, -25, -11, +11, +25, +53 | 114 total, 108 usable |
  1701. +-----------------+-------------------+------------------------------+--------------------------+
  1702. .. note::
  1703. - For STBC packet, CSI is provided for every space-time stream without CSD (cyclic shift delay). As each cyclic shift on the additional chains shall be -200 ns, only the CSD angle of first space-time stream is recorded in sub-carrier 0 of HT-LTF and STBC-HT-LTF for there is no channel frequency response in sub-carrier 0. CSD[10:0] is 11 bits, ranging from -pi to pi.
  1704. - If LLTF, HT-LTF, or STBC-HT-LTF is not enabled by calling API :cpp:func:`esp_wifi_set_csi_config()`, the total bytes of CSI data will be fewer than that in the table. For example, if LLTF and HT-LTF is not enabled and STBC-HT-LTF is enabled, when a packet is received with the condition above/HT/40MHz/STBC, the total bytes of CSI data is 244 ((61 + 60) * 2 + 2 = 244. The result is aligned to four bytes, and the last two bytes are invalid).
  1705. Wi-Fi Channel State Information Configure
  1706. -------------------------------------------
  1707. To use Wi-Fi CSI, the following steps need to be done.
  1708. - Select Wi-Fi CSI in menuconfig. Go to ``Menuconfig`` > ``Components config`` > ``Wi-Fi`` > ``Wi-Fi CSI (Channel State Information)``.
  1709. - Set CSI receiving callback function by calling API :cpp:func:`esp_wifi_set_csi_rx_cb()`.
  1710. - Configure CSI by calling API :cpp:func:`esp_wifi_set_csi_config()`.
  1711. - Enable CSI by calling API :cpp:func:`esp_wifi_set_csi()`.
  1712. The CSI receiving callback function runs from Wi-Fi task. So, do not do lengthy operations in the callback function. Instead, post necessary data to a queue and handle it from a lower priority task. Because station does not receive any packet when it is disconnected and only receives packets from AP when it is connected, it is suggested to enable sniffer mode to receive more CSI data by calling :cpp:func:`esp_wifi_set_promiscuous()`.
  1713. Wi-Fi HT20/40
  1714. -------------------------
  1715. .. only:: esp32 or esp32s2 or esp32c3 or esp32s3 or esp32c6
  1716. {IDF_TARGET_NAME} supports Wi-Fi bandwidth HT20 or HT40 and does not support HT20/40 coexist. :cpp:func:`esp_wifi_set_bandwidth()` can be used to change the default bandwidth of station or AP. The default bandwidth for {IDF_TARGET_NAME} station and AP is HT40.
  1717. In station mode, the actual bandwidth is firstly negotiated during the Wi-Fi connection. It is HT40 only if both the station and the connected AP support HT40, otherwise it is HT20. If the bandwidth of connected AP is changes, the actual bandwidth is negotiated again without Wi-Fi disconnecting.
  1718. Similarly, in AP mode, the actual bandwidth is negotiated between AP and the stations that connect to the AP. It is HT40 if the AP and one of the stations support HT40, otherwise it is HT20.
  1719. In station/AP coexist mode, the station/AP can configure HT20/40 seperately. If both station and AP are negotiated to HT40, the HT40 channel should be the channel of station because the station always has higher priority than AP in {IDF_TARGET_NAME}. For example, the configured bandwidth of AP is HT40, the configured primary channel is 6, and the configured secondary channel is 10. The station is connected to an router whose primary channel is 6 and secondary channel is 2, then the actual channel of AP is changed to primary 6 and secondary 2 automatically.
  1720. Theoretically, the HT40 can gain better throughput because the maximum raw physicial (PHY) data rate for HT40 is 150 Mbps while it is 72 Mbps for HT20. However, if the device is used in some special environment, e.g., there are too many other Wi-Fi devices around the {IDF_TARGET_NAME} device, the performance of HT40 may be degraded. So if the applications need to support same or similar scenarios, it is recommended that the bandwidth is always configured to HT20.
  1721. .. only:: esp32c2
  1722. {IDF_TARGET_NAME} supports Wi-Fi bandwidth HT20 and does not support Wi-Fi bandwidth HT40 or HT20/40 coexist.
  1723. Wi-Fi QoS
  1724. -------------------------
  1725. {IDF_TARGET_NAME} supports all the mandatory features required in WFA Wi-Fi QoS Certification.
  1726. Four ACs (Access Category) are defined in Wi-Fi specification, and each AC has its own priority to access the Wi-Fi channel. Moreover, a map rule is defined to map the QoS priority of other protocol, e.g., 802.11D or TCP/IP precedence is mapped to Wi-Fi AC.
  1727. The table below describes how the IP Precedences are mapped to Wi-Fi ACs in {IDF_TARGET_NAME}. It also indicates whether the AMPDU is supported for this AC. The table is sorted from high to low priority. That is to say, the AC_VO has the highest priority.
  1728. +------------------+------------------------+-----------------+
  1729. | IP Precedence | Wi-Fi AC | Support AMPDU? |
  1730. +==================+========================+=================+
  1731. | 6, 7 | AC_VO (Voice) | No |
  1732. +------------------+------------------------+-----------------+
  1733. | 4, 5 | AC_VI (Video) | Yes |
  1734. +------------------+------------------------+-----------------+
  1735. | 3, 0 | AC_BE (Best Effort) | Yes |
  1736. +------------------+------------------------+-----------------+
  1737. | 1, 2 | AC_BK (Background) | Yes |
  1738. +------------------+------------------------+-----------------+
  1739. The application can make use of the QoS feature by configuring the IP precedence via socket option IP_TOS. Here is an example to make the socket to use VI queue::
  1740. const int ip_precedence_vi = 4;
  1741. const int ip_precedence_offset = 5;
  1742. int priority = (ip_precedence_vi << ip_precedence_offset);
  1743. setsockopt(socket_id, IPPROTO_IP, IP_TOS, &priority, sizeof(priority));
  1744. Theoretically, the higher priority AC has better performance than the lower priority AC. However, it is not always true. Here are some suggestions about how to use the Wi-Fi QoS:
  1745. - Some really important application traffic can be put into the AC_VO queue. But avoid using the AC_VO queue for heavy traffic, as it may impact the management frames which also use this queue. Eventually, it is worth noting that the AC_VO queue does not support AMPDU, and its performance with heavy traffic is no better than other queues.
  1746. - Avoid using more than two precedences supported by different AMPDUs, e.g., when socket A uses precedence 0, socket B uses precedence 1, and socket C uses precedence 2. This can be a bad design because it may need much more memory. To be specific, the Wi-Fi driver may generate a Block Ack session for each precedence and it needs more memory if the Block Ack session is set up.
  1747. Wi-Fi AMSDU
  1748. -------------------------
  1749. .. only:: not SOC_SPIRAM_SUPPORTED
  1750. {IDF_TARGET_NAME} supports receiving AMSDU.
  1751. .. only:: SOC_SPIRAM_SUPPORTED
  1752. {IDF_TARGET_NAME} supports receiving and transmitting AMSDU. AMSDU TX is disabled by default, since enable AMSDU TX need more memory. Select :ref:`CONFIG_ESP_WIFI_AMSDU_TX_ENABLED` to enable AMSDU Tx feature, it depends on :ref:`CONFIG_SPIRAM`.
  1753. Wi-Fi Fragment
  1754. -------------------------
  1755. .. only:: esp32 or esp32s2
  1756. supports Wi-Fi receiving fragment, but does not support Wi-Fi transmitting fragment.
  1757. .. only:: esp32c3 or esp32s3 or esp32c6
  1758. {IDF_TARGET_NAME} supports Wi-Fi receiving and transmitting fragment.
  1759. WPS Enrollee
  1760. -------------------------
  1761. {IDF_TARGET_NAME} supports WPS enrollee feature in Wi-Fi mode :cpp:enumerator:`WIFI_MODE_STA` or :cpp:enumerator:`WIFI_MODE_APSTA`. Currently, {IDF_TARGET_NAME} supports WPS enrollee type PBC and PIN.
  1762. .. _wifi-buffer-usage:
  1763. Wi-Fi Buffer Usage
  1764. --------------------------
  1765. This section is only about the dynamic buffer configuration.
  1766. Why Buffer Configuration Is Important
  1767. +++++++++++++++++++++++++++++++++++++++
  1768. In order to get a high-performance system, consider the memory usage/configuration carefully for the following reasons:
  1769. - the available memory in {IDF_TARGET_NAME} is limited.
  1770. - currently, the default type of buffer in LwIP and Wi-Fi drivers is "dynamic", **which means that both the LwIP and Wi-Fi share memory with the application**. Programmers should always keep this in mind; otherwise, they will face a memory issue, such as "running out of heap memory".
  1771. - it is very dangerous to run out of heap memory, as this will cause {IDF_TARGET_NAME} an "undefined behavior". Thus, enough heap memory should be reserved for the application, so that it never runs out of it.
  1772. - the Wi-Fi throughput heavily depends on memory-related configurations, such as the TCP window size and Wi-Fi RX/TX dynamic buffer number.
  1773. - the peak heap memory that the {IDF_TARGET_NAME} LwIP/Wi-Fi may consume depends on a number of factors, such as the maximum TCP/UDP connections that the application may have.
  1774. - the total memory that the application requires is also an important factor when considering memory configuration.
  1775. Due to these reasons, there is not a good-for-all application configuration. Rather, it is recommended to consider memory configurations separately for every different application.
  1776. Dynamic vs. Static Buffer
  1777. ++++++++++++++++++++++++++++++
  1778. The default type of buffer in Wi-Fi drivers is "dynamic". Most of the time the dynamic buffer can significantly save memory. However, it makes the application programming a little more difficult, because in this case the application needs to consider memory usage in Wi-Fi.
  1779. lwIP also allocates buffers at the TCP/IP layer, and this buffer allocation is also dynamic. See :ref:`lwIP documentation section about memory use and performance <lwip-performance>`.
  1780. Peak Wi-Fi Dynamic Buffer
  1781. ++++++++++++++++++++++++++++++
  1782. The Wi-Fi driver supports several types of buffer (refer to `Wi-Fi Buffer Configure`_). However, this section is about the usage of the dynamic Wi-Fi buffer only.
  1783. The peak heap memory that Wi-Fi consumes is the **theoretically-maximum memory** that the Wi-Fi driver consumes. Generally, the peak memory depends on:
  1784. - :math:`b_{rx}` the number of dynamic RX buffers that are configured
  1785. - :math:`b_{tx}` the number of dynamic TX buffers that are configured
  1786. - :math:`m_{rx}` the maximum packet size that the Wi-Fi driver can receive
  1787. - :math:`m_{tx}` the maximum packet size that the Wi-Fi driver can send
  1788. So, the peak memory that the Wi-Fi driver consumes (:math:`p`) can be calculated with the following formula:
  1789. .. math::
  1790. p = (b_{rx} * m_{rx}) + (b_{tx} * m_{tx})
  1791. Generally, the dynamic TX long buffers and dynamic TX long long buffers can be ignored, because they are management frames which only have a small impact on the system.
  1792. .. _How-to-improve-Wi-Fi-performance:
  1793. How to Improve Wi-Fi Performance
  1794. ----------------------------------
  1795. The performance of {IDF_TARGET_NAME} Wi-Fi is affected by many parameters, and there are mutual constraints between each parameter. A proper configuration cannot only improve performance, but also increase available memory for applications and improve stability.
  1796. This section briefly explains the operating mode of the Wi-Fi/LwIP protocol stack and the role of each parameter. It also gives several recommended configuration ranks to help choose the appropriate rank according to the usage scenario.
  1797. Protocol Stack Operation Mode
  1798. ++++++++++++++++++++++++++++++++++
  1799. .. figure:: ../../_static/api-guides-WiFi-driver-how-to-improve-WiFi-performance.png
  1800. :align: center
  1801. {IDF_TARGET_NAME} datapath
  1802. The {IDF_TARGET_NAME} protocol stack is divided into four layers: Application, LwIP, Wi-Fi, and Hardware.
  1803. - During receiving, hardware puts the received packet into DMA buffer, and then transfers it into the RX buffer of Wi-Fi and LwIP in turn for related protocol processing, and finally to the application layer. The Wi-Fi RX buffer and the LwIP RX buffer shares the same buffer by default. In other words, the Wi-Fi forwards the packet to LwIP by reference by default.
  1804. - During sending, the application copies the messages to be sent into the TX buffer of the LwIP layer for TCP/IP encapsulation. The messages will then be passed to the TX buffer of the Wi-Fi layer for MAC encapsulation and wait to be sent.
  1805. Parameters
  1806. ++++++++++++++
  1807. Increasing the size or number of the buffers mentioned above properly can improve Wi-Fi performance. Meanwhile, it will reduce available memory to the application. The following is an introduction to the parameters that users need to configure:
  1808. **RX direction:**
  1809. - :ref:`CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM`
  1810. This parameter indicates the number of DMA buffer at the hardware layer. Increasing this parameter will increase the sender's one-time receiving throughput, thereby improving the Wi-Fi protocol stack ability to handle burst traffic.
  1811. - :ref:`CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM`
  1812. This parameter indicates the number of RX buffer in the Wi-Fi layer. Increasing this parameter will improve the performance of packet reception. This parameter needs to match the RX buffer size of the LwIP layer.
  1813. - :ref:`CONFIG_ESP_WIFI_RX_BA_WIN`
  1814. This parameter indicates the size of the AMPDU BA Window at the receiving end. This parameter should be configured to the smaller value between twice of :ref:`CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM` and :ref:`CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM`.
  1815. - :ref:`CONFIG_LWIP_TCP_WND_DEFAULT`
  1816. This parameter represents the RX buffer size of the LwIP layer for each TCP stream. Its value should be configured to the value of WIFI_DYNAMIC_RX_BUFFER_NUM (KB) to reach a high and stable performance. Meanwhile, in case of multiple streams, this value needs to be reduced proportionally.
  1817. **TX direction:**
  1818. - :ref:`CONFIG_ESP_WIFI_TX_BUFFER`
  1819. This parameter indicates the type of TX buffer, it is recommended to configure it as a dynamic buffer, which can make full use of memory.
  1820. - :ref:`CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM`
  1821. This parameter indicates the number of TX buffer on the Wi-Fi layer. Increasing this parameter will improve the performance of packet sending. The parameter value needs to match the TX buffer size of the LwIP layer.
  1822. - :ref:`CONFIG_LWIP_TCP_SND_BUF_DEFAULT`
  1823. This parameter represents the TX buffer size of the LwIP layer for each TCP stream. Its value should be configured to the value of WIFI_DYNAMIC_TX_BUFFER_NUM (KB) to reach a high and stable performance. In case of multiple streams, this value needs to be reduced proportionally.
  1824. **Throughput optimization by placing code in IRAM:**
  1825. .. only:: esp32 or esp32s2
  1826. - :ref:`CONFIG_ESP_WIFI_IRAM_OPT`
  1827. If this option is enabled, some Wi-Fi functions are moved to IRAM, improving throughput. This increases IRAM usage by 15 kB.
  1828. - :ref:`CONFIG_ESP_WIFI_RX_IRAM_OPT`
  1829. If this option is enabled, some Wi-Fi RX functions are moved to IRAM, improving throughput. This increases IRAM usage by 16 kB.
  1830. - :ref:`CONFIG_LWIP_IRAM_OPTIMIZATION`
  1831. If this option is enabled, some LwIP functions are moved to IRAM, improving throughput. This increases IRAM usage by 13 kB.
  1832. .. only:: esp32c6
  1833. - :ref:`CONFIG_ESP_WIFI_IRAM_OPT`
  1834. If this option is enabled, some Wi-Fi functions are moved to IRAM, improving throughput. This increases IRAM usage by 13 kB.
  1835. - :ref:`CONFIG_ESP_WIFI_RX_IRAM_OPT`
  1836. If this option is enabled, some Wi-Fi RX functions are moved to IRAM, improving throughput. This increases IRAM usage by 7 kB.
  1837. - :ref:`CONFIG_LWIP_IRAM_OPTIMIZATION`
  1838. If this option is enabled, some LwIP functions are moved to IRAM, improving throughput. This increases IRAM usage by 14 kB.
  1839. .. only:: esp32s2
  1840. **CACHE:**
  1841. - :ref:`CONFIG_ESP32S2_INSTRUCTION_CACHE_SIZE`
  1842. Configure the size of the instruction Cache.
  1843. - :ref:`CONFIG_ESP32S2_INSTRUCTION_CACHE_LINE_SIZE`
  1844. Configure the width of the instruction Cache bus.
  1845. .. only:: esp32s3
  1846. **CACHE:**
  1847. - :ref:`CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE`
  1848. Configure the size of the instruction Cache.
  1849. - :ref:`CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE`
  1850. Configure the size of the instruction Cache bus.
  1851. - :ref:`CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS`
  1852. Configure the associated ways of the instruction Cache.
  1853. - :ref:`CONFIG_ESP32S3_DATA_CACHE_SIZE`
  1854. Configure the size of the Data Cache.
  1855. - :ref:`CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE`
  1856. Configure the line size of the Data Cache.
  1857. - :ref:`CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS`
  1858. Configure the associated ways of the Data Cache.
  1859. .. note::
  1860. The buffer size mentioned above is fixed as 1.6 KB.
  1861. How to Configure Parameters
  1862. ++++++++++++++++++++++++++++
  1863. The memory of {IDF_TARGET_NAME} is shared by protocol stack and applications.
  1864. Here, several configuration ranks are given. In most cases, the user should select a suitable rank for parameter configuration according to the size of the memory occupied by the application.
  1865. The parameters not mentioned in the following table should be set to the default.
  1866. .. only:: esp32
  1867. .. list-table::
  1868. :header-rows: 1
  1869. :widths: 10 5 5 10 5 5 10 5
  1870. * - Rank
  1871. - Iperf
  1872. - TX prior
  1873. - High-performance
  1874. - RX prior
  1875. - Default
  1876. - Memory saving
  1877. - Minimum
  1878. * - Available memory (KB)
  1879. - 37.1
  1880. - 113.8
  1881. - 123.3
  1882. - 145.5
  1883. - 144.5
  1884. - 170.2
  1885. - 185.2
  1886. * - WIFI_STATIC_RX_BUFFER_NUM
  1887. - 16
  1888. - 6
  1889. - 6
  1890. - 6
  1891. - 6
  1892. - 6
  1893. - 4
  1894. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  1895. - 64
  1896. - 16
  1897. - 24
  1898. - 34
  1899. - 20
  1900. - 12
  1901. - 8
  1902. * - WIFI_DYNAMIC_TX_BUFFER_NUM
  1903. - 64
  1904. - 28
  1905. - 24
  1906. - 18
  1907. - 20
  1908. - 12
  1909. - 8
  1910. * - WIFI_RX_BA_WIN
  1911. - 32
  1912. - 8
  1913. - 12
  1914. - 12
  1915. - 10
  1916. - 6
  1917. - Disable
  1918. * - TCP_SND_BUF_DEFAULT (KB)
  1919. - 65
  1920. - 28
  1921. - 24
  1922. - 18
  1923. - 20
  1924. - 12
  1925. - 8
  1926. * - TCP_WND_DEFAULT (KB)
  1927. - 65
  1928. - 16
  1929. - 24
  1930. - 34
  1931. - 20
  1932. - 12
  1933. - 8
  1934. * - WIFI_IRAM_OPT
  1935. - 15
  1936. - 15
  1937. - 15
  1938. - 15
  1939. - 15
  1940. - 15
  1941. - 15
  1942. * - WIFI_RX_IRAM_OPT
  1943. - 16
  1944. - 16
  1945. - 16
  1946. - 16
  1947. - 16
  1948. - 16
  1949. - 16
  1950. * - LWIP_IRAM_OPTIMIZATION
  1951. - 13
  1952. - 13
  1953. - 13
  1954. - 13
  1955. - 13
  1956. - 13
  1957. - 13
  1958. * - TCP TX throughput (Mbit/s)
  1959. - 74.6
  1960. - 50.8
  1961. - 46.5
  1962. - 39.9
  1963. - 44.2
  1964. - 33.8
  1965. - 25.6
  1966. * - TCP RX throughput (Mbit/s)
  1967. - 63.6
  1968. - 35.5
  1969. - 42.3
  1970. - 48.5
  1971. - 40.5
  1972. - 30.1
  1973. - 27.8
  1974. * - UDP TX throughput (Mbit/s)
  1975. - 76.2
  1976. - 75.1
  1977. - 74.1
  1978. - 72.4
  1979. - 69.6
  1980. - 64.1
  1981. - 36.5
  1982. * - UDP RX throughput (Mbit/s)
  1983. - 83.1
  1984. - 66.3
  1985. - 75.1
  1986. - 75.6
  1987. - 73.1
  1988. - 65.3
  1989. - 54.7
  1990. .. only:: esp32s2
  1991. .. list-table::
  1992. :header-rows: 1
  1993. :widths: 10 10 10 10 10 10
  1994. * - Rank
  1995. - Iperf
  1996. - High-performance
  1997. - Default
  1998. - Memory saving
  1999. - Minimum
  2000. * - Available memory (KB)
  2001. - 4.1
  2002. - 24.2
  2003. - 78.4
  2004. - 86.5
  2005. - 116.4
  2006. * - WIFI_STATIC_RX_BUFFER_NUM
  2007. - 8
  2008. - 6
  2009. - 6
  2010. - 4
  2011. - 3
  2012. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2013. - 24
  2014. - 18
  2015. - 12
  2016. - 8
  2017. - 6
  2018. * - WIFI_DYNAMIC_TX_BUFFER_NUM
  2019. - 24
  2020. - 18
  2021. - 12
  2022. - 8
  2023. - 6
  2024. * - WIFI_RX_BA_WIN
  2025. - 12
  2026. - 9
  2027. - 6
  2028. - 4
  2029. - 3
  2030. * - TCP_SND_BUF_DEFAULT (KB)
  2031. - 24
  2032. - 18
  2033. - 12
  2034. - 8
  2035. - 6
  2036. * - TCP_WND_DEFAULT (KB)
  2037. - 24
  2038. - 18
  2039. - 12
  2040. - 8
  2041. - 6
  2042. * - WIFI_IRAM_OPT
  2043. - 15
  2044. - 15
  2045. - 15
  2046. - 15
  2047. - 0
  2048. * - WIFI_RX_IRAM_OPT
  2049. - 16
  2050. - 16
  2051. - 16
  2052. - 0
  2053. - 0
  2054. * - LWIP_IRAM_OPTIMIZATION
  2055. - 13
  2056. - 13
  2057. - 0
  2058. - 0
  2059. - 0
  2060. * - INSTRUCTION_CACHE
  2061. - 16
  2062. - 16
  2063. - 16
  2064. - 16
  2065. - 8
  2066. * - INSTRUCTION_CACHE_LINE
  2067. - 16
  2068. - 16
  2069. - 16
  2070. - 16
  2071. - 16
  2072. * - TCP TX throughput (Mbit/s)
  2073. - 37.6
  2074. - 33.1
  2075. - 22.5
  2076. - 12.2
  2077. - 5.5
  2078. * - TCP RX throughput (Mbit/s)
  2079. - 31.5
  2080. - 28.1
  2081. - 20.1
  2082. - 13.1
  2083. - 7.2
  2084. * - UDP TX throughput (Mbit/s)
  2085. - 58.1
  2086. - 57.3
  2087. - 28.1
  2088. - 22.6
  2089. - 8.7
  2090. * - UDP RX throughput (Mbit/s)
  2091. - 78.1
  2092. - 66.7
  2093. - 65.3
  2094. - 53.8
  2095. - 28.5
  2096. .. only:: esp32c3
  2097. .. list-table::
  2098. :header-rows: 1
  2099. :widths: 10 10 10 15
  2100. * - Rank
  2101. - Iperf
  2102. - Default
  2103. - Minimum
  2104. * - Available memory (KB)
  2105. - 59
  2106. - 160
  2107. - 180
  2108. * - WIFI_STATIC_RX_BUFFER_NUM
  2109. - 20
  2110. - 8
  2111. - 3
  2112. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2113. - 40
  2114. - 16
  2115. - 6
  2116. * - WIFI_DYNAMIC_TX_BUFFER_NUM
  2117. - 40
  2118. - 16
  2119. - 6
  2120. * - WIFI_RX_BA_WIN
  2121. - 32
  2122. - 16
  2123. - 6
  2124. * - TCP_SND_BUF_DEFAULT (KB)
  2125. - 40
  2126. - 16
  2127. - 6
  2128. * - TCP_WND_DEFAULT (KB)
  2129. - 40
  2130. - 16
  2131. - 6
  2132. * - LWIP_IRAM_OPTIMIZATION
  2133. - 13
  2134. - 13
  2135. - 0
  2136. * - TCP TX throughput (Mbit/s)
  2137. - 38.1
  2138. - 27.2
  2139. - 20.4
  2140. * - TCP RX throughput (Mbit/s)
  2141. - 35.3
  2142. - 24.2
  2143. - 17.4
  2144. * - UDP TX throughput (Mbit/s)
  2145. - 40.6
  2146. - 38.9
  2147. - 34.1
  2148. * - UDP RX throughput (Mbit/s)
  2149. - 52.4
  2150. - 44.5
  2151. - 44.2
  2152. .. only:: esp32c6
  2153. .. list-table::
  2154. :header-rows: 1
  2155. :widths: 10 10 10 15
  2156. * - Rank
  2157. - Iperf
  2158. - Default
  2159. - Minimum
  2160. * - Available memory (KB)
  2161. - 223
  2162. - 276
  2163. - 299
  2164. * - WIFI_STATIC_RX_BUFFER_NUM
  2165. - 20
  2166. - 8
  2167. - 3
  2168. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2169. - 40
  2170. - 16
  2171. - 6
  2172. * - WIFI_DYNAMIC_TX_BUFFER_NUM
  2173. - 40
  2174. - 16
  2175. - 6
  2176. * - WIFI_RX_BA_WIN
  2177. - 32
  2178. - 16
  2179. - 6
  2180. * - TCP_SND_BUF_DEFAULT (KB)
  2181. - 40
  2182. - 16
  2183. - 6
  2184. * - TCP_WND_DEFAULT (KB)
  2185. - 40
  2186. - 16
  2187. - 6
  2188. * - LWIP_IRAM_OPTIMIZATION
  2189. - 13
  2190. - 13
  2191. - 0
  2192. * - TCP TX throughput (Mbit/s)
  2193. - 30.5
  2194. - 25.9
  2195. - 16.4
  2196. * - TCP RX throughput (Mbit/s)
  2197. - 27.8
  2198. - 21.6
  2199. - 14.3
  2200. * - UDP TX throughput (Mbit/s)
  2201. - 37.8
  2202. - 36.1
  2203. - 34.6
  2204. * - UDP RX throughput (Mbit/s)
  2205. - 41.5
  2206. - 36.8
  2207. - 36.7
  2208. .. only:: esp32c2
  2209. .. list-table::
  2210. :header-rows: 1
  2211. :widths: 10 10 10 15
  2212. * - Rank
  2213. - Iperf
  2214. - Default
  2215. - Minimum
  2216. * - Available memory (KB)
  2217. - 37
  2218. - 56
  2219. - 84
  2220. * - WIFI_STATIC_RX_BUFFER_NUM
  2221. - 14
  2222. - 7
  2223. - 3
  2224. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2225. - 18
  2226. - 14
  2227. - 6
  2228. * - WIFI_DYNAMIC_TX_BUFFER_NUM
  2229. - 18
  2230. - 14
  2231. - 6
  2232. * - WIFI_RX_BA_WIN
  2233. - 16
  2234. - 12
  2235. - 6
  2236. * - TCP_SND_BUF_DEFAULT (KB)
  2237. - 18
  2238. - 14
  2239. - 6
  2240. * - TCP_WND_DEFAULT (KB)
  2241. - 18
  2242. - 14
  2243. - 6
  2244. * - LWIP_IRAM_OPTIMIZATION
  2245. - 13
  2246. - 13
  2247. - 0
  2248. * - TCP TX throughput (Mbit/s)
  2249. - 21.6
  2250. - 21.4
  2251. - 14.3
  2252. * - TCP RX throughput (Mbit/s)
  2253. - 19.1
  2254. - 17.9
  2255. - 12.4
  2256. * - UDP TX throughput (Mbit/s)
  2257. - 26.4
  2258. - 26.3
  2259. - 25.0
  2260. * - UDP RX throughput (Mbit/s)
  2261. - 32.3
  2262. - 31.5
  2263. - 27.7
  2264. .. only:: esp32s3
  2265. .. list-table::
  2266. :header-rows: 1
  2267. :widths: 25 20 25 25
  2268. * - Rank
  2269. - Iperf
  2270. - Default
  2271. - Minimum
  2272. * - Available memory (KB)
  2273. - 133.9
  2274. - 183.9
  2275. - 273.6
  2276. * - WIFI_STATIC_RX_BUFFER_NUM
  2277. - 24
  2278. - 8
  2279. - 3
  2280. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2281. - 64
  2282. - 32
  2283. - 6
  2284. * - WIFI_DYNAMIC_TX_BUFFER_NUM
  2285. - 64
  2286. - 32
  2287. - 6
  2288. * - WIFI_RX_BA_WIN
  2289. - 32
  2290. - 16
  2291. - 6
  2292. * - TCP_SND_BUF_DEFAULT (KB)
  2293. - 64
  2294. - 32
  2295. - 6
  2296. * - TCP_WND_DEFAULT (KB)
  2297. - 64
  2298. - 32
  2299. - 6
  2300. * - WIFI_IRAM_OPT
  2301. - 15
  2302. - 15
  2303. - 15
  2304. * - WIFI_RX_IRAM_OPT
  2305. - 16
  2306. - 16
  2307. - 16
  2308. * - LWIP_IRAM_OPTIMIZATION
  2309. - 13
  2310. - 13
  2311. - 0
  2312. * - INSTRUCTION_CACHE
  2313. - 32
  2314. - 32
  2315. - 16
  2316. * - INSTRUCTION_CACHE_LINE
  2317. - 32
  2318. - 32
  2319. - 32
  2320. * - INSTRUCTION_CACHE_WAYS
  2321. - 8
  2322. - 8
  2323. - 4
  2324. * - TCP TX throughput (Mbit/s)
  2325. - 83.93
  2326. - 64.28
  2327. - 23.17
  2328. * - TCP RX throughput (Mbit/s)
  2329. - 73.98
  2330. - 60.39
  2331. - 18.11
  2332. * - UDP TX throughput (Mbit/s)
  2333. - 98.69
  2334. - 96.28
  2335. - 48.78
  2336. * - UDP RX throughput (Mbit/s)
  2337. - 88.58
  2338. - 86.57
  2339. - 59.45
  2340. .. only:: esp32 or esp32s3
  2341. .. note::
  2342. The test was performed with a single stream in a shielded box using an ASUS RT-N66U router.
  2343. {IDF_TARGET_NAME}'s CPU is dual core with 240 MHz. {IDF_TARGET_NAME}'s flash is in QIO mode with 80 MHz.
  2344. .. only:: esp32s2
  2345. .. note::
  2346. The test was performed with a single stream in a shielded box using an ASUS RT-N66U router.
  2347. {IDF_TARGET_NAME}'s CPU is single core with 240 MHz. {IDF_TARGET_NAME}'s flash is in QIO mode with 80 MHz.
  2348. .. only:: esp32c3
  2349. .. note::
  2350. The test was performed with a single stream in a shielded box using an ASUS RT-N66U router.
  2351. {IDF_TARGET_NAME}'s CPU is single core with 160 MHz. {IDF_TARGET_NAME}'s flash is in QIO mode with 80 MHz.
  2352. .. only:: esp32c6
  2353. .. note::
  2354. The test was performed with a single stream in a shielded box using an XIAOMI AX-6000 router.
  2355. {IDF_TARGET_NAME}'s CPU is single core with 160 MHz. {IDF_TARGET_NAME}'s flash is in QIO mode with 80 MHz.
  2356. .. only:: esp32c2
  2357. .. note::
  2358. The test was performed with a single stream in a shielded box using an Redmi RM2100 router.
  2359. {IDF_TARGET_NAME}'s CPU is single core with 120 MHz. {IDF_TARGET_NAME}'s flash is in QIO mode with 60 MHz.
  2360. .. only:: esp32
  2361. **Ranks:**
  2362. - **Iperf rank**
  2363. {IDF_TARGET_NAME} extreme performance rank used to test extreme performance.
  2364. - **High-performance rank**
  2365. The {IDF_TARGET_NAME}'s high-performance configuration rank, suitable for scenarios where the application occupies less memory and has high-performance requirements. In this rank, users can choose to use the RX prior rank or the TX prior rank according to the usage scenario.
  2366. - **Default rank**
  2367. {IDF_TARGET_NAME}'s default configuration rank, the available memory, and performance are in balance.
  2368. - **Memory saving rank**
  2369. This rank is suitable for scenarios where the application requires a large amount of memory, and the transceiver performance will be reduced in this rank.
  2370. - **Minimum rank**
  2371. This is the minimum configuration rank of {IDF_TARGET_NAME}. The protocol stack only uses the necessary memory for running. It is suitable for scenarios where there is no requirement for performance and the application requires lots of space.
  2372. .. only:: esp32s2
  2373. **Ranks:**
  2374. - **Iperf rank**
  2375. {IDF_TARGET_NAME} extreme performance rank used to test extreme performance.
  2376. - **High-performance rank**
  2377. The {IDF_TARGET_NAME}'s high-performance configuration rank, suitable for scenarios where the application occupies less memory and has high-performance requirements.
  2378. - **Default rank**
  2379. {IDF_TARGET_NAME}'s default configuration rank, the available memory, and performance are in balance.
  2380. - **Memory saving rank**
  2381. This rank is suitable for scenarios where the application requires a large amount of memory, and the transceiver performance will be reduced in this rank.
  2382. - **Minimum rank**
  2383. This is the minimum configuration rank of {IDF_TARGET_NAME}. The protocol stack only uses the necessary memory for running. It is suitable for scenarios where there is no requirement for performance and the application requires lots of space.
  2384. .. only:: esp32c3 or esp32s3 or esp32c6
  2385. **Ranks:**
  2386. - **Iperf rank**
  2387. {IDF_TARGET_NAME} extreme performance rank used to test extreme performance.
  2388. - **Default rank**
  2389. {IDF_TARGET_NAME}'s default configuration rank, the available memory, and performance are in balance.
  2390. - **Minimum rank**
  2391. This is the minimum configuration rank of {IDF_TARGET_NAME}. The protocol stack only uses the necessary memory for running. It is suitable for scenarios where there is no requirement for performance and the application requires lots of space.
  2392. .. only:: SOC_SPIRAM_SUPPORTED
  2393. Using PSRAM
  2394. ++++++++++++++++++++++++++++
  2395. PSRAM is generally used when the application takes up a lot of memory. In this mode, the :ref:`CONFIG_ESP_WIFI_TX_BUFFER` is forced to be static. :ref:`CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM` indicates the number of DMA buffers at the hardware layer, and increasing this parameter can improve performance.
  2396. The following are the recommended ranks for using PSRAM:
  2397. .. only:: esp32
  2398. .. list-table::
  2399. :header-rows: 1
  2400. :widths: 15 10 10 15 10
  2401. * - Rank
  2402. - Iperf
  2403. - Default
  2404. - Memory saving
  2405. - Minimum
  2406. * - Available memory (KB)
  2407. - 113.8
  2408. - 152.4
  2409. - 181.2
  2410. - 202.6
  2411. * - WIFI_STATIC_RX_BUFFER_NUM
  2412. - 16
  2413. - 8
  2414. - 4
  2415. - 2
  2416. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2417. - 128
  2418. - 128
  2419. - 128
  2420. - 128
  2421. * - WIFI_STATIC_TX_BUFFER_NUM
  2422. - 16
  2423. - 8
  2424. - 4
  2425. - 2
  2426. * - WIFI_RX_BA_WIN
  2427. - 16
  2428. - 16
  2429. - 8
  2430. - Disable
  2431. * - TCP_SND_BUF_DEFAULT (KB)
  2432. - 65
  2433. - 65
  2434. - 65
  2435. - 65
  2436. * - TCP_WND_DEFAULT (KB)
  2437. - 65
  2438. - 65
  2439. - 65
  2440. - 65
  2441. * - WIFI_IRAM_OPT
  2442. - 15
  2443. - 15
  2444. - 15
  2445. - 0
  2446. * - WIFI_RX_IRAM_OPT
  2447. - 16
  2448. - 16
  2449. - 0
  2450. - 0
  2451. * - LWIP_IRAM_OPTIMIZATION
  2452. - 13
  2453. - 0
  2454. - 0
  2455. - 0
  2456. * - TCP TX throughput (Mbit/s)
  2457. - 37.5
  2458. - 31.7
  2459. - 21.7
  2460. - 14.6
  2461. * - TCP RX throughput (Mbit/s)
  2462. - 31.5
  2463. - 29.8
  2464. - 26.5
  2465. - 21.1
  2466. * - UDP TX throughput (Mbit/s)
  2467. - 69.1
  2468. - 31.5
  2469. - 27.1
  2470. - 24.1
  2471. * - UDP RX throughput (Mbit/s)
  2472. - 40.1
  2473. - 38.5
  2474. - 37.5
  2475. - 36.9
  2476. .. only:: esp32s2
  2477. .. list-table::
  2478. :header-rows: 1
  2479. :widths: 10 10 10 10 15
  2480. * - Rank
  2481. - Iperf
  2482. - Default
  2483. - Memory saving
  2484. - Minimum
  2485. * - Available memory (KB)
  2486. - 70.6
  2487. - 96.4
  2488. - 118.8
  2489. - 148.2
  2490. * - WIFI_STATIC_RX_BUFFER_NUM
  2491. - 8
  2492. - 8
  2493. - 6
  2494. - 4
  2495. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2496. - 64
  2497. - 64
  2498. - 64
  2499. - 64
  2500. * - WIFI_STATIC_TX_BUFFER_NUM
  2501. - 16
  2502. - 8
  2503. - 6
  2504. - 4
  2505. * - WIFI_RX_BA_WIN
  2506. - 16
  2507. - 6
  2508. - 6
  2509. - Disable
  2510. * - TCP_SND_BUF_DEFAULT (KB)
  2511. - 32
  2512. - 32
  2513. - 32
  2514. - 32
  2515. * - TCP_WND_DEFAULT (KB)
  2516. - 32
  2517. - 32
  2518. - 32
  2519. - 32
  2520. * - WIFI_IRAM_OPT
  2521. - 15
  2522. - 15
  2523. - 15
  2524. - 0
  2525. * - WIFI_RX_IRAM_OPT
  2526. - 16
  2527. - 16
  2528. - 0
  2529. - 0
  2530. * - LWIP_IRAM_OPTIMIZATION
  2531. - 13
  2532. - 0
  2533. - 0
  2534. - 0
  2535. * - INSTRUCTION_CACHE
  2536. - 16
  2537. - 16
  2538. - 16
  2539. - 8
  2540. * - INSTRUCTION_CACHE_LINE
  2541. - 16
  2542. - 16
  2543. - 16
  2544. - 16
  2545. * - DATA_CACHE
  2546. - 8
  2547. - 8
  2548. - 8
  2549. - 8
  2550. * - DATA_CACHE_LINE
  2551. - 32
  2552. - 32
  2553. - 32
  2554. - 32
  2555. * - TCP TX throughput (Mbit/s)
  2556. - 40.1
  2557. - 29.2
  2558. - 20.1
  2559. - 8.9
  2560. * - TCP RX throughput (Mbit/s)
  2561. - 21.9
  2562. - 16.8
  2563. - 14.8
  2564. - 9.6
  2565. * - UDP TX throughput (Mbit/s)
  2566. - 50.1
  2567. - 25.7
  2568. - 22.4
  2569. - 10.2
  2570. * - UDP RX throughput (Mbit/s)
  2571. - 45.3
  2572. - 43.1
  2573. - 28.5
  2574. - 15.1
  2575. .. note::
  2576. Reaching peak performance may cause task watchdog. It is a normal phenomenon considering the CPU may have no time for lower priority tasks.
  2577. .. only:: esp32s3
  2578. **PSRAM with 4 lines:**
  2579. .. list-table::
  2580. :header-rows: 1
  2581. :widths: 25 20 25 25 25
  2582. * - Rank
  2583. - Iperf
  2584. - Default
  2585. - Memory saving
  2586. - Minimum
  2587. * - Available memory (KB)
  2588. - 50.3
  2589. - 158.7
  2590. - 198.2
  2591. - 228.9
  2592. * - WIFI_STATIC_RX_BUFFER_NUM
  2593. - 24
  2594. - 8
  2595. - 6
  2596. - 4
  2597. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2598. - 85
  2599. - 64
  2600. - 32
  2601. - 32
  2602. * - WIFI_STATIC_TX_BUFFER_NUM
  2603. - 32
  2604. - 32
  2605. - 6
  2606. - 4
  2607. * - WIFI_RX_BA_WIN
  2608. - 32
  2609. - 16
  2610. - 12
  2611. - Disable
  2612. * - TCP_SND_BUF_DEFAULT (KB)
  2613. - 85
  2614. - 32
  2615. - 32
  2616. - 32
  2617. * - TCP_WND_DEFAULT (KB)
  2618. - 85
  2619. - 32
  2620. - 32
  2621. - 32
  2622. * - WIFI_IRAM_OPT
  2623. - 15
  2624. - 15
  2625. - 15
  2626. - 0
  2627. * - WIFI_RX_IRAM_OPT
  2628. - 16
  2629. - 16
  2630. - 0
  2631. - 0
  2632. * - LWIP_IRAM_OPTIMIZATION
  2633. - 13
  2634. - 0
  2635. - 0
  2636. - 0
  2637. * - LWIP_UDP_RECVMBOX_SIZE
  2638. - 16
  2639. - 16
  2640. - 16
  2641. - 16
  2642. * - INSTRUCTION_CACHE
  2643. - 32
  2644. - 16
  2645. - 16
  2646. - 16
  2647. * - INSTRUCTION_CACHE_LINE
  2648. - 32
  2649. - 16
  2650. - 16
  2651. - 16
  2652. * - INSTRUCTION_CACHE_WAYS
  2653. - 8
  2654. - 8
  2655. - 8
  2656. - 8
  2657. * - DATA_CACHE
  2658. - 64
  2659. - 16
  2660. - 16
  2661. - 16
  2662. * - DATA_CACHE_LINE
  2663. - 32
  2664. - 32
  2665. - 32
  2666. - 32
  2667. * - DATA_CACHE_WAYS
  2668. - 8
  2669. - 8
  2670. - 8
  2671. - 8
  2672. * - TCP TX throughput (Mbit/s)
  2673. - 93.1
  2674. - 62.5
  2675. - 41.3
  2676. - 42.7
  2677. * - TCP RX throughput (Mbit/s)
  2678. - 88.9
  2679. - 46.5
  2680. - 46.2
  2681. - 37.9
  2682. * - UDP TX throughput (Mbit/s)
  2683. - 106.4
  2684. - 106.2
  2685. - 60.7
  2686. - 50
  2687. * - UDP RX throughput (Mbit/s)
  2688. - 99.8
  2689. - 92.6
  2690. - 94.3
  2691. - 53.3
  2692. **PSRAM with 8 lines:**
  2693. .. list-table::
  2694. :header-rows: 1
  2695. :widths: 25 20 25 25 25
  2696. * - Rank
  2697. - Iperf
  2698. - Default
  2699. - Memory saving
  2700. - Minimum
  2701. * - Available memory (KB)
  2702. - 49.1
  2703. - 151.3
  2704. - 215.3
  2705. - 243.6
  2706. * - WIFI_STATIC_RX_BUFFER_NUM
  2707. - 24
  2708. - 8
  2709. - 6
  2710. - 4
  2711. * - WIFI_DYNAMIC_RX_BUFFER_NUM
  2712. - 85
  2713. - 64
  2714. - 32
  2715. - 32
  2716. * - WIFI_STATIC_TX_BUFFER_NUM
  2717. - 32
  2718. - 32
  2719. - 6
  2720. - 4
  2721. * - WIFI_RX_BA_WIN
  2722. - 32
  2723. - 16
  2724. - 12
  2725. - Disable
  2726. * - TCP_SND_BUF_DEFAULT (KB)
  2727. - 85
  2728. - 32
  2729. - 32
  2730. - 32
  2731. * - TCP_WND_DEFAULT (KB)
  2732. - 85
  2733. - 32
  2734. - 32
  2735. - 32
  2736. * - WIFI_IRAM_OPT
  2737. - 15
  2738. - 15
  2739. - 15
  2740. - 0
  2741. * - WIFI_RX_IRAM_OPT
  2742. - 16
  2743. - 16
  2744. - 0
  2745. - 0
  2746. * - LWIP_IRAM_OPTIMIZATION
  2747. - 13
  2748. - 0
  2749. - 0
  2750. - 0
  2751. * - LWIP_UDP_RECVMBOX_SIZE
  2752. - 16
  2753. - 16
  2754. - 16
  2755. - 16
  2756. * - INSTRUCTION_CACHE
  2757. - 32
  2758. - 16
  2759. - 16
  2760. - 16
  2761. * - INSTRUCTION_CACHE_LINE
  2762. - 32
  2763. - 16
  2764. - 16
  2765. - 16
  2766. * - INSTRUCTION_CACHE_WAYS
  2767. - 8
  2768. - 8
  2769. - 8
  2770. - 8
  2771. * - DATA_CACHE
  2772. - 64
  2773. - 16
  2774. - 16
  2775. - 16
  2776. * - DATA_CACHE_LINE
  2777. - 32
  2778. - 32
  2779. - 32
  2780. - 32
  2781. * - DATA_CACHE_WAYS
  2782. - 8
  2783. - 8
  2784. - 8
  2785. - 8
  2786. * - TCP TX throughput (Mbit/s)
  2787. - 93.3
  2788. - 58.4
  2789. - 37.1
  2790. - 35.6
  2791. * - TCP RX throughput (Mbit/s)
  2792. - 86.1
  2793. - 43.6
  2794. - 42.5
  2795. - 35
  2796. * - UDP TX throughput (Mbit/s)
  2797. - 104.7
  2798. - 82.2
  2799. - 60.4
  2800. - 47.9
  2801. * - UDP RX throughput (Mbit/s)
  2802. - 104.6
  2803. - 104.8
  2804. - 104
  2805. - 55.7
  2806. Wi-Fi Menuconfig
  2807. -----------------------
  2808. Wi-Fi Buffer Configure
  2809. +++++++++++++++++++++++
  2810. If you are going to modify the default number or type of buffer, it would be helpful to also have an overview of how the buffer is allocated/freed in the data path. The following diagram shows this process in the TX direction:
  2811. .. blockdiag::
  2812. :caption: TX Buffer Allocation
  2813. :align: center
  2814. blockdiag buffer_allocation_tx {
  2815. # global attributes
  2816. node_height = 60;
  2817. node_width = 100;
  2818. span_width = 50;
  2819. span_height = 20;
  2820. default_shape = roundedbox;
  2821. # labels of diagram nodes
  2822. APPL_TASK [label="Application\n task", fontsize=12];
  2823. LwIP_TASK [label="LwIP\n task", fontsize=12];
  2824. WIFI_TASK [label="Wi-Fi\n task", fontsize=12];
  2825. # labels of description nodes
  2826. APPL_DESC [label="1> User data", width=120, height=25, shape=note, color=yellow];
  2827. LwIP_DESC [label="2> Pbuf", width=120, height=25, shape=note, color=yellow];
  2828. WIFI_DESC [label="3> Dynamic (Static)\n TX Buffer", width=150, height=40, shape=note, color=yellow];
  2829. # node connections
  2830. APPL_TASK -> LwIP_TASK -> WIFI_TASK
  2831. APPL_DESC -> LwIP_DESC -> WIFI_DESC [style=none]
  2832. }
  2833. Description:
  2834. - The application allocates the data which needs to be sent out.
  2835. - The application calls TCPIP-/Socket-related APIs to send the user data. These APIs will allocate a PBUF used in LwIP, and make a copy of the user data.
  2836. - When LwIP calls a Wi-Fi API to send the PBUF, the Wi-Fi API will allocate a "Dynamic Tx Buffer" or "Static Tx Buffer", make a copy of the LwIP PBUF, and finally send the data.
  2837. The following diagram shows how buffer is allocated/freed in the RX direction:
  2838. .. blockdiag::
  2839. :caption: RX Buffer Allocation
  2840. :align: center
  2841. blockdiag buffer_allocation_rx {
  2842. # global attributes
  2843. node_height = 60;
  2844. node_width = 100;
  2845. span_width = 40;
  2846. span_height = 20;
  2847. default_shape = roundedbox;
  2848. # labels of diagram nodes
  2849. APPL_TASK [label="Application\n task", fontsize=12];
  2850. LwIP_TASK [label="LwIP\n task", fontsize=12];
  2851. WIFI_TASK [label="Wi-Fi\n task", fontsize=12];
  2852. WIFI_INTR [label="Wi-Fi\n interrupt", fontsize=12];
  2853. # labels of description nodes
  2854. APPL_DESC [label="4> User\n Data Buffer", height=40, shape=note, color=yellow];
  2855. LwIP_DESC [label="3> Pbuf", height=40, shape=note, color=yellow];
  2856. WIFI_DESC [label="2> Dynamic\n RX Buffer", height=40, shape=note, color=yellow];
  2857. INTR_DESC [label="1> Static\n RX Buffer", height=40, shape=note, color=yellow];
  2858. # node connections
  2859. APPL_TASK <- LwIP_TASK <- WIFI_TASK <- WIFI_INTR
  2860. APPL_DESC <- LwIP_DESC <- WIFI_DESC <- INTR_DESC [style=none]
  2861. }
  2862. Description:
  2863. - The Wi-Fi hardware receives a packet over the air and puts the packet content to the "Static Rx Buffer", which is also called "RX DMA Buffer".
  2864. - The Wi-Fi driver allocates a "Dynamic Rx Buffer", makes a copy of the "Static Rx Buffer", and returns the "Static Rx Buffer" to hardware.
  2865. - The Wi-Fi driver delivers the packet to the upper-layer (LwIP), and allocates a PBUF for holding the "Dynamic Rx Buffer".
  2866. - The application receives data from LwIP.
  2867. The diagram shows the configuration of the Wi-Fi internal buffer.
  2868. .. list-table::
  2869. :header-rows: 1
  2870. :widths: 10 10 10 10 25
  2871. * - Buffer Type
  2872. - Alloc Type
  2873. - Default
  2874. - Configurable
  2875. - Description
  2876. * - Static RX Buffer (Hardware RX Buffer)
  2877. - Static
  2878. - 10 * 1600 Bytes
  2879. - Yes
  2880. - This is a kind of DMA memory. It is initialized in :cpp:func:`esp_wifi_init()` and freed in :cpp:func:`esp_wifi_deinit()`. The ‘Static Rx Buffer’ forms the hardware receiving list. Upon receiving a frame over the air, hardware writes the frame into the buffer and raises an interrupt to the CPU. Then, the Wi-Fi driver reads the content from the buffer and returns the buffer back to the list.
  2881. If needs be, the application can reduce the memory statically allocated by Wi-Fi. It can reduce this value from 10 to 6 to save 6400 Bytes of memory. It is not recommended to reduce the configuration to a value less than 6 unless the AMPDU feature is disabled.
  2882. * - Dynamic RX Buffer
  2883. - Dynamic
  2884. - 32
  2885. - Yes
  2886. - The buffer length is variable and it depends on the received frames’ length. When the Wi-Fi driver receives a frame from the ‘Hardware Rx Buffer’, the ‘Dynamic Rx Buffer’ needs to be allocated from the heap. The number of the Dynamic Rx Buffer, configured in the menuconfig, is used to limit the total un-freed Dynamic Rx Buffer number.
  2887. * - Dynamic TX Buffer
  2888. - Dynamic
  2889. - 32
  2890. - Yes
  2891. - This is a kind of DMA memory. It is allocated to the heap. When the upper-layer (LwIP) sends packets to the Wi-Fi driver, it firstly allocates a ‘Dynamic TX Buffer’ and makes a copy of the upper-layer buffer.
  2892. The Dynamic and Static TX Buffers are mutually exclusive.
  2893. * - Static TX Buffer
  2894. - Static
  2895. - 16 * 1600Bytes
  2896. - Yes
  2897. - This is a kind of DMA memory. It is initialized in :cpp:func:`esp_wifi_init()` and freed in :cpp:func:`esp_wifi_deinit()`. When the upper-layer (LwIP) sends packets to the Wi-Fi driver, it firstly allocates a ‘Static TX Buffer’ and makes a copy of the upper-layer buffer.
  2898. The Dynamic and Static TX Buffer are mutually exclusive.
  2899. The TX buffer must be a DMA buffer. For this reason, if PSRAM is enabled, the TX buffer must be static.
  2900. * - Management Short Buffer
  2901. - Dynamic
  2902. - 8
  2903. - NO
  2904. - Wi-Fi driver’s internal buffer.
  2905. * - Management Long Buffer
  2906. - Dynamic
  2907. - 32
  2908. - NO
  2909. - Wi-Fi driver’s internal buffer.
  2910. * - Management Long Long Buffer
  2911. - Dynamic
  2912. - 32
  2913. - NO
  2914. - Wi-Fi driver’s internal buffer.
  2915. Wi-Fi NVS Flash
  2916. +++++++++++++++++++++
  2917. If the Wi-Fi NVS flash is enabled, all Wi-Fi configurations set via the Wi-Fi APIs will be stored into flash, and the Wi-Fi driver will start up with these configurations the next time it powers on/reboots. However, the application can choose to disable the Wi-Fi NVS flash if it does not need to store the configurations into persistent memory, or has its own persistent storage, or simply due to debugging reasons, etc.
  2918. Wi-Fi Aggregate MAC Protocol Data Unit (AMPDU)
  2919. ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2920. {IDF_TARGET_NAME} supports both receiving and transmitting AMPDU, and the AMPDU can greatly improve the Wi-Fi throughput.
  2921. Generally, the AMPDU should be enabled. Disabling AMPDU is usually for debugging purposes.
  2922. Troubleshooting
  2923. ---------------
  2924. Please refer to a separate document with :doc:`wireshark-user-guide`.
  2925. .. toctree::
  2926. :hidden:
  2927. wireshark-user-guide