mlme.c 62 KB

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