mlme.c 77 KB

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