mlme.c 66 KB

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