mac80211: update to wireless-testing 2011-11-01
[openwrt.git] / package / mac80211 / patches / 300-pending_work.patch
1 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
2 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
3 @@ -908,12 +908,15 @@ static bool ar9003_hw_rtt_restore(struct
4         int i;
5         bool restore;
6  
7 -       if (!(ah->caps.hw_caps & ATH9K_HW_CAP_RTT) || !ah->caldata)
8 +       if (!ah->caldata)
9                 return false;
10  
11         hist = &ah->caldata->rtt_hist;
12 +       if (!hist->num_readings)
13 +               return false;
14 +
15         ar9003_hw_rtt_enable(ah);
16 -       ar9003_hw_rtt_set_mask(ah, 0x10);
17 +       ar9003_hw_rtt_set_mask(ah, 0x00);
18         for (i = 0; i < AR9300_MAX_CHAINS; i++) {
19                 if (!(ah->rxchainmask & (1 << i)))
20                         continue;
21 @@ -1070,6 +1073,7 @@ skip_tx_iqcal:
22                 if (is_reusable && (hist->num_readings < RTT_HIST_MAX)) {
23                         u32 *table;
24  
25 +                       hist->num_readings++;
26                         for (i = 0; i < AR9300_MAX_CHAINS; i++) {
27                                 if (!(ah->rxchainmask & (1 << i)))
28                                         continue;
29 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
30 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
31 @@ -572,14 +572,14 @@
32  
33  #define AR_PHY_TXGAIN_TABLE      (AR_SM_BASE + 0x300)
34  
35 -#define AR_PHY_TX_IQCAL_CONTROL_0   (AR_SM_BASE + AR_SREV_9485(ah) ? \
36 -                                                0x3c4 : 0x444)
37 -#define AR_PHY_TX_IQCAL_CONTROL_1   (AR_SM_BASE + AR_SREV_9485(ah) ? \
38 -                                                0x3c8 : 0x448)
39 -#define AR_PHY_TX_IQCAL_START       (AR_SM_BASE + AR_SREV_9485(ah) ? \
40 -                                                0x3c4 : 0x440)
41 -#define AR_PHY_TX_IQCAL_STATUS_B0   (AR_SM_BASE + AR_SREV_9485(ah) ? \
42 -                                                0x3f0 : 0x48c)
43 +#define AR_PHY_TX_IQCAL_CONTROL_0   (AR_SM_BASE + (AR_SREV_9485(ah) ? \
44 +                                                0x3c4 : 0x444))
45 +#define AR_PHY_TX_IQCAL_CONTROL_1   (AR_SM_BASE + (AR_SREV_9485(ah) ? \
46 +                                                0x3c8 : 0x448))
47 +#define AR_PHY_TX_IQCAL_START       (AR_SM_BASE + (AR_SREV_9485(ah) ? \
48 +                                                0x3c4 : 0x440))
49 +#define AR_PHY_TX_IQCAL_STATUS_B0   (AR_SM_BASE + (AR_SREV_9485(ah) ? \
50 +                                                0x3f0 : 0x48c))
51  #define AR_PHY_TX_IQCAL_CORR_COEFF_B0(_i)    (AR_SM_BASE + \
52                                              (AR_SREV_9485(ah) ? \
53                                               0x3d0 : 0x450) + ((_i) << 2))
54 @@ -931,10 +931,10 @@
55  #define AR_PHY_AIC_SRAM_ADDR_B1        (AR_SM1_BASE + 0x5f0)
56  #define AR_PHY_AIC_SRAM_DATA_B1        (AR_SM1_BASE + 0x5f4)
57  
58 -#define AR_PHY_RTT_TABLE_SW_INTF_B(i)  (0x384 + (i) ? \
59 -                                       AR_SM1_BASE : AR_SM_BASE)
60 -#define AR_PHY_RTT_TABLE_SW_INTF_1_B(i)        (0x388 + (i) ? \
61 -                                       AR_SM1_BASE : AR_SM_BASE)
62 +#define AR_PHY_RTT_TABLE_SW_INTF_B(i)  (0x384 + ((i) ? \
63 +                                       AR_SM1_BASE : AR_SM_BASE))
64 +#define AR_PHY_RTT_TABLE_SW_INTF_1_B(i)        (0x388 + ((i) ? \
65 +                                       AR_SM1_BASE : AR_SM_BASE))
66  /*
67   * Channel 2 Register Map
68   */
69 --- a/include/net/cfg80211.h
70 +++ b/include/net/cfg80211.h
71 @@ -1122,6 +1122,7 @@ struct cfg80211_ibss_params {
72         u8 *ssid;
73         u8 *bssid;
74         struct ieee80211_channel *channel;
75 +       enum nl80211_channel_type channel_type;
76         u8 *ie;
77         u8 ssid_len, ie_len;
78         u16 beacon_interval;
79 @@ -3188,6 +3189,16 @@ void cfg80211_gtk_rekey_notify(struct ne
80  void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
81                                      const u8 *bssid, bool preauth, gfp_t gfp);
82  
83 +/**
84 + * cfg80211_can_use_ext_chan - test if ht40 on extension channel can be used
85 + * @wiphy: the wiphy
86 + * @chan: main channel
87 + * @channel_type: HT mode
88 + */
89 +bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
90 +                                 struct ieee80211_channel *chan,
91 +                                 enum nl80211_channel_type channel_type);
92 +
93  /* Logging, debugging and troubleshooting/diagnostic helpers. */
94  
95  /* wiphy_printk helpers, similar to dev_printk */
96 --- a/net/mac80211/agg-rx.c
97 +++ b/net/mac80211/agg-rx.c
98 @@ -180,6 +180,10 @@ static void ieee80211_send_addba_resp(st
99                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
100         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
101                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
102 +       else if (sdata->vif.type == NL80211_IFTYPE_WDS)
103 +               memcpy(mgmt->bssid, da, ETH_ALEN);
104 +       else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
105 +               memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
106  
107         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
108                                           IEEE80211_STYPE_ACTION);
109 --- a/net/mac80211/agg-tx.c
110 +++ b/net/mac80211/agg-tx.c
111 @@ -77,10 +77,13 @@ static void ieee80211_send_addba_request
112         memcpy(mgmt->da, da, ETH_ALEN);
113         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
114         if (sdata->vif.type == NL80211_IFTYPE_AP ||
115 -           sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
116 +           sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
117 +           sdata->vif.type == NL80211_IFTYPE_WDS)
118                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
119         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
120                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
121 +       else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
122 +               memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
123  
124         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
125                                           IEEE80211_STYPE_ACTION);
126 @@ -397,7 +400,9 @@ int ieee80211_start_tx_ba_session(struct
127          */
128         if (sdata->vif.type != NL80211_IFTYPE_STATION &&
129             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
130 -           sdata->vif.type != NL80211_IFTYPE_AP)
131 +           sdata->vif.type != NL80211_IFTYPE_AP &&
132 +           sdata->vif.type != NL80211_IFTYPE_ADHOC &&
133 +           sdata->vif.type != NL80211_IFTYPE_WDS)
134                 return -EINVAL;
135  
136         if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
137 --- a/net/mac80211/debugfs_sta.c
138 +++ b/net/mac80211/debugfs_sta.c
139 @@ -63,11 +63,11 @@ static ssize_t sta_flags_read(struct fil
140         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
141  
142         int res = scnprintf(buf, sizeof(buf),
143 -                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
144 +                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
145                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
146                             TEST(PS_DRIVER), TEST(AUTHORIZED),
147                             TEST(SHORT_PREAMBLE), TEST(ASSOC_AP),
148 -                           TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
149 +                           TEST(WME), TEST(CLEAR_PS_FILT),
150                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
151                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
152                             TEST(TDLS_PEER_AUTH));
153 --- a/net/mac80211/ht.c
154 +++ b/net/mac80211/ht.c
155 @@ -199,6 +199,8 @@ void ieee80211_send_delba(struct ieee802
156                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
157         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
158                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
159 +       else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
160 +               memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
161  
162         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
163                                           IEEE80211_STYPE_ACTION);
164 --- a/net/mac80211/ibss.c
165 +++ b/net/mac80211/ibss.c
166 @@ -77,6 +77,7 @@ static void __ieee80211_sta_join_ibss(st
167         struct cfg80211_bss *bss;
168         u32 bss_change;
169         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
170 +       enum nl80211_channel_type channel_type;
171  
172         lockdep_assert_held(&ifibss->mtx);
173  
174 @@ -104,8 +105,16 @@ static void __ieee80211_sta_join_ibss(st
175  
176         sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
177  
178 -       local->oper_channel = chan;
179 -       WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
180 +       channel_type = ifibss->channel_type;
181 +       if (channel_type > NL80211_CHAN_HT20 &&
182 +           !cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
183 +               channel_type = NL80211_CHAN_HT20;
184 +       if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
185 +               /* can only fail due to HT40+/- mismatch */
186 +               channel_type = NL80211_CHAN_HT20;
187 +               WARN_ON(!ieee80211_set_channel_type(local, sdata,
188 +                                                   NL80211_CHAN_HT20));
189 +       }
190         ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
191  
192         sband = local->hw.wiphy->bands[chan->band];
193 @@ -171,6 +180,18 @@ static void __ieee80211_sta_join_ibss(st
194                 memcpy(skb_put(skb, ifibss->ie_len),
195                        ifibss->ie, ifibss->ie_len);
196  
197 +       /* add HT capability and information IEs */
198 +       if (channel_type && sband->ht_cap.ht_supported) {
199 +               pos = skb_put(skb, 4 +
200 +                                  sizeof(struct ieee80211_ht_cap) +
201 +                                  sizeof(struct ieee80211_ht_info));
202 +               pos = ieee80211_ie_build_ht_cap(pos, sband, sband->ht_cap.cap);
203 +               pos = ieee80211_ie_build_ht_info(pos,
204 +                                                &sband->ht_cap,
205 +                                                chan,
206 +                                                channel_type);
207 +       }
208 +
209         if (local->hw.queues >= 4) {
210                 pos = skb_put(skb, 9);
211                 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
212 @@ -194,6 +215,7 @@ static void __ieee80211_sta_join_ibss(st
213         bss_change |= BSS_CHANGED_BEACON;
214         bss_change |= BSS_CHANGED_BEACON_ENABLED;
215         bss_change |= BSS_CHANGED_BASIC_RATES;
216 +       bss_change |= BSS_CHANGED_HT;
217         bss_change |= BSS_CHANGED_IBSS;
218         sdata->vif.bss_conf.ibss_joined = true;
219         ieee80211_bss_info_change_notify(sdata, bss_change);
220 @@ -266,6 +288,7 @@ static void ieee80211_rx_bss_info(struct
221         u64 beacon_timestamp, rx_timestamp;
222         u32 supp_rates = 0;
223         enum ieee80211_band band = rx_status->band;
224 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
225  
226         if (elems->ds_params && elems->ds_params_len == 1)
227                 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
228 @@ -275,7 +298,10 @@ static void ieee80211_rx_bss_info(struct
229  
230         channel = ieee80211_get_channel(local->hw.wiphy, freq);
231  
232 -       if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
233 +       if (!channel ||
234 +           channel->flags & (IEEE80211_CHAN_DISABLED ||
235 +                             IEEE80211_CHAN_NO_IBSS ||
236 +                             IEEE80211_CHAN_RADAR))
237                 return;
238  
239         if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
240 @@ -313,8 +339,41 @@ static void ieee80211_rx_bss_info(struct
241                                                 GFP_ATOMIC);
242                 }
243  
244 -               if (sta && elems->wmm_info)
245 -                       set_sta_flag(sta, WLAN_STA_WME);
246 +               if (sta) {
247 +                       if (elems->wmm_info)
248 +                               set_sta_flag(sta, WLAN_STA_WME);
249 +
250 +                       /* we both use HT */
251 +                       if (elems->ht_info_elem && elems->ht_cap_elem &&
252 +                           sdata->u.ibss.channel_type) {
253 +                               enum nl80211_channel_type channel_type =
254 +                                       ieee80211_ht_info_to_channel_type(
255 +                                                          elems->ht_info_elem);
256 +                               struct ieee80211_sta_ht_cap sta_ht_cap_new;
257 +
258 +                               /*
259 +                                * fall back to HT20 if we don't use or use
260 +                                * the other extension channel
261 +                                */
262 +                               if (channel_type > NL80211_CHAN_HT20 &&
263 +                                   channel_type != sdata->u.ibss.channel_type)
264 +                                       channel_type = NL80211_CHAN_HT20;
265 +
266 +                               ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
267 +                                               elems->ht_cap_elem,
268 +                                               &sta_ht_cap_new);
269 +                               if (memcmp(&sta->sta.ht_cap, &sta_ht_cap_new,
270 +                                          sizeof(sta_ht_cap_new))) {
271 +                                       memcpy(&sta->sta.ht_cap,
272 +                                              &sta_ht_cap_new,
273 +                                              sizeof(sta_ht_cap_new));
274 +                                       rate_control_rate_update(local, sband,
275 +                                                       sta,
276 +                                                       IEEE80211_RC_HT_CHANGED,
277 +                                                       channel_type);
278 +                               }
279 +                       }
280 +               }
281  
282                 rcu_read_unlock();
283         }
284 @@ -896,10 +955,15 @@ int ieee80211_ibss_join(struct ieee80211
285         struct sk_buff *skb;
286  
287         skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
288 -                           36 /* bitrates */ +
289 -                           34 /* SSID */ +
290 -                           3  /* DS params */ +
291 -                           4  /* IBSS params */ +
292 +                           sizeof(struct ieee80211_hdr_3addr) +
293 +                           12 /* struct ieee80211_mgmt.u.beacon */ +
294 +                           2 + IEEE80211_MAX_SSID_LEN /* max SSID */ +
295 +                           2 + 8 /* max Supported Rates */ +
296 +                           3 /* max DS params */ +
297 +                           4 /* IBSS params */ +
298 +                           2 + (IEEE80211_MAX_SUPP_RATES - 8) +
299 +                           2 + sizeof(struct ieee80211_ht_cap) +
300 +                           2 + sizeof(struct ieee80211_ht_info) +
301                             params->ie_len);
302         if (!skb)
303                 return -ENOMEM;
304 @@ -920,13 +984,15 @@ int ieee80211_ibss_join(struct ieee80211
305         sdata->vif.bss_conf.beacon_int = params->beacon_interval;
306  
307         sdata->u.ibss.channel = params->channel;
308 +       sdata->u.ibss.channel_type = params->channel_type;
309         sdata->u.ibss.fixed_channel = params->channel_fixed;
310  
311         /* fix ourselves to that channel now already */
312         if (params->channel_fixed) {
313                 sdata->local->oper_channel = params->channel;
314 -               WARN_ON(!ieee80211_set_channel_type(sdata->local, sdata,
315 -                                                   NL80211_CHAN_NO_HT));
316 +               if (!ieee80211_set_channel_type(sdata->local, sdata,
317 +                                              params->channel_type))
318 +                       return -EINVAL;
319         }
320  
321         if (params->ie) {
322 --- a/net/mac80211/ieee80211_i.h
323 +++ b/net/mac80211/ieee80211_i.h
324 @@ -464,6 +464,7 @@ struct ieee80211_if_ibss {
325         u8 ssid_len, ie_len;
326         u8 *ie;
327         struct ieee80211_channel *channel;
328 +       enum nl80211_channel_type channel_type;
329  
330         unsigned long ibss_join_req;
331         /* probe response/beacon for IBSS */
332 @@ -1338,6 +1339,12 @@ void ieee80211_recalc_smps(struct ieee80
333  size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
334                           const u8 *ids, int n_ids, size_t offset);
335  size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset);
336 +u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_supported_band *sband,
337 +                             u16 cap);
338 +u8 *ieee80211_ie_build_ht_info(u8 *pos,
339 +                               struct ieee80211_sta_ht_cap *ht_cap,
340 +                               struct ieee80211_channel *channel,
341 +                               enum nl80211_channel_type channel_type);
342  
343  /* internal work items */
344  void ieee80211_work_init(struct ieee80211_local *local);
345 @@ -1366,6 +1373,8 @@ ieee80211_get_channel_mode(struct ieee80
346  bool ieee80211_set_channel_type(struct ieee80211_local *local,
347                                 struct ieee80211_sub_if_data *sdata,
348                                 enum nl80211_channel_type chantype);
349 +enum nl80211_channel_type
350 +ieee80211_ht_info_to_channel_type(struct ieee80211_ht_info *ht_info);
351  
352  #ifdef CONFIG_MAC80211_NOINLINE
353  #define debug_noinline noinline
354 --- a/net/mac80211/iface.c
355 +++ b/net/mac80211/iface.c
356 @@ -178,7 +178,6 @@ static int ieee80211_do_open(struct net_
357  {
358         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
359         struct ieee80211_local *local = sdata->local;
360 -       struct sta_info *sta;
361         u32 changed = 0;
362         int res;
363         u32 hw_reconf_flags = 0;
364 @@ -290,27 +289,6 @@ static int ieee80211_do_open(struct net_
365  
366         set_bit(SDATA_STATE_RUNNING, &sdata->state);
367  
368 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
369 -               /* Create STA entry for the WDS peer */
370 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
371 -                                    GFP_KERNEL);
372 -               if (!sta) {
373 -                       res = -ENOMEM;
374 -                       goto err_del_interface;
375 -               }
376 -
377 -               /* no atomic bitop required since STA is not live yet */
378 -               set_sta_flag(sta, WLAN_STA_AUTHORIZED);
379 -
380 -               res = sta_info_insert(sta);
381 -               if (res) {
382 -                       /* STA has been freed */
383 -                       goto err_del_interface;
384 -               }
385 -
386 -               rate_control_rate_init(sta);
387 -       }
388 -
389         /*
390          * set_multicast_list will be invoked by the networking core
391          * which will check whether any increments here were done in
392 @@ -344,8 +322,7 @@ static int ieee80211_do_open(struct net_
393         netif_tx_start_all_queues(dev);
394  
395         return 0;
396 - err_del_interface:
397 -       drv_remove_interface(local, &sdata->vif);
398 +
399   err_stop:
400         if (!local->open_count)
401                 drv_stop(local);
402 @@ -716,6 +693,70 @@ static void ieee80211_if_setup(struct ne
403         dev->destructor = free_netdev;
404  }
405  
406 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
407 +                                        struct sk_buff *skb)
408 +{
409 +       struct ieee80211_local *local = sdata->local;
410 +       struct ieee80211_rx_status *rx_status;
411 +       struct ieee802_11_elems elems;
412 +       struct ieee80211_mgmt *mgmt;
413 +       struct sta_info *sta;
414 +       size_t baselen;
415 +       u32 rates = 0;
416 +       u16 stype;
417 +       bool new = false;
418 +       enum ieee80211_band band = local->hw.conf.channel->band;
419 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
420 +
421 +       rx_status = IEEE80211_SKB_RXCB(skb);
422 +       mgmt = (struct ieee80211_mgmt *) skb->data;
423 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
424 +
425 +       if (stype != IEEE80211_STYPE_BEACON)
426 +               return;
427 +
428 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
429 +       if (baselen > skb->len)
430 +               return;
431 +
432 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
433 +                              skb->len - baselen, &elems);
434 +
435 +       rates = ieee80211_sta_get_rates(local, &elems, band);
436 +
437 +       rcu_read_lock();
438 +
439 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
440 +
441 +       if (!sta) {
442 +               rcu_read_unlock();
443 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
444 +                                    GFP_KERNEL);
445 +               if (!sta)
446 +                       return;
447 +
448 +               new = true;
449 +       }
450 +
451 +       sta->last_rx = jiffies;
452 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
453 +
454 +       if (elems.ht_cap_elem)
455 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
456 +                               elems.ht_cap_elem, &sta->sta.ht_cap);
457 +
458 +       if (elems.wmm_param)
459 +               set_sta_flag(sta, WLAN_STA_WME);
460 +
461 +       if (new) {
462 +               set_sta_flag(sta, WLAN_STA_AUTHORIZED);
463 +               rate_control_rate_init(sta);
464 +               sta_info_insert_rcu(sta);
465 +       }
466 +
467 +       rcu_read_unlock();
468 +}
469 +
470  static void ieee80211_iface_work(struct work_struct *work)
471  {
472         struct ieee80211_sub_if_data *sdata =
473 @@ -820,6 +861,9 @@ static void ieee80211_iface_work(struct 
474                                 break;
475                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
476                         break;
477 +               case NL80211_IFTYPE_WDS:
478 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
479 +                       break;
480                 default:
481                         WARN(1, "frame for unexpected interface type");
482                         break;
483 --- a/net/mac80211/rx.c
484 +++ b/net/mac80211/rx.c
485 @@ -2211,7 +2211,9 @@ ieee80211_rx_h_action(struct ieee80211_r
486                  */
487                 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
488                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
489 -                   sdata->vif.type != NL80211_IFTYPE_AP)
490 +                   sdata->vif.type != NL80211_IFTYPE_AP &&
491 +                   sdata->vif.type != NL80211_IFTYPE_ADHOC &&
492 +                   sdata->vif.type != NL80211_IFTYPE_WDS)
493                         break;
494  
495                 /* verify action_code is present */
496 @@ -2426,13 +2428,14 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
497  
498         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
499             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
500 -           sdata->vif.type != NL80211_IFTYPE_STATION)
501 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
502 +           sdata->vif.type != NL80211_IFTYPE_WDS)
503                 return RX_DROP_MONITOR;
504  
505         switch (stype) {
506         case cpu_to_le16(IEEE80211_STYPE_BEACON):
507         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
508 -               /* process for all: mesh, mlme, ibss */
509 +               /* process for all: mesh, mlme, ibss, wds */
510                 break;
511         case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
512         case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
513 @@ -2775,10 +2778,16 @@ static int prepare_for_handlers(struct i
514                 }
515                 break;
516         case NL80211_IFTYPE_WDS:
517 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
518 -                       return 0;
519                 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
520                         return 0;
521 +
522 +               if (ieee80211_is_data(hdr->frame_control) ||
523 +                   ieee80211_is_action(hdr->frame_control)) {
524 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
525 +                               return 0;
526 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
527 +                       return 0;
528 +
529                 break;
530         default:
531                 /* should never get here */
532 --- a/net/mac80211/sta_info.h
533 +++ b/net/mac80211/sta_info.h
534 @@ -32,7 +32,6 @@
535   *     frames.
536   * @WLAN_STA_ASSOC_AP: We're associated to that station, it is an AP.
537   * @WLAN_STA_WME: Station is a QoS-STA.
538 - * @WLAN_STA_WDS: Station is one of our WDS peers.
539   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
540   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
541   *     frame to this station is transmitted.
542 @@ -61,7 +60,6 @@ enum ieee80211_sta_info_flags {
543         WLAN_STA_SHORT_PREAMBLE,
544         WLAN_STA_ASSOC_AP,
545         WLAN_STA_WME,
546 -       WLAN_STA_WDS,
547         WLAN_STA_CLEAR_PS_FILT,
548         WLAN_STA_MFP,
549         WLAN_STA_BLOCK_BA,
550 --- a/net/mac80211/util.c
551 +++ b/net/mac80211/util.c
552 @@ -836,23 +836,8 @@ int ieee80211_build_preq_ies(struct ieee
553                 offset = noffset;
554         }
555  
556 -       if (sband->ht_cap.ht_supported) {
557 -               u16 cap = sband->ht_cap.cap;
558 -               __le16 tmp;
559 -
560 -               *pos++ = WLAN_EID_HT_CAPABILITY;
561 -               *pos++ = sizeof(struct ieee80211_ht_cap);
562 -               memset(pos, 0, sizeof(struct ieee80211_ht_cap));
563 -               tmp = cpu_to_le16(cap);
564 -               memcpy(pos, &tmp, sizeof(u16));
565 -               pos += sizeof(u16);
566 -               *pos++ = sband->ht_cap.ampdu_factor |
567 -                        (sband->ht_cap.ampdu_density <<
568 -                               IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
569 -               memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
570 -               pos += sizeof(sband->ht_cap.mcs);
571 -               pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
572 -       }
573 +       if (sband->ht_cap.ht_supported)
574 +               pos = ieee80211_ie_build_ht_cap(pos, sband, sband->ht_cap.cap);
575  
576         /*
577          * If adding more here, adjust code in main.c
578 @@ -1443,3 +1428,100 @@ int ieee80211_add_ext_srates_ie(struct i
579         }
580         return 0;
581  }
582 +
583 +u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_supported_band *sband,
584 +                             u16 cap)
585 +{
586 +       __le16 tmp;
587 +
588 +       *pos++ = WLAN_EID_HT_CAPABILITY;
589 +       *pos++ = sizeof(struct ieee80211_ht_cap);
590 +       memset(pos, 0, sizeof(struct ieee80211_ht_cap));
591 +
592 +       /* capability flags */
593 +       tmp = cpu_to_le16(cap);
594 +       memcpy(pos, &tmp, sizeof(u16));
595 +       pos += sizeof(u16);
596 +
597 +       /* AMPDU parameters */
598 +       *pos++ = sband->ht_cap.ampdu_factor |
599 +                (sband->ht_cap.ampdu_density <<
600 +                       IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
601 +
602 +       /* MCS set */
603 +       memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
604 +       pos += sizeof(sband->ht_cap.mcs);
605 +
606 +       /* extended capabilities */
607 +       pos += sizeof(__le16);
608 +
609 +       /* BF capabilities */
610 +       pos += sizeof(__le32);
611 +
612 +       /* antenna selection */
613 +       pos += sizeof(u8);
614 +
615 +       return pos;
616 +}
617 +
618 +u8 *ieee80211_ie_build_ht_info(u8 *pos,
619 +                              struct ieee80211_sta_ht_cap *ht_cap,
620 +                              struct ieee80211_channel *channel,
621 +                              enum nl80211_channel_type channel_type)
622 +{
623 +       struct ieee80211_ht_info *ht_info;
624 +       /* Build HT Information */
625 +       *pos++ = WLAN_EID_HT_INFORMATION;
626 +       *pos++ = sizeof(struct ieee80211_ht_info);
627 +       ht_info = (struct ieee80211_ht_info *)pos;
628 +       ht_info->control_chan =
629 +                       ieee80211_frequency_to_channel(channel->center_freq);
630 +       switch (channel_type) {
631 +       case NL80211_CHAN_HT40MINUS:
632 +               ht_info->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
633 +               break;
634 +       case NL80211_CHAN_HT40PLUS:
635 +               ht_info->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
636 +               break;
637 +       case NL80211_CHAN_HT20:
638 +       default:
639 +               ht_info->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
640 +               break;
641 +       }
642 +       if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
643 +               ht_info->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
644 +       ht_info->operation_mode = 0x0000;
645 +       ht_info->stbc_param = 0x0000;
646 +
647 +       /* It seems that Basic MCS set and Supported MCS set
648 +          are identical for the first 10 bytes */
649 +       memset(&ht_info->basic_set, 0, 16);
650 +       memcpy(&ht_info->basic_set, &ht_cap->mcs, 10);
651 +
652 +       return pos + sizeof(struct ieee80211_ht_info);
653 +}
654 +
655 +enum nl80211_channel_type
656 +ieee80211_ht_info_to_channel_type(struct ieee80211_ht_info *ht_info)
657 +{
658 +       enum nl80211_channel_type channel_type;
659 +
660 +       if (!ht_info)
661 +               return NL80211_CHAN_NO_HT;
662 +
663 +       switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
664 +       case IEEE80211_HT_PARAM_CHA_SEC_NONE:
665 +               channel_type = NL80211_CHAN_HT20;
666 +               break;
667 +       case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
668 +               channel_type = NL80211_CHAN_HT40PLUS;
669 +               break;
670 +       case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
671 +               channel_type = NL80211_CHAN_HT40MINUS;
672 +               break;
673 +       default:
674 +               channel_type = NL80211_CHAN_NO_HT;
675 +       }
676 +
677 +       return channel_type;
678 +}
679 --- a/net/mac80211/work.c
680 +++ b/net/mac80211/work.c
681 @@ -118,7 +118,6 @@ static void ieee80211_add_ht_ie(struct s
682         u8 *pos;
683         u32 flags = channel->flags;
684         u16 cap = sband->ht_cap.cap;
685 -       __le16 tmp;
686  
687         if (!sband->ht_cap.ht_supported)
688                 return;
689 @@ -169,34 +168,8 @@ static void ieee80211_add_ht_ie(struct s
690         }
691  
692         /* reserve and fill IE */
693 -
694         pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
695 -       *pos++ = WLAN_EID_HT_CAPABILITY;
696 -       *pos++ = sizeof(struct ieee80211_ht_cap);
697 -       memset(pos, 0, sizeof(struct ieee80211_ht_cap));
698 -
699 -       /* capability flags */
700 -       tmp = cpu_to_le16(cap);
701 -       memcpy(pos, &tmp, sizeof(u16));
702 -       pos += sizeof(u16);
703 -
704 -       /* AMPDU parameters */
705 -       *pos++ = sband->ht_cap.ampdu_factor |
706 -                (sband->ht_cap.ampdu_density <<
707 -                       IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
708 -
709 -       /* MCS set */
710 -       memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
711 -       pos += sizeof(sband->ht_cap.mcs);
712 -
713 -       /* extended capabilities */
714 -       pos += sizeof(__le16);
715 -
716 -       /* BF capabilities */
717 -       pos += sizeof(__le32);
718 -
719 -       /* antenna selection */
720 -       pos += sizeof(u8);
721 +       ieee80211_ie_build_ht_cap(pos, sband, cap);
722  }
723  
724  static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
725 --- a/net/wireless/chan.c
726 +++ b/net/wireless/chan.c
727 @@ -44,9 +44,9 @@ rdev_freq_to_chan(struct cfg80211_regist
728         return chan;
729  }
730  
731 -static bool can_beacon_sec_chan(struct wiphy *wiphy,
732 -                               struct ieee80211_channel *chan,
733 -                               enum nl80211_channel_type channel_type)
734 +bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
735 +                                 struct ieee80211_channel *chan,
736 +                                 enum nl80211_channel_type channel_type)
737  {
738         struct ieee80211_channel *sec_chan;
739         int diff;
740 @@ -75,6 +75,7 @@ static bool can_beacon_sec_chan(struct w
741  
742         return true;
743  }
744 +EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
745  
746  int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
747                       struct wireless_dev *wdev, int freq,
748 @@ -109,8 +110,8 @@ int cfg80211_set_freq(struct cfg80211_re
749                 switch (channel_type) {
750                 case NL80211_CHAN_HT40PLUS:
751                 case NL80211_CHAN_HT40MINUS:
752 -                       if (!can_beacon_sec_chan(&rdev->wiphy, chan,
753 -                                                channel_type)) {
754 +                       if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, chan,
755 +                                                         channel_type)) {
756                                 printk(KERN_DEBUG
757                                        "cfg80211: Secondary channel not "
758                                        "allowed to initiate communication\n");
759 --- a/net/wireless/nl80211.c
760 +++ b/net/wireless/nl80211.c
761 @@ -4574,13 +4574,34 @@ static int nl80211_join_ibss(struct sk_b
762                 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
763         }
764  
765 -       ibss.channel = ieee80211_get_channel(wiphy,
766 -               nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
767 +       if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
768 +               enum nl80211_channel_type channel_type;
769 +
770 +               channel_type = nla_get_u32(
771 +                               info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
772 +               if (channel_type > NL80211_CHAN_HT40PLUS)
773 +                       return -EINVAL;
774 +               ibss.channel_type = channel_type;
775 +       } else {
776 +               ibss.channel_type = NL80211_CHAN_NO_HT;
777 +       }
778 +
779 +       ibss.channel = rdev_freq_to_chan(rdev,
780 +               nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
781 +               ibss.channel_type);
782         if (!ibss.channel ||
783 +           ibss.channel->flags & IEEE80211_CHAN_RADAR ||
784             ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
785             ibss.channel->flags & IEEE80211_CHAN_DISABLED)
786                 return -EINVAL;
787  
788 +       /* Both channels should be able to initiate communication */
789 +       if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
790 +            ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
791 +           !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
792 +                                         ibss.channel_type))
793 +               return -EINVAL;
794 +
795         ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
796         ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
797