mlme.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846
  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->broken_ap)
  537. return false;
  538. if (!mgd->associated)
  539. return false;
  540. if (!mgd->associated->beacon_ies)
  541. return false;
  542. if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
  543. IEEE80211_STA_CONNECTION_POLL))
  544. return false;
  545. rcu_read_lock();
  546. sta = sta_info_get(sdata, mgd->bssid);
  547. if (sta)
  548. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  549. rcu_read_unlock();
  550. return authorized;
  551. }
  552. /* need to hold RTNL or interface lock */
  553. void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
  554. {
  555. struct ieee80211_sub_if_data *sdata, *found = NULL;
  556. int count = 0;
  557. int timeout;
  558. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
  559. local->ps_sdata = NULL;
  560. return;
  561. }
  562. if (!list_empty(&local->work_list)) {
  563. local->ps_sdata = NULL;
  564. goto change;
  565. }
  566. list_for_each_entry(sdata, &local->interfaces, list) {
  567. if (!ieee80211_sdata_running(sdata))
  568. continue;
  569. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  570. /* If an AP vif is found, then disable PS
  571. * by setting the count to zero thereby setting
  572. * ps_sdata to NULL.
  573. */
  574. count = 0;
  575. break;
  576. }
  577. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  578. continue;
  579. found = sdata;
  580. count++;
  581. }
  582. if (count == 1 && ieee80211_powersave_allowed(found)) {
  583. struct ieee80211_conf *conf = &local->hw.conf;
  584. s32 beaconint_us;
  585. if (latency < 0)
  586. latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
  587. beaconint_us = ieee80211_tu_to_usec(
  588. found->vif.bss_conf.beacon_int);
  589. timeout = local->dynamic_ps_forced_timeout;
  590. if (timeout < 0) {
  591. /*
  592. * Go to full PSM if the user configures a very low
  593. * latency requirement.
  594. * The 2000 second value is there for compatibility
  595. * until the PM_QOS_NETWORK_LATENCY is configured
  596. * with real values.
  597. */
  598. if (latency > (1900 * USEC_PER_MSEC) &&
  599. latency != (2000 * USEC_PER_SEC))
  600. timeout = 0;
  601. else
  602. timeout = 100;
  603. }
  604. local->dynamic_ps_user_timeout = timeout;
  605. if (!local->disable_dynamic_ps)
  606. conf->dynamic_ps_timeout =
  607. local->dynamic_ps_user_timeout;
  608. if (beaconint_us > latency) {
  609. local->ps_sdata = NULL;
  610. } else {
  611. struct ieee80211_bss *bss;
  612. int maxslp = 1;
  613. u8 dtimper;
  614. bss = (void *)found->u.mgd.associated->priv;
  615. dtimper = bss->dtim_period;
  616. /* If the TIM IE is invalid, pretend the value is 1 */
  617. if (!dtimper)
  618. dtimper = 1;
  619. else if (dtimper > 1)
  620. maxslp = min_t(int, dtimper,
  621. latency / beaconint_us);
  622. local->hw.conf.max_sleep_period = maxslp;
  623. local->hw.conf.ps_dtim_period = dtimper;
  624. local->ps_sdata = found;
  625. }
  626. } else {
  627. local->ps_sdata = NULL;
  628. }
  629. change:
  630. ieee80211_change_ps(local);
  631. }
  632. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  633. {
  634. struct ieee80211_local *local =
  635. container_of(work, struct ieee80211_local,
  636. dynamic_ps_disable_work);
  637. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  638. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  639. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  640. }
  641. ieee80211_wake_queues_by_reason(&local->hw,
  642. IEEE80211_QUEUE_STOP_REASON_PS);
  643. }
  644. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  645. {
  646. struct ieee80211_local *local =
  647. container_of(work, struct ieee80211_local,
  648. dynamic_ps_enable_work);
  649. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  650. struct ieee80211_if_managed *ifmgd;
  651. unsigned long flags;
  652. int q;
  653. /* can only happen when PS was just disabled anyway */
  654. if (!sdata)
  655. return;
  656. ifmgd = &sdata->u.mgd;
  657. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  658. return;
  659. if (!local->disable_dynamic_ps &&
  660. local->hw.conf.dynamic_ps_timeout > 0) {
  661. /* don't enter PS if TX frames are pending */
  662. if (drv_tx_frames_pending(local)) {
  663. mod_timer(&local->dynamic_ps_timer, jiffies +
  664. msecs_to_jiffies(
  665. local->hw.conf.dynamic_ps_timeout));
  666. return;
  667. }
  668. /*
  669. * transmission can be stopped by others which leads to
  670. * dynamic_ps_timer expiry. Postpone the ps timer if it
  671. * is not the actual idle state.
  672. */
  673. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  674. for (q = 0; q < local->hw.queues; q++) {
  675. if (local->queue_stop_reasons[q]) {
  676. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  677. flags);
  678. mod_timer(&local->dynamic_ps_timer, jiffies +
  679. msecs_to_jiffies(
  680. local->hw.conf.dynamic_ps_timeout));
  681. return;
  682. }
  683. }
  684. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  685. }
  686. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  687. (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) {
  688. netif_tx_stop_all_queues(sdata->dev);
  689. if (drv_tx_frames_pending(local))
  690. mod_timer(&local->dynamic_ps_timer, jiffies +
  691. msecs_to_jiffies(
  692. local->hw.conf.dynamic_ps_timeout));
  693. else {
  694. ieee80211_send_nullfunc(local, sdata, 1);
  695. /* Flush to get the tx status of nullfunc frame */
  696. drv_flush(local, false);
  697. }
  698. }
  699. if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
  700. (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
  701. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  702. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  703. local->hw.conf.flags |= IEEE80211_CONF_PS;
  704. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  705. }
  706. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  707. netif_tx_wake_all_queues(sdata->dev);
  708. }
  709. void ieee80211_dynamic_ps_timer(unsigned long data)
  710. {
  711. struct ieee80211_local *local = (void *) data;
  712. if (local->quiescing || local->suspended)
  713. return;
  714. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  715. }
  716. /* MLME */
  717. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  718. struct ieee80211_sub_if_data *sdata,
  719. u8 *wmm_param, size_t wmm_param_len)
  720. {
  721. struct ieee80211_tx_queue_params params;
  722. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  723. size_t left;
  724. int count;
  725. u8 *pos, uapsd_queues = 0;
  726. if (!local->ops->conf_tx)
  727. return;
  728. if (local->hw.queues < 4)
  729. return;
  730. if (!wmm_param)
  731. return;
  732. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  733. return;
  734. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  735. uapsd_queues = local->uapsd_queues;
  736. count = wmm_param[6] & 0x0f;
  737. if (count == ifmgd->wmm_last_param_set)
  738. return;
  739. ifmgd->wmm_last_param_set = count;
  740. pos = wmm_param + 8;
  741. left = wmm_param_len - 8;
  742. memset(&params, 0, sizeof(params));
  743. local->wmm_acm = 0;
  744. for (; left >= 4; left -= 4, pos += 4) {
  745. int aci = (pos[0] >> 5) & 0x03;
  746. int acm = (pos[0] >> 4) & 0x01;
  747. bool uapsd = false;
  748. int queue;
  749. switch (aci) {
  750. case 1: /* AC_BK */
  751. queue = 3;
  752. if (acm)
  753. local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  754. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  755. uapsd = true;
  756. break;
  757. case 2: /* AC_VI */
  758. queue = 1;
  759. if (acm)
  760. local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  761. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  762. uapsd = true;
  763. break;
  764. case 3: /* AC_VO */
  765. queue = 0;
  766. if (acm)
  767. local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  768. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  769. uapsd = true;
  770. break;
  771. case 0: /* AC_BE */
  772. default:
  773. queue = 2;
  774. if (acm)
  775. local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  776. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  777. uapsd = true;
  778. break;
  779. }
  780. params.aifs = pos[0] & 0x0f;
  781. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  782. params.cw_min = ecw2cw(pos[1] & 0x0f);
  783. params.txop = get_unaligned_le16(pos + 2);
  784. params.uapsd = uapsd;
  785. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  786. wiphy_debug(local->hw.wiphy,
  787. "WMM queue=%d aci=%d acm=%d aifs=%d "
  788. "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
  789. queue, aci, acm,
  790. params.aifs, params.cw_min, params.cw_max,
  791. params.txop, params.uapsd);
  792. #endif
  793. sdata->tx_conf[queue] = params;
  794. if (drv_conf_tx(local, sdata, queue, &params))
  795. wiphy_debug(local->hw.wiphy,
  796. "failed to set TX queue parameters for queue %d\n",
  797. queue);
  798. }
  799. /* enable WMM or activate new settings */
  800. sdata->vif.bss_conf.qos = true;
  801. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  802. }
  803. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  804. u16 capab, bool erp_valid, u8 erp)
  805. {
  806. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  807. u32 changed = 0;
  808. bool use_protection;
  809. bool use_short_preamble;
  810. bool use_short_slot;
  811. if (erp_valid) {
  812. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  813. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  814. } else {
  815. use_protection = false;
  816. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  817. }
  818. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  819. if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
  820. use_short_slot = true;
  821. if (use_protection != bss_conf->use_cts_prot) {
  822. bss_conf->use_cts_prot = use_protection;
  823. changed |= BSS_CHANGED_ERP_CTS_PROT;
  824. }
  825. if (use_short_preamble != bss_conf->use_short_preamble) {
  826. bss_conf->use_short_preamble = use_short_preamble;
  827. changed |= BSS_CHANGED_ERP_PREAMBLE;
  828. }
  829. if (use_short_slot != bss_conf->use_short_slot) {
  830. bss_conf->use_short_slot = use_short_slot;
  831. changed |= BSS_CHANGED_ERP_SLOT;
  832. }
  833. return changed;
  834. }
  835. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  836. struct cfg80211_bss *cbss,
  837. u32 bss_info_changed)
  838. {
  839. struct ieee80211_bss *bss = (void *)cbss->priv;
  840. struct ieee80211_local *local = sdata->local;
  841. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  842. bss_info_changed |= BSS_CHANGED_ASSOC;
  843. /* set timing information */
  844. bss_conf->beacon_int = cbss->beacon_interval;
  845. bss_conf->timestamp = cbss->tsf;
  846. bss_info_changed |= BSS_CHANGED_BEACON_INT;
  847. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  848. cbss->capability, bss->has_erp_value, bss->erp_value);
  849. sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
  850. IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
  851. sdata->u.mgd.associated = cbss;
  852. memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  853. sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
  854. /* just to be sure */
  855. sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  856. IEEE80211_STA_BEACON_POLL);
  857. ieee80211_led_assoc(local, 1);
  858. if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
  859. bss_conf->dtim_period = bss->dtim_period;
  860. else
  861. bss_conf->dtim_period = 0;
  862. bss_conf->assoc = 1;
  863. /*
  864. * For now just always ask the driver to update the basic rateset
  865. * when we have associated, we aren't checking whether it actually
  866. * changed or not.
  867. */
  868. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  869. /* And the BSSID changed - we're associated now */
  870. bss_info_changed |= BSS_CHANGED_BSSID;
  871. /* Tell the driver to monitor connection quality (if supported) */
  872. if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
  873. bss_conf->cqm_rssi_thold)
  874. bss_info_changed |= BSS_CHANGED_CQM;
  875. /* Enable ARP filtering */
  876. if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
  877. bss_conf->arp_filter_enabled = sdata->arp_filter_state;
  878. bss_info_changed |= BSS_CHANGED_ARP_FILTER;
  879. }
  880. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  881. mutex_lock(&local->iflist_mtx);
  882. ieee80211_recalc_ps(local, -1);
  883. ieee80211_recalc_smps(local);
  884. mutex_unlock(&local->iflist_mtx);
  885. netif_tx_start_all_queues(sdata->dev);
  886. netif_carrier_on(sdata->dev);
  887. }
  888. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  889. bool remove_sta, bool tx)
  890. {
  891. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  892. struct ieee80211_local *local = sdata->local;
  893. struct sta_info *sta;
  894. u32 changed = 0, config_changed = 0;
  895. u8 bssid[ETH_ALEN];
  896. ASSERT_MGD_MTX(ifmgd);
  897. if (WARN_ON(!ifmgd->associated))
  898. return;
  899. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  900. ifmgd->associated = NULL;
  901. memset(ifmgd->bssid, 0, ETH_ALEN);
  902. /*
  903. * we need to commit the associated = NULL change because the
  904. * scan code uses that to determine whether this iface should
  905. * go to/wake up from powersave or not -- and could otherwise
  906. * wake the queues erroneously.
  907. */
  908. smp_mb();
  909. /*
  910. * Thus, we can only afterwards stop the queues -- to account
  911. * for the case where another CPU is finishing a scan at this
  912. * time -- we don't want the scan code to enable queues.
  913. */
  914. netif_tx_stop_all_queues(sdata->dev);
  915. netif_carrier_off(sdata->dev);
  916. mutex_lock(&local->sta_mtx);
  917. sta = sta_info_get(sdata, bssid);
  918. if (sta) {
  919. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  920. ieee80211_sta_tear_down_BA_sessions(sta, tx);
  921. }
  922. mutex_unlock(&local->sta_mtx);
  923. changed |= ieee80211_reset_erp_info(sdata);
  924. ieee80211_led_assoc(local, 0);
  925. changed |= BSS_CHANGED_ASSOC;
  926. sdata->vif.bss_conf.assoc = false;
  927. ieee80211_set_wmm_default(sdata);
  928. /* channel(_type) changes are handled by ieee80211_hw_config */
  929. WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
  930. /* on the next assoc, re-program HT parameters */
  931. sdata->ht_opmode_valid = false;
  932. local->power_constr_level = 0;
  933. del_timer_sync(&local->dynamic_ps_timer);
  934. cancel_work_sync(&local->dynamic_ps_enable_work);
  935. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  936. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  937. config_changed |= IEEE80211_CONF_CHANGE_PS;
  938. }
  939. local->ps_sdata = NULL;
  940. ieee80211_hw_config(local, config_changed);
  941. /* Disable ARP filtering */
  942. if (sdata->vif.bss_conf.arp_filter_enabled) {
  943. sdata->vif.bss_conf.arp_filter_enabled = false;
  944. changed |= BSS_CHANGED_ARP_FILTER;
  945. }
  946. /* The BSSID (not really interesting) and HT changed */
  947. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  948. ieee80211_bss_info_change_notify(sdata, changed);
  949. /* remove AP and TDLS peers */
  950. if (remove_sta)
  951. sta_info_flush(local, sdata);
  952. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  953. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  954. del_timer_sync(&sdata->u.mgd.timer);
  955. del_timer_sync(&sdata->u.mgd.chswitch_timer);
  956. }
  957. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  958. struct ieee80211_hdr *hdr)
  959. {
  960. /*
  961. * We can postpone the mgd.timer whenever receiving unicast frames
  962. * from AP because we know that the connection is working both ways
  963. * at that time. But multicast frames (and hence also beacons) must
  964. * be ignored here, because we need to trigger the timer during
  965. * data idle periods for sending the periodic probe request to the
  966. * AP we're connected to.
  967. */
  968. if (is_multicast_ether_addr(hdr->addr1))
  969. return;
  970. ieee80211_sta_reset_conn_monitor(sdata);
  971. }
  972. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  973. {
  974. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  975. if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  976. IEEE80211_STA_CONNECTION_POLL)))
  977. return;
  978. ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  979. IEEE80211_STA_BEACON_POLL);
  980. mutex_lock(&sdata->local->iflist_mtx);
  981. ieee80211_recalc_ps(sdata->local, -1);
  982. mutex_unlock(&sdata->local->iflist_mtx);
  983. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  984. return;
  985. /*
  986. * We've received a probe response, but are not sure whether
  987. * we have or will be receiving any beacons or data, so let's
  988. * schedule the timers again, just in case.
  989. */
  990. ieee80211_sta_reset_beacon_monitor(sdata);
  991. mod_timer(&ifmgd->conn_mon_timer,
  992. round_jiffies_up(jiffies +
  993. IEEE80211_CONNECTION_IDLE_TIME));
  994. }
  995. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  996. struct ieee80211_hdr *hdr, bool ack)
  997. {
  998. if (!ieee80211_is_data(hdr->frame_control))
  999. return;
  1000. if (ack)
  1001. ieee80211_sta_reset_conn_monitor(sdata);
  1002. if (ieee80211_is_nullfunc(hdr->frame_control) &&
  1003. sdata->u.mgd.probe_send_count > 0) {
  1004. if (ack)
  1005. sdata->u.mgd.probe_send_count = 0;
  1006. else
  1007. sdata->u.mgd.nullfunc_failed = true;
  1008. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1009. }
  1010. }
  1011. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  1012. {
  1013. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1014. const u8 *ssid;
  1015. u8 *dst = ifmgd->associated->bssid;
  1016. u8 unicast_limit = max(1, max_probe_tries - 3);
  1017. /*
  1018. * Try sending broadcast probe requests for the last three
  1019. * probe requests after the first ones failed since some
  1020. * buggy APs only support broadcast probe requests.
  1021. */
  1022. if (ifmgd->probe_send_count >= unicast_limit)
  1023. dst = NULL;
  1024. /*
  1025. * When the hardware reports an accurate Tx ACK status, it's
  1026. * better to send a nullfunc frame instead of a probe request,
  1027. * as it will kick us off the AP quickly if we aren't associated
  1028. * anymore. The timeout will be reset if the frame is ACKed by
  1029. * the AP.
  1030. */
  1031. if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1032. ifmgd->nullfunc_failed = false;
  1033. ieee80211_send_nullfunc(sdata->local, sdata, 0);
  1034. } else {
  1035. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1036. ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0,
  1037. (u32) -1, true, false);
  1038. }
  1039. ifmgd->probe_send_count++;
  1040. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  1041. run_again(ifmgd, ifmgd->probe_timeout);
  1042. }
  1043. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  1044. bool beacon)
  1045. {
  1046. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1047. bool already = false;
  1048. if (!ieee80211_sdata_running(sdata))
  1049. return;
  1050. if (sdata->local->scanning)
  1051. return;
  1052. if (sdata->local->tmp_channel)
  1053. return;
  1054. mutex_lock(&ifmgd->mtx);
  1055. if (!ifmgd->associated)
  1056. goto out;
  1057. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1058. if (beacon && net_ratelimit())
  1059. printk(KERN_DEBUG "%s: detected beacon loss from AP "
  1060. "- sending probe request\n", sdata->name);
  1061. #endif
  1062. /*
  1063. * The driver/our work has already reported this event or the
  1064. * connection monitoring has kicked in and we have already sent
  1065. * a probe request. Or maybe the AP died and the driver keeps
  1066. * reporting until we disassociate...
  1067. *
  1068. * In either case we have to ignore the current call to this
  1069. * function (except for setting the correct probe reason bit)
  1070. * because otherwise we would reset the timer every time and
  1071. * never check whether we received a probe response!
  1072. */
  1073. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1074. IEEE80211_STA_CONNECTION_POLL))
  1075. already = true;
  1076. if (beacon)
  1077. ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
  1078. else
  1079. ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
  1080. if (already)
  1081. goto out;
  1082. mutex_lock(&sdata->local->iflist_mtx);
  1083. ieee80211_recalc_ps(sdata->local, -1);
  1084. mutex_unlock(&sdata->local->iflist_mtx);
  1085. ifmgd->probe_send_count = 0;
  1086. ieee80211_mgd_probe_ap_send(sdata);
  1087. out:
  1088. mutex_unlock(&ifmgd->mtx);
  1089. }
  1090. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  1091. struct ieee80211_vif *vif)
  1092. {
  1093. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1094. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1095. struct sk_buff *skb;
  1096. const u8 *ssid;
  1097. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1098. return NULL;
  1099. ASSERT_MGD_MTX(ifmgd);
  1100. if (!ifmgd->associated)
  1101. return NULL;
  1102. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  1103. skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
  1104. (u32) -1, ssid + 2, ssid[1],
  1105. NULL, 0, true);
  1106. return skb;
  1107. }
  1108. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  1109. static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
  1110. {
  1111. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1112. struct ieee80211_local *local = sdata->local;
  1113. u8 bssid[ETH_ALEN];
  1114. mutex_lock(&ifmgd->mtx);
  1115. if (!ifmgd->associated) {
  1116. mutex_unlock(&ifmgd->mtx);
  1117. return;
  1118. }
  1119. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  1120. printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n",
  1121. sdata->name, bssid);
  1122. ieee80211_set_disassoc(sdata, true, true);
  1123. mutex_unlock(&ifmgd->mtx);
  1124. mutex_lock(&local->mtx);
  1125. ieee80211_recalc_idle(local);
  1126. mutex_unlock(&local->mtx);
  1127. /*
  1128. * must be outside lock due to cfg80211,
  1129. * but that's not a problem.
  1130. */
  1131. ieee80211_send_deauth_disassoc(sdata, bssid,
  1132. IEEE80211_STYPE_DEAUTH,
  1133. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  1134. NULL, true);
  1135. }
  1136. void ieee80211_beacon_connection_loss_work(struct work_struct *work)
  1137. {
  1138. struct ieee80211_sub_if_data *sdata =
  1139. container_of(work, struct ieee80211_sub_if_data,
  1140. u.mgd.beacon_connection_loss_work);
  1141. if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
  1142. __ieee80211_connection_loss(sdata);
  1143. else
  1144. ieee80211_mgd_probe_ap(sdata, true);
  1145. }
  1146. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  1147. {
  1148. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1149. struct ieee80211_hw *hw = &sdata->local->hw;
  1150. trace_api_beacon_loss(sdata);
  1151. WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
  1152. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1153. }
  1154. EXPORT_SYMBOL(ieee80211_beacon_loss);
  1155. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  1156. {
  1157. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1158. struct ieee80211_hw *hw = &sdata->local->hw;
  1159. trace_api_connection_loss(sdata);
  1160. WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
  1161. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  1162. }
  1163. EXPORT_SYMBOL(ieee80211_connection_loss);
  1164. static enum rx_mgmt_action __must_check
  1165. ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1166. struct ieee80211_mgmt *mgmt, size_t len)
  1167. {
  1168. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1169. const u8 *bssid = NULL;
  1170. u16 reason_code;
  1171. if (len < 24 + 2)
  1172. return RX_MGMT_NONE;
  1173. ASSERT_MGD_MTX(ifmgd);
  1174. bssid = ifmgd->associated->bssid;
  1175. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1176. printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
  1177. sdata->name, bssid, reason_code);
  1178. ieee80211_set_disassoc(sdata, true, false);
  1179. mutex_lock(&sdata->local->mtx);
  1180. ieee80211_recalc_idle(sdata->local);
  1181. mutex_unlock(&sdata->local->mtx);
  1182. return RX_MGMT_CFG80211_DEAUTH;
  1183. }
  1184. static enum rx_mgmt_action __must_check
  1185. ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1186. struct ieee80211_mgmt *mgmt, size_t len)
  1187. {
  1188. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1189. u16 reason_code;
  1190. if (len < 24 + 2)
  1191. return RX_MGMT_NONE;
  1192. ASSERT_MGD_MTX(ifmgd);
  1193. if (WARN_ON(!ifmgd->associated))
  1194. return RX_MGMT_NONE;
  1195. if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
  1196. return RX_MGMT_NONE;
  1197. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1198. printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
  1199. sdata->name, mgmt->sa, reason_code);
  1200. ieee80211_set_disassoc(sdata, true, false);
  1201. mutex_lock(&sdata->local->mtx);
  1202. ieee80211_recalc_idle(sdata->local);
  1203. mutex_unlock(&sdata->local->mtx);
  1204. return RX_MGMT_CFG80211_DISASSOC;
  1205. }
  1206. static bool ieee80211_assoc_success(struct ieee80211_work *wk,
  1207. struct ieee80211_mgmt *mgmt, size_t len)
  1208. {
  1209. struct ieee80211_sub_if_data *sdata = wk->sdata;
  1210. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1211. struct ieee80211_local *local = sdata->local;
  1212. struct ieee80211_supported_band *sband;
  1213. struct sta_info *sta;
  1214. struct cfg80211_bss *cbss = wk->assoc.bss;
  1215. u8 *pos;
  1216. u32 rates, basic_rates;
  1217. u16 capab_info, aid;
  1218. struct ieee802_11_elems elems;
  1219. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1220. u32 changed = 0;
  1221. int i, j, err;
  1222. bool have_higher_than_11mbit = false;
  1223. u16 ap_ht_cap_flags;
  1224. int min_rate = INT_MAX, min_rate_index = -1;
  1225. /* AssocResp and ReassocResp have identical structure */
  1226. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1227. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1228. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1229. printk(KERN_DEBUG
  1230. "%s: invalid AID value 0x%x; bits 15:14 not set\n",
  1231. sdata->name, aid);
  1232. aid &= ~(BIT(15) | BIT(14));
  1233. ifmgd->broken_ap = false;
  1234. if (aid == 0 || aid > IEEE80211_MAX_AID) {
  1235. printk(KERN_DEBUG
  1236. "%s: invalid AID value %d (out of range), turn off PS\n",
  1237. sdata->name, aid);
  1238. aid = 0;
  1239. ifmgd->broken_ap = true;
  1240. }
  1241. pos = mgmt->u.assoc_resp.variable;
  1242. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1243. if (!elems.supp_rates) {
  1244. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1245. sdata->name);
  1246. return false;
  1247. }
  1248. ifmgd->aid = aid;
  1249. mutex_lock(&sdata->local->sta_mtx);
  1250. /*
  1251. * station info was already allocated and inserted before
  1252. * the association and should be available to us
  1253. */
  1254. sta = sta_info_get_rx(sdata, cbss->bssid);
  1255. if (WARN_ON(!sta)) {
  1256. mutex_unlock(&sdata->local->sta_mtx);
  1257. return false;
  1258. }
  1259. set_sta_flag(sta, WLAN_STA_AUTH);
  1260. set_sta_flag(sta, WLAN_STA_ASSOC);
  1261. set_sta_flag(sta, WLAN_STA_ASSOC_AP);
  1262. if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  1263. set_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1264. rates = 0;
  1265. basic_rates = 0;
  1266. sband = local->hw.wiphy->bands[wk->chan->band];
  1267. for (i = 0; i < elems.supp_rates_len; i++) {
  1268. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1269. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1270. if (rate > 110)
  1271. have_higher_than_11mbit = true;
  1272. for (j = 0; j < sband->n_bitrates; j++) {
  1273. if (sband->bitrates[j].bitrate == rate) {
  1274. rates |= BIT(j);
  1275. if (is_basic)
  1276. basic_rates |= BIT(j);
  1277. if (rate < min_rate) {
  1278. min_rate = rate;
  1279. min_rate_index = j;
  1280. }
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1286. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1287. bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
  1288. if (rate > 110)
  1289. have_higher_than_11mbit = true;
  1290. for (j = 0; j < sband->n_bitrates; j++) {
  1291. if (sband->bitrates[j].bitrate == rate) {
  1292. rates |= BIT(j);
  1293. if (is_basic)
  1294. basic_rates |= BIT(j);
  1295. if (rate < min_rate) {
  1296. min_rate = rate;
  1297. min_rate_index = j;
  1298. }
  1299. break;
  1300. }
  1301. }
  1302. }
  1303. /*
  1304. * some buggy APs don't advertise basic_rates. use the lowest
  1305. * supported rate instead.
  1306. */
  1307. if (unlikely(!basic_rates) && min_rate_index >= 0) {
  1308. printk(KERN_DEBUG "%s: No basic rates in AssocResp. "
  1309. "Using min supported rate instead.\n", sdata->name);
  1310. basic_rates = BIT(min_rate_index);
  1311. }
  1312. sta->sta.supp_rates[wk->chan->band] = rates;
  1313. sdata->vif.bss_conf.basic_rates = basic_rates;
  1314. /* cf. IEEE 802.11 9.2.12 */
  1315. if (wk->chan->band == IEEE80211_BAND_2GHZ &&
  1316. have_higher_than_11mbit)
  1317. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1318. else
  1319. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1320. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1321. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1322. elems.ht_cap_elem, &sta->sta.ht_cap);
  1323. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1324. rate_control_rate_init(sta);
  1325. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  1326. set_sta_flag(sta, WLAN_STA_MFP);
  1327. if (elems.wmm_param)
  1328. set_sta_flag(sta, WLAN_STA_WME);
  1329. /* sta_info_reinsert will also unlock the mutex lock */
  1330. err = sta_info_reinsert(sta);
  1331. sta = NULL;
  1332. if (err) {
  1333. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1334. " the AP (error %d)\n", sdata->name, err);
  1335. return false;
  1336. }
  1337. /*
  1338. * Always handle WMM once after association regardless
  1339. * of the first value the AP uses. Setting -1 here has
  1340. * that effect because the AP values is an unsigned
  1341. * 4-bit value.
  1342. */
  1343. ifmgd->wmm_last_param_set = -1;
  1344. if (elems.wmm_param)
  1345. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  1346. elems.wmm_param_len);
  1347. else
  1348. ieee80211_set_wmm_default(sdata);
  1349. local->oper_channel = wk->chan;
  1350. if (elems.ht_info_elem && elems.wmm_param &&
  1351. (sdata->local->hw.queues >= 4) &&
  1352. !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1353. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1354. cbss->bssid, ap_ht_cap_flags,
  1355. false);
  1356. /* set AID and assoc capability,
  1357. * ieee80211_set_associated() will tell the driver */
  1358. bss_conf->aid = aid;
  1359. bss_conf->assoc_capability = capab_info;
  1360. ieee80211_set_associated(sdata, cbss, changed);
  1361. /*
  1362. * If we're using 4-addr mode, let the AP know that we're
  1363. * doing so, so that it can create the STA VLAN on its side
  1364. */
  1365. if (ifmgd->use_4addr)
  1366. ieee80211_send_4addr_nullfunc(local, sdata);
  1367. /*
  1368. * Start timer to probe the connection to the AP now.
  1369. * Also start the timer that will detect beacon loss.
  1370. */
  1371. ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
  1372. ieee80211_sta_reset_beacon_monitor(sdata);
  1373. return true;
  1374. }
  1375. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1376. struct ieee80211_mgmt *mgmt,
  1377. size_t len,
  1378. struct ieee80211_rx_status *rx_status,
  1379. struct ieee802_11_elems *elems,
  1380. bool beacon)
  1381. {
  1382. struct ieee80211_local *local = sdata->local;
  1383. int freq;
  1384. struct ieee80211_bss *bss;
  1385. struct ieee80211_channel *channel;
  1386. bool need_ps = false;
  1387. if (sdata->u.mgd.associated) {
  1388. bss = (void *)sdata->u.mgd.associated->priv;
  1389. /* not previously set so we may need to recalc */
  1390. need_ps = !bss->dtim_period;
  1391. }
  1392. if (elems->ds_params && elems->ds_params_len == 1)
  1393. freq = ieee80211_channel_to_frequency(elems->ds_params[0],
  1394. rx_status->band);
  1395. else
  1396. freq = rx_status->freq;
  1397. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1398. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1399. return;
  1400. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1401. channel, beacon);
  1402. if (bss)
  1403. ieee80211_rx_bss_put(local, bss);
  1404. if (!sdata->u.mgd.associated)
  1405. return;
  1406. if (need_ps) {
  1407. mutex_lock(&local->iflist_mtx);
  1408. ieee80211_recalc_ps(local, -1);
  1409. mutex_unlock(&local->iflist_mtx);
  1410. }
  1411. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1412. (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
  1413. ETH_ALEN) == 0)) {
  1414. struct ieee80211_channel_sw_ie *sw_elem =
  1415. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1416. ieee80211_sta_process_chanswitch(sdata, sw_elem,
  1417. bss, rx_status->mactime);
  1418. }
  1419. }
  1420. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1421. struct sk_buff *skb)
  1422. {
  1423. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1424. struct ieee80211_if_managed *ifmgd;
  1425. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  1426. size_t baselen, len = skb->len;
  1427. struct ieee802_11_elems elems;
  1428. ifmgd = &sdata->u.mgd;
  1429. ASSERT_MGD_MTX(ifmgd);
  1430. if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
  1431. return; /* ignore ProbeResp to foreign address */
  1432. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1433. if (baselen > len)
  1434. return;
  1435. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1436. &elems);
  1437. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1438. if (ifmgd->associated &&
  1439. memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
  1440. ieee80211_reset_ap_probe(sdata);
  1441. }
  1442. /*
  1443. * This is the canonical list of information elements we care about,
  1444. * the filter code also gives us all changes to the Microsoft OUI
  1445. * (00:50:F2) vendor IE which is used for WMM which we need to track.
  1446. *
  1447. * We implement beacon filtering in software since that means we can
  1448. * avoid processing the frame here and in cfg80211, and userspace
  1449. * will not be able to tell whether the hardware supports it or not.
  1450. *
  1451. * XXX: This list needs to be dynamic -- userspace needs to be able to
  1452. * add items it requires. It also needs to be able to tell us to
  1453. * look out for other vendor IEs.
  1454. */
  1455. static const u64 care_about_ies =
  1456. (1ULL << WLAN_EID_COUNTRY) |
  1457. (1ULL << WLAN_EID_ERP_INFO) |
  1458. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  1459. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  1460. (1ULL << WLAN_EID_HT_CAPABILITY) |
  1461. (1ULL << WLAN_EID_HT_INFORMATION);
  1462. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1463. struct ieee80211_mgmt *mgmt,
  1464. size_t len,
  1465. struct ieee80211_rx_status *rx_status)
  1466. {
  1467. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1468. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1469. size_t baselen;
  1470. struct ieee802_11_elems elems;
  1471. struct ieee80211_local *local = sdata->local;
  1472. u32 changed = 0;
  1473. bool erp_valid, directed_tim = false;
  1474. u8 erp_value = 0;
  1475. u32 ncrc;
  1476. u8 *bssid;
  1477. ASSERT_MGD_MTX(ifmgd);
  1478. /* Process beacon from the current BSS */
  1479. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1480. if (baselen > len)
  1481. return;
  1482. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1483. return;
  1484. /*
  1485. * We might have received a number of frames, among them a
  1486. * disassoc frame and a beacon...
  1487. */
  1488. if (!ifmgd->associated)
  1489. return;
  1490. bssid = ifmgd->associated->bssid;
  1491. /*
  1492. * And in theory even frames from a different AP we were just
  1493. * associated to a split-second ago!
  1494. */
  1495. if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
  1496. return;
  1497. /* Track average RSSI from the Beacon frames of the current AP */
  1498. ifmgd->last_beacon_signal = rx_status->signal;
  1499. if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
  1500. ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
  1501. ifmgd->ave_beacon_signal = rx_status->signal * 16;
  1502. ifmgd->last_cqm_event_signal = 0;
  1503. ifmgd->count_beacon_signal = 1;
  1504. ifmgd->last_ave_beacon_signal = 0;
  1505. } else {
  1506. ifmgd->ave_beacon_signal =
  1507. (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
  1508. (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
  1509. ifmgd->ave_beacon_signal) / 16;
  1510. ifmgd->count_beacon_signal++;
  1511. }
  1512. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  1513. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  1514. int sig = ifmgd->ave_beacon_signal;
  1515. int last_sig = ifmgd->last_ave_beacon_signal;
  1516. /*
  1517. * if signal crosses either of the boundaries, invoke callback
  1518. * with appropriate parameters
  1519. */
  1520. if (sig > ifmgd->rssi_max_thold &&
  1521. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  1522. ifmgd->last_ave_beacon_signal = sig;
  1523. drv_rssi_callback(local, RSSI_EVENT_HIGH);
  1524. } else if (sig < ifmgd->rssi_min_thold &&
  1525. (last_sig >= ifmgd->rssi_max_thold ||
  1526. last_sig == 0)) {
  1527. ifmgd->last_ave_beacon_signal = sig;
  1528. drv_rssi_callback(local, RSSI_EVENT_LOW);
  1529. }
  1530. }
  1531. if (bss_conf->cqm_rssi_thold &&
  1532. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  1533. !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1534. int sig = ifmgd->ave_beacon_signal / 16;
  1535. int last_event = ifmgd->last_cqm_event_signal;
  1536. int thold = bss_conf->cqm_rssi_thold;
  1537. int hyst = bss_conf->cqm_rssi_hyst;
  1538. if (sig < thold &&
  1539. (last_event == 0 || sig < last_event - hyst)) {
  1540. ifmgd->last_cqm_event_signal = sig;
  1541. ieee80211_cqm_rssi_notify(
  1542. &sdata->vif,
  1543. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  1544. GFP_KERNEL);
  1545. } else if (sig > thold &&
  1546. (last_event == 0 || sig > last_event + hyst)) {
  1547. ifmgd->last_cqm_event_signal = sig;
  1548. ieee80211_cqm_rssi_notify(
  1549. &sdata->vif,
  1550. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  1551. GFP_KERNEL);
  1552. }
  1553. }
  1554. if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
  1555. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1556. if (net_ratelimit()) {
  1557. printk(KERN_DEBUG "%s: cancelling probereq poll due "
  1558. "to a received beacon\n", sdata->name);
  1559. }
  1560. #endif
  1561. ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
  1562. mutex_lock(&local->iflist_mtx);
  1563. ieee80211_recalc_ps(local, -1);
  1564. mutex_unlock(&local->iflist_mtx);
  1565. }
  1566. /*
  1567. * Push the beacon loss detection into the future since
  1568. * we are processing a beacon from the AP just now.
  1569. */
  1570. ieee80211_sta_reset_beacon_monitor(sdata);
  1571. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  1572. ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
  1573. len - baselen, &elems,
  1574. care_about_ies, ncrc);
  1575. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  1576. directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
  1577. ifmgd->aid);
  1578. if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
  1579. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
  1580. true);
  1581. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  1582. elems.wmm_param_len);
  1583. }
  1584. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  1585. if (directed_tim) {
  1586. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1587. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1588. ieee80211_hw_config(local,
  1589. IEEE80211_CONF_CHANGE_PS);
  1590. ieee80211_send_nullfunc(local, sdata, 0);
  1591. } else {
  1592. local->pspolling = true;
  1593. /*
  1594. * Here is assumed that the driver will be
  1595. * able to send ps-poll frame and receive a
  1596. * response even though power save mode is
  1597. * enabled, but some drivers might require
  1598. * to disable power save here. This needs
  1599. * to be investigated.
  1600. */
  1601. ieee80211_send_pspoll(local, sdata);
  1602. }
  1603. }
  1604. }
  1605. if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
  1606. return;
  1607. ifmgd->beacon_crc = ncrc;
  1608. ifmgd->beacon_crc_valid = true;
  1609. if (elems.erp_info && elems.erp_info_len >= 1) {
  1610. erp_valid = true;
  1611. erp_value = elems.erp_info[0];
  1612. } else {
  1613. erp_valid = false;
  1614. }
  1615. changed |= ieee80211_handle_bss_capability(sdata,
  1616. le16_to_cpu(mgmt->u.beacon.capab_info),
  1617. erp_valid, erp_value);
  1618. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
  1619. !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
  1620. struct sta_info *sta;
  1621. struct ieee80211_supported_band *sband;
  1622. u16 ap_ht_cap_flags;
  1623. rcu_read_lock();
  1624. sta = sta_info_get(sdata, bssid);
  1625. if (WARN_ON(!sta)) {
  1626. rcu_read_unlock();
  1627. return;
  1628. }
  1629. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1630. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1631. elems.ht_cap_elem, &sta->sta.ht_cap);
  1632. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1633. rcu_read_unlock();
  1634. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1635. bssid, ap_ht_cap_flags, true);
  1636. }
  1637. /* Note: country IE parsing is done for us by cfg80211 */
  1638. if (elems.country_elem) {
  1639. /* TODO: IBSS also needs this */
  1640. if (elems.pwr_constr_elem)
  1641. ieee80211_handle_pwr_constr(sdata,
  1642. le16_to_cpu(mgmt->u.probe_resp.capab_info),
  1643. elems.pwr_constr_elem,
  1644. elems.pwr_constr_elem_len);
  1645. }
  1646. ieee80211_bss_info_change_notify(sdata, changed);
  1647. }
  1648. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1649. struct sk_buff *skb)
  1650. {
  1651. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1652. struct ieee80211_rx_status *rx_status;
  1653. struct ieee80211_mgmt *mgmt;
  1654. enum rx_mgmt_action rma = RX_MGMT_NONE;
  1655. u16 fc;
  1656. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1657. mgmt = (struct ieee80211_mgmt *) skb->data;
  1658. fc = le16_to_cpu(mgmt->frame_control);
  1659. mutex_lock(&ifmgd->mtx);
  1660. if (ifmgd->associated &&
  1661. memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
  1662. switch (fc & IEEE80211_FCTL_STYPE) {
  1663. case IEEE80211_STYPE_BEACON:
  1664. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
  1665. rx_status);
  1666. break;
  1667. case IEEE80211_STYPE_PROBE_RESP:
  1668. ieee80211_rx_mgmt_probe_resp(sdata, skb);
  1669. break;
  1670. case IEEE80211_STYPE_DEAUTH:
  1671. rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  1672. break;
  1673. case IEEE80211_STYPE_DISASSOC:
  1674. rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  1675. break;
  1676. case IEEE80211_STYPE_ACTION:
  1677. switch (mgmt->u.action.category) {
  1678. case WLAN_CATEGORY_SPECTRUM_MGMT:
  1679. ieee80211_sta_process_chanswitch(sdata,
  1680. &mgmt->u.action.u.chan_switch.sw_elem,
  1681. (void *)ifmgd->associated->priv,
  1682. rx_status->mactime);
  1683. break;
  1684. }
  1685. }
  1686. mutex_unlock(&ifmgd->mtx);
  1687. switch (rma) {
  1688. case RX_MGMT_NONE:
  1689. /* no action */
  1690. break;
  1691. case RX_MGMT_CFG80211_DEAUTH:
  1692. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  1693. break;
  1694. case RX_MGMT_CFG80211_DISASSOC:
  1695. cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
  1696. break;
  1697. default:
  1698. WARN(1, "unexpected: %d", rma);
  1699. }
  1700. return;
  1701. }
  1702. mutex_unlock(&ifmgd->mtx);
  1703. if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
  1704. (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
  1705. struct ieee80211_local *local = sdata->local;
  1706. struct ieee80211_work *wk;
  1707. mutex_lock(&local->mtx);
  1708. list_for_each_entry(wk, &local->work_list, list) {
  1709. if (wk->sdata != sdata)
  1710. continue;
  1711. if (wk->type != IEEE80211_WORK_ASSOC &&
  1712. wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
  1713. continue;
  1714. if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
  1715. continue;
  1716. if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
  1717. continue;
  1718. /*
  1719. * Printing the message only here means we can't
  1720. * spuriously print it, but it also means that it
  1721. * won't be printed when the frame comes in before
  1722. * we even tried to associate or in similar cases.
  1723. *
  1724. * Ultimately, I suspect cfg80211 should print the
  1725. * messages instead.
  1726. */
  1727. printk(KERN_DEBUG
  1728. "%s: deauthenticated from %pM (Reason: %u)\n",
  1729. sdata->name, mgmt->bssid,
  1730. le16_to_cpu(mgmt->u.deauth.reason_code));
  1731. list_del_rcu(&wk->list);
  1732. free_work(wk);
  1733. break;
  1734. }
  1735. mutex_unlock(&local->mtx);
  1736. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
  1737. }
  1738. }
  1739. static void ieee80211_sta_timer(unsigned long data)
  1740. {
  1741. struct ieee80211_sub_if_data *sdata =
  1742. (struct ieee80211_sub_if_data *) data;
  1743. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1744. struct ieee80211_local *local = sdata->local;
  1745. if (local->quiescing) {
  1746. set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
  1747. return;
  1748. }
  1749. ieee80211_queue_work(&local->hw, &sdata->work);
  1750. }
  1751. static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  1752. u8 *bssid, u8 reason)
  1753. {
  1754. struct ieee80211_local *local = sdata->local;
  1755. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1756. ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  1757. IEEE80211_STA_BEACON_POLL);
  1758. ieee80211_set_disassoc(sdata, true, true);
  1759. mutex_unlock(&ifmgd->mtx);
  1760. mutex_lock(&local->mtx);
  1761. ieee80211_recalc_idle(local);
  1762. mutex_unlock(&local->mtx);
  1763. /*
  1764. * must be outside lock due to cfg80211,
  1765. * but that's not a problem.
  1766. */
  1767. ieee80211_send_deauth_disassoc(sdata, bssid,
  1768. IEEE80211_STYPE_DEAUTH, reason,
  1769. NULL, true);
  1770. mutex_lock(&ifmgd->mtx);
  1771. }
  1772. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  1773. {
  1774. struct ieee80211_local *local = sdata->local;
  1775. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1776. /* then process the rest of the work */
  1777. mutex_lock(&ifmgd->mtx);
  1778. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1779. IEEE80211_STA_CONNECTION_POLL) &&
  1780. ifmgd->associated) {
  1781. u8 bssid[ETH_ALEN];
  1782. int max_tries;
  1783. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  1784. if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
  1785. max_tries = max_nullfunc_tries;
  1786. else
  1787. max_tries = max_probe_tries;
  1788. /* ACK received for nullfunc probing frame */
  1789. if (!ifmgd->probe_send_count)
  1790. ieee80211_reset_ap_probe(sdata);
  1791. else if (ifmgd->nullfunc_failed) {
  1792. if (ifmgd->probe_send_count < max_tries) {
  1793. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1794. wiphy_debug(local->hw.wiphy,
  1795. "%s: No ack for nullfunc frame to"
  1796. " AP %pM, try %d/%i\n",
  1797. sdata->name, bssid,
  1798. ifmgd->probe_send_count, max_tries);
  1799. #endif
  1800. ieee80211_mgd_probe_ap_send(sdata);
  1801. } else {
  1802. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1803. wiphy_debug(local->hw.wiphy,
  1804. "%s: No ack for nullfunc frame to"
  1805. " AP %pM, disconnecting.\n",
  1806. sdata->name, bssid);
  1807. #endif
  1808. ieee80211_sta_connection_lost(sdata, bssid,
  1809. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1810. }
  1811. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  1812. run_again(ifmgd, ifmgd->probe_timeout);
  1813. else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
  1814. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1815. wiphy_debug(local->hw.wiphy,
  1816. "%s: Failed to send nullfunc to AP %pM"
  1817. " after %dms, disconnecting.\n",
  1818. sdata->name,
  1819. bssid, probe_wait_ms);
  1820. #endif
  1821. ieee80211_sta_connection_lost(sdata, bssid,
  1822. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1823. } else if (ifmgd->probe_send_count < max_tries) {
  1824. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1825. wiphy_debug(local->hw.wiphy,
  1826. "%s: No probe response from AP %pM"
  1827. " after %dms, try %d/%i\n",
  1828. sdata->name,
  1829. bssid, probe_wait_ms,
  1830. ifmgd->probe_send_count, max_tries);
  1831. #endif
  1832. ieee80211_mgd_probe_ap_send(sdata);
  1833. } else {
  1834. /*
  1835. * We actually lost the connection ... or did we?
  1836. * Let's make sure!
  1837. */
  1838. wiphy_debug(local->hw.wiphy,
  1839. "%s: No probe response from AP %pM"
  1840. " after %dms, disconnecting.\n",
  1841. sdata->name,
  1842. bssid, probe_wait_ms);
  1843. ieee80211_sta_connection_lost(sdata, bssid,
  1844. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  1845. }
  1846. }
  1847. mutex_unlock(&ifmgd->mtx);
  1848. }
  1849. static void ieee80211_sta_bcn_mon_timer(unsigned long data)
  1850. {
  1851. struct ieee80211_sub_if_data *sdata =
  1852. (struct ieee80211_sub_if_data *) data;
  1853. struct ieee80211_local *local = sdata->local;
  1854. if (local->quiescing)
  1855. return;
  1856. ieee80211_queue_work(&sdata->local->hw,
  1857. &sdata->u.mgd.beacon_connection_loss_work);
  1858. }
  1859. static void ieee80211_sta_conn_mon_timer(unsigned long data)
  1860. {
  1861. struct ieee80211_sub_if_data *sdata =
  1862. (struct ieee80211_sub_if_data *) data;
  1863. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1864. struct ieee80211_local *local = sdata->local;
  1865. if (local->quiescing)
  1866. return;
  1867. ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
  1868. }
  1869. static void ieee80211_sta_monitor_work(struct work_struct *work)
  1870. {
  1871. struct ieee80211_sub_if_data *sdata =
  1872. container_of(work, struct ieee80211_sub_if_data,
  1873. u.mgd.monitor_work);
  1874. ieee80211_mgd_probe_ap(sdata, false);
  1875. }
  1876. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  1877. {
  1878. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  1879. sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
  1880. IEEE80211_STA_CONNECTION_POLL);
  1881. /* let's probe the connection once */
  1882. ieee80211_queue_work(&sdata->local->hw,
  1883. &sdata->u.mgd.monitor_work);
  1884. /* and do all the other regular work too */
  1885. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  1886. }
  1887. }
  1888. #ifdef CONFIG_PM
  1889. void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
  1890. {
  1891. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1892. /*
  1893. * we need to use atomic bitops for the running bits
  1894. * only because both timers might fire at the same
  1895. * time -- the code here is properly synchronised.
  1896. */
  1897. cancel_work_sync(&ifmgd->request_smps_work);
  1898. cancel_work_sync(&ifmgd->monitor_work);
  1899. cancel_work_sync(&ifmgd->beacon_connection_loss_work);
  1900. if (del_timer_sync(&ifmgd->timer))
  1901. set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
  1902. cancel_work_sync(&ifmgd->chswitch_work);
  1903. if (del_timer_sync(&ifmgd->chswitch_timer))
  1904. set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
  1905. /* these will just be re-established on connection */
  1906. del_timer_sync(&ifmgd->conn_mon_timer);
  1907. del_timer_sync(&ifmgd->bcn_mon_timer);
  1908. }
  1909. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  1910. {
  1911. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1912. if (!ifmgd->associated)
  1913. return;
  1914. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  1915. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  1916. mutex_lock(&ifmgd->mtx);
  1917. if (ifmgd->associated) {
  1918. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1919. wiphy_debug(sdata->local->hw.wiphy,
  1920. "%s: driver requested disconnect after resume.\n",
  1921. sdata->name);
  1922. #endif
  1923. ieee80211_sta_connection_lost(sdata,
  1924. ifmgd->associated->bssid,
  1925. WLAN_REASON_UNSPECIFIED);
  1926. mutex_unlock(&ifmgd->mtx);
  1927. return;
  1928. }
  1929. mutex_unlock(&ifmgd->mtx);
  1930. }
  1931. if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
  1932. add_timer(&ifmgd->timer);
  1933. if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
  1934. add_timer(&ifmgd->chswitch_timer);
  1935. ieee80211_sta_reset_beacon_monitor(sdata);
  1936. ieee80211_restart_sta_timer(sdata);
  1937. ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.monitor_work);
  1938. }
  1939. #endif
  1940. /* interface setup */
  1941. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  1942. {
  1943. struct ieee80211_if_managed *ifmgd;
  1944. ifmgd = &sdata->u.mgd;
  1945. INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  1946. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  1947. INIT_WORK(&ifmgd->beacon_connection_loss_work,
  1948. ieee80211_beacon_connection_loss_work);
  1949. INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
  1950. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  1951. (unsigned long) sdata);
  1952. setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
  1953. (unsigned long) sdata);
  1954. setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
  1955. (unsigned long) sdata);
  1956. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  1957. (unsigned long) sdata);
  1958. ifmgd->flags = 0;
  1959. mutex_init(&ifmgd->mtx);
  1960. if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
  1961. ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
  1962. else
  1963. ifmgd->req_smps = IEEE80211_SMPS_OFF;
  1964. }
  1965. /* scan finished notification */
  1966. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  1967. {
  1968. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1969. /* Restart STA timers */
  1970. rcu_read_lock();
  1971. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  1972. ieee80211_restart_sta_timer(sdata);
  1973. rcu_read_unlock();
  1974. }
  1975. int ieee80211_max_network_latency(struct notifier_block *nb,
  1976. unsigned long data, void *dummy)
  1977. {
  1978. s32 latency_usec = (s32) data;
  1979. struct ieee80211_local *local =
  1980. container_of(nb, struct ieee80211_local,
  1981. network_latency_notifier);
  1982. mutex_lock(&local->iflist_mtx);
  1983. ieee80211_recalc_ps(local, latency_usec);
  1984. mutex_unlock(&local->iflist_mtx);
  1985. return 0;
  1986. }
  1987. /* config hooks */
  1988. static enum work_done_result
  1989. ieee80211_probe_auth_done(struct ieee80211_work *wk,
  1990. struct sk_buff *skb)
  1991. {
  1992. struct ieee80211_local *local = wk->sdata->local;
  1993. if (!skb) {
  1994. cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
  1995. goto destroy;
  1996. }
  1997. if (wk->type == IEEE80211_WORK_AUTH) {
  1998. cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
  1999. goto destroy;
  2000. }
  2001. mutex_lock(&wk->sdata->u.mgd.mtx);
  2002. ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
  2003. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2004. wk->type = IEEE80211_WORK_AUTH;
  2005. wk->probe_auth.tries = 0;
  2006. return WORK_DONE_REQUEUE;
  2007. destroy:
  2008. if (wk->probe_auth.synced)
  2009. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2010. IEEE80211_TX_SYNC_AUTH);
  2011. return WORK_DONE_DESTROY;
  2012. }
  2013. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  2014. struct cfg80211_auth_request *req)
  2015. {
  2016. const u8 *ssid;
  2017. struct ieee80211_work *wk;
  2018. u16 auth_alg;
  2019. if (req->local_state_change)
  2020. return 0; /* no need to update mac80211 state */
  2021. switch (req->auth_type) {
  2022. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  2023. auth_alg = WLAN_AUTH_OPEN;
  2024. break;
  2025. case NL80211_AUTHTYPE_SHARED_KEY:
  2026. if (IS_ERR(sdata->local->wep_tx_tfm))
  2027. return -EOPNOTSUPP;
  2028. auth_alg = WLAN_AUTH_SHARED_KEY;
  2029. break;
  2030. case NL80211_AUTHTYPE_FT:
  2031. auth_alg = WLAN_AUTH_FT;
  2032. break;
  2033. case NL80211_AUTHTYPE_NETWORK_EAP:
  2034. auth_alg = WLAN_AUTH_LEAP;
  2035. break;
  2036. default:
  2037. return -EOPNOTSUPP;
  2038. }
  2039. wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
  2040. if (!wk)
  2041. return -ENOMEM;
  2042. memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
  2043. if (req->ie && req->ie_len) {
  2044. memcpy(wk->ie, req->ie, req->ie_len);
  2045. wk->ie_len = req->ie_len;
  2046. }
  2047. if (req->key && req->key_len) {
  2048. wk->probe_auth.key_len = req->key_len;
  2049. wk->probe_auth.key_idx = req->key_idx;
  2050. memcpy(wk->probe_auth.key, req->key, req->key_len);
  2051. }
  2052. ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  2053. memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
  2054. wk->probe_auth.ssid_len = ssid[1];
  2055. wk->probe_auth.algorithm = auth_alg;
  2056. wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
  2057. /* if we already have a probe, don't probe again */
  2058. if (req->bss->proberesp_ies)
  2059. wk->type = IEEE80211_WORK_AUTH;
  2060. else
  2061. wk->type = IEEE80211_WORK_DIRECT_PROBE;
  2062. wk->chan = req->bss->channel;
  2063. wk->chan_type = NL80211_CHAN_NO_HT;
  2064. wk->sdata = sdata;
  2065. wk->done = ieee80211_probe_auth_done;
  2066. ieee80211_add_work(wk);
  2067. return 0;
  2068. }
  2069. /* create and insert a dummy station entry */
  2070. static int ieee80211_pre_assoc(struct ieee80211_sub_if_data *sdata,
  2071. u8 *bssid) {
  2072. struct sta_info *sta;
  2073. int err;
  2074. sta = sta_info_alloc(sdata, bssid, GFP_KERNEL);
  2075. if (!sta)
  2076. return -ENOMEM;
  2077. sta->dummy = true;
  2078. err = sta_info_insert(sta);
  2079. sta = NULL;
  2080. if (err) {
  2081. printk(KERN_DEBUG "%s: failed to insert Dummy STA entry for"
  2082. " the AP (error %d)\n", sdata->name, err);
  2083. return err;
  2084. }
  2085. return 0;
  2086. }
  2087. static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
  2088. struct sk_buff *skb)
  2089. {
  2090. struct ieee80211_local *local = wk->sdata->local;
  2091. struct ieee80211_mgmt *mgmt;
  2092. struct ieee80211_rx_status *rx_status;
  2093. struct ieee802_11_elems elems;
  2094. struct cfg80211_bss *cbss = wk->assoc.bss;
  2095. u16 status;
  2096. if (!skb) {
  2097. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2098. cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
  2099. goto destroy;
  2100. }
  2101. if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
  2102. mutex_lock(&wk->sdata->u.mgd.mtx);
  2103. rx_status = (void *) skb->cb;
  2104. ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
  2105. ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
  2106. &elems, true);
  2107. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2108. wk->type = IEEE80211_WORK_ASSOC;
  2109. /* not really done yet */
  2110. return WORK_DONE_REQUEUE;
  2111. }
  2112. mgmt = (void *)skb->data;
  2113. status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  2114. if (status == WLAN_STATUS_SUCCESS) {
  2115. if (wk->assoc.synced)
  2116. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2117. IEEE80211_TX_SYNC_ASSOC);
  2118. mutex_lock(&wk->sdata->u.mgd.mtx);
  2119. if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
  2120. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2121. /* oops -- internal error -- send timeout for now */
  2122. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2123. cfg80211_send_assoc_timeout(wk->sdata->dev,
  2124. wk->filter_ta);
  2125. return WORK_DONE_DESTROY;
  2126. }
  2127. mutex_unlock(&wk->sdata->u.mgd.mtx);
  2128. } else {
  2129. /* assoc failed - destroy the dummy station entry */
  2130. sta_info_destroy_addr(wk->sdata, cbss->bssid);
  2131. }
  2132. cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
  2133. destroy:
  2134. if (wk->assoc.synced)
  2135. drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
  2136. IEEE80211_TX_SYNC_ASSOC);
  2137. return WORK_DONE_DESTROY;
  2138. }
  2139. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  2140. struct cfg80211_assoc_request *req)
  2141. {
  2142. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2143. struct ieee80211_bss *bss = (void *)req->bss->priv;
  2144. struct ieee80211_work *wk;
  2145. const u8 *ssid;
  2146. int i, err;
  2147. mutex_lock(&ifmgd->mtx);
  2148. if (ifmgd->associated) {
  2149. if (!req->prev_bssid ||
  2150. memcmp(req->prev_bssid, ifmgd->associated->bssid,
  2151. ETH_ALEN)) {
  2152. /*
  2153. * We are already associated and the request was not a
  2154. * reassociation request from the current BSS, so
  2155. * reject it.
  2156. */
  2157. mutex_unlock(&ifmgd->mtx);
  2158. return -EALREADY;
  2159. }
  2160. /* Trying to reassociate - clear previous association state */
  2161. ieee80211_set_disassoc(sdata, true, false);
  2162. }
  2163. mutex_unlock(&ifmgd->mtx);
  2164. wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
  2165. if (!wk)
  2166. return -ENOMEM;
  2167. /*
  2168. * create a dummy station info entry in order
  2169. * to start accepting incoming EAPOL packets from the station
  2170. */
  2171. err = ieee80211_pre_assoc(sdata, req->bss->bssid);
  2172. if (err) {
  2173. kfree(wk);
  2174. return err;
  2175. }
  2176. ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
  2177. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  2178. ifmgd->beacon_crc_valid = false;
  2179. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
  2180. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  2181. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  2182. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
  2183. ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
  2184. if (req->ie && req->ie_len) {
  2185. memcpy(wk->ie, req->ie, req->ie_len);
  2186. wk->ie_len = req->ie_len;
  2187. } else
  2188. wk->ie_len = 0;
  2189. wk->assoc.bss = req->bss;
  2190. memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
  2191. /* new association always uses requested smps mode */
  2192. if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
  2193. if (ifmgd->powersave)
  2194. ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
  2195. else
  2196. ifmgd->ap_smps = IEEE80211_SMPS_OFF;
  2197. } else
  2198. ifmgd->ap_smps = ifmgd->req_smps;
  2199. wk->assoc.smps = ifmgd->ap_smps;
  2200. /*
  2201. * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
  2202. * We still associate in non-HT mode (11a/b/g) if any one of these
  2203. * ciphers is configured as pairwise.
  2204. * We can set this to true for non-11n hardware, that'll be checked
  2205. * separately along with the peer capabilities.
  2206. */
  2207. wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
  2208. wk->assoc.capability = req->bss->capability;
  2209. wk->assoc.wmm_used = bss->wmm_used;
  2210. wk->assoc.supp_rates = bss->supp_rates;
  2211. wk->assoc.supp_rates_len = bss->supp_rates_len;
  2212. wk->assoc.ht_information_ie =
  2213. ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
  2214. if (bss->wmm_used && bss->uapsd_supported &&
  2215. (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
  2216. wk->assoc.uapsd_used = true;
  2217. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  2218. } else {
  2219. wk->assoc.uapsd_used = false;
  2220. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  2221. }
  2222. ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  2223. memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
  2224. wk->assoc.ssid_len = ssid[1];
  2225. if (req->prev_bssid)
  2226. memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
  2227. wk->chan = req->bss->channel;
  2228. wk->chan_type = NL80211_CHAN_NO_HT;
  2229. wk->sdata = sdata;
  2230. wk->done = ieee80211_assoc_done;
  2231. if (!bss->dtim_period &&
  2232. sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
  2233. wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
  2234. else
  2235. wk->type = IEEE80211_WORK_ASSOC;
  2236. if (req->use_mfp) {
  2237. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  2238. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  2239. } else {
  2240. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  2241. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  2242. }
  2243. if (req->crypto.control_port)
  2244. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  2245. else
  2246. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  2247. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  2248. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  2249. ieee80211_add_work(wk);
  2250. return 0;
  2251. }
  2252. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  2253. struct cfg80211_deauth_request *req,
  2254. void *cookie)
  2255. {
  2256. struct ieee80211_local *local = sdata->local;
  2257. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2258. struct ieee80211_work *wk;
  2259. u8 bssid[ETH_ALEN];
  2260. bool assoc_bss = false;
  2261. mutex_lock(&ifmgd->mtx);
  2262. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  2263. if (ifmgd->associated == req->bss) {
  2264. ieee80211_set_disassoc(sdata, false, true);
  2265. mutex_unlock(&ifmgd->mtx);
  2266. assoc_bss = true;
  2267. } else {
  2268. bool not_auth_yet = false;
  2269. mutex_unlock(&ifmgd->mtx);
  2270. mutex_lock(&local->mtx);
  2271. list_for_each_entry(wk, &local->work_list, list) {
  2272. if (wk->sdata != sdata)
  2273. continue;
  2274. if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
  2275. wk->type != IEEE80211_WORK_AUTH &&
  2276. wk->type != IEEE80211_WORK_ASSOC &&
  2277. wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
  2278. continue;
  2279. if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
  2280. continue;
  2281. not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
  2282. list_del_rcu(&wk->list);
  2283. free_work(wk);
  2284. break;
  2285. }
  2286. mutex_unlock(&local->mtx);
  2287. /*
  2288. * If somebody requests authentication and we haven't
  2289. * sent out an auth frame yet there's no need to send
  2290. * out a deauth frame either. If the state was PROBE,
  2291. * then this is the case. If it's AUTH we have sent a
  2292. * frame, and if it's IDLE we have completed the auth
  2293. * process already.
  2294. */
  2295. if (not_auth_yet) {
  2296. __cfg80211_auth_canceled(sdata->dev, bssid);
  2297. return 0;
  2298. }
  2299. }
  2300. printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
  2301. sdata->name, bssid, req->reason_code);
  2302. ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
  2303. req->reason_code, cookie,
  2304. !req->local_state_change);
  2305. if (assoc_bss)
  2306. sta_info_flush(sdata->local, sdata);
  2307. mutex_lock(&sdata->local->mtx);
  2308. ieee80211_recalc_idle(sdata->local);
  2309. mutex_unlock(&sdata->local->mtx);
  2310. return 0;
  2311. }
  2312. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  2313. struct cfg80211_disassoc_request *req,
  2314. void *cookie)
  2315. {
  2316. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2317. u8 bssid[ETH_ALEN];
  2318. mutex_lock(&ifmgd->mtx);
  2319. /*
  2320. * cfg80211 should catch this ... but it's racy since
  2321. * we can receive a disassoc frame, process it, hand it
  2322. * to cfg80211 while that's in a locked section already
  2323. * trying to tell us that the user wants to disconnect.
  2324. */
  2325. if (ifmgd->associated != req->bss) {
  2326. mutex_unlock(&ifmgd->mtx);
  2327. return -ENOLINK;
  2328. }
  2329. printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
  2330. sdata->name, req->bss->bssid, req->reason_code);
  2331. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  2332. ieee80211_set_disassoc(sdata, false, true);
  2333. mutex_unlock(&ifmgd->mtx);
  2334. ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
  2335. IEEE80211_STYPE_DISASSOC, req->reason_code,
  2336. cookie, !req->local_state_change);
  2337. sta_info_flush(sdata->local, sdata);
  2338. mutex_lock(&sdata->local->mtx);
  2339. ieee80211_recalc_idle(sdata->local);
  2340. mutex_unlock(&sdata->local->mtx);
  2341. return 0;
  2342. }
  2343. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  2344. enum nl80211_cqm_rssi_threshold_event rssi_event,
  2345. gfp_t gfp)
  2346. {
  2347. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2348. trace_api_cqm_rssi_notify(sdata, rssi_event);
  2349. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
  2350. }
  2351. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
  2352. unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
  2353. {
  2354. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2355. return sdata->dev->operstate;
  2356. }
  2357. EXPORT_SYMBOL(ieee80211_get_operstate);