mlme.c 62 KB

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