mlme.c 65 KB

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