mlme.c 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807
  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/rtnetlink.h>
  19. #include <linux/pm_qos_params.h>
  20. #include <linux/crc32.h>
  21. #include <linux/slab.h>
  22. #include <net/mac80211.h>
  23. #include <asm/unaligned.h>
  24. #include "ieee80211_i.h"
  25. #include "driver-ops.h"
  26. #include "rate.h"
  27. #include "led.h"
  28. static int max_nullfunc_tries = 2;
  29. module_param(max_nullfunc_tries, int, 0644);
  30. MODULE_PARM_DESC(max_nullfunc_tries,
  31. "Maximum nullfunc tx tries before disconnecting (reason 4).");
  32. static int max_probe_tries = 5;
  33. module_param(max_probe_tries, int, 0644);
  34. MODULE_PARM_DESC(max_probe_tries,
  35. "Maximum probe tries before disconnecting (reason 4).");
  36. /*
  37. * Beacon loss timeout is calculated as N frames times the
  38. * advertised beacon interval. This may need to be somewhat
  39. * higher than what hardware might detect to account for
  40. * delays in the host processing frames. But since we also
  41. * probe on beacon miss before declaring the connection lost
  42. * default to what we want.
  43. */
  44. #define IEEE80211_BEACON_LOSS_COUNT 7
  45. /*
  46. * Time the connection can be idle before we probe
  47. * it to see if we can still talk to the AP.
  48. */
  49. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  50. /*
  51. * Time we wait for a probe response after sending
  52. * a probe request because of beacon loss or for
  53. * checking the connection still works.
  54. */
  55. static int probe_wait_ms = 500;
  56. module_param(probe_wait_ms, int, 0644);
  57. MODULE_PARM_DESC(probe_wait_ms,
  58. "Maximum time(ms) to wait for probe response"
  59. " before disconnecting (reason 4).");
  60. /*
  61. * Weight given to the latest Beacon frame when calculating average signal
  62. * strength for Beacon frames received in the current BSS. This must be
  63. * between 1 and 15.
  64. */
  65. #define IEEE80211_SIGNAL_AVE_WEIGHT 3
  66. /*
  67. * How many Beacon frames need to have been used in average signal strength
  68. * before starting to indicate signal change events.
  69. */
  70. #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
  71. #define TMR_RUNNING_TIMER 0
  72. #define TMR_RUNNING_CHANSW 1
  73. /*
  74. * All cfg80211 functions have to be called outside a locked
  75. * section so that they can acquire a lock themselves... This
  76. * is much simpler than queuing up things in cfg80211, but we
  77. * do need some indirection for that here.
  78. */
  79. enum rx_mgmt_action {
  80. /* no action required */
  81. RX_MGMT_NONE,
  82. /* caller must call cfg80211_send_deauth() */
  83. RX_MGMT_CFG80211_DEAUTH,
  84. /* caller must call cfg80211_send_disassoc() */
  85. RX_MGMT_CFG80211_DISASSOC,
  86. };
  87. /* utils */
  88. static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
  89. {
  90. lockdep_assert_held(&ifmgd->mtx);
  91. }
  92. /*
  93. * We can have multiple work items (and connection probing)
  94. * scheduling this timer, but we need to take care to only
  95. * reschedule it when it should fire _earlier_ than it was
  96. * asked for before, or if it's not pending right now. This
  97. * function ensures that. Note that it then is required to
  98. * run this function for all timeouts after the first one
  99. * has happened -- the work that runs from this timer will
  100. * do that.
  101. */
  102. static void run_again(struct ieee80211_if_managed *ifmgd,
  103. unsigned long timeout)
  104. {
  105. ASSERT_MGD_MTX(ifmgd);
  106. if (!timer_pending(&ifmgd->timer) ||
  107. time_before(timeout, ifmgd->timer.expires))
  108. mod_timer(&ifmgd->timer, timeout);
  109. }
  110. void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
  111. {
  112. if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
  113. return;
  114. mod_timer(&sdata->u.mgd.bcn_mon_timer,
  115. round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
  116. }
  117. void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
  118. {
  119. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  120. if (unlikely(!sdata->u.mgd.associated))
  121. return;
  122. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  123. return;
  124. mod_timer(&sdata->u.mgd.conn_mon_timer,
  125. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  126. ifmgd->probe_send_count = 0;
  127. }
  128. static int ecw2cw(int ecw)
  129. {
  130. return (1 << ecw) - 1;
  131. }
  132. /*
  133. * ieee80211_enable_ht should be called only after the operating band
  134. * has been determined as ht configuration depends on the hw's
  135. * HT abilities for a specific band.
  136. */
  137. static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
  138. struct ieee80211_ht_info *hti,
  139. const u8 *bssid, u16 ap_ht_cap_flags,
  140. bool beacon_htcap_ie)
  141. {
  142. struct ieee80211_local *local = sdata->local;
  143. struct ieee80211_supported_band *sband;
  144. struct sta_info *sta;
  145. u32 changed = 0;
  146. int hti_cfreq;
  147. u16 ht_opmode;
  148. bool enable_ht = true;
  149. enum nl80211_channel_type prev_chantype;
  150. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  151. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  152. prev_chantype = sdata->vif.bss_conf.channel_type;
  153. /* HT is not supported */
  154. if (!sband->ht_cap.ht_supported)
  155. enable_ht = false;
  156. if (enable_ht) {
  157. hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan,
  158. sband->band);
  159. /* check that channel matches the right operating channel */
  160. if (local->hw.conf.channel->center_freq != hti_cfreq) {
  161. /* Some APs mess this up, evidently.
  162. * Netgear WNDR3700 sometimes reports 4 higher than
  163. * the actual channel, for instance.
  164. */
  165. printk(KERN_DEBUG
  166. "%s: Wrong control channel in association"
  167. " response: configured center-freq: %d"
  168. " hti-cfreq: %d hti->control_chan: %d"
  169. " band: %d. Disabling HT.\n",
  170. sdata->name,
  171. local->hw.conf.channel->center_freq,
  172. hti_cfreq, hti->control_chan,
  173. sband->band);
  174. enable_ht = false;
  175. }
  176. }
  177. if (enable_ht) {
  178. channel_type = NL80211_CHAN_HT20;
  179. if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
  180. (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
  181. (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
  182. switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  183. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  184. if (!(local->hw.conf.channel->flags &
  185. IEEE80211_CHAN_NO_HT40PLUS))
  186. channel_type = NL80211_CHAN_HT40PLUS;
  187. break;
  188. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  189. if (!(local->hw.conf.channel->flags &
  190. IEEE80211_CHAN_NO_HT40MINUS))
  191. channel_type = NL80211_CHAN_HT40MINUS;
  192. break;
  193. }
  194. }
  195. }
  196. if (local->tmp_channel)
  197. local->tmp_channel_type = channel_type;
  198. if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
  199. /* can only fail due to HT40+/- mismatch */
  200. channel_type = NL80211_CHAN_HT20;
  201. WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
  202. }
  203. if (beacon_htcap_ie && (prev_chantype != channel_type)) {
  204. /*
  205. * Whenever the AP announces the HT mode change that can be
  206. * 40MHz intolerant or etc., it would be safer to stop tx
  207. * queues before doing hw config to avoid buffer overflow.
  208. */
  209. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  210. IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
  211. /* flush out all packets */
  212. synchronize_net();
  213. drv_flush(local, false);
  214. }
  215. /* channel_type change automatically detected */
  216. ieee80211_hw_config(local, 0);
  217. if (prev_chantype != channel_type) {
  218. rcu_read_lock();
  219. sta = sta_info_get(sdata, bssid);
  220. if (sta)
  221. rate_control_rate_update(local, sband, sta,
  222. IEEE80211_RC_HT_CHANGED,
  223. channel_type);
  224. rcu_read_unlock();
  225. if (beacon_htcap_ie)
  226. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  227. IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
  228. }
  229. ht_opmode = le16_to_cpu(hti->operation_mode);
  230. /* if bss configuration changed store the new one */
  231. if (sdata->ht_opmode_valid != enable_ht ||
  232. sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
  233. prev_chantype != channel_type) {
  234. changed |= BSS_CHANGED_HT;
  235. sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
  236. sdata->ht_opmode_valid = enable_ht;
  237. }
  238. return changed;
  239. }
  240. /* frame sending functions */
  241. static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  242. const u8 *bssid, u16 stype, u16 reason,
  243. void *cookie, bool send_frame)
  244. {
  245. struct ieee80211_local *local = sdata->local;
  246. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  247. struct sk_buff *skb;
  248. struct ieee80211_mgmt *mgmt;
  249. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  250. if (!skb)
  251. return;
  252. skb_reserve(skb, local->hw.extra_tx_headroom);
  253. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  254. memset(mgmt, 0, 24);
  255. memcpy(mgmt->da, bssid, ETH_ALEN);
  256. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  257. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  258. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  259. skb_put(skb, 2);
  260. /* u.deauth.reason_code == u.disassoc.reason_code */
  261. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  262. if (stype == IEEE80211_STYPE_DEAUTH)
  263. if (cookie)
  264. __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  265. else
  266. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  267. else
  268. if (cookie)
  269. __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
  270. else
  271. cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
  272. if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
  273. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  274. if (send_frame)
  275. ieee80211_tx_skb(sdata, skb);
  276. else
  277. kfree_skb(skb);
  278. }
  279. void ieee80211_send_pspoll(struct ieee80211_local *local,
  280. struct ieee80211_sub_if_data *sdata)
  281. {
  282. struct ieee80211_pspoll *pspoll;
  283. struct sk_buff *skb;
  284. skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
  285. if (!skb)
  286. return;
  287. pspoll = (struct ieee80211_pspoll *) skb->data;
  288. pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  289. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  290. ieee80211_tx_skb(sdata, skb);
  291. }
  292. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  293. struct ieee80211_sub_if_data *sdata,
  294. int powersave)
  295. {
  296. struct sk_buff *skb;
  297. struct ieee80211_hdr_3addr *nullfunc;
  298. skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
  299. if (!skb)
  300. return;
  301. nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
  302. if (powersave)
  303. nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  304. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  305. ieee80211_tx_skb(sdata, skb);
  306. }
  307. static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
  308. struct ieee80211_sub_if_data *sdata)
  309. {
  310. struct sk_buff *skb;
  311. struct ieee80211_hdr *nullfunc;
  312. __le16 fc;
  313. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  314. return;
  315. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
  316. if (!skb)
  317. return;
  318. skb_reserve(skb, local->hw.extra_tx_headroom);
  319. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
  320. memset(nullfunc, 0, 30);
  321. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  322. IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  323. nullfunc->frame_control = fc;
  324. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  325. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  326. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  327. memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
  328. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  329. ieee80211_tx_skb(sdata, skb);
  330. }
  331. /* spectrum management related things */
  332. static void ieee80211_chswitch_work(struct work_struct *work)
  333. {
  334. struct ieee80211_sub_if_data *sdata =
  335. container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
  336. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  337. if (!ieee80211_sdata_running(sdata))
  338. return;
  339. mutex_lock(&ifmgd->mtx);
  340. if (!ifmgd->associated)
  341. goto out;
  342. sdata->local->oper_channel = sdata->local->csa_channel;
  343. if (!sdata->local->ops->channel_switch) {
  344. /* call "hw_config" only if doing sw channel switch */
  345. ieee80211_hw_config(sdata->local,
  346. IEEE80211_CONF_CHANGE_CHANNEL);
  347. } else {
  348. /* update the device channel directly */
  349. sdata->local->hw.conf.channel = sdata->local->oper_channel;
  350. }
  351. /* XXX: shouldn't really modify cfg80211-owned data! */
  352. ifmgd->associated->channel = sdata->local->oper_channel;
  353. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  354. IEEE80211_QUEUE_STOP_REASON_CSA);
  355. out:
  356. ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
  357. mutex_unlock(&ifmgd->mtx);
  358. }
  359. void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
  360. {
  361. struct ieee80211_sub_if_data *sdata;
  362. struct ieee80211_if_managed *ifmgd;
  363. sdata = vif_to_sdata(vif);
  364. ifmgd = &sdata->u.mgd;
  365. trace_api_chswitch_done(sdata, success);
  366. if (!success) {
  367. /*
  368. * If the channel switch was not successful, stay
  369. * around on the old channel. We currently lack
  370. * good handling of this situation, possibly we
  371. * should just drop the association.
  372. */
  373. sdata->local->csa_channel = sdata->local->oper_channel;
  374. }
  375. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  376. }
  377. EXPORT_SYMBOL(ieee80211_chswitch_done);
  378. static void ieee80211_chswitch_timer(unsigned long data)
  379. {
  380. struct ieee80211_sub_if_data *sdata =
  381. (struct ieee80211_sub_if_data *) data;
  382. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  383. if (sdata->local->quiescing) {
  384. set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
  385. return;
  386. }
  387. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  388. }
  389. void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
  390. struct ieee80211_channel_sw_ie *sw_elem,
  391. struct ieee80211_bss *bss,
  392. u64 timestamp)
  393. {
  394. struct cfg80211_bss *cbss =
  395. container_of((void *)bss, struct cfg80211_bss, priv);
  396. struct ieee80211_channel *new_ch;
  397. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  398. int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
  399. cbss->channel->band);
  400. ASSERT_MGD_MTX(ifmgd);
  401. if (!ifmgd->associated)
  402. return;
  403. if (sdata->local->scanning)
  404. return;
  405. /* Disregard subsequent beacons if we are already running a timer
  406. processing a CSA */
  407. if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
  408. return;
  409. new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
  410. if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
  411. return;
  412. sdata->local->csa_channel = new_ch;
  413. if (sdata->local->ops->channel_switch) {
  414. /* use driver's channel switch callback */
  415. struct ieee80211_channel_switch ch_switch;
  416. memset(&ch_switch, 0, sizeof(ch_switch));
  417. ch_switch.timestamp = timestamp;
  418. if (sw_elem->mode) {
  419. ch_switch.block_tx = true;
  420. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  421. IEEE80211_QUEUE_STOP_REASON_CSA);
  422. }
  423. ch_switch.channel = new_ch;
  424. ch_switch.count = sw_elem->count;
  425. ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
  426. drv_channel_switch(sdata->local, &ch_switch);
  427. return;
  428. }
  429. /* channel switch handled in software */
  430. if (sw_elem->count <= 1) {
  431. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  432. } else {
  433. if (sw_elem->mode)
  434. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  435. IEEE80211_QUEUE_STOP_REASON_CSA);
  436. ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
  437. mod_timer(&ifmgd->chswitch_timer,
  438. jiffies +
  439. msecs_to_jiffies(sw_elem->count *
  440. cbss->beacon_interval));
  441. }
  442. }
  443. static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
  444. u16 capab_info, u8 *pwr_constr_elem,
  445. u8 pwr_constr_elem_len)
  446. {
  447. struct ieee80211_conf *conf = &sdata->local->hw.conf;
  448. if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
  449. return;
  450. /* Power constraint IE length should be 1 octet */
  451. if (pwr_constr_elem_len != 1)
  452. return;
  453. if ((*pwr_constr_elem <= conf->channel->max_power) &&
  454. (*pwr_constr_elem != sdata->local->power_constr_level)) {
  455. sdata->local->power_constr_level = *pwr_constr_elem;
  456. ieee80211_hw_config(sdata->local, 0);
  457. }
  458. }
  459. void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
  460. {
  461. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  462. struct ieee80211_local *local = sdata->local;
  463. struct ieee80211_conf *conf = &local->hw.conf;
  464. WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
  465. !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
  466. (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
  467. local->disable_dynamic_ps = false;
  468. conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
  469. }
  470. EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
  471. void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
  472. {
  473. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  474. struct ieee80211_local *local = sdata->local;
  475. struct ieee80211_conf *conf = &local->hw.conf;
  476. WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
  477. !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
  478. (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
  479. local->disable_dynamic_ps = true;
  480. conf->dynamic_ps_timeout = 0;
  481. del_timer_sync(&local->dynamic_ps_timer);
  482. ieee80211_queue_work(&local->hw,
  483. &local->dynamic_ps_enable_work);
  484. }
  485. EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
  486. /* powersave */
  487. static void ieee80211_enable_ps(struct ieee80211_local *local,
  488. struct ieee80211_sub_if_data *sdata)
  489. {
  490. struct ieee80211_conf *conf = &local->hw.conf;
  491. /*
  492. * If we are scanning right now then the parameters will
  493. * take effect when scan finishes.
  494. */
  495. if (local->scanning)
  496. return;
  497. if (conf->dynamic_ps_timeout > 0 &&
  498. !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
  499. mod_timer(&local->dynamic_ps_timer, jiffies +
  500. msecs_to_jiffies(conf->dynamic_ps_timeout));
  501. } else {
  502. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  503. ieee80211_send_nullfunc(local, sdata, 1);
  504. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  505. (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
  506. return;
  507. conf->flags |= IEEE80211_CONF_PS;
  508. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  509. }
  510. }
  511. static void ieee80211_change_ps(struct ieee80211_local *local)
  512. {
  513. struct ieee80211_conf *conf = &local->hw.conf;
  514. if (local->ps_sdata) {
  515. ieee80211_enable_ps(local, local->ps_sdata);
  516. } else if (conf->flags & IEEE80211_CONF_PS) {
  517. conf->flags &= ~IEEE80211_CONF_PS;
  518. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  519. del_timer_sync(&local->dynamic_ps_timer);
  520. cancel_work_sync(&local->dynamic_ps_enable_work);
  521. }
  522. }
  523. static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
  524. {
  525. struct ieee80211_if_managed *mgd = &sdata->u.mgd;
  526. struct sta_info *sta = NULL;
  527. u32 sta_flags = 0;
  528. if (!mgd->powersave)
  529. return false;
  530. if (!mgd->associated)
  531. return false;
  532. if (!mgd->associated->beacon_ies)
  533. return false;
  534. if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
  535. IEEE80211_STA_CONNECTION_POLL))
  536. return false;
  537. rcu_read_lock();
  538. sta = sta_info_get(sdata, mgd->bssid);
  539. if (sta)
  540. sta_flags = get_sta_flags(sta);
  541. rcu_read_unlock();
  542. if (!(sta_flags & WLAN_STA_AUTHORIZED))
  543. return false;
  544. return true;
  545. }
  546. /* need to hold RTNL or interface lock */
  547. void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
  548. {
  549. struct ieee80211_sub_if_data *sdata, *found = NULL;
  550. int count = 0;
  551. int timeout;
  552. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
  553. local->ps_sdata = NULL;
  554. return;
  555. }
  556. if (!list_empty(&local->work_list)) {
  557. local->ps_sdata = NULL;
  558. goto change;
  559. }
  560. list_for_each_entry(sdata, &local->interfaces, list) {
  561. if (!ieee80211_sdata_running(sdata))
  562. continue;
  563. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  564. /* If an AP vif is found, then disable PS
  565. * by setting the count to zero thereby setting
  566. * ps_sdata to NULL.
  567. */
  568. count = 0;
  569. break;
  570. }
  571. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  572. continue;
  573. found = sdata;
  574. count++;
  575. }
  576. if (count == 1 && ieee80211_powersave_allowed(found)) {
  577. struct ieee80211_conf *conf = &local->hw.conf;
  578. s32 beaconint_us;
  579. if (latency < 0)
  580. latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
  581. beaconint_us = ieee80211_tu_to_usec(
  582. found->vif.bss_conf.beacon_int);
  583. timeout = local->dynamic_ps_forced_timeout;
  584. if (timeout < 0) {
  585. /*
  586. * Go to full PSM if the user configures a very low
  587. * latency requirement.
  588. * The 2000 second value is there for compatibility
  589. * until the PM_QOS_NETWORK_LATENCY is configured
  590. * with real values.
  591. */
  592. if (latency > (1900 * USEC_PER_MSEC) &&
  593. latency != (2000 * USEC_PER_SEC))
  594. timeout = 0;
  595. else
  596. timeout = 100;
  597. }
  598. local->dynamic_ps_user_timeout = timeout;
  599. if (!local->disable_dynamic_ps)
  600. conf->dynamic_ps_timeout =
  601. local->dynamic_ps_user_timeout;
  602. if (beaconint_us > latency) {
  603. local->ps_sdata = NULL;
  604. } else {
  605. struct ieee80211_bss *bss;
  606. int maxslp = 1;
  607. u8 dtimper;
  608. bss = (void *)found->u.mgd.associated->priv;
  609. dtimper = bss->dtim_period;
  610. /* If the TIM IE is invalid, pretend the value is 1 */
  611. if (!dtimper)
  612. dtimper = 1;
  613. else if (dtimper > 1)
  614. maxslp = min_t(int, dtimper,
  615. latency / beaconint_us);
  616. local->hw.conf.max_sleep_period = maxslp;
  617. local->hw.conf.ps_dtim_period = dtimper;
  618. local->ps_sdata = found;
  619. }
  620. } else {
  621. local->ps_sdata = NULL;
  622. }
  623. change:
  624. ieee80211_change_ps(local);
  625. }
  626. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  627. {
  628. struct ieee80211_local *local =
  629. container_of(work, struct ieee80211_local,
  630. dynamic_ps_disable_work);
  631. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  632. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  633. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  634. }
  635. ieee80211_wake_queues_by_reason(&local->hw,
  636. IEEE80211_QUEUE_STOP_REASON_PS);
  637. }
  638. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  639. {
  640. struct ieee80211_local *local =
  641. container_of(work, struct ieee80211_local,
  642. dynamic_ps_enable_work);
  643. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  644. struct ieee80211_if_managed *ifmgd;
  645. unsigned long flags;
  646. int q;
  647. /* can only happen when PS was just disabled anyway */
  648. if (!sdata)
  649. return;
  650. ifmgd = &sdata->u.mgd;
  651. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  652. return;
  653. if (!local->disable_dynamic_ps &&
  654. local->hw.conf.dynamic_ps_timeout > 0) {
  655. /* don't enter PS if TX frames are pending */
  656. if (drv_tx_frames_pending(local)) {
  657. mod_timer(&local->dynamic_ps_timer, jiffies +
  658. msecs_to_jiffies(
  659. local->hw.conf.dynamic_ps_timeout));
  660. return;
  661. }
  662. /*
  663. * transmission can be stopped by others which leads to
  664. * dynamic_ps_timer expiry. Postpone the ps timer if it
  665. * is not the actual idle state.
  666. */
  667. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  668. for (q = 0; q < local->hw.queues; q++) {
  669. if (local->queue_stop_reasons[q]) {
  670. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  671. flags);
  672. mod_timer(&local->dynamic_ps_timer, jiffies +
  673. msecs_to_jiffies(
  674. local->hw.conf.dynamic_ps_timeout));
  675. return;
  676. }
  677. }
  678. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  679. }
  680. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  681. (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) {
  682. netif_tx_stop_all_queues(sdata->dev);
  683. if (drv_tx_frames_pending(local))
  684. mod_timer(&local->dynamic_ps_timer, jiffies +
  685. msecs_to_jiffies(
  686. local->hw.conf.dynamic_ps_timeout));
  687. else {
  688. ieee80211_send_nullfunc(local, sdata, 1);
  689. /* Flush to get the tx status of nullfunc frame */
  690. drv_flush(local, false);
  691. }
  692. }
  693. if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
  694. (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
  695. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  696. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  697. local->hw.conf.flags |= IEEE80211_CONF_PS;
  698. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  699. }
  700. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  701. netif_tx_wake_all_queues(sdata->dev);
  702. }
  703. void ieee80211_dynamic_ps_timer(unsigned long data)
  704. {
  705. struct ieee80211_local *local = (void *) data;
  706. if (local->quiescing || local->suspended)
  707. return;
  708. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  709. }
  710. /* MLME */
  711. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  712. struct ieee80211_sub_if_data *sdata,
  713. u8 *wmm_param, size_t wmm_param_len)
  714. {
  715. struct ieee80211_tx_queue_params params;
  716. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  717. size_t left;
  718. int count;
  719. u8 *pos, uapsd_queues = 0;
  720. if (!local->ops->conf_tx)
  721. return;
  722. if (local->hw.queues < 4)
  723. return;
  724. if (!wmm_param)
  725. return;
  726. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  727. return;
  728. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  729. uapsd_queues = local->uapsd_queues;
  730. count = wmm_param[6] & 0x0f;
  731. if (count == ifmgd->wmm_last_param_set)
  732. return;
  733. ifmgd->wmm_last_param_set = count;
  734. pos = wmm_param + 8;
  735. left = wmm_param_len - 8;
  736. memset(&params, 0, sizeof(params));
  737. local->wmm_acm = 0;
  738. for (; left >= 4; left -= 4, pos += 4) {
  739. int aci = (pos[0] >> 5) & 0x03;
  740. int acm = (pos[0] >> 4) & 0x01;
  741. bool uapsd = false;
  742. int queue;
  743. switch (aci) {
  744. case 1: /* AC_BK */
  745. queue = 3;
  746. if (acm)
  747. local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  748. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  749. uapsd = true;
  750. break;
  751. case 2: /* AC_VI */
  752. queue = 1;
  753. if (acm)
  754. local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  755. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  756. uapsd = true;
  757. break;
  758. case 3: /* AC_VO */
  759. queue = 0;
  760. if (acm)
  761. local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  762. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  763. uapsd = true;
  764. break;
  765. case 0: /* AC_BE */
  766. default:
  767. queue = 2;
  768. if (acm)
  769. local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  770. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  771. uapsd = true;
  772. break;
  773. }
  774. params.aifs = pos[0] & 0x0f;
  775. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  776. params.cw_min = ecw2cw(pos[1] & 0x0f);
  777. params.txop = get_unaligned_le16(pos + 2);
  778. params.uapsd = uapsd;
  779. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  780. wiphy_debug(local->hw.wiphy,
  781. "WMM queue=%d aci=%d acm=%d aifs=%d "
  782. "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
  783. queue, aci, acm,
  784. params.aifs, params.cw_min, params.cw_max,
  785. params.txop, params.uapsd);
  786. #endif
  787. sdata->tx_conf[queue] = params;
  788. if (drv_conf_tx(local, sdata, queue, &params))
  789. wiphy_debug(local->hw.wiphy,
  790. "failed to set TX queue parameters for queue %d\n",
  791. queue);
  792. }
  793. /* enable WMM or activate new settings */
  794. sdata->vif.bss_conf.qos = true;
  795. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  796. }
  797. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  798. u16 capab, bool erp_valid, u8 erp)
  799. {
  800. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  801. u32 changed = 0;
  802. bool use_protection;
  803. bool use_short_preamble;
  804. bool use_short_slot;
  805. if (erp_valid) {
  806. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  807. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  808. } else {
  809. use_protection = false;
  810. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  811. }
  812. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  813. if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
  814. use_short_slot = true;
  815. if (use_protection != bss_conf->use_cts_prot) {
  816. bss_conf->use_cts_prot = use_protection;
  817. changed |= BSS_CHANGED_ERP_CTS_PROT;
  818. }
  819. if (use_short_preamble != bss_conf->use_short_preamble) {
  820. bss_conf->use_short_preamble = use_short_preamble;
  821. changed |= BSS_CHANGED_ERP_PREAMBLE;
  822. }
  823. if (use_short_slot != bss_conf->use_short_slot) {
  824. bss_conf->use_short_slot = use_short_slot;
  825. changed |= BSS_CHANGED_ERP_SLOT;
  826. }
  827. return changed;
  828. }
  829. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  830. struct cfg80211_bss *cbss,
  831. u32 bss_info_changed)
  832. {
  833. struct ieee80211_bss *bss = (void *)cbss->priv;
  834. struct ieee80211_local *local = sdata->local;
  835. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  836. bss_info_changed |= BSS_CHANGED_ASSOC;
  837. /* set timing information */
  838. bss_conf->beacon_int = cbss->beacon_interval;
  839. bss_conf->timestamp = cbss->tsf;
  840. bss_info_changed |= BSS_CHANGED_BEACON_INT;
  841. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  842. cbss->capability, bss->has_erp_value, bss->erp_value);
  843. sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
  844. IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
  845. sdata->u.mgd.associated = cbss;
  846. memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  847. sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
  848. /* just to be sure */
  849. sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  850. IEEE80211_STA_BEACON_POLL);
  851. ieee80211_led_assoc(local, 1);
  852. if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
  853. bss_conf->dtim_period = bss->dtim_period;
  854. else
  855. bss_conf->dtim_period = 0;
  856. bss_conf->assoc = 1;
  857. /*
  858. * For now just always ask the driver to update the basic rateset
  859. * when we have associated, we aren't checking whether it actually
  860. * changed or not.
  861. */
  862. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  863. /* And the BSSID changed - we're associated now */
  864. bss_info_changed |= BSS_CHANGED_BSSID;
  865. /* Tell the driver to monitor connection quality (if supported) */
  866. if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
  867. bss_conf->cqm_rssi_thold)
  868. bss_info_changed |= BSS_CHANGED_CQM;
  869. /* Enable ARP filtering */
  870. if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
  871. bss_conf->arp_filter_enabled = sdata->arp_filter_state;
  872. bss_info_changed |= BSS_CHANGED_ARP_FILTER;
  873. }
  874. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  875. mutex_lock(&local->iflist_mtx);
  876. ieee80211_recalc_ps(local, -1);
  877. ieee80211_recalc_smps(local);
  878. mutex_unlock(&local->iflist_mtx);
  879. netif_tx_start_all_queues(sdata->dev);
  880. netif_carrier_on(sdata->dev);
  881. }
  882. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  883. bool remove_sta, bool tx)
  884. {
  885. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  886. struct ieee80211_local *local = sdata->local;
  887. struct sta_info *sta;
  888. u32 changed = 0, config_changed = 0;
  889. u8 bssid[ETH_ALEN];
  890. ASSERT_MGD_MTX(ifmgd);
  891. if (WARN_ON(!ifmgd->associated))
  892. return;
  893. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  894. ifmgd->associated = NULL;
  895. memset(ifmgd->bssid, 0, ETH_ALEN);
  896. /*
  897. * we need to commit the associated = NULL change because the
  898. * scan code uses that to determine whether this iface should
  899. * go to/wake up from powersave or not -- and could otherwise
  900. * wake the queues erroneously.
  901. */
  902. smp_mb();
  903. /*
  904. * Thus, we can only afterwards stop the queues -- to account
  905. * for the case where another CPU is finishing a scan at this
  906. * time -- we don't want the scan code to enable queues.
  907. */
  908. netif_tx_stop_all_queues(sdata->dev);
  909. netif_carrier_off(sdata->dev);
  910. mutex_lock(&local->sta_mtx);
  911. sta = sta_info_get(sdata, bssid);
  912. if (sta) {
  913. set_sta_flags(sta, WLAN_STA_BLOCK_BA);
  914. ieee80211_sta_tear_down_BA_sessions(sta, tx);
  915. }
  916. mutex_unlock(&local->sta_mtx);
  917. changed |= ieee80211_reset_erp_info(sdata);
  918. ieee80211_led_assoc(local, 0);
  919. changed |= BSS_CHANGED_ASSOC;
  920. sdata->vif.bss_conf.assoc = false;
  921. ieee80211_set_wmm_default(sdata);
  922. /* channel(_type) changes are handled by ieee80211_hw_config */
  923. WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
  924. /* on the next assoc, re-program HT parameters */
  925. sdata->ht_opmode_valid = false;
  926. local->power_constr_level = 0;
  927. del_timer_sync(&local->dynamic_ps_timer);
  928. cancel_work_sync(&local->dynamic_ps_enable_work);
  929. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  930. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  931. config_changed |= IEEE80211_CONF_CHANGE_PS;
  932. }
  933. local->ps_sdata = NULL;
  934. ieee80211_hw_config(local, config_changed);
  935. /* Disable ARP filtering */
  936. if (sdata->vif.bss_conf.arp_filter_enabled) {
  937. sdata->vif.bss_conf.arp_filter_enabled = false;
  938. changed |= BSS_CHANGED_ARP_FILTER;
  939. }
  940. /* The BSSID (not really interesting) and HT changed */
  941. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  942. ieee80211_bss_info_change_notify(sdata, changed);
  943. if (remove_sta)
  944. sta_info_destroy_addr(sdata, bssid);
  945. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  946. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  947. del_timer_sync(&sdata->u.mgd.timer);
  948. del_timer_sync(&sdata->u.mgd.chswitch_timer);
  949. }
  950. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  951. struct ieee80211_hdr *hdr)
  952. {
  953. /*
  954. * We can postpone the mgd.timer whenever receiving unicast frames
  955. * from AP because we know that the connection is working both ways
  956. * at that time. But multicast frames (and hence also beacons) must
  957. * be ignored here, because we need to trigger the timer during
  958. * data idle periods for sending the periodic probe request to the
  959. * AP we're connected to.
  960. */
  961. if (is_multicast_ether_addr(hdr->addr1))
  962. return;
  963. ieee80211_sta_reset_conn_monitor(sdata);
  964. }
  965. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  966. {
  967. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  968. if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  969. IEEE80211_STA_CONNECTION_POLL)))
  970. return;
  971. ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  972. IEEE80211_STA_BEACON_POLL);
  973. mutex_lock(&sdata->local->iflist_mtx);
  974. ieee80211_recalc_ps(sdata->local, -1);
  975. mutex_unlock(&sdata->local->iflist_mtx);
  976. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  977. return;
  978. /*
  979. * We've received a probe response, but are not sure whether
  980. * we have or will be receiving any beacons or data, so let's
  981. * schedule the timers again, just in case.
  982. */
  983. ieee80211_sta_reset_beacon_monitor(sdata);
  984. mod_timer(&ifmgd->conn_mon_timer,
  985. round_jiffies_up(jiffies +
  986. IEEE80211_CONNECTION_IDLE_TIME));
  987. }
  988. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  989. struct ieee80211_hdr *hdr, bool ack)
  990. {
  991. if (!ieee80211_is_data(hdr->frame_control))
  992. return;
  993. if (ack)
  994. ieee80211_sta_reset_conn_monitor(sdata);
  995. if (ieee80211_is_nullfunc(hdr->frame_control) &&
  996. sdata->u.mgd.probe_send_count > 0) {
  997. if (ack)
  998. sdata->u.mgd.probe_send_count = 0;
  999. else
  1000. sdata->u.mgd.nullfunc_failed = true;
  1001. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1002. }
  1003. }
  1004. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  1005. {
  1006. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1007. const u8 *ssid;
  1008. u8 *dst = ifmgd->associated->bssid;
  1009. u8 unicast_limit = max(1, max_probe_tries - 3);
  1010. /*
  1011. * Try sending broadcast probe requests for the last three
  1012. * probe requests after the first ones failed since some
  1013. * buggy APs only support broadcast probe requests.
  1014. */
  1015. if (ifmgd->probe_send_count >= unicast_limit)
  1016. dst = NULL;
  1017. /*
  1018. * When the hardware reports an accurate Tx ACK status, it's
  1019. * better to send a nullfunc frame instead of a probe request,
  1020. * as it will kick us off the AP quickly if we aren't associated
  1021. * anymore. The timeout will be reset if the frame is ACKed by
  1022. * the AP.
  1023. */
  1024. if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1025. ifmgd->nullfunc_failed = false;
  1026. ieee80211_send_nullfunc(sdata->local, sdata, 0);
  1027. } else {
  1028. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1029. ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0,
  1030. (u32) -1, true, false);
  1031. }
  1032. ifmgd->probe_send_count++;
  1033. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  1034. run_again(ifmgd, ifmgd->probe_timeout);
  1035. }
  1036. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  1037. bool beacon)
  1038. {
  1039. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1040. bool already = false;
  1041. if (!ieee80211_sdata_running(sdata))
  1042. return;
  1043. if (sdata->local->scanning)
  1044. return;
  1045. if (sdata->local->tmp_channel)
  1046. return;
  1047. mutex_lock(&ifmgd->mtx);
  1048. if (!ifmgd->associated)
  1049. goto out;
  1050. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1051. if (beacon && net_ratelimit())
  1052. printk(KERN_DEBUG "%s: detected beacon loss from AP "
  1053. "- sending probe request\n", sdata->name);
  1054. #endif
  1055. /*
  1056. * The driver/our work has already reported this event or the
  1057. * connection monitoring has kicked in and we have already sent
  1058. * a probe request. Or maybe the AP died and the driver keeps
  1059. * reporting until we disassociate...
  1060. *
  1061. * In either case we have to ignore the current call to this
  1062. * function (except for setting the correct probe reason bit)
  1063. * because otherwise we would reset the timer every time and
  1064. * never check whether we received a probe response!
  1065. */
  1066. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1067. IEEE80211_STA_CONNECTION_POLL))
  1068. already = true;
  1069. if (beacon)
  1070. ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
  1071. else
  1072. ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
  1073. if (already)
  1074. goto out;
  1075. mutex_lock(&sdata->local->iflist_mtx);
  1076. ieee80211_recalc_ps(sdata->local, -1);
  1077. mutex_unlock(&sdata->local->iflist_mtx);
  1078. ifmgd->probe_send_count = 0;
  1079. ieee80211_mgd_probe_ap_send(sdata);
  1080. out:
  1081. mutex_unlock(&ifmgd->mtx);
  1082. }
  1083. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  1084. struct ieee80211_vif *vif)
  1085. {
  1086. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1087. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1088. struct sk_buff *skb;
  1089. const u8 *ssid;
  1090. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1091. return NULL;
  1092. ASSERT_MGD_MTX(ifmgd);
  1093. if (!ifmgd->associated)
  1094. return NULL;
  1095. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1096. skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
  1097. (u32) -1, ssid + 2, ssid[1],
  1098. NULL, 0, true);
  1099. return skb;
  1100. }
  1101. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  1102. static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
  1103. {
  1104. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1105. struct ieee80211_local *local = sdata->local;
  1106. u8 bssid[ETH_ALEN];
  1107. mutex_lock(&ifmgd->mtx);
  1108. if (!ifmgd->associated) {
  1109. mutex_unlock(&ifmgd->mtx);
  1110. return;
  1111. }
  1112. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  1113. printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n",
  1114. sdata->name, bssid);
  1115. ieee80211_set_disassoc(sdata, true, true);
  1116. mutex_unlock(&ifmgd->mtx);
  1117. mutex_lock(&local->mtx);
  1118. ieee80211_recalc_idle(local);
  1119. mutex_unlock(&local->mtx);
  1120. /*
  1121. * must be outside lock due to cfg80211,
  1122. * but that's not a problem.
  1123. */
  1124. ieee80211_send_deauth_disassoc(sdata, bssid,
  1125. IEEE80211_STYPE_DEAUTH,
  1126. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  1127. NULL, true);
  1128. }
  1129. void ieee80211_beacon_connection_loss_work(struct work_struct *work)
  1130. {
  1131. struct ieee80211_sub_if_data *sdata =
  1132. container_of(work, struct ieee80211_sub_if_data,
  1133. u.mgd.beacon_connection_loss_work);
  1134. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  1135. __ieee80211_connection_loss(sdata);
  1136. else
  1137. ieee80211_mgd_probe_ap(sdata, true);
  1138. }
  1139. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  1140. {
  1141. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1142. struct ieee80211_hw *hw = &sdata->local->hw;
  1143. trace_api_beacon_loss(sdata);
  1144. WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
  1145. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1146. }
  1147. EXPORT_SYMBOL(ieee80211_beacon_loss);
  1148. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  1149. {
  1150. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1151. struct ieee80211_hw *hw = &sdata->local->hw;
  1152. trace_api_connection_loss(sdata);
  1153. WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
  1154. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1155. }
  1156. EXPORT_SYMBOL(ieee80211_connection_loss);
  1157. static enum rx_mgmt_action __must_check
  1158. ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1159. struct ieee80211_mgmt *mgmt, size_t len)
  1160. {
  1161. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1162. const u8 *bssid = NULL;
  1163. u16 reason_code;
  1164. if (len < 24 + 2)
  1165. return RX_MGMT_NONE;
  1166. ASSERT_MGD_MTX(ifmgd);
  1167. bssid = ifmgd->associated->bssid;
  1168. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1169. printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
  1170. sdata->name, bssid, reason_code);
  1171. ieee80211_set_disassoc(sdata, true, false);
  1172. mutex_lock(&sdata->local->mtx);
  1173. ieee80211_recalc_idle(sdata->local);
  1174. mutex_unlock(&sdata->local->mtx);
  1175. return RX_MGMT_CFG80211_DEAUTH;
  1176. }
  1177. static enum rx_mgmt_action __must_check
  1178. ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1179. struct ieee80211_mgmt *mgmt, size_t len)
  1180. {
  1181. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1182. u16 reason_code;
  1183. if (len < 24 + 2)
  1184. return RX_MGMT_NONE;
  1185. ASSERT_MGD_MTX(ifmgd);
  1186. if (WARN_ON(!ifmgd->associated))
  1187. return RX_MGMT_NONE;
  1188. if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
  1189. return RX_MGMT_NONE;
  1190. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1191. printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
  1192. sdata->name, mgmt->sa, reason_code);
  1193. ieee80211_set_disassoc(sdata, true, false);
  1194. mutex_lock(&sdata->local->mtx);
  1195. ieee80211_recalc_idle(sdata->local);
  1196. mutex_unlock(&sdata->local->mtx);
  1197. return RX_MGMT_CFG80211_DISASSOC;
  1198. }
  1199. static bool ieee80211_assoc_success(struct ieee80211_work *wk,
  1200. struct ieee80211_mgmt *mgmt, size_t len)
  1201. {
  1202. struct ieee80211_sub_if_data *sdata = wk->sdata;
  1203. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1204. struct ieee80211_local *local = sdata->local;
  1205. struct ieee80211_supported_band *sband;
  1206. struct sta_info *sta;
  1207. struct cfg80211_bss *cbss = wk->assoc.bss;
  1208. u8 *pos;
  1209. u32 rates, basic_rates;
  1210. u16 capab_info, aid;
  1211. struct ieee802_11_elems elems;
  1212. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1213. u32 changed = 0;
  1214. int i, j, err;
  1215. bool have_higher_than_11mbit = false;
  1216. u16 ap_ht_cap_flags;
  1217. /* AssocResp and ReassocResp have identical structure */
  1218. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1219. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1220. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1221. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1222. "set\n", sdata->name, aid);
  1223. aid &= ~(BIT(15) | BIT(14));
  1224. pos = mgmt->u.assoc_resp.variable;
  1225. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1226. if (!elems.supp_rates) {
  1227. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1228. sdata->name);
  1229. return false;
  1230. }
  1231. ifmgd->aid = aid;
  1232. mutex_lock(&sdata->local->sta_mtx);
  1233. /*
  1234. * station info was already allocated and inserted before
  1235. * the association and should be available to us
  1236. */
  1237. sta = sta_info_get_rx(sdata, cbss->bssid);
  1238. if (WARN_ON(!sta)) {
  1239. mutex_unlock(&sdata->local->sta_mtx);
  1240. return false;
  1241. }
  1242. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
  1243. WLAN_STA_ASSOC_AP);
  1244. if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  1245. set_sta_flags(sta, WLAN_STA_AUTHORIZED);
  1246. rates = 0;
  1247. basic_rates = 0;
  1248. sband = local->hw.wiphy->bands[wk->chan->band];
  1249. for (i = 0; i < elems.supp_rates_len; i++) {
  1250. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1251. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1252. if (rate > 110)
  1253. have_higher_than_11mbit = true;
  1254. for (j = 0; j < sband->n_bitrates; j++) {
  1255. if (sband->bitrates[j].bitrate == rate) {
  1256. rates |= BIT(j);
  1257. if (is_basic)
  1258. basic_rates |= BIT(j);
  1259. break;
  1260. }
  1261. }
  1262. }
  1263. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1264. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1265. bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
  1266. if (rate > 110)
  1267. have_higher_than_11mbit = true;
  1268. for (j = 0; j < sband->n_bitrates; j++) {
  1269. if (sband->bitrates[j].bitrate == rate) {
  1270. rates |= BIT(j);
  1271. if (is_basic)
  1272. basic_rates |= BIT(j);
  1273. break;
  1274. }
  1275. }
  1276. }
  1277. sta->sta.supp_rates[wk->chan->band] = rates;
  1278. sdata->vif.bss_conf.basic_rates = basic_rates;
  1279. /* cf. IEEE 802.11 9.2.12 */
  1280. if (wk->chan->band == IEEE80211_BAND_2GHZ &&
  1281. have_higher_than_11mbit)
  1282. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1283. else
  1284. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1285. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1286. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1287. elems.ht_cap_elem, &sta->sta.ht_cap);
  1288. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1289. rate_control_rate_init(sta);
  1290. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  1291. set_sta_flags(sta, WLAN_STA_MFP);
  1292. if (elems.wmm_param)
  1293. set_sta_flags(sta, WLAN_STA_WME);
  1294. /* sta_info_reinsert will also unlock the mutex lock */
  1295. err = sta_info_reinsert(sta);
  1296. sta = NULL;
  1297. if (err) {
  1298. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1299. " the AP (error %d)\n", sdata->name, err);
  1300. return false;
  1301. }
  1302. /*
  1303. * Always handle WMM once after association regardless
  1304. * of the first value the AP uses. Setting -1 here has
  1305. * that effect because the AP values is an unsigned
  1306. * 4-bit value.
  1307. */
  1308. ifmgd->wmm_last_param_set = -1;
  1309. if (elems.wmm_param)
  1310. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  1311. elems.wmm_param_len);
  1312. else
  1313. ieee80211_set_wmm_default(sdata);
  1314. local->oper_channel = wk->chan;
  1315. if (elems.ht_info_elem && elems.wmm_param &&
  1316. (sdata->local->hw.queues >= 4) &&
  1317. !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1318. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1319. cbss->bssid, ap_ht_cap_flags,
  1320. false);
  1321. /* set AID and assoc capability,
  1322. * ieee80211_set_associated() will tell the driver */
  1323. bss_conf->aid = aid;
  1324. bss_conf->assoc_capability = capab_info;
  1325. ieee80211_set_associated(sdata, cbss, changed);
  1326. /*
  1327. * If we're using 4-addr mode, let the AP know that we're
  1328. * doing so, so that it can create the STA VLAN on its side
  1329. */
  1330. if (ifmgd->use_4addr)
  1331. ieee80211_send_4addr_nullfunc(local, sdata);
  1332. /*
  1333. * Start timer to probe the connection to the AP now.
  1334. * Also start the timer that will detect beacon loss.
  1335. */
  1336. ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
  1337. ieee80211_sta_reset_beacon_monitor(sdata);
  1338. return true;
  1339. }
  1340. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1341. struct ieee80211_mgmt *mgmt,
  1342. size_t len,
  1343. struct ieee80211_rx_status *rx_status,
  1344. struct ieee802_11_elems *elems,
  1345. bool beacon)
  1346. {
  1347. struct ieee80211_local *local = sdata->local;
  1348. int freq;
  1349. struct ieee80211_bss *bss;
  1350. struct ieee80211_channel *channel;
  1351. bool need_ps = false;
  1352. if (sdata->u.mgd.associated) {
  1353. bss = (void *)sdata->u.mgd.associated->priv;
  1354. /* not previously set so we may need to recalc */
  1355. need_ps = !bss->dtim_period;
  1356. }
  1357. if (elems->ds_params && elems->ds_params_len == 1)
  1358. freq = ieee80211_channel_to_frequency(elems->ds_params[0],
  1359. rx_status->band);
  1360. else
  1361. freq = rx_status->freq;
  1362. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1363. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1364. return;
  1365. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1366. channel, beacon);
  1367. if (bss)
  1368. ieee80211_rx_bss_put(local, bss);
  1369. if (!sdata->u.mgd.associated)
  1370. return;
  1371. if (need_ps) {
  1372. mutex_lock(&local->iflist_mtx);
  1373. ieee80211_recalc_ps(local, -1);
  1374. mutex_unlock(&local->iflist_mtx);
  1375. }
  1376. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1377. (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
  1378. ETH_ALEN) == 0)) {
  1379. struct ieee80211_channel_sw_ie *sw_elem =
  1380. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1381. ieee80211_sta_process_chanswitch(sdata, sw_elem,
  1382. bss, rx_status->mactime);
  1383. }
  1384. }
  1385. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1386. struct sk_buff *skb)
  1387. {
  1388. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1389. struct ieee80211_if_managed *ifmgd;
  1390. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  1391. size_t baselen, len = skb->len;
  1392. struct ieee802_11_elems elems;
  1393. ifmgd = &sdata->u.mgd;
  1394. ASSERT_MGD_MTX(ifmgd);
  1395. if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
  1396. return; /* ignore ProbeResp to foreign address */
  1397. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1398. if (baselen > len)
  1399. return;
  1400. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1401. &elems);
  1402. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1403. if (ifmgd->associated &&
  1404. memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
  1405. ieee80211_reset_ap_probe(sdata);
  1406. }
  1407. /*
  1408. * This is the canonical list of information elements we care about,
  1409. * the filter code also gives us all changes to the Microsoft OUI
  1410. * (00:50:F2) vendor IE which is used for WMM which we need to track.
  1411. *
  1412. * We implement beacon filtering in software since that means we can
  1413. * avoid processing the frame here and in cfg80211, and userspace
  1414. * will not be able to tell whether the hardware supports it or not.
  1415. *
  1416. * XXX: This list needs to be dynamic -- userspace needs to be able to
  1417. * add items it requires. It also needs to be able to tell us to
  1418. * look out for other vendor IEs.
  1419. */
  1420. static const u64 care_about_ies =
  1421. (1ULL << WLAN_EID_COUNTRY) |
  1422. (1ULL << WLAN_EID_ERP_INFO) |
  1423. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  1424. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  1425. (1ULL << WLAN_EID_HT_CAPABILITY) |
  1426. (1ULL << WLAN_EID_HT_INFORMATION);
  1427. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1428. struct ieee80211_mgmt *mgmt,
  1429. size_t len,
  1430. struct ieee80211_rx_status *rx_status)
  1431. {
  1432. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1433. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1434. size_t baselen;
  1435. struct ieee802_11_elems elems;
  1436. struct ieee80211_local *local = sdata->local;
  1437. u32 changed = 0;
  1438. bool erp_valid, directed_tim = false;
  1439. u8 erp_value = 0;
  1440. u32 ncrc;
  1441. u8 *bssid;
  1442. ASSERT_MGD_MTX(ifmgd);
  1443. /* Process beacon from the current BSS */
  1444. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1445. if (baselen > len)
  1446. return;
  1447. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1448. return;
  1449. /*
  1450. * We might have received a number of frames, among them a
  1451. * disassoc frame and a beacon...
  1452. */
  1453. if (!ifmgd->associated)
  1454. return;
  1455. bssid = ifmgd->associated->bssid;
  1456. /*
  1457. * And in theory even frames from a different AP we were just
  1458. * associated to a split-second ago!
  1459. */
  1460. if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
  1461. return;
  1462. /* Track average RSSI from the Beacon frames of the current AP */
  1463. ifmgd->last_beacon_signal = rx_status->signal;
  1464. if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
  1465. ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
  1466. ifmgd->ave_beacon_signal = rx_status->signal * 16;
  1467. ifmgd->last_cqm_event_signal = 0;
  1468. ifmgd->count_beacon_signal = 1;
  1469. ifmgd->last_ave_beacon_signal = 0;
  1470. } else {
  1471. ifmgd->ave_beacon_signal =
  1472. (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
  1473. (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
  1474. ifmgd->ave_beacon_signal) / 16;
  1475. ifmgd->count_beacon_signal++;
  1476. }
  1477. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  1478. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  1479. int sig = ifmgd->ave_beacon_signal;
  1480. int last_sig = ifmgd->last_ave_beacon_signal;
  1481. /*
  1482. * if signal crosses either of the boundaries, invoke callback
  1483. * with appropriate parameters
  1484. */
  1485. if (sig > ifmgd->rssi_max_thold &&
  1486. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  1487. ifmgd->last_ave_beacon_signal = sig;
  1488. drv_rssi_callback(local, RSSI_EVENT_HIGH);
  1489. } else if (sig < ifmgd->rssi_min_thold &&
  1490. (last_sig >= ifmgd->rssi_max_thold ||
  1491. last_sig == 0)) {
  1492. ifmgd->last_ave_beacon_signal = sig;
  1493. drv_rssi_callback(local, RSSI_EVENT_LOW);
  1494. }
  1495. }
  1496. if (bss_conf->cqm_rssi_thold &&
  1497. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  1498. !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1499. int sig = ifmgd->ave_beacon_signal / 16;
  1500. int last_event = ifmgd->last_cqm_event_signal;
  1501. int thold = bss_conf->cqm_rssi_thold;
  1502. int hyst = bss_conf->cqm_rssi_hyst;
  1503. if (sig < thold &&
  1504. (last_event == 0 || sig < last_event - hyst)) {
  1505. ifmgd->last_cqm_event_signal = sig;
  1506. ieee80211_cqm_rssi_notify(
  1507. &sdata->vif,
  1508. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  1509. GFP_KERNEL);
  1510. } else if (sig > thold &&
  1511. (last_event == 0 || sig > last_event + hyst)) {
  1512. ifmgd->last_cqm_event_signal = sig;
  1513. ieee80211_cqm_rssi_notify(
  1514. &sdata->vif,
  1515. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  1516. GFP_KERNEL);
  1517. }
  1518. }
  1519. if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
  1520. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1521. if (net_ratelimit()) {
  1522. printk(KERN_DEBUG "%s: cancelling probereq poll due "
  1523. "to a received beacon\n", sdata->name);
  1524. }
  1525. #endif
  1526. ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
  1527. mutex_lock(&local->iflist_mtx);
  1528. ieee80211_recalc_ps(local, -1);
  1529. mutex_unlock(&local->iflist_mtx);
  1530. }
  1531. /*
  1532. * Push the beacon loss detection into the future since
  1533. * we are processing a beacon from the AP just now.
  1534. */
  1535. ieee80211_sta_reset_beacon_monitor(sdata);
  1536. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  1537. ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
  1538. len - baselen, &elems,
  1539. care_about_ies, ncrc);
  1540. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  1541. directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
  1542. ifmgd->aid);
  1543. if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
  1544. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
  1545. true);
  1546. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  1547. elems.wmm_param_len);
  1548. }
  1549. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  1550. if (directed_tim) {
  1551. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1552. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1553. ieee80211_hw_config(local,
  1554. IEEE80211_CONF_CHANGE_PS);
  1555. ieee80211_send_nullfunc(local, sdata, 0);
  1556. } else {
  1557. local->pspolling = true;
  1558. /*
  1559. * Here is assumed that the driver will be
  1560. * able to send ps-poll frame and receive a
  1561. * response even though power save mode is
  1562. * enabled, but some drivers might require
  1563. * to disable power save here. This needs
  1564. * to be investigated.
  1565. */
  1566. ieee80211_send_pspoll(local, sdata);
  1567. }
  1568. }
  1569. }
  1570. if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
  1571. return;
  1572. ifmgd->beacon_crc = ncrc;
  1573. ifmgd->beacon_crc_valid = true;
  1574. if (elems.erp_info && elems.erp_info_len >= 1) {
  1575. erp_valid = true;
  1576. erp_value = elems.erp_info[0];
  1577. } else {
  1578. erp_valid = false;
  1579. }
  1580. changed |= ieee80211_handle_bss_capability(sdata,
  1581. le16_to_cpu(mgmt->u.beacon.capab_info),
  1582. erp_valid, erp_value);
  1583. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
  1584. !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
  1585. struct sta_info *sta;
  1586. struct ieee80211_supported_band *sband;
  1587. u16 ap_ht_cap_flags;
  1588. rcu_read_lock();
  1589. sta = sta_info_get(sdata, bssid);
  1590. if (WARN_ON(!sta)) {
  1591. rcu_read_unlock();
  1592. return;
  1593. }
  1594. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1595. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1596. elems.ht_cap_elem, &sta->sta.ht_cap);
  1597. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1598. rcu_read_unlock();
  1599. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1600. bssid, ap_ht_cap_flags, true);
  1601. }
  1602. /* Note: country IE parsing is done for us by cfg80211 */
  1603. if (elems.country_elem) {
  1604. /* TODO: IBSS also needs this */
  1605. if (elems.pwr_constr_elem)
  1606. ieee80211_handle_pwr_constr(sdata,
  1607. le16_to_cpu(mgmt->u.probe_resp.capab_info),
  1608. elems.pwr_constr_elem,
  1609. elems.pwr_constr_elem_len);
  1610. }
  1611. ieee80211_bss_info_change_notify(sdata, changed);
  1612. }
  1613. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1614. struct sk_buff *skb)
  1615. {
  1616. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1617. struct ieee80211_rx_status *rx_status;
  1618. struct ieee80211_mgmt *mgmt;
  1619. enum rx_mgmt_action rma = RX_MGMT_NONE;
  1620. u16 fc;
  1621. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1622. mgmt = (struct ieee80211_mgmt *) skb->data;
  1623. fc = le16_to_cpu(mgmt->frame_control);
  1624. mutex_lock(&ifmgd->mtx);
  1625. if (ifmgd->associated &&
  1626. memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
  1627. switch (fc & IEEE80211_FCTL_STYPE) {
  1628. case IEEE80211_STYPE_BEACON:
  1629. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
  1630. rx_status);
  1631. break;
  1632. case IEEE80211_STYPE_PROBE_RESP:
  1633. ieee80211_rx_mgmt_probe_resp(sdata, skb);
  1634. break;
  1635. case IEEE80211_STYPE_DEAUTH:
  1636. rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  1637. break;
  1638. case IEEE80211_STYPE_DISASSOC:
  1639. rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  1640. break;
  1641. case IEEE80211_STYPE_ACTION:
  1642. switch (mgmt->u.action.category) {
  1643. case WLAN_CATEGORY_SPECTRUM_MGMT:
  1644. ieee80211_sta_process_chanswitch(sdata,
  1645. &mgmt->u.action.u.chan_switch.sw_elem,
  1646. (void *)ifmgd->associated->priv,
  1647. rx_status->mactime);
  1648. break;
  1649. }
  1650. }
  1651. mutex_unlock(&ifmgd->mtx);
  1652. switch (rma) {
  1653. case RX_MGMT_NONE:
  1654. /* no action */
  1655. break;
  1656. case RX_MGMT_CFG80211_DEAUTH:
  1657. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  1658. break;
  1659. case RX_MGMT_CFG80211_DISASSOC:
  1660. cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
  1661. break;
  1662. default:
  1663. WARN(1, "unexpected: %d", rma);
  1664. }
  1665. return;
  1666. }
  1667. mutex_unlock(&ifmgd->mtx);
  1668. if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
  1669. (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
  1670. struct ieee80211_local *local = sdata->local;
  1671. struct ieee80211_work *wk;
  1672. mutex_lock(&local->mtx);
  1673. list_for_each_entry(wk, &local->work_list, list) {
  1674. if (wk->sdata != sdata)
  1675. continue;
  1676. if (wk->type != IEEE80211_WORK_ASSOC &&
  1677. wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
  1678. continue;
  1679. if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
  1680. continue;
  1681. if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
  1682. continue;
  1683. /*
  1684. * Printing the message only here means we can't
  1685. * spuriously print it, but it also means that it
  1686. * won't be printed when the frame comes in before
  1687. * we even tried to associate or in similar cases.
  1688. *
  1689. * Ultimately, I suspect cfg80211 should print the
  1690. * messages instead.
  1691. */
  1692. printk(KERN_DEBUG
  1693. "%s: deauthenticated from %pM (Reason: %u)\n",
  1694. sdata->name, mgmt->bssid,
  1695. le16_to_cpu(mgmt->u.deauth.reason_code));
  1696. list_del_rcu(&wk->list);
  1697. free_work(wk);
  1698. break;
  1699. }
  1700. mutex_unlock(&local->mtx);
  1701. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  1702. }
  1703. }
  1704. static void ieee80211_sta_timer(unsigned long data)
  1705. {
  1706. struct ieee80211_sub_if_data *sdata =
  1707. (struct ieee80211_sub_if_data *) data;
  1708. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1709. struct ieee80211_local *local = sdata->local;
  1710. if (local->quiescing) {
  1711. set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
  1712. return;
  1713. }
  1714. ieee80211_queue_work(&local->hw, &sdata->work);
  1715. }
  1716. static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  1717. u8 *bssid, u8 reason)
  1718. {
  1719. struct ieee80211_local *local = sdata->local;
  1720. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1721. ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  1722. IEEE80211_STA_BEACON_POLL);
  1723. ieee80211_set_disassoc(sdata, true, true);
  1724. mutex_unlock(&ifmgd->mtx);
  1725. mutex_lock(&local->mtx);
  1726. ieee80211_recalc_idle(local);
  1727. mutex_unlock(&local->mtx);
  1728. /*
  1729. * must be outside lock due to cfg80211,
  1730. * but that's not a problem.
  1731. */
  1732. ieee80211_send_deauth_disassoc(sdata, bssid,
  1733. IEEE80211_STYPE_DEAUTH, reason,
  1734. NULL, true);
  1735. mutex_lock(&ifmgd->mtx);
  1736. }
  1737. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  1738. {
  1739. struct ieee80211_local *local = sdata->local;
  1740. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1741. /* then process the rest of the work */
  1742. mutex_lock(&ifmgd->mtx);
  1743. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1744. IEEE80211_STA_CONNECTION_POLL) &&
  1745. ifmgd->associated) {
  1746. u8 bssid[ETH_ALEN];
  1747. int max_tries;
  1748. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  1749. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  1750. max_tries = max_nullfunc_tries;
  1751. else
  1752. max_tries = max_probe_tries;
  1753. /* ACK received for nullfunc probing frame */
  1754. if (!ifmgd->probe_send_count)
  1755. ieee80211_reset_ap_probe(sdata);
  1756. else if (ifmgd->nullfunc_failed) {
  1757. if (ifmgd->probe_send_count < max_tries) {
  1758. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1759. wiphy_debug(local->hw.wiphy,
  1760. "%s: No ack for nullfunc frame to"
  1761. " AP %pM, try %d/%i\n",
  1762. sdata->name, bssid,
  1763. ifmgd->probe_send_count, max_tries);
  1764. #endif
  1765. ieee80211_mgd_probe_ap_send(sdata);
  1766. } else {
  1767. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1768. wiphy_debug(local->hw.wiphy,
  1769. "%s: No ack for nullfunc frame to"
  1770. " AP %pM, disconnecting.\n",
  1771. sdata->name, bssid);
  1772. #endif
  1773. ieee80211_sta_connection_lost(sdata, bssid,
  1774. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1775. }
  1776. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  1777. run_again(ifmgd, ifmgd->probe_timeout);
  1778. else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1779. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1780. wiphy_debug(local->hw.wiphy,
  1781. "%s: Failed to send nullfunc to AP %pM"
  1782. " after %dms, disconnecting.\n",
  1783. sdata->name,
  1784. bssid, probe_wait_ms);
  1785. #endif
  1786. ieee80211_sta_connection_lost(sdata, bssid,
  1787. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1788. } else if (ifmgd->probe_send_count < max_tries) {
  1789. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1790. wiphy_debug(local->hw.wiphy,
  1791. "%s: No probe response from AP %pM"
  1792. " after %dms, try %d/%i\n",
  1793. sdata->name,
  1794. bssid, probe_wait_ms,
  1795. ifmgd->probe_send_count, max_tries);
  1796. #endif
  1797. ieee80211_mgd_probe_ap_send(sdata);
  1798. } else {
  1799. /*
  1800. * We actually lost the connection ... or did we?
  1801. * Let's make sure!
  1802. */
  1803. wiphy_debug(local->hw.wiphy,
  1804. "%s: No probe response from AP %pM"
  1805. " after %dms, disconnecting.\n",
  1806. sdata->name,
  1807. bssid, probe_wait_ms);
  1808. ieee80211_sta_connection_lost(sdata, bssid,
  1809. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1810. }
  1811. }
  1812. mutex_unlock(&ifmgd->mtx);
  1813. }
  1814. static void ieee80211_sta_bcn_mon_timer(unsigned long data)
  1815. {
  1816. struct ieee80211_sub_if_data *sdata =
  1817. (struct ieee80211_sub_if_data *) data;
  1818. struct ieee80211_local *local = sdata->local;
  1819. if (local->quiescing)
  1820. return;
  1821. ieee80211_queue_work(&sdata->local->hw,
  1822. &sdata->u.mgd.beacon_connection_loss_work);
  1823. }
  1824. static void ieee80211_sta_conn_mon_timer(unsigned long data)
  1825. {
  1826. struct ieee80211_sub_if_data *sdata =
  1827. (struct ieee80211_sub_if_data *) data;
  1828. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1829. struct ieee80211_local *local = sdata->local;
  1830. if (local->quiescing)
  1831. return;
  1832. ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
  1833. }
  1834. static void ieee80211_sta_monitor_work(struct work_struct *work)
  1835. {
  1836. struct ieee80211_sub_if_data *sdata =
  1837. container_of(work, struct ieee80211_sub_if_data,
  1838. u.mgd.monitor_work);
  1839. ieee80211_mgd_probe_ap(sdata, false);
  1840. }
  1841. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  1842. {
  1843. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  1844. sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
  1845. IEEE80211_STA_CONNECTION_POLL);
  1846. /* let's probe the connection once */
  1847. ieee80211_queue_work(&sdata->local->hw,
  1848. &sdata->u.mgd.monitor_work);
  1849. /* and do all the other regular work too */
  1850. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1851. }
  1852. }
  1853. #ifdef CONFIG_PM
  1854. void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
  1855. {
  1856. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1857. /*
  1858. * we need to use atomic bitops for the running bits
  1859. * only because both timers might fire at the same
  1860. * time -- the code here is properly synchronised.
  1861. */
  1862. cancel_work_sync(&ifmgd->request_smps_work);
  1863. cancel_work_sync(&ifmgd->beacon_connection_loss_work);
  1864. if (del_timer_sync(&ifmgd->timer))
  1865. set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
  1866. cancel_work_sync(&ifmgd->chswitch_work);
  1867. if (del_timer_sync(&ifmgd->chswitch_timer))
  1868. set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
  1869. cancel_work_sync(&ifmgd->monitor_work);
  1870. /* these will just be re-established on connection */
  1871. del_timer_sync(&ifmgd->conn_mon_timer);
  1872. del_timer_sync(&ifmgd->bcn_mon_timer);
  1873. }
  1874. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  1875. {
  1876. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1877. if (!ifmgd->associated)
  1878. return;
  1879. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  1880. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  1881. mutex_lock(&ifmgd->mtx);
  1882. if (ifmgd->associated) {
  1883. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1884. wiphy_debug(sdata->local->hw.wiphy,
  1885. "%s: driver requested disconnect after resume.\n",
  1886. sdata->name);
  1887. #endif
  1888. ieee80211_sta_connection_lost(sdata,
  1889. ifmgd->associated->bssid,
  1890. WLAN_REASON_UNSPECIFIED);
  1891. mutex_unlock(&ifmgd->mtx);
  1892. return;
  1893. }
  1894. mutex_unlock(&ifmgd->mtx);
  1895. }
  1896. if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
  1897. add_timer(&ifmgd->timer);
  1898. if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
  1899. add_timer(&ifmgd->chswitch_timer);
  1900. ieee80211_sta_reset_beacon_monitor(sdata);
  1901. ieee80211_restart_sta_timer(sdata);
  1902. ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.monitor_work);
  1903. }
  1904. #endif
  1905. /* interface setup */
  1906. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  1907. {
  1908. struct ieee80211_if_managed *ifmgd;
  1909. ifmgd = &sdata->u.mgd;
  1910. INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  1911. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  1912. INIT_WORK(&ifmgd->beacon_connection_loss_work,
  1913. ieee80211_beacon_connection_loss_work);
  1914. INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
  1915. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  1916. (unsigned long) sdata);
  1917. setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
  1918. (unsigned long) sdata);
  1919. setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
  1920. (unsigned long) sdata);
  1921. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  1922. (unsigned long) sdata);
  1923. ifmgd->flags = 0;
  1924. mutex_init(&ifmgd->mtx);
  1925. if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
  1926. ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
  1927. else
  1928. ifmgd->req_smps = IEEE80211_SMPS_OFF;
  1929. }
  1930. /* scan finished notification */
  1931. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  1932. {
  1933. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1934. /* Restart STA timers */
  1935. rcu_read_lock();
  1936. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  1937. ieee80211_restart_sta_timer(sdata);
  1938. rcu_read_unlock();
  1939. }
  1940. int ieee80211_max_network_latency(struct notifier_block *nb,
  1941. unsigned long data, void *dummy)
  1942. {
  1943. s32 latency_usec = (s32) data;
  1944. struct ieee80211_local *local =
  1945. container_of(nb, struct ieee80211_local,
  1946. network_latency_notifier);
  1947. mutex_lock(&local->iflist_mtx);
  1948. ieee80211_recalc_ps(local, latency_usec);
  1949. mutex_unlock(&local->iflist_mtx);
  1950. return 0;
  1951. }
  1952. /* config hooks */
  1953. static enum work_done_result
  1954. ieee80211_probe_auth_done(struct ieee80211_work *wk,
  1955. struct sk_buff *skb)
  1956. {
  1957. struct ieee80211_local *local = wk->sdata->local;
  1958. if (!skb) {
  1959. cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
  1960. goto destroy;
  1961. }
  1962. if (wk->type == IEEE80211_WORK_AUTH) {
  1963. cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
  1964. goto destroy;
  1965. }
  1966. mutex_lock(&wk->sdata->u.mgd.mtx);
  1967. ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
  1968. mutex_unlock(&wk->sdata->u.mgd.mtx);
  1969. wk->type = IEEE80211_WORK_AUTH;
  1970. wk->probe_auth.tries = 0;
  1971. return WORK_DONE_REQUEUE;
  1972. destroy:
  1973. if (wk->probe_auth.synced)
  1974. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  1975. IEEE80211_TX_SYNC_AUTH);
  1976. return WORK_DONE_DESTROY;
  1977. }
  1978. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  1979. struct cfg80211_auth_request *req)
  1980. {
  1981. const u8 *ssid;
  1982. struct ieee80211_work *wk;
  1983. u16 auth_alg;
  1984. if (req->local_state_change)
  1985. return 0; /* no need to update mac80211 state */
  1986. switch (req->auth_type) {
  1987. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  1988. auth_alg = WLAN_AUTH_OPEN;
  1989. break;
  1990. case NL80211_AUTHTYPE_SHARED_KEY:
  1991. if (IS_ERR(sdata->local->wep_tx_tfm))
  1992. return -EOPNOTSUPP;
  1993. auth_alg = WLAN_AUTH_SHARED_KEY;
  1994. break;
  1995. case NL80211_AUTHTYPE_FT:
  1996. auth_alg = WLAN_AUTH_FT;
  1997. break;
  1998. case NL80211_AUTHTYPE_NETWORK_EAP:
  1999. auth_alg = WLAN_AUTH_LEAP;
  2000. break;
  2001. default:
  2002. return -EOPNOTSUPP;
  2003. }
  2004. wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
  2005. if (!wk)
  2006. return -ENOMEM;
  2007. memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
  2008. if (req->ie && req->ie_len) {
  2009. memcpy(wk->ie, req->ie, req->ie_len);
  2010. wk->ie_len = req->ie_len;
  2011. }
  2012. if (req->key && req->key_len) {
  2013. wk->probe_auth.key_len = req->key_len;
  2014. wk->probe_auth.key_idx = req->key_idx;
  2015. memcpy(wk->probe_auth.key, req->key, req->key_len);
  2016. }
  2017. ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  2018. memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
  2019. wk->probe_auth.ssid_len = ssid[1];
  2020. wk->probe_auth.algorithm = auth_alg;
  2021. wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
  2022. /* if we already have a probe, don't probe again */
  2023. if (req->bss->proberesp_ies)
  2024. wk->type = IEEE80211_WORK_AUTH;
  2025. else
  2026. wk->type = IEEE80211_WORK_DIRECT_PROBE;
  2027. wk->chan = req->bss->channel;
  2028. wk->chan_type = NL80211_CHAN_NO_HT;
  2029. wk->sdata = sdata;
  2030. wk->done = ieee80211_probe_auth_done;
  2031. ieee80211_add_work(wk);
  2032. return 0;
  2033. }
  2034. /* create and insert a dummy station entry */
  2035. static int ieee80211_pre_assoc(struct ieee80211_sub_if_data *sdata,
  2036. u8 *bssid) {
  2037. struct sta_info *sta;
  2038. int err;
  2039. sta = sta_info_alloc(sdata, bssid, GFP_KERNEL);
  2040. if (!sta)
  2041. return -ENOMEM;
  2042. sta->dummy = true;
  2043. err = sta_info_insert(sta);
  2044. sta = NULL;
  2045. if (err) {
  2046. printk(KERN_DEBUG "%s: failed to insert Dummy STA entry for"
  2047. " the AP (error %d)\n", sdata->name, err);
  2048. return err;
  2049. }
  2050. return 0;
  2051. }
  2052. static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
  2053. struct sk_buff *skb)
  2054. {
  2055. struct ieee80211_local *local = wk->sdata->local;
  2056. struct ieee80211_mgmt *mgmt;
  2057. struct ieee80211_rx_status *rx_status;
  2058. struct ieee802_11_elems elems;
  2059. struct cfg80211_bss *cbss = wk->assoc.bss;
  2060. u16 status;
  2061. if (!skb) {
  2062. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2063. cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
  2064. goto destroy;
  2065. }
  2066. if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
  2067. mutex_lock(&wk->sdata->u.mgd.mtx);
  2068. rx_status = (void *) skb->cb;
  2069. ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
  2070. ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
  2071. &elems, true);
  2072. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2073. wk->type = IEEE80211_WORK_ASSOC;
  2074. /* not really done yet */
  2075. return WORK_DONE_REQUEUE;
  2076. }
  2077. mgmt = (void *)skb->data;
  2078. status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  2079. if (status == WLAN_STATUS_SUCCESS) {
  2080. if (wk->assoc.synced)
  2081. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2082. IEEE80211_TX_SYNC_ASSOC);
  2083. mutex_lock(&wk->sdata->u.mgd.mtx);
  2084. if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
  2085. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2086. /* oops -- internal error -- send timeout for now */
  2087. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2088. cfg80211_send_assoc_timeout(wk->sdata->dev,
  2089. wk->filter_ta);
  2090. return WORK_DONE_DESTROY;
  2091. }
  2092. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2093. } else {
  2094. /* assoc failed - destroy the dummy station entry */
  2095. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2096. }
  2097. cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
  2098. destroy:
  2099. if (wk->assoc.synced)
  2100. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2101. IEEE80211_TX_SYNC_ASSOC);
  2102. return WORK_DONE_DESTROY;
  2103. }
  2104. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  2105. struct cfg80211_assoc_request *req)
  2106. {
  2107. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2108. struct ieee80211_bss *bss = (void *)req->bss->priv;
  2109. struct ieee80211_work *wk;
  2110. const u8 *ssid;
  2111. int i, err;
  2112. mutex_lock(&ifmgd->mtx);
  2113. if (ifmgd->associated) {
  2114. if (!req->prev_bssid ||
  2115. memcmp(req->prev_bssid, ifmgd->associated->bssid,
  2116. ETH_ALEN)) {
  2117. /*
  2118. * We are already associated and the request was not a
  2119. * reassociation request from the current BSS, so
  2120. * reject it.
  2121. */
  2122. mutex_unlock(&ifmgd->mtx);
  2123. return -EALREADY;
  2124. }
  2125. /* Trying to reassociate - clear previous association state */
  2126. ieee80211_set_disassoc(sdata, true, false);
  2127. }
  2128. mutex_unlock(&ifmgd->mtx);
  2129. wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
  2130. if (!wk)
  2131. return -ENOMEM;
  2132. /*
  2133. * create a dummy station info entry in order
  2134. * to start accepting incoming EAPOL packets from the station
  2135. */
  2136. err = ieee80211_pre_assoc(sdata, req->bss->bssid);
  2137. if (err) {
  2138. kfree(wk);
  2139. return err;
  2140. }
  2141. ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
  2142. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  2143. ifmgd->beacon_crc_valid = false;
  2144. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
  2145. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  2146. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  2147. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
  2148. ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
  2149. if (req->ie && req->ie_len) {
  2150. memcpy(wk->ie, req->ie, req->ie_len);
  2151. wk->ie_len = req->ie_len;
  2152. } else
  2153. wk->ie_len = 0;
  2154. wk->assoc.bss = req->bss;
  2155. memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
  2156. /* new association always uses requested smps mode */
  2157. if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
  2158. if (ifmgd->powersave)
  2159. ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
  2160. else
  2161. ifmgd->ap_smps = IEEE80211_SMPS_OFF;
  2162. } else
  2163. ifmgd->ap_smps = ifmgd->req_smps;
  2164. wk->assoc.smps = ifmgd->ap_smps;
  2165. /*
  2166. * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
  2167. * We still associate in non-HT mode (11a/b/g) if any one of these
  2168. * ciphers is configured as pairwise.
  2169. * We can set this to true for non-11n hardware, that'll be checked
  2170. * separately along with the peer capabilities.
  2171. */
  2172. wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
  2173. wk->assoc.capability = req->bss->capability;
  2174. wk->assoc.wmm_used = bss->wmm_used;
  2175. wk->assoc.supp_rates = bss->supp_rates;
  2176. wk->assoc.supp_rates_len = bss->supp_rates_len;
  2177. wk->assoc.ht_information_ie =
  2178. ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
  2179. if (bss->wmm_used && bss->uapsd_supported &&
  2180. (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
  2181. wk->assoc.uapsd_used = true;
  2182. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  2183. } else {
  2184. wk->assoc.uapsd_used = false;
  2185. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  2186. }
  2187. ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  2188. memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
  2189. wk->assoc.ssid_len = ssid[1];
  2190. if (req->prev_bssid)
  2191. memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
  2192. wk->chan = req->bss->channel;
  2193. wk->chan_type = NL80211_CHAN_NO_HT;
  2194. wk->sdata = sdata;
  2195. wk->done = ieee80211_assoc_done;
  2196. if (!bss->dtim_period &&
  2197. sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
  2198. wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
  2199. else
  2200. wk->type = IEEE80211_WORK_ASSOC;
  2201. if (req->use_mfp) {
  2202. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  2203. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  2204. } else {
  2205. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  2206. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  2207. }
  2208. if (req->crypto.control_port)
  2209. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  2210. else
  2211. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  2212. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  2213. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  2214. ieee80211_add_work(wk);
  2215. return 0;
  2216. }
  2217. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  2218. struct cfg80211_deauth_request *req,
  2219. void *cookie)
  2220. {
  2221. struct ieee80211_local *local = sdata->local;
  2222. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2223. struct ieee80211_work *wk;
  2224. u8 bssid[ETH_ALEN];
  2225. bool assoc_bss = false;
  2226. mutex_lock(&ifmgd->mtx);
  2227. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  2228. if (ifmgd->associated == req->bss) {
  2229. ieee80211_set_disassoc(sdata, false, true);
  2230. mutex_unlock(&ifmgd->mtx);
  2231. assoc_bss = true;
  2232. } else {
  2233. bool not_auth_yet = false;
  2234. mutex_unlock(&ifmgd->mtx);
  2235. mutex_lock(&local->mtx);
  2236. list_for_each_entry(wk, &local->work_list, list) {
  2237. if (wk->sdata != sdata)
  2238. continue;
  2239. if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
  2240. wk->type != IEEE80211_WORK_AUTH &&
  2241. wk->type != IEEE80211_WORK_ASSOC &&
  2242. wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
  2243. continue;
  2244. if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
  2245. continue;
  2246. not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
  2247. list_del_rcu(&wk->list);
  2248. free_work(wk);
  2249. break;
  2250. }
  2251. mutex_unlock(&local->mtx);
  2252. /*
  2253. * If somebody requests authentication and we haven't
  2254. * sent out an auth frame yet there's no need to send
  2255. * out a deauth frame either. If the state was PROBE,
  2256. * then this is the case. If it's AUTH we have sent a
  2257. * frame, and if it's IDLE we have completed the auth
  2258. * process already.
  2259. */
  2260. if (not_auth_yet) {
  2261. __cfg80211_auth_canceled(sdata->dev, bssid);
  2262. return 0;
  2263. }
  2264. }
  2265. printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
  2266. sdata->name, bssid, req->reason_code);
  2267. ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
  2268. req->reason_code, cookie,
  2269. !req->local_state_change);
  2270. if (assoc_bss)
  2271. sta_info_destroy_addr(sdata, bssid);
  2272. mutex_lock(&sdata->local->mtx);
  2273. ieee80211_recalc_idle(sdata->local);
  2274. mutex_unlock(&sdata->local->mtx);
  2275. return 0;
  2276. }
  2277. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  2278. struct cfg80211_disassoc_request *req,
  2279. void *cookie)
  2280. {
  2281. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2282. u8 bssid[ETH_ALEN];
  2283. mutex_lock(&ifmgd->mtx);
  2284. /*
  2285. * cfg80211 should catch this ... but it's racy since
  2286. * we can receive a disassoc frame, process it, hand it
  2287. * to cfg80211 while that's in a locked section already
  2288. * trying to tell us that the user wants to disconnect.
  2289. */
  2290. if (ifmgd->associated != req->bss) {
  2291. mutex_unlock(&ifmgd->mtx);
  2292. return -ENOLINK;
  2293. }
  2294. printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
  2295. sdata->name, req->bss->bssid, req->reason_code);
  2296. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  2297. ieee80211_set_disassoc(sdata, false, true);
  2298. mutex_unlock(&ifmgd->mtx);
  2299. ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
  2300. IEEE80211_STYPE_DISASSOC, req->reason_code,
  2301. cookie, !req->local_state_change);
  2302. sta_info_destroy_addr(sdata, bssid);
  2303. mutex_lock(&sdata->local->mtx);
  2304. ieee80211_recalc_idle(sdata->local);
  2305. mutex_unlock(&sdata->local->mtx);
  2306. return 0;
  2307. }
  2308. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  2309. enum nl80211_cqm_rssi_threshold_event rssi_event,
  2310. gfp_t gfp)
  2311. {
  2312. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2313. trace_api_cqm_rssi_notify(sdata, rssi_event);
  2314. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
  2315. }
  2316. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
  2317. unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
  2318. {
  2319. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2320. return sdata->dev->operstate;
  2321. }
  2322. EXPORT_SYMBOL(ieee80211_get_operstate);