util.c 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2002-2005, Instant802 Networks, Inc.
  4. * Copyright 2005-2006, Devicescape Software, Inc.
  5. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  6. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright 2013-2014 Intel Mobile Communications GmbH
  8. * Copyright (C) 2015-2017 Intel Deutschland GmbH
  9. * Copyright (C) 2018-2025 Intel Corporation
  10. *
  11. * utilities for mac80211
  12. */
  13. #include <net/mac80211.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/export.h>
  16. #include <linux/types.h>
  17. #include <linux/slab.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/if_arp.h>
  21. #include <linux/bitmap.h>
  22. #include <linux/crc32.h>
  23. #include <net/net_namespace.h>
  24. #include <net/cfg80211.h>
  25. #include <net/rtnetlink.h>
  26. #include <kunit/visibility.h>
  27. #include "ieee80211_i.h"
  28. #include "driver-ops.h"
  29. #include "rate.h"
  30. #include "mesh.h"
  31. #include "wme.h"
  32. #include "led.h"
  33. #include "wep.h"
  34. /* privid for wiphys to determine whether they belong to us or not */
  35. const void *const mac80211_wiphy_privid = &mac80211_wiphy_privid;
  36. struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
  37. {
  38. struct ieee80211_local *local;
  39. local = wiphy_priv(wiphy);
  40. return &local->hw;
  41. }
  42. EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
  43. const struct ieee80211_conn_settings ieee80211_conn_settings_unlimited = {
  44. .mode = IEEE80211_CONN_MODE_EHT,
  45. .bw_limit = IEEE80211_CONN_BW_LIMIT_320,
  46. };
  47. u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
  48. enum nl80211_iftype type)
  49. {
  50. __le16 fc = hdr->frame_control;
  51. if (ieee80211_is_data(fc)) {
  52. if (len < 24) /* drop incorrect hdr len (data) */
  53. return NULL;
  54. if (ieee80211_has_a4(fc))
  55. return NULL;
  56. if (ieee80211_has_tods(fc))
  57. return hdr->addr1;
  58. if (ieee80211_has_fromds(fc))
  59. return hdr->addr2;
  60. return hdr->addr3;
  61. }
  62. if (ieee80211_is_s1g_beacon(fc)) {
  63. struct ieee80211_ext *ext = (void *) hdr;
  64. return ext->u.s1g_beacon.sa;
  65. }
  66. if (ieee80211_is_mgmt(fc)) {
  67. if (len < 24) /* drop incorrect hdr len (mgmt) */
  68. return NULL;
  69. return hdr->addr3;
  70. }
  71. if (ieee80211_is_ctl(fc)) {
  72. if (ieee80211_is_pspoll(fc))
  73. return hdr->addr1;
  74. if (ieee80211_is_back_req(fc)) {
  75. switch (type) {
  76. case NL80211_IFTYPE_STATION:
  77. return hdr->addr2;
  78. case NL80211_IFTYPE_AP:
  79. case NL80211_IFTYPE_AP_VLAN:
  80. return hdr->addr1;
  81. default:
  82. break; /* fall through to the return */
  83. }
  84. }
  85. }
  86. return NULL;
  87. }
  88. EXPORT_SYMBOL(ieee80211_get_bssid);
  89. void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
  90. {
  91. struct sk_buff *skb;
  92. struct ieee80211_hdr *hdr;
  93. skb_queue_walk(&tx->skbs, skb) {
  94. hdr = (struct ieee80211_hdr *) skb->data;
  95. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  96. }
  97. }
  98. int ieee80211_frame_duration(enum nl80211_band band, size_t len,
  99. int rate, int erp, int short_preamble)
  100. {
  101. int dur;
  102. /* calculate duration (in microseconds, rounded up to next higher
  103. * integer if it includes a fractional microsecond) to send frame of
  104. * len bytes (does not include FCS) at the given rate. Duration will
  105. * also include SIFS.
  106. *
  107. * rate is in 100 kbps, so divident is multiplied by 10 in the
  108. * DIV_ROUND_UP() operations.
  109. */
  110. if (band == NL80211_BAND_5GHZ || erp) {
  111. /*
  112. * OFDM:
  113. *
  114. * N_DBPS = DATARATE x 4
  115. * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
  116. * (16 = SIGNAL time, 6 = tail bits)
  117. * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
  118. *
  119. * T_SYM = 4 usec
  120. * 802.11a - 18.5.2: aSIFSTime = 16 usec
  121. * 802.11g - 19.8.4: aSIFSTime = 10 usec +
  122. * signal ext = 6 usec
  123. */
  124. dur = 16; /* SIFS + signal ext */
  125. dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */
  126. dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */
  127. /* rates should already consider the channel bandwidth,
  128. * don't apply divisor again.
  129. */
  130. dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
  131. 4 * rate); /* T_SYM x N_SYM */
  132. } else {
  133. /*
  134. * 802.11b or 802.11g with 802.11b compatibility:
  135. * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
  136. * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
  137. *
  138. * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
  139. * aSIFSTime = 10 usec
  140. * aPreambleLength = 144 usec or 72 usec with short preamble
  141. * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
  142. */
  143. dur = 10; /* aSIFSTime = 10 usec */
  144. dur += short_preamble ? (72 + 24) : (144 + 48);
  145. dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
  146. }
  147. return dur;
  148. }
  149. /* Exported duration function for driver use */
  150. __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
  151. struct ieee80211_vif *vif,
  152. enum nl80211_band band,
  153. size_t frame_len,
  154. struct ieee80211_rate *rate)
  155. {
  156. struct ieee80211_sub_if_data *sdata;
  157. u16 dur;
  158. int erp;
  159. bool short_preamble = false;
  160. erp = 0;
  161. if (vif) {
  162. sdata = vif_to_sdata(vif);
  163. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  164. if (sdata->deflink.operating_11g_mode)
  165. erp = rate->flags & IEEE80211_RATE_ERP_G;
  166. }
  167. dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
  168. short_preamble);
  169. return cpu_to_le16(dur);
  170. }
  171. EXPORT_SYMBOL(ieee80211_generic_frame_duration);
  172. __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
  173. struct ieee80211_vif *vif, size_t frame_len,
  174. const struct ieee80211_tx_info *frame_txctl)
  175. {
  176. struct ieee80211_local *local = hw_to_local(hw);
  177. struct ieee80211_rate *rate;
  178. struct ieee80211_sub_if_data *sdata;
  179. bool short_preamble;
  180. int erp, bitrate;
  181. u16 dur;
  182. struct ieee80211_supported_band *sband;
  183. sband = local->hw.wiphy->bands[frame_txctl->band];
  184. short_preamble = false;
  185. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  186. erp = 0;
  187. if (vif) {
  188. sdata = vif_to_sdata(vif);
  189. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  190. if (sdata->deflink.operating_11g_mode)
  191. erp = rate->flags & IEEE80211_RATE_ERP_G;
  192. }
  193. bitrate = rate->bitrate;
  194. /* CTS duration */
  195. dur = ieee80211_frame_duration(sband->band, 10, bitrate,
  196. erp, short_preamble);
  197. /* Data frame duration */
  198. dur += ieee80211_frame_duration(sband->band, frame_len, bitrate,
  199. erp, short_preamble);
  200. /* ACK duration */
  201. dur += ieee80211_frame_duration(sband->band, 10, bitrate,
  202. erp, short_preamble);
  203. return cpu_to_le16(dur);
  204. }
  205. EXPORT_SYMBOL(ieee80211_rts_duration);
  206. __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
  207. struct ieee80211_vif *vif,
  208. size_t frame_len,
  209. const struct ieee80211_tx_info *frame_txctl)
  210. {
  211. struct ieee80211_local *local = hw_to_local(hw);
  212. struct ieee80211_rate *rate;
  213. struct ieee80211_sub_if_data *sdata;
  214. bool short_preamble;
  215. int erp, bitrate;
  216. u16 dur;
  217. struct ieee80211_supported_band *sband;
  218. sband = local->hw.wiphy->bands[frame_txctl->band];
  219. short_preamble = false;
  220. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  221. erp = 0;
  222. if (vif) {
  223. sdata = vif_to_sdata(vif);
  224. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  225. if (sdata->deflink.operating_11g_mode)
  226. erp = rate->flags & IEEE80211_RATE_ERP_G;
  227. }
  228. bitrate = rate->bitrate;
  229. /* Data frame duration */
  230. dur = ieee80211_frame_duration(sband->band, frame_len, bitrate,
  231. erp, short_preamble);
  232. if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
  233. /* ACK duration */
  234. dur += ieee80211_frame_duration(sband->band, 10, bitrate,
  235. erp, short_preamble);
  236. }
  237. return cpu_to_le16(dur);
  238. }
  239. EXPORT_SYMBOL(ieee80211_ctstoself_duration);
  240. static void wake_tx_push_queue(struct ieee80211_local *local,
  241. struct ieee80211_sub_if_data *sdata,
  242. struct ieee80211_txq *queue)
  243. {
  244. struct ieee80211_tx_control control = {
  245. .sta = queue->sta,
  246. };
  247. struct sk_buff *skb;
  248. while (1) {
  249. skb = ieee80211_tx_dequeue(&local->hw, queue);
  250. if (!skb)
  251. break;
  252. drv_tx(local, &control, skb);
  253. }
  254. }
  255. /* wake_tx_queue handler for driver not implementing a custom one*/
  256. void ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw,
  257. struct ieee80211_txq *txq)
  258. {
  259. struct ieee80211_local *local = hw_to_local(hw);
  260. struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->vif);
  261. struct ieee80211_txq *queue;
  262. spin_lock(&local->handle_wake_tx_queue_lock);
  263. /* Use ieee80211_next_txq() for airtime fairness accounting */
  264. ieee80211_txq_schedule_start(hw, txq->ac);
  265. while ((queue = ieee80211_next_txq(hw, txq->ac))) {
  266. wake_tx_push_queue(local, sdata, queue);
  267. ieee80211_return_txq(hw, queue, false);
  268. }
  269. ieee80211_txq_schedule_end(hw, txq->ac);
  270. spin_unlock(&local->handle_wake_tx_queue_lock);
  271. }
  272. EXPORT_SYMBOL(ieee80211_handle_wake_tx_queue);
  273. static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
  274. {
  275. struct ieee80211_local *local = sdata->local;
  276. struct ieee80211_vif *vif = &sdata->vif;
  277. struct fq *fq = &local->fq;
  278. struct ps_data *ps = NULL;
  279. struct txq_info *txqi;
  280. struct sta_info *sta;
  281. int i;
  282. local_bh_disable();
  283. spin_lock(&fq->lock);
  284. if (!test_bit(SDATA_STATE_RUNNING, &sdata->state))
  285. goto out;
  286. if (sdata->vif.type == NL80211_IFTYPE_AP)
  287. ps = &sdata->bss->ps;
  288. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  289. if (sdata != sta->sdata)
  290. continue;
  291. for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
  292. struct ieee80211_txq *txq = sta->sta.txq[i];
  293. if (!txq)
  294. continue;
  295. txqi = to_txq_info(txq);
  296. if (ac != txq->ac)
  297. continue;
  298. if (!test_and_clear_bit(IEEE80211_TXQ_DIRTY,
  299. &txqi->flags))
  300. continue;
  301. spin_unlock(&fq->lock);
  302. drv_wake_tx_queue(local, txqi);
  303. spin_lock(&fq->lock);
  304. }
  305. }
  306. if (!vif->txq)
  307. goto out;
  308. txqi = to_txq_info(vif->txq);
  309. if (!test_and_clear_bit(IEEE80211_TXQ_DIRTY, &txqi->flags) ||
  310. (ps && atomic_read(&ps->num_sta_ps)) || ac != vif->txq->ac)
  311. goto out;
  312. spin_unlock(&fq->lock);
  313. drv_wake_tx_queue(local, txqi);
  314. local_bh_enable();
  315. return;
  316. out:
  317. spin_unlock(&fq->lock);
  318. local_bh_enable();
  319. }
  320. static void
  321. __releases(&local->queue_stop_reason_lock)
  322. __acquires(&local->queue_stop_reason_lock)
  323. _ieee80211_wake_txqs(struct ieee80211_local *local, unsigned long *flags)
  324. {
  325. struct ieee80211_sub_if_data *sdata;
  326. int n_acs = IEEE80211_NUM_ACS;
  327. int i;
  328. rcu_read_lock();
  329. if (local->hw.queues < IEEE80211_NUM_ACS)
  330. n_acs = 1;
  331. for (i = 0; i < local->hw.queues; i++) {
  332. if (local->queue_stop_reasons[i])
  333. continue;
  334. spin_unlock_irqrestore(&local->queue_stop_reason_lock, *flags);
  335. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  336. int ac;
  337. for (ac = 0; ac < n_acs; ac++) {
  338. int ac_queue = sdata->vif.hw_queue[ac];
  339. if (ac_queue == i ||
  340. sdata->vif.cab_queue == i)
  341. __ieee80211_wake_txqs(sdata, ac);
  342. }
  343. }
  344. spin_lock_irqsave(&local->queue_stop_reason_lock, *flags);
  345. }
  346. rcu_read_unlock();
  347. }
  348. void ieee80211_wake_txqs(struct tasklet_struct *t)
  349. {
  350. struct ieee80211_local *local = from_tasklet(local, t,
  351. wake_txqs_tasklet);
  352. unsigned long flags;
  353. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  354. _ieee80211_wake_txqs(local, &flags);
  355. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  356. }
  357. static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
  358. enum queue_stop_reason reason,
  359. bool refcounted,
  360. unsigned long *flags)
  361. {
  362. struct ieee80211_local *local = hw_to_local(hw);
  363. trace_wake_queue(local, queue, reason);
  364. if (WARN_ON(queue >= hw->queues))
  365. return;
  366. if (!test_bit(reason, &local->queue_stop_reasons[queue]))
  367. return;
  368. if (!refcounted) {
  369. local->q_stop_reasons[queue][reason] = 0;
  370. } else {
  371. local->q_stop_reasons[queue][reason]--;
  372. if (WARN_ON(local->q_stop_reasons[queue][reason] < 0))
  373. local->q_stop_reasons[queue][reason] = 0;
  374. }
  375. if (local->q_stop_reasons[queue][reason] == 0)
  376. __clear_bit(reason, &local->queue_stop_reasons[queue]);
  377. if (local->queue_stop_reasons[queue] != 0)
  378. /* someone still has this queue stopped */
  379. return;
  380. if (!skb_queue_empty(&local->pending[queue]))
  381. tasklet_schedule(&local->tx_pending_tasklet);
  382. /*
  383. * Calling _ieee80211_wake_txqs here can be a problem because it may
  384. * release queue_stop_reason_lock which has been taken by
  385. * __ieee80211_wake_queue's caller. It is certainly not very nice to
  386. * release someone's lock, but it is fine because all the callers of
  387. * __ieee80211_wake_queue call it right before releasing the lock.
  388. */
  389. if (reason == IEEE80211_QUEUE_STOP_REASON_DRIVER)
  390. tasklet_schedule(&local->wake_txqs_tasklet);
  391. else
  392. _ieee80211_wake_txqs(local, flags);
  393. }
  394. void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
  395. enum queue_stop_reason reason,
  396. bool refcounted)
  397. {
  398. struct ieee80211_local *local = hw_to_local(hw);
  399. unsigned long flags;
  400. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  401. __ieee80211_wake_queue(hw, queue, reason, refcounted, &flags);
  402. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  403. }
  404. void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
  405. {
  406. ieee80211_wake_queue_by_reason(hw, queue,
  407. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  408. false);
  409. }
  410. EXPORT_SYMBOL(ieee80211_wake_queue);
  411. static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
  412. enum queue_stop_reason reason,
  413. bool refcounted)
  414. {
  415. struct ieee80211_local *local = hw_to_local(hw);
  416. trace_stop_queue(local, queue, reason);
  417. if (WARN_ON(queue >= hw->queues))
  418. return;
  419. if (!refcounted)
  420. local->q_stop_reasons[queue][reason] = 1;
  421. else
  422. local->q_stop_reasons[queue][reason]++;
  423. set_bit(reason, &local->queue_stop_reasons[queue]);
  424. }
  425. void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
  426. enum queue_stop_reason reason,
  427. bool refcounted)
  428. {
  429. struct ieee80211_local *local = hw_to_local(hw);
  430. unsigned long flags;
  431. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  432. __ieee80211_stop_queue(hw, queue, reason, refcounted);
  433. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  434. }
  435. void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
  436. {
  437. ieee80211_stop_queue_by_reason(hw, queue,
  438. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  439. false);
  440. }
  441. EXPORT_SYMBOL(ieee80211_stop_queue);
  442. void ieee80211_add_pending_skb(struct ieee80211_local *local,
  443. struct sk_buff *skb)
  444. {
  445. struct ieee80211_hw *hw = &local->hw;
  446. unsigned long flags;
  447. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  448. int queue = info->hw_queue;
  449. if (WARN_ON(!info->control.vif)) {
  450. ieee80211_free_txskb(&local->hw, skb);
  451. return;
  452. }
  453. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  454. __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  455. false);
  456. __skb_queue_tail(&local->pending[queue], skb);
  457. __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  458. false, &flags);
  459. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  460. }
  461. void ieee80211_add_pending_skbs(struct ieee80211_local *local,
  462. struct sk_buff_head *skbs)
  463. {
  464. struct ieee80211_hw *hw = &local->hw;
  465. struct sk_buff *skb;
  466. unsigned long flags;
  467. int queue, i;
  468. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  469. while ((skb = skb_dequeue(skbs))) {
  470. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  471. if (WARN_ON(!info->control.vif)) {
  472. ieee80211_free_txskb(&local->hw, skb);
  473. continue;
  474. }
  475. queue = info->hw_queue;
  476. __ieee80211_stop_queue(hw, queue,
  477. IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  478. false);
  479. __skb_queue_tail(&local->pending[queue], skb);
  480. }
  481. for (i = 0; i < hw->queues; i++)
  482. __ieee80211_wake_queue(hw, i,
  483. IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  484. false, &flags);
  485. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  486. }
  487. void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
  488. unsigned long queues,
  489. enum queue_stop_reason reason,
  490. bool refcounted)
  491. {
  492. struct ieee80211_local *local = hw_to_local(hw);
  493. unsigned long flags;
  494. int i;
  495. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  496. for_each_set_bit(i, &queues, hw->queues)
  497. __ieee80211_stop_queue(hw, i, reason, refcounted);
  498. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  499. }
  500. void ieee80211_stop_queues(struct ieee80211_hw *hw)
  501. {
  502. ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  503. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  504. false);
  505. }
  506. EXPORT_SYMBOL(ieee80211_stop_queues);
  507. int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
  508. {
  509. struct ieee80211_local *local = hw_to_local(hw);
  510. unsigned long flags;
  511. int ret;
  512. if (WARN_ON(queue >= hw->queues))
  513. return true;
  514. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  515. ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
  516. &local->queue_stop_reasons[queue]);
  517. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  518. return ret;
  519. }
  520. EXPORT_SYMBOL(ieee80211_queue_stopped);
  521. void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
  522. unsigned long queues,
  523. enum queue_stop_reason reason,
  524. bool refcounted)
  525. {
  526. struct ieee80211_local *local = hw_to_local(hw);
  527. unsigned long flags;
  528. int i;
  529. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  530. for_each_set_bit(i, &queues, hw->queues)
  531. __ieee80211_wake_queue(hw, i, reason, refcounted, &flags);
  532. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  533. }
  534. void ieee80211_wake_queues(struct ieee80211_hw *hw)
  535. {
  536. ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  537. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  538. false);
  539. }
  540. EXPORT_SYMBOL(ieee80211_wake_queues);
  541. unsigned int
  542. ieee80211_get_vif_queues(struct ieee80211_local *local,
  543. struct ieee80211_sub_if_data *sdata)
  544. {
  545. unsigned int queues;
  546. if (sdata && ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
  547. int ac;
  548. queues = 0;
  549. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  550. if (sdata->vif.hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  551. queues |= BIT(sdata->vif.hw_queue[ac]);
  552. if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE)
  553. queues |= BIT(sdata->vif.cab_queue);
  554. } else {
  555. /* all queues */
  556. queues = BIT(local->hw.queues) - 1;
  557. }
  558. return queues;
  559. }
  560. void __ieee80211_flush_queues(struct ieee80211_local *local,
  561. struct ieee80211_sub_if_data *sdata,
  562. unsigned int queues, bool drop)
  563. {
  564. if (!local->ops->flush && !drop)
  565. return;
  566. /*
  567. * If no queue was set, or if the HW doesn't support
  568. * IEEE80211_HW_QUEUE_CONTROL - flush all queues
  569. */
  570. if (!queues || !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
  571. queues = ieee80211_get_vif_queues(local, sdata);
  572. ieee80211_stop_queues_by_reason(&local->hw, queues,
  573. IEEE80211_QUEUE_STOP_REASON_FLUSH,
  574. false);
  575. if (drop) {
  576. struct sta_info *sta;
  577. /* Purge the queues, so the frames on them won't be
  578. * sent during __ieee80211_wake_queue()
  579. */
  580. list_for_each_entry(sta, &local->sta_list, list) {
  581. if (sdata != sta->sdata)
  582. continue;
  583. ieee80211_purge_sta_txqs(sta);
  584. }
  585. }
  586. if (local->ops->flush)
  587. drv_flush(local, sdata, queues, drop);
  588. ieee80211_wake_queues_by_reason(&local->hw, queues,
  589. IEEE80211_QUEUE_STOP_REASON_FLUSH,
  590. false);
  591. }
  592. void ieee80211_flush_queues(struct ieee80211_local *local,
  593. struct ieee80211_sub_if_data *sdata, bool drop)
  594. {
  595. __ieee80211_flush_queues(local, sdata, 0, drop);
  596. }
  597. static void __iterate_interfaces(struct ieee80211_local *local,
  598. u32 iter_flags,
  599. void (*iterator)(void *data, u8 *mac,
  600. struct ieee80211_vif *vif),
  601. void *data)
  602. {
  603. struct ieee80211_sub_if_data *sdata;
  604. bool active_only = iter_flags & IEEE80211_IFACE_ITER_ACTIVE;
  605. list_for_each_entry_rcu(sdata, &local->interfaces, list,
  606. lockdep_is_held(&local->iflist_mtx) ||
  607. lockdep_is_held(&local->hw.wiphy->mtx)) {
  608. switch (sdata->vif.type) {
  609. case NL80211_IFTYPE_MONITOR:
  610. if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
  611. continue;
  612. break;
  613. case NL80211_IFTYPE_AP_VLAN:
  614. continue;
  615. default:
  616. break;
  617. }
  618. if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) &&
  619. active_only && !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  620. continue;
  621. if ((iter_flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) &&
  622. !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  623. continue;
  624. if (ieee80211_sdata_running(sdata) || !active_only)
  625. iterator(data, sdata->vif.addr,
  626. &sdata->vif);
  627. }
  628. sdata = rcu_dereference_check(local->monitor_sdata,
  629. lockdep_is_held(&local->iflist_mtx) ||
  630. lockdep_is_held(&local->hw.wiphy->mtx));
  631. if (sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) &&
  632. (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL || !active_only ||
  633. sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  634. iterator(data, sdata->vif.addr, &sdata->vif);
  635. }
  636. void ieee80211_iterate_interfaces(
  637. struct ieee80211_hw *hw, u32 iter_flags,
  638. void (*iterator)(void *data, u8 *mac,
  639. struct ieee80211_vif *vif),
  640. void *data)
  641. {
  642. struct ieee80211_local *local = hw_to_local(hw);
  643. mutex_lock(&local->iflist_mtx);
  644. __iterate_interfaces(local, iter_flags, iterator, data);
  645. mutex_unlock(&local->iflist_mtx);
  646. }
  647. EXPORT_SYMBOL_GPL(ieee80211_iterate_interfaces);
  648. void ieee80211_iterate_active_interfaces_atomic(
  649. struct ieee80211_hw *hw, u32 iter_flags,
  650. void (*iterator)(void *data, u8 *mac,
  651. struct ieee80211_vif *vif),
  652. void *data)
  653. {
  654. struct ieee80211_local *local = hw_to_local(hw);
  655. rcu_read_lock();
  656. __iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE,
  657. iterator, data);
  658. rcu_read_unlock();
  659. }
  660. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
  661. void ieee80211_iterate_active_interfaces_mtx(
  662. struct ieee80211_hw *hw, u32 iter_flags,
  663. void (*iterator)(void *data, u8 *mac,
  664. struct ieee80211_vif *vif),
  665. void *data)
  666. {
  667. struct ieee80211_local *local = hw_to_local(hw);
  668. lockdep_assert_wiphy(hw->wiphy);
  669. __iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE,
  670. iterator, data);
  671. }
  672. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_mtx);
  673. static void __iterate_stations(struct ieee80211_local *local,
  674. void (*iterator)(void *data,
  675. struct ieee80211_sta *sta),
  676. void *data)
  677. {
  678. struct sta_info *sta;
  679. list_for_each_entry_rcu(sta, &local->sta_list, list,
  680. lockdep_is_held(&local->hw.wiphy->mtx)) {
  681. if (!sta->uploaded)
  682. continue;
  683. iterator(data, &sta->sta);
  684. }
  685. }
  686. void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
  687. void (*iterator)(void *data,
  688. struct ieee80211_sta *sta),
  689. void *data)
  690. {
  691. struct ieee80211_local *local = hw_to_local(hw);
  692. rcu_read_lock();
  693. __iterate_stations(local, iterator, data);
  694. rcu_read_unlock();
  695. }
  696. EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_atomic);
  697. void ieee80211_iterate_stations_mtx(struct ieee80211_hw *hw,
  698. void (*iterator)(void *data,
  699. struct ieee80211_sta *sta),
  700. void *data)
  701. {
  702. struct ieee80211_local *local = hw_to_local(hw);
  703. lockdep_assert_wiphy(local->hw.wiphy);
  704. __iterate_stations(local, iterator, data);
  705. }
  706. EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_mtx);
  707. struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev)
  708. {
  709. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  710. if (!ieee80211_sdata_running(sdata) ||
  711. !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  712. return NULL;
  713. return &sdata->vif;
  714. }
  715. EXPORT_SYMBOL_GPL(wdev_to_ieee80211_vif);
  716. struct wireless_dev *ieee80211_vif_to_wdev(struct ieee80211_vif *vif)
  717. {
  718. if (!vif)
  719. return NULL;
  720. return &vif_to_sdata(vif)->wdev;
  721. }
  722. EXPORT_SYMBOL_GPL(ieee80211_vif_to_wdev);
  723. /*
  724. * Nothing should have been stuffed into the workqueue during
  725. * the suspend->resume cycle. Since we can't check each caller
  726. * of this function if we are already quiescing / suspended,
  727. * check here and don't WARN since this can actually happen when
  728. * the rx path (for example) is racing against __ieee80211_suspend
  729. * and suspending / quiescing was set after the rx path checked
  730. * them.
  731. */
  732. static bool ieee80211_can_queue_work(struct ieee80211_local *local)
  733. {
  734. if (local->quiescing || (local->suspended && !local->resuming)) {
  735. pr_warn("queueing ieee80211 work while going to suspend\n");
  736. return false;
  737. }
  738. return true;
  739. }
  740. void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
  741. {
  742. struct ieee80211_local *local = hw_to_local(hw);
  743. if (!ieee80211_can_queue_work(local))
  744. return;
  745. queue_work(local->workqueue, work);
  746. }
  747. EXPORT_SYMBOL(ieee80211_queue_work);
  748. void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
  749. struct delayed_work *dwork,
  750. unsigned long delay)
  751. {
  752. struct ieee80211_local *local = hw_to_local(hw);
  753. if (!ieee80211_can_queue_work(local))
  754. return;
  755. queue_delayed_work(local->workqueue, dwork, delay);
  756. }
  757. EXPORT_SYMBOL(ieee80211_queue_delayed_work);
  758. void ieee80211_regulatory_limit_wmm_params(struct ieee80211_sub_if_data *sdata,
  759. struct ieee80211_tx_queue_params
  760. *qparam, int ac)
  761. {
  762. struct ieee80211_chanctx_conf *chanctx_conf;
  763. const struct ieee80211_reg_rule *rrule;
  764. const struct ieee80211_wmm_ac *wmm_ac;
  765. u16 center_freq = 0;
  766. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  767. sdata->vif.type != NL80211_IFTYPE_STATION)
  768. return;
  769. rcu_read_lock();
  770. chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
  771. if (chanctx_conf)
  772. center_freq = chanctx_conf->def.chan->center_freq;
  773. if (!center_freq) {
  774. rcu_read_unlock();
  775. return;
  776. }
  777. rrule = freq_reg_info(sdata->wdev.wiphy, MHZ_TO_KHZ(center_freq));
  778. if (IS_ERR_OR_NULL(rrule) || !rrule->has_wmm) {
  779. rcu_read_unlock();
  780. return;
  781. }
  782. if (sdata->vif.type == NL80211_IFTYPE_AP)
  783. wmm_ac = &rrule->wmm_rule.ap[ac];
  784. else
  785. wmm_ac = &rrule->wmm_rule.client[ac];
  786. qparam->cw_min = max_t(u16, qparam->cw_min, wmm_ac->cw_min);
  787. qparam->cw_max = max_t(u16, qparam->cw_max, wmm_ac->cw_max);
  788. qparam->aifs = max_t(u8, qparam->aifs, wmm_ac->aifsn);
  789. qparam->txop = min_t(u16, qparam->txop, wmm_ac->cot / 32);
  790. rcu_read_unlock();
  791. }
  792. void ieee80211_set_wmm_default(struct ieee80211_link_data *link,
  793. bool bss_notify, bool enable_qos)
  794. {
  795. struct ieee80211_sub_if_data *sdata = link->sdata;
  796. struct ieee80211_local *local = sdata->local;
  797. struct ieee80211_tx_queue_params qparam;
  798. struct ieee80211_chanctx_conf *chanctx_conf;
  799. int ac;
  800. bool use_11b;
  801. bool is_ocb; /* Use another EDCA parameters if dot11OCBActivated=true */
  802. int aCWmin, aCWmax;
  803. if (!local->ops->conf_tx)
  804. return;
  805. if (local->hw.queues < IEEE80211_NUM_ACS)
  806. return;
  807. memset(&qparam, 0, sizeof(qparam));
  808. rcu_read_lock();
  809. chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
  810. use_11b = (chanctx_conf &&
  811. chanctx_conf->def.chan->band == NL80211_BAND_2GHZ) &&
  812. !link->operating_11g_mode;
  813. rcu_read_unlock();
  814. is_ocb = (sdata->vif.type == NL80211_IFTYPE_OCB);
  815. /* Set defaults according to 802.11-2007 Table 7-37 */
  816. aCWmax = 1023;
  817. if (use_11b)
  818. aCWmin = 31;
  819. else
  820. aCWmin = 15;
  821. /* Confiure old 802.11b/g medium access rules. */
  822. qparam.cw_max = aCWmax;
  823. qparam.cw_min = aCWmin;
  824. qparam.txop = 0;
  825. qparam.aifs = 2;
  826. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  827. /* Update if QoS is enabled. */
  828. if (enable_qos) {
  829. switch (ac) {
  830. case IEEE80211_AC_BK:
  831. qparam.cw_max = aCWmax;
  832. qparam.cw_min = aCWmin;
  833. qparam.txop = 0;
  834. if (is_ocb)
  835. qparam.aifs = 9;
  836. else
  837. qparam.aifs = 7;
  838. break;
  839. /* never happens but let's not leave undefined */
  840. default:
  841. case IEEE80211_AC_BE:
  842. qparam.cw_max = aCWmax;
  843. qparam.cw_min = aCWmin;
  844. qparam.txop = 0;
  845. if (is_ocb)
  846. qparam.aifs = 6;
  847. else
  848. qparam.aifs = 3;
  849. break;
  850. case IEEE80211_AC_VI:
  851. qparam.cw_max = aCWmin;
  852. qparam.cw_min = (aCWmin + 1) / 2 - 1;
  853. if (is_ocb)
  854. qparam.txop = 0;
  855. else if (use_11b)
  856. qparam.txop = 6016/32;
  857. else
  858. qparam.txop = 3008/32;
  859. if (is_ocb)
  860. qparam.aifs = 3;
  861. else
  862. qparam.aifs = 2;
  863. break;
  864. case IEEE80211_AC_VO:
  865. qparam.cw_max = (aCWmin + 1) / 2 - 1;
  866. qparam.cw_min = (aCWmin + 1) / 4 - 1;
  867. if (is_ocb)
  868. qparam.txop = 0;
  869. else if (use_11b)
  870. qparam.txop = 3264/32;
  871. else
  872. qparam.txop = 1504/32;
  873. qparam.aifs = 2;
  874. break;
  875. }
  876. }
  877. ieee80211_regulatory_limit_wmm_params(sdata, &qparam, ac);
  878. qparam.uapsd = false;
  879. link->tx_conf[ac] = qparam;
  880. drv_conf_tx(local, link, ac, &qparam);
  881. }
  882. if (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  883. sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
  884. sdata->vif.type != NL80211_IFTYPE_NAN) {
  885. link->conf->qos = enable_qos;
  886. if (bss_notify)
  887. ieee80211_link_info_change_notify(sdata, link,
  888. BSS_CHANGED_QOS);
  889. }
  890. }
  891. void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  892. u16 transaction, u16 auth_alg, u16 status,
  893. const u8 *extra, size_t extra_len, const u8 *da,
  894. const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx,
  895. u32 tx_flags)
  896. {
  897. struct ieee80211_local *local = sdata->local;
  898. struct sk_buff *skb;
  899. struct ieee80211_mgmt *mgmt;
  900. bool multi_link = ieee80211_vif_is_mld(&sdata->vif);
  901. struct {
  902. u8 id;
  903. u8 len;
  904. u8 ext_id;
  905. struct ieee80211_multi_link_elem ml;
  906. struct ieee80211_mle_basic_common_info basic;
  907. } __packed mle = {
  908. .id = WLAN_EID_EXTENSION,
  909. .len = sizeof(mle) - 2,
  910. .ext_id = WLAN_EID_EXT_EHT_MULTI_LINK,
  911. .ml.control = cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC),
  912. .basic.len = sizeof(mle.basic),
  913. };
  914. int err;
  915. memcpy(mle.basic.mld_mac_addr, sdata->vif.addr, ETH_ALEN);
  916. /* 24 + 6 = header + auth_algo + auth_transaction + status_code */
  917. skb = dev_alloc_skb(local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN +
  918. 24 + 6 + extra_len + IEEE80211_WEP_ICV_LEN +
  919. multi_link * sizeof(mle));
  920. if (!skb)
  921. return;
  922. skb_reserve(skb, local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN);
  923. mgmt = skb_put_zero(skb, 24 + 6);
  924. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  925. IEEE80211_STYPE_AUTH);
  926. memcpy(mgmt->da, da, ETH_ALEN);
  927. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  928. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  929. mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
  930. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  931. mgmt->u.auth.status_code = cpu_to_le16(status);
  932. if (extra)
  933. skb_put_data(skb, extra, extra_len);
  934. if (multi_link)
  935. skb_put_data(skb, &mle, sizeof(mle));
  936. if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
  937. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  938. err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
  939. if (WARN_ON(err)) {
  940. kfree_skb(skb);
  941. return;
  942. }
  943. }
  944. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  945. tx_flags;
  946. ieee80211_tx_skb(sdata, skb);
  947. }
  948. void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  949. const u8 *da, const u8 *bssid,
  950. u16 stype, u16 reason,
  951. bool send_frame, u8 *frame_buf)
  952. {
  953. struct ieee80211_local *local = sdata->local;
  954. struct sk_buff *skb;
  955. struct ieee80211_mgmt *mgmt = (void *)frame_buf;
  956. /* build frame */
  957. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  958. mgmt->duration = 0; /* initialize only */
  959. mgmt->seq_ctrl = 0; /* initialize only */
  960. memcpy(mgmt->da, da, ETH_ALEN);
  961. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  962. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  963. /* u.deauth.reason_code == u.disassoc.reason_code */
  964. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  965. if (send_frame) {
  966. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  967. IEEE80211_DEAUTH_FRAME_LEN);
  968. if (!skb)
  969. return;
  970. skb_reserve(skb, local->hw.extra_tx_headroom);
  971. /* copy in frame */
  972. skb_put_data(skb, mgmt, IEEE80211_DEAUTH_FRAME_LEN);
  973. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  974. !(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED))
  975. IEEE80211_SKB_CB(skb)->flags |=
  976. IEEE80211_TX_INTFL_DONT_ENCRYPT;
  977. ieee80211_tx_skb(sdata, skb);
  978. }
  979. }
  980. static int ieee80211_put_s1g_cap(struct sk_buff *skb,
  981. struct ieee80211_sta_s1g_cap *s1g_cap)
  982. {
  983. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_s1g_cap))
  984. return -ENOBUFS;
  985. skb_put_u8(skb, WLAN_EID_S1G_CAPABILITIES);
  986. skb_put_u8(skb, sizeof(struct ieee80211_s1g_cap));
  987. skb_put_data(skb, &s1g_cap->cap, sizeof(s1g_cap->cap));
  988. skb_put_data(skb, &s1g_cap->nss_mcs, sizeof(s1g_cap->nss_mcs));
  989. return 0;
  990. }
  991. static int ieee80211_put_preq_ies_band(struct sk_buff *skb,
  992. struct ieee80211_sub_if_data *sdata,
  993. const u8 *ie, size_t ie_len,
  994. size_t *offset,
  995. enum nl80211_band band,
  996. u32 rate_mask,
  997. struct cfg80211_chan_def *chandef,
  998. u32 flags)
  999. {
  1000. struct ieee80211_local *local = sdata->local;
  1001. struct ieee80211_supported_band *sband;
  1002. int i, err;
  1003. size_t noffset;
  1004. u32 rate_flags;
  1005. bool have_80mhz = false;
  1006. *offset = 0;
  1007. sband = local->hw.wiphy->bands[band];
  1008. if (WARN_ON_ONCE(!sband))
  1009. return 0;
  1010. rate_flags = ieee80211_chandef_rate_flags(chandef);
  1011. /* For direct scan add S1G IE and consider its override bits */
  1012. if (band == NL80211_BAND_S1GHZ)
  1013. return ieee80211_put_s1g_cap(skb, &sband->s1g_cap);
  1014. err = ieee80211_put_srates_elem(skb, sband, 0, rate_flags,
  1015. ~rate_mask, WLAN_EID_SUPP_RATES);
  1016. if (err)
  1017. return err;
  1018. /* insert "request information" if in custom IEs */
  1019. if (ie && ie_len) {
  1020. static const u8 before_extrates[] = {
  1021. WLAN_EID_SSID,
  1022. WLAN_EID_SUPP_RATES,
  1023. WLAN_EID_REQUEST,
  1024. };
  1025. noffset = ieee80211_ie_split(ie, ie_len,
  1026. before_extrates,
  1027. ARRAY_SIZE(before_extrates),
  1028. *offset);
  1029. if (skb_tailroom(skb) < noffset - *offset)
  1030. return -ENOBUFS;
  1031. skb_put_data(skb, ie + *offset, noffset - *offset);
  1032. *offset = noffset;
  1033. }
  1034. err = ieee80211_put_srates_elem(skb, sband, 0, rate_flags,
  1035. ~rate_mask, WLAN_EID_EXT_SUPP_RATES);
  1036. if (err)
  1037. return err;
  1038. if (chandef->chan && sband->band == NL80211_BAND_2GHZ) {
  1039. if (skb_tailroom(skb) < 3)
  1040. return -ENOBUFS;
  1041. skb_put_u8(skb, WLAN_EID_DS_PARAMS);
  1042. skb_put_u8(skb, 1);
  1043. skb_put_u8(skb,
  1044. ieee80211_frequency_to_channel(chandef->chan->center_freq));
  1045. }
  1046. if (flags & IEEE80211_PROBE_FLAG_MIN_CONTENT)
  1047. return 0;
  1048. /* insert custom IEs that go before HT */
  1049. if (ie && ie_len) {
  1050. static const u8 before_ht[] = {
  1051. /*
  1052. * no need to list the ones split off already
  1053. * (or generated here)
  1054. */
  1055. WLAN_EID_DS_PARAMS,
  1056. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  1057. };
  1058. noffset = ieee80211_ie_split(ie, ie_len,
  1059. before_ht, ARRAY_SIZE(before_ht),
  1060. *offset);
  1061. if (skb_tailroom(skb) < noffset - *offset)
  1062. return -ENOBUFS;
  1063. skb_put_data(skb, ie + *offset, noffset - *offset);
  1064. *offset = noffset;
  1065. }
  1066. if (sband->ht_cap.ht_supported) {
  1067. u8 *pos;
  1068. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
  1069. return -ENOBUFS;
  1070. pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
  1071. ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
  1072. sband->ht_cap.cap);
  1073. }
  1074. /* insert custom IEs that go before VHT */
  1075. if (ie && ie_len) {
  1076. static const u8 before_vht[] = {
  1077. /*
  1078. * no need to list the ones split off already
  1079. * (or generated here)
  1080. */
  1081. WLAN_EID_BSS_COEX_2040,
  1082. WLAN_EID_EXT_CAPABILITY,
  1083. WLAN_EID_SSID_LIST,
  1084. WLAN_EID_CHANNEL_USAGE,
  1085. WLAN_EID_INTERWORKING,
  1086. WLAN_EID_MESH_ID,
  1087. /* 60 GHz (Multi-band, DMG, MMS) can't happen */
  1088. };
  1089. noffset = ieee80211_ie_split(ie, ie_len,
  1090. before_vht, ARRAY_SIZE(before_vht),
  1091. *offset);
  1092. if (skb_tailroom(skb) < noffset - *offset)
  1093. return -ENOBUFS;
  1094. skb_put_data(skb, ie + *offset, noffset - *offset);
  1095. *offset = noffset;
  1096. }
  1097. /* Check if any channel in this sband supports at least 80 MHz */
  1098. for (i = 0; i < sband->n_channels; i++) {
  1099. if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
  1100. IEEE80211_CHAN_NO_80MHZ))
  1101. continue;
  1102. have_80mhz = true;
  1103. break;
  1104. }
  1105. if (sband->vht_cap.vht_supported && have_80mhz) {
  1106. u8 *pos;
  1107. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_cap))
  1108. return -ENOBUFS;
  1109. pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_cap));
  1110. ieee80211_ie_build_vht_cap(pos, &sband->vht_cap,
  1111. sband->vht_cap.cap);
  1112. }
  1113. /* insert custom IEs that go before HE */
  1114. if (ie && ie_len) {
  1115. static const u8 before_he[] = {
  1116. /*
  1117. * no need to list the ones split off before VHT
  1118. * or generated here
  1119. */
  1120. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_REQ_PARAMS,
  1121. WLAN_EID_AP_CSN,
  1122. /* TODO: add 11ah/11aj/11ak elements */
  1123. };
  1124. noffset = ieee80211_ie_split(ie, ie_len,
  1125. before_he, ARRAY_SIZE(before_he),
  1126. *offset);
  1127. if (skb_tailroom(skb) < noffset - *offset)
  1128. return -ENOBUFS;
  1129. skb_put_data(skb, ie + *offset, noffset - *offset);
  1130. *offset = noffset;
  1131. }
  1132. if (cfg80211_any_usable_channels(local->hw.wiphy, BIT(sband->band),
  1133. IEEE80211_CHAN_NO_HE)) {
  1134. err = ieee80211_put_he_cap(skb, sdata, sband, NULL);
  1135. if (err)
  1136. return err;
  1137. }
  1138. if (cfg80211_any_usable_channels(local->hw.wiphy, BIT(sband->band),
  1139. IEEE80211_CHAN_NO_HE |
  1140. IEEE80211_CHAN_NO_EHT)) {
  1141. err = ieee80211_put_eht_cap(skb, sdata, sband, NULL);
  1142. if (err)
  1143. return err;
  1144. }
  1145. err = ieee80211_put_he_6ghz_cap(skb, sdata, IEEE80211_SMPS_OFF);
  1146. if (err)
  1147. return err;
  1148. /*
  1149. * If adding more here, adjust code in main.c
  1150. * that calculates local->scan_ies_len.
  1151. */
  1152. return 0;
  1153. }
  1154. static int ieee80211_put_preq_ies(struct sk_buff *skb,
  1155. struct ieee80211_sub_if_data *sdata,
  1156. struct ieee80211_scan_ies *ie_desc,
  1157. const u8 *ie, size_t ie_len,
  1158. u8 bands_used, u32 *rate_masks,
  1159. struct cfg80211_chan_def *chandef,
  1160. u32 flags)
  1161. {
  1162. size_t custom_ie_offset = 0;
  1163. int i, err;
  1164. memset(ie_desc, 0, sizeof(*ie_desc));
  1165. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  1166. if (bands_used & BIT(i)) {
  1167. ie_desc->ies[i] = skb_tail_pointer(skb);
  1168. err = ieee80211_put_preq_ies_band(skb, sdata,
  1169. ie, ie_len,
  1170. &custom_ie_offset,
  1171. i, rate_masks[i],
  1172. chandef, flags);
  1173. if (err)
  1174. return err;
  1175. ie_desc->len[i] = skb_tail_pointer(skb) -
  1176. ie_desc->ies[i];
  1177. }
  1178. }
  1179. /* add any remaining custom IEs */
  1180. if (ie && ie_len) {
  1181. if (WARN_ONCE(skb_tailroom(skb) < ie_len - custom_ie_offset,
  1182. "not enough space for preq custom IEs\n"))
  1183. return -ENOBUFS;
  1184. ie_desc->common_ies = skb_tail_pointer(skb);
  1185. skb_put_data(skb, ie + custom_ie_offset,
  1186. ie_len - custom_ie_offset);
  1187. ie_desc->common_ie_len = skb_tail_pointer(skb) -
  1188. ie_desc->common_ies;
  1189. }
  1190. return 0;
  1191. };
  1192. int ieee80211_build_preq_ies(struct ieee80211_sub_if_data *sdata, u8 *buffer,
  1193. size_t buffer_len,
  1194. struct ieee80211_scan_ies *ie_desc,
  1195. const u8 *ie, size_t ie_len,
  1196. u8 bands_used, u32 *rate_masks,
  1197. struct cfg80211_chan_def *chandef,
  1198. u32 flags)
  1199. {
  1200. struct sk_buff *skb = alloc_skb(buffer_len, GFP_KERNEL);
  1201. uintptr_t offs;
  1202. int ret, i;
  1203. u8 *start;
  1204. if (!skb)
  1205. return -ENOMEM;
  1206. start = skb_tail_pointer(skb);
  1207. memset(start, 0, skb_tailroom(skb));
  1208. ret = ieee80211_put_preq_ies(skb, sdata, ie_desc, ie, ie_len,
  1209. bands_used, rate_masks, chandef,
  1210. flags);
  1211. if (ret < 0) {
  1212. goto out;
  1213. }
  1214. if (skb->len > buffer_len) {
  1215. ret = -ENOBUFS;
  1216. goto out;
  1217. }
  1218. memcpy(buffer, start, skb->len);
  1219. /* adjust ie_desc for copy */
  1220. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  1221. offs = ie_desc->ies[i] - start;
  1222. ie_desc->ies[i] = buffer + offs;
  1223. }
  1224. offs = ie_desc->common_ies - start;
  1225. ie_desc->common_ies = buffer + offs;
  1226. ret = skb->len;
  1227. out:
  1228. consume_skb(skb);
  1229. return ret;
  1230. }
  1231. struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
  1232. const u8 *src, const u8 *dst,
  1233. u32 ratemask,
  1234. struct ieee80211_channel *chan,
  1235. const u8 *ssid, size_t ssid_len,
  1236. const u8 *ie, size_t ie_len,
  1237. u32 flags)
  1238. {
  1239. struct ieee80211_local *local = sdata->local;
  1240. struct cfg80211_chan_def chandef;
  1241. struct sk_buff *skb;
  1242. struct ieee80211_mgmt *mgmt;
  1243. u32 rate_masks[NUM_NL80211_BANDS] = {};
  1244. struct ieee80211_scan_ies dummy_ie_desc;
  1245. /*
  1246. * Do not send DS Channel parameter for directed probe requests
  1247. * in order to maximize the chance that we get a response. Some
  1248. * badly-behaved APs don't respond when this parameter is included.
  1249. */
  1250. chandef.width = sdata->vif.bss_conf.chanreq.oper.width;
  1251. if (flags & IEEE80211_PROBE_FLAG_DIRECTED)
  1252. chandef.chan = NULL;
  1253. else
  1254. chandef.chan = chan;
  1255. skb = ieee80211_probereq_get(&local->hw, src, ssid, ssid_len,
  1256. local->scan_ies_len + ie_len);
  1257. if (!skb)
  1258. return NULL;
  1259. rate_masks[chan->band] = ratemask;
  1260. ieee80211_put_preq_ies(skb, sdata, &dummy_ie_desc,
  1261. ie, ie_len, BIT(chan->band),
  1262. rate_masks, &chandef, flags);
  1263. if (dst) {
  1264. mgmt = (struct ieee80211_mgmt *) skb->data;
  1265. memcpy(mgmt->da, dst, ETH_ALEN);
  1266. memcpy(mgmt->bssid, dst, ETH_ALEN);
  1267. }
  1268. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1269. return skb;
  1270. }
  1271. u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
  1272. struct ieee802_11_elems *elems,
  1273. enum nl80211_band band, u32 *basic_rates)
  1274. {
  1275. struct ieee80211_supported_band *sband;
  1276. size_t num_rates;
  1277. u32 supp_rates, rate_flags;
  1278. int i, j;
  1279. sband = sdata->local->hw.wiphy->bands[band];
  1280. if (WARN_ON(!sband))
  1281. return 1;
  1282. rate_flags =
  1283. ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chanreq.oper);
  1284. num_rates = sband->n_bitrates;
  1285. supp_rates = 0;
  1286. for (i = 0; i < elems->supp_rates_len +
  1287. elems->ext_supp_rates_len; i++) {
  1288. u8 rate = 0;
  1289. int own_rate;
  1290. bool is_basic;
  1291. if (i < elems->supp_rates_len)
  1292. rate = elems->supp_rates[i];
  1293. else if (elems->ext_supp_rates)
  1294. rate = elems->ext_supp_rates
  1295. [i - elems->supp_rates_len];
  1296. own_rate = 5 * (rate & 0x7f);
  1297. is_basic = !!(rate & 0x80);
  1298. if (is_basic && (rate & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
  1299. continue;
  1300. for (j = 0; j < num_rates; j++) {
  1301. int brate;
  1302. if ((rate_flags & sband->bitrates[j].flags)
  1303. != rate_flags)
  1304. continue;
  1305. brate = sband->bitrates[j].bitrate;
  1306. if (brate == own_rate) {
  1307. supp_rates |= BIT(j);
  1308. if (basic_rates && is_basic)
  1309. *basic_rates |= BIT(j);
  1310. }
  1311. }
  1312. }
  1313. return supp_rates;
  1314. }
  1315. void ieee80211_stop_device(struct ieee80211_local *local, bool suspend)
  1316. {
  1317. local_bh_disable();
  1318. ieee80211_handle_queued_frames(local);
  1319. local_bh_enable();
  1320. ieee80211_led_radio(local, false);
  1321. ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO);
  1322. wiphy_work_cancel(local->hw.wiphy, &local->reconfig_filter);
  1323. flush_workqueue(local->workqueue);
  1324. wiphy_work_flush(local->hw.wiphy, NULL);
  1325. drv_stop(local, suspend);
  1326. }
  1327. static void ieee80211_flush_completed_scan(struct ieee80211_local *local,
  1328. bool aborted)
  1329. {
  1330. /* It's possible that we don't handle the scan completion in
  1331. * time during suspend, so if it's still marked as completed
  1332. * here, queue the work and flush it to clean things up.
  1333. * Instead of calling the worker function directly here, we
  1334. * really queue it to avoid potential races with other flows
  1335. * scheduling the same work.
  1336. */
  1337. if (test_bit(SCAN_COMPLETED, &local->scanning)) {
  1338. /* If coming from reconfiguration failure, abort the scan so
  1339. * we don't attempt to continue a partial HW scan - which is
  1340. * possible otherwise if (e.g.) the 2.4 GHz portion was the
  1341. * completed scan, and a 5 GHz portion is still pending.
  1342. */
  1343. if (aborted)
  1344. set_bit(SCAN_ABORTED, &local->scanning);
  1345. wiphy_delayed_work_queue(local->hw.wiphy, &local->scan_work, 0);
  1346. wiphy_delayed_work_flush(local->hw.wiphy, &local->scan_work);
  1347. }
  1348. }
  1349. static void ieee80211_handle_reconfig_failure(struct ieee80211_local *local)
  1350. {
  1351. struct ieee80211_sub_if_data *sdata;
  1352. struct ieee80211_chanctx *ctx;
  1353. lockdep_assert_wiphy(local->hw.wiphy);
  1354. /*
  1355. * We get here if during resume the device can't be restarted properly.
  1356. * We might also get here if this happens during HW reset, which is a
  1357. * slightly different situation and we need to drop all connections in
  1358. * the latter case.
  1359. *
  1360. * Ask cfg80211 to turn off all interfaces, this will result in more
  1361. * warnings but at least we'll then get into a clean stopped state.
  1362. */
  1363. local->resuming = false;
  1364. local->suspended = false;
  1365. local->in_reconfig = false;
  1366. local->reconfig_failure = true;
  1367. ieee80211_flush_completed_scan(local, true);
  1368. /* scheduled scan clearly can't be running any more, but tell
  1369. * cfg80211 and clear local state
  1370. */
  1371. ieee80211_sched_scan_end(local);
  1372. list_for_each_entry(sdata, &local->interfaces, list)
  1373. sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
  1374. /* Mark channel contexts as not being in the driver any more to avoid
  1375. * removing them from the driver during the shutdown process...
  1376. */
  1377. list_for_each_entry(ctx, &local->chanctx_list, list)
  1378. ctx->driver_present = false;
  1379. }
  1380. static void ieee80211_assign_chanctx(struct ieee80211_local *local,
  1381. struct ieee80211_sub_if_data *sdata,
  1382. struct ieee80211_link_data *link)
  1383. {
  1384. struct ieee80211_chanctx_conf *conf;
  1385. struct ieee80211_chanctx *ctx;
  1386. lockdep_assert_wiphy(local->hw.wiphy);
  1387. conf = rcu_dereference_protected(link->conf->chanctx_conf,
  1388. lockdep_is_held(&local->hw.wiphy->mtx));
  1389. if (conf) {
  1390. ctx = container_of(conf, struct ieee80211_chanctx, conf);
  1391. drv_assign_vif_chanctx(local, sdata, link->conf, ctx);
  1392. }
  1393. }
  1394. static void ieee80211_reconfig_stations(struct ieee80211_sub_if_data *sdata)
  1395. {
  1396. struct ieee80211_local *local = sdata->local;
  1397. struct sta_info *sta;
  1398. lockdep_assert_wiphy(local->hw.wiphy);
  1399. /* add STAs back */
  1400. list_for_each_entry(sta, &local->sta_list, list) {
  1401. enum ieee80211_sta_state state;
  1402. if (!sta->uploaded || sta->sdata != sdata)
  1403. continue;
  1404. for (state = IEEE80211_STA_NOTEXIST;
  1405. state < sta->sta_state; state++)
  1406. WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
  1407. state + 1));
  1408. }
  1409. }
  1410. static int ieee80211_reconfig_nan(struct ieee80211_sub_if_data *sdata)
  1411. {
  1412. struct cfg80211_nan_func *func, **funcs;
  1413. int res, id, i = 0;
  1414. res = drv_start_nan(sdata->local, sdata,
  1415. &sdata->u.nan.conf);
  1416. if (WARN_ON(res))
  1417. return res;
  1418. funcs = kcalloc(sdata->local->hw.max_nan_de_entries + 1,
  1419. sizeof(*funcs),
  1420. GFP_KERNEL);
  1421. if (!funcs)
  1422. return -ENOMEM;
  1423. /* Add all the functions:
  1424. * This is a little bit ugly. We need to call a potentially sleeping
  1425. * callback for each NAN function, so we can't hold the spinlock.
  1426. */
  1427. spin_lock_bh(&sdata->u.nan.func_lock);
  1428. idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id)
  1429. funcs[i++] = func;
  1430. spin_unlock_bh(&sdata->u.nan.func_lock);
  1431. for (i = 0; funcs[i]; i++) {
  1432. res = drv_add_nan_func(sdata->local, sdata, funcs[i]);
  1433. if (WARN_ON(res))
  1434. ieee80211_nan_func_terminated(&sdata->vif,
  1435. funcs[i]->instance_id,
  1436. NL80211_NAN_FUNC_TERM_REASON_ERROR,
  1437. GFP_KERNEL);
  1438. }
  1439. kfree(funcs);
  1440. return 0;
  1441. }
  1442. static void ieee80211_reconfig_ap_links(struct ieee80211_local *local,
  1443. struct ieee80211_sub_if_data *sdata,
  1444. u64 changed)
  1445. {
  1446. int link_id;
  1447. for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
  1448. struct ieee80211_link_data *link;
  1449. if (!(sdata->vif.active_links & BIT(link_id)))
  1450. continue;
  1451. link = sdata_dereference(sdata->link[link_id], sdata);
  1452. if (!link)
  1453. continue;
  1454. if (rcu_access_pointer(link->u.ap.beacon))
  1455. drv_start_ap(local, sdata, link->conf);
  1456. if (!link->conf->enable_beacon)
  1457. continue;
  1458. changed |= BSS_CHANGED_BEACON |
  1459. BSS_CHANGED_BEACON_ENABLED;
  1460. ieee80211_link_info_change_notify(sdata, link, changed);
  1461. }
  1462. }
  1463. int ieee80211_reconfig(struct ieee80211_local *local)
  1464. {
  1465. struct ieee80211_hw *hw = &local->hw;
  1466. struct ieee80211_sub_if_data *sdata;
  1467. struct ieee80211_chanctx *ctx;
  1468. struct sta_info *sta;
  1469. int res, i;
  1470. bool reconfig_due_to_wowlan = false;
  1471. struct ieee80211_sub_if_data *sched_scan_sdata;
  1472. struct cfg80211_sched_scan_request *sched_scan_req;
  1473. bool sched_scan_stopped = false;
  1474. bool suspended = local->suspended;
  1475. bool in_reconfig = false;
  1476. lockdep_assert_wiphy(local->hw.wiphy);
  1477. /* nothing to do if HW shouldn't run */
  1478. if (!local->open_count)
  1479. goto wake_up;
  1480. #ifdef CONFIG_PM
  1481. if (suspended)
  1482. local->resuming = true;
  1483. if (local->wowlan) {
  1484. /*
  1485. * In the wowlan case, both mac80211 and the device
  1486. * are functional when the resume op is called, so
  1487. * clear local->suspended so the device could operate
  1488. * normally (e.g. pass rx frames).
  1489. */
  1490. local->suspended = false;
  1491. res = drv_resume(local);
  1492. local->wowlan = false;
  1493. if (res < 0) {
  1494. local->resuming = false;
  1495. return res;
  1496. }
  1497. if (res == 0)
  1498. goto wake_up;
  1499. WARN_ON(res > 1);
  1500. /*
  1501. * res is 1, which means the driver requested
  1502. * to go through a regular reset on wakeup.
  1503. * restore local->suspended in this case.
  1504. */
  1505. reconfig_due_to_wowlan = true;
  1506. local->suspended = true;
  1507. }
  1508. #endif
  1509. /*
  1510. * In case of hw_restart during suspend (without wowlan),
  1511. * cancel restart work, as we are reconfiguring the device
  1512. * anyway.
  1513. * Note that restart_work is scheduled on a frozen workqueue,
  1514. * so we can't deadlock in this case.
  1515. */
  1516. if (suspended && local->in_reconfig && !reconfig_due_to_wowlan)
  1517. cancel_work_sync(&local->restart_work);
  1518. local->started = false;
  1519. /*
  1520. * Upon resume hardware can sometimes be goofy due to
  1521. * various platform / driver / bus issues, so restarting
  1522. * the device may at times not work immediately. Propagate
  1523. * the error.
  1524. */
  1525. res = drv_start(local);
  1526. if (res) {
  1527. if (suspended)
  1528. WARN(1, "Hardware became unavailable upon resume. This could be a software issue prior to suspend or a hardware issue.\n");
  1529. else
  1530. WARN(1, "Hardware became unavailable during restart.\n");
  1531. ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  1532. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  1533. false);
  1534. ieee80211_handle_reconfig_failure(local);
  1535. return res;
  1536. }
  1537. /* setup fragmentation threshold */
  1538. drv_set_frag_threshold(local, hw->wiphy->frag_threshold);
  1539. /* setup RTS threshold */
  1540. drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
  1541. /* reset coverage class */
  1542. drv_set_coverage_class(local, hw->wiphy->coverage_class);
  1543. ieee80211_led_radio(local, true);
  1544. ieee80211_mod_tpt_led_trig(local,
  1545. IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
  1546. /* add interfaces */
  1547. sdata = wiphy_dereference(local->hw.wiphy, local->monitor_sdata);
  1548. if (sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) {
  1549. /* in HW restart it exists already */
  1550. WARN_ON(local->resuming);
  1551. res = drv_add_interface(local, sdata);
  1552. if (WARN_ON(res)) {
  1553. RCU_INIT_POINTER(local->monitor_sdata, NULL);
  1554. synchronize_net();
  1555. kfree(sdata);
  1556. }
  1557. }
  1558. list_for_each_entry(sdata, &local->interfaces, list) {
  1559. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1560. sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1561. ieee80211_sdata_running(sdata)) {
  1562. res = drv_add_interface(local, sdata);
  1563. if (WARN_ON(res))
  1564. break;
  1565. }
  1566. }
  1567. /* If adding any of the interfaces failed above, roll back and
  1568. * report failure.
  1569. */
  1570. if (res) {
  1571. list_for_each_entry_continue_reverse(sdata, &local->interfaces,
  1572. list)
  1573. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1574. sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1575. ieee80211_sdata_running(sdata))
  1576. drv_remove_interface(local, sdata);
  1577. ieee80211_handle_reconfig_failure(local);
  1578. return res;
  1579. }
  1580. /* add channel contexts */
  1581. list_for_each_entry(ctx, &local->chanctx_list, list)
  1582. if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
  1583. WARN_ON(drv_add_chanctx(local, ctx));
  1584. sdata = wiphy_dereference(local->hw.wiphy, local->monitor_sdata);
  1585. if (sdata && ieee80211_sdata_running(sdata))
  1586. ieee80211_assign_chanctx(local, sdata, &sdata->deflink);
  1587. /* reconfigure hardware */
  1588. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_LISTEN_INTERVAL |
  1589. IEEE80211_CONF_CHANGE_MONITOR |
  1590. IEEE80211_CONF_CHANGE_PS |
  1591. IEEE80211_CONF_CHANGE_RETRY_LIMITS |
  1592. IEEE80211_CONF_CHANGE_IDLE);
  1593. ieee80211_configure_filter(local);
  1594. /* Finally also reconfigure all the BSS information */
  1595. list_for_each_entry(sdata, &local->interfaces, list) {
  1596. /* common change flags for all interface types - link only */
  1597. u64 changed = BSS_CHANGED_ERP_CTS_PROT |
  1598. BSS_CHANGED_ERP_PREAMBLE |
  1599. BSS_CHANGED_ERP_SLOT |
  1600. BSS_CHANGED_HT |
  1601. BSS_CHANGED_BASIC_RATES |
  1602. BSS_CHANGED_BEACON_INT |
  1603. BSS_CHANGED_BSSID |
  1604. BSS_CHANGED_CQM |
  1605. BSS_CHANGED_QOS |
  1606. BSS_CHANGED_TXPOWER |
  1607. BSS_CHANGED_MCAST_RATE;
  1608. struct ieee80211_link_data *link = NULL;
  1609. unsigned int link_id;
  1610. u32 active_links = 0;
  1611. if (!ieee80211_sdata_running(sdata))
  1612. continue;
  1613. if (ieee80211_vif_is_mld(&sdata->vif)) {
  1614. struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS] = {
  1615. [0] = &sdata->vif.bss_conf,
  1616. };
  1617. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  1618. /* start with a single active link */
  1619. active_links = sdata->vif.active_links;
  1620. link_id = ffs(active_links) - 1;
  1621. sdata->vif.active_links = BIT(link_id);
  1622. }
  1623. drv_change_vif_links(local, sdata, 0,
  1624. sdata->vif.active_links,
  1625. old);
  1626. }
  1627. sdata->restart_active_links = active_links;
  1628. for (link_id = 0;
  1629. link_id < ARRAY_SIZE(sdata->vif.link_conf);
  1630. link_id++) {
  1631. if (!ieee80211_vif_link_active(&sdata->vif, link_id))
  1632. continue;
  1633. link = sdata_dereference(sdata->link[link_id], sdata);
  1634. if (!link)
  1635. continue;
  1636. ieee80211_assign_chanctx(local, sdata, link);
  1637. }
  1638. switch (sdata->vif.type) {
  1639. case NL80211_IFTYPE_AP_VLAN:
  1640. case NL80211_IFTYPE_MONITOR:
  1641. break;
  1642. case NL80211_IFTYPE_ADHOC:
  1643. if (sdata->vif.cfg.ibss_joined)
  1644. WARN_ON(drv_join_ibss(local, sdata));
  1645. fallthrough;
  1646. default:
  1647. ieee80211_reconfig_stations(sdata);
  1648. fallthrough;
  1649. case NL80211_IFTYPE_AP: /* AP stations are handled later */
  1650. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1651. drv_conf_tx(local, &sdata->deflink, i,
  1652. &sdata->deflink.tx_conf[i]);
  1653. break;
  1654. }
  1655. if (sdata->vif.bss_conf.mu_mimo_owner)
  1656. changed |= BSS_CHANGED_MU_GROUPS;
  1657. if (!ieee80211_vif_is_mld(&sdata->vif))
  1658. changed |= BSS_CHANGED_IDLE;
  1659. switch (sdata->vif.type) {
  1660. case NL80211_IFTYPE_STATION:
  1661. if (!ieee80211_vif_is_mld(&sdata->vif)) {
  1662. changed |= BSS_CHANGED_ASSOC |
  1663. BSS_CHANGED_ARP_FILTER |
  1664. BSS_CHANGED_PS;
  1665. /* Re-send beacon info report to the driver */
  1666. if (sdata->deflink.u.mgd.have_beacon)
  1667. changed |= BSS_CHANGED_BEACON_INFO;
  1668. if (sdata->vif.bss_conf.max_idle_period ||
  1669. sdata->vif.bss_conf.protected_keep_alive)
  1670. changed |= BSS_CHANGED_KEEP_ALIVE;
  1671. ieee80211_bss_info_change_notify(sdata,
  1672. changed);
  1673. } else if (!WARN_ON(!link)) {
  1674. ieee80211_link_info_change_notify(sdata, link,
  1675. changed);
  1676. changed = BSS_CHANGED_ASSOC |
  1677. BSS_CHANGED_IDLE |
  1678. BSS_CHANGED_PS |
  1679. BSS_CHANGED_ARP_FILTER;
  1680. ieee80211_vif_cfg_change_notify(sdata, changed);
  1681. }
  1682. break;
  1683. case NL80211_IFTYPE_OCB:
  1684. changed |= BSS_CHANGED_OCB;
  1685. ieee80211_bss_info_change_notify(sdata, changed);
  1686. break;
  1687. case NL80211_IFTYPE_ADHOC:
  1688. changed |= BSS_CHANGED_IBSS;
  1689. fallthrough;
  1690. case NL80211_IFTYPE_AP:
  1691. changed |= BSS_CHANGED_P2P_PS;
  1692. if (ieee80211_vif_is_mld(&sdata->vif))
  1693. ieee80211_vif_cfg_change_notify(sdata,
  1694. BSS_CHANGED_SSID);
  1695. else
  1696. changed |= BSS_CHANGED_SSID;
  1697. if (sdata->vif.bss_conf.ftm_responder == 1 &&
  1698. wiphy_ext_feature_isset(sdata->local->hw.wiphy,
  1699. NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
  1700. changed |= BSS_CHANGED_FTM_RESPONDER;
  1701. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1702. changed |= BSS_CHANGED_AP_PROBE_RESP;
  1703. if (ieee80211_vif_is_mld(&sdata->vif)) {
  1704. ieee80211_reconfig_ap_links(local,
  1705. sdata,
  1706. changed);
  1707. break;
  1708. }
  1709. if (rcu_access_pointer(sdata->deflink.u.ap.beacon))
  1710. drv_start_ap(local, sdata,
  1711. sdata->deflink.conf);
  1712. }
  1713. fallthrough;
  1714. case NL80211_IFTYPE_MESH_POINT:
  1715. if (sdata->vif.bss_conf.enable_beacon) {
  1716. changed |= BSS_CHANGED_BEACON |
  1717. BSS_CHANGED_BEACON_ENABLED;
  1718. ieee80211_bss_info_change_notify(sdata, changed);
  1719. }
  1720. break;
  1721. case NL80211_IFTYPE_NAN:
  1722. res = ieee80211_reconfig_nan(sdata);
  1723. if (res < 0) {
  1724. ieee80211_handle_reconfig_failure(local);
  1725. return res;
  1726. }
  1727. break;
  1728. case NL80211_IFTYPE_AP_VLAN:
  1729. case NL80211_IFTYPE_MONITOR:
  1730. case NL80211_IFTYPE_P2P_DEVICE:
  1731. /* nothing to do */
  1732. break;
  1733. case NL80211_IFTYPE_UNSPECIFIED:
  1734. case NUM_NL80211_IFTYPES:
  1735. case NL80211_IFTYPE_P2P_CLIENT:
  1736. case NL80211_IFTYPE_P2P_GO:
  1737. case NL80211_IFTYPE_WDS:
  1738. WARN_ON(1);
  1739. break;
  1740. }
  1741. }
  1742. ieee80211_recalc_ps(local);
  1743. /*
  1744. * The sta might be in psm against the ap (e.g. because
  1745. * this was the state before a hw restart), so we
  1746. * explicitly send a null packet in order to make sure
  1747. * it'll sync against the ap (and get out of psm).
  1748. */
  1749. if (!(local->hw.conf.flags & IEEE80211_CONF_PS)) {
  1750. list_for_each_entry(sdata, &local->interfaces, list) {
  1751. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1752. continue;
  1753. if (!sdata->u.mgd.associated)
  1754. continue;
  1755. ieee80211_send_nullfunc(local, sdata, false);
  1756. }
  1757. }
  1758. /* APs are now beaconing, add back stations */
  1759. list_for_each_entry(sdata, &local->interfaces, list) {
  1760. if (!ieee80211_sdata_running(sdata))
  1761. continue;
  1762. switch (sdata->vif.type) {
  1763. case NL80211_IFTYPE_AP_VLAN:
  1764. case NL80211_IFTYPE_AP:
  1765. ieee80211_reconfig_stations(sdata);
  1766. break;
  1767. default:
  1768. break;
  1769. }
  1770. }
  1771. /* add back keys */
  1772. list_for_each_entry(sdata, &local->interfaces, list)
  1773. ieee80211_reenable_keys(sdata);
  1774. /* re-enable multi-link for client interfaces */
  1775. list_for_each_entry(sdata, &local->interfaces, list) {
  1776. if (sdata->restart_active_links)
  1777. ieee80211_set_active_links(&sdata->vif,
  1778. sdata->restart_active_links);
  1779. /*
  1780. * If a link switch was scheduled before the restart, and ran
  1781. * before reconfig, it will do nothing, so re-schedule.
  1782. */
  1783. if (sdata->desired_active_links)
  1784. wiphy_work_queue(sdata->local->hw.wiphy,
  1785. &sdata->activate_links_work);
  1786. }
  1787. /* Reconfigure sched scan if it was interrupted by FW restart */
  1788. sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
  1789. lockdep_is_held(&local->hw.wiphy->mtx));
  1790. sched_scan_req = rcu_dereference_protected(local->sched_scan_req,
  1791. lockdep_is_held(&local->hw.wiphy->mtx));
  1792. if (sched_scan_sdata && sched_scan_req)
  1793. /*
  1794. * Sched scan stopped, but we don't want to report it. Instead,
  1795. * we're trying to reschedule. However, if more than one scan
  1796. * plan was set, we cannot reschedule since we don't know which
  1797. * scan plan was currently running (and some scan plans may have
  1798. * already finished).
  1799. */
  1800. if (sched_scan_req->n_scan_plans > 1 ||
  1801. __ieee80211_request_sched_scan_start(sched_scan_sdata,
  1802. sched_scan_req)) {
  1803. RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
  1804. RCU_INIT_POINTER(local->sched_scan_req, NULL);
  1805. sched_scan_stopped = true;
  1806. }
  1807. if (sched_scan_stopped)
  1808. cfg80211_sched_scan_stopped_locked(local->hw.wiphy, 0);
  1809. wake_up:
  1810. if (local->monitors == local->open_count && local->monitors > 0)
  1811. ieee80211_add_virtual_monitor(local);
  1812. /*
  1813. * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
  1814. * sessions can be established after a resume.
  1815. *
  1816. * Also tear down aggregation sessions since reconfiguring
  1817. * them in a hardware restart scenario is not easily done
  1818. * right now, and the hardware will have lost information
  1819. * about the sessions, but we and the AP still think they
  1820. * are active. This is really a workaround though.
  1821. */
  1822. if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
  1823. list_for_each_entry(sta, &local->sta_list, list) {
  1824. if (!local->resuming)
  1825. ieee80211_sta_tear_down_BA_sessions(
  1826. sta, AGG_STOP_LOCAL_REQUEST);
  1827. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  1828. }
  1829. }
  1830. /*
  1831. * If this is for hw restart things are still running.
  1832. * We may want to change that later, however.
  1833. */
  1834. if (local->open_count && (!suspended || reconfig_due_to_wowlan))
  1835. drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_RESTART);
  1836. if (local->in_reconfig) {
  1837. in_reconfig = local->in_reconfig;
  1838. local->in_reconfig = false;
  1839. barrier();
  1840. ieee80211_reconfig_roc(local);
  1841. /* Requeue all works */
  1842. list_for_each_entry(sdata, &local->interfaces, list) {
  1843. if (ieee80211_sdata_running(sdata))
  1844. wiphy_work_queue(local->hw.wiphy, &sdata->work);
  1845. }
  1846. }
  1847. ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  1848. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  1849. false);
  1850. if (in_reconfig) {
  1851. list_for_each_entry(sdata, &local->interfaces, list) {
  1852. if (!ieee80211_sdata_running(sdata))
  1853. continue;
  1854. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1855. ieee80211_sta_restart(sdata);
  1856. }
  1857. }
  1858. if (!suspended)
  1859. return 0;
  1860. #ifdef CONFIG_PM
  1861. /* first set suspended false, then resuming */
  1862. local->suspended = false;
  1863. mb();
  1864. local->resuming = false;
  1865. ieee80211_flush_completed_scan(local, false);
  1866. if (local->open_count && !reconfig_due_to_wowlan)
  1867. drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_SUSPEND);
  1868. list_for_each_entry(sdata, &local->interfaces, list) {
  1869. if (!ieee80211_sdata_running(sdata))
  1870. continue;
  1871. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1872. ieee80211_sta_restart(sdata);
  1873. }
  1874. mod_timer(&local->sta_cleanup, jiffies + 1);
  1875. #else
  1876. WARN_ON(1);
  1877. #endif
  1878. return 0;
  1879. }
  1880. static void ieee80211_reconfig_disconnect(struct ieee80211_vif *vif, u8 flag)
  1881. {
  1882. struct ieee80211_sub_if_data *sdata;
  1883. struct ieee80211_local *local;
  1884. struct ieee80211_key *key;
  1885. if (WARN_ON(!vif))
  1886. return;
  1887. sdata = vif_to_sdata(vif);
  1888. local = sdata->local;
  1889. lockdep_assert_wiphy(local->hw.wiphy);
  1890. if (WARN_ON(flag & IEEE80211_SDATA_DISCONNECT_RESUME &&
  1891. !local->resuming))
  1892. return;
  1893. if (WARN_ON(flag & IEEE80211_SDATA_DISCONNECT_HW_RESTART &&
  1894. !local->in_reconfig))
  1895. return;
  1896. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  1897. return;
  1898. sdata->flags |= flag;
  1899. list_for_each_entry(key, &sdata->key_list, list)
  1900. key->flags |= KEY_FLAG_TAINTED;
  1901. }
  1902. void ieee80211_hw_restart_disconnect(struct ieee80211_vif *vif)
  1903. {
  1904. ieee80211_reconfig_disconnect(vif, IEEE80211_SDATA_DISCONNECT_HW_RESTART);
  1905. }
  1906. EXPORT_SYMBOL_GPL(ieee80211_hw_restart_disconnect);
  1907. void ieee80211_resume_disconnect(struct ieee80211_vif *vif)
  1908. {
  1909. ieee80211_reconfig_disconnect(vif, IEEE80211_SDATA_DISCONNECT_RESUME);
  1910. }
  1911. EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect);
  1912. void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata,
  1913. struct ieee80211_link_data *link)
  1914. {
  1915. struct ieee80211_local *local = sdata->local;
  1916. struct ieee80211_chanctx_conf *chanctx_conf;
  1917. struct ieee80211_chanctx *chanctx;
  1918. lockdep_assert_wiphy(local->hw.wiphy);
  1919. chanctx_conf = rcu_dereference_protected(link->conf->chanctx_conf,
  1920. lockdep_is_held(&local->hw.wiphy->mtx));
  1921. /*
  1922. * This function can be called from a work, thus it may be possible
  1923. * that the chanctx_conf is removed (due to a disconnection, for
  1924. * example).
  1925. * So nothing should be done in such case.
  1926. */
  1927. if (!chanctx_conf)
  1928. return;
  1929. chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
  1930. ieee80211_recalc_smps_chanctx(local, chanctx);
  1931. }
  1932. void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata,
  1933. int link_id)
  1934. {
  1935. struct ieee80211_local *local = sdata->local;
  1936. struct ieee80211_chanctx_conf *chanctx_conf;
  1937. struct ieee80211_chanctx *chanctx;
  1938. int i;
  1939. lockdep_assert_wiphy(local->hw.wiphy);
  1940. for (i = 0; i < ARRAY_SIZE(sdata->vif.link_conf); i++) {
  1941. struct ieee80211_bss_conf *bss_conf;
  1942. if (link_id >= 0 && link_id != i)
  1943. continue;
  1944. rcu_read_lock();
  1945. bss_conf = rcu_dereference(sdata->vif.link_conf[i]);
  1946. if (!bss_conf) {
  1947. rcu_read_unlock();
  1948. continue;
  1949. }
  1950. chanctx_conf = rcu_dereference_protected(bss_conf->chanctx_conf,
  1951. lockdep_is_held(&local->hw.wiphy->mtx));
  1952. /*
  1953. * Since we hold the wiphy mutex (checked above)
  1954. * we can take the chanctx_conf pointer out of the
  1955. * RCU critical section, it cannot go away without
  1956. * the mutex. Just the way we reached it could - in
  1957. * theory - go away, but we don't really care and
  1958. * it really shouldn't happen anyway.
  1959. */
  1960. rcu_read_unlock();
  1961. if (!chanctx_conf)
  1962. return;
  1963. chanctx = container_of(chanctx_conf, struct ieee80211_chanctx,
  1964. conf);
  1965. ieee80211_recalc_chanctx_min_def(local, chanctx, NULL, false);
  1966. }
  1967. }
  1968. size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
  1969. {
  1970. size_t pos = offset;
  1971. while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
  1972. pos += 2 + ies[pos + 1];
  1973. return pos;
  1974. }
  1975. u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  1976. u16 cap)
  1977. {
  1978. __le16 tmp;
  1979. *pos++ = WLAN_EID_HT_CAPABILITY;
  1980. *pos++ = sizeof(struct ieee80211_ht_cap);
  1981. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  1982. /* capability flags */
  1983. tmp = cpu_to_le16(cap);
  1984. memcpy(pos, &tmp, sizeof(u16));
  1985. pos += sizeof(u16);
  1986. /* AMPDU parameters */
  1987. *pos++ = ht_cap->ampdu_factor |
  1988. (ht_cap->ampdu_density <<
  1989. IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
  1990. /* MCS set */
  1991. memcpy(pos, &ht_cap->mcs, sizeof(ht_cap->mcs));
  1992. pos += sizeof(ht_cap->mcs);
  1993. /* extended capabilities */
  1994. pos += sizeof(__le16);
  1995. /* BF capabilities */
  1996. pos += sizeof(__le32);
  1997. /* antenna selection */
  1998. pos += sizeof(u8);
  1999. return pos;
  2000. }
  2001. u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
  2002. u32 cap)
  2003. {
  2004. __le32 tmp;
  2005. *pos++ = WLAN_EID_VHT_CAPABILITY;
  2006. *pos++ = sizeof(struct ieee80211_vht_cap);
  2007. memset(pos, 0, sizeof(struct ieee80211_vht_cap));
  2008. /* capability flags */
  2009. tmp = cpu_to_le32(cap);
  2010. memcpy(pos, &tmp, sizeof(u32));
  2011. pos += sizeof(u32);
  2012. /* VHT MCS set */
  2013. memcpy(pos, &vht_cap->vht_mcs, sizeof(vht_cap->vht_mcs));
  2014. pos += sizeof(vht_cap->vht_mcs);
  2015. return pos;
  2016. }
  2017. /* this may return more than ieee80211_put_he_6ghz_cap() will need */
  2018. u8 ieee80211_ie_len_he_cap(struct ieee80211_sub_if_data *sdata)
  2019. {
  2020. const struct ieee80211_sta_he_cap *he_cap;
  2021. struct ieee80211_supported_band *sband;
  2022. u8 n;
  2023. sband = ieee80211_get_sband(sdata);
  2024. if (!sband)
  2025. return 0;
  2026. he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  2027. if (!he_cap)
  2028. return 0;
  2029. n = ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem);
  2030. return 2 + 1 +
  2031. sizeof(he_cap->he_cap_elem) + n +
  2032. ieee80211_he_ppe_size(he_cap->ppe_thres[0],
  2033. he_cap->he_cap_elem.phy_cap_info);
  2034. }
  2035. static void
  2036. ieee80211_get_adjusted_he_cap(const struct ieee80211_conn_settings *conn,
  2037. const struct ieee80211_sta_he_cap *he_cap,
  2038. struct ieee80211_he_cap_elem *elem)
  2039. {
  2040. u8 ru_limit, max_ru;
  2041. *elem = he_cap->he_cap_elem;
  2042. switch (conn->bw_limit) {
  2043. case IEEE80211_CONN_BW_LIMIT_20:
  2044. ru_limit = IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_242;
  2045. break;
  2046. case IEEE80211_CONN_BW_LIMIT_40:
  2047. ru_limit = IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484;
  2048. break;
  2049. case IEEE80211_CONN_BW_LIMIT_80:
  2050. ru_limit = IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_996;
  2051. break;
  2052. default:
  2053. ru_limit = IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_2x996;
  2054. break;
  2055. }
  2056. max_ru = elem->phy_cap_info[8] & IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_MASK;
  2057. max_ru = min(max_ru, ru_limit);
  2058. elem->phy_cap_info[8] &= ~IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_MASK;
  2059. elem->phy_cap_info[8] |= max_ru;
  2060. if (conn->bw_limit < IEEE80211_CONN_BW_LIMIT_40) {
  2061. elem->phy_cap_info[0] &=
  2062. ~(IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  2063. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G);
  2064. elem->phy_cap_info[9] &=
  2065. ~IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM;
  2066. }
  2067. if (conn->bw_limit < IEEE80211_CONN_BW_LIMIT_160) {
  2068. elem->phy_cap_info[0] &=
  2069. ~(IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  2070. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G);
  2071. elem->phy_cap_info[5] &=
  2072. ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK;
  2073. elem->phy_cap_info[7] &=
  2074. ~(IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
  2075. IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ);
  2076. }
  2077. }
  2078. int ieee80211_put_he_cap(struct sk_buff *skb,
  2079. struct ieee80211_sub_if_data *sdata,
  2080. const struct ieee80211_supported_band *sband,
  2081. const struct ieee80211_conn_settings *conn)
  2082. {
  2083. const struct ieee80211_sta_he_cap *he_cap;
  2084. struct ieee80211_he_cap_elem elem;
  2085. u8 *len;
  2086. u8 n;
  2087. u8 ie_len;
  2088. if (!conn)
  2089. conn = &ieee80211_conn_settings_unlimited;
  2090. he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  2091. if (!he_cap)
  2092. return 0;
  2093. /* modify on stack first to calculate 'n' and 'ie_len' correctly */
  2094. ieee80211_get_adjusted_he_cap(conn, he_cap, &elem);
  2095. n = ieee80211_he_mcs_nss_size(&elem);
  2096. ie_len = 2 + 1 +
  2097. sizeof(he_cap->he_cap_elem) + n +
  2098. ieee80211_he_ppe_size(he_cap->ppe_thres[0],
  2099. he_cap->he_cap_elem.phy_cap_info);
  2100. if (skb_tailroom(skb) < ie_len)
  2101. return -ENOBUFS;
  2102. skb_put_u8(skb, WLAN_EID_EXTENSION);
  2103. len = skb_put(skb, 1); /* We'll set the size later below */
  2104. skb_put_u8(skb, WLAN_EID_EXT_HE_CAPABILITY);
  2105. /* Fixed data */
  2106. skb_put_data(skb, &elem, sizeof(elem));
  2107. skb_put_data(skb, &he_cap->he_mcs_nss_supp, n);
  2108. /* Check if PPE Threshold should be present */
  2109. if ((he_cap->he_cap_elem.phy_cap_info[6] &
  2110. IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) == 0)
  2111. goto end;
  2112. /*
  2113. * Calculate how many PPET16/PPET8 pairs are to come. Algorithm:
  2114. * (NSS_M1 + 1) x (num of 1 bits in RU_INDEX_BITMASK)
  2115. */
  2116. n = hweight8(he_cap->ppe_thres[0] &
  2117. IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK);
  2118. n *= (1 + ((he_cap->ppe_thres[0] & IEEE80211_PPE_THRES_NSS_MASK) >>
  2119. IEEE80211_PPE_THRES_NSS_POS));
  2120. /*
  2121. * Each pair is 6 bits, and we need to add the 7 "header" bits to the
  2122. * total size.
  2123. */
  2124. n = (n * IEEE80211_PPE_THRES_INFO_PPET_SIZE * 2) + 7;
  2125. n = DIV_ROUND_UP(n, 8);
  2126. /* Copy PPE Thresholds */
  2127. skb_put_data(skb, &he_cap->ppe_thres, n);
  2128. end:
  2129. *len = skb_tail_pointer(skb) - len - 1;
  2130. return 0;
  2131. }
  2132. int ieee80211_put_he_6ghz_cap(struct sk_buff *skb,
  2133. struct ieee80211_sub_if_data *sdata,
  2134. enum ieee80211_smps_mode smps_mode)
  2135. {
  2136. struct ieee80211_supported_band *sband;
  2137. const struct ieee80211_sband_iftype_data *iftd;
  2138. enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
  2139. __le16 cap;
  2140. if (!cfg80211_any_usable_channels(sdata->local->hw.wiphy,
  2141. BIT(NL80211_BAND_6GHZ),
  2142. IEEE80211_CHAN_NO_HE))
  2143. return 0;
  2144. sband = sdata->local->hw.wiphy->bands[NL80211_BAND_6GHZ];
  2145. iftd = ieee80211_get_sband_iftype_data(sband, iftype);
  2146. if (!iftd)
  2147. return 0;
  2148. /* Check for device HE 6 GHz capability before adding element */
  2149. if (!iftd->he_6ghz_capa.capa)
  2150. return 0;
  2151. cap = iftd->he_6ghz_capa.capa;
  2152. cap &= cpu_to_le16(~IEEE80211_HE_6GHZ_CAP_SM_PS);
  2153. switch (smps_mode) {
  2154. case IEEE80211_SMPS_AUTOMATIC:
  2155. case IEEE80211_SMPS_NUM_MODES:
  2156. WARN_ON(1);
  2157. fallthrough;
  2158. case IEEE80211_SMPS_OFF:
  2159. cap |= le16_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED,
  2160. IEEE80211_HE_6GHZ_CAP_SM_PS);
  2161. break;
  2162. case IEEE80211_SMPS_STATIC:
  2163. cap |= le16_encode_bits(WLAN_HT_CAP_SM_PS_STATIC,
  2164. IEEE80211_HE_6GHZ_CAP_SM_PS);
  2165. break;
  2166. case IEEE80211_SMPS_DYNAMIC:
  2167. cap |= le16_encode_bits(WLAN_HT_CAP_SM_PS_DYNAMIC,
  2168. IEEE80211_HE_6GHZ_CAP_SM_PS);
  2169. break;
  2170. }
  2171. if (skb_tailroom(skb) < 2 + 1 + sizeof(cap))
  2172. return -ENOBUFS;
  2173. skb_put_u8(skb, WLAN_EID_EXTENSION);
  2174. skb_put_u8(skb, 1 + sizeof(cap));
  2175. skb_put_u8(skb, WLAN_EID_EXT_HE_6GHZ_CAPA);
  2176. skb_put_data(skb, &cap, sizeof(cap));
  2177. return 0;
  2178. }
  2179. u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  2180. const struct cfg80211_chan_def *chandef,
  2181. u16 prot_mode, bool rifs_mode)
  2182. {
  2183. struct ieee80211_ht_operation *ht_oper;
  2184. /* Build HT Information */
  2185. *pos++ = WLAN_EID_HT_OPERATION;
  2186. *pos++ = sizeof(struct ieee80211_ht_operation);
  2187. ht_oper = (struct ieee80211_ht_operation *)pos;
  2188. ht_oper->primary_chan = ieee80211_frequency_to_channel(
  2189. chandef->chan->center_freq);
  2190. switch (chandef->width) {
  2191. case NL80211_CHAN_WIDTH_160:
  2192. case NL80211_CHAN_WIDTH_80P80:
  2193. case NL80211_CHAN_WIDTH_80:
  2194. case NL80211_CHAN_WIDTH_40:
  2195. if (chandef->center_freq1 > chandef->chan->center_freq)
  2196. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2197. else
  2198. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2199. break;
  2200. case NL80211_CHAN_WIDTH_320:
  2201. /* HT information element should not be included on 6GHz */
  2202. WARN_ON(1);
  2203. return pos;
  2204. default:
  2205. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2206. break;
  2207. }
  2208. if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  2209. chandef->width != NL80211_CHAN_WIDTH_20_NOHT &&
  2210. chandef->width != NL80211_CHAN_WIDTH_20)
  2211. ht_oper->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
  2212. if (rifs_mode)
  2213. ht_oper->ht_param |= IEEE80211_HT_PARAM_RIFS_MODE;
  2214. ht_oper->operation_mode = cpu_to_le16(prot_mode);
  2215. ht_oper->stbc_param = 0x0000;
  2216. /* It seems that Basic MCS set and Supported MCS set
  2217. are identical for the first 10 bytes */
  2218. memset(&ht_oper->basic_set, 0, 16);
  2219. memcpy(&ht_oper->basic_set, &ht_cap->mcs, 10);
  2220. return pos + sizeof(struct ieee80211_ht_operation);
  2221. }
  2222. void ieee80211_ie_build_wide_bw_cs(u8 *pos,
  2223. const struct cfg80211_chan_def *chandef)
  2224. {
  2225. *pos++ = WLAN_EID_WIDE_BW_CHANNEL_SWITCH; /* EID */
  2226. *pos++ = 3; /* IE length */
  2227. /* New channel width */
  2228. switch (chandef->width) {
  2229. case NL80211_CHAN_WIDTH_80:
  2230. *pos++ = IEEE80211_VHT_CHANWIDTH_80MHZ;
  2231. break;
  2232. case NL80211_CHAN_WIDTH_160:
  2233. *pos++ = IEEE80211_VHT_CHANWIDTH_160MHZ;
  2234. break;
  2235. case NL80211_CHAN_WIDTH_80P80:
  2236. *pos++ = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
  2237. break;
  2238. case NL80211_CHAN_WIDTH_320:
  2239. /* The behavior is not defined for 320 MHz channels */
  2240. WARN_ON(1);
  2241. fallthrough;
  2242. default:
  2243. *pos++ = IEEE80211_VHT_CHANWIDTH_USE_HT;
  2244. }
  2245. /* new center frequency segment 0 */
  2246. *pos++ = ieee80211_frequency_to_channel(chandef->center_freq1);
  2247. /* new center frequency segment 1 */
  2248. if (chandef->center_freq2)
  2249. *pos++ = ieee80211_frequency_to_channel(chandef->center_freq2);
  2250. else
  2251. *pos++ = 0;
  2252. }
  2253. u8 *ieee80211_ie_build_vht_oper(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
  2254. const struct cfg80211_chan_def *chandef)
  2255. {
  2256. struct ieee80211_vht_operation *vht_oper;
  2257. *pos++ = WLAN_EID_VHT_OPERATION;
  2258. *pos++ = sizeof(struct ieee80211_vht_operation);
  2259. vht_oper = (struct ieee80211_vht_operation *)pos;
  2260. vht_oper->center_freq_seg0_idx = ieee80211_frequency_to_channel(
  2261. chandef->center_freq1);
  2262. if (chandef->center_freq2)
  2263. vht_oper->center_freq_seg1_idx =
  2264. ieee80211_frequency_to_channel(chandef->center_freq2);
  2265. else
  2266. vht_oper->center_freq_seg1_idx = 0x00;
  2267. switch (chandef->width) {
  2268. case NL80211_CHAN_WIDTH_160:
  2269. /*
  2270. * Convert 160 MHz channel width to new style as interop
  2271. * workaround.
  2272. */
  2273. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  2274. vht_oper->center_freq_seg1_idx = vht_oper->center_freq_seg0_idx;
  2275. if (chandef->chan->center_freq < chandef->center_freq1)
  2276. vht_oper->center_freq_seg0_idx -= 8;
  2277. else
  2278. vht_oper->center_freq_seg0_idx += 8;
  2279. break;
  2280. case NL80211_CHAN_WIDTH_80P80:
  2281. /*
  2282. * Convert 80+80 MHz channel width to new style as interop
  2283. * workaround.
  2284. */
  2285. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  2286. break;
  2287. case NL80211_CHAN_WIDTH_80:
  2288. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  2289. break;
  2290. case NL80211_CHAN_WIDTH_320:
  2291. /* VHT information element should not be included on 6GHz */
  2292. WARN_ON(1);
  2293. return pos;
  2294. default:
  2295. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
  2296. break;
  2297. }
  2298. /* don't require special VHT peer rates */
  2299. vht_oper->basic_mcs_set = cpu_to_le16(0xffff);
  2300. return pos + sizeof(struct ieee80211_vht_operation);
  2301. }
  2302. u8 *ieee80211_ie_build_he_oper(u8 *pos, struct cfg80211_chan_def *chandef)
  2303. {
  2304. struct ieee80211_he_operation *he_oper;
  2305. struct ieee80211_he_6ghz_oper *he_6ghz_op;
  2306. u32 he_oper_params;
  2307. u8 ie_len = 1 + sizeof(struct ieee80211_he_operation);
  2308. if (chandef->chan->band == NL80211_BAND_6GHZ)
  2309. ie_len += sizeof(struct ieee80211_he_6ghz_oper);
  2310. *pos++ = WLAN_EID_EXTENSION;
  2311. *pos++ = ie_len;
  2312. *pos++ = WLAN_EID_EXT_HE_OPERATION;
  2313. he_oper_params = 0;
  2314. he_oper_params |= u32_encode_bits(1023, /* disabled */
  2315. IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
  2316. he_oper_params |= u32_encode_bits(1,
  2317. IEEE80211_HE_OPERATION_ER_SU_DISABLE);
  2318. he_oper_params |= u32_encode_bits(1,
  2319. IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
  2320. if (chandef->chan->band == NL80211_BAND_6GHZ)
  2321. he_oper_params |= u32_encode_bits(1,
  2322. IEEE80211_HE_OPERATION_6GHZ_OP_INFO);
  2323. he_oper = (struct ieee80211_he_operation *)pos;
  2324. he_oper->he_oper_params = cpu_to_le32(he_oper_params);
  2325. /* don't require special HE peer rates */
  2326. he_oper->he_mcs_nss_set = cpu_to_le16(0xffff);
  2327. pos += sizeof(struct ieee80211_he_operation);
  2328. if (chandef->chan->band != NL80211_BAND_6GHZ)
  2329. goto out;
  2330. /* TODO add VHT operational */
  2331. he_6ghz_op = (struct ieee80211_he_6ghz_oper *)pos;
  2332. he_6ghz_op->minrate = 6; /* 6 Mbps */
  2333. he_6ghz_op->primary =
  2334. ieee80211_frequency_to_channel(chandef->chan->center_freq);
  2335. he_6ghz_op->ccfs0 =
  2336. ieee80211_frequency_to_channel(chandef->center_freq1);
  2337. if (chandef->center_freq2)
  2338. he_6ghz_op->ccfs1 =
  2339. ieee80211_frequency_to_channel(chandef->center_freq2);
  2340. else
  2341. he_6ghz_op->ccfs1 = 0;
  2342. switch (chandef->width) {
  2343. case NL80211_CHAN_WIDTH_320:
  2344. /*
  2345. * TODO: mesh operation is not defined over 6GHz 320 MHz
  2346. * channels.
  2347. */
  2348. WARN_ON(1);
  2349. break;
  2350. case NL80211_CHAN_WIDTH_160:
  2351. /* Convert 160 MHz channel width to new style as interop
  2352. * workaround.
  2353. */
  2354. he_6ghz_op->control =
  2355. IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
  2356. he_6ghz_op->ccfs1 = he_6ghz_op->ccfs0;
  2357. if (chandef->chan->center_freq < chandef->center_freq1)
  2358. he_6ghz_op->ccfs0 -= 8;
  2359. else
  2360. he_6ghz_op->ccfs0 += 8;
  2361. fallthrough;
  2362. case NL80211_CHAN_WIDTH_80P80:
  2363. he_6ghz_op->control =
  2364. IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
  2365. break;
  2366. case NL80211_CHAN_WIDTH_80:
  2367. he_6ghz_op->control =
  2368. IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ;
  2369. break;
  2370. case NL80211_CHAN_WIDTH_40:
  2371. he_6ghz_op->control =
  2372. IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ;
  2373. break;
  2374. default:
  2375. he_6ghz_op->control =
  2376. IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ;
  2377. break;
  2378. }
  2379. pos += sizeof(struct ieee80211_he_6ghz_oper);
  2380. out:
  2381. return pos;
  2382. }
  2383. u8 *ieee80211_ie_build_eht_oper(u8 *pos, struct cfg80211_chan_def *chandef,
  2384. const struct ieee80211_sta_eht_cap *eht_cap)
  2385. {
  2386. const struct ieee80211_eht_mcs_nss_supp_20mhz_only *eht_mcs_nss =
  2387. &eht_cap->eht_mcs_nss_supp.only_20mhz;
  2388. struct ieee80211_eht_operation *eht_oper;
  2389. struct ieee80211_eht_operation_info *eht_oper_info;
  2390. u8 eht_oper_len = offsetof(struct ieee80211_eht_operation, optional);
  2391. u8 eht_oper_info_len =
  2392. offsetof(struct ieee80211_eht_operation_info, optional);
  2393. u8 chan_width = 0;
  2394. *pos++ = WLAN_EID_EXTENSION;
  2395. *pos++ = 1 + eht_oper_len + eht_oper_info_len;
  2396. *pos++ = WLAN_EID_EXT_EHT_OPERATION;
  2397. eht_oper = (struct ieee80211_eht_operation *)pos;
  2398. memcpy(&eht_oper->basic_mcs_nss, eht_mcs_nss, sizeof(*eht_mcs_nss));
  2399. eht_oper->params |= IEEE80211_EHT_OPER_INFO_PRESENT;
  2400. pos += eht_oper_len;
  2401. eht_oper_info =
  2402. (struct ieee80211_eht_operation_info *)eht_oper->optional;
  2403. eht_oper_info->ccfs0 =
  2404. ieee80211_frequency_to_channel(chandef->center_freq1);
  2405. if (chandef->center_freq2)
  2406. eht_oper_info->ccfs1 =
  2407. ieee80211_frequency_to_channel(chandef->center_freq2);
  2408. else
  2409. eht_oper_info->ccfs1 = 0;
  2410. switch (chandef->width) {
  2411. case NL80211_CHAN_WIDTH_320:
  2412. chan_width = IEEE80211_EHT_OPER_CHAN_WIDTH_320MHZ;
  2413. eht_oper_info->ccfs1 = eht_oper_info->ccfs0;
  2414. if (chandef->chan->center_freq < chandef->center_freq1)
  2415. eht_oper_info->ccfs0 -= 16;
  2416. else
  2417. eht_oper_info->ccfs0 += 16;
  2418. break;
  2419. case NL80211_CHAN_WIDTH_160:
  2420. eht_oper_info->ccfs1 = eht_oper_info->ccfs0;
  2421. if (chandef->chan->center_freq < chandef->center_freq1)
  2422. eht_oper_info->ccfs0 -= 8;
  2423. else
  2424. eht_oper_info->ccfs0 += 8;
  2425. fallthrough;
  2426. case NL80211_CHAN_WIDTH_80P80:
  2427. chan_width = IEEE80211_EHT_OPER_CHAN_WIDTH_160MHZ;
  2428. break;
  2429. case NL80211_CHAN_WIDTH_80:
  2430. chan_width = IEEE80211_EHT_OPER_CHAN_WIDTH_80MHZ;
  2431. break;
  2432. case NL80211_CHAN_WIDTH_40:
  2433. chan_width = IEEE80211_EHT_OPER_CHAN_WIDTH_40MHZ;
  2434. break;
  2435. default:
  2436. chan_width = IEEE80211_EHT_OPER_CHAN_WIDTH_20MHZ;
  2437. break;
  2438. }
  2439. eht_oper_info->control = chan_width;
  2440. pos += eht_oper_info_len;
  2441. /* TODO: eht_oper_info->optional */
  2442. return pos;
  2443. }
  2444. bool ieee80211_chandef_ht_oper(const struct ieee80211_ht_operation *ht_oper,
  2445. struct cfg80211_chan_def *chandef)
  2446. {
  2447. enum nl80211_channel_type channel_type;
  2448. if (!ht_oper)
  2449. return false;
  2450. switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  2451. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  2452. channel_type = NL80211_CHAN_HT20;
  2453. break;
  2454. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  2455. channel_type = NL80211_CHAN_HT40PLUS;
  2456. break;
  2457. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  2458. channel_type = NL80211_CHAN_HT40MINUS;
  2459. break;
  2460. default:
  2461. return false;
  2462. }
  2463. cfg80211_chandef_create(chandef, chandef->chan, channel_type);
  2464. return true;
  2465. }
  2466. bool ieee80211_chandef_vht_oper(struct ieee80211_hw *hw, u32 vht_cap_info,
  2467. const struct ieee80211_vht_operation *oper,
  2468. const struct ieee80211_ht_operation *htop,
  2469. struct cfg80211_chan_def *chandef)
  2470. {
  2471. struct cfg80211_chan_def new = *chandef;
  2472. int cf0, cf1;
  2473. int ccfs0, ccfs1, ccfs2;
  2474. int ccf0, ccf1;
  2475. u32 vht_cap;
  2476. bool support_80_80 = false;
  2477. bool support_160 = false;
  2478. u8 ext_nss_bw_supp = u32_get_bits(vht_cap_info,
  2479. IEEE80211_VHT_CAP_EXT_NSS_BW_MASK);
  2480. u8 supp_chwidth = u32_get_bits(vht_cap_info,
  2481. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK);
  2482. if (!oper || !htop)
  2483. return false;
  2484. vht_cap = hw->wiphy->bands[chandef->chan->band]->vht_cap.cap;
  2485. support_160 = (vht_cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK |
  2486. IEEE80211_VHT_CAP_EXT_NSS_BW_MASK));
  2487. support_80_80 = ((vht_cap &
  2488. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) ||
  2489. (vht_cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ &&
  2490. vht_cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) ||
  2491. ((vht_cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) >>
  2492. IEEE80211_VHT_CAP_EXT_NSS_BW_SHIFT > 1));
  2493. ccfs0 = oper->center_freq_seg0_idx;
  2494. ccfs1 = oper->center_freq_seg1_idx;
  2495. ccfs2 = (le16_to_cpu(htop->operation_mode) &
  2496. IEEE80211_HT_OP_MODE_CCFS2_MASK)
  2497. >> IEEE80211_HT_OP_MODE_CCFS2_SHIFT;
  2498. ccf0 = ccfs0;
  2499. /* if not supported, parse as though we didn't understand it */
  2500. if (!ieee80211_hw_check(hw, SUPPORTS_VHT_EXT_NSS_BW))
  2501. ext_nss_bw_supp = 0;
  2502. /*
  2503. * Cf. IEEE 802.11 Table 9-250
  2504. *
  2505. * We really just consider that because it's inefficient to connect
  2506. * at a higher bandwidth than we'll actually be able to use.
  2507. */
  2508. switch ((supp_chwidth << 4) | ext_nss_bw_supp) {
  2509. default:
  2510. case 0x00:
  2511. ccf1 = 0;
  2512. support_160 = false;
  2513. support_80_80 = false;
  2514. break;
  2515. case 0x01:
  2516. support_80_80 = false;
  2517. fallthrough;
  2518. case 0x02:
  2519. case 0x03:
  2520. ccf1 = ccfs2;
  2521. break;
  2522. case 0x10:
  2523. ccf1 = ccfs1;
  2524. break;
  2525. case 0x11:
  2526. case 0x12:
  2527. if (!ccfs1)
  2528. ccf1 = ccfs2;
  2529. else
  2530. ccf1 = ccfs1;
  2531. break;
  2532. case 0x13:
  2533. case 0x20:
  2534. case 0x23:
  2535. ccf1 = ccfs1;
  2536. break;
  2537. }
  2538. cf0 = ieee80211_channel_to_frequency(ccf0, chandef->chan->band);
  2539. cf1 = ieee80211_channel_to_frequency(ccf1, chandef->chan->band);
  2540. switch (oper->chan_width) {
  2541. case IEEE80211_VHT_CHANWIDTH_USE_HT:
  2542. /* just use HT information directly */
  2543. break;
  2544. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  2545. new.width = NL80211_CHAN_WIDTH_80;
  2546. new.center_freq1 = cf0;
  2547. /* If needed, adjust based on the newer interop workaround. */
  2548. if (ccf1) {
  2549. unsigned int diff;
  2550. diff = abs(ccf1 - ccf0);
  2551. if ((diff == 8) && support_160) {
  2552. new.width = NL80211_CHAN_WIDTH_160;
  2553. new.center_freq1 = cf1;
  2554. } else if ((diff > 8) && support_80_80) {
  2555. new.width = NL80211_CHAN_WIDTH_80P80;
  2556. new.center_freq2 = cf1;
  2557. }
  2558. }
  2559. break;
  2560. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  2561. /* deprecated encoding */
  2562. new.width = NL80211_CHAN_WIDTH_160;
  2563. new.center_freq1 = cf0;
  2564. break;
  2565. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  2566. /* deprecated encoding */
  2567. new.width = NL80211_CHAN_WIDTH_80P80;
  2568. new.center_freq1 = cf0;
  2569. new.center_freq2 = cf1;
  2570. break;
  2571. default:
  2572. return false;
  2573. }
  2574. if (!cfg80211_chandef_valid(&new))
  2575. return false;
  2576. *chandef = new;
  2577. return true;
  2578. }
  2579. void ieee80211_chandef_eht_oper(const struct ieee80211_eht_operation_info *info,
  2580. struct cfg80211_chan_def *chandef)
  2581. {
  2582. chandef->center_freq1 =
  2583. ieee80211_channel_to_frequency(info->ccfs0,
  2584. chandef->chan->band);
  2585. switch (u8_get_bits(info->control,
  2586. IEEE80211_EHT_OPER_CHAN_WIDTH)) {
  2587. case IEEE80211_EHT_OPER_CHAN_WIDTH_20MHZ:
  2588. chandef->width = NL80211_CHAN_WIDTH_20;
  2589. break;
  2590. case IEEE80211_EHT_OPER_CHAN_WIDTH_40MHZ:
  2591. chandef->width = NL80211_CHAN_WIDTH_40;
  2592. break;
  2593. case IEEE80211_EHT_OPER_CHAN_WIDTH_80MHZ:
  2594. chandef->width = NL80211_CHAN_WIDTH_80;
  2595. break;
  2596. case IEEE80211_EHT_OPER_CHAN_WIDTH_160MHZ:
  2597. chandef->width = NL80211_CHAN_WIDTH_160;
  2598. chandef->center_freq1 =
  2599. ieee80211_channel_to_frequency(info->ccfs1,
  2600. chandef->chan->band);
  2601. break;
  2602. case IEEE80211_EHT_OPER_CHAN_WIDTH_320MHZ:
  2603. chandef->width = NL80211_CHAN_WIDTH_320;
  2604. chandef->center_freq1 =
  2605. ieee80211_channel_to_frequency(info->ccfs1,
  2606. chandef->chan->band);
  2607. break;
  2608. }
  2609. }
  2610. bool ieee80211_chandef_he_6ghz_oper(struct ieee80211_local *local,
  2611. const struct ieee80211_he_operation *he_oper,
  2612. const struct ieee80211_eht_operation *eht_oper,
  2613. struct cfg80211_chan_def *chandef)
  2614. {
  2615. struct cfg80211_chan_def he_chandef = *chandef;
  2616. const struct ieee80211_he_6ghz_oper *he_6ghz_oper;
  2617. u32 freq;
  2618. if (chandef->chan->band != NL80211_BAND_6GHZ)
  2619. return true;
  2620. if (!he_oper)
  2621. return false;
  2622. he_6ghz_oper = ieee80211_he_6ghz_oper(he_oper);
  2623. if (!he_6ghz_oper)
  2624. return false;
  2625. /*
  2626. * The EHT operation IE does not contain the primary channel so the
  2627. * primary channel frequency should be taken from the 6 GHz operation
  2628. * information.
  2629. */
  2630. freq = ieee80211_channel_to_frequency(he_6ghz_oper->primary,
  2631. NL80211_BAND_6GHZ);
  2632. he_chandef.chan = ieee80211_get_channel(local->hw.wiphy, freq);
  2633. if (!he_chandef.chan)
  2634. return false;
  2635. if (!eht_oper ||
  2636. !(eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
  2637. switch (u8_get_bits(he_6ghz_oper->control,
  2638. IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH)) {
  2639. case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ:
  2640. he_chandef.width = NL80211_CHAN_WIDTH_20;
  2641. break;
  2642. case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ:
  2643. he_chandef.width = NL80211_CHAN_WIDTH_40;
  2644. break;
  2645. case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ:
  2646. he_chandef.width = NL80211_CHAN_WIDTH_80;
  2647. break;
  2648. case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ:
  2649. he_chandef.width = NL80211_CHAN_WIDTH_80;
  2650. if (!he_6ghz_oper->ccfs1)
  2651. break;
  2652. if (abs(he_6ghz_oper->ccfs1 - he_6ghz_oper->ccfs0) == 8)
  2653. he_chandef.width = NL80211_CHAN_WIDTH_160;
  2654. else
  2655. he_chandef.width = NL80211_CHAN_WIDTH_80P80;
  2656. break;
  2657. }
  2658. if (he_chandef.width == NL80211_CHAN_WIDTH_160) {
  2659. he_chandef.center_freq1 =
  2660. ieee80211_channel_to_frequency(he_6ghz_oper->ccfs1,
  2661. NL80211_BAND_6GHZ);
  2662. } else {
  2663. he_chandef.center_freq1 =
  2664. ieee80211_channel_to_frequency(he_6ghz_oper->ccfs0,
  2665. NL80211_BAND_6GHZ);
  2666. he_chandef.center_freq2 =
  2667. ieee80211_channel_to_frequency(he_6ghz_oper->ccfs1,
  2668. NL80211_BAND_6GHZ);
  2669. }
  2670. } else {
  2671. ieee80211_chandef_eht_oper((const void *)eht_oper->optional,
  2672. &he_chandef);
  2673. he_chandef.punctured =
  2674. ieee80211_eht_oper_dis_subchan_bitmap(eht_oper);
  2675. }
  2676. if (!cfg80211_chandef_valid(&he_chandef))
  2677. return false;
  2678. *chandef = he_chandef;
  2679. return true;
  2680. }
  2681. bool ieee80211_chandef_s1g_oper(const struct ieee80211_s1g_oper_ie *oper,
  2682. struct cfg80211_chan_def *chandef)
  2683. {
  2684. u32 oper_freq;
  2685. if (!oper)
  2686. return false;
  2687. switch (FIELD_GET(S1G_OPER_CH_WIDTH_OPER, oper->ch_width)) {
  2688. case IEEE80211_S1G_CHANWIDTH_1MHZ:
  2689. chandef->width = NL80211_CHAN_WIDTH_1;
  2690. break;
  2691. case IEEE80211_S1G_CHANWIDTH_2MHZ:
  2692. chandef->width = NL80211_CHAN_WIDTH_2;
  2693. break;
  2694. case IEEE80211_S1G_CHANWIDTH_4MHZ:
  2695. chandef->width = NL80211_CHAN_WIDTH_4;
  2696. break;
  2697. case IEEE80211_S1G_CHANWIDTH_8MHZ:
  2698. chandef->width = NL80211_CHAN_WIDTH_8;
  2699. break;
  2700. case IEEE80211_S1G_CHANWIDTH_16MHZ:
  2701. chandef->width = NL80211_CHAN_WIDTH_16;
  2702. break;
  2703. default:
  2704. return false;
  2705. }
  2706. oper_freq = ieee80211_channel_to_freq_khz(oper->oper_ch,
  2707. NL80211_BAND_S1GHZ);
  2708. chandef->center_freq1 = KHZ_TO_MHZ(oper_freq);
  2709. chandef->freq1_offset = oper_freq % 1000;
  2710. return true;
  2711. }
  2712. int ieee80211_put_srates_elem(struct sk_buff *skb,
  2713. const struct ieee80211_supported_band *sband,
  2714. u32 basic_rates, u32 rate_flags, u32 masked_rates,
  2715. u8 element_id)
  2716. {
  2717. u8 i, rates, skip;
  2718. rates = 0;
  2719. for (i = 0; i < sband->n_bitrates; i++) {
  2720. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  2721. continue;
  2722. if (masked_rates & BIT(i))
  2723. continue;
  2724. rates++;
  2725. }
  2726. if (element_id == WLAN_EID_SUPP_RATES) {
  2727. rates = min_t(u8, rates, 8);
  2728. skip = 0;
  2729. } else {
  2730. skip = 8;
  2731. if (rates <= skip)
  2732. return 0;
  2733. rates -= skip;
  2734. }
  2735. if (skb_tailroom(skb) < rates + 2)
  2736. return -ENOBUFS;
  2737. skb_put_u8(skb, element_id);
  2738. skb_put_u8(skb, rates);
  2739. for (i = 0; i < sband->n_bitrates && rates; i++) {
  2740. int rate;
  2741. u8 basic;
  2742. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  2743. continue;
  2744. if (masked_rates & BIT(i))
  2745. continue;
  2746. if (skip > 0) {
  2747. skip--;
  2748. continue;
  2749. }
  2750. basic = basic_rates & BIT(i) ? 0x80 : 0;
  2751. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 5);
  2752. skb_put_u8(skb, basic | (u8)rate);
  2753. rates--;
  2754. }
  2755. WARN(rates > 0, "rates confused: rates:%d, element:%d\n",
  2756. rates, element_id);
  2757. return 0;
  2758. }
  2759. int ieee80211_ave_rssi(struct ieee80211_vif *vif)
  2760. {
  2761. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2762. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
  2763. return 0;
  2764. return -ewma_beacon_signal_read(&sdata->deflink.u.mgd.ave_beacon_signal);
  2765. }
  2766. EXPORT_SYMBOL_GPL(ieee80211_ave_rssi);
  2767. u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs)
  2768. {
  2769. if (!mcs)
  2770. return 1;
  2771. /* TODO: consider rx_highest */
  2772. if (mcs->rx_mask[3])
  2773. return 4;
  2774. if (mcs->rx_mask[2])
  2775. return 3;
  2776. if (mcs->rx_mask[1])
  2777. return 2;
  2778. return 1;
  2779. }
  2780. /**
  2781. * ieee80211_calculate_rx_timestamp - calculate timestamp in frame
  2782. * @local: mac80211 hw info struct
  2783. * @status: RX status
  2784. * @mpdu_len: total MPDU length (including FCS)
  2785. * @mpdu_offset: offset into MPDU to calculate timestamp at
  2786. *
  2787. * This function calculates the RX timestamp at the given MPDU offset, taking
  2788. * into account what the RX timestamp was. An offset of 0 will just normalize
  2789. * the timestamp to TSF at beginning of MPDU reception.
  2790. *
  2791. * Returns: the calculated timestamp
  2792. */
  2793. u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
  2794. struct ieee80211_rx_status *status,
  2795. unsigned int mpdu_len,
  2796. unsigned int mpdu_offset)
  2797. {
  2798. u64 ts = status->mactime;
  2799. bool mactime_plcp_start;
  2800. struct rate_info ri;
  2801. u16 rate;
  2802. u8 n_ltf;
  2803. if (WARN_ON(!ieee80211_have_rx_timestamp(status)))
  2804. return 0;
  2805. mactime_plcp_start = (status->flag & RX_FLAG_MACTIME) ==
  2806. RX_FLAG_MACTIME_PLCP_START;
  2807. memset(&ri, 0, sizeof(ri));
  2808. ri.bw = status->bw;
  2809. /* Fill cfg80211 rate info */
  2810. switch (status->encoding) {
  2811. case RX_ENC_EHT:
  2812. ri.flags |= RATE_INFO_FLAGS_EHT_MCS;
  2813. ri.mcs = status->rate_idx;
  2814. ri.nss = status->nss;
  2815. ri.eht_ru_alloc = status->eht.ru;
  2816. if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
  2817. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  2818. /* TODO/FIXME: is this right? handle other PPDUs */
  2819. if (mactime_plcp_start) {
  2820. mpdu_offset += 2;
  2821. ts += 36;
  2822. }
  2823. break;
  2824. case RX_ENC_HE:
  2825. ri.flags |= RATE_INFO_FLAGS_HE_MCS;
  2826. ri.mcs = status->rate_idx;
  2827. ri.nss = status->nss;
  2828. ri.he_ru_alloc = status->he_ru;
  2829. if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
  2830. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  2831. /*
  2832. * See P802.11ax_D6.0, section 27.3.4 for
  2833. * VHT PPDU format.
  2834. */
  2835. if (mactime_plcp_start) {
  2836. mpdu_offset += 2;
  2837. ts += 36;
  2838. /*
  2839. * TODO:
  2840. * For HE MU PPDU, add the HE-SIG-B.
  2841. * For HE ER PPDU, add 8us for the HE-SIG-A.
  2842. * For HE TB PPDU, add 4us for the HE-STF.
  2843. * Add the HE-LTF durations - variable.
  2844. */
  2845. }
  2846. break;
  2847. case RX_ENC_HT:
  2848. ri.mcs = status->rate_idx;
  2849. ri.flags |= RATE_INFO_FLAGS_MCS;
  2850. if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
  2851. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  2852. /*
  2853. * See P802.11REVmd_D3.0, section 19.3.2 for
  2854. * HT PPDU format.
  2855. */
  2856. if (mactime_plcp_start) {
  2857. mpdu_offset += 2;
  2858. if (status->enc_flags & RX_ENC_FLAG_HT_GF)
  2859. ts += 24;
  2860. else
  2861. ts += 32;
  2862. /*
  2863. * Add Data HT-LTFs per streams
  2864. * TODO: add Extension HT-LTFs, 4us per LTF
  2865. */
  2866. n_ltf = ((ri.mcs >> 3) & 3) + 1;
  2867. n_ltf = n_ltf == 3 ? 4 : n_ltf;
  2868. ts += n_ltf * 4;
  2869. }
  2870. break;
  2871. case RX_ENC_VHT:
  2872. ri.flags |= RATE_INFO_FLAGS_VHT_MCS;
  2873. ri.mcs = status->rate_idx;
  2874. ri.nss = status->nss;
  2875. if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
  2876. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  2877. /*
  2878. * See P802.11REVmd_D3.0, section 21.3.2 for
  2879. * VHT PPDU format.
  2880. */
  2881. if (mactime_plcp_start) {
  2882. mpdu_offset += 2;
  2883. ts += 36;
  2884. /*
  2885. * Add VHT-LTFs per streams
  2886. */
  2887. n_ltf = (ri.nss != 1) && (ri.nss % 2) ?
  2888. ri.nss + 1 : ri.nss;
  2889. ts += 4 * n_ltf;
  2890. }
  2891. break;
  2892. default:
  2893. WARN_ON(1);
  2894. fallthrough;
  2895. case RX_ENC_LEGACY: {
  2896. struct ieee80211_supported_band *sband;
  2897. sband = local->hw.wiphy->bands[status->band];
  2898. ri.legacy = sband->bitrates[status->rate_idx].bitrate;
  2899. if (mactime_plcp_start) {
  2900. if (status->band == NL80211_BAND_5GHZ) {
  2901. ts += 20;
  2902. mpdu_offset += 2;
  2903. } else if (status->enc_flags & RX_ENC_FLAG_SHORTPRE) {
  2904. ts += 96;
  2905. } else {
  2906. ts += 192;
  2907. }
  2908. }
  2909. break;
  2910. }
  2911. }
  2912. rate = cfg80211_calculate_bitrate(&ri);
  2913. if (WARN_ONCE(!rate,
  2914. "Invalid bitrate: flags=0x%llx, idx=%d, vht_nss=%d\n",
  2915. (unsigned long long)status->flag, status->rate_idx,
  2916. status->nss))
  2917. return 0;
  2918. /* rewind from end of MPDU */
  2919. if ((status->flag & RX_FLAG_MACTIME) == RX_FLAG_MACTIME_END)
  2920. ts -= mpdu_len * 8 * 10 / rate;
  2921. ts += mpdu_offset * 8 * 10 / rate;
  2922. return ts;
  2923. }
  2924. /* Cancel CAC for the interfaces under the specified @local. If @ctx is
  2925. * also provided, only the interfaces using that ctx will be canceled.
  2926. */
  2927. void ieee80211_dfs_cac_cancel(struct ieee80211_local *local,
  2928. struct ieee80211_chanctx *ctx)
  2929. {
  2930. struct ieee80211_sub_if_data *sdata;
  2931. struct cfg80211_chan_def chandef;
  2932. struct ieee80211_link_data *link;
  2933. struct ieee80211_chanctx_conf *chanctx_conf;
  2934. unsigned int link_id;
  2935. lockdep_assert_wiphy(local->hw.wiphy);
  2936. list_for_each_entry(sdata, &local->interfaces, list) {
  2937. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
  2938. link_id++) {
  2939. link = sdata_dereference(sdata->link[link_id],
  2940. sdata);
  2941. if (!link)
  2942. continue;
  2943. chanctx_conf = sdata_dereference(link->conf->chanctx_conf,
  2944. sdata);
  2945. if (ctx && &ctx->conf != chanctx_conf)
  2946. continue;
  2947. wiphy_delayed_work_cancel(local->hw.wiphy,
  2948. &link->dfs_cac_timer_work);
  2949. if (!sdata->wdev.links[link_id].cac_started)
  2950. continue;
  2951. chandef = link->conf->chanreq.oper;
  2952. ieee80211_link_release_channel(link);
  2953. cfg80211_cac_event(sdata->dev, &chandef,
  2954. NL80211_RADAR_CAC_ABORTED,
  2955. GFP_KERNEL, link_id);
  2956. }
  2957. }
  2958. }
  2959. void ieee80211_dfs_radar_detected_work(struct wiphy *wiphy,
  2960. struct wiphy_work *work)
  2961. {
  2962. struct ieee80211_local *local =
  2963. container_of(work, struct ieee80211_local, radar_detected_work);
  2964. struct cfg80211_chan_def chandef;
  2965. struct ieee80211_chanctx *ctx;
  2966. lockdep_assert_wiphy(local->hw.wiphy);
  2967. list_for_each_entry(ctx, &local->chanctx_list, list) {
  2968. if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER)
  2969. continue;
  2970. if (!ctx->radar_detected)
  2971. continue;
  2972. ctx->radar_detected = false;
  2973. chandef = ctx->conf.def;
  2974. ieee80211_dfs_cac_cancel(local, ctx);
  2975. cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL);
  2976. }
  2977. }
  2978. static void
  2979. ieee80211_radar_mark_chan_ctx_iterator(struct ieee80211_hw *hw,
  2980. struct ieee80211_chanctx_conf *chanctx_conf,
  2981. void *data)
  2982. {
  2983. struct ieee80211_chanctx *ctx =
  2984. container_of(chanctx_conf, struct ieee80211_chanctx,
  2985. conf);
  2986. if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER)
  2987. return;
  2988. if (data && data != chanctx_conf)
  2989. return;
  2990. ctx->radar_detected = true;
  2991. }
  2992. void ieee80211_radar_detected(struct ieee80211_hw *hw,
  2993. struct ieee80211_chanctx_conf *chanctx_conf)
  2994. {
  2995. struct ieee80211_local *local = hw_to_local(hw);
  2996. trace_api_radar_detected(local);
  2997. ieee80211_iter_chan_contexts_atomic(hw, ieee80211_radar_mark_chan_ctx_iterator,
  2998. chanctx_conf);
  2999. wiphy_work_queue(hw->wiphy, &local->radar_detected_work);
  3000. }
  3001. EXPORT_SYMBOL(ieee80211_radar_detected);
  3002. void ieee80211_chandef_downgrade(struct cfg80211_chan_def *c,
  3003. struct ieee80211_conn_settings *conn)
  3004. {
  3005. enum nl80211_chan_width new_primary_width;
  3006. struct ieee80211_conn_settings _ignored = {};
  3007. /* allow passing NULL if caller doesn't care */
  3008. if (!conn)
  3009. conn = &_ignored;
  3010. again:
  3011. /* no-HT indicates nothing to do */
  3012. new_primary_width = NL80211_CHAN_WIDTH_20_NOHT;
  3013. switch (c->width) {
  3014. default:
  3015. case NL80211_CHAN_WIDTH_20_NOHT:
  3016. WARN_ON_ONCE(1);
  3017. fallthrough;
  3018. case NL80211_CHAN_WIDTH_20:
  3019. c->width = NL80211_CHAN_WIDTH_20_NOHT;
  3020. conn->mode = IEEE80211_CONN_MODE_LEGACY;
  3021. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  3022. c->punctured = 0;
  3023. break;
  3024. case NL80211_CHAN_WIDTH_40:
  3025. c->width = NL80211_CHAN_WIDTH_20;
  3026. c->center_freq1 = c->chan->center_freq;
  3027. if (conn->mode == IEEE80211_CONN_MODE_VHT)
  3028. conn->mode = IEEE80211_CONN_MODE_HT;
  3029. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  3030. c->punctured = 0;
  3031. break;
  3032. case NL80211_CHAN_WIDTH_80:
  3033. new_primary_width = NL80211_CHAN_WIDTH_40;
  3034. if (conn->mode == IEEE80211_CONN_MODE_VHT)
  3035. conn->mode = IEEE80211_CONN_MODE_HT;
  3036. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_40;
  3037. break;
  3038. case NL80211_CHAN_WIDTH_80P80:
  3039. c->center_freq2 = 0;
  3040. c->width = NL80211_CHAN_WIDTH_80;
  3041. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80;
  3042. break;
  3043. case NL80211_CHAN_WIDTH_160:
  3044. new_primary_width = NL80211_CHAN_WIDTH_80;
  3045. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80;
  3046. break;
  3047. case NL80211_CHAN_WIDTH_320:
  3048. new_primary_width = NL80211_CHAN_WIDTH_160;
  3049. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_160;
  3050. break;
  3051. case NL80211_CHAN_WIDTH_1:
  3052. case NL80211_CHAN_WIDTH_2:
  3053. case NL80211_CHAN_WIDTH_4:
  3054. case NL80211_CHAN_WIDTH_8:
  3055. case NL80211_CHAN_WIDTH_16:
  3056. WARN_ON_ONCE(1);
  3057. /* keep c->width */
  3058. conn->mode = IEEE80211_CONN_MODE_S1G;
  3059. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  3060. break;
  3061. case NL80211_CHAN_WIDTH_5:
  3062. case NL80211_CHAN_WIDTH_10:
  3063. WARN_ON_ONCE(1);
  3064. /* keep c->width */
  3065. conn->mode = IEEE80211_CONN_MODE_LEGACY;
  3066. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  3067. break;
  3068. }
  3069. if (new_primary_width != NL80211_CHAN_WIDTH_20_NOHT) {
  3070. c->center_freq1 = cfg80211_chandef_primary(c, new_primary_width,
  3071. &c->punctured);
  3072. c->width = new_primary_width;
  3073. }
  3074. /*
  3075. * With an 80 MHz channel, we might have the puncturing in the primary
  3076. * 40 Mhz channel, but that's not valid when downgraded to 40 MHz width.
  3077. * In that case, downgrade again.
  3078. */
  3079. if (!cfg80211_chandef_valid(c) && c->punctured)
  3080. goto again;
  3081. WARN_ON_ONCE(!cfg80211_chandef_valid(c));
  3082. }
  3083. /*
  3084. * Returns true if smps_mode_new is strictly more restrictive than
  3085. * smps_mode_old.
  3086. */
  3087. bool ieee80211_smps_is_restrictive(enum ieee80211_smps_mode smps_mode_old,
  3088. enum ieee80211_smps_mode smps_mode_new)
  3089. {
  3090. if (WARN_ON_ONCE(smps_mode_old == IEEE80211_SMPS_AUTOMATIC ||
  3091. smps_mode_new == IEEE80211_SMPS_AUTOMATIC))
  3092. return false;
  3093. switch (smps_mode_old) {
  3094. case IEEE80211_SMPS_STATIC:
  3095. return false;
  3096. case IEEE80211_SMPS_DYNAMIC:
  3097. return smps_mode_new == IEEE80211_SMPS_STATIC;
  3098. case IEEE80211_SMPS_OFF:
  3099. return smps_mode_new != IEEE80211_SMPS_OFF;
  3100. default:
  3101. WARN_ON(1);
  3102. }
  3103. return false;
  3104. }
  3105. int ieee80211_send_action_csa(struct ieee80211_sub_if_data *sdata,
  3106. struct cfg80211_csa_settings *csa_settings)
  3107. {
  3108. struct sk_buff *skb;
  3109. struct ieee80211_mgmt *mgmt;
  3110. struct ieee80211_local *local = sdata->local;
  3111. int freq;
  3112. int hdr_len = offsetofend(struct ieee80211_mgmt,
  3113. u.action.u.chan_switch);
  3114. u8 *pos;
  3115. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  3116. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  3117. return -EOPNOTSUPP;
  3118. skb = dev_alloc_skb(local->tx_headroom + hdr_len +
  3119. 5 + /* channel switch announcement element */
  3120. 3 + /* secondary channel offset element */
  3121. 5 + /* wide bandwidth channel switch announcement */
  3122. 8); /* mesh channel switch parameters element */
  3123. if (!skb)
  3124. return -ENOMEM;
  3125. skb_reserve(skb, local->tx_headroom);
  3126. mgmt = skb_put_zero(skb, hdr_len);
  3127. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  3128. IEEE80211_STYPE_ACTION);
  3129. eth_broadcast_addr(mgmt->da);
  3130. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  3131. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  3132. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  3133. } else {
  3134. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  3135. memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
  3136. }
  3137. mgmt->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT;
  3138. mgmt->u.action.u.chan_switch.action_code = WLAN_ACTION_SPCT_CHL_SWITCH;
  3139. pos = skb_put(skb, 5);
  3140. *pos++ = WLAN_EID_CHANNEL_SWITCH; /* EID */
  3141. *pos++ = 3; /* IE length */
  3142. *pos++ = csa_settings->block_tx ? 1 : 0; /* CSA mode */
  3143. freq = csa_settings->chandef.chan->center_freq;
  3144. *pos++ = ieee80211_frequency_to_channel(freq); /* channel */
  3145. *pos++ = csa_settings->count; /* count */
  3146. if (csa_settings->chandef.width == NL80211_CHAN_WIDTH_40) {
  3147. enum nl80211_channel_type ch_type;
  3148. skb_put(skb, 3);
  3149. *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */
  3150. *pos++ = 1; /* IE length */
  3151. ch_type = cfg80211_get_chandef_type(&csa_settings->chandef);
  3152. if (ch_type == NL80211_CHAN_HT40PLUS)
  3153. *pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  3154. else
  3155. *pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  3156. }
  3157. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  3158. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  3159. skb_put(skb, 8);
  3160. *pos++ = WLAN_EID_CHAN_SWITCH_PARAM; /* EID */
  3161. *pos++ = 6; /* IE length */
  3162. *pos++ = sdata->u.mesh.mshcfg.dot11MeshTTL; /* Mesh TTL */
  3163. *pos = 0x00; /* Mesh Flag: Tx Restrict, Initiator, Reason */
  3164. *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
  3165. *pos++ |= csa_settings->block_tx ?
  3166. WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00;
  3167. put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); /* Reason Cd */
  3168. pos += 2;
  3169. put_unaligned_le16(ifmsh->pre_value, pos);/* Precedence Value */
  3170. pos += 2;
  3171. }
  3172. if (csa_settings->chandef.width == NL80211_CHAN_WIDTH_80 ||
  3173. csa_settings->chandef.width == NL80211_CHAN_WIDTH_80P80 ||
  3174. csa_settings->chandef.width == NL80211_CHAN_WIDTH_160) {
  3175. skb_put(skb, 5);
  3176. ieee80211_ie_build_wide_bw_cs(pos, &csa_settings->chandef);
  3177. }
  3178. ieee80211_tx_skb(sdata, skb);
  3179. return 0;
  3180. }
  3181. static bool
  3182. ieee80211_extend_noa_desc(struct ieee80211_noa_data *data, u32 tsf, int i)
  3183. {
  3184. s32 end = data->desc[i].start + data->desc[i].duration - (tsf + 1);
  3185. int skip;
  3186. if (end > 0)
  3187. return false;
  3188. /* One shot NOA */
  3189. if (data->count[i] == 1)
  3190. return false;
  3191. if (data->desc[i].interval == 0)
  3192. return false;
  3193. /* End time is in the past, check for repetitions */
  3194. skip = DIV_ROUND_UP(-end, data->desc[i].interval);
  3195. if (data->count[i] < 255) {
  3196. if (data->count[i] <= skip) {
  3197. data->count[i] = 0;
  3198. return false;
  3199. }
  3200. data->count[i] -= skip;
  3201. }
  3202. data->desc[i].start += skip * data->desc[i].interval;
  3203. return true;
  3204. }
  3205. static bool
  3206. ieee80211_extend_absent_time(struct ieee80211_noa_data *data, u32 tsf,
  3207. s32 *offset)
  3208. {
  3209. bool ret = false;
  3210. int i;
  3211. for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
  3212. s32 cur;
  3213. if (!data->count[i])
  3214. continue;
  3215. if (ieee80211_extend_noa_desc(data, tsf + *offset, i))
  3216. ret = true;
  3217. cur = data->desc[i].start - tsf;
  3218. if (cur > *offset)
  3219. continue;
  3220. cur = data->desc[i].start + data->desc[i].duration - tsf;
  3221. if (cur > *offset)
  3222. *offset = cur;
  3223. }
  3224. return ret;
  3225. }
  3226. static u32
  3227. ieee80211_get_noa_absent_time(struct ieee80211_noa_data *data, u32 tsf)
  3228. {
  3229. s32 offset = 0;
  3230. int tries = 0;
  3231. /*
  3232. * arbitrary limit, used to avoid infinite loops when combined NoA
  3233. * descriptors cover the full time period.
  3234. */
  3235. int max_tries = 5;
  3236. ieee80211_extend_absent_time(data, tsf, &offset);
  3237. do {
  3238. if (!ieee80211_extend_absent_time(data, tsf, &offset))
  3239. break;
  3240. tries++;
  3241. } while (tries < max_tries);
  3242. return offset;
  3243. }
  3244. void ieee80211_update_p2p_noa(struct ieee80211_noa_data *data, u32 tsf)
  3245. {
  3246. u32 next_offset = BIT(31) - 1;
  3247. int i;
  3248. data->absent = 0;
  3249. data->has_next_tsf = false;
  3250. for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
  3251. s32 start;
  3252. if (!data->count[i])
  3253. continue;
  3254. ieee80211_extend_noa_desc(data, tsf, i);
  3255. start = data->desc[i].start - tsf;
  3256. if (start <= 0)
  3257. data->absent |= BIT(i);
  3258. if (next_offset > start)
  3259. next_offset = start;
  3260. data->has_next_tsf = true;
  3261. }
  3262. if (data->absent)
  3263. next_offset = ieee80211_get_noa_absent_time(data, tsf);
  3264. data->next_tsf = tsf + next_offset;
  3265. }
  3266. EXPORT_SYMBOL(ieee80211_update_p2p_noa);
  3267. int ieee80211_parse_p2p_noa(const struct ieee80211_p2p_noa_attr *attr,
  3268. struct ieee80211_noa_data *data, u32 tsf)
  3269. {
  3270. int ret = 0;
  3271. int i;
  3272. memset(data, 0, sizeof(*data));
  3273. for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
  3274. const struct ieee80211_p2p_noa_desc *desc = &attr->desc[i];
  3275. if (!desc->count || !desc->duration)
  3276. continue;
  3277. data->count[i] = desc->count;
  3278. data->desc[i].start = le32_to_cpu(desc->start_time);
  3279. data->desc[i].duration = le32_to_cpu(desc->duration);
  3280. data->desc[i].interval = le32_to_cpu(desc->interval);
  3281. if (data->count[i] > 1 &&
  3282. data->desc[i].interval < data->desc[i].duration)
  3283. continue;
  3284. ieee80211_extend_noa_desc(data, tsf, i);
  3285. ret++;
  3286. }
  3287. if (ret)
  3288. ieee80211_update_p2p_noa(data, tsf);
  3289. return ret;
  3290. }
  3291. EXPORT_SYMBOL(ieee80211_parse_p2p_noa);
  3292. void ieee80211_recalc_dtim(struct ieee80211_local *local,
  3293. struct ieee80211_sub_if_data *sdata)
  3294. {
  3295. u64 tsf = drv_get_tsf(local, sdata);
  3296. u64 dtim_count = 0;
  3297. u32 beacon_int = sdata->vif.bss_conf.beacon_int * 1024;
  3298. u8 dtim_period = sdata->vif.bss_conf.dtim_period;
  3299. struct ps_data *ps;
  3300. u8 bcns_from_dtim;
  3301. if (tsf == -1ULL || !beacon_int || !dtim_period)
  3302. return;
  3303. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  3304. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  3305. if (!sdata->bss)
  3306. return;
  3307. ps = &sdata->bss->ps;
  3308. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  3309. ps = &sdata->u.mesh.ps;
  3310. } else {
  3311. return;
  3312. }
  3313. /*
  3314. * actually finds last dtim_count, mac80211 will update in
  3315. * __beacon_add_tim().
  3316. * dtim_count = dtim_period - (tsf / bcn_int) % dtim_period
  3317. */
  3318. do_div(tsf, beacon_int);
  3319. bcns_from_dtim = do_div(tsf, dtim_period);
  3320. /* just had a DTIM */
  3321. if (!bcns_from_dtim)
  3322. dtim_count = 0;
  3323. else
  3324. dtim_count = dtim_period - bcns_from_dtim;
  3325. ps->dtim_count = dtim_count;
  3326. }
  3327. static u8 ieee80211_chanctx_radar_detect(struct ieee80211_local *local,
  3328. struct ieee80211_chanctx *ctx)
  3329. {
  3330. struct ieee80211_link_data *link;
  3331. u8 radar_detect = 0;
  3332. lockdep_assert_wiphy(local->hw.wiphy);
  3333. if (WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED))
  3334. return 0;
  3335. list_for_each_entry(link, &ctx->reserved_links, reserved_chanctx_list)
  3336. if (link->reserved_radar_required)
  3337. radar_detect |= BIT(link->reserved.oper.width);
  3338. /*
  3339. * An in-place reservation context should not have any assigned vifs
  3340. * until it replaces the other context.
  3341. */
  3342. WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER &&
  3343. !list_empty(&ctx->assigned_links));
  3344. list_for_each_entry(link, &ctx->assigned_links, assigned_chanctx_list) {
  3345. if (!link->radar_required)
  3346. continue;
  3347. radar_detect |=
  3348. BIT(link->conf->chanreq.oper.width);
  3349. }
  3350. return radar_detect;
  3351. }
  3352. static u32
  3353. __ieee80211_get_radio_mask(struct ieee80211_sub_if_data *sdata)
  3354. {
  3355. struct ieee80211_bss_conf *link_conf;
  3356. struct ieee80211_chanctx_conf *conf;
  3357. unsigned int link_id;
  3358. u32 mask = 0;
  3359. for_each_vif_active_link(&sdata->vif, link_conf, link_id) {
  3360. conf = sdata_dereference(link_conf->chanctx_conf, sdata);
  3361. if (!conf || conf->radio_idx < 0)
  3362. continue;
  3363. mask |= BIT(conf->radio_idx);
  3364. }
  3365. return mask;
  3366. }
  3367. u32 ieee80211_get_radio_mask(struct wiphy *wiphy, struct net_device *dev)
  3368. {
  3369. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3370. return __ieee80211_get_radio_mask(sdata);
  3371. }
  3372. static bool
  3373. ieee80211_sdata_uses_radio(struct ieee80211_sub_if_data *sdata, int radio_idx)
  3374. {
  3375. if (radio_idx < 0)
  3376. return true;
  3377. return __ieee80211_get_radio_mask(sdata) & BIT(radio_idx);
  3378. }
  3379. static int
  3380. ieee80211_fill_ifcomb_params(struct ieee80211_local *local,
  3381. struct iface_combination_params *params,
  3382. const struct cfg80211_chan_def *chandef,
  3383. struct ieee80211_sub_if_data *sdata)
  3384. {
  3385. struct ieee80211_sub_if_data *sdata_iter;
  3386. struct ieee80211_chanctx *ctx;
  3387. int total = !!sdata;
  3388. list_for_each_entry(ctx, &local->chanctx_list, list) {
  3389. if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
  3390. continue;
  3391. if (params->radio_idx >= 0 &&
  3392. ctx->conf.radio_idx != params->radio_idx)
  3393. continue;
  3394. params->radar_detect |=
  3395. ieee80211_chanctx_radar_detect(local, ctx);
  3396. if (chandef && ctx->mode != IEEE80211_CHANCTX_EXCLUSIVE &&
  3397. cfg80211_chandef_compatible(chandef, &ctx->conf.def))
  3398. continue;
  3399. params->num_different_channels++;
  3400. }
  3401. list_for_each_entry(sdata_iter, &local->interfaces, list) {
  3402. struct wireless_dev *wdev_iter;
  3403. wdev_iter = &sdata_iter->wdev;
  3404. if (sdata_iter == sdata ||
  3405. !ieee80211_sdata_running(sdata_iter) ||
  3406. cfg80211_iftype_allowed(local->hw.wiphy,
  3407. wdev_iter->iftype, 0, 1))
  3408. continue;
  3409. if (!ieee80211_sdata_uses_radio(sdata_iter, params->radio_idx))
  3410. continue;
  3411. params->iftype_num[wdev_iter->iftype]++;
  3412. total++;
  3413. }
  3414. return total;
  3415. }
  3416. int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
  3417. const struct cfg80211_chan_def *chandef,
  3418. enum ieee80211_chanctx_mode chanmode,
  3419. u8 radar_detect, int radio_idx)
  3420. {
  3421. bool shared = chanmode == IEEE80211_CHANCTX_SHARED;
  3422. struct ieee80211_local *local = sdata->local;
  3423. enum nl80211_iftype iftype = sdata->wdev.iftype;
  3424. struct iface_combination_params params = {
  3425. .radar_detect = radar_detect,
  3426. .radio_idx = radio_idx,
  3427. };
  3428. int total;
  3429. lockdep_assert_wiphy(local->hw.wiphy);
  3430. if (WARN_ON(hweight32(radar_detect) > 1))
  3431. return -EINVAL;
  3432. if (WARN_ON(chandef && chanmode == IEEE80211_CHANCTX_SHARED &&
  3433. !chandef->chan))
  3434. return -EINVAL;
  3435. if (WARN_ON(iftype >= NUM_NL80211_IFTYPES))
  3436. return -EINVAL;
  3437. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  3438. sdata->vif.type == NL80211_IFTYPE_MESH_POINT) {
  3439. /*
  3440. * always passing this is harmless, since it'll be the
  3441. * same value that cfg80211 finds if it finds the same
  3442. * interface ... and that's always allowed
  3443. */
  3444. params.new_beacon_int = sdata->vif.bss_conf.beacon_int;
  3445. }
  3446. /* Always allow software iftypes */
  3447. if (cfg80211_iftype_allowed(local->hw.wiphy, iftype, 0, 1)) {
  3448. if (radar_detect)
  3449. return -EINVAL;
  3450. return 0;
  3451. }
  3452. if (chandef)
  3453. params.num_different_channels = 1;
  3454. if (iftype != NL80211_IFTYPE_UNSPECIFIED)
  3455. params.iftype_num[iftype] = 1;
  3456. total = ieee80211_fill_ifcomb_params(local, &params,
  3457. shared ? chandef : NULL,
  3458. sdata);
  3459. if (total == 1 && !params.radar_detect)
  3460. return 0;
  3461. return cfg80211_check_combinations(local->hw.wiphy, &params);
  3462. }
  3463. static void
  3464. ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c,
  3465. void *data)
  3466. {
  3467. u32 *max_num_different_channels = data;
  3468. *max_num_different_channels = max(*max_num_different_channels,
  3469. c->num_different_channels);
  3470. }
  3471. int ieee80211_max_num_channels(struct ieee80211_local *local, int radio_idx)
  3472. {
  3473. u32 max_num_different_channels = 1;
  3474. int err;
  3475. struct iface_combination_params params = {
  3476. .radio_idx = radio_idx,
  3477. };
  3478. lockdep_assert_wiphy(local->hw.wiphy);
  3479. ieee80211_fill_ifcomb_params(local, &params, NULL, NULL);
  3480. err = cfg80211_iter_combinations(local->hw.wiphy, &params,
  3481. ieee80211_iter_max_chans,
  3482. &max_num_different_channels);
  3483. if (err < 0)
  3484. return err;
  3485. return max_num_different_channels;
  3486. }
  3487. void ieee80211_add_s1g_capab_ie(struct ieee80211_sub_if_data *sdata,
  3488. struct ieee80211_sta_s1g_cap *caps,
  3489. struct sk_buff *skb)
  3490. {
  3491. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3492. struct ieee80211_s1g_cap s1g_capab;
  3493. u8 *pos;
  3494. int i;
  3495. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  3496. return;
  3497. if (!caps->s1g)
  3498. return;
  3499. memcpy(s1g_capab.capab_info, caps->cap, sizeof(caps->cap));
  3500. memcpy(s1g_capab.supp_mcs_nss, caps->nss_mcs, sizeof(caps->nss_mcs));
  3501. /* override the capability info */
  3502. for (i = 0; i < sizeof(ifmgd->s1g_capa.capab_info); i++) {
  3503. u8 mask = ifmgd->s1g_capa_mask.capab_info[i];
  3504. s1g_capab.capab_info[i] &= ~mask;
  3505. s1g_capab.capab_info[i] |= ifmgd->s1g_capa.capab_info[i] & mask;
  3506. }
  3507. /* then MCS and NSS set */
  3508. for (i = 0; i < sizeof(ifmgd->s1g_capa.supp_mcs_nss); i++) {
  3509. u8 mask = ifmgd->s1g_capa_mask.supp_mcs_nss[i];
  3510. s1g_capab.supp_mcs_nss[i] &= ~mask;
  3511. s1g_capab.supp_mcs_nss[i] |=
  3512. ifmgd->s1g_capa.supp_mcs_nss[i] & mask;
  3513. }
  3514. pos = skb_put(skb, 2 + sizeof(s1g_capab));
  3515. *pos++ = WLAN_EID_S1G_CAPABILITIES;
  3516. *pos++ = sizeof(s1g_capab);
  3517. memcpy(pos, &s1g_capab, sizeof(s1g_capab));
  3518. }
  3519. void ieee80211_add_aid_request_ie(struct ieee80211_sub_if_data *sdata,
  3520. struct sk_buff *skb)
  3521. {
  3522. u8 *pos = skb_put(skb, 3);
  3523. *pos++ = WLAN_EID_AID_REQUEST;
  3524. *pos++ = 1;
  3525. *pos++ = 0;
  3526. }
  3527. u8 *ieee80211_add_wmm_info_ie(u8 *buf, u8 qosinfo)
  3528. {
  3529. *buf++ = WLAN_EID_VENDOR_SPECIFIC;
  3530. *buf++ = 7; /* len */
  3531. *buf++ = 0x00; /* Microsoft OUI 00:50:F2 */
  3532. *buf++ = 0x50;
  3533. *buf++ = 0xf2;
  3534. *buf++ = 2; /* WME */
  3535. *buf++ = 0; /* WME info */
  3536. *buf++ = 1; /* WME ver */
  3537. *buf++ = qosinfo; /* U-APSD no in use */
  3538. return buf;
  3539. }
  3540. void ieee80211_txq_get_depth(struct ieee80211_txq *txq,
  3541. unsigned long *frame_cnt,
  3542. unsigned long *byte_cnt)
  3543. {
  3544. struct txq_info *txqi = to_txq_info(txq);
  3545. u32 frag_cnt = 0, frag_bytes = 0;
  3546. struct sk_buff *skb;
  3547. skb_queue_walk(&txqi->frags, skb) {
  3548. frag_cnt++;
  3549. frag_bytes += skb->len;
  3550. }
  3551. if (frame_cnt)
  3552. *frame_cnt = txqi->tin.backlog_packets + frag_cnt;
  3553. if (byte_cnt)
  3554. *byte_cnt = txqi->tin.backlog_bytes + frag_bytes;
  3555. }
  3556. EXPORT_SYMBOL(ieee80211_txq_get_depth);
  3557. const u8 ieee80211_ac_to_qos_mask[IEEE80211_NUM_ACS] = {
  3558. IEEE80211_WMM_IE_STA_QOSINFO_AC_VO,
  3559. IEEE80211_WMM_IE_STA_QOSINFO_AC_VI,
  3560. IEEE80211_WMM_IE_STA_QOSINFO_AC_BE,
  3561. IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
  3562. };
  3563. u16 ieee80211_encode_usf(int listen_interval)
  3564. {
  3565. static const int listen_int_usf[] = { 1, 10, 1000, 10000 };
  3566. u16 ui, usf = 0;
  3567. /* find greatest USF */
  3568. while (usf < IEEE80211_MAX_USF) {
  3569. if (listen_interval % listen_int_usf[usf + 1])
  3570. break;
  3571. usf += 1;
  3572. }
  3573. ui = listen_interval / listen_int_usf[usf];
  3574. /* error if there is a remainder. Should've been checked by user */
  3575. WARN_ON_ONCE(ui > IEEE80211_MAX_UI);
  3576. listen_interval = FIELD_PREP(LISTEN_INT_USF, usf) |
  3577. FIELD_PREP(LISTEN_INT_UI, ui);
  3578. return (u16) listen_interval;
  3579. }
  3580. /* this may return more than ieee80211_put_eht_cap() will need */
  3581. u8 ieee80211_ie_len_eht_cap(struct ieee80211_sub_if_data *sdata)
  3582. {
  3583. const struct ieee80211_sta_he_cap *he_cap;
  3584. const struct ieee80211_sta_eht_cap *eht_cap;
  3585. struct ieee80211_supported_band *sband;
  3586. bool is_ap;
  3587. u8 n;
  3588. sband = ieee80211_get_sband(sdata);
  3589. if (!sband)
  3590. return 0;
  3591. he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  3592. eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
  3593. if (!he_cap || !eht_cap)
  3594. return 0;
  3595. is_ap = sdata->vif.type == NL80211_IFTYPE_AP;
  3596. n = ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
  3597. &eht_cap->eht_cap_elem,
  3598. is_ap);
  3599. return 2 + 1 +
  3600. sizeof(eht_cap->eht_cap_elem) + n +
  3601. ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
  3602. eht_cap->eht_cap_elem.phy_cap_info);
  3603. return 0;
  3604. }
  3605. int ieee80211_put_eht_cap(struct sk_buff *skb,
  3606. struct ieee80211_sub_if_data *sdata,
  3607. const struct ieee80211_supported_band *sband,
  3608. const struct ieee80211_conn_settings *conn)
  3609. {
  3610. const struct ieee80211_sta_he_cap *he_cap =
  3611. ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  3612. const struct ieee80211_sta_eht_cap *eht_cap =
  3613. ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
  3614. bool for_ap = sdata->vif.type == NL80211_IFTYPE_AP;
  3615. struct ieee80211_eht_cap_elem_fixed fixed;
  3616. struct ieee80211_he_cap_elem he;
  3617. u8 mcs_nss_len, ppet_len;
  3618. u8 orig_mcs_nss_len;
  3619. u8 ie_len;
  3620. if (!conn)
  3621. conn = &ieee80211_conn_settings_unlimited;
  3622. /* Make sure we have place for the IE */
  3623. if (!he_cap || !eht_cap)
  3624. return 0;
  3625. orig_mcs_nss_len = ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
  3626. &eht_cap->eht_cap_elem,
  3627. for_ap);
  3628. ieee80211_get_adjusted_he_cap(conn, he_cap, &he);
  3629. fixed = eht_cap->eht_cap_elem;
  3630. if (conn->bw_limit < IEEE80211_CONN_BW_LIMIT_80)
  3631. fixed.phy_cap_info[6] &=
  3632. ~IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_80MHZ;
  3633. if (conn->bw_limit < IEEE80211_CONN_BW_LIMIT_160) {
  3634. fixed.phy_cap_info[1] &=
  3635. ~IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK;
  3636. fixed.phy_cap_info[2] &=
  3637. ~IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK;
  3638. fixed.phy_cap_info[6] &=
  3639. ~IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_160MHZ;
  3640. }
  3641. if (conn->bw_limit < IEEE80211_CONN_BW_LIMIT_320) {
  3642. fixed.phy_cap_info[0] &=
  3643. ~IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ;
  3644. fixed.phy_cap_info[1] &=
  3645. ~IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK;
  3646. fixed.phy_cap_info[2] &=
  3647. ~IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK;
  3648. fixed.phy_cap_info[6] &=
  3649. ~IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_320MHZ;
  3650. }
  3651. if (conn->bw_limit == IEEE80211_CONN_BW_LIMIT_20)
  3652. fixed.phy_cap_info[0] &=
  3653. ~IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ;
  3654. mcs_nss_len = ieee80211_eht_mcs_nss_size(&he, &fixed, for_ap);
  3655. ppet_len = ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
  3656. fixed.phy_cap_info);
  3657. ie_len = 2 + 1 + sizeof(eht_cap->eht_cap_elem) + mcs_nss_len + ppet_len;
  3658. if (skb_tailroom(skb) < ie_len)
  3659. return -ENOBUFS;
  3660. skb_put_u8(skb, WLAN_EID_EXTENSION);
  3661. skb_put_u8(skb, ie_len - 2);
  3662. skb_put_u8(skb, WLAN_EID_EXT_EHT_CAPABILITY);
  3663. skb_put_data(skb, &fixed, sizeof(fixed));
  3664. if (mcs_nss_len == 4 && orig_mcs_nss_len != 4) {
  3665. /*
  3666. * If the (non-AP) STA became 20 MHz only, then convert from
  3667. * <=80 to 20-MHz-only format, where MCSes are indicated in
  3668. * the groups 0-7, 8-9, 10-11, 12-13 rather than just 0-9,
  3669. * 10-11, 12-13. Thus, use 0-9 for 0-7 and 8-9.
  3670. */
  3671. skb_put_u8(skb, eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_mcs9_max_nss);
  3672. skb_put_u8(skb, eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_mcs9_max_nss);
  3673. skb_put_u8(skb, eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_mcs11_max_nss);
  3674. skb_put_u8(skb, eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_mcs13_max_nss);
  3675. } else {
  3676. skb_put_data(skb, &eht_cap->eht_mcs_nss_supp, mcs_nss_len);
  3677. }
  3678. if (ppet_len)
  3679. skb_put_data(skb, &eht_cap->eht_ppe_thres, ppet_len);
  3680. return 0;
  3681. }
  3682. const char *ieee80211_conn_mode_str(enum ieee80211_conn_mode mode)
  3683. {
  3684. static const char * const modes[] = {
  3685. [IEEE80211_CONN_MODE_S1G] = "S1G",
  3686. [IEEE80211_CONN_MODE_LEGACY] = "legacy",
  3687. [IEEE80211_CONN_MODE_HT] = "HT",
  3688. [IEEE80211_CONN_MODE_VHT] = "VHT",
  3689. [IEEE80211_CONN_MODE_HE] = "HE",
  3690. [IEEE80211_CONN_MODE_EHT] = "EHT",
  3691. };
  3692. if (WARN_ON(mode >= ARRAY_SIZE(modes)))
  3693. return "<out of range>";
  3694. return modes[mode] ?: "<missing string>";
  3695. }
  3696. enum ieee80211_conn_bw_limit
  3697. ieee80211_min_bw_limit_from_chandef(struct cfg80211_chan_def *chandef)
  3698. {
  3699. switch (chandef->width) {
  3700. case NL80211_CHAN_WIDTH_20_NOHT:
  3701. case NL80211_CHAN_WIDTH_20:
  3702. return IEEE80211_CONN_BW_LIMIT_20;
  3703. case NL80211_CHAN_WIDTH_40:
  3704. return IEEE80211_CONN_BW_LIMIT_40;
  3705. case NL80211_CHAN_WIDTH_80:
  3706. return IEEE80211_CONN_BW_LIMIT_80;
  3707. case NL80211_CHAN_WIDTH_80P80:
  3708. case NL80211_CHAN_WIDTH_160:
  3709. return IEEE80211_CONN_BW_LIMIT_160;
  3710. case NL80211_CHAN_WIDTH_320:
  3711. return IEEE80211_CONN_BW_LIMIT_320;
  3712. default:
  3713. WARN(1, "unhandled chandef width %d\n", chandef->width);
  3714. return IEEE80211_CONN_BW_LIMIT_20;
  3715. }
  3716. }
  3717. void ieee80211_clear_tpe(struct ieee80211_parsed_tpe *tpe)
  3718. {
  3719. for (int i = 0; i < 2; i++) {
  3720. tpe->max_local[i].valid = false;
  3721. memset(tpe->max_local[i].power,
  3722. IEEE80211_TPE_MAX_TX_PWR_NO_CONSTRAINT,
  3723. sizeof(tpe->max_local[i].power));
  3724. tpe->max_reg_client[i].valid = false;
  3725. memset(tpe->max_reg_client[i].power,
  3726. IEEE80211_TPE_MAX_TX_PWR_NO_CONSTRAINT,
  3727. sizeof(tpe->max_reg_client[i].power));
  3728. tpe->psd_local[i].valid = false;
  3729. memset(tpe->psd_local[i].power,
  3730. IEEE80211_TPE_PSD_NO_LIMIT,
  3731. sizeof(tpe->psd_local[i].power));
  3732. tpe->psd_reg_client[i].valid = false;
  3733. memset(tpe->psd_reg_client[i].power,
  3734. IEEE80211_TPE_PSD_NO_LIMIT,
  3735. sizeof(tpe->psd_reg_client[i].power));
  3736. }
  3737. }