mlme.c 62 KB

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