mlme.c 64 KB

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