mlme.c 62 KB

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