mlme.c 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274
  1. /*
  2. * BSS client mode implementation
  3. * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright 2004, Instant802 Networks, Inc.
  5. * Copyright 2005, Devicescape Software, Inc.
  6. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/if_ether.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/rtnetlink.h>
  20. #include <linux/pm_qos.h>
  21. #include <linux/crc32.h>
  22. #include <linux/slab.h>
  23. #include <linux/export.h>
  24. #include <net/mac80211.h>
  25. #include <asm/unaligned.h>
  26. #include "ieee80211_i.h"
  27. #include "driver-ops.h"
  28. #include "rate.h"
  29. #include "led.h"
  30. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  31. #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
  32. #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
  33. #define IEEE80211_AUTH_MAX_TRIES 3
  34. #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
  35. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  36. #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
  37. #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
  38. #define IEEE80211_ASSOC_MAX_TRIES 3
  39. static int max_nullfunc_tries = 2;
  40. module_param(max_nullfunc_tries, int, 0644);
  41. MODULE_PARM_DESC(max_nullfunc_tries,
  42. "Maximum nullfunc tx tries before disconnecting (reason 4).");
  43. static int max_probe_tries = 5;
  44. module_param(max_probe_tries, int, 0644);
  45. MODULE_PARM_DESC(max_probe_tries,
  46. "Maximum probe tries before disconnecting (reason 4).");
  47. /*
  48. * Beacon loss timeout is calculated as N frames times the
  49. * advertised beacon interval. This may need to be somewhat
  50. * higher than what hardware might detect to account for
  51. * delays in the host processing frames. But since we also
  52. * probe on beacon miss before declaring the connection lost
  53. * default to what we want.
  54. */
  55. static int beacon_loss_count = 7;
  56. module_param(beacon_loss_count, int, 0644);
  57. MODULE_PARM_DESC(beacon_loss_count,
  58. "Number of beacon intervals before we decide beacon was lost.");
  59. /*
  60. * Time the connection can be idle before we probe
  61. * it to see if we can still talk to the AP.
  62. */
  63. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  64. /*
  65. * Time we wait for a probe response after sending
  66. * a probe request because of beacon loss or for
  67. * checking the connection still works.
  68. */
  69. static int probe_wait_ms = 500;
  70. module_param(probe_wait_ms, int, 0644);
  71. MODULE_PARM_DESC(probe_wait_ms,
  72. "Maximum time(ms) to wait for probe response"
  73. " before disconnecting (reason 4).");
  74. /*
  75. * Weight given to the latest Beacon frame when calculating average signal
  76. * strength for Beacon frames received in the current BSS. This must be
  77. * between 1 and 15.
  78. */
  79. #define IEEE80211_SIGNAL_AVE_WEIGHT 3
  80. /*
  81. * How many Beacon frames need to have been used in average signal strength
  82. * before starting to indicate signal change events.
  83. */
  84. #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
  85. /*
  86. * We can have multiple work items (and connection probing)
  87. * scheduling this timer, but we need to take care to only
  88. * reschedule it when it should fire _earlier_ than it was
  89. * asked for before, or if it's not pending right now. This
  90. * function ensures that. Note that it then is required to
  91. * run this function for all timeouts after the first one
  92. * has happened -- the work that runs from this timer will
  93. * do that.
  94. */
  95. static void run_again(struct ieee80211_sub_if_data *sdata,
  96. unsigned long timeout)
  97. {
  98. sdata_assert_lock(sdata);
  99. if (!timer_pending(&sdata->u.mgd.timer) ||
  100. time_before(timeout, sdata->u.mgd.timer.expires))
  101. mod_timer(&sdata->u.mgd.timer, timeout);
  102. }
  103. void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
  104. {
  105. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  106. return;
  107. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  108. return;
  109. mod_timer(&sdata->u.mgd.bcn_mon_timer,
  110. round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
  111. }
  112. void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
  113. {
  114. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  115. if (unlikely(!sdata->u.mgd.associated))
  116. return;
  117. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  118. return;
  119. mod_timer(&sdata->u.mgd.conn_mon_timer,
  120. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  121. ifmgd->probe_send_count = 0;
  122. }
  123. static int ecw2cw(int ecw)
  124. {
  125. return (1 << ecw) - 1;
  126. }
  127. static u32
  128. ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
  129. struct ieee80211_supported_band *sband,
  130. struct ieee80211_channel *channel,
  131. const struct ieee80211_ht_operation *ht_oper,
  132. const struct ieee80211_vht_operation *vht_oper,
  133. struct cfg80211_chan_def *chandef, bool tracking)
  134. {
  135. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  136. struct cfg80211_chan_def vht_chandef;
  137. u32 ht_cfreq, ret;
  138. chandef->chan = channel;
  139. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  140. chandef->center_freq1 = channel->center_freq;
  141. chandef->center_freq2 = 0;
  142. if (!ht_oper || !sband->ht_cap.ht_supported) {
  143. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  144. goto out;
  145. }
  146. chandef->width = NL80211_CHAN_WIDTH_20;
  147. ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
  148. channel->band);
  149. /* check that channel matches the right operating channel */
  150. if (!tracking && channel->center_freq != ht_cfreq) {
  151. /*
  152. * It's possible that some APs are confused here;
  153. * Netgear WNDR3700 sometimes reports 4 higher than
  154. * the actual channel in association responses, but
  155. * since we look at probe response/beacon data here
  156. * it should be OK.
  157. */
  158. sdata_info(sdata,
  159. "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
  160. channel->center_freq, ht_cfreq,
  161. ht_oper->primary_chan, channel->band);
  162. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  163. goto out;
  164. }
  165. /* check 40 MHz support, if we have it */
  166. if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  167. switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  168. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  169. chandef->width = NL80211_CHAN_WIDTH_40;
  170. chandef->center_freq1 += 10;
  171. break;
  172. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  173. chandef->width = NL80211_CHAN_WIDTH_40;
  174. chandef->center_freq1 -= 10;
  175. break;
  176. }
  177. } else {
  178. /* 40 MHz (and 80 MHz) must be supported for VHT */
  179. ret = IEEE80211_STA_DISABLE_VHT;
  180. /* also mark 40 MHz disabled */
  181. ret |= IEEE80211_STA_DISABLE_40MHZ;
  182. goto out;
  183. }
  184. if (!vht_oper || !sband->vht_cap.vht_supported) {
  185. ret = IEEE80211_STA_DISABLE_VHT;
  186. goto out;
  187. }
  188. vht_chandef.chan = channel;
  189. vht_chandef.center_freq1 =
  190. ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
  191. channel->band);
  192. vht_chandef.center_freq2 = 0;
  193. switch (vht_oper->chan_width) {
  194. case IEEE80211_VHT_CHANWIDTH_USE_HT:
  195. vht_chandef.width = chandef->width;
  196. break;
  197. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  198. vht_chandef.width = NL80211_CHAN_WIDTH_80;
  199. break;
  200. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  201. vht_chandef.width = NL80211_CHAN_WIDTH_160;
  202. break;
  203. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  204. vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
  205. vht_chandef.center_freq2 =
  206. ieee80211_channel_to_frequency(
  207. vht_oper->center_freq_seg2_idx,
  208. channel->band);
  209. break;
  210. default:
  211. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  212. sdata_info(sdata,
  213. "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
  214. vht_oper->chan_width);
  215. ret = IEEE80211_STA_DISABLE_VHT;
  216. goto out;
  217. }
  218. if (!cfg80211_chandef_valid(&vht_chandef)) {
  219. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  220. sdata_info(sdata,
  221. "AP VHT information is invalid, disable VHT\n");
  222. ret = IEEE80211_STA_DISABLE_VHT;
  223. goto out;
  224. }
  225. if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
  226. ret = 0;
  227. goto out;
  228. }
  229. if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
  230. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  231. sdata_info(sdata,
  232. "AP VHT information doesn't match HT, disable VHT\n");
  233. ret = IEEE80211_STA_DISABLE_VHT;
  234. goto out;
  235. }
  236. *chandef = vht_chandef;
  237. ret = 0;
  238. out:
  239. /* don't print the message below for VHT mismatch if VHT is disabled */
  240. if (ret & IEEE80211_STA_DISABLE_VHT)
  241. vht_chandef = *chandef;
  242. /*
  243. * Ignore the DISABLED flag when we're already connected and only
  244. * tracking the APs beacon for bandwidth changes - otherwise we
  245. * might get disconnected here if we connect to an AP, update our
  246. * regulatory information based on the AP's country IE and the
  247. * information we have is wrong/outdated and disables the channel
  248. * that we're actually using for the connection to the AP.
  249. */
  250. while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
  251. tracking ? 0 :
  252. IEEE80211_CHAN_DISABLED)) {
  253. if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
  254. ret = IEEE80211_STA_DISABLE_HT |
  255. IEEE80211_STA_DISABLE_VHT;
  256. break;
  257. }
  258. ret |= ieee80211_chandef_downgrade(chandef);
  259. }
  260. if (chandef->width != vht_chandef.width && !tracking)
  261. sdata_info(sdata,
  262. "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
  263. WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
  264. return ret;
  265. }
  266. static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
  267. struct sta_info *sta,
  268. const struct ieee80211_ht_operation *ht_oper,
  269. const struct ieee80211_vht_operation *vht_oper,
  270. const u8 *bssid, u32 *changed)
  271. {
  272. struct ieee80211_local *local = sdata->local;
  273. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  274. struct ieee80211_supported_band *sband;
  275. struct ieee80211_channel *chan;
  276. struct cfg80211_chan_def chandef;
  277. u16 ht_opmode;
  278. u32 flags;
  279. enum ieee80211_sta_rx_bandwidth new_sta_bw;
  280. int ret;
  281. /* if HT was/is disabled, don't track any bandwidth changes */
  282. if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
  283. return 0;
  284. /* don't check VHT if we associated as non-VHT station */
  285. if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
  286. vht_oper = NULL;
  287. if (WARN_ON_ONCE(!sta))
  288. return -EINVAL;
  289. chan = sdata->vif.bss_conf.chandef.chan;
  290. sband = local->hw.wiphy->bands[chan->band];
  291. /* calculate new channel (type) based on HT/VHT operation IEs */
  292. flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
  293. vht_oper, &chandef, true);
  294. /*
  295. * Downgrade the new channel if we associated with restricted
  296. * capabilities. For example, if we associated as a 20 MHz STA
  297. * to a 40 MHz AP (due to regulatory, capabilities or config
  298. * reasons) then switching to a 40 MHz channel now won't do us
  299. * any good -- we couldn't use it with the AP.
  300. */
  301. if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
  302. chandef.width == NL80211_CHAN_WIDTH_80P80)
  303. flags |= ieee80211_chandef_downgrade(&chandef);
  304. if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
  305. chandef.width == NL80211_CHAN_WIDTH_160)
  306. flags |= ieee80211_chandef_downgrade(&chandef);
  307. if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
  308. chandef.width > NL80211_CHAN_WIDTH_20)
  309. flags |= ieee80211_chandef_downgrade(&chandef);
  310. if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
  311. return 0;
  312. sdata_info(sdata,
  313. "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
  314. ifmgd->bssid, chandef.chan->center_freq, chandef.width,
  315. chandef.center_freq1, chandef.center_freq2);
  316. if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
  317. IEEE80211_STA_DISABLE_VHT |
  318. IEEE80211_STA_DISABLE_40MHZ |
  319. IEEE80211_STA_DISABLE_80P80MHZ |
  320. IEEE80211_STA_DISABLE_160MHZ)) ||
  321. !cfg80211_chandef_valid(&chandef)) {
  322. sdata_info(sdata,
  323. "AP %pM changed bandwidth in a way we can't support - disconnect\n",
  324. ifmgd->bssid);
  325. return -EINVAL;
  326. }
  327. switch (chandef.width) {
  328. case NL80211_CHAN_WIDTH_20_NOHT:
  329. case NL80211_CHAN_WIDTH_20:
  330. new_sta_bw = IEEE80211_STA_RX_BW_20;
  331. break;
  332. case NL80211_CHAN_WIDTH_40:
  333. new_sta_bw = IEEE80211_STA_RX_BW_40;
  334. break;
  335. case NL80211_CHAN_WIDTH_80:
  336. new_sta_bw = IEEE80211_STA_RX_BW_80;
  337. break;
  338. case NL80211_CHAN_WIDTH_80P80:
  339. case NL80211_CHAN_WIDTH_160:
  340. new_sta_bw = IEEE80211_STA_RX_BW_160;
  341. break;
  342. default:
  343. return -EINVAL;
  344. }
  345. if (new_sta_bw > sta->cur_max_bandwidth)
  346. new_sta_bw = sta->cur_max_bandwidth;
  347. if (new_sta_bw < sta->sta.bandwidth) {
  348. sta->sta.bandwidth = new_sta_bw;
  349. rate_control_rate_update(local, sband, sta,
  350. IEEE80211_RC_BW_CHANGED);
  351. }
  352. ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
  353. if (ret) {
  354. sdata_info(sdata,
  355. "AP %pM changed bandwidth to incompatible one - disconnect\n",
  356. ifmgd->bssid);
  357. return ret;
  358. }
  359. if (new_sta_bw > sta->sta.bandwidth) {
  360. sta->sta.bandwidth = new_sta_bw;
  361. rate_control_rate_update(local, sband, sta,
  362. IEEE80211_RC_BW_CHANGED);
  363. }
  364. ht_opmode = le16_to_cpu(ht_oper->operation_mode);
  365. /* if bss configuration changed store the new one */
  366. if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
  367. *changed |= BSS_CHANGED_HT;
  368. sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
  369. }
  370. return 0;
  371. }
  372. /* frame sending functions */
  373. static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
  374. struct sk_buff *skb, u8 ap_ht_param,
  375. struct ieee80211_supported_band *sband,
  376. struct ieee80211_channel *channel,
  377. enum ieee80211_smps_mode smps)
  378. {
  379. u8 *pos;
  380. u32 flags = channel->flags;
  381. u16 cap;
  382. struct ieee80211_sta_ht_cap ht_cap;
  383. BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
  384. memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
  385. ieee80211_apply_htcap_overrides(sdata, &ht_cap);
  386. /* determine capability flags */
  387. cap = ht_cap.cap;
  388. switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  389. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  390. if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
  391. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  392. cap &= ~IEEE80211_HT_CAP_SGI_40;
  393. }
  394. break;
  395. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  396. if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
  397. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  398. cap &= ~IEEE80211_HT_CAP_SGI_40;
  399. }
  400. break;
  401. }
  402. /*
  403. * If 40 MHz was disabled associate as though we weren't
  404. * capable of 40 MHz -- some broken APs will never fall
  405. * back to trying to transmit in 20 MHz.
  406. */
  407. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
  408. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  409. cap &= ~IEEE80211_HT_CAP_SGI_40;
  410. }
  411. /* set SM PS mode properly */
  412. cap &= ~IEEE80211_HT_CAP_SM_PS;
  413. switch (smps) {
  414. case IEEE80211_SMPS_AUTOMATIC:
  415. case IEEE80211_SMPS_NUM_MODES:
  416. WARN_ON(1);
  417. case IEEE80211_SMPS_OFF:
  418. cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  419. IEEE80211_HT_CAP_SM_PS_SHIFT;
  420. break;
  421. case IEEE80211_SMPS_STATIC:
  422. cap |= WLAN_HT_CAP_SM_PS_STATIC <<
  423. IEEE80211_HT_CAP_SM_PS_SHIFT;
  424. break;
  425. case IEEE80211_SMPS_DYNAMIC:
  426. cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
  427. IEEE80211_HT_CAP_SM_PS_SHIFT;
  428. break;
  429. }
  430. /* reserve and fill IE */
  431. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  432. ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
  433. }
  434. static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
  435. struct sk_buff *skb,
  436. struct ieee80211_supported_band *sband,
  437. struct ieee80211_vht_cap *ap_vht_cap)
  438. {
  439. u8 *pos;
  440. u32 cap;
  441. struct ieee80211_sta_vht_cap vht_cap;
  442. BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
  443. memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
  444. ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
  445. /* determine capability flags */
  446. cap = vht_cap.cap;
  447. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
  448. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  449. cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  450. }
  451. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
  452. cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
  453. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  454. }
  455. /*
  456. * Some APs apparently get confused if our capabilities are better
  457. * than theirs, so restrict what we advertise in the assoc request.
  458. */
  459. if (!(ap_vht_cap->vht_cap_info &
  460. cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
  461. cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
  462. /* reserve and fill IE */
  463. pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
  464. ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
  465. }
  466. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
  467. {
  468. struct ieee80211_local *local = sdata->local;
  469. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  470. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  471. struct sk_buff *skb;
  472. struct ieee80211_mgmt *mgmt;
  473. u8 *pos, qos_info;
  474. size_t offset = 0, noffset;
  475. int i, count, rates_len, supp_rates_len, shift;
  476. u16 capab;
  477. struct ieee80211_supported_band *sband;
  478. struct ieee80211_chanctx_conf *chanctx_conf;
  479. struct ieee80211_channel *chan;
  480. u32 rate_flags, rates = 0;
  481. sdata_assert_lock(sdata);
  482. rcu_read_lock();
  483. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  484. if (WARN_ON(!chanctx_conf)) {
  485. rcu_read_unlock();
  486. return;
  487. }
  488. chan = chanctx_conf->def.chan;
  489. rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
  490. rcu_read_unlock();
  491. sband = local->hw.wiphy->bands[chan->band];
  492. shift = ieee80211_vif_get_shift(&sdata->vif);
  493. if (assoc_data->supp_rates_len) {
  494. /*
  495. * Get all rates supported by the device and the AP as
  496. * some APs don't like getting a superset of their rates
  497. * in the association request (e.g. D-Link DAP 1353 in
  498. * b-only mode)...
  499. */
  500. rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
  501. assoc_data->supp_rates,
  502. assoc_data->supp_rates_len,
  503. &rates);
  504. } else {
  505. /*
  506. * In case AP not provide any supported rates information
  507. * before association, we send information element(s) with
  508. * all rates that we support.
  509. */
  510. rates_len = 0;
  511. for (i = 0; i < sband->n_bitrates; i++) {
  512. if ((rate_flags & sband->bitrates[i].flags)
  513. != rate_flags)
  514. continue;
  515. rates |= BIT(i);
  516. rates_len++;
  517. }
  518. }
  519. skb = alloc_skb(local->hw.extra_tx_headroom +
  520. sizeof(*mgmt) + /* bit too much but doesn't matter */
  521. 2 + assoc_data->ssid_len + /* SSID */
  522. 4 + rates_len + /* (extended) rates */
  523. 4 + /* power capability */
  524. 2 + 2 * sband->n_channels + /* supported channels */
  525. 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
  526. 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
  527. assoc_data->ie_len + /* extra IEs */
  528. 9, /* WMM */
  529. GFP_KERNEL);
  530. if (!skb)
  531. return;
  532. skb_reserve(skb, local->hw.extra_tx_headroom);
  533. capab = WLAN_CAPABILITY_ESS;
  534. if (sband->band == IEEE80211_BAND_2GHZ) {
  535. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  536. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  537. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  538. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  539. }
  540. if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
  541. capab |= WLAN_CAPABILITY_PRIVACY;
  542. if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  543. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  544. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  545. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  546. memset(mgmt, 0, 24);
  547. memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
  548. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  549. memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
  550. if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
  551. skb_put(skb, 10);
  552. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  553. IEEE80211_STYPE_REASSOC_REQ);
  554. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  555. mgmt->u.reassoc_req.listen_interval =
  556. cpu_to_le16(local->hw.conf.listen_interval);
  557. memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
  558. ETH_ALEN);
  559. } else {
  560. skb_put(skb, 4);
  561. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  562. IEEE80211_STYPE_ASSOC_REQ);
  563. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  564. mgmt->u.assoc_req.listen_interval =
  565. cpu_to_le16(local->hw.conf.listen_interval);
  566. }
  567. /* SSID */
  568. pos = skb_put(skb, 2 + assoc_data->ssid_len);
  569. *pos++ = WLAN_EID_SSID;
  570. *pos++ = assoc_data->ssid_len;
  571. memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
  572. /* add all rates which were marked to be used above */
  573. supp_rates_len = rates_len;
  574. if (supp_rates_len > 8)
  575. supp_rates_len = 8;
  576. pos = skb_put(skb, supp_rates_len + 2);
  577. *pos++ = WLAN_EID_SUPP_RATES;
  578. *pos++ = supp_rates_len;
  579. count = 0;
  580. for (i = 0; i < sband->n_bitrates; i++) {
  581. if (BIT(i) & rates) {
  582. int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  583. 5 * (1 << shift));
  584. *pos++ = (u8) rate;
  585. if (++count == 8)
  586. break;
  587. }
  588. }
  589. if (rates_len > count) {
  590. pos = skb_put(skb, rates_len - count + 2);
  591. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  592. *pos++ = rates_len - count;
  593. for (i++; i < sband->n_bitrates; i++) {
  594. if (BIT(i) & rates) {
  595. int rate;
  596. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  597. 5 * (1 << shift));
  598. *pos++ = (u8) rate;
  599. }
  600. }
  601. }
  602. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  603. /* 1. power capabilities */
  604. pos = skb_put(skb, 4);
  605. *pos++ = WLAN_EID_PWR_CAPABILITY;
  606. *pos++ = 2;
  607. *pos++ = 0; /* min tx power */
  608. /* max tx power */
  609. *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
  610. /* 2. supported channels */
  611. /* TODO: get this in reg domain format */
  612. pos = skb_put(skb, 2 * sband->n_channels + 2);
  613. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  614. *pos++ = 2 * sband->n_channels;
  615. for (i = 0; i < sband->n_channels; i++) {
  616. *pos++ = ieee80211_frequency_to_channel(
  617. sband->channels[i].center_freq);
  618. *pos++ = 1; /* one channel in the subband*/
  619. }
  620. }
  621. /* if present, add any custom IEs that go before HT */
  622. if (assoc_data->ie_len && assoc_data->ie) {
  623. static const u8 before_ht[] = {
  624. WLAN_EID_SSID,
  625. WLAN_EID_SUPP_RATES,
  626. WLAN_EID_EXT_SUPP_RATES,
  627. WLAN_EID_PWR_CAPABILITY,
  628. WLAN_EID_SUPPORTED_CHANNELS,
  629. WLAN_EID_RSN,
  630. WLAN_EID_QOS_CAPA,
  631. WLAN_EID_RRM_ENABLED_CAPABILITIES,
  632. WLAN_EID_MOBILITY_DOMAIN,
  633. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  634. };
  635. noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
  636. before_ht, ARRAY_SIZE(before_ht),
  637. offset);
  638. pos = skb_put(skb, noffset - offset);
  639. memcpy(pos, assoc_data->ie + offset, noffset - offset);
  640. offset = noffset;
  641. }
  642. if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  643. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
  644. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  645. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
  646. ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
  647. sband, chan, sdata->smps_mode);
  648. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  649. ieee80211_add_vht_ie(sdata, skb, sband,
  650. &assoc_data->ap_vht_cap);
  651. /* if present, add any custom non-vendor IEs that go after HT */
  652. if (assoc_data->ie_len && assoc_data->ie) {
  653. noffset = ieee80211_ie_split_vendor(assoc_data->ie,
  654. assoc_data->ie_len,
  655. offset);
  656. pos = skb_put(skb, noffset - offset);
  657. memcpy(pos, assoc_data->ie + offset, noffset - offset);
  658. offset = noffset;
  659. }
  660. if (assoc_data->wmm) {
  661. if (assoc_data->uapsd) {
  662. qos_info = ifmgd->uapsd_queues;
  663. qos_info |= (ifmgd->uapsd_max_sp_len <<
  664. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  665. } else {
  666. qos_info = 0;
  667. }
  668. pos = skb_put(skb, 9);
  669. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  670. *pos++ = 7; /* len */
  671. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  672. *pos++ = 0x50;
  673. *pos++ = 0xf2;
  674. *pos++ = 2; /* WME */
  675. *pos++ = 0; /* WME info */
  676. *pos++ = 1; /* WME ver */
  677. *pos++ = qos_info;
  678. }
  679. /* add any remaining custom (i.e. vendor specific here) IEs */
  680. if (assoc_data->ie_len && assoc_data->ie) {
  681. noffset = assoc_data->ie_len;
  682. pos = skb_put(skb, noffset - offset);
  683. memcpy(pos, assoc_data->ie + offset, noffset - offset);
  684. }
  685. drv_mgd_prepare_tx(local, sdata);
  686. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  687. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  688. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  689. IEEE80211_TX_INTFL_MLME_CONN_TX;
  690. ieee80211_tx_skb(sdata, skb);
  691. }
  692. void ieee80211_send_pspoll(struct ieee80211_local *local,
  693. struct ieee80211_sub_if_data *sdata)
  694. {
  695. struct ieee80211_pspoll *pspoll;
  696. struct sk_buff *skb;
  697. skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
  698. if (!skb)
  699. return;
  700. pspoll = (struct ieee80211_pspoll *) skb->data;
  701. pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  702. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  703. ieee80211_tx_skb(sdata, skb);
  704. }
  705. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  706. struct ieee80211_sub_if_data *sdata,
  707. int powersave)
  708. {
  709. struct sk_buff *skb;
  710. struct ieee80211_hdr_3addr *nullfunc;
  711. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  712. skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
  713. if (!skb)
  714. return;
  715. nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
  716. if (powersave)
  717. nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  718. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  719. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  720. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  721. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  722. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  723. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  724. ieee80211_tx_skb(sdata, skb);
  725. }
  726. static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
  727. struct ieee80211_sub_if_data *sdata)
  728. {
  729. struct sk_buff *skb;
  730. struct ieee80211_hdr *nullfunc;
  731. __le16 fc;
  732. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  733. return;
  734. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
  735. if (!skb)
  736. return;
  737. skb_reserve(skb, local->hw.extra_tx_headroom);
  738. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
  739. memset(nullfunc, 0, 30);
  740. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  741. IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  742. nullfunc->frame_control = fc;
  743. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  744. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  745. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  746. memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
  747. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  748. ieee80211_tx_skb(sdata, skb);
  749. }
  750. /* spectrum management related things */
  751. static void ieee80211_chswitch_work(struct work_struct *work)
  752. {
  753. struct ieee80211_sub_if_data *sdata =
  754. container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
  755. struct ieee80211_local *local = sdata->local;
  756. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  757. if (!ieee80211_sdata_running(sdata))
  758. return;
  759. sdata_lock(sdata);
  760. if (!ifmgd->associated)
  761. goto out;
  762. local->_oper_chandef = local->csa_chandef;
  763. if (!local->ops->channel_switch) {
  764. /* call "hw_config" only if doing sw channel switch */
  765. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  766. } else {
  767. /* update the device channel directly */
  768. local->hw.conf.chandef = local->_oper_chandef;
  769. }
  770. /* XXX: shouldn't really modify cfg80211-owned data! */
  771. ifmgd->associated->channel = local->_oper_chandef.chan;
  772. /* XXX: wait for a beacon first? */
  773. ieee80211_wake_queues_by_reason(&local->hw,
  774. IEEE80211_MAX_QUEUE_MAP,
  775. IEEE80211_QUEUE_STOP_REASON_CSA);
  776. out:
  777. ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
  778. sdata_unlock(sdata);
  779. }
  780. void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
  781. {
  782. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  783. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  784. trace_api_chswitch_done(sdata, success);
  785. if (!success) {
  786. sdata_info(sdata,
  787. "driver channel switch failed, disconnecting\n");
  788. ieee80211_queue_work(&sdata->local->hw,
  789. &ifmgd->csa_connection_drop_work);
  790. } else {
  791. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  792. }
  793. }
  794. EXPORT_SYMBOL(ieee80211_chswitch_done);
  795. static void ieee80211_chswitch_timer(unsigned long data)
  796. {
  797. struct ieee80211_sub_if_data *sdata =
  798. (struct ieee80211_sub_if_data *) data;
  799. ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
  800. }
  801. static void
  802. ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
  803. u64 timestamp, struct ieee802_11_elems *elems,
  804. bool beacon)
  805. {
  806. struct ieee80211_local *local = sdata->local;
  807. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  808. struct cfg80211_bss *cbss = ifmgd->associated;
  809. struct ieee80211_chanctx *chanctx;
  810. enum ieee80211_band current_band;
  811. u8 count;
  812. u8 mode;
  813. struct cfg80211_chan_def new_chandef = {};
  814. int res;
  815. sdata_assert_lock(sdata);
  816. if (!cbss)
  817. return;
  818. if (local->scanning)
  819. return;
  820. /* disregard subsequent announcements if we are already processing */
  821. if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
  822. return;
  823. current_band = cbss->channel->band;
  824. res = ieee80211_parse_ch_switch_ie(sdata, elems, beacon, current_band,
  825. ifmgd->flags,
  826. ifmgd->associated->bssid, &count,
  827. &mode, &new_chandef);
  828. if (res < 0)
  829. ieee80211_queue_work(&local->hw,
  830. &ifmgd->csa_connection_drop_work);
  831. if (res)
  832. return;
  833. if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
  834. IEEE80211_CHAN_DISABLED)) {
  835. sdata_info(sdata,
  836. "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
  837. ifmgd->associated->bssid,
  838. new_chandef.chan->center_freq,
  839. new_chandef.width, new_chandef.center_freq1,
  840. new_chandef.center_freq2);
  841. ieee80211_queue_work(&local->hw,
  842. &ifmgd->csa_connection_drop_work);
  843. return;
  844. }
  845. ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
  846. if (local->use_chanctx) {
  847. sdata_info(sdata,
  848. "not handling channel switch with channel contexts\n");
  849. ieee80211_queue_work(&local->hw,
  850. &ifmgd->csa_connection_drop_work);
  851. return;
  852. }
  853. mutex_lock(&local->chanctx_mtx);
  854. if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
  855. mutex_unlock(&local->chanctx_mtx);
  856. return;
  857. }
  858. chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
  859. struct ieee80211_chanctx, conf);
  860. if (chanctx->refcount > 1) {
  861. sdata_info(sdata,
  862. "channel switch with multiple interfaces on the same channel, disconnecting\n");
  863. ieee80211_queue_work(&local->hw,
  864. &ifmgd->csa_connection_drop_work);
  865. mutex_unlock(&local->chanctx_mtx);
  866. return;
  867. }
  868. mutex_unlock(&local->chanctx_mtx);
  869. local->csa_chandef = new_chandef;
  870. if (mode)
  871. ieee80211_stop_queues_by_reason(&local->hw,
  872. IEEE80211_MAX_QUEUE_MAP,
  873. IEEE80211_QUEUE_STOP_REASON_CSA);
  874. if (local->ops->channel_switch) {
  875. /* use driver's channel switch callback */
  876. struct ieee80211_channel_switch ch_switch = {
  877. .timestamp = timestamp,
  878. .block_tx = mode,
  879. .chandef = new_chandef,
  880. .count = count,
  881. };
  882. drv_channel_switch(local, &ch_switch);
  883. return;
  884. }
  885. /* channel switch handled in software */
  886. if (count <= 1)
  887. ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
  888. else
  889. mod_timer(&ifmgd->chswitch_timer,
  890. TU_TO_EXP_TIME(count * cbss->beacon_interval));
  891. }
  892. static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
  893. struct ieee80211_channel *channel,
  894. const u8 *country_ie, u8 country_ie_len,
  895. const u8 *pwr_constr_elem)
  896. {
  897. struct ieee80211_country_ie_triplet *triplet;
  898. int chan = ieee80211_frequency_to_channel(channel->center_freq);
  899. int i, chan_pwr, chan_increment, new_ap_level;
  900. bool have_chan_pwr = false;
  901. /* Invalid IE */
  902. if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
  903. return 0;
  904. triplet = (void *)(country_ie + 3);
  905. country_ie_len -= 3;
  906. switch (channel->band) {
  907. default:
  908. WARN_ON_ONCE(1);
  909. /* fall through */
  910. case IEEE80211_BAND_2GHZ:
  911. case IEEE80211_BAND_60GHZ:
  912. chan_increment = 1;
  913. break;
  914. case IEEE80211_BAND_5GHZ:
  915. chan_increment = 4;
  916. break;
  917. }
  918. /* find channel */
  919. while (country_ie_len >= 3) {
  920. u8 first_channel = triplet->chans.first_channel;
  921. if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
  922. goto next;
  923. for (i = 0; i < triplet->chans.num_channels; i++) {
  924. if (first_channel + i * chan_increment == chan) {
  925. have_chan_pwr = true;
  926. chan_pwr = triplet->chans.max_power;
  927. break;
  928. }
  929. }
  930. if (have_chan_pwr)
  931. break;
  932. next:
  933. triplet++;
  934. country_ie_len -= 3;
  935. }
  936. if (!have_chan_pwr)
  937. return 0;
  938. new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
  939. if (sdata->ap_power_level == new_ap_level)
  940. return 0;
  941. sdata_info(sdata,
  942. "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
  943. new_ap_level, chan_pwr, *pwr_constr_elem,
  944. sdata->u.mgd.bssid);
  945. sdata->ap_power_level = new_ap_level;
  946. if (__ieee80211_recalc_txpower(sdata))
  947. return BSS_CHANGED_TXPOWER;
  948. return 0;
  949. }
  950. /* powersave */
  951. static void ieee80211_enable_ps(struct ieee80211_local *local,
  952. struct ieee80211_sub_if_data *sdata)
  953. {
  954. struct ieee80211_conf *conf = &local->hw.conf;
  955. /*
  956. * If we are scanning right now then the parameters will
  957. * take effect when scan finishes.
  958. */
  959. if (local->scanning)
  960. return;
  961. if (conf->dynamic_ps_timeout > 0 &&
  962. !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
  963. mod_timer(&local->dynamic_ps_timer, jiffies +
  964. msecs_to_jiffies(conf->dynamic_ps_timeout));
  965. } else {
  966. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  967. ieee80211_send_nullfunc(local, sdata, 1);
  968. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  969. (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
  970. return;
  971. conf->flags |= IEEE80211_CONF_PS;
  972. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  973. }
  974. }
  975. static void ieee80211_change_ps(struct ieee80211_local *local)
  976. {
  977. struct ieee80211_conf *conf = &local->hw.conf;
  978. if (local->ps_sdata) {
  979. ieee80211_enable_ps(local, local->ps_sdata);
  980. } else if (conf->flags & IEEE80211_CONF_PS) {
  981. conf->flags &= ~IEEE80211_CONF_PS;
  982. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  983. del_timer_sync(&local->dynamic_ps_timer);
  984. cancel_work_sync(&local->dynamic_ps_enable_work);
  985. }
  986. }
  987. static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
  988. {
  989. struct ieee80211_if_managed *mgd = &sdata->u.mgd;
  990. struct sta_info *sta = NULL;
  991. bool authorized = false;
  992. if (!mgd->powersave)
  993. return false;
  994. if (mgd->broken_ap)
  995. return false;
  996. if (!mgd->associated)
  997. return false;
  998. if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
  999. return false;
  1000. if (!mgd->have_beacon)
  1001. return false;
  1002. rcu_read_lock();
  1003. sta = sta_info_get(sdata, mgd->bssid);
  1004. if (sta)
  1005. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1006. rcu_read_unlock();
  1007. return authorized;
  1008. }
  1009. /* need to hold RTNL or interface lock */
  1010. void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
  1011. {
  1012. struct ieee80211_sub_if_data *sdata, *found = NULL;
  1013. int count = 0;
  1014. int timeout;
  1015. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
  1016. local->ps_sdata = NULL;
  1017. return;
  1018. }
  1019. list_for_each_entry(sdata, &local->interfaces, list) {
  1020. if (!ieee80211_sdata_running(sdata))
  1021. continue;
  1022. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1023. /* If an AP vif is found, then disable PS
  1024. * by setting the count to zero thereby setting
  1025. * ps_sdata to NULL.
  1026. */
  1027. count = 0;
  1028. break;
  1029. }
  1030. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1031. continue;
  1032. found = sdata;
  1033. count++;
  1034. }
  1035. if (count == 1 && ieee80211_powersave_allowed(found)) {
  1036. s32 beaconint_us;
  1037. if (latency < 0)
  1038. latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
  1039. beaconint_us = ieee80211_tu_to_usec(
  1040. found->vif.bss_conf.beacon_int);
  1041. timeout = local->dynamic_ps_forced_timeout;
  1042. if (timeout < 0) {
  1043. /*
  1044. * Go to full PSM if the user configures a very low
  1045. * latency requirement.
  1046. * The 2000 second value is there for compatibility
  1047. * until the PM_QOS_NETWORK_LATENCY is configured
  1048. * with real values.
  1049. */
  1050. if (latency > (1900 * USEC_PER_MSEC) &&
  1051. latency != (2000 * USEC_PER_SEC))
  1052. timeout = 0;
  1053. else
  1054. timeout = 100;
  1055. }
  1056. local->hw.conf.dynamic_ps_timeout = timeout;
  1057. if (beaconint_us > latency) {
  1058. local->ps_sdata = NULL;
  1059. } else {
  1060. int maxslp = 1;
  1061. u8 dtimper = found->u.mgd.dtim_period;
  1062. /* If the TIM IE is invalid, pretend the value is 1 */
  1063. if (!dtimper)
  1064. dtimper = 1;
  1065. else if (dtimper > 1)
  1066. maxslp = min_t(int, dtimper,
  1067. latency / beaconint_us);
  1068. local->hw.conf.max_sleep_period = maxslp;
  1069. local->hw.conf.ps_dtim_period = dtimper;
  1070. local->ps_sdata = found;
  1071. }
  1072. } else {
  1073. local->ps_sdata = NULL;
  1074. }
  1075. ieee80211_change_ps(local);
  1076. }
  1077. void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
  1078. {
  1079. bool ps_allowed = ieee80211_powersave_allowed(sdata);
  1080. if (sdata->vif.bss_conf.ps != ps_allowed) {
  1081. sdata->vif.bss_conf.ps = ps_allowed;
  1082. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
  1083. }
  1084. }
  1085. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  1086. {
  1087. struct ieee80211_local *local =
  1088. container_of(work, struct ieee80211_local,
  1089. dynamic_ps_disable_work);
  1090. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1091. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1092. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1093. }
  1094. ieee80211_wake_queues_by_reason(&local->hw,
  1095. IEEE80211_MAX_QUEUE_MAP,
  1096. IEEE80211_QUEUE_STOP_REASON_PS);
  1097. }
  1098. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  1099. {
  1100. struct ieee80211_local *local =
  1101. container_of(work, struct ieee80211_local,
  1102. dynamic_ps_enable_work);
  1103. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  1104. struct ieee80211_if_managed *ifmgd;
  1105. unsigned long flags;
  1106. int q;
  1107. /* can only happen when PS was just disabled anyway */
  1108. if (!sdata)
  1109. return;
  1110. ifmgd = &sdata->u.mgd;
  1111. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  1112. return;
  1113. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1114. /* don't enter PS if TX frames are pending */
  1115. if (drv_tx_frames_pending(local)) {
  1116. mod_timer(&local->dynamic_ps_timer, jiffies +
  1117. msecs_to_jiffies(
  1118. local->hw.conf.dynamic_ps_timeout));
  1119. return;
  1120. }
  1121. /*
  1122. * transmission can be stopped by others which leads to
  1123. * dynamic_ps_timer expiry. Postpone the ps timer if it
  1124. * is not the actual idle state.
  1125. */
  1126. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  1127. for (q = 0; q < local->hw.queues; q++) {
  1128. if (local->queue_stop_reasons[q]) {
  1129. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  1130. flags);
  1131. mod_timer(&local->dynamic_ps_timer, jiffies +
  1132. msecs_to_jiffies(
  1133. local->hw.conf.dynamic_ps_timeout));
  1134. return;
  1135. }
  1136. }
  1137. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  1138. }
  1139. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  1140. !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1141. if (drv_tx_frames_pending(local)) {
  1142. mod_timer(&local->dynamic_ps_timer, jiffies +
  1143. msecs_to_jiffies(
  1144. local->hw.conf.dynamic_ps_timeout));
  1145. } else {
  1146. ieee80211_send_nullfunc(local, sdata, 1);
  1147. /* Flush to get the tx status of nullfunc frame */
  1148. ieee80211_flush_queues(local, sdata);
  1149. }
  1150. }
  1151. if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
  1152. (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
  1153. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1154. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  1155. local->hw.conf.flags |= IEEE80211_CONF_PS;
  1156. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1157. }
  1158. }
  1159. void ieee80211_dynamic_ps_timer(unsigned long data)
  1160. {
  1161. struct ieee80211_local *local = (void *) data;
  1162. if (local->quiescing || local->suspended)
  1163. return;
  1164. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  1165. }
  1166. void ieee80211_dfs_cac_timer_work(struct work_struct *work)
  1167. {
  1168. struct delayed_work *delayed_work =
  1169. container_of(work, struct delayed_work, work);
  1170. struct ieee80211_sub_if_data *sdata =
  1171. container_of(delayed_work, struct ieee80211_sub_if_data,
  1172. dfs_cac_timer_work);
  1173. ieee80211_vif_release_channel(sdata);
  1174. cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
  1175. }
  1176. /* MLME */
  1177. static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
  1178. struct ieee80211_sub_if_data *sdata,
  1179. const u8 *wmm_param, size_t wmm_param_len)
  1180. {
  1181. struct ieee80211_tx_queue_params params;
  1182. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1183. size_t left;
  1184. int count;
  1185. const u8 *pos;
  1186. u8 uapsd_queues = 0;
  1187. if (!local->ops->conf_tx)
  1188. return false;
  1189. if (local->hw.queues < IEEE80211_NUM_ACS)
  1190. return false;
  1191. if (!wmm_param)
  1192. return false;
  1193. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  1194. return false;
  1195. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  1196. uapsd_queues = ifmgd->uapsd_queues;
  1197. count = wmm_param[6] & 0x0f;
  1198. if (count == ifmgd->wmm_last_param_set)
  1199. return false;
  1200. ifmgd->wmm_last_param_set = count;
  1201. pos = wmm_param + 8;
  1202. left = wmm_param_len - 8;
  1203. memset(&params, 0, sizeof(params));
  1204. sdata->wmm_acm = 0;
  1205. for (; left >= 4; left -= 4, pos += 4) {
  1206. int aci = (pos[0] >> 5) & 0x03;
  1207. int acm = (pos[0] >> 4) & 0x01;
  1208. bool uapsd = false;
  1209. int queue;
  1210. switch (aci) {
  1211. case 1: /* AC_BK */
  1212. queue = 3;
  1213. if (acm)
  1214. sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  1215. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  1216. uapsd = true;
  1217. break;
  1218. case 2: /* AC_VI */
  1219. queue = 1;
  1220. if (acm)
  1221. sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  1222. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  1223. uapsd = true;
  1224. break;
  1225. case 3: /* AC_VO */
  1226. queue = 0;
  1227. if (acm)
  1228. sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  1229. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  1230. uapsd = true;
  1231. break;
  1232. case 0: /* AC_BE */
  1233. default:
  1234. queue = 2;
  1235. if (acm)
  1236. sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  1237. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  1238. uapsd = true;
  1239. break;
  1240. }
  1241. params.aifs = pos[0] & 0x0f;
  1242. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  1243. params.cw_min = ecw2cw(pos[1] & 0x0f);
  1244. params.txop = get_unaligned_le16(pos + 2);
  1245. params.acm = acm;
  1246. params.uapsd = uapsd;
  1247. mlme_dbg(sdata,
  1248. "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
  1249. queue, aci, acm,
  1250. params.aifs, params.cw_min, params.cw_max,
  1251. params.txop, params.uapsd);
  1252. sdata->tx_conf[queue] = params;
  1253. if (drv_conf_tx(local, sdata, queue, &params))
  1254. sdata_err(sdata,
  1255. "failed to set TX queue parameters for queue %d\n",
  1256. queue);
  1257. }
  1258. /* enable WMM or activate new settings */
  1259. sdata->vif.bss_conf.qos = true;
  1260. return true;
  1261. }
  1262. static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  1263. {
  1264. lockdep_assert_held(&sdata->local->mtx);
  1265. sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
  1266. ieee80211_run_deferred_scan(sdata->local);
  1267. }
  1268. static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  1269. {
  1270. mutex_lock(&sdata->local->mtx);
  1271. __ieee80211_stop_poll(sdata);
  1272. mutex_unlock(&sdata->local->mtx);
  1273. }
  1274. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  1275. u16 capab, bool erp_valid, u8 erp)
  1276. {
  1277. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1278. u32 changed = 0;
  1279. bool use_protection;
  1280. bool use_short_preamble;
  1281. bool use_short_slot;
  1282. if (erp_valid) {
  1283. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  1284. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  1285. } else {
  1286. use_protection = false;
  1287. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  1288. }
  1289. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  1290. if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
  1291. use_short_slot = true;
  1292. if (use_protection != bss_conf->use_cts_prot) {
  1293. bss_conf->use_cts_prot = use_protection;
  1294. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1295. }
  1296. if (use_short_preamble != bss_conf->use_short_preamble) {
  1297. bss_conf->use_short_preamble = use_short_preamble;
  1298. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1299. }
  1300. if (use_short_slot != bss_conf->use_short_slot) {
  1301. bss_conf->use_short_slot = use_short_slot;
  1302. changed |= BSS_CHANGED_ERP_SLOT;
  1303. }
  1304. return changed;
  1305. }
  1306. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  1307. struct cfg80211_bss *cbss,
  1308. u32 bss_info_changed)
  1309. {
  1310. struct ieee80211_bss *bss = (void *)cbss->priv;
  1311. struct ieee80211_local *local = sdata->local;
  1312. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1313. bss_info_changed |= BSS_CHANGED_ASSOC;
  1314. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  1315. bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
  1316. sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
  1317. beacon_loss_count * bss_conf->beacon_int));
  1318. sdata->u.mgd.associated = cbss;
  1319. memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  1320. sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
  1321. if (sdata->vif.p2p) {
  1322. const struct cfg80211_bss_ies *ies;
  1323. rcu_read_lock();
  1324. ies = rcu_dereference(cbss->ies);
  1325. if (ies) {
  1326. int ret;
  1327. ret = cfg80211_get_p2p_attr(
  1328. ies->data, ies->len,
  1329. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  1330. (u8 *) &bss_conf->p2p_noa_attr,
  1331. sizeof(bss_conf->p2p_noa_attr));
  1332. if (ret >= 2) {
  1333. sdata->u.mgd.p2p_noa_index =
  1334. bss_conf->p2p_noa_attr.index;
  1335. bss_info_changed |= BSS_CHANGED_P2P_PS;
  1336. }
  1337. }
  1338. rcu_read_unlock();
  1339. }
  1340. /* just to be sure */
  1341. ieee80211_stop_poll(sdata);
  1342. ieee80211_led_assoc(local, 1);
  1343. if (sdata->u.mgd.have_beacon) {
  1344. /*
  1345. * If the AP is buggy we may get here with no DTIM period
  1346. * known, so assume it's 1 which is the only safe assumption
  1347. * in that case, although if the TIM IE is broken powersave
  1348. * probably just won't work at all.
  1349. */
  1350. bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
  1351. bss_conf->beacon_rate = bss->beacon_rate;
  1352. bss_info_changed |= BSS_CHANGED_BEACON_INFO;
  1353. } else {
  1354. bss_conf->beacon_rate = NULL;
  1355. bss_conf->dtim_period = 0;
  1356. }
  1357. bss_conf->assoc = 1;
  1358. /* Tell the driver to monitor connection quality (if supported) */
  1359. if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
  1360. bss_conf->cqm_rssi_thold)
  1361. bss_info_changed |= BSS_CHANGED_CQM;
  1362. /* Enable ARP filtering */
  1363. if (bss_conf->arp_addr_cnt)
  1364. bss_info_changed |= BSS_CHANGED_ARP_FILTER;
  1365. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  1366. mutex_lock(&local->iflist_mtx);
  1367. ieee80211_recalc_ps(local, -1);
  1368. mutex_unlock(&local->iflist_mtx);
  1369. ieee80211_recalc_smps(sdata);
  1370. ieee80211_recalc_ps_vif(sdata);
  1371. netif_carrier_on(sdata->dev);
  1372. }
  1373. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  1374. u16 stype, u16 reason, bool tx,
  1375. u8 *frame_buf)
  1376. {
  1377. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1378. struct ieee80211_local *local = sdata->local;
  1379. u32 changed = 0;
  1380. sdata_assert_lock(sdata);
  1381. if (WARN_ON_ONCE(tx && !frame_buf))
  1382. return;
  1383. if (WARN_ON(!ifmgd->associated))
  1384. return;
  1385. ieee80211_stop_poll(sdata);
  1386. ifmgd->associated = NULL;
  1387. netif_carrier_off(sdata->dev);
  1388. /*
  1389. * if we want to get out of ps before disassoc (why?) we have
  1390. * to do it before sending disassoc, as otherwise the null-packet
  1391. * won't be valid.
  1392. */
  1393. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1394. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1395. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1396. }
  1397. local->ps_sdata = NULL;
  1398. /* disable per-vif ps */
  1399. ieee80211_recalc_ps_vif(sdata);
  1400. /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
  1401. if (tx)
  1402. ieee80211_flush_queues(local, sdata);
  1403. /* deauthenticate/disassociate now */
  1404. if (tx || frame_buf)
  1405. ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
  1406. reason, tx, frame_buf);
  1407. /* flush out frame */
  1408. if (tx)
  1409. ieee80211_flush_queues(local, sdata);
  1410. /* clear bssid only after building the needed mgmt frames */
  1411. memset(ifmgd->bssid, 0, ETH_ALEN);
  1412. /* remove AP and TDLS peers */
  1413. sta_info_flush_defer(sdata);
  1414. /* finally reset all BSS / config parameters */
  1415. changed |= ieee80211_reset_erp_info(sdata);
  1416. ieee80211_led_assoc(local, 0);
  1417. changed |= BSS_CHANGED_ASSOC;
  1418. sdata->vif.bss_conf.assoc = false;
  1419. ifmgd->p2p_noa_index = -1;
  1420. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  1421. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  1422. /* on the next assoc, re-program HT/VHT parameters */
  1423. memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
  1424. memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
  1425. memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
  1426. memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
  1427. sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1428. del_timer_sync(&local->dynamic_ps_timer);
  1429. cancel_work_sync(&local->dynamic_ps_enable_work);
  1430. /* Disable ARP filtering */
  1431. if (sdata->vif.bss_conf.arp_addr_cnt)
  1432. changed |= BSS_CHANGED_ARP_FILTER;
  1433. sdata->vif.bss_conf.qos = false;
  1434. changed |= BSS_CHANGED_QOS;
  1435. /* The BSSID (not really interesting) and HT changed */
  1436. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  1437. ieee80211_bss_info_change_notify(sdata, changed);
  1438. /* disassociated - set to defaults now */
  1439. ieee80211_set_wmm_default(sdata, false);
  1440. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  1441. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  1442. del_timer_sync(&sdata->u.mgd.timer);
  1443. del_timer_sync(&sdata->u.mgd.chswitch_timer);
  1444. sdata->vif.bss_conf.dtim_period = 0;
  1445. sdata->vif.bss_conf.beacon_rate = NULL;
  1446. ifmgd->have_beacon = false;
  1447. ifmgd->flags = 0;
  1448. ieee80211_vif_release_channel(sdata);
  1449. }
  1450. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  1451. struct ieee80211_hdr *hdr)
  1452. {
  1453. /*
  1454. * We can postpone the mgd.timer whenever receiving unicast frames
  1455. * from AP because we know that the connection is working both ways
  1456. * at that time. But multicast frames (and hence also beacons) must
  1457. * be ignored here, because we need to trigger the timer during
  1458. * data idle periods for sending the periodic probe request to the
  1459. * AP we're connected to.
  1460. */
  1461. if (is_multicast_ether_addr(hdr->addr1))
  1462. return;
  1463. ieee80211_sta_reset_conn_monitor(sdata);
  1464. }
  1465. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  1466. {
  1467. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1468. struct ieee80211_local *local = sdata->local;
  1469. mutex_lock(&local->mtx);
  1470. if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
  1471. goto out;
  1472. __ieee80211_stop_poll(sdata);
  1473. mutex_lock(&local->iflist_mtx);
  1474. ieee80211_recalc_ps(local, -1);
  1475. mutex_unlock(&local->iflist_mtx);
  1476. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  1477. goto out;
  1478. /*
  1479. * We've received a probe response, but are not sure whether
  1480. * we have or will be receiving any beacons or data, so let's
  1481. * schedule the timers again, just in case.
  1482. */
  1483. ieee80211_sta_reset_beacon_monitor(sdata);
  1484. mod_timer(&ifmgd->conn_mon_timer,
  1485. round_jiffies_up(jiffies +
  1486. IEEE80211_CONNECTION_IDLE_TIME));
  1487. out:
  1488. mutex_unlock(&local->mtx);
  1489. }
  1490. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  1491. struct ieee80211_hdr *hdr, bool ack)
  1492. {
  1493. if (!ieee80211_is_data(hdr->frame_control))
  1494. return;
  1495. if (ieee80211_is_nullfunc(hdr->frame_control) &&
  1496. sdata->u.mgd.probe_send_count > 0) {
  1497. if (ack)
  1498. ieee80211_sta_reset_conn_monitor(sdata);
  1499. else
  1500. sdata->u.mgd.nullfunc_failed = true;
  1501. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1502. return;
  1503. }
  1504. if (ack)
  1505. ieee80211_sta_reset_conn_monitor(sdata);
  1506. }
  1507. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  1508. {
  1509. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1510. const u8 *ssid;
  1511. u8 *dst = ifmgd->associated->bssid;
  1512. u8 unicast_limit = max(1, max_probe_tries - 3);
  1513. /*
  1514. * Try sending broadcast probe requests for the last three
  1515. * probe requests after the first ones failed since some
  1516. * buggy APs only support broadcast probe requests.
  1517. */
  1518. if (ifmgd->probe_send_count >= unicast_limit)
  1519. dst = NULL;
  1520. /*
  1521. * When the hardware reports an accurate Tx ACK status, it's
  1522. * better to send a nullfunc frame instead of a probe request,
  1523. * as it will kick us off the AP quickly if we aren't associated
  1524. * anymore. The timeout will be reset if the frame is ACKed by
  1525. * the AP.
  1526. */
  1527. ifmgd->probe_send_count++;
  1528. if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1529. ifmgd->nullfunc_failed = false;
  1530. ieee80211_send_nullfunc(sdata->local, sdata, 0);
  1531. } else {
  1532. int ssid_len;
  1533. rcu_read_lock();
  1534. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1535. if (WARN_ON_ONCE(ssid == NULL))
  1536. ssid_len = 0;
  1537. else
  1538. ssid_len = ssid[1];
  1539. ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
  1540. 0, (u32) -1, true, 0,
  1541. ifmgd->associated->channel, false);
  1542. rcu_read_unlock();
  1543. }
  1544. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  1545. run_again(sdata, ifmgd->probe_timeout);
  1546. if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  1547. ieee80211_flush_queues(sdata->local, sdata);
  1548. }
  1549. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  1550. bool beacon)
  1551. {
  1552. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1553. bool already = false;
  1554. if (!ieee80211_sdata_running(sdata))
  1555. return;
  1556. sdata_lock(sdata);
  1557. if (!ifmgd->associated)
  1558. goto out;
  1559. mutex_lock(&sdata->local->mtx);
  1560. if (sdata->local->tmp_channel || sdata->local->scanning) {
  1561. mutex_unlock(&sdata->local->mtx);
  1562. goto out;
  1563. }
  1564. if (beacon) {
  1565. mlme_dbg_ratelimited(sdata,
  1566. "detected beacon loss from AP (missed %d beacons) - probing\n",
  1567. beacon_loss_count);
  1568. ieee80211_cqm_rssi_notify(&sdata->vif,
  1569. NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
  1570. GFP_KERNEL);
  1571. }
  1572. /*
  1573. * The driver/our work has already reported this event or the
  1574. * connection monitoring has kicked in and we have already sent
  1575. * a probe request. Or maybe the AP died and the driver keeps
  1576. * reporting until we disassociate...
  1577. *
  1578. * In either case we have to ignore the current call to this
  1579. * function (except for setting the correct probe reason bit)
  1580. * because otherwise we would reset the timer every time and
  1581. * never check whether we received a probe response!
  1582. */
  1583. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  1584. already = true;
  1585. mutex_unlock(&sdata->local->mtx);
  1586. if (already)
  1587. goto out;
  1588. mutex_lock(&sdata->local->iflist_mtx);
  1589. ieee80211_recalc_ps(sdata->local, -1);
  1590. mutex_unlock(&sdata->local->iflist_mtx);
  1591. ifmgd->probe_send_count = 0;
  1592. ieee80211_mgd_probe_ap_send(sdata);
  1593. out:
  1594. sdata_unlock(sdata);
  1595. }
  1596. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  1597. struct ieee80211_vif *vif)
  1598. {
  1599. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1600. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1601. struct cfg80211_bss *cbss;
  1602. struct sk_buff *skb;
  1603. const u8 *ssid;
  1604. int ssid_len;
  1605. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1606. return NULL;
  1607. sdata_assert_lock(sdata);
  1608. if (ifmgd->associated)
  1609. cbss = ifmgd->associated;
  1610. else if (ifmgd->auth_data)
  1611. cbss = ifmgd->auth_data->bss;
  1612. else if (ifmgd->assoc_data)
  1613. cbss = ifmgd->assoc_data->bss;
  1614. else
  1615. return NULL;
  1616. rcu_read_lock();
  1617. ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
  1618. if (WARN_ON_ONCE(ssid == NULL))
  1619. ssid_len = 0;
  1620. else
  1621. ssid_len = ssid[1];
  1622. skb = ieee80211_build_probe_req(sdata, cbss->bssid,
  1623. (u32) -1, cbss->channel,
  1624. ssid + 2, ssid_len,
  1625. NULL, 0, true);
  1626. rcu_read_unlock();
  1627. return skb;
  1628. }
  1629. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  1630. static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
  1631. {
  1632. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1633. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  1634. sdata_lock(sdata);
  1635. if (!ifmgd->associated) {
  1636. sdata_unlock(sdata);
  1637. return;
  1638. }
  1639. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  1640. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  1641. true, frame_buf);
  1642. ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
  1643. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  1644. IEEE80211_MAX_QUEUE_MAP,
  1645. IEEE80211_QUEUE_STOP_REASON_CSA);
  1646. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  1647. IEEE80211_DEAUTH_FRAME_LEN);
  1648. sdata_unlock(sdata);
  1649. }
  1650. static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
  1651. {
  1652. struct ieee80211_sub_if_data *sdata =
  1653. container_of(work, struct ieee80211_sub_if_data,
  1654. u.mgd.beacon_connection_loss_work);
  1655. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1656. struct sta_info *sta;
  1657. if (ifmgd->associated) {
  1658. rcu_read_lock();
  1659. sta = sta_info_get(sdata, ifmgd->bssid);
  1660. if (sta)
  1661. sta->beacon_loss_count++;
  1662. rcu_read_unlock();
  1663. }
  1664. if (ifmgd->connection_loss) {
  1665. sdata_info(sdata, "Connection to AP %pM lost\n",
  1666. ifmgd->bssid);
  1667. __ieee80211_disconnect(sdata);
  1668. } else {
  1669. ieee80211_mgd_probe_ap(sdata, true);
  1670. }
  1671. }
  1672. static void ieee80211_csa_connection_drop_work(struct work_struct *work)
  1673. {
  1674. struct ieee80211_sub_if_data *sdata =
  1675. container_of(work, struct ieee80211_sub_if_data,
  1676. u.mgd.csa_connection_drop_work);
  1677. __ieee80211_disconnect(sdata);
  1678. }
  1679. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  1680. {
  1681. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1682. struct ieee80211_hw *hw = &sdata->local->hw;
  1683. trace_api_beacon_loss(sdata);
  1684. sdata->u.mgd.connection_loss = false;
  1685. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1686. }
  1687. EXPORT_SYMBOL(ieee80211_beacon_loss);
  1688. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  1689. {
  1690. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1691. struct ieee80211_hw *hw = &sdata->local->hw;
  1692. trace_api_connection_loss(sdata);
  1693. sdata->u.mgd.connection_loss = true;
  1694. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1695. }
  1696. EXPORT_SYMBOL(ieee80211_connection_loss);
  1697. static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
  1698. bool assoc)
  1699. {
  1700. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  1701. sdata_assert_lock(sdata);
  1702. if (!assoc) {
  1703. sta_info_destroy_addr(sdata, auth_data->bss->bssid);
  1704. memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
  1705. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  1706. sdata->u.mgd.flags = 0;
  1707. ieee80211_vif_release_channel(sdata);
  1708. }
  1709. cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
  1710. kfree(auth_data);
  1711. sdata->u.mgd.auth_data = NULL;
  1712. }
  1713. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  1714. struct ieee80211_mgmt *mgmt, size_t len)
  1715. {
  1716. struct ieee80211_local *local = sdata->local;
  1717. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  1718. u8 *pos;
  1719. struct ieee802_11_elems elems;
  1720. u32 tx_flags = 0;
  1721. pos = mgmt->u.auth.variable;
  1722. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  1723. if (!elems.challenge)
  1724. return;
  1725. auth_data->expected_transaction = 4;
  1726. drv_mgd_prepare_tx(sdata->local, sdata);
  1727. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  1728. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  1729. IEEE80211_TX_INTFL_MLME_CONN_TX;
  1730. ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
  1731. elems.challenge - 2, elems.challenge_len + 2,
  1732. auth_data->bss->bssid, auth_data->bss->bssid,
  1733. auth_data->key, auth_data->key_len,
  1734. auth_data->key_idx, tx_flags);
  1735. }
  1736. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  1737. struct ieee80211_mgmt *mgmt, size_t len)
  1738. {
  1739. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1740. u8 bssid[ETH_ALEN];
  1741. u16 auth_alg, auth_transaction, status_code;
  1742. struct sta_info *sta;
  1743. sdata_assert_lock(sdata);
  1744. if (len < 24 + 6)
  1745. return;
  1746. if (!ifmgd->auth_data || ifmgd->auth_data->done)
  1747. return;
  1748. memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
  1749. if (!ether_addr_equal(bssid, mgmt->bssid))
  1750. return;
  1751. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  1752. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  1753. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  1754. if (auth_alg != ifmgd->auth_data->algorithm ||
  1755. auth_transaction != ifmgd->auth_data->expected_transaction) {
  1756. sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
  1757. mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
  1758. auth_transaction,
  1759. ifmgd->auth_data->expected_transaction);
  1760. return;
  1761. }
  1762. if (status_code != WLAN_STATUS_SUCCESS) {
  1763. sdata_info(sdata, "%pM denied authentication (status %d)\n",
  1764. mgmt->sa, status_code);
  1765. ieee80211_destroy_auth_data(sdata, false);
  1766. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1767. return;
  1768. }
  1769. switch (ifmgd->auth_data->algorithm) {
  1770. case WLAN_AUTH_OPEN:
  1771. case WLAN_AUTH_LEAP:
  1772. case WLAN_AUTH_FT:
  1773. case WLAN_AUTH_SAE:
  1774. break;
  1775. case WLAN_AUTH_SHARED_KEY:
  1776. if (ifmgd->auth_data->expected_transaction != 4) {
  1777. ieee80211_auth_challenge(sdata, mgmt, len);
  1778. /* need another frame */
  1779. return;
  1780. }
  1781. break;
  1782. default:
  1783. WARN_ONCE(1, "invalid auth alg %d",
  1784. ifmgd->auth_data->algorithm);
  1785. return;
  1786. }
  1787. sdata_info(sdata, "authenticated\n");
  1788. ifmgd->auth_data->done = true;
  1789. ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
  1790. ifmgd->auth_data->timeout_started = true;
  1791. run_again(sdata, ifmgd->auth_data->timeout);
  1792. if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
  1793. ifmgd->auth_data->expected_transaction != 2) {
  1794. /*
  1795. * Report auth frame to user space for processing since another
  1796. * round of Authentication frames is still needed.
  1797. */
  1798. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1799. return;
  1800. }
  1801. /* move station state to auth */
  1802. mutex_lock(&sdata->local->sta_mtx);
  1803. sta = sta_info_get(sdata, bssid);
  1804. if (!sta) {
  1805. WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
  1806. goto out_err;
  1807. }
  1808. if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
  1809. sdata_info(sdata, "failed moving %pM to auth\n", bssid);
  1810. goto out_err;
  1811. }
  1812. mutex_unlock(&sdata->local->sta_mtx);
  1813. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1814. return;
  1815. out_err:
  1816. mutex_unlock(&sdata->local->sta_mtx);
  1817. /* ignore frame -- wait for timeout */
  1818. }
  1819. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1820. struct ieee80211_mgmt *mgmt, size_t len)
  1821. {
  1822. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1823. const u8 *bssid = NULL;
  1824. u16 reason_code;
  1825. sdata_assert_lock(sdata);
  1826. if (len < 24 + 2)
  1827. return;
  1828. if (!ifmgd->associated ||
  1829. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  1830. return;
  1831. bssid = ifmgd->associated->bssid;
  1832. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1833. sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
  1834. bssid, reason_code);
  1835. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  1836. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1837. }
  1838. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1839. struct ieee80211_mgmt *mgmt, size_t len)
  1840. {
  1841. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1842. u16 reason_code;
  1843. sdata_assert_lock(sdata);
  1844. if (len < 24 + 2)
  1845. return;
  1846. if (!ifmgd->associated ||
  1847. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  1848. return;
  1849. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1850. sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
  1851. mgmt->sa, reason_code);
  1852. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  1853. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  1854. }
  1855. static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
  1856. u8 *supp_rates, unsigned int supp_rates_len,
  1857. u32 *rates, u32 *basic_rates,
  1858. bool *have_higher_than_11mbit,
  1859. int *min_rate, int *min_rate_index,
  1860. int shift, u32 rate_flags)
  1861. {
  1862. int i, j;
  1863. for (i = 0; i < supp_rates_len; i++) {
  1864. int rate = supp_rates[i] & 0x7f;
  1865. bool is_basic = !!(supp_rates[i] & 0x80);
  1866. if ((rate * 5 * (1 << shift)) > 110)
  1867. *have_higher_than_11mbit = true;
  1868. /*
  1869. * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
  1870. * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
  1871. *
  1872. * Note: Even through the membership selector and the basic
  1873. * rate flag share the same bit, they are not exactly
  1874. * the same.
  1875. */
  1876. if (!!(supp_rates[i] & 0x80) &&
  1877. (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
  1878. continue;
  1879. for (j = 0; j < sband->n_bitrates; j++) {
  1880. struct ieee80211_rate *br;
  1881. int brate;
  1882. br = &sband->bitrates[j];
  1883. if ((rate_flags & br->flags) != rate_flags)
  1884. continue;
  1885. brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
  1886. if (brate == rate) {
  1887. *rates |= BIT(j);
  1888. if (is_basic)
  1889. *basic_rates |= BIT(j);
  1890. if ((rate * 5) < *min_rate) {
  1891. *min_rate = rate * 5;
  1892. *min_rate_index = j;
  1893. }
  1894. break;
  1895. }
  1896. }
  1897. }
  1898. }
  1899. static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
  1900. bool assoc)
  1901. {
  1902. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  1903. sdata_assert_lock(sdata);
  1904. if (!assoc) {
  1905. sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
  1906. memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
  1907. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  1908. sdata->u.mgd.flags = 0;
  1909. ieee80211_vif_release_channel(sdata);
  1910. }
  1911. kfree(assoc_data);
  1912. sdata->u.mgd.assoc_data = NULL;
  1913. }
  1914. static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
  1915. struct cfg80211_bss *cbss,
  1916. struct ieee80211_mgmt *mgmt, size_t len)
  1917. {
  1918. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1919. struct ieee80211_local *local = sdata->local;
  1920. struct ieee80211_supported_band *sband;
  1921. struct sta_info *sta;
  1922. u8 *pos;
  1923. u16 capab_info, aid;
  1924. struct ieee802_11_elems elems;
  1925. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1926. const struct cfg80211_bss_ies *bss_ies = NULL;
  1927. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  1928. u32 changed = 0;
  1929. int err;
  1930. bool ret;
  1931. /* AssocResp and ReassocResp have identical structure */
  1932. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1933. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1934. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1935. sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
  1936. aid);
  1937. aid &= ~(BIT(15) | BIT(14));
  1938. ifmgd->broken_ap = false;
  1939. if (aid == 0 || aid > IEEE80211_MAX_AID) {
  1940. sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
  1941. aid);
  1942. aid = 0;
  1943. ifmgd->broken_ap = true;
  1944. }
  1945. pos = mgmt->u.assoc_resp.variable;
  1946. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  1947. if (!elems.supp_rates) {
  1948. sdata_info(sdata, "no SuppRates element in AssocResp\n");
  1949. return false;
  1950. }
  1951. ifmgd->aid = aid;
  1952. /*
  1953. * Some APs are erroneously not including some information in their
  1954. * (re)association response frames. Try to recover by using the data
  1955. * from the beacon or probe response. This seems to afflict mobile
  1956. * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
  1957. * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
  1958. */
  1959. if ((assoc_data->wmm && !elems.wmm_param) ||
  1960. (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  1961. (!elems.ht_cap_elem || !elems.ht_operation)) ||
  1962. (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  1963. (!elems.vht_cap_elem || !elems.vht_operation))) {
  1964. const struct cfg80211_bss_ies *ies;
  1965. struct ieee802_11_elems bss_elems;
  1966. rcu_read_lock();
  1967. ies = rcu_dereference(cbss->ies);
  1968. if (ies)
  1969. bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
  1970. GFP_ATOMIC);
  1971. rcu_read_unlock();
  1972. if (!bss_ies)
  1973. return false;
  1974. ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
  1975. false, &bss_elems);
  1976. if (assoc_data->wmm &&
  1977. !elems.wmm_param && bss_elems.wmm_param) {
  1978. elems.wmm_param = bss_elems.wmm_param;
  1979. sdata_info(sdata,
  1980. "AP bug: WMM param missing from AssocResp\n");
  1981. }
  1982. /*
  1983. * Also check if we requested HT/VHT, otherwise the AP doesn't
  1984. * have to include the IEs in the (re)association response.
  1985. */
  1986. if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
  1987. !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
  1988. elems.ht_cap_elem = bss_elems.ht_cap_elem;
  1989. sdata_info(sdata,
  1990. "AP bug: HT capability missing from AssocResp\n");
  1991. }
  1992. if (!elems.ht_operation && bss_elems.ht_operation &&
  1993. !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
  1994. elems.ht_operation = bss_elems.ht_operation;
  1995. sdata_info(sdata,
  1996. "AP bug: HT operation missing from AssocResp\n");
  1997. }
  1998. if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
  1999. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
  2000. elems.vht_cap_elem = bss_elems.vht_cap_elem;
  2001. sdata_info(sdata,
  2002. "AP bug: VHT capa missing from AssocResp\n");
  2003. }
  2004. if (!elems.vht_operation && bss_elems.vht_operation &&
  2005. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
  2006. elems.vht_operation = bss_elems.vht_operation;
  2007. sdata_info(sdata,
  2008. "AP bug: VHT operation missing from AssocResp\n");
  2009. }
  2010. }
  2011. /*
  2012. * We previously checked these in the beacon/probe response, so
  2013. * they should be present here. This is just a safety net.
  2014. */
  2015. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  2016. (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
  2017. sdata_info(sdata,
  2018. "HT AP is missing WMM params or HT capability/operation\n");
  2019. ret = false;
  2020. goto out;
  2021. }
  2022. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  2023. (!elems.vht_cap_elem || !elems.vht_operation)) {
  2024. sdata_info(sdata,
  2025. "VHT AP is missing VHT capability/operation\n");
  2026. ret = false;
  2027. goto out;
  2028. }
  2029. mutex_lock(&sdata->local->sta_mtx);
  2030. /*
  2031. * station info was already allocated and inserted before
  2032. * the association and should be available to us
  2033. */
  2034. sta = sta_info_get(sdata, cbss->bssid);
  2035. if (WARN_ON(!sta)) {
  2036. mutex_unlock(&sdata->local->sta_mtx);
  2037. ret = false;
  2038. goto out;
  2039. }
  2040. sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
  2041. /* Set up internal HT/VHT capabilities */
  2042. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
  2043. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  2044. elems.ht_cap_elem, sta);
  2045. if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  2046. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  2047. elems.vht_cap_elem, sta);
  2048. /*
  2049. * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
  2050. * in their association response, so ignore that data for our own
  2051. * configuration. If it changed since the last beacon, we'll get the
  2052. * next beacon and update then.
  2053. */
  2054. /*
  2055. * If an operating mode notification IE is present, override the
  2056. * NSS calculation (that would be done in rate_control_rate_init())
  2057. * and use the # of streams from that element.
  2058. */
  2059. if (elems.opmode_notif &&
  2060. !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
  2061. u8 nss;
  2062. nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  2063. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  2064. nss += 1;
  2065. sta->sta.rx_nss = nss;
  2066. }
  2067. rate_control_rate_init(sta);
  2068. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  2069. set_sta_flag(sta, WLAN_STA_MFP);
  2070. if (elems.wmm_param)
  2071. set_sta_flag(sta, WLAN_STA_WME);
  2072. err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  2073. if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  2074. err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  2075. if (err) {
  2076. sdata_info(sdata,
  2077. "failed to move station %pM to desired state\n",
  2078. sta->sta.addr);
  2079. WARN_ON(__sta_info_destroy(sta));
  2080. mutex_unlock(&sdata->local->sta_mtx);
  2081. ret = false;
  2082. goto out;
  2083. }
  2084. mutex_unlock(&sdata->local->sta_mtx);
  2085. /*
  2086. * Always handle WMM once after association regardless
  2087. * of the first value the AP uses. Setting -1 here has
  2088. * that effect because the AP values is an unsigned
  2089. * 4-bit value.
  2090. */
  2091. ifmgd->wmm_last_param_set = -1;
  2092. if (elems.wmm_param)
  2093. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  2094. elems.wmm_param_len);
  2095. else
  2096. ieee80211_set_wmm_default(sdata, false);
  2097. changed |= BSS_CHANGED_QOS;
  2098. /* set AID and assoc capability,
  2099. * ieee80211_set_associated() will tell the driver */
  2100. bss_conf->aid = aid;
  2101. bss_conf->assoc_capability = capab_info;
  2102. ieee80211_set_associated(sdata, cbss, changed);
  2103. /*
  2104. * If we're using 4-addr mode, let the AP know that we're
  2105. * doing so, so that it can create the STA VLAN on its side
  2106. */
  2107. if (ifmgd->use_4addr)
  2108. ieee80211_send_4addr_nullfunc(local, sdata);
  2109. /*
  2110. * Start timer to probe the connection to the AP now.
  2111. * Also start the timer that will detect beacon loss.
  2112. */
  2113. ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
  2114. ieee80211_sta_reset_beacon_monitor(sdata);
  2115. ret = true;
  2116. out:
  2117. kfree(bss_ies);
  2118. return ret;
  2119. }
  2120. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  2121. struct ieee80211_mgmt *mgmt,
  2122. size_t len)
  2123. {
  2124. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2125. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  2126. u16 capab_info, status_code, aid;
  2127. struct ieee802_11_elems elems;
  2128. u8 *pos;
  2129. bool reassoc;
  2130. struct cfg80211_bss *bss;
  2131. sdata_assert_lock(sdata);
  2132. if (!assoc_data)
  2133. return;
  2134. if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
  2135. return;
  2136. /*
  2137. * AssocResp and ReassocResp have identical structure, so process both
  2138. * of them in this function.
  2139. */
  2140. if (len < 24 + 6)
  2141. return;
  2142. reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
  2143. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  2144. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  2145. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  2146. sdata_info(sdata,
  2147. "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
  2148. reassoc ? "Rea" : "A", mgmt->sa,
  2149. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  2150. pos = mgmt->u.assoc_resp.variable;
  2151. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  2152. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  2153. elems.timeout_int &&
  2154. elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  2155. u32 tu, ms;
  2156. tu = le32_to_cpu(elems.timeout_int->value);
  2157. ms = tu * 1024 / 1000;
  2158. sdata_info(sdata,
  2159. "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
  2160. mgmt->sa, tu, ms);
  2161. assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
  2162. assoc_data->timeout_started = true;
  2163. if (ms > IEEE80211_ASSOC_TIMEOUT)
  2164. run_again(sdata, assoc_data->timeout);
  2165. return;
  2166. }
  2167. bss = assoc_data->bss;
  2168. if (status_code != WLAN_STATUS_SUCCESS) {
  2169. sdata_info(sdata, "%pM denied association (code=%d)\n",
  2170. mgmt->sa, status_code);
  2171. ieee80211_destroy_assoc_data(sdata, false);
  2172. } else {
  2173. if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
  2174. /* oops -- internal error -- send timeout for now */
  2175. ieee80211_destroy_assoc_data(sdata, false);
  2176. cfg80211_assoc_timeout(sdata->dev, bss);
  2177. return;
  2178. }
  2179. sdata_info(sdata, "associated\n");
  2180. /*
  2181. * destroy assoc_data afterwards, as otherwise an idle
  2182. * recalc after assoc_data is NULL but before associated
  2183. * is set can cause the interface to go idle
  2184. */
  2185. ieee80211_destroy_assoc_data(sdata, true);
  2186. }
  2187. cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len);
  2188. }
  2189. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  2190. struct ieee80211_mgmt *mgmt, size_t len,
  2191. struct ieee80211_rx_status *rx_status,
  2192. struct ieee802_11_elems *elems)
  2193. {
  2194. struct ieee80211_local *local = sdata->local;
  2195. int freq;
  2196. struct ieee80211_bss *bss;
  2197. struct ieee80211_channel *channel;
  2198. sdata_assert_lock(sdata);
  2199. if (elems->ds_params)
  2200. freq = ieee80211_channel_to_frequency(elems->ds_params[0],
  2201. rx_status->band);
  2202. else
  2203. freq = rx_status->freq;
  2204. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  2205. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  2206. return;
  2207. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  2208. channel);
  2209. if (bss) {
  2210. ieee80211_rx_bss_put(local, bss);
  2211. sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
  2212. }
  2213. }
  2214. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  2215. struct sk_buff *skb)
  2216. {
  2217. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  2218. struct ieee80211_if_managed *ifmgd;
  2219. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  2220. size_t baselen, len = skb->len;
  2221. struct ieee802_11_elems elems;
  2222. ifmgd = &sdata->u.mgd;
  2223. sdata_assert_lock(sdata);
  2224. if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
  2225. return; /* ignore ProbeResp to foreign address */
  2226. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  2227. if (baselen > len)
  2228. return;
  2229. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  2230. false, &elems);
  2231. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  2232. if (ifmgd->associated &&
  2233. ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  2234. ieee80211_reset_ap_probe(sdata);
  2235. if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
  2236. ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
  2237. /* got probe response, continue with auth */
  2238. sdata_info(sdata, "direct probe responded\n");
  2239. ifmgd->auth_data->tries = 0;
  2240. ifmgd->auth_data->timeout = jiffies;
  2241. ifmgd->auth_data->timeout_started = true;
  2242. run_again(sdata, ifmgd->auth_data->timeout);
  2243. }
  2244. }
  2245. /*
  2246. * This is the canonical list of information elements we care about,
  2247. * the filter code also gives us all changes to the Microsoft OUI
  2248. * (00:50:F2) vendor IE which is used for WMM which we need to track.
  2249. *
  2250. * We implement beacon filtering in software since that means we can
  2251. * avoid processing the frame here and in cfg80211, and userspace
  2252. * will not be able to tell whether the hardware supports it or not.
  2253. *
  2254. * XXX: This list needs to be dynamic -- userspace needs to be able to
  2255. * add items it requires. It also needs to be able to tell us to
  2256. * look out for other vendor IEs.
  2257. */
  2258. static const u64 care_about_ies =
  2259. (1ULL << WLAN_EID_COUNTRY) |
  2260. (1ULL << WLAN_EID_ERP_INFO) |
  2261. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  2262. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  2263. (1ULL << WLAN_EID_HT_CAPABILITY) |
  2264. (1ULL << WLAN_EID_HT_OPERATION);
  2265. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  2266. struct ieee80211_mgmt *mgmt, size_t len,
  2267. struct ieee80211_rx_status *rx_status)
  2268. {
  2269. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2270. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  2271. size_t baselen;
  2272. struct ieee802_11_elems elems;
  2273. struct ieee80211_local *local = sdata->local;
  2274. struct ieee80211_chanctx_conf *chanctx_conf;
  2275. struct ieee80211_channel *chan;
  2276. struct sta_info *sta;
  2277. u32 changed = 0;
  2278. bool erp_valid;
  2279. u8 erp_value = 0;
  2280. u32 ncrc;
  2281. u8 *bssid;
  2282. u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
  2283. sdata_assert_lock(sdata);
  2284. /* Process beacon from the current BSS */
  2285. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  2286. if (baselen > len)
  2287. return;
  2288. rcu_read_lock();
  2289. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2290. if (!chanctx_conf) {
  2291. rcu_read_unlock();
  2292. return;
  2293. }
  2294. if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
  2295. rcu_read_unlock();
  2296. return;
  2297. }
  2298. chan = chanctx_conf->def.chan;
  2299. rcu_read_unlock();
  2300. if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
  2301. ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
  2302. ieee802_11_parse_elems(mgmt->u.beacon.variable,
  2303. len - baselen, false, &elems);
  2304. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  2305. if (elems.tim && !elems.parse_error) {
  2306. const struct ieee80211_tim_ie *tim_ie = elems.tim;
  2307. ifmgd->dtim_period = tim_ie->dtim_period;
  2308. }
  2309. ifmgd->have_beacon = true;
  2310. ifmgd->assoc_data->need_beacon = false;
  2311. if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
  2312. sdata->vif.bss_conf.sync_tsf =
  2313. le64_to_cpu(mgmt->u.beacon.timestamp);
  2314. sdata->vif.bss_conf.sync_device_ts =
  2315. rx_status->device_timestamp;
  2316. if (elems.tim)
  2317. sdata->vif.bss_conf.sync_dtim_count =
  2318. elems.tim->dtim_count;
  2319. else
  2320. sdata->vif.bss_conf.sync_dtim_count = 0;
  2321. }
  2322. /* continue assoc process */
  2323. ifmgd->assoc_data->timeout = jiffies;
  2324. ifmgd->assoc_data->timeout_started = true;
  2325. run_again(sdata, ifmgd->assoc_data->timeout);
  2326. return;
  2327. }
  2328. if (!ifmgd->associated ||
  2329. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  2330. return;
  2331. bssid = ifmgd->associated->bssid;
  2332. /* Track average RSSI from the Beacon frames of the current AP */
  2333. ifmgd->last_beacon_signal = rx_status->signal;
  2334. if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
  2335. ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
  2336. ifmgd->ave_beacon_signal = rx_status->signal * 16;
  2337. ifmgd->last_cqm_event_signal = 0;
  2338. ifmgd->count_beacon_signal = 1;
  2339. ifmgd->last_ave_beacon_signal = 0;
  2340. } else {
  2341. ifmgd->ave_beacon_signal =
  2342. (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
  2343. (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
  2344. ifmgd->ave_beacon_signal) / 16;
  2345. ifmgd->count_beacon_signal++;
  2346. }
  2347. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  2348. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  2349. int sig = ifmgd->ave_beacon_signal;
  2350. int last_sig = ifmgd->last_ave_beacon_signal;
  2351. /*
  2352. * if signal crosses either of the boundaries, invoke callback
  2353. * with appropriate parameters
  2354. */
  2355. if (sig > ifmgd->rssi_max_thold &&
  2356. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  2357. ifmgd->last_ave_beacon_signal = sig;
  2358. drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
  2359. } else if (sig < ifmgd->rssi_min_thold &&
  2360. (last_sig >= ifmgd->rssi_max_thold ||
  2361. last_sig == 0)) {
  2362. ifmgd->last_ave_beacon_signal = sig;
  2363. drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
  2364. }
  2365. }
  2366. if (bss_conf->cqm_rssi_thold &&
  2367. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  2368. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
  2369. int sig = ifmgd->ave_beacon_signal / 16;
  2370. int last_event = ifmgd->last_cqm_event_signal;
  2371. int thold = bss_conf->cqm_rssi_thold;
  2372. int hyst = bss_conf->cqm_rssi_hyst;
  2373. if (sig < thold &&
  2374. (last_event == 0 || sig < last_event - hyst)) {
  2375. ifmgd->last_cqm_event_signal = sig;
  2376. ieee80211_cqm_rssi_notify(
  2377. &sdata->vif,
  2378. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  2379. GFP_KERNEL);
  2380. } else if (sig > thold &&
  2381. (last_event == 0 || sig > last_event + hyst)) {
  2382. ifmgd->last_cqm_event_signal = sig;
  2383. ieee80211_cqm_rssi_notify(
  2384. &sdata->vif,
  2385. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  2386. GFP_KERNEL);
  2387. }
  2388. }
  2389. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
  2390. mlme_dbg_ratelimited(sdata,
  2391. "cancelling AP probe due to a received beacon\n");
  2392. ieee80211_reset_ap_probe(sdata);
  2393. }
  2394. /*
  2395. * Push the beacon loss detection into the future since
  2396. * we are processing a beacon from the AP just now.
  2397. */
  2398. ieee80211_sta_reset_beacon_monitor(sdata);
  2399. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  2400. ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
  2401. len - baselen, false, &elems,
  2402. care_about_ies, ncrc);
  2403. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  2404. bool directed_tim = ieee80211_check_tim(elems.tim,
  2405. elems.tim_len,
  2406. ifmgd->aid);
  2407. if (directed_tim) {
  2408. if (local->hw.conf.dynamic_ps_timeout > 0) {
  2409. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  2410. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  2411. ieee80211_hw_config(local,
  2412. IEEE80211_CONF_CHANGE_PS);
  2413. }
  2414. ieee80211_send_nullfunc(local, sdata, 0);
  2415. } else if (!local->pspolling && sdata->u.mgd.powersave) {
  2416. local->pspolling = true;
  2417. /*
  2418. * Here is assumed that the driver will be
  2419. * able to send ps-poll frame and receive a
  2420. * response even though power save mode is
  2421. * enabled, but some drivers might require
  2422. * to disable power save here. This needs
  2423. * to be investigated.
  2424. */
  2425. ieee80211_send_pspoll(local, sdata);
  2426. }
  2427. }
  2428. }
  2429. if (sdata->vif.p2p) {
  2430. struct ieee80211_p2p_noa_attr noa = {};
  2431. int ret;
  2432. ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
  2433. len - baselen,
  2434. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  2435. (u8 *) &noa, sizeof(noa));
  2436. if (ret >= 2) {
  2437. if (sdata->u.mgd.p2p_noa_index != noa.index) {
  2438. /* valid noa_attr and index changed */
  2439. sdata->u.mgd.p2p_noa_index = noa.index;
  2440. memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
  2441. changed |= BSS_CHANGED_P2P_PS;
  2442. /*
  2443. * make sure we update all information, the CRC
  2444. * mechanism doesn't look at P2P attributes.
  2445. */
  2446. ifmgd->beacon_crc_valid = false;
  2447. }
  2448. } else if (sdata->u.mgd.p2p_noa_index != -1) {
  2449. /* noa_attr not found and we had valid noa_attr before */
  2450. sdata->u.mgd.p2p_noa_index = -1;
  2451. memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
  2452. changed |= BSS_CHANGED_P2P_PS;
  2453. ifmgd->beacon_crc_valid = false;
  2454. }
  2455. }
  2456. if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
  2457. return;
  2458. ifmgd->beacon_crc = ncrc;
  2459. ifmgd->beacon_crc_valid = true;
  2460. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  2461. ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
  2462. &elems, true);
  2463. if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  2464. elems.wmm_param_len))
  2465. changed |= BSS_CHANGED_QOS;
  2466. /*
  2467. * If we haven't had a beacon before, tell the driver about the
  2468. * DTIM period (and beacon timing if desired) now.
  2469. */
  2470. if (!ifmgd->have_beacon) {
  2471. /* a few bogus AP send dtim_period = 0 or no TIM IE */
  2472. if (elems.tim)
  2473. bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
  2474. else
  2475. bss_conf->dtim_period = 1;
  2476. if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
  2477. sdata->vif.bss_conf.sync_tsf =
  2478. le64_to_cpu(mgmt->u.beacon.timestamp);
  2479. sdata->vif.bss_conf.sync_device_ts =
  2480. rx_status->device_timestamp;
  2481. if (elems.tim)
  2482. sdata->vif.bss_conf.sync_dtim_count =
  2483. elems.tim->dtim_count;
  2484. else
  2485. sdata->vif.bss_conf.sync_dtim_count = 0;
  2486. }
  2487. changed |= BSS_CHANGED_BEACON_INFO;
  2488. ifmgd->have_beacon = true;
  2489. mutex_lock(&local->iflist_mtx);
  2490. ieee80211_recalc_ps(local, -1);
  2491. mutex_unlock(&local->iflist_mtx);
  2492. ieee80211_recalc_ps_vif(sdata);
  2493. }
  2494. if (elems.erp_info) {
  2495. erp_valid = true;
  2496. erp_value = elems.erp_info[0];
  2497. } else {
  2498. erp_valid = false;
  2499. }
  2500. changed |= ieee80211_handle_bss_capability(sdata,
  2501. le16_to_cpu(mgmt->u.beacon.capab_info),
  2502. erp_valid, erp_value);
  2503. mutex_lock(&local->sta_mtx);
  2504. sta = sta_info_get(sdata, bssid);
  2505. if (ieee80211_config_bw(sdata, sta, elems.ht_operation,
  2506. elems.vht_operation, bssid, &changed)) {
  2507. mutex_unlock(&local->sta_mtx);
  2508. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  2509. WLAN_REASON_DEAUTH_LEAVING,
  2510. true, deauth_buf);
  2511. cfg80211_tx_mlme_mgmt(sdata->dev, deauth_buf,
  2512. sizeof(deauth_buf));
  2513. return;
  2514. }
  2515. if (sta && elems.opmode_notif)
  2516. ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
  2517. rx_status->band, true);
  2518. mutex_unlock(&local->sta_mtx);
  2519. if (elems.country_elem && elems.pwr_constr_elem &&
  2520. mgmt->u.probe_resp.capab_info &
  2521. cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
  2522. changed |= ieee80211_handle_pwr_constr(sdata, chan,
  2523. elems.country_elem,
  2524. elems.country_elem_len,
  2525. elems.pwr_constr_elem);
  2526. ieee80211_bss_info_change_notify(sdata, changed);
  2527. }
  2528. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  2529. struct sk_buff *skb)
  2530. {
  2531. struct ieee80211_rx_status *rx_status;
  2532. struct ieee80211_mgmt *mgmt;
  2533. u16 fc;
  2534. struct ieee802_11_elems elems;
  2535. int ies_len;
  2536. rx_status = (struct ieee80211_rx_status *) skb->cb;
  2537. mgmt = (struct ieee80211_mgmt *) skb->data;
  2538. fc = le16_to_cpu(mgmt->frame_control);
  2539. sdata_lock(sdata);
  2540. switch (fc & IEEE80211_FCTL_STYPE) {
  2541. case IEEE80211_STYPE_BEACON:
  2542. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
  2543. break;
  2544. case IEEE80211_STYPE_PROBE_RESP:
  2545. ieee80211_rx_mgmt_probe_resp(sdata, skb);
  2546. break;
  2547. case IEEE80211_STYPE_AUTH:
  2548. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  2549. break;
  2550. case IEEE80211_STYPE_DEAUTH:
  2551. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  2552. break;
  2553. case IEEE80211_STYPE_DISASSOC:
  2554. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  2555. break;
  2556. case IEEE80211_STYPE_ASSOC_RESP:
  2557. case IEEE80211_STYPE_REASSOC_RESP:
  2558. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
  2559. break;
  2560. case IEEE80211_STYPE_ACTION:
  2561. if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
  2562. ies_len = skb->len -
  2563. offsetof(struct ieee80211_mgmt,
  2564. u.action.u.chan_switch.variable);
  2565. if (ies_len < 0)
  2566. break;
  2567. ieee802_11_parse_elems(
  2568. mgmt->u.action.u.chan_switch.variable,
  2569. ies_len, true, &elems);
  2570. if (elems.parse_error)
  2571. break;
  2572. ieee80211_sta_process_chanswitch(sdata,
  2573. rx_status->mactime,
  2574. &elems, false);
  2575. } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
  2576. ies_len = skb->len -
  2577. offsetof(struct ieee80211_mgmt,
  2578. u.action.u.ext_chan_switch.variable);
  2579. if (ies_len < 0)
  2580. break;
  2581. ieee802_11_parse_elems(
  2582. mgmt->u.action.u.ext_chan_switch.variable,
  2583. ies_len, true, &elems);
  2584. if (elems.parse_error)
  2585. break;
  2586. /* for the handling code pretend this was also an IE */
  2587. elems.ext_chansw_ie =
  2588. &mgmt->u.action.u.ext_chan_switch.data;
  2589. ieee80211_sta_process_chanswitch(sdata,
  2590. rx_status->mactime,
  2591. &elems, false);
  2592. }
  2593. break;
  2594. }
  2595. sdata_unlock(sdata);
  2596. }
  2597. static void ieee80211_sta_timer(unsigned long data)
  2598. {
  2599. struct ieee80211_sub_if_data *sdata =
  2600. (struct ieee80211_sub_if_data *) data;
  2601. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  2602. }
  2603. static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  2604. u8 *bssid, u8 reason, bool tx)
  2605. {
  2606. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  2607. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
  2608. tx, frame_buf);
  2609. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  2610. IEEE80211_DEAUTH_FRAME_LEN);
  2611. }
  2612. static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
  2613. {
  2614. struct ieee80211_local *local = sdata->local;
  2615. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2616. struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
  2617. u32 tx_flags = 0;
  2618. sdata_assert_lock(sdata);
  2619. if (WARN_ON_ONCE(!auth_data))
  2620. return -EINVAL;
  2621. auth_data->tries++;
  2622. if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
  2623. sdata_info(sdata, "authentication with %pM timed out\n",
  2624. auth_data->bss->bssid);
  2625. /*
  2626. * Most likely AP is not in the range so remove the
  2627. * bss struct for that AP.
  2628. */
  2629. cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
  2630. return -ETIMEDOUT;
  2631. }
  2632. drv_mgd_prepare_tx(local, sdata);
  2633. if (auth_data->bss->proberesp_ies) {
  2634. u16 trans = 1;
  2635. u16 status = 0;
  2636. sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
  2637. auth_data->bss->bssid, auth_data->tries,
  2638. IEEE80211_AUTH_MAX_TRIES);
  2639. auth_data->expected_transaction = 2;
  2640. if (auth_data->algorithm == WLAN_AUTH_SAE) {
  2641. trans = auth_data->sae_trans;
  2642. status = auth_data->sae_status;
  2643. auth_data->expected_transaction = trans;
  2644. }
  2645. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  2646. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  2647. IEEE80211_TX_INTFL_MLME_CONN_TX;
  2648. ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
  2649. auth_data->data, auth_data->data_len,
  2650. auth_data->bss->bssid,
  2651. auth_data->bss->bssid, NULL, 0, 0,
  2652. tx_flags);
  2653. } else {
  2654. const u8 *ssidie;
  2655. sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
  2656. auth_data->bss->bssid, auth_data->tries,
  2657. IEEE80211_AUTH_MAX_TRIES);
  2658. rcu_read_lock();
  2659. ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
  2660. if (!ssidie) {
  2661. rcu_read_unlock();
  2662. return -EINVAL;
  2663. }
  2664. /*
  2665. * Direct probe is sent to broadcast address as some APs
  2666. * will not answer to direct packet in unassociated state.
  2667. */
  2668. ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
  2669. NULL, 0, (u32) -1, true, 0,
  2670. auth_data->bss->channel, false);
  2671. rcu_read_unlock();
  2672. }
  2673. if (tx_flags == 0) {
  2674. auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  2675. auth_data->timeout_started = true;
  2676. run_again(sdata, auth_data->timeout);
  2677. } else {
  2678. auth_data->timeout =
  2679. round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
  2680. auth_data->timeout_started = true;
  2681. run_again(sdata, auth_data->timeout);
  2682. }
  2683. return 0;
  2684. }
  2685. static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
  2686. {
  2687. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  2688. struct ieee80211_local *local = sdata->local;
  2689. sdata_assert_lock(sdata);
  2690. assoc_data->tries++;
  2691. if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
  2692. sdata_info(sdata, "association with %pM timed out\n",
  2693. assoc_data->bss->bssid);
  2694. /*
  2695. * Most likely AP is not in the range so remove the
  2696. * bss struct for that AP.
  2697. */
  2698. cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
  2699. return -ETIMEDOUT;
  2700. }
  2701. sdata_info(sdata, "associate with %pM (try %d/%d)\n",
  2702. assoc_data->bss->bssid, assoc_data->tries,
  2703. IEEE80211_ASSOC_MAX_TRIES);
  2704. ieee80211_send_assoc(sdata);
  2705. if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
  2706. assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
  2707. assoc_data->timeout_started = true;
  2708. run_again(sdata, assoc_data->timeout);
  2709. } else {
  2710. assoc_data->timeout =
  2711. round_jiffies_up(jiffies +
  2712. IEEE80211_ASSOC_TIMEOUT_LONG);
  2713. assoc_data->timeout_started = true;
  2714. run_again(sdata, assoc_data->timeout);
  2715. }
  2716. return 0;
  2717. }
  2718. void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
  2719. __le16 fc, bool acked)
  2720. {
  2721. struct ieee80211_local *local = sdata->local;
  2722. sdata->u.mgd.status_fc = fc;
  2723. sdata->u.mgd.status_acked = acked;
  2724. sdata->u.mgd.status_received = true;
  2725. ieee80211_queue_work(&local->hw, &sdata->work);
  2726. }
  2727. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  2728. {
  2729. struct ieee80211_local *local = sdata->local;
  2730. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2731. sdata_lock(sdata);
  2732. if (ifmgd->status_received) {
  2733. __le16 fc = ifmgd->status_fc;
  2734. bool status_acked = ifmgd->status_acked;
  2735. ifmgd->status_received = false;
  2736. if (ifmgd->auth_data &&
  2737. (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
  2738. if (status_acked) {
  2739. ifmgd->auth_data->timeout =
  2740. jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
  2741. run_again(sdata, ifmgd->auth_data->timeout);
  2742. } else {
  2743. ifmgd->auth_data->timeout = jiffies - 1;
  2744. }
  2745. ifmgd->auth_data->timeout_started = true;
  2746. } else if (ifmgd->assoc_data &&
  2747. (ieee80211_is_assoc_req(fc) ||
  2748. ieee80211_is_reassoc_req(fc))) {
  2749. if (status_acked) {
  2750. ifmgd->assoc_data->timeout =
  2751. jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
  2752. run_again(sdata, ifmgd->assoc_data->timeout);
  2753. } else {
  2754. ifmgd->assoc_data->timeout = jiffies - 1;
  2755. }
  2756. ifmgd->assoc_data->timeout_started = true;
  2757. }
  2758. }
  2759. if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
  2760. time_after(jiffies, ifmgd->auth_data->timeout)) {
  2761. if (ifmgd->auth_data->done) {
  2762. /*
  2763. * ok ... we waited for assoc but userspace didn't,
  2764. * so let's just kill the auth data
  2765. */
  2766. ieee80211_destroy_auth_data(sdata, false);
  2767. } else if (ieee80211_probe_auth(sdata)) {
  2768. u8 bssid[ETH_ALEN];
  2769. memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
  2770. ieee80211_destroy_auth_data(sdata, false);
  2771. cfg80211_auth_timeout(sdata->dev, bssid);
  2772. }
  2773. } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
  2774. run_again(sdata, ifmgd->auth_data->timeout);
  2775. if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
  2776. time_after(jiffies, ifmgd->assoc_data->timeout)) {
  2777. if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
  2778. ieee80211_do_assoc(sdata)) {
  2779. struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
  2780. ieee80211_destroy_assoc_data(sdata, false);
  2781. cfg80211_assoc_timeout(sdata->dev, bss);
  2782. }
  2783. } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
  2784. run_again(sdata, ifmgd->assoc_data->timeout);
  2785. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
  2786. ifmgd->associated) {
  2787. u8 bssid[ETH_ALEN];
  2788. int max_tries;
  2789. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  2790. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  2791. max_tries = max_nullfunc_tries;
  2792. else
  2793. max_tries = max_probe_tries;
  2794. /* ACK received for nullfunc probing frame */
  2795. if (!ifmgd->probe_send_count)
  2796. ieee80211_reset_ap_probe(sdata);
  2797. else if (ifmgd->nullfunc_failed) {
  2798. if (ifmgd->probe_send_count < max_tries) {
  2799. mlme_dbg(sdata,
  2800. "No ack for nullfunc frame to AP %pM, try %d/%i\n",
  2801. bssid, ifmgd->probe_send_count,
  2802. max_tries);
  2803. ieee80211_mgd_probe_ap_send(sdata);
  2804. } else {
  2805. mlme_dbg(sdata,
  2806. "No ack for nullfunc frame to AP %pM, disconnecting.\n",
  2807. bssid);
  2808. ieee80211_sta_connection_lost(sdata, bssid,
  2809. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  2810. false);
  2811. }
  2812. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  2813. run_again(sdata, ifmgd->probe_timeout);
  2814. else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  2815. mlme_dbg(sdata,
  2816. "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
  2817. bssid, probe_wait_ms);
  2818. ieee80211_sta_connection_lost(sdata, bssid,
  2819. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  2820. } else if (ifmgd->probe_send_count < max_tries) {
  2821. mlme_dbg(sdata,
  2822. "No probe response from AP %pM after %dms, try %d/%i\n",
  2823. bssid, probe_wait_ms,
  2824. ifmgd->probe_send_count, max_tries);
  2825. ieee80211_mgd_probe_ap_send(sdata);
  2826. } else {
  2827. /*
  2828. * We actually lost the connection ... or did we?
  2829. * Let's make sure!
  2830. */
  2831. wiphy_debug(local->hw.wiphy,
  2832. "%s: No probe response from AP %pM"
  2833. " after %dms, disconnecting.\n",
  2834. sdata->name,
  2835. bssid, probe_wait_ms);
  2836. ieee80211_sta_connection_lost(sdata, bssid,
  2837. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  2838. }
  2839. }
  2840. sdata_unlock(sdata);
  2841. }
  2842. static void ieee80211_sta_bcn_mon_timer(unsigned long data)
  2843. {
  2844. struct ieee80211_sub_if_data *sdata =
  2845. (struct ieee80211_sub_if_data *) data;
  2846. struct ieee80211_local *local = sdata->local;
  2847. if (local->quiescing)
  2848. return;
  2849. sdata->u.mgd.connection_loss = false;
  2850. ieee80211_queue_work(&sdata->local->hw,
  2851. &sdata->u.mgd.beacon_connection_loss_work);
  2852. }
  2853. static void ieee80211_sta_conn_mon_timer(unsigned long data)
  2854. {
  2855. struct ieee80211_sub_if_data *sdata =
  2856. (struct ieee80211_sub_if_data *) data;
  2857. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2858. struct ieee80211_local *local = sdata->local;
  2859. if (local->quiescing)
  2860. return;
  2861. ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
  2862. }
  2863. static void ieee80211_sta_monitor_work(struct work_struct *work)
  2864. {
  2865. struct ieee80211_sub_if_data *sdata =
  2866. container_of(work, struct ieee80211_sub_if_data,
  2867. u.mgd.monitor_work);
  2868. ieee80211_mgd_probe_ap(sdata, false);
  2869. }
  2870. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  2871. {
  2872. u32 flags;
  2873. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  2874. __ieee80211_stop_poll(sdata);
  2875. /* let's probe the connection once */
  2876. flags = sdata->local->hw.flags;
  2877. if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
  2878. ieee80211_queue_work(&sdata->local->hw,
  2879. &sdata->u.mgd.monitor_work);
  2880. /* and do all the other regular work too */
  2881. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  2882. }
  2883. }
  2884. #ifdef CONFIG_PM
  2885. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  2886. {
  2887. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2888. sdata_lock(sdata);
  2889. if (!ifmgd->associated) {
  2890. sdata_unlock(sdata);
  2891. return;
  2892. }
  2893. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  2894. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  2895. mlme_dbg(sdata, "driver requested disconnect after resume\n");
  2896. ieee80211_sta_connection_lost(sdata,
  2897. ifmgd->associated->bssid,
  2898. WLAN_REASON_UNSPECIFIED,
  2899. true);
  2900. sdata_unlock(sdata);
  2901. return;
  2902. }
  2903. sdata_unlock(sdata);
  2904. }
  2905. #endif
  2906. /* interface setup */
  2907. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  2908. {
  2909. struct ieee80211_if_managed *ifmgd;
  2910. ifmgd = &sdata->u.mgd;
  2911. INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  2912. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  2913. INIT_WORK(&ifmgd->beacon_connection_loss_work,
  2914. ieee80211_beacon_connection_loss_work);
  2915. INIT_WORK(&ifmgd->csa_connection_drop_work,
  2916. ieee80211_csa_connection_drop_work);
  2917. INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
  2918. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  2919. (unsigned long) sdata);
  2920. setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
  2921. (unsigned long) sdata);
  2922. setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
  2923. (unsigned long) sdata);
  2924. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  2925. (unsigned long) sdata);
  2926. ifmgd->flags = 0;
  2927. ifmgd->powersave = sdata->wdev.ps;
  2928. ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
  2929. ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
  2930. ifmgd->p2p_noa_index = -1;
  2931. if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
  2932. ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
  2933. else
  2934. ifmgd->req_smps = IEEE80211_SMPS_OFF;
  2935. }
  2936. /* scan finished notification */
  2937. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  2938. {
  2939. struct ieee80211_sub_if_data *sdata;
  2940. /* Restart STA timers */
  2941. rcu_read_lock();
  2942. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2943. if (ieee80211_sdata_running(sdata))
  2944. ieee80211_restart_sta_timer(sdata);
  2945. }
  2946. rcu_read_unlock();
  2947. }
  2948. int ieee80211_max_network_latency(struct notifier_block *nb,
  2949. unsigned long data, void *dummy)
  2950. {
  2951. s32 latency_usec = (s32) data;
  2952. struct ieee80211_local *local =
  2953. container_of(nb, struct ieee80211_local,
  2954. network_latency_notifier);
  2955. mutex_lock(&local->iflist_mtx);
  2956. ieee80211_recalc_ps(local, latency_usec);
  2957. mutex_unlock(&local->iflist_mtx);
  2958. return 0;
  2959. }
  2960. static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
  2961. struct cfg80211_bss *cbss)
  2962. {
  2963. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2964. const u8 *ht_cap_ie, *vht_cap_ie;
  2965. const struct ieee80211_ht_cap *ht_cap;
  2966. const struct ieee80211_vht_cap *vht_cap;
  2967. u8 chains = 1;
  2968. if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
  2969. return chains;
  2970. ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
  2971. if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
  2972. ht_cap = (void *)(ht_cap_ie + 2);
  2973. chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
  2974. /*
  2975. * TODO: use "Tx Maximum Number Spatial Streams Supported" and
  2976. * "Tx Unequal Modulation Supported" fields.
  2977. */
  2978. }
  2979. if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
  2980. return chains;
  2981. vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
  2982. if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
  2983. u8 nss;
  2984. u16 tx_mcs_map;
  2985. vht_cap = (void *)(vht_cap_ie + 2);
  2986. tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
  2987. for (nss = 8; nss > 0; nss--) {
  2988. if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
  2989. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  2990. break;
  2991. }
  2992. /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
  2993. chains = max(chains, nss);
  2994. }
  2995. return chains;
  2996. }
  2997. static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
  2998. struct cfg80211_bss *cbss)
  2999. {
  3000. struct ieee80211_local *local = sdata->local;
  3001. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3002. const struct ieee80211_ht_operation *ht_oper = NULL;
  3003. const struct ieee80211_vht_operation *vht_oper = NULL;
  3004. struct ieee80211_supported_band *sband;
  3005. struct cfg80211_chan_def chandef;
  3006. int ret;
  3007. sband = local->hw.wiphy->bands[cbss->channel->band];
  3008. ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
  3009. IEEE80211_STA_DISABLE_80P80MHZ |
  3010. IEEE80211_STA_DISABLE_160MHZ);
  3011. rcu_read_lock();
  3012. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  3013. sband->ht_cap.ht_supported) {
  3014. const u8 *ht_oper_ie, *ht_cap;
  3015. ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
  3016. if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
  3017. ht_oper = (void *)(ht_oper_ie + 2);
  3018. ht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
  3019. if (!ht_cap || ht_cap[1] < sizeof(struct ieee80211_ht_cap)) {
  3020. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3021. ht_oper = NULL;
  3022. }
  3023. }
  3024. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  3025. sband->vht_cap.vht_supported) {
  3026. const u8 *vht_oper_ie, *vht_cap;
  3027. vht_oper_ie = ieee80211_bss_get_ie(cbss,
  3028. WLAN_EID_VHT_OPERATION);
  3029. if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
  3030. vht_oper = (void *)(vht_oper_ie + 2);
  3031. if (vht_oper && !ht_oper) {
  3032. vht_oper = NULL;
  3033. sdata_info(sdata,
  3034. "AP advertised VHT without HT, disabling both\n");
  3035. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3036. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3037. }
  3038. vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
  3039. if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
  3040. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3041. vht_oper = NULL;
  3042. }
  3043. }
  3044. ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
  3045. cbss->channel,
  3046. ht_oper, vht_oper,
  3047. &chandef, false);
  3048. sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
  3049. local->rx_chains);
  3050. rcu_read_unlock();
  3051. /* will change later if needed */
  3052. sdata->smps_mode = IEEE80211_SMPS_OFF;
  3053. /*
  3054. * If this fails (possibly due to channel context sharing
  3055. * on incompatible channels, e.g. 80+80 and 160 sharing the
  3056. * same control channel) try to use a smaller bandwidth.
  3057. */
  3058. ret = ieee80211_vif_use_channel(sdata, &chandef,
  3059. IEEE80211_CHANCTX_SHARED);
  3060. /* don't downgrade for 5 and 10 MHz channels, though. */
  3061. if (chandef.width == NL80211_CHAN_WIDTH_5 ||
  3062. chandef.width == NL80211_CHAN_WIDTH_10)
  3063. return ret;
  3064. while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
  3065. ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
  3066. ret = ieee80211_vif_use_channel(sdata, &chandef,
  3067. IEEE80211_CHANCTX_SHARED);
  3068. }
  3069. return ret;
  3070. }
  3071. static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
  3072. struct cfg80211_bss *cbss, bool assoc)
  3073. {
  3074. struct ieee80211_local *local = sdata->local;
  3075. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3076. struct ieee80211_bss *bss = (void *)cbss->priv;
  3077. struct sta_info *new_sta = NULL;
  3078. bool have_sta = false;
  3079. int err;
  3080. if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
  3081. return -EINVAL;
  3082. if (assoc) {
  3083. rcu_read_lock();
  3084. have_sta = sta_info_get(sdata, cbss->bssid);
  3085. rcu_read_unlock();
  3086. }
  3087. if (!have_sta) {
  3088. new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
  3089. if (!new_sta)
  3090. return -ENOMEM;
  3091. }
  3092. if (new_sta) {
  3093. u32 rates = 0, basic_rates = 0;
  3094. bool have_higher_than_11mbit;
  3095. int min_rate = INT_MAX, min_rate_index = -1;
  3096. struct ieee80211_chanctx_conf *chanctx_conf;
  3097. struct ieee80211_supported_band *sband;
  3098. const struct cfg80211_bss_ies *ies;
  3099. int shift;
  3100. u32 rate_flags;
  3101. sband = local->hw.wiphy->bands[cbss->channel->band];
  3102. err = ieee80211_prep_channel(sdata, cbss);
  3103. if (err) {
  3104. sta_info_free(local, new_sta);
  3105. return -EINVAL;
  3106. }
  3107. shift = ieee80211_vif_get_shift(&sdata->vif);
  3108. rcu_read_lock();
  3109. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  3110. if (WARN_ON(!chanctx_conf)) {
  3111. rcu_read_unlock();
  3112. return -EINVAL;
  3113. }
  3114. rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
  3115. rcu_read_unlock();
  3116. ieee80211_get_rates(sband, bss->supp_rates,
  3117. bss->supp_rates_len,
  3118. &rates, &basic_rates,
  3119. &have_higher_than_11mbit,
  3120. &min_rate, &min_rate_index,
  3121. shift, rate_flags);
  3122. /*
  3123. * This used to be a workaround for basic rates missing
  3124. * in the association response frame. Now that we no
  3125. * longer use the basic rates from there, it probably
  3126. * doesn't happen any more, but keep the workaround so
  3127. * in case some *other* APs are buggy in different ways
  3128. * we can connect -- with a warning.
  3129. */
  3130. if (!basic_rates && min_rate_index >= 0) {
  3131. sdata_info(sdata,
  3132. "No basic rates, using min rate instead\n");
  3133. basic_rates = BIT(min_rate_index);
  3134. }
  3135. new_sta->sta.supp_rates[cbss->channel->band] = rates;
  3136. sdata->vif.bss_conf.basic_rates = basic_rates;
  3137. /* cf. IEEE 802.11 9.2.12 */
  3138. if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
  3139. have_higher_than_11mbit)
  3140. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  3141. else
  3142. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  3143. memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
  3144. /* set timing information */
  3145. sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
  3146. rcu_read_lock();
  3147. ies = rcu_dereference(cbss->beacon_ies);
  3148. if (ies) {
  3149. const u8 *tim_ie;
  3150. sdata->vif.bss_conf.sync_tsf = ies->tsf;
  3151. sdata->vif.bss_conf.sync_device_ts =
  3152. bss->device_ts_beacon;
  3153. tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
  3154. ies->data, ies->len);
  3155. if (tim_ie && tim_ie[1] >= 2)
  3156. sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
  3157. else
  3158. sdata->vif.bss_conf.sync_dtim_count = 0;
  3159. } else if (!(local->hw.flags &
  3160. IEEE80211_HW_TIMING_BEACON_ONLY)) {
  3161. ies = rcu_dereference(cbss->proberesp_ies);
  3162. /* must be non-NULL since beacon IEs were NULL */
  3163. sdata->vif.bss_conf.sync_tsf = ies->tsf;
  3164. sdata->vif.bss_conf.sync_device_ts =
  3165. bss->device_ts_presp;
  3166. sdata->vif.bss_conf.sync_dtim_count = 0;
  3167. } else {
  3168. sdata->vif.bss_conf.sync_tsf = 0;
  3169. sdata->vif.bss_conf.sync_device_ts = 0;
  3170. sdata->vif.bss_conf.sync_dtim_count = 0;
  3171. }
  3172. rcu_read_unlock();
  3173. /* tell driver about BSSID, basic rates and timing */
  3174. ieee80211_bss_info_change_notify(sdata,
  3175. BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
  3176. BSS_CHANGED_BEACON_INT);
  3177. if (assoc)
  3178. sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
  3179. err = sta_info_insert(new_sta);
  3180. new_sta = NULL;
  3181. if (err) {
  3182. sdata_info(sdata,
  3183. "failed to insert STA entry for the AP (error %d)\n",
  3184. err);
  3185. return err;
  3186. }
  3187. } else
  3188. WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
  3189. return 0;
  3190. }
  3191. /* config hooks */
  3192. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  3193. struct cfg80211_auth_request *req)
  3194. {
  3195. struct ieee80211_local *local = sdata->local;
  3196. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3197. struct ieee80211_mgd_auth_data *auth_data;
  3198. u16 auth_alg;
  3199. int err;
  3200. /* prepare auth data structure */
  3201. switch (req->auth_type) {
  3202. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  3203. auth_alg = WLAN_AUTH_OPEN;
  3204. break;
  3205. case NL80211_AUTHTYPE_SHARED_KEY:
  3206. if (IS_ERR(local->wep_tx_tfm))
  3207. return -EOPNOTSUPP;
  3208. auth_alg = WLAN_AUTH_SHARED_KEY;
  3209. break;
  3210. case NL80211_AUTHTYPE_FT:
  3211. auth_alg = WLAN_AUTH_FT;
  3212. break;
  3213. case NL80211_AUTHTYPE_NETWORK_EAP:
  3214. auth_alg = WLAN_AUTH_LEAP;
  3215. break;
  3216. case NL80211_AUTHTYPE_SAE:
  3217. auth_alg = WLAN_AUTH_SAE;
  3218. break;
  3219. default:
  3220. return -EOPNOTSUPP;
  3221. }
  3222. auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
  3223. req->ie_len, GFP_KERNEL);
  3224. if (!auth_data)
  3225. return -ENOMEM;
  3226. auth_data->bss = req->bss;
  3227. if (req->sae_data_len >= 4) {
  3228. __le16 *pos = (__le16 *) req->sae_data;
  3229. auth_data->sae_trans = le16_to_cpu(pos[0]);
  3230. auth_data->sae_status = le16_to_cpu(pos[1]);
  3231. memcpy(auth_data->data, req->sae_data + 4,
  3232. req->sae_data_len - 4);
  3233. auth_data->data_len += req->sae_data_len - 4;
  3234. }
  3235. if (req->ie && req->ie_len) {
  3236. memcpy(&auth_data->data[auth_data->data_len],
  3237. req->ie, req->ie_len);
  3238. auth_data->data_len += req->ie_len;
  3239. }
  3240. if (req->key && req->key_len) {
  3241. auth_data->key_len = req->key_len;
  3242. auth_data->key_idx = req->key_idx;
  3243. memcpy(auth_data->key, req->key, req->key_len);
  3244. }
  3245. auth_data->algorithm = auth_alg;
  3246. /* try to authenticate/probe */
  3247. if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
  3248. ifmgd->assoc_data) {
  3249. err = -EBUSY;
  3250. goto err_free;
  3251. }
  3252. if (ifmgd->auth_data)
  3253. ieee80211_destroy_auth_data(sdata, false);
  3254. /* prep auth_data so we don't go into idle on disassoc */
  3255. ifmgd->auth_data = auth_data;
  3256. if (ifmgd->associated) {
  3257. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3258. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3259. WLAN_REASON_UNSPECIFIED,
  3260. false, frame_buf);
  3261. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3262. sizeof(frame_buf));
  3263. }
  3264. sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
  3265. err = ieee80211_prep_connection(sdata, req->bss, false);
  3266. if (err)
  3267. goto err_clear;
  3268. err = ieee80211_probe_auth(sdata);
  3269. if (err) {
  3270. sta_info_destroy_addr(sdata, req->bss->bssid);
  3271. goto err_clear;
  3272. }
  3273. /* hold our own reference */
  3274. cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
  3275. return 0;
  3276. err_clear:
  3277. memset(ifmgd->bssid, 0, ETH_ALEN);
  3278. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  3279. ifmgd->auth_data = NULL;
  3280. err_free:
  3281. kfree(auth_data);
  3282. return err;
  3283. }
  3284. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  3285. struct cfg80211_assoc_request *req)
  3286. {
  3287. struct ieee80211_local *local = sdata->local;
  3288. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3289. struct ieee80211_bss *bss = (void *)req->bss->priv;
  3290. struct ieee80211_mgd_assoc_data *assoc_data;
  3291. const struct cfg80211_bss_ies *beacon_ies;
  3292. struct ieee80211_supported_band *sband;
  3293. const u8 *ssidie, *ht_ie, *vht_ie;
  3294. int i, err;
  3295. assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
  3296. if (!assoc_data)
  3297. return -ENOMEM;
  3298. rcu_read_lock();
  3299. ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  3300. if (!ssidie) {
  3301. rcu_read_unlock();
  3302. kfree(assoc_data);
  3303. return -EINVAL;
  3304. }
  3305. memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
  3306. assoc_data->ssid_len = ssidie[1];
  3307. rcu_read_unlock();
  3308. if (ifmgd->associated) {
  3309. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3310. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3311. WLAN_REASON_UNSPECIFIED,
  3312. false, frame_buf);
  3313. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3314. sizeof(frame_buf));
  3315. }
  3316. if (ifmgd->auth_data && !ifmgd->auth_data->done) {
  3317. err = -EBUSY;
  3318. goto err_free;
  3319. }
  3320. if (ifmgd->assoc_data) {
  3321. err = -EBUSY;
  3322. goto err_free;
  3323. }
  3324. if (ifmgd->auth_data) {
  3325. bool match;
  3326. /* keep sta info, bssid if matching */
  3327. match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
  3328. ieee80211_destroy_auth_data(sdata, match);
  3329. }
  3330. /* prepare assoc data */
  3331. ifmgd->beacon_crc_valid = false;
  3332. /*
  3333. * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
  3334. * We still associate in non-HT mode (11a/b/g) if any one of these
  3335. * ciphers is configured as pairwise.
  3336. * We can set this to true for non-11n hardware, that'll be checked
  3337. * separately along with the peer capabilities.
  3338. */
  3339. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
  3340. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  3341. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  3342. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
  3343. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3344. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3345. netdev_info(sdata->dev,
  3346. "disabling HT/VHT due to WEP/TKIP use\n");
  3347. }
  3348. }
  3349. if (req->flags & ASSOC_REQ_DISABLE_HT) {
  3350. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3351. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3352. }
  3353. if (req->flags & ASSOC_REQ_DISABLE_VHT)
  3354. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3355. /* Also disable HT if we don't support it or the AP doesn't use WMM */
  3356. sband = local->hw.wiphy->bands[req->bss->channel->band];
  3357. if (!sband->ht_cap.ht_supported ||
  3358. local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
  3359. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3360. if (!bss->wmm_used)
  3361. netdev_info(sdata->dev,
  3362. "disabling HT as WMM/QoS is not supported by the AP\n");
  3363. }
  3364. /* disable VHT if we don't support it or the AP doesn't use WMM */
  3365. if (!sband->vht_cap.vht_supported ||
  3366. local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
  3367. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3368. if (!bss->wmm_used)
  3369. netdev_info(sdata->dev,
  3370. "disabling VHT as WMM/QoS is not supported by the AP\n");
  3371. }
  3372. memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
  3373. memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
  3374. sizeof(ifmgd->ht_capa_mask));
  3375. memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
  3376. memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
  3377. sizeof(ifmgd->vht_capa_mask));
  3378. if (req->ie && req->ie_len) {
  3379. memcpy(assoc_data->ie, req->ie, req->ie_len);
  3380. assoc_data->ie_len = req->ie_len;
  3381. }
  3382. assoc_data->bss = req->bss;
  3383. if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
  3384. if (ifmgd->powersave)
  3385. sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
  3386. else
  3387. sdata->smps_mode = IEEE80211_SMPS_OFF;
  3388. } else
  3389. sdata->smps_mode = ifmgd->req_smps;
  3390. assoc_data->capability = req->bss->capability;
  3391. assoc_data->wmm = bss->wmm_used &&
  3392. (local->hw.queues >= IEEE80211_NUM_ACS);
  3393. assoc_data->supp_rates = bss->supp_rates;
  3394. assoc_data->supp_rates_len = bss->supp_rates_len;
  3395. rcu_read_lock();
  3396. ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
  3397. if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
  3398. assoc_data->ap_ht_param =
  3399. ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
  3400. else
  3401. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3402. vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
  3403. if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
  3404. memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
  3405. sizeof(struct ieee80211_vht_cap));
  3406. else
  3407. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3408. rcu_read_unlock();
  3409. if (bss->wmm_used && bss->uapsd_supported &&
  3410. (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) &&
  3411. sdata->wmm_acm != 0xff) {
  3412. assoc_data->uapsd = true;
  3413. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  3414. } else {
  3415. assoc_data->uapsd = false;
  3416. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  3417. }
  3418. if (req->prev_bssid)
  3419. memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
  3420. if (req->use_mfp) {
  3421. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  3422. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  3423. } else {
  3424. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  3425. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  3426. }
  3427. if (req->crypto.control_port)
  3428. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  3429. else
  3430. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  3431. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  3432. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  3433. /* kick off associate process */
  3434. ifmgd->assoc_data = assoc_data;
  3435. ifmgd->dtim_period = 0;
  3436. ifmgd->have_beacon = false;
  3437. err = ieee80211_prep_connection(sdata, req->bss, true);
  3438. if (err)
  3439. goto err_clear;
  3440. rcu_read_lock();
  3441. beacon_ies = rcu_dereference(req->bss->beacon_ies);
  3442. if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
  3443. !beacon_ies) {
  3444. /*
  3445. * Wait up to one beacon interval ...
  3446. * should this be more if we miss one?
  3447. */
  3448. sdata_info(sdata, "waiting for beacon from %pM\n",
  3449. ifmgd->bssid);
  3450. assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
  3451. assoc_data->timeout_started = true;
  3452. assoc_data->need_beacon = true;
  3453. } else if (beacon_ies) {
  3454. const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
  3455. beacon_ies->data,
  3456. beacon_ies->len);
  3457. u8 dtim_count = 0;
  3458. if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
  3459. const struct ieee80211_tim_ie *tim;
  3460. tim = (void *)(tim_ie + 2);
  3461. ifmgd->dtim_period = tim->dtim_period;
  3462. dtim_count = tim->dtim_count;
  3463. }
  3464. ifmgd->have_beacon = true;
  3465. assoc_data->timeout = jiffies;
  3466. assoc_data->timeout_started = true;
  3467. if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
  3468. sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
  3469. sdata->vif.bss_conf.sync_device_ts =
  3470. bss->device_ts_beacon;
  3471. sdata->vif.bss_conf.sync_dtim_count = dtim_count;
  3472. }
  3473. } else {
  3474. assoc_data->timeout = jiffies;
  3475. assoc_data->timeout_started = true;
  3476. }
  3477. rcu_read_unlock();
  3478. run_again(sdata, assoc_data->timeout);
  3479. if (bss->corrupt_data) {
  3480. char *corrupt_type = "data";
  3481. if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
  3482. if (bss->corrupt_data &
  3483. IEEE80211_BSS_CORRUPT_PROBE_RESP)
  3484. corrupt_type = "beacon and probe response";
  3485. else
  3486. corrupt_type = "beacon";
  3487. } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
  3488. corrupt_type = "probe response";
  3489. sdata_info(sdata, "associating with AP with corrupt %s\n",
  3490. corrupt_type);
  3491. }
  3492. return 0;
  3493. err_clear:
  3494. memset(ifmgd->bssid, 0, ETH_ALEN);
  3495. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  3496. ifmgd->assoc_data = NULL;
  3497. err_free:
  3498. kfree(assoc_data);
  3499. return err;
  3500. }
  3501. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  3502. struct cfg80211_deauth_request *req)
  3503. {
  3504. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3505. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3506. bool tx = !req->local_state_change;
  3507. bool report_frame = false;
  3508. sdata_info(sdata,
  3509. "deauthenticating from %pM by local choice (reason=%d)\n",
  3510. req->bssid, req->reason_code);
  3511. if (ifmgd->auth_data) {
  3512. drv_mgd_prepare_tx(sdata->local, sdata);
  3513. ieee80211_send_deauth_disassoc(sdata, req->bssid,
  3514. IEEE80211_STYPE_DEAUTH,
  3515. req->reason_code, tx,
  3516. frame_buf);
  3517. ieee80211_destroy_auth_data(sdata, false);
  3518. report_frame = true;
  3519. goto out;
  3520. }
  3521. if (ifmgd->associated &&
  3522. ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
  3523. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3524. req->reason_code, tx, frame_buf);
  3525. report_frame = true;
  3526. }
  3527. out:
  3528. if (report_frame)
  3529. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3530. IEEE80211_DEAUTH_FRAME_LEN);
  3531. return 0;
  3532. }
  3533. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  3534. struct cfg80211_disassoc_request *req)
  3535. {
  3536. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3537. u8 bssid[ETH_ALEN];
  3538. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3539. /*
  3540. * cfg80211 should catch this ... but it's racy since
  3541. * we can receive a disassoc frame, process it, hand it
  3542. * to cfg80211 while that's in a locked section already
  3543. * trying to tell us that the user wants to disconnect.
  3544. */
  3545. if (ifmgd->associated != req->bss)
  3546. return -ENOLINK;
  3547. sdata_info(sdata,
  3548. "disassociating from %pM by local choice (reason=%d)\n",
  3549. req->bss->bssid, req->reason_code);
  3550. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  3551. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
  3552. req->reason_code, !req->local_state_change,
  3553. frame_buf);
  3554. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3555. IEEE80211_DEAUTH_FRAME_LEN);
  3556. return 0;
  3557. }
  3558. void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
  3559. {
  3560. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3561. /*
  3562. * Make sure some work items will not run after this,
  3563. * they will not do anything but might not have been
  3564. * cancelled when disconnecting.
  3565. */
  3566. cancel_work_sync(&ifmgd->monitor_work);
  3567. cancel_work_sync(&ifmgd->beacon_connection_loss_work);
  3568. cancel_work_sync(&ifmgd->request_smps_work);
  3569. cancel_work_sync(&ifmgd->csa_connection_drop_work);
  3570. cancel_work_sync(&ifmgd->chswitch_work);
  3571. sdata_lock(sdata);
  3572. if (ifmgd->assoc_data) {
  3573. struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
  3574. ieee80211_destroy_assoc_data(sdata, false);
  3575. cfg80211_assoc_timeout(sdata->dev, bss);
  3576. }
  3577. if (ifmgd->auth_data)
  3578. ieee80211_destroy_auth_data(sdata, false);
  3579. del_timer_sync(&ifmgd->timer);
  3580. sdata_unlock(sdata);
  3581. }
  3582. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  3583. enum nl80211_cqm_rssi_threshold_event rssi_event,
  3584. gfp_t gfp)
  3585. {
  3586. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3587. trace_api_cqm_rssi_notify(sdata, rssi_event);
  3588. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
  3589. }
  3590. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);