mlme.c 77 KB

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