mlme.c 61 KB

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