44935791319287035389246b3fd86a02e87f1621
[openwrt.git] / package / mac80211 / patches / 300-pending_work.patch
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
4                         i);
5  
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]);
10  
11                 iqCorrNeg = 0;
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
15                         i);
16  
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]);
21  
22                 iqCorrNeg = 0;
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
26         }
27  
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) {
32                 aniflag = true;
33                 common->ani.checkani_timer = timestamp;
34         }
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
38                 return ecode;
39         }
40  
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);
45         }
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;
49  
50 +       /* disable ANI for 9340 */
51 +       if (AR_SREV_9340(ah))
52 +               ah->config.enable_ani = false;
53 +
54         ath9k_hw_init_mode_regs(ah);
55  
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)
61                 goto unlock;
62  
63 -       if (sc->ps_idle)
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
69                 hchan = ah->curchan;
70         }
71  
72 -       if (fastcc && !ath9k_hw_check_alive(ah))
73 +       if (fastcc && (ah->chip_fullsleep ||
74 +           !ath9k_hw_check_alive(ah)))
75                 fastcc = false;
76  
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) {
81                 longcal = true;
82 -               ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
83                 common->ani.longcal_timer = timestamp;
84         }
85  
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) {
89                         shortcal = true;
90 -                       ath_dbg(common, ATH_DBG_ANI,
91 -                               "shortcal @%lu\n", jiffies);
92                         common->ani.shortcal_timer = timestamp;
93                         common->ani.resetcal_timer = timestamp;
94                 }
95 @@ -584,8 +582,9 @@ void ath_ani_calibrate(unsigned long dat
96         }
97  
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) {
104                 aniflag = true;
105                 common->ani.checkani_timer = timestamp;
106         }
107 @@ -605,6 +604,11 @@ void ath_ani_calibrate(unsigned long dat
108                                                 ah->rxchainmask, longcal);
109         }
110  
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");
115 +
116         ath9k_ps_restore(sc);
117  
118  set_timer:
119 @@ -886,82 +890,6 @@ chip_reset:
120  #undef SCHED_INTR
121  }
122  
123 -static void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
124 -{
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;
128 -       int r;
129 -
130 -       ath9k_ps_wakeup(sc);
131 -       spin_lock_bh(&sc->sc_pcu_lock);
132 -       atomic_set(&ah->intr_ref_cnt, -1);
133 -
134 -       ath9k_hw_configpcipowersave(ah, false);
135 -
136 -       if (!ah->curchan)
137 -               ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
138 -
139 -       r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
140 -       if (r) {
141 -               ath_err(common,
142 -                       "Unable to reset channel (%u MHz), reset status %d\n",
143 -                       channel->center_freq, r);
144 -       }
145 -
146 -       ath_complete_reset(sc, true);
147 -
148 -       /* Enable LED */
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);
152 -
153 -       spin_unlock_bh(&sc->sc_pcu_lock);
154 -
155 -       ath9k_ps_restore(sc);
156 -}
157 -
158 -void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
159 -{
160 -       struct ath_hw *ah = sc->sc_ah;
161 -       struct ieee80211_channel *channel = hw->conf.channel;
162 -       int r;
163 -
164 -       ath9k_ps_wakeup(sc);
165 -
166 -       ath_cancel_work(sc);
167 -
168 -       spin_lock_bh(&sc->sc_pcu_lock);
169 -
170 -       /*
171 -        * Keep the LED on when the radio is disabled
172 -        * during idle unassociated state.
173 -        */
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);
177 -       }
178 -
179 -       ath_prepare_reset(sc, false, true);
180 -
181 -       if (!ah->curchan)
182 -               ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
183 -
184 -       r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
185 -       if (r) {
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);
189 -       }
190 -
191 -       ath9k_hw_phy_disable(ah);
192 -
193 -       ath9k_hw_configpcipowersave(ah, true);
194 -
195 -       spin_unlock_bh(&sc->sc_pcu_lock);
196 -       ath9k_ps_restore(sc);
197 -}
198 -
199  static int ath_reset(struct ath_softc *sc, bool retry_tx)
200  {
201         int r;
202 @@ -1097,6 +1025,9 @@ static int ath9k_start(struct ieee80211_
203          * and then setup of the interrupt mask.
204          */
205         spin_lock_bh(&sc->sc_pcu_lock);
206 +
207 +       atomic_set(&ah->intr_ref_cnt, -1);
208 +
209         r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
210         if (r) {
211                 ath_err(common,
212 @@ -1138,6 +1069,18 @@ static int ath9k_start(struct ieee80211_
213                 goto mutex_unlock;
214         }
215  
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);
220 +       }
221 +
222 +       /*
223 +        * Reset key cache to sane defaults (all entries cleared) instead of
224 +        * semi-random values after suspend/resume.
225 +        */
226 +       ath9k_cmn_init_crypto(sc->sc_ah);
227 +
228         spin_unlock_bh(&sc->sc_pcu_lock);
229  
230         if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
231 @@ -1183,6 +1126,13 @@ static void ath9k_tx(struct ieee80211_hw
232                 }
233         }
234  
235 +       /*
236 +        * Cannot tx while the hardware is in full sleep, it first needs a full
237 +        * chip reset to recover from that
238 +        */
239 +       if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP))
240 +               goto exit;
241 +
242         if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
243                 /*
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);
249 +       bool prev_idle;
250  
251         mutex_lock(&sc->mutex);
252  
253 @@ -1259,35 +1210,45 @@ static void ath9k_stop(struct ieee80211_
254          * before setting the invalid flag. */
255         ath9k_hw_disable_interrupts(ah);
256  
257 -       if (!(sc->sc_flags & SC_OP_INVALID)) {
258 -               ath_drain_all_txq(sc, false);
259 -               ath_stoprecv(sc);
260 -               ath9k_hw_phy_disable(ah);
261 -       } else
262 -               sc->rx.rxlink = NULL;
263 +       spin_unlock_bh(&sc->sc_pcu_lock);
264 +
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);
270 +
271 +       prev_idle = sc->ps_idle;
272 +       sc->ps_idle = true;
273 +
274 +       spin_lock_bh(&sc->sc_pcu_lock);
275 +
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);
279 +       }
280 +
281 +       ath_prepare_reset(sc, false, true);
282  
283         if (sc->rx.frag) {
284                 dev_kfree_skb_any(sc->rx.frag);
285                 sc->rx.frag = NULL;
286         }
287  
288 -       /* disable HAL and put h/w to sleep */
289 -       ath9k_hw_disable(ah);
290 +       if (!ah->curchan)
291 +               ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
292  
293 -       spin_unlock_bh(&sc->sc_pcu_lock);
294 +       ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
295 +       ath9k_hw_phy_disable(ah);
296  
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);
303  
304 -       ath9k_ps_restore(sc);
305 +       spin_unlock_bh(&sc->sc_pcu_lock);
306  
307 -       sc->ps_idle = true;
308 -       ath_radio_disable(sc, hw);
309 +       ath9k_ps_restore(sc);
310  
311         sc->sc_flags |= SC_OP_INVALID;
312 +       sc->ps_idle = prev_idle;
313  
314         mutex_unlock(&sc->mutex);
315  
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;
321  
322 +       ath9k_ps_wakeup(sc);
323         mutex_lock(&sc->mutex);
324  
325         /*
326 @@ -1639,13 +1600,8 @@ static int ath9k_config(struct ieee80211
327          */
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");
334 -               } else {
335 -                       disable_radio = true;
336 -               }
337 +               if (sc->ps_idle)
338 +                       ath_cancel_work(sc);
339         }
340  
341         /*
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);
350 -       }
351 -
352 -       if (disable_radio) {
353 -               ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
354 -               ath_radio_disable(sc, hw);
355         }
356  
357         mutex_unlock(&sc->mutex);
358 +       ath9k_ps_restore(sc);
359  
360         return 0;
361  }
362 @@ -2331,9 +2281,6 @@ static void ath9k_flush(struct ieee80211
363                 return;
364         }
365  
366 -       if (drop)
367 -               timeout = 1;
368 -
369         for (j = 0; j < timeout; j++) {
370                 bool npend = false;
371  
372 @@ -2351,21 +2298,22 @@ static void ath9k_flush(struct ieee80211
373                 }
374  
375                 if (!npend)
376 -                   goto out;
377 +                   break;
378         }
379  
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);
384 +       if (drop) {
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);
389  
390 -       if (!drain_txq)
391 -               ath_reset(sc, false);
392 +               if (!drain_txq)
393 +                       ath_reset(sc, false);
394  
395 -       ath9k_ps_restore(sc);
396 -       ieee80211_wake_queues(hw);
397 +               ath9k_ps_restore(sc);
398 +               ieee80211_wake_queues(hw);
399 +       }
400  
401 -out:
402         ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
403         mutex_unlock(&sc->mutex);
404  }
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;
410  
411 -       ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
412 -
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.
416          */
417 +       ath9k_hw_disable(sc->sc_ah);
418         ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
419  
420         return 0;
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);
424  
425 -       ath9k_ps_wakeup(sc);
426 -       /* Enable LED */
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);
430 -
431 -         /*
432 -          * Reset key cache to sane defaults (all entries cleared) instead of
433 -          * semi-random values after suspend/resume.
434 -          */
435 -       ath9k_cmn_init_crypto(sc->sc_ah);
436 -       ath9k_ps_restore(sc);
437 -
438 -       sc->ps_idle = true;
439 -       ath_radio_disable(sc, hw);
440 -
441         return 0;
442  }
443  
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);
448         }
449  
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
460   *     socket option.
461 + * @NL80211_FEATURE_HT_IBSS: This driver supports IBSS with HT datarates.
462   */
463  enum nl80211_feature_flags {
464         NL80211_FEATURE_SK_TX_STATUS    = 1 << 0,
465 +       NL80211_FEATURE_HT_IBSS         = 1 << 1,
466  };
467  
468  /**
469 --- a/include/net/cfg80211.h
470 +++ b/include/net/cfg80211.h
471 @@ -1149,6 +1149,7 @@ struct cfg80211_ibss_params {
472         u8 *ssid;
473         u8 *bssid;
474         struct ieee80211_channel *channel;
475 +       enum nl80211_channel_type channel_type;
476         u8 *ie;
477         u8 ssid_len, ie_len;
478         u16 beacon_interval;
479 @@ -3270,6 +3271,16 @@ void cfg80211_report_obss_beacon(struct 
480                                  const u8 *frame, size_t len,
481                                  int freq, gfp_t gfp);
482  
483 +/*
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
488 + */
489 +int cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
490 +                                struct ieee80211_channel *chan,
491 +                                enum nl80211_channel_type channel_type);
492 +
493  /* Logging, debugging and troubleshooting/diagnostic helpers. */
494  
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);
506  
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);
523  
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)
534                 return -EINVAL;
535  
536         if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
537 @@ -448,6 +453,27 @@ int ieee80211_start_tx_ba_session(struct
538                 return -EINVAL;
539         }
540  
541 +       /*
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.
548 +        *
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.
552 +        */
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 */
559 +               return -EINVAL;
560 +       }
561 +
562         spin_lock_bh(&sta->lock);
563  
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" : ""
569  
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);
589  
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;
596         u32 bss_change;
597         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
598 +       enum nl80211_channel_type channel_type;
599  
600         lockdep_assert_held(&ifibss->mtx);
601  
602 @@ -105,8 +106,16 @@ static void __ieee80211_sta_join_ibss(st
603  
604         sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
605  
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));
617 +       }
618         ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
619  
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);
624  
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,
633 +                                                &sband->ht_cap,
634 +                                                chan,
635 +                                                channel_type);
636 +       }
637 +
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;
651         u32 supp_rates = 0;
652         enum ieee80211_band band = rx_status->band;
653 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
654 +       bool rates_updated = false;
655  
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
659                                                 prev_rates,
660                                                 sta->sta.supp_rates[band]);
661  #endif
662 -                                       rate_control_rate_init(sta);
663 +                                       rates_updated = true;
664                                 }
665                         } else
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);
670  
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);
678 +
679 +                       ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
680 +                                                         elems->ht_cap_elem,
681 +                                                         &sta_ht_cap_new);
682 +
683 +                       /*
684 +                        * fall back to HT20 if we don't use or use
685 +                        * the other extension channel
686 +                        */
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;
692 +
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;
698 +                       }
699 +               }
700 +
701 +               if (sta && rates_updated)
702 +                       rate_control_rate_init(sta);
703 +
704                 rcu_read_unlock();
705         }
706  
707 @@ -896,12 +954,18 @@ int ieee80211_ibss_join(struct ieee80211
708                         struct cfg80211_ibss_params *params)
709  {
710         struct sk_buff *skb;
711 +       u32 changed = 0;
712  
713         skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
714 -                           36 /* bitrates */ +
715 -                           34 /* SSID */ +
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) +
727                             params->ie_len);
728         if (!skb)
729                 return -ENOMEM;
730 @@ -922,13 +986,15 @@ int ieee80211_ibss_join(struct ieee80211
731         sdata->vif.bss_conf.beacon_int = params->beacon_interval;
732  
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;
736  
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))
744 +                       return -EINVAL;
745         }
746  
747         if (params->ie) {
748 @@ -951,6 +1017,23 @@ int ieee80211_ibss_join(struct ieee80211
749         ieee80211_recalc_idle(sdata->local);
750         mutex_unlock(&sdata->local->mtx);
751  
752 +       /*
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.
756 +        *
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
759 +        * were set to 1.
760 +        */
761 +
762 +       sdata->vif.bss_conf.ht_operation_mode |=
763 +                 IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
764 +               | IEEE80211_HT_PARAM_RIFS_MODE;
765 +
766 +       changed |= BSS_CHANGED_HT;
767 +       ieee80211_bss_info_change_notify(sdata, changed);
768 +
769         ieee80211_queue_work(&sdata->local->hw, &sdata->work);
770  
771         return 0;
772 --- a/net/mac80211/ieee80211_i.h
773 +++ b/net/mac80211/ieee80211_i.h
774 @@ -474,6 +474,7 @@ struct ieee80211_if_ibss {
775         u8 ssid_len, ie_len;
776         u8 *ie;
777         struct ieee80211_channel *channel;
778 +       enum nl80211_channel_type channel_type;
779  
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_
785  {
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;
789         u32 changed = 0;
790         int res;
791         u32 hw_reconf_flags = 0;
792 @@ -309,27 +308,6 @@ static int ieee80211_do_open(struct net_
793  
794         set_bit(SDATA_STATE_RUNNING, &sdata->state);
795  
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,
799 -                                    GFP_KERNEL);
800 -               if (!sta) {
801 -                       res = -ENOMEM;
802 -                       goto err_del_interface;
803 -               }
804 -
805 -               /* no atomic bitop required since STA is not live yet */
806 -               set_sta_flag(sta, WLAN_STA_AUTHORIZED);
807 -
808 -               res = sta_info_insert(sta);
809 -               if (res) {
810 -                       /* STA has been freed */
811 -                       goto err_del_interface;
812 -               }
813 -
814 -               rate_control_rate_init(sta);
815 -       }
816 -
817         /*
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);
822  
823         return 0;
824 - err_del_interface:
825 -       drv_remove_interface(local, sdata);
826 +
827   err_stop:
828         if (!local->open_count)
829                 drv_stop(local);
830 @@ -719,6 +696,70 @@ static void ieee80211_if_setup(struct ne
831         dev->destructor = free_netdev;
832  }
833  
834 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
835 +                                        struct sk_buff *skb)
836 +{
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;
842 +       size_t baselen;
843 +       u32 rates = 0;
844 +       u16 stype;
845 +       bool new = false;
846 +       enum ieee80211_band band = local->hw.conf.channel->band;
847 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
848 +
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;
852 +
853 +       if (stype != IEEE80211_STYPE_BEACON)
854 +               return;
855 +
856 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
857 +       if (baselen > skb->len)
858 +               return;
859 +
860 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
861 +                              skb->len - baselen, &elems);
862 +
863 +       rates = ieee80211_sta_get_rates(local, &elems, band);
864 +
865 +       rcu_read_lock();
866 +
867 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
868 +
869 +       if (!sta) {
870 +               rcu_read_unlock();
871 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
872 +                                    GFP_KERNEL);
873 +               if (!sta)
874 +                       return;
875 +
876 +               new = true;
877 +       }
878 +
879 +       sta->last_rx = jiffies;
880 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
881 +
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);
885 +
886 +       if (elems.wmm_param)
887 +               set_sta_flag(sta, WLAN_STA_WME);
888 +
889 +       if (new) {
890 +               set_sta_flag(sta, WLAN_STA_AUTHORIZED);
891 +               rate_control_rate_init(sta);
892 +               sta_info_insert_rcu(sta);
893 +       }
894 +
895 +       rcu_read_unlock();
896 +}
897 +
898  static void ieee80211_iface_work(struct work_struct *work)
899  {
900         struct ieee80211_sub_if_data *sdata =
901 @@ -823,6 +864,9 @@ static void ieee80211_iface_work(struct 
902                                 break;
903                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
904                         break;
905 +               case NL80211_IFTYPE_WDS:
906 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
907 +                       break;
908                 default:
909                         WARN(1, "frame for unexpected interface type");
910                         break;
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;
916  
917 -       wiphy->features = NL80211_FEATURE_SK_TX_STATUS;
918 +       wiphy->features = NL80211_FEATURE_SK_TX_STATUS |
919 +                         NL80211_FEATURE_HT_IBSS;
920  
921         if (!ops->set_key)
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)
933                         break;
934  
935                 /* verify action_code is present */
936 @@ -2452,13 +2454,14 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
937  
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;
944  
945         switch (stype) {
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 */
950                 break;
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
954                 }
955                 break;
956         case NL80211_IFTYPE_WDS:
957 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
958 -                       return 0;
959                 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
960                         return 0;
961 +
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))
965 +                               return 0;
966 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
967 +                       return 0;
968 +
969                 break;
970         default:
971                 /* should never get here */
972 --- a/net/mac80211/sta_info.h
973 +++ b/net/mac80211/sta_info.h
974 @@ -31,7 +31,6 @@
975   * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
976   *     frames.
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 {
983         WLAN_STA_AUTHORIZED,
984         WLAN_STA_SHORT_PREAMBLE,
985         WLAN_STA_WME,
986 -       WLAN_STA_WDS,
987         WLAN_STA_CLEAR_PS_FILT,
988         WLAN_STA_MFP,
989         WLAN_STA_BLOCK_BA,
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,
993         }
994         if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
995                 ht_info->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
996 +
997 +       /*
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
1000 +        */
1001         ht_info->operation_mode = 0x0000;
1002         ht_info->stbc_param = 0x0000;
1003  
1004 --- a/net/wireless/chan.c
1005 +++ b/net/wireless/chan.c
1006 @@ -6,6 +6,7 @@
1007   * Copyright 2009      Johannes Berg <johannes@sipsolutions.net>
1008   */
1009  
1010 +#include <linux/export.h>
1011  #include <net/cfg80211.h>
1012  #include "core.h"
1013  
1014 @@ -44,9 +45,9 @@ rdev_freq_to_chan(struct cfg80211_regist
1015         return chan;
1016  }
1017  
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)
1024  {
1025         struct ieee80211_channel *sec_chan;
1026         int diff;
1027 @@ -75,6 +76,7 @@ static bool can_beacon_sec_chan(struct w
1028  
1029         return true;
1030  }
1031 +EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
1032  
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,
1040 -                                                channel_type)) {
1041 +                       if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, chan,
1042 +                                                         channel_type)) {
1043                                 printk(KERN_DEBUG
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]);
1050         }
1051  
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;
1056 +
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)
1063 +                       return -EINVAL;
1064 +
1065 +               if (channel_type != NL80211_CHAN_NO_HT &&
1066 +                   !(wiphy->features & NL80211_FEATURE_HT_IBSS))
1067 +                       return -EINVAL;
1068 +
1069 +               ibss.channel_type = channel_type;
1070 +       } else {
1071 +               ibss.channel_type = NL80211_CHAN_NO_HT;
1072 +       }
1073 +
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)
1080                 return -EINVAL;
1081  
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))
1087 +               return -EINVAL;
1088 +
1089         ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
1090         ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
1091