mlme.c 77 KB

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