PageRenderTime 31ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/net/mac80211/mlme.c

https://bitbucket.org/paulobrien/android_kernel_andypad
C | 1780 lines | 1250 code | 322 blank | 208 comment | 230 complexity | fc3c42602562b3f1e2617bc5a55402b9 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  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_AUTH_TIMEOUT (HZ / 5)
  28. #define IEEE80211_AUTH_MAX_TRIES 3
  29. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  30. #define IEEE80211_ASSOC_MAX_TRIES 3
  31. #define IEEE80211_MAX_PROBE_TRIES 5
  32. /*
  33. * beacon loss detection timeout
  34. * XXX: should depend on beacon interval
  35. */
  36. #define IEEE80211_BEACON_LOSS_TIME (2 * HZ)
  37. /*
  38. * Time the connection can be idle before we probe
  39. * it to see if we can still talk to the AP.
  40. */
  41. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  42. /*
  43. * Time we wait for a probe response after sending
  44. * a probe request because of beacon loss or for
  45. * checking the connection still works.
  46. */
  47. #define IEEE80211_PROBE_WAIT (HZ / 2)
  48. #define TMR_RUNNING_TIMER 0
  49. #define TMR_RUNNING_CHANSW 1
  50. /*
  51. * All cfg80211 functions have to be called outside a locked
  52. * section so that they can acquire a lock themselves... This
  53. * is much simpler than queuing up things in cfg80211, but we
  54. * do need some indirection for that here.
  55. */
  56. enum rx_mgmt_action {
  57. /* no action required */
  58. RX_MGMT_NONE,
  59. /* caller must call cfg80211_send_rx_auth() */
  60. RX_MGMT_CFG80211_AUTH,
  61. /* caller must call cfg80211_send_rx_assoc() */
  62. RX_MGMT_CFG80211_ASSOC,
  63. /* caller must call cfg80211_send_deauth() */
  64. RX_MGMT_CFG80211_DEAUTH,
  65. /* caller must call cfg80211_send_disassoc() */
  66. RX_MGMT_CFG80211_DISASSOC,
  67. /* caller must call cfg80211_auth_timeout() & free work */
  68. RX_MGMT_CFG80211_AUTH_TO,
  69. /* caller must call cfg80211_assoc_timeout() & free work */
  70. RX_MGMT_CFG80211_ASSOC_TO,
  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. static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
  107. struct ieee80211_supported_band *sband,
  108. u32 *rates)
  109. {
  110. int i, j, count;
  111. *rates = 0;
  112. count = 0;
  113. for (i = 0; i < bss->supp_rates_len; i++) {
  114. int rate = (bss->supp_rates[i] & 0x7F) * 5;
  115. for (j = 0; j < sband->n_bitrates; j++)
  116. if (sband->bitrates[j].bitrate == rate) {
  117. *rates |= BIT(j);
  118. count++;
  119. break;
  120. }
  121. }
  122. return count;
  123. }
  124. /*
  125. * ieee80211_enable_ht should be called only after the operating band
  126. * has been determined as ht configuration depends on the hw's
  127. * HT abilities for a specific band.
  128. */
  129. static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
  130. struct ieee80211_ht_info *hti,
  131. const u8 *bssid, u16 ap_ht_cap_flags)
  132. {
  133. struct ieee80211_local *local = sdata->local;
  134. struct ieee80211_supported_band *sband;
  135. struct sta_info *sta;
  136. u32 changed = 0;
  137. u16 ht_opmode;
  138. bool enable_ht = true, ht_changed;
  139. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  140. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  141. /* HT is not supported */
  142. if (!sband->ht_cap.ht_supported)
  143. enable_ht = false;
  144. /* check that channel matches the right operating channel */
  145. if (local->hw.conf.channel->center_freq !=
  146. ieee80211_channel_to_frequency(hti->control_chan))
  147. enable_ht = false;
  148. if (enable_ht) {
  149. channel_type = NL80211_CHAN_HT20;
  150. if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
  151. (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
  152. (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
  153. switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  154. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  155. if (!(local->hw.conf.channel->flags &
  156. IEEE80211_CHAN_NO_HT40PLUS))
  157. channel_type = NL80211_CHAN_HT40PLUS;
  158. break;
  159. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  160. if (!(local->hw.conf.channel->flags &
  161. IEEE80211_CHAN_NO_HT40MINUS))
  162. channel_type = NL80211_CHAN_HT40MINUS;
  163. break;
  164. }
  165. }
  166. }
  167. ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
  168. channel_type != local->hw.conf.channel_type;
  169. local->oper_channel_type = channel_type;
  170. if (ht_changed) {
  171. /* channel_type change automatically detected */
  172. ieee80211_hw_config(local, 0);
  173. rcu_read_lock();
  174. sta = sta_info_get(local, bssid);
  175. if (sta)
  176. rate_control_rate_update(local, sband, sta,
  177. IEEE80211_RC_HT_CHANGED);
  178. rcu_read_unlock();
  179. }
  180. /* disable HT */
  181. if (!enable_ht)
  182. return 0;
  183. ht_opmode = le16_to_cpu(hti->operation_mode);
  184. /* if bss configuration changed store the new one */
  185. if (!sdata->ht_opmode_valid ||
  186. sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
  187. changed |= BSS_CHANGED_HT;
  188. sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
  189. sdata->ht_opmode_valid = true;
  190. }
  191. return changed;
  192. }
  193. /* frame sending functions */
  194. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
  195. struct ieee80211_mgd_work *wk)
  196. {
  197. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  198. struct ieee80211_local *local = sdata->local;
  199. struct sk_buff *skb;
  200. struct ieee80211_mgmt *mgmt;
  201. u8 *pos;
  202. const u8 *ies, *ht_ie;
  203. int i, len, count, rates_len, supp_rates_len;
  204. u16 capab;
  205. int wmm = 0;
  206. struct ieee80211_supported_band *sband;
  207. u32 rates = 0;
  208. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  209. sizeof(*mgmt) + 200 + wk->ie_len +
  210. wk->ssid_len);
  211. if (!skb) {
  212. printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
  213. "frame\n", sdata->dev->name);
  214. return;
  215. }
  216. skb_reserve(skb, local->hw.extra_tx_headroom);
  217. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  218. capab = ifmgd->capab;
  219. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
  220. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  221. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  222. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  223. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  224. }
  225. if (wk->bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
  226. capab |= WLAN_CAPABILITY_PRIVACY;
  227. if (wk->bss->wmm_used)
  228. wmm = 1;
  229. if ((wk->bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  230. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  231. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  232. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  233. memset(mgmt, 0, 24);
  234. memcpy(mgmt->da, wk->bss->cbss.bssid, ETH_ALEN);
  235. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  236. memcpy(mgmt->bssid, wk->bss->cbss.bssid, ETH_ALEN);
  237. if (!is_zero_ether_addr(wk->prev_bssid)) {
  238. skb_put(skb, 10);
  239. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  240. IEEE80211_STYPE_REASSOC_REQ);
  241. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  242. mgmt->u.reassoc_req.listen_interval =
  243. cpu_to_le16(local->hw.conf.listen_interval);
  244. memcpy(mgmt->u.reassoc_req.current_ap, wk->prev_bssid,
  245. ETH_ALEN);
  246. } else {
  247. skb_put(skb, 4);
  248. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  249. IEEE80211_STYPE_ASSOC_REQ);
  250. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  251. mgmt->u.assoc_req.listen_interval =
  252. cpu_to_le16(local->hw.conf.listen_interval);
  253. }
  254. /* SSID */
  255. ies = pos = skb_put(skb, 2 + wk->ssid_len);
  256. *pos++ = WLAN_EID_SSID;
  257. *pos++ = wk->ssid_len;
  258. memcpy(pos, wk->ssid, wk->ssid_len);
  259. if (wk->bss->supp_rates_len) {
  260. /* get all rates supported by the device and the AP as
  261. * some APs don't like getting a superset of their rates
  262. * in the association request (e.g. D-Link DAP 1353 in
  263. * b-only mode) */
  264. rates_len = ieee80211_compatible_rates(wk->bss, sband, &rates);
  265. } else {
  266. rates = ~0;
  267. rates_len = sband->n_bitrates;
  268. }
  269. /* add all rates which were marked to be used above */
  270. supp_rates_len = rates_len;
  271. if (supp_rates_len > 8)
  272. supp_rates_len = 8;
  273. len = sband->n_bitrates;
  274. pos = skb_put(skb, supp_rates_len + 2);
  275. *pos++ = WLAN_EID_SUPP_RATES;
  276. *pos++ = supp_rates_len;
  277. count = 0;
  278. for (i = 0; i < sband->n_bitrates; i++) {
  279. if (BIT(i) & rates) {
  280. int rate = sband->bitrates[i].bitrate;
  281. *pos++ = (u8) (rate / 5);
  282. if (++count == 8)
  283. break;
  284. }
  285. }
  286. if (rates_len > count) {
  287. pos = skb_put(skb, rates_len - count + 2);
  288. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  289. *pos++ = rates_len - count;
  290. for (i++; i < sband->n_bitrates; i++) {
  291. if (BIT(i) & rates) {
  292. int rate = sband->bitrates[i].bitrate;
  293. *pos++ = (u8) (rate / 5);
  294. }
  295. }
  296. }
  297. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  298. /* 1. power capabilities */
  299. pos = skb_put(skb, 4);
  300. *pos++ = WLAN_EID_PWR_CAPABILITY;
  301. *pos++ = 2;
  302. *pos++ = 0; /* min tx power */
  303. *pos++ = local->hw.conf.channel->max_power; /* max tx power */
  304. /* 2. supported channels */
  305. /* TODO: get this in reg domain format */
  306. pos = skb_put(skb, 2 * sband->n_channels + 2);
  307. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  308. *pos++ = 2 * sband->n_channels;
  309. for (i = 0; i < sband->n_channels; i++) {
  310. *pos++ = ieee80211_frequency_to_channel(
  311. sband->channels[i].center_freq);
  312. *pos++ = 1; /* one channel in the subband*/
  313. }
  314. }
  315. if (wk->ie_len && wk->ie) {
  316. pos = skb_put(skb, wk->ie_len);
  317. memcpy(pos, wk->ie, wk->ie_len);
  318. }
  319. if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
  320. pos = skb_put(skb, 9);
  321. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  322. *pos++ = 7; /* len */
  323. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  324. *pos++ = 0x50;
  325. *pos++ = 0xf2;
  326. *pos++ = 2; /* WME */
  327. *pos++ = 0; /* WME info */
  328. *pos++ = 1; /* WME ver */
  329. *pos++ = 0;
  330. }
  331. /* wmm support is a must to HT */
  332. /*
  333. * IEEE802.11n does not allow TKIP/WEP as pairwise
  334. * ciphers in HT mode. We still associate in non-ht
  335. * mode (11a/b/g) if any one of these ciphers is
  336. * configured as pairwise.
  337. */
  338. if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
  339. sband->ht_cap.ht_supported &&
  340. (ht_ie = ieee80211_bss_get_ie(&wk->bss->cbss, WLAN_EID_HT_INFORMATION)) &&
  341. ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
  342. (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))) {
  343. struct ieee80211_ht_info *ht_info =
  344. (struct ieee80211_ht_info *)(ht_ie + 2);
  345. u16 cap = sband->ht_cap.cap;
  346. __le16 tmp;
  347. u32 flags = local->hw.conf.channel->flags;
  348. switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  349. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  350. if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
  351. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  352. cap &= ~IEEE80211_HT_CAP_SGI_40;
  353. }
  354. break;
  355. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  356. if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
  357. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  358. cap &= ~IEEE80211_HT_CAP_SGI_40;
  359. }
  360. break;
  361. }
  362. tmp = cpu_to_le16(cap);
  363. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
  364. *pos++ = WLAN_EID_HT_CAPABILITY;
  365. *pos++ = sizeof(struct ieee80211_ht_cap);
  366. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  367. memcpy(pos, &tmp, sizeof(u16));
  368. pos += sizeof(u16);
  369. /* TODO: needs a define here for << 2 */
  370. *pos++ = sband->ht_cap.ampdu_factor |
  371. (sband->ht_cap.ampdu_density << 2);
  372. memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
  373. }
  374. ieee80211_tx_skb(sdata, skb, 0);
  375. }
  376. static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  377. const u8 *bssid, u16 stype, u16 reason,
  378. void *cookie)
  379. {
  380. struct ieee80211_local *local = sdata->local;
  381. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  382. struct sk_buff *skb;
  383. struct ieee80211_mgmt *mgmt;
  384. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  385. if (!skb) {
  386. printk(KERN_DEBUG "%s: failed to allocate buffer for "
  387. "deauth/disassoc frame\n", sdata->dev->name);
  388. return;
  389. }
  390. skb_reserve(skb, local->hw.extra_tx_headroom);
  391. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  392. memset(mgmt, 0, 24);
  393. memcpy(mgmt->da, bssid, ETH_ALEN);
  394. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  395. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  396. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  397. skb_put(skb, 2);
  398. /* u.deauth.reason_code == u.disassoc.reason_code */
  399. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  400. if (stype == IEEE80211_STYPE_DEAUTH)
  401. cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, cookie);
  402. else
  403. cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len, cookie);
  404. ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
  405. }
  406. void ieee80211_send_pspoll(struct ieee80211_local *local,
  407. struct ieee80211_sub_if_data *sdata)
  408. {
  409. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  410. struct ieee80211_pspoll *pspoll;
  411. struct sk_buff *skb;
  412. u16 fc;
  413. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
  414. if (!skb) {
  415. printk(KERN_DEBUG "%s: failed to allocate buffer for "
  416. "pspoll frame\n", sdata->dev->name);
  417. return;
  418. }
  419. skb_reserve(skb, local->hw.extra_tx_headroom);
  420. pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
  421. memset(pspoll, 0, sizeof(*pspoll));
  422. fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
  423. pspoll->frame_control = cpu_to_le16(fc);
  424. pspoll->aid = cpu_to_le16(ifmgd->aid);
  425. /* aid in PS-Poll has its two MSBs each set to 1 */
  426. pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
  427. memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
  428. memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
  429. ieee80211_tx_skb(sdata, skb, 0);
  430. }
  431. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  432. struct ieee80211_sub_if_data *sdata,
  433. int powersave)
  434. {
  435. struct sk_buff *skb;
  436. struct ieee80211_hdr *nullfunc;
  437. __le16 fc;
  438. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  439. return;
  440. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
  441. if (!skb) {
  442. printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
  443. "frame\n", sdata->dev->name);
  444. return;
  445. }
  446. skb_reserve(skb, local->hw.extra_tx_headroom);
  447. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
  448. memset(nullfunc, 0, 24);
  449. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  450. IEEE80211_FCTL_TODS);
  451. if (powersave)
  452. fc |= cpu_to_le16(IEEE80211_FCTL_PM);
  453. nullfunc->frame_control = fc;
  454. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  455. memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
  456. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  457. ieee80211_tx_skb(sdata, skb, 0);
  458. }
  459. /* spectrum management related things */
  460. static void ieee80211_chswitch_work(struct work_struct *work)
  461. {
  462. struct ieee80211_sub_if_data *sdata =
  463. container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
  464. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  465. if (!netif_running(sdata->dev))
  466. return;
  467. mutex_lock(&ifmgd->mtx);
  468. if (!ifmgd->associated)
  469. goto out;
  470. sdata->local->oper_channel = sdata->local->csa_channel;
  471. ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
  472. /* XXX: shouldn't really modify cfg80211-owned data! */
  473. ifmgd->associated->cbss.channel = sdata->local->oper_channel;
  474. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  475. IEEE80211_QUEUE_STOP_REASON_CSA);
  476. out:
  477. ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
  478. mutex_unlock(&ifmgd->mtx);
  479. }
  480. static void ieee80211_chswitch_timer(unsigned long data)
  481. {
  482. struct ieee80211_sub_if_data *sdata =
  483. (struct ieee80211_sub_if_data *) data;
  484. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  485. if (sdata->local->quiescing) {
  486. set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
  487. return;
  488. }
  489. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  490. }
  491. void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
  492. struct ieee80211_channel_sw_ie *sw_elem,
  493. struct ieee80211_bss *bss)
  494. {
  495. struct ieee80211_channel *new_ch;
  496. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  497. int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
  498. ASSERT_MGD_MTX(ifmgd);
  499. if (!ifmgd->associated)
  500. return;
  501. if (sdata->local->scanning)
  502. return;
  503. /* Disregard subsequent beacons if we are already running a timer
  504. processing a CSA */
  505. if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
  506. return;
  507. new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
  508. if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
  509. return;
  510. sdata->local->csa_channel = new_ch;
  511. if (sw_elem->count <= 1) {
  512. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  513. } else {
  514. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  515. IEEE80211_QUEUE_STOP_REASON_CSA);
  516. ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
  517. mod_timer(&ifmgd->chswitch_timer,
  518. jiffies +
  519. msecs_to_jiffies(sw_elem->count *
  520. bss->cbss.beacon_interval));
  521. }
  522. }
  523. static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
  524. u16 capab_info, u8 *pwr_constr_elem,
  525. u8 pwr_constr_elem_len)
  526. {
  527. struct ieee80211_conf *conf = &sdata->local->hw.conf;
  528. if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
  529. return;
  530. /* Power constraint IE length should be 1 octet */
  531. if (pwr_constr_elem_len != 1)
  532. return;
  533. if ((*pwr_constr_elem <= conf->channel->max_power) &&
  534. (*pwr_constr_elem != sdata->local->power_constr_level)) {
  535. sdata->local->power_constr_level = *pwr_constr_elem;
  536. ieee80211_hw_config(sdata->local, 0);
  537. }
  538. }
  539. /* powersave */
  540. static void ieee80211_enable_ps(struct ieee80211_local *local,
  541. struct ieee80211_sub_if_data *sdata)
  542. {
  543. struct ieee80211_conf *conf = &local->hw.conf;
  544. /*
  545. * If we are scanning right now then the parameters will
  546. * take effect when scan finishes.
  547. */
  548. if (local->scanning)
  549. return;
  550. if (conf->dynamic_ps_timeout > 0 &&
  551. !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
  552. mod_timer(&local->dynamic_ps_timer, jiffies +
  553. msecs_to_jiffies(conf->dynamic_ps_timeout));
  554. } else {
  555. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  556. ieee80211_send_nullfunc(local, sdata, 1);
  557. if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
  558. conf->flags |= IEEE80211_CONF_PS;
  559. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  560. }
  561. }
  562. }
  563. static void ieee80211_change_ps(struct ieee80211_local *local)
  564. {
  565. struct ieee80211_conf *conf = &local->hw.conf;
  566. if (local->ps_sdata) {
  567. ieee80211_enable_ps(local, local->ps_sdata);
  568. } else if (conf->flags & IEEE80211_CONF_PS) {
  569. conf->flags &= ~IEEE80211_CONF_PS;
  570. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  571. del_timer_sync(&local->dynamic_ps_timer);
  572. cancel_work_sync(&local->dynamic_ps_enable_work);
  573. }
  574. }
  575. /* need to hold RTNL or interface lock */
  576. void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
  577. {
  578. struct ieee80211_sub_if_data *sdata, *found = NULL;
  579. int count = 0;
  580. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
  581. local->ps_sdata = NULL;
  582. return;
  583. }
  584. list_for_each_entry(sdata, &local->interfaces, list) {
  585. if (!netif_running(sdata->dev))
  586. continue;
  587. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  588. continue;
  589. found = sdata;
  590. count++;
  591. }
  592. if (count == 1 && found->u.mgd.powersave &&
  593. found->u.mgd.associated && list_empty(&found->u.mgd.work_list) &&
  594. !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
  595. IEEE80211_STA_CONNECTION_POLL))) {
  596. s32 beaconint_us;
  597. if (latency < 0)
  598. latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
  599. beaconint_us = ieee80211_tu_to_usec(
  600. found->vif.bss_conf.beacon_int);
  601. if (beaconint_us > latency) {
  602. local->ps_sdata = NULL;
  603. } else {
  604. u8 dtimper = found->vif.bss_conf.dtim_period;
  605. int maxslp = 1;
  606. if (dtimper > 1)
  607. maxslp = min_t(int, dtimper,
  608. latency / beaconint_us);
  609. local->hw.conf.max_sleep_period = maxslp;
  610. local->ps_sdata = found;
  611. }
  612. } else {
  613. local->ps_sdata = NULL;
  614. }
  615. ieee80211_change_ps(local);
  616. }
  617. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  618. {
  619. struct ieee80211_local *local =
  620. container_of(work, struct ieee80211_local,
  621. dynamic_ps_disable_work);
  622. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  623. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  624. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  625. }
  626. ieee80211_wake_queues_by_reason(&local->hw,
  627. IEEE80211_QUEUE_STOP_REASON_PS);
  628. }
  629. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  630. {
  631. struct ieee80211_local *local =
  632. container_of(work, struct ieee80211_local,
  633. dynamic_ps_enable_work);
  634. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  635. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  636. /* can only happen when PS was just disabled anyway */
  637. if (!sdata)
  638. return;
  639. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  640. return;
  641. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  642. (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
  643. ieee80211_send_nullfunc(local, sdata, 1);
  644. if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) ||
  645. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  646. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  647. local->hw.conf.flags |= IEEE80211_CONF_PS;
  648. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  649. }
  650. }
  651. void ieee80211_dynamic_ps_timer(unsigned long data)
  652. {
  653. struct ieee80211_local *local = (void *) data;
  654. if (local->quiescing || local->suspended)
  655. return;
  656. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  657. }
  658. /* MLME */
  659. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  660. struct ieee80211_if_managed *ifmgd,
  661. u8 *wmm_param, size_t wmm_param_len)
  662. {
  663. struct ieee80211_tx_queue_params params;
  664. size_t left;
  665. int count;
  666. u8 *pos;
  667. if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
  668. return;
  669. if (!wmm_param)
  670. return;
  671. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  672. return;
  673. count = wmm_param[6] & 0x0f;
  674. if (count == ifmgd->wmm_last_param_set)
  675. return;
  676. ifmgd->wmm_last_param_set = count;
  677. pos = wmm_param + 8;
  678. left = wmm_param_len - 8;
  679. memset(&params, 0, sizeof(params));
  680. local->wmm_acm = 0;
  681. for (; left >= 4; left -= 4, pos += 4) {
  682. int aci = (pos[0] >> 5) & 0x03;
  683. int acm = (pos[0] >> 4) & 0x01;
  684. int queue;
  685. switch (aci) {
  686. case 1: /* AC_BK */
  687. queue = 3;
  688. if (acm)
  689. local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  690. break;
  691. case 2: /* AC_VI */
  692. queue = 1;
  693. if (acm)
  694. local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  695. break;
  696. case 3: /* AC_VO */
  697. queue = 0;
  698. if (acm)
  699. local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  700. break;
  701. case 0: /* AC_BE */
  702. default:
  703. queue = 2;
  704. if (acm)
  705. local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  706. break;
  707. }
  708. params.aifs = pos[0] & 0x0f;
  709. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  710. params.cw_min = ecw2cw(pos[1] & 0x0f);
  711. params.txop = get_unaligned_le16(pos + 2);
  712. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  713. printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
  714. "cWmin=%d cWmax=%d txop=%d\n",
  715. wiphy_name(local->hw.wiphy), queue, aci, acm,
  716. params.aifs, params.cw_min, params.cw_max, params.txop);
  717. #endif
  718. if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
  719. printk(KERN_DEBUG "%s: failed to set TX queue "
  720. "parameters for queue %d\n",
  721. wiphy_name(local->hw.wiphy), queue);
  722. }
  723. }
  724. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  725. u16 capab, bool erp_valid, u8 erp)
  726. {
  727. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  728. u32 changed = 0;
  729. bool use_protection;
  730. bool use_short_preamble;
  731. bool use_short_slot;
  732. if (erp_valid) {
  733. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  734. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  735. } else {
  736. use_protection = false;
  737. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  738. }
  739. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  740. if (use_protection != bss_conf->use_cts_prot) {
  741. bss_conf->use_cts_prot = use_protection;
  742. changed |= BSS_CHANGED_ERP_CTS_PROT;
  743. }
  744. if (use_short_preamble != bss_conf->use_short_preamble) {
  745. bss_conf->use_short_preamble = use_short_preamble;
  746. changed |= BSS_CHANGED_ERP_PREAMBLE;
  747. }
  748. if (use_short_slot != bss_conf->use_short_slot) {
  749. bss_conf->use_short_slot = use_short_slot;
  750. changed |= BSS_CHANGED_ERP_SLOT;
  751. }
  752. return changed;
  753. }
  754. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  755. struct ieee80211_mgd_work *wk,
  756. u32 bss_info_changed)
  757. {
  758. struct ieee80211_local *local = sdata->local;
  759. struct ieee80211_bss *bss = wk->bss;
  760. bss_info_changed |= BSS_CHANGED_ASSOC;
  761. /* set timing information */
  762. sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
  763. sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
  764. sdata->vif.bss_conf.dtim_period = bss->dtim_period;
  765. bss_info_changed |= BSS_CHANGED_BEACON_INT;
  766. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  767. bss->cbss.capability, bss->has_erp_value, bss->erp_value);
  768. sdata->u.mgd.associated = bss;
  769. sdata->u.mgd.old_associate_work = wk;
  770. memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN);
  771. /* just to be sure */
  772. sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  773. IEEE80211_STA_BEACON_POLL);
  774. /*
  775. * Always handle WMM once after association regardless
  776. * of the first value the AP uses. Setting -1 here has
  777. * that effect because the AP values is an unsigned
  778. * 4-bit value.
  779. */
  780. sdata->u.mgd.wmm_last_param_set = -1;
  781. ieee80211_led_assoc(local, 1);
  782. sdata->vif.bss_conf.assoc = 1;
  783. /*
  784. * For now just always ask the driver to update the basic rateset
  785. * when we have associated, we aren't checking whether it actually
  786. * changed or not.
  787. */
  788. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  789. /* And the BSSID changed - we're associated now */
  790. bss_info_changed |= BSS_CHANGED_BSSID;
  791. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  792. mutex_lock(&local->iflist_mtx);
  793. ieee80211_recalc_ps(local, -1);
  794. mutex_unlock(&local->iflist_mtx);
  795. netif_tx_start_all_queues(sdata->dev);
  796. netif_carrier_on(sdata->dev);
  797. }
  798. static enum rx_mgmt_action __must_check
  799. ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
  800. struct ieee80211_mgd_work *wk)
  801. {
  802. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  803. struct ieee80211_local *local = sdata->local;
  804. wk->tries++;
  805. if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
  806. printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
  807. sdata->dev->name, wk->bss->cbss.bssid);
  808. /*
  809. * Most likely AP is not in the range so remove the
  810. * bss struct for that AP.
  811. */
  812. cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
  813. /*
  814. * We might have a pending scan which had no chance to run yet
  815. * due to work needing to be done. Hence, queue the STAs work
  816. * again for that.
  817. */
  818. ieee80211_queue_work(&local->hw, &ifmgd->work);
  819. return RX_MGMT_CFG80211_AUTH_TO;
  820. }
  821. printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n",
  822. sdata->dev->name, wk->bss->cbss.bssid,
  823. wk->tries);
  824. /*
  825. * Direct probe is sent to broadcast address as some APs
  826. * will not answer to direct packet in unassociated state.
  827. */
  828. ieee80211_send_probe_req(sdata, NULL, wk->ssid, wk->ssid_len, NULL, 0);
  829. wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  830. run_again(ifmgd, wk->timeout);
  831. return RX_MGMT_NONE;
  832. }
  833. static enum rx_mgmt_action __must_check
  834. ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
  835. struct ieee80211_mgd_work *wk)
  836. {
  837. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  838. struct ieee80211_local *local = sdata->local;
  839. wk->tries++;
  840. if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
  841. printk(KERN_DEBUG "%s: authentication with AP %pM"
  842. " timed out\n",
  843. sdata->dev->name, wk->bss->cbss.bssid);
  844. /*
  845. * Most likely AP is not in the range so remove the
  846. * bss struct for that AP.
  847. */
  848. cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
  849. /*
  850. * We might have a pending scan which had no chance to run yet
  851. * due to work needing to be done. Hence, queue the STAs work
  852. * again for that.
  853. */
  854. ieee80211_queue_work(&local->hw, &ifmgd->work);
  855. return RX_MGMT_CFG80211_AUTH_TO;
  856. }
  857. printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n",
  858. sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
  859. ieee80211_send_auth(sdata, 1, wk->auth_alg, wk->ie, wk->ie_len,
  860. wk->bss->cbss.bssid, NULL, 0, 0);
  861. wk->auth_transaction = 2;
  862. wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  863. run_again(ifmgd, wk->timeout);
  864. return RX_MGMT_NONE;
  865. }
  866. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  867. bool deauth)
  868. {
  869. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  870. struct ieee80211_local *local = sdata->local;
  871. struct sta_info *sta;
  872. u32 changed = 0, config_changed = 0;
  873. u8 bssid[ETH_ALEN];
  874. ASSERT_MGD_MTX(ifmgd);
  875. if (WARN_ON(!ifmgd->associated))
  876. return;
  877. memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN);
  878. ifmgd->associated = NULL;
  879. memset(ifmgd->bssid, 0, ETH_ALEN);
  880. if (deauth) {
  881. kfree(ifmgd->old_associate_work);
  882. ifmgd->old_associate_work = NULL;
  883. } else {
  884. struct ieee80211_mgd_work *wk = ifmgd->old_associate_work;
  885. wk->state = IEEE80211_MGD_STATE_IDLE;
  886. list_add(&wk->list, &ifmgd->work_list);
  887. }
  888. /*
  889. * we need to commit the associated = NULL change because the
  890. * scan code uses that to determine whether this iface should
  891. * go to/wake up from powersave or not -- and could otherwise
  892. * wake the queues erroneously.
  893. */
  894. smp_mb();
  895. /*
  896. * Thus, we can only afterwards stop the queues -- to account
  897. * for the case where another CPU is finishing a scan at this
  898. * time -- we don't want the scan code to enable queues.
  899. */
  900. netif_tx_stop_all_queues(sdata->dev);
  901. netif_carrier_off(sdata->dev);
  902. rcu_read_lock();
  903. sta = sta_info_get(local, bssid);
  904. if (sta)
  905. ieee80211_sta_tear_down_BA_sessions(sta);
  906. rcu_read_unlock();
  907. changed |= ieee80211_reset_erp_info(sdata);
  908. ieee80211_led_assoc(local, 0);
  909. changed |= BSS_CHANGED_ASSOC;
  910. sdata->vif.bss_conf.assoc = false;
  911. ieee80211_set_wmm_default(sdata);
  912. ieee80211_recalc_idle(local);
  913. /* channel(_type) changes are handled by ieee80211_hw_config */
  914. local->oper_channel_type = NL80211_CHAN_NO_HT;
  915. /* on the next assoc, re-program HT parameters */
  916. sdata->ht_opmode_valid = false;
  917. local->power_constr_level = 0;
  918. del_timer_sync(&local->dynamic_ps_timer);
  919. cancel_work_sync(&local->dynamic_ps_enable_work);
  920. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  921. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  922. config_changed |= IEEE80211_CONF_CHANGE_PS;
  923. }
  924. ieee80211_hw_config(local, config_changed);
  925. /* And the BSSID changed -- not very interesting here */
  926. changed |= BSS_CHANGED_BSSID;
  927. ieee80211_bss_info_change_notify(sdata, changed);
  928. rcu_read_lock();
  929. sta = sta_info_get(local, bssid);
  930. if (!sta) {
  931. rcu_read_unlock();
  932. return;
  933. }
  934. sta_info_unlink(&sta);
  935. rcu_read_unlock();
  936. sta_info_destroy(sta);
  937. }
  938. static enum rx_mgmt_action __must_check
  939. ieee80211_associate(struct ieee80211_sub_if_data *sdata,
  940. struct ieee80211_mgd_work *wk)
  941. {
  942. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  943. struct ieee80211_local *local = sdata->local;
  944. wk->tries++;
  945. if (wk->tries > IEEE80211_ASSOC_MAX_TRIES) {
  946. printk(KERN_DEBUG "%s: association with AP %pM"
  947. " timed out\n",
  948. sdata->dev->name, wk->bss->cbss.bssid);
  949. /*
  950. * Most likely AP is not in the range so remove the
  951. * bss struct for that AP.
  952. */
  953. cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
  954. /*
  955. * We might have a pending scan which had no chance to run yet
  956. * due to work needing to be done. Hence, queue the STAs work
  957. * again for that.
  958. */
  959. ieee80211_queue_work(&local->hw, &ifmgd->work);
  960. return RX_MGMT_CFG80211_ASSOC_TO;
  961. }
  962. printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n",
  963. sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
  964. ieee80211_send_assoc(sdata, wk);
  965. wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
  966. run_again(ifmgd, wk->timeout);
  967. return RX_MGMT_NONE;
  968. }
  969. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  970. struct ieee80211_hdr *hdr)
  971. {
  972. /*
  973. * We can postpone the mgd.timer whenever receiving unicast frames
  974. * from AP because we know that the connection is working both ways
  975. * at that time. But multicast frames (and hence also beacons) must
  976. * be ignored here, because we need to trigger the timer during
  977. * data idle periods for sending the periodic probe request to the
  978. * AP we're connected to.
  979. */
  980. if (is_multicast_ether_addr(hdr->addr1))
  981. return;
  982. mod_timer(&sdata->u.mgd.conn_mon_timer,
  983. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  984. }
  985. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  986. {
  987. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  988. const u8 *ssid;
  989. ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID);
  990. ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid,
  991. ssid + 2, ssid[1], NULL, 0);
  992. ifmgd->probe_send_count++;
  993. ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT;
  994. run_again(ifmgd, ifmgd->probe_timeout);
  995. }
  996. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  997. bool beacon)
  998. {
  999. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1000. bool already = false;
  1001. if (!netif_running(sdata->dev))
  1002. return;
  1003. if (sdata->local->scanning)
  1004. return;
  1005. mutex_lock(&ifmgd->mtx);
  1006. if (!ifmgd->associated)
  1007. goto out;
  1008. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1009. if (beacon && net_ratelimit())
  1010. printk(KERN_DEBUG "%s: detected beacon loss from AP "
  1011. "- sending probe request\n", sdata->dev->name);
  1012. #endif
  1013. /*
  1014. * The driver/our work has already reported this event or the
  1015. * connection monitoring has kicked in and we have already sent
  1016. * a probe request. Or maybe the AP died and the driver keeps
  1017. * reporting until we disassociate...
  1018. *
  1019. * In either case we have to ignore the current call to this
  1020. * function (except for setting the correct probe reason bit)
  1021. * because otherwise we would reset the timer every time and
  1022. * never check whether we received a probe response!
  1023. */
  1024. if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1025. IEEE80211_STA_CONNECTION_POLL))
  1026. already = true;
  1027. if (beacon)
  1028. ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
  1029. else
  1030. ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
  1031. if (already)
  1032. goto out;
  1033. mutex_lock(&sdata->local->iflist_mtx);
  1034. ieee80211_recalc_ps(sdata->local, -1);
  1035. mutex_unlock(&sdata->local->iflist_mtx);
  1036. ifmgd->probe_send_count = 0;
  1037. ieee80211_mgd_probe_ap_send(sdata);
  1038. out:
  1039. mutex_unlock(&ifmgd->mtx);
  1040. }
  1041. void ieee80211_beacon_loss_work(struct work_struct *work)
  1042. {
  1043. struct ieee80211_sub_if_data *sdata =
  1044. container_of(work, struct ieee80211_sub_if_data,
  1045. u.mgd.beacon_loss_work);
  1046. ieee80211_mgd_probe_ap(sdata, true);
  1047. }
  1048. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  1049. {
  1050. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1051. ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.beacon_loss_work);
  1052. }
  1053. EXPORT_SYMBOL(ieee80211_beacon_loss);
  1054. static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
  1055. struct ieee80211_mgd_work *wk)
  1056. {
  1057. wk->state = IEEE80211_MGD_STATE_IDLE;
  1058. printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
  1059. }
  1060. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  1061. struct ieee80211_mgd_work *wk,
  1062. struct ieee80211_mgmt *mgmt,
  1063. size_t len)
  1064. {
  1065. u8 *pos;
  1066. struct ieee802_11_elems elems;
  1067. pos = mgmt->u.auth.variable;
  1068. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1069. if (!elems.challenge)
  1070. return;
  1071. ieee80211_send_auth(sdata, 3, wk->auth_alg,
  1072. elems.challenge - 2, elems.challenge_len + 2,
  1073. wk->bss->cbss.bssid,
  1074. wk->key, wk->key_len, wk->key_idx);
  1075. wk->auth_transaction = 4;
  1076. }
  1077. static enum rx_mgmt_action __must_check
  1078. ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  1079. struct ieee80211_mgd_work *wk,
  1080. struct ieee80211_mgmt *mgmt, size_t len)
  1081. {
  1082. u16 auth_alg, auth_transaction, status_code;
  1083. if (wk->state != IEEE80211_MGD_STATE_AUTH)
  1084. return RX_MGMT_NONE;
  1085. if (len < 24 + 6)
  1086. return RX_MGMT_NONE;
  1087. if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
  1088. return RX_MGMT_NONE;
  1089. if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
  1090. return RX_MGMT_NONE;
  1091. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  1092. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  1093. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  1094. if (auth_alg != wk->auth_alg ||
  1095. auth_transaction != wk->auth_transaction)
  1096. return RX_MGMT_NONE;
  1097. if (status_code != WLAN_STATUS_SUCCESS) {
  1098. list_del(&wk->list);
  1099. kfree(wk);
  1100. return RX_MGMT_CFG80211_AUTH;
  1101. }
  1102. switch (wk->auth_alg) {
  1103. case WLAN_AUTH_OPEN:
  1104. case WLAN_AUTH_LEAP:
  1105. case WLAN_AUTH_FT:
  1106. ieee80211_auth_completed(sdata, wk);
  1107. return RX_MGMT_CFG80211_AUTH;
  1108. case WLAN_AUTH_SHARED_KEY:
  1109. if (wk->auth_transaction == 4) {
  1110. ieee80211_auth_completed(sdata, wk);
  1111. return RX_MGMT_CFG80211_AUTH;
  1112. } else
  1113. ieee80211_auth_challenge(sdata, wk, mgmt, len);
  1114. break;
  1115. }
  1116. return RX_MGMT_NONE;
  1117. }
  1118. static enum rx_mgmt_action __must_check
  1119. ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1120. struct ieee80211_mgd_work *wk,
  1121. struct ieee80211_mgmt *mgmt, size_t len)
  1122. {
  1123. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1124. const u8 *bssid = NULL;
  1125. u16 reason_code;
  1126. if (len < 24 + 2)
  1127. return RX_MGMT_NONE;
  1128. ASSERT_MGD_MTX(ifmgd);
  1129. if (wk)
  1130. bssid = wk->bss->cbss.bssid;
  1131. else
  1132. bssid = ifmgd->associated->cbss.bssid;
  1133. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1134. printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
  1135. sdata->dev->name, bssid, reason_code);
  1136. if (!wk) {
  1137. ieee80211_set_disassoc(sdata, true);
  1138. } else {
  1139. list_del(&wk->list);
  1140. kfree(wk);
  1141. }
  1142. return RX_MGMT_CFG80211_DEAUTH;
  1143. }
  1144. static enum rx_mgmt_action __must_check
  1145. ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1146. struct ieee80211_mgmt *mgmt, size_t len)
  1147. {
  1148. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1149. u16 reason_code;
  1150. if (len < 24 + 2)
  1151. return RX_MGMT_NONE;
  1152. ASSERT_MGD_MTX(ifmgd);
  1153. if (WARN_ON(!ifmgd->associated))
  1154. return RX_MGMT_NONE;
  1155. if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN)))
  1156. return RX_MGMT_NONE;
  1157. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1158. printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
  1159. sdata->dev->name, mgmt->sa, reason_code);
  1160. ieee80211_set_disassoc(sdata, false);
  1161. return RX_MGMT_CFG80211_DISASSOC;
  1162. }
  1163. static enum rx_mgmt_action __must_check
  1164. ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  1165. struct ieee80211_mgd_work *wk,
  1166. struct ieee80211_mgmt *mgmt, size_t len,
  1167. bool reassoc)
  1168. {
  1169. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1170. struct ieee80211_local *local = sdata->local;
  1171. struct ieee80211_supported_band *sband;
  1172. struct sta_info *sta;
  1173. u32 rates, basic_rates;
  1174. u16 capab_info, status_code, aid;
  1175. struct ieee802_11_elems elems;
  1176. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1177. u8 *pos;
  1178. u32 changed = 0;
  1179. int i, j;
  1180. bool have_higher_than_11mbit = false, newsta = false;
  1181. u16 ap_ht_cap_flags;
  1182. /*
  1183. * AssocResp and ReassocResp have identical structure, so process both
  1184. * of them in this function.
  1185. */
  1186. if (len < 24 + 6)
  1187. return RX_MGMT_NONE;
  1188. if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
  1189. return RX_MGMT_NONE;
  1190. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1191. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  1192. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1193. printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
  1194. "status=%d aid=%d)\n",
  1195. sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
  1196. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  1197. pos = mgmt->u.assoc_resp.variable;
  1198. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1199. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  1200. elems.timeout_int && elems.timeout_int_len == 5 &&
  1201. elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  1202. u32 tu, ms;
  1203. tu = get_unaligned_le32(elems.timeout_int + 1);
  1204. ms = tu * 1024 / 1000;
  1205. printk(KERN_DEBUG "%s: AP rejected association temporarily; "
  1206. "comeback duration %u TU (%u ms)\n",
  1207. sdata->dev->name, tu, ms);
  1208. wk->timeout = jiffies + msecs_to_jiffies(ms);
  1209. if (ms > IEEE80211_ASSOC_TIMEOUT)
  1210. run_again(ifmgd, jiffies + msecs_to_jiffies(ms));
  1211. return RX_MGMT_NONE;
  1212. }
  1213. if (status_code != WLAN_STATUS_SUCCESS) {
  1214. printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
  1215. sdata->dev->name, status_code);
  1216. wk->state = IEEE80211_MGD_STATE_IDLE;
  1217. return RX_MGMT_CFG80211_ASSOC;
  1218. }
  1219. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1220. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1221. "set\n", sdata->dev->name, aid);
  1222. aid &= ~(BIT(15) | BIT(14));
  1223. if (!elems.supp_rates) {
  1224. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1225. sdata->dev->name);
  1226. return RX_MGMT_NONE;
  1227. }
  1228. printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
  1229. ifmgd->aid = aid;
  1230. rcu_read_lock();
  1231. /* Add STA entry for the AP */
  1232. sta = sta_info_get(local, wk->bss->cbss.bssid);
  1233. if (!sta) {
  1234. newsta = true;
  1235. rcu_read_unlock();
  1236. sta = sta_info_alloc(sdata, wk->bss->cbss.bssid, GFP_KERNEL);
  1237. if (!sta) {
  1238. printk(KERN_DEBUG "%s: failed to alloc STA entry for"
  1239. " the AP\n", sdata->dev->name);
  1240. return RX_MGMT_NONE;
  1241. }
  1242. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
  1243. WLAN_STA_ASSOC_AP);
  1244. if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  1245. set_sta_flags(sta, WLAN_STA_AUTHORIZED);
  1246. rcu_read_lock();
  1247. }
  1248. rates = 0;
  1249. basic_rates = 0;
  1250. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1251. for (i = 0; i < elems.supp_rates_len; i++) {
  1252. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1253. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1254. if (rate > 110)
  1255. have_higher_than_11mbit = true;
  1256. for (j = 0; j < sband->n_bitrates; j++) {
  1257. if (sband->bitrates[j].bitrate == rate) {
  1258. rates |= BIT(j);
  1259. if (is_basic)
  1260. basic_rates |= BIT(j);
  1261. break;
  1262. }
  1263. }
  1264. }
  1265. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1266. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1267. bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
  1268. if (rate > 110)
  1269. have_higher_than_11mbit = true;
  1270. for (j = 0; j < sband->n_bitrates; j++) {
  1271. if (sband->bitrates[j].bitrate == rate) {
  1272. rates |= BIT(j);
  1273. if (is_basic)
  1274. basic_rates |= BIT(j);
  1275. break;
  1276. }
  1277. }
  1278. }
  1279. sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
  1280. sdata->vif.bss_conf.basic_rates = basic_rates;
  1281. /* cf. IEEE 802.11 9.2.12 */
  1282. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  1283. have_higher_than_11mbit)
  1284. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1285. else
  1286. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1287. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1288. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1289. elems.ht_cap_elem, &sta->sta.ht_cap);
  1290. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1291. rate_control_rate_init(sta);
  1292. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  1293. set_sta_flags(sta, WLAN_STA_MFP);
  1294. if (elems.wmm_param)
  1295. set_sta_flags(sta, WLAN_STA_WME);
  1296. if (newsta) {
  1297. int err = sta_info_insert(sta);
  1298. if (err) {
  1299. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1300. " the AP (error %d)\n", sdata->dev->name, err);
  1301. rcu_read_unlock();
  1302. return RX_MGMT_NONE;
  1303. }
  1304. }
  1305. rcu_read_unlock();
  1306. if (elems.wmm_param)
  1307. ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
  1308. elems.wmm_param_len);
  1309. else
  1310. ieee80211_set_wmm_default(sdata);
  1311. if (elems.ht_info_elem && elems.wmm_param &&
  1312. (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
  1313. !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
  1314. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1315. wk->bss->cbss.bssid,
  1316. ap_ht_cap_flags);
  1317. /* delete work item -- must be before set_associated for PS */
  1318. list_del(&wk->list);
  1319. /* set AID and assoc capability,
  1320. * ieee80211_set_associated() will tell the driver */
  1321. bss_conf->aid = aid;
  1322. bss_conf->assoc_capability = capab_info;
  1323. /* this will take ownership of wk */
  1324. ieee80211_set_associated(sdata, wk, changed);
  1325. /*
  1326. * Start timer to probe the connection to the AP now.
  1327. * Also start the timer that will detect beacon loss.
  1328. */
  1329. ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
  1330. mod_beacon_timer(sdata);
  1331. return RX_MGMT_CFG80211_ASSOC;
  1332. }
  1333. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1334. struct ieee80211_mgmt *mgmt,
  1335. size_t len,
  1336. struct ieee80211_rx_status *rx_status,
  1337. struct ieee802_11_elems *elems,
  1338. bool beacon)
  1339. {
  1340. struct ieee80211_local *local = sdata->local;
  1341. int freq;
  1342. struct ieee80211_bss *bss;
  1343. struct ieee80211_channel *channel;
  1344. if (elems->ds_params && elems->ds_params_len == 1)
  1345. freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
  1346. else
  1347. freq = rx_status->freq;
  1348. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1349. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1350. return;
  1351. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1352. channel, beacon);
  1353. if (bss)
  1354. ieee80211_rx_bss_put(local, bss);
  1355. if (!sdata->u.mgd.associated)
  1356. return;
  1357. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1358. (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid,
  1359. ETH_ALEN) == 0)) {
  1360. struct ieee80211_channel_sw_ie *sw_elem =
  1361. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1362. ieee80211_sta_process_chanswitch(sdata, sw_elem, bss);
  1363. }
  1364. }
  1365. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1366. struct ieee80211_mgd_work *wk,
  1367. struct ieee80211_mgmt *mgmt, size_t len,
  1368. struct ieee80211_rx_status *rx_status)
  1369. {
  1370. struct ieee80211_if_managed *ifmgd;
  1371. size_t baselen;
  1372. struct ieee802_11_elems elems;
  1373. ifmgd = &sdata->u.mgd;
  1374. ASSERT_MGD_MTX(ifmgd);
  1375. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  1376. return; /* ignore ProbeResp to foreign address */
  1377. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1378. if (baselen > len)
  1379. return;
  1380. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1381. &elems);
  1382. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1383. /* direct probe may be part of the association flow */
  1384. if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) {
  1385. printk(KERN_DEBUG "%s: direct probe responded\n",
  1386. sdata->dev->name);
  1387. wk->tries = 0;
  1388. wk->state = IEEE80211_MGD_STATE_AUTH;
  1389. WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE);
  1390. }
  1391. if (ifmgd->associated &&
  1392. memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 &&
  1393. ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
  1394. IEEE80211_STA_CONNECTION_POLL)) {
  1395. ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
  1396. IEEE80211_STA_BEACON_POLL);
  1397. mutex_lock(&sdata->local->iflist_mtx);
  1398. ieee80211_recalc_ps(sdata->local, -1);
  1399. mutex_unlock(&sdata->local->iflist_mtx);
  1400. /*
  1401. * We've received a probe response, but are not sure whether
  1402. * we have or will be receiving any beacons or data, so let's
  1403. * schedule the timers again, just in case.
  1404. */
  1405. mod_beacon_timer(sdata);
  1406. mod_timer(&ifmgd->conn_mon_timer,
  1407. round_jiffies_up(jiffies +
  1408. IEEE80211_CONNECTION_IDLE_TIME));
  1409. }
  1410. }
  1411. /*
  1412. * This is the canonical list of information elements we care about,
  1413. * the filter code also gives us all changes to the Microsoft OUI
  1414. * (00:50:F2) vendor IE which is used for WMM which we need to track.
  1415. *
  1416. * We implement beacon filtering in software since that means we can
  1417. * avoid processing the frame here and in cfg80211, and userspace
  1418. * will not be able to tell whether the hardware supports it or not.
  1419. *
  1420. * XXX: This list needs to be dynamic -- userspace needs to be able to
  1421. * add items it requires. It also needs to be able to tell us to
  1422. * look out for other vendor IEs.
  1423. */
  1424. static const u64 care_about_ies =
  1425. (1ULL << WLAN_EID_COUNTRY) |
  1426. (1ULL << WLAN_EID_ERP_INFO) |
  1427. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  1428. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  1429. (1ULL << WLAN_EID_HT_CAPABILITY) |
  1430. (1ULL << WLAN_EID_HT_INFORMATION);
  1431. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1432. struct ieee80211_mgmt *mgmt,
  1433. size_t len,
  1434. struct ieee80211_rx_status *rx_status)
  1435. {
  1436. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1437. size_t baselen;
  1438. struct ieee802_11_elems elems;
  1439. struct ieee80211_local *local = sdata->local;
  1440. u32 changed = 0;
  1441. bool erp_valid, directed_tim = false;
  1442. u8 erp_value = 0;
  1443. u32 ncrc;
  1444. u8 *bssid;
  1445. ASSERT_MGD_MTX(ifmgd);
  1446. /* Process beacon from the current BSS */
  1447. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1448. if (baselen > len)
  1449. return;
  1450. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1451. return;
  1452. /*
  1453. * We might have received a number of frames, among them a
  1454. * disassoc frame and a beacon...
  1455. */
  1456. if (!ifmgd->associated)
  1457. return;
  1458. bssid = ifmgd->associated-