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