mlme.c 105 KB

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