1 --- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
2 +++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
3 @@ -203,7 +203,7 @@ static void ar9002_hw_iqcalibrate(struct
6 ath_dbg(common, ATH_DBG_CALIBRATE,
7 - "Orignal: Chn %diq_corr_meas = 0x%08x\n",
8 + "Original: Chn %d iq_corr_meas = 0x%08x\n",
9 i, ah->totalIqCorrMeas[i]);
12 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
13 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
14 @@ -226,7 +226,7 @@ static void ar9003_hw_iqcalibrate(struct
17 ath_dbg(common, ATH_DBG_CALIBRATE,
18 - "Orignal: Chn %diq_corr_meas = 0x%08x\n",
19 + "Original: Chn %d iq_corr_meas = 0x%08x\n",
20 i, ah->totalIqCorrMeas[i]);
23 --- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
24 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
25 @@ -808,7 +808,8 @@ void ath9k_htc_ani_work(struct work_stru
28 /* Verify whether we must check ANI */
29 - if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
30 + if (ah->config.enable_ani &&
31 + (timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
33 common->ani.checkani_timer = timestamp;
35 --- a/drivers/net/wireless/ath/ath9k/hw.c
36 +++ b/drivers/net/wireless/ath/ath9k/hw.c
37 @@ -504,7 +504,7 @@ static int ath9k_hw_post_init(struct ath
41 - if (!AR_SREV_9100(ah) && !AR_SREV_9340(ah)) {
42 + if (ah->config.enable_ani) {
43 ath9k_hw_ani_setup(ah);
44 ath9k_hw_ani_init(ah);
46 @@ -610,6 +610,10 @@ static int __ath9k_hw_init(struct ath_hw
47 if (!AR_SREV_9300_20_OR_LATER(ah))
48 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
50 + /* disable ANI for 9340 */
51 + if (AR_SREV_9340(ah))
52 + ah->config.enable_ani = false;
54 ath9k_hw_init_mode_regs(ah);
56 if (!ah->is_pciexpress)
57 --- a/drivers/net/wireless/ath/ath9k/main.c
58 +++ b/drivers/net/wireless/ath/ath9k/main.c
59 @@ -118,7 +118,7 @@ void ath9k_ps_restore(struct ath_softc *
60 if (--sc->ps_usecount != 0)
64 + if (sc->ps_idle && (sc->ps_flags & PS_WAIT_FOR_TX_ACK))
65 mode = ATH9K_PM_FULL_SLEEP;
66 else if (sc->ps_enabled &&
67 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
68 @@ -332,7 +332,8 @@ static int ath_reset_internal(struct ath
72 - if (fastcc && !ath9k_hw_check_alive(ah))
73 + if (fastcc && (ah->chip_fullsleep ||
74 + !ath9k_hw_check_alive(ah)))
77 if (!ath_prepare_reset(sc, retry_tx, flush))
78 @@ -561,7 +562,6 @@ void ath_ani_calibrate(unsigned long dat
79 /* Long calibration runs independently of short calibration. */
80 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
82 - ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
83 common->ani.longcal_timer = timestamp;
86 @@ -569,8 +569,6 @@ void ath_ani_calibrate(unsigned long dat
87 if (!common->ani.caldone) {
88 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
90 - ath_dbg(common, ATH_DBG_ANI,
91 - "shortcal @%lu\n", jiffies);
92 common->ani.shortcal_timer = timestamp;
93 common->ani.resetcal_timer = timestamp;
95 @@ -584,8 +582,9 @@ void ath_ani_calibrate(unsigned long dat
98 /* Verify whether we must check ANI */
99 - if ((timestamp - common->ani.checkani_timer) >=
100 - ah->config.ani_poll_interval) {
101 + if (sc->sc_ah->config.enable_ani
102 + && (timestamp - common->ani.checkani_timer) >=
103 + ah->config.ani_poll_interval) {
105 common->ani.checkani_timer = timestamp;
107 @@ -605,6 +604,11 @@ void ath_ani_calibrate(unsigned long dat
108 ah->rxchainmask, longcal);
111 + ath_dbg(common, ATH_DBG_ANI,
112 + "Calibration @%lu finished: %s %s %s, caldone: %s\n", jiffies,
113 + longcal ? "long" : "", shortcal ? "short" : "",
114 + aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
116 ath9k_ps_restore(sc);
119 @@ -886,82 +890,6 @@ chip_reset:
123 -static void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
125 - struct ath_hw *ah = sc->sc_ah;
126 - struct ath_common *common = ath9k_hw_common(ah);
127 - struct ieee80211_channel *channel = hw->conf.channel;
130 - ath9k_ps_wakeup(sc);
131 - spin_lock_bh(&sc->sc_pcu_lock);
132 - atomic_set(&ah->intr_ref_cnt, -1);
134 - ath9k_hw_configpcipowersave(ah, false);
137 - ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
139 - r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
142 - "Unable to reset channel (%u MHz), reset status %d\n",
143 - channel->center_freq, r);
146 - ath_complete_reset(sc, true);
149 - ath9k_hw_cfg_output(ah, ah->led_pin,
150 - AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
151 - ath9k_hw_set_gpio(ah, ah->led_pin, 0);
153 - spin_unlock_bh(&sc->sc_pcu_lock);
155 - ath9k_ps_restore(sc);
158 -void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
160 - struct ath_hw *ah = sc->sc_ah;
161 - struct ieee80211_channel *channel = hw->conf.channel;
164 - ath9k_ps_wakeup(sc);
166 - ath_cancel_work(sc);
168 - spin_lock_bh(&sc->sc_pcu_lock);
171 - * Keep the LED on when the radio is disabled
172 - * during idle unassociated state.
174 - if (!sc->ps_idle) {
175 - ath9k_hw_set_gpio(ah, ah->led_pin, 1);
176 - ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
179 - ath_prepare_reset(sc, false, true);
182 - ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
184 - r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
186 - ath_err(ath9k_hw_common(sc->sc_ah),
187 - "Unable to reset channel (%u MHz), reset status %d\n",
188 - channel->center_freq, r);
191 - ath9k_hw_phy_disable(ah);
193 - ath9k_hw_configpcipowersave(ah, true);
195 - spin_unlock_bh(&sc->sc_pcu_lock);
196 - ath9k_ps_restore(sc);
199 static int ath_reset(struct ath_softc *sc, bool retry_tx)
202 @@ -1097,6 +1025,9 @@ static int ath9k_start(struct ieee80211_
203 * and then setup of the interrupt mask.
205 spin_lock_bh(&sc->sc_pcu_lock);
207 + atomic_set(&ah->intr_ref_cnt, -1);
209 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
212 @@ -1138,6 +1069,18 @@ static int ath9k_start(struct ieee80211_
216 + if (ah->led_pin >= 0) {
217 + ath9k_hw_cfg_output(ah, ah->led_pin,
218 + AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
219 + ath9k_hw_set_gpio(ah, ah->led_pin, 0);
223 + * Reset key cache to sane defaults (all entries cleared) instead of
224 + * semi-random values after suspend/resume.
226 + ath9k_cmn_init_crypto(sc->sc_ah);
228 spin_unlock_bh(&sc->sc_pcu_lock);
230 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
231 @@ -1183,6 +1126,13 @@ static void ath9k_tx(struct ieee80211_hw
236 + * Cannot tx while the hardware is in full sleep, it first needs a full
237 + * chip reset to recover from that
239 + if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP))
242 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
244 * We are using PS-Poll and mac80211 can request TX while in
245 @@ -1229,6 +1179,7 @@ static void ath9k_stop(struct ieee80211_
246 struct ath_softc *sc = hw->priv;
247 struct ath_hw *ah = sc->sc_ah;
248 struct ath_common *common = ath9k_hw_common(ah);
251 mutex_lock(&sc->mutex);
253 @@ -1259,35 +1210,45 @@ static void ath9k_stop(struct ieee80211_
254 * before setting the invalid flag. */
255 ath9k_hw_disable_interrupts(ah);
257 - if (!(sc->sc_flags & SC_OP_INVALID)) {
258 - ath_drain_all_txq(sc, false);
260 - ath9k_hw_phy_disable(ah);
262 - sc->rx.rxlink = NULL;
263 + spin_unlock_bh(&sc->sc_pcu_lock);
265 + /* we can now sync irq and kill any running tasklets, since we already
266 + * disabled interrupts and not holding a spin lock */
267 + synchronize_irq(sc->irq);
268 + tasklet_kill(&sc->intr_tq);
269 + tasklet_kill(&sc->bcon_tasklet);
271 + prev_idle = sc->ps_idle;
272 + sc->ps_idle = true;
274 + spin_lock_bh(&sc->sc_pcu_lock);
276 + if (ah->led_pin >= 0) {
277 + ath9k_hw_set_gpio(ah, ah->led_pin, 1);
278 + ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
281 + ath_prepare_reset(sc, false, true);
284 dev_kfree_skb_any(sc->rx.frag);
288 - /* disable HAL and put h/w to sleep */
289 - ath9k_hw_disable(ah);
291 + ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
293 - spin_unlock_bh(&sc->sc_pcu_lock);
294 + ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
295 + ath9k_hw_phy_disable(ah);
297 - /* we can now sync irq and kill any running tasklets, since we already
298 - * disabled interrupts and not holding a spin lock */
299 - synchronize_irq(sc->irq);
300 - tasklet_kill(&sc->intr_tq);
301 - tasklet_kill(&sc->bcon_tasklet);
302 + ath9k_hw_configpcipowersave(ah, true);
304 - ath9k_ps_restore(sc);
305 + spin_unlock_bh(&sc->sc_pcu_lock);
307 - sc->ps_idle = true;
308 - ath_radio_disable(sc, hw);
309 + ath9k_ps_restore(sc);
311 sc->sc_flags |= SC_OP_INVALID;
312 + sc->ps_idle = prev_idle;
314 mutex_unlock(&sc->mutex);
316 @@ -1627,8 +1588,8 @@ static int ath9k_config(struct ieee80211
317 struct ath_hw *ah = sc->sc_ah;
318 struct ath_common *common = ath9k_hw_common(ah);
319 struct ieee80211_conf *conf = &hw->conf;
320 - bool disable_radio = false;
322 + ath9k_ps_wakeup(sc);
323 mutex_lock(&sc->mutex);
326 @@ -1639,13 +1600,8 @@ static int ath9k_config(struct ieee80211
328 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
329 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
330 - if (!sc->ps_idle) {
331 - ath_radio_enable(sc, hw);
332 - ath_dbg(common, ATH_DBG_CONFIG,
333 - "not-idle: enabling radio\n");
335 - disable_radio = true;
338 + ath_cancel_work(sc);
342 @@ -1752,18 +1708,12 @@ static int ath9k_config(struct ieee80211
343 ath_dbg(common, ATH_DBG_CONFIG,
344 "Set power: %d\n", conf->power_level);
345 sc->config.txpowlimit = 2 * conf->power_level;
346 - ath9k_ps_wakeup(sc);
347 ath9k_cmn_update_txpow(ah, sc->curtxpow,
348 sc->config.txpowlimit, &sc->curtxpow);
349 - ath9k_ps_restore(sc);
352 - if (disable_radio) {
353 - ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
354 - ath_radio_disable(sc, hw);
357 mutex_unlock(&sc->mutex);
358 + ath9k_ps_restore(sc);
362 @@ -2331,9 +2281,6 @@ static void ath9k_flush(struct ieee80211
369 for (j = 0; j < timeout; j++) {
372 @@ -2351,21 +2298,22 @@ static void ath9k_flush(struct ieee80211
380 - ath9k_ps_wakeup(sc);
381 - spin_lock_bh(&sc->sc_pcu_lock);
382 - drain_txq = ath_drain_all_txq(sc, false);
383 - spin_unlock_bh(&sc->sc_pcu_lock);
385 + ath9k_ps_wakeup(sc);
386 + spin_lock_bh(&sc->sc_pcu_lock);
387 + drain_txq = ath_drain_all_txq(sc, false);
388 + spin_unlock_bh(&sc->sc_pcu_lock);
391 - ath_reset(sc, false);
393 + ath_reset(sc, false);
395 - ath9k_ps_restore(sc);
396 - ieee80211_wake_queues(hw);
397 + ath9k_ps_restore(sc);
398 + ieee80211_wake_queues(hw);
402 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
403 mutex_unlock(&sc->mutex);
405 --- a/drivers/net/wireless/ath/ath9k/pci.c
406 +++ b/drivers/net/wireless/ath/ath9k/pci.c
407 @@ -307,12 +307,11 @@ static int ath_pci_suspend(struct device
408 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
409 struct ath_softc *sc = hw->priv;
411 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
413 /* The device has to be moved to FULLSLEEP forcibly.
414 * Otherwise the chip never moved to full sleep,
415 * when no interface is up.
417 + ath9k_hw_disable(sc->sc_ah);
418 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
421 @@ -334,22 +333,6 @@ static int ath_pci_resume(struct device
422 if ((val & 0x0000ff00) != 0)
423 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
425 - ath9k_ps_wakeup(sc);
427 - ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
428 - AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
429 - ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
432 - * Reset key cache to sane defaults (all entries cleared) instead of
433 - * semi-random values after suspend/resume.
435 - ath9k_cmn_init_crypto(sc->sc_ah);
436 - ath9k_ps_restore(sc);
438 - sc->ps_idle = true;
439 - ath_radio_disable(sc, hw);
444 --- a/drivers/net/wireless/ath/ath9k/xmit.c
445 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
446 @@ -1954,7 +1954,7 @@ static void ath_tx_complete(struct ath_s
447 skb_pull(skb, padsize);
450 - if (sc->ps_flags & PS_WAIT_FOR_TX_ACK) {
451 + if ((sc->ps_flags & PS_WAIT_FOR_TX_ACK) && !txq->axq_depth) {
452 sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK;
453 ath_dbg(common, ATH_DBG_PS,
454 "Going back to sleep after having received TX status (0x%lx)\n",
455 --- a/include/linux/nl80211.h
456 +++ b/include/linux/nl80211.h
457 @@ -2785,9 +2785,11 @@ enum nl80211_ap_sme_features {
458 * @NL80211_FEATURE_SK_TX_STATUS: This driver supports reflecting back
459 * TX status to the socket error queue when requested with the
461 + * @NL80211_FEATURE_HT_IBSS: This driver supports IBSS with HT datarates.
463 enum nl80211_feature_flags {
464 NL80211_FEATURE_SK_TX_STATUS = 1 << 0,
465 + NL80211_FEATURE_HT_IBSS = 1 << 1,
469 --- a/include/net/cfg80211.h
470 +++ b/include/net/cfg80211.h
471 @@ -1149,6 +1149,7 @@ struct cfg80211_ibss_params {
474 struct ieee80211_channel *channel;
475 + enum nl80211_channel_type channel_type;
479 @@ -3270,6 +3271,16 @@ void cfg80211_report_obss_beacon(struct
480 const u8 *frame, size_t len,
481 int freq, gfp_t gfp);
484 + * cfg80211_can_beacon_sec_chan - test if ht40 on extension channel can be used
485 + * @wiphy: the wiphy
486 + * @chan: main channel
487 + * @channel_type: HT mode
489 +int cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
490 + struct ieee80211_channel *chan,
491 + enum nl80211_channel_type channel_type);
493 /* Logging, debugging and troubleshooting/diagnostic helpers. */
495 /* wiphy_printk helpers, similar to dev_printk */
496 --- a/net/mac80211/agg-rx.c
497 +++ b/net/mac80211/agg-rx.c
498 @@ -185,6 +185,10 @@ static void ieee80211_send_addba_resp(st
499 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
500 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
501 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
502 + else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
503 + memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
504 + else if (sdata->vif.type == NL80211_IFTYPE_WDS)
505 + memcpy(mgmt->bssid, da, ETH_ALEN);
507 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
508 IEEE80211_STYPE_ACTION);
509 --- a/net/mac80211/agg-tx.c
510 +++ b/net/mac80211/agg-tx.c
511 @@ -79,10 +79,13 @@ static void ieee80211_send_addba_request
512 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
513 if (sdata->vif.type == NL80211_IFTYPE_AP ||
514 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
515 - sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
516 + sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
517 + sdata->vif.type == NL80211_IFTYPE_WDS)
518 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
519 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
520 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
521 + else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
522 + memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
524 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
525 IEEE80211_STYPE_ACTION);
526 @@ -437,7 +440,9 @@ int ieee80211_start_tx_ba_session(struct
527 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
528 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
529 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
530 - sdata->vif.type != NL80211_IFTYPE_AP)
531 + sdata->vif.type != NL80211_IFTYPE_AP &&
532 + sdata->vif.type != NL80211_IFTYPE_WDS &&
533 + sdata->vif.type != NL80211_IFTYPE_ADHOC)
536 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
537 @@ -448,6 +453,27 @@ int ieee80211_start_tx_ba_session(struct
542 + * 802.11n-2009 11.5.1.1: If the initiating STA is an HT STA, is a
543 + * member of an IBSS, and has no other existing Block Ack agreement
544 + * with the recipient STA, then the initiating STA shall transmit a
545 + * Probe Request frame to the recipient STA and shall not transmit an
546 + * ADDBA Request frame unless it receives a Probe Response frame
547 + * from the recipient within dot11ADDBAFailureTimeout.
549 + * The probe request mechanism for ADDBA is currently not implemented,
550 + * but we only build up Block Ack session with HT STAs. This information
551 + * is set when we receive a bss info from a probe response or a beacon.
553 + if (sta->sdata->vif.type == NL80211_IFTYPE_ADHOC &&
554 + !sta->sta.ht_cap.ht_supported) {
555 +#ifdef CONFIG_MAC80211_HT_DEBUG
556 + printk(KERN_DEBUG "BA request denied - IBSS STA %pM"
557 + "does not advertise HT support\n", pubsta->addr);
558 +#endif /* CONFIG_MAC80211_HT_DEBUG */
562 spin_lock_bh(&sta->lock);
564 /* we have tried too many times, receiver does not want A-MPDU */
565 --- a/net/mac80211/debugfs_sta.c
566 +++ b/net/mac80211/debugfs_sta.c
567 @@ -63,11 +63,11 @@ static ssize_t sta_flags_read(struct fil
568 test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
570 int res = scnprintf(buf, sizeof(buf),
571 - "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
572 + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
573 TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
574 TEST(PS_DRIVER), TEST(AUTHORIZED),
575 TEST(SHORT_PREAMBLE),
576 - TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
577 + TEST(WME), TEST(CLEAR_PS_FILT),
578 TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
579 TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
580 TEST(TDLS_PEER_AUTH));
581 --- a/net/mac80211/ht.c
582 +++ b/net/mac80211/ht.c
583 @@ -282,6 +282,8 @@ void ieee80211_send_delba(struct ieee802
584 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
585 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
586 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
587 + else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
588 + memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
590 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
591 IEEE80211_STYPE_ACTION);
592 --- a/net/mac80211/ibss.c
593 +++ b/net/mac80211/ibss.c
594 @@ -77,6 +77,7 @@ static void __ieee80211_sta_join_ibss(st
595 struct cfg80211_bss *bss;
597 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
598 + enum nl80211_channel_type channel_type;
600 lockdep_assert_held(&ifibss->mtx);
602 @@ -105,8 +106,16 @@ static void __ieee80211_sta_join_ibss(st
604 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
606 - local->oper_channel = chan;
607 - WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
608 + channel_type = ifibss->channel_type;
609 + if (channel_type > NL80211_CHAN_HT20 &&
610 + !cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
611 + channel_type = NL80211_CHAN_HT20;
612 + if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
613 + /* can only fail due to HT40+/- mismatch */
614 + channel_type = NL80211_CHAN_HT20;
615 + WARN_ON(!ieee80211_set_channel_type(local, sdata,
616 + NL80211_CHAN_HT20));
618 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
620 sband = local->hw.wiphy->bands[chan->band];
621 @@ -172,6 +181,19 @@ static void __ieee80211_sta_join_ibss(st
622 memcpy(skb_put(skb, ifibss->ie_len),
623 ifibss->ie, ifibss->ie_len);
625 + /* add HT capability and information IEs */
626 + if (channel_type && sband->ht_cap.ht_supported) {
627 + pos = skb_put(skb, 4 +
628 + sizeof(struct ieee80211_ht_cap) +
629 + sizeof(struct ieee80211_ht_info));
630 + pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
631 + sband->ht_cap.cap);
632 + pos = ieee80211_ie_build_ht_info(pos,
638 if (local->hw.queues >= 4) {
639 pos = skb_put(skb, 9);
640 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
641 @@ -195,6 +217,7 @@ static void __ieee80211_sta_join_ibss(st
642 bss_change |= BSS_CHANGED_BEACON;
643 bss_change |= BSS_CHANGED_BEACON_ENABLED;
644 bss_change |= BSS_CHANGED_BASIC_RATES;
645 + bss_change |= BSS_CHANGED_HT;
646 bss_change |= BSS_CHANGED_IBSS;
647 sdata->vif.bss_conf.ibss_joined = true;
648 ieee80211_bss_info_change_notify(sdata, bss_change);
649 @@ -268,6 +291,8 @@ static void ieee80211_rx_bss_info(struct
650 u64 beacon_timestamp, rx_timestamp;
652 enum ieee80211_band band = rx_status->band;
653 + struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
654 + bool rates_updated = false;
656 if (elems->ds_params && elems->ds_params_len == 1)
657 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
658 @@ -307,7 +332,7 @@ static void ieee80211_rx_bss_info(struct
660 sta->sta.supp_rates[band]);
662 - rate_control_rate_init(sta);
663 + rates_updated = true;
666 sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid,
667 @@ -318,6 +343,39 @@ static void ieee80211_rx_bss_info(struct
668 if (sta && elems->wmm_info)
669 set_sta_flag(sta, WLAN_STA_WME);
671 + if (sta && elems->ht_info_elem && elems->ht_cap_elem &&
672 + sdata->u.ibss.channel_type != NL80211_CHAN_NO_HT) {
673 + /* we both use HT */
674 + struct ieee80211_sta_ht_cap sta_ht_cap_new;
675 + enum nl80211_channel_type channel_type =
676 + ieee80211_ht_info_to_channel_type(
677 + elems->ht_info_elem);
679 + ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
680 + elems->ht_cap_elem,
684 + * fall back to HT20 if we don't use or use
685 + * the other extension channel
687 + if ((channel_type == NL80211_CHAN_HT40MINUS ||
688 + channel_type == NL80211_CHAN_HT40PLUS) &&
689 + channel_type != sdata->u.ibss.channel_type)
690 + sta_ht_cap_new.cap &=
691 + ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
693 + if (memcmp(&sta->sta.ht_cap, &sta_ht_cap_new,
694 + sizeof(sta_ht_cap_new))) {
695 + memcpy(&sta->sta.ht_cap, &sta_ht_cap_new,
696 + sizeof(sta_ht_cap_new));
697 + rates_updated = true;
701 + if (sta && rates_updated)
702 + rate_control_rate_init(sta);
707 @@ -896,12 +954,18 @@ int ieee80211_ibss_join(struct ieee80211
708 struct cfg80211_ibss_params *params)
713 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
714 - 36 /* bitrates */ +
716 - 3 /* DS params */ +
717 - 4 /* IBSS params */ +
718 + sizeof(struct ieee80211_hdr_3addr) +
719 + 12 /* struct ieee80211_mgmt.u.beacon */ +
720 + 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ +
721 + 2 + 8 /* max Supported Rates */ +
722 + 3 /* max DS params */ +
723 + 4 /* IBSS params */ +
724 + 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
725 + 2 + sizeof(struct ieee80211_ht_cap) +
726 + 2 + sizeof(struct ieee80211_ht_info) +
730 @@ -922,13 +986,15 @@ int ieee80211_ibss_join(struct ieee80211
731 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
733 sdata->u.ibss.channel = params->channel;
734 + sdata->u.ibss.channel_type = params->channel_type;
735 sdata->u.ibss.fixed_channel = params->channel_fixed;
737 /* fix ourselves to that channel now already */
738 if (params->channel_fixed) {
739 sdata->local->oper_channel = params->channel;
740 - WARN_ON(!ieee80211_set_channel_type(sdata->local, sdata,
741 - NL80211_CHAN_NO_HT));
742 + if (!ieee80211_set_channel_type(sdata->local, sdata,
743 + params->channel_type))
748 @@ -951,6 +1017,23 @@ int ieee80211_ibss_join(struct ieee80211
749 ieee80211_recalc_idle(sdata->local);
750 mutex_unlock(&sdata->local->mtx);
753 + * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is
754 + * reserved, but an HT STA shall protect HT transmissions as though
755 + * the HT Protection field were set to non-HT mixed mode.
757 + * In an IBSS, the RIFS Mode field of the HT Operation element is
758 + * also reserved, but an HT STA shall operate as though this field
762 + sdata->vif.bss_conf.ht_operation_mode |=
763 + IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
764 + | IEEE80211_HT_PARAM_RIFS_MODE;
766 + changed |= BSS_CHANGED_HT;
767 + ieee80211_bss_info_change_notify(sdata, changed);
769 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
772 --- a/net/mac80211/ieee80211_i.h
773 +++ b/net/mac80211/ieee80211_i.h
774 @@ -474,6 +474,7 @@ struct ieee80211_if_ibss {
777 struct ieee80211_channel *channel;
778 + enum nl80211_channel_type channel_type;
780 unsigned long ibss_join_req;
781 /* probe response/beacon for IBSS */
782 --- a/net/mac80211/iface.c
783 +++ b/net/mac80211/iface.c
784 @@ -178,7 +178,6 @@ static int ieee80211_do_open(struct net_
786 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
787 struct ieee80211_local *local = sdata->local;
788 - struct sta_info *sta;
791 u32 hw_reconf_flags = 0;
792 @@ -309,27 +308,6 @@ static int ieee80211_do_open(struct net_
794 set_bit(SDATA_STATE_RUNNING, &sdata->state);
796 - if (sdata->vif.type == NL80211_IFTYPE_WDS) {
797 - /* Create STA entry for the WDS peer */
798 - sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
802 - goto err_del_interface;
805 - /* no atomic bitop required since STA is not live yet */
806 - set_sta_flag(sta, WLAN_STA_AUTHORIZED);
808 - res = sta_info_insert(sta);
810 - /* STA has been freed */
811 - goto err_del_interface;
814 - rate_control_rate_init(sta);
818 * set_multicast_list will be invoked by the networking core
819 * which will check whether any increments here were done in
820 @@ -356,8 +334,7 @@ static int ieee80211_do_open(struct net_
821 netif_tx_start_all_queues(dev);
825 - drv_remove_interface(local, sdata);
828 if (!local->open_count)
830 @@ -719,6 +696,70 @@ static void ieee80211_if_setup(struct ne
831 dev->destructor = free_netdev;
834 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
835 + struct sk_buff *skb)
837 + struct ieee80211_local *local = sdata->local;
838 + struct ieee80211_rx_status *rx_status;
839 + struct ieee802_11_elems elems;
840 + struct ieee80211_mgmt *mgmt;
841 + struct sta_info *sta;
846 + enum ieee80211_band band = local->hw.conf.channel->band;
847 + struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
849 + rx_status = IEEE80211_SKB_RXCB(skb);
850 + mgmt = (struct ieee80211_mgmt *) skb->data;
851 + stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
853 + if (stype != IEEE80211_STYPE_BEACON)
856 + baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
857 + if (baselen > skb->len)
860 + ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
861 + skb->len - baselen, &elems);
863 + rates = ieee80211_sta_get_rates(local, &elems, band);
867 + sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
871 + sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
879 + sta->last_rx = jiffies;
880 + sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
882 + if (elems.ht_cap_elem)
883 + ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
884 + elems.ht_cap_elem, &sta->sta.ht_cap);
886 + if (elems.wmm_param)
887 + set_sta_flag(sta, WLAN_STA_WME);
890 + set_sta_flag(sta, WLAN_STA_AUTHORIZED);
891 + rate_control_rate_init(sta);
892 + sta_info_insert_rcu(sta);
898 static void ieee80211_iface_work(struct work_struct *work)
900 struct ieee80211_sub_if_data *sdata =
901 @@ -823,6 +864,9 @@ static void ieee80211_iface_work(struct
903 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
905 + case NL80211_IFTYPE_WDS:
906 + ieee80211_wds_rx_queued_mgmt(sdata, skb);
909 WARN(1, "frame for unexpected interface type");
911 --- a/net/mac80211/main.c
912 +++ b/net/mac80211/main.c
913 @@ -574,7 +574,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(
914 WIPHY_FLAG_OFFCHAN_TX |
915 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
917 - wiphy->features = NL80211_FEATURE_SK_TX_STATUS;
918 + wiphy->features = NL80211_FEATURE_SK_TX_STATUS |
919 + NL80211_FEATURE_HT_IBSS;
922 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
923 --- a/net/mac80211/rx.c
924 +++ b/net/mac80211/rx.c
925 @@ -2237,7 +2237,9 @@ ieee80211_rx_h_action(struct ieee80211_r
926 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
927 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
928 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
929 - sdata->vif.type != NL80211_IFTYPE_AP)
930 + sdata->vif.type != NL80211_IFTYPE_AP &&
931 + sdata->vif.type != NL80211_IFTYPE_WDS &&
932 + sdata->vif.type != NL80211_IFTYPE_ADHOC)
935 /* verify action_code is present */
936 @@ -2452,13 +2454,14 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
938 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
939 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
940 - sdata->vif.type != NL80211_IFTYPE_STATION)
941 + sdata->vif.type != NL80211_IFTYPE_STATION &&
942 + sdata->vif.type != NL80211_IFTYPE_WDS)
943 return RX_DROP_MONITOR;
946 case cpu_to_le16(IEEE80211_STYPE_BEACON):
947 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
948 - /* process for all: mesh, mlme, ibss */
949 + /* process for all: mesh, mlme, ibss, wds */
951 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
952 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
953 @@ -2805,10 +2808,16 @@ static int prepare_for_handlers(struct i
956 case NL80211_IFTYPE_WDS:
957 - if (bssid || !ieee80211_is_data(hdr->frame_control))
959 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
962 + if (ieee80211_is_data(hdr->frame_control) ||
963 + ieee80211_is_action(hdr->frame_control)) {
964 + if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
966 + } else if (!ieee80211_is_beacon(hdr->frame_control))
971 /* should never get here */
972 --- a/net/mac80211/sta_info.h
973 +++ b/net/mac80211/sta_info.h
975 * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
977 * @WLAN_STA_WME: Station is a QoS-STA.
978 - * @WLAN_STA_WDS: Station is one of our WDS peers.
979 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
980 * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
981 * frame to this station is transmitted.
982 @@ -60,7 +59,6 @@ enum ieee80211_sta_info_flags {
984 WLAN_STA_SHORT_PREAMBLE,
987 WLAN_STA_CLEAR_PS_FILT,
990 --- a/net/mac80211/util.c
991 +++ b/net/mac80211/util.c
992 @@ -1612,6 +1612,11 @@ u8 *ieee80211_ie_build_ht_info(u8 *pos,
994 if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
995 ht_info->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
998 + * Note: According to 802.11n-2009 9.13.3.1, HT Protection field and
999 + * RIFS Mode are reserved in IBSS mode, therefore keep them at 0
1001 ht_info->operation_mode = 0x0000;
1002 ht_info->stbc_param = 0x0000;
1004 --- a/net/wireless/chan.c
1005 +++ b/net/wireless/chan.c
1007 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
1010 +#include <linux/export.h>
1011 #include <net/cfg80211.h>
1014 @@ -44,9 +45,9 @@ rdev_freq_to_chan(struct cfg80211_regist
1018 -static bool can_beacon_sec_chan(struct wiphy *wiphy,
1019 - struct ieee80211_channel *chan,
1020 - enum nl80211_channel_type channel_type)
1021 +int cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
1022 + struct ieee80211_channel *chan,
1023 + enum nl80211_channel_type channel_type)
1025 struct ieee80211_channel *sec_chan;
1027 @@ -75,6 +76,7 @@ static bool can_beacon_sec_chan(struct w
1031 +EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
1033 int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
1034 struct wireless_dev *wdev, int freq,
1035 @@ -109,8 +111,8 @@ int cfg80211_set_freq(struct cfg80211_re
1036 switch (channel_type) {
1037 case NL80211_CHAN_HT40PLUS:
1038 case NL80211_CHAN_HT40MINUS:
1039 - if (!can_beacon_sec_chan(&rdev->wiphy, chan,
1041 + if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, chan,
1044 "cfg80211: Secondary channel not "
1045 "allowed to initiate communication\n");
1046 --- a/net/wireless/nl80211.c
1047 +++ b/net/wireless/nl80211.c
1048 @@ -4684,13 +4684,41 @@ static int nl80211_join_ibss(struct sk_b
1049 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
1052 - ibss.channel = ieee80211_get_channel(wiphy,
1053 - nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
1054 + if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1055 + enum nl80211_channel_type channel_type;
1057 + channel_type = nla_get_u32(
1058 + info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1059 + if (channel_type != NL80211_CHAN_NO_HT &&
1060 + channel_type != NL80211_CHAN_HT20 &&
1061 + channel_type != NL80211_CHAN_HT40MINUS &&
1062 + channel_type != NL80211_CHAN_HT40PLUS)
1065 + if (channel_type != NL80211_CHAN_NO_HT &&
1066 + !(wiphy->features & NL80211_FEATURE_HT_IBSS))
1069 + ibss.channel_type = channel_type;
1071 + ibss.channel_type = NL80211_CHAN_NO_HT;
1074 + ibss.channel = rdev_freq_to_chan(rdev,
1075 + nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
1076 + ibss.channel_type);
1077 if (!ibss.channel ||
1078 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
1079 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
1082 + /* Both channels should be able to initiate communication */
1083 + if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
1084 + ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
1085 + !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
1086 + ibss.channel_type))
1089 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
1090 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];