]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - net/mac80211/ieee80211_sta.c
cfg80211 API for channels/bitrates, mac80211 and driver conversion
[karo-tx-linux.git] / net / mac80211 / ieee80211_sta.c
index 3c552fed2af51afd53752d9f5565a70d6e5a65d9..2628222a5085f1f321f54b67f5b967f77eac67e7 100644 (file)
 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
+#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
+#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
+
+/* next values represent the buffer size for A-MPDU frame.
+ * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
+#define IEEE80211_MIN_AMPDU_BUF 0x8
+#define IEEE80211_MAX_AMPDU_BUF 0x40
 
 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
                                     u8 *ssid, size_t ssid_len);
 static struct ieee80211_sta_bss *
-ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
+ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
                     u8 *ssid, u8 ssid_len);
 static void ieee80211_rx_bss_put(struct net_device *dev,
                                 struct ieee80211_sta_bss *bss);
@@ -306,48 +313,42 @@ static void ieee80211_sta_wmm_params(struct net_device *dev,
 }
 
 
-static void ieee80211_handle_erp_ie(struct net_device *dev, u8 erp_value)
+static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
+                                  u8 erp_value)
 {
-       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
        struct ieee80211_if_sta *ifsta = &sdata->u.sta;
-       int use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
-       int preamble_mode = (erp_value & WLAN_ERP_BARKER_PREAMBLE) != 0;
-       u8 changes = 0;
+       bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
+       bool preamble_mode = (erp_value & WLAN_ERP_BARKER_PREAMBLE) != 0;
        DECLARE_MAC_BUF(mac);
+       u32 changed = 0;
 
-       if (use_protection != !!(sdata->flags & IEEE80211_SDATA_USE_PROTECTION)) {
+       if (use_protection != bss_conf->use_cts_prot) {
                if (net_ratelimit()) {
                        printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
                               "%s)\n",
-                              dev->name,
+                              sdata->dev->name,
                               use_protection ? "enabled" : "disabled",
                               print_mac(mac, ifsta->bssid));
                }
-               if (use_protection)
-                       sdata->flags |= IEEE80211_SDATA_USE_PROTECTION;
-               else
-                       sdata->flags &= ~IEEE80211_SDATA_USE_PROTECTION;
-               changes |= IEEE80211_ERP_CHANGE_PROTECTION;
+               bss_conf->use_cts_prot = use_protection;
+               changed |= BSS_CHANGED_ERP_CTS_PROT;
        }
 
-       if (preamble_mode != !(sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE)) {
+       if (preamble_mode != bss_conf->use_short_preamble) {
                if (net_ratelimit()) {
                        printk(KERN_DEBUG "%s: switched to %s barker preamble"
                               " (BSSID=%s)\n",
-                              dev->name,
+                              sdata->dev->name,
                               (preamble_mode == WLAN_ERP_PREAMBLE_SHORT) ?
                                        "short" : "long",
                               print_mac(mac, ifsta->bssid));
                }
-               if (preamble_mode)
-                       sdata->flags &= ~IEEE80211_SDATA_SHORT_PREAMBLE;
-               else
-                       sdata->flags |= IEEE80211_SDATA_SHORT_PREAMBLE;
-               changes |= IEEE80211_ERP_CHANGE_PREAMBLE;
+               bss_conf->use_short_preamble = preamble_mode;
+               changed |= BSS_CHANGED_ERP_PREAMBLE;
        }
 
-       if (changes)
-               ieee80211_erp_info_change_notify(dev, changes);
+       return changed;
 }
 
 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
@@ -451,28 +452,26 @@ static void ieee80211_set_associated(struct net_device *dev,
                                     struct ieee80211_if_sta *ifsta,
                                     bool assoc)
 {
-       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct ieee80211_local *local = sdata->local;
        union iwreq_data wrqu;
-
-       if (!!(ifsta->flags & IEEE80211_STA_ASSOCIATED) == assoc)
-               return;
+       u32 changed = BSS_CHANGED_ASSOC;
 
        if (assoc) {
-               struct ieee80211_sub_if_data *sdata;
                struct ieee80211_sta_bss *bss;
 
                ifsta->flags |= IEEE80211_STA_ASSOCIATED;
 
-               sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-               if (sdata->type != IEEE80211_IF_TYPE_STA)
+               if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
                        return;
 
                bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
-                                          local->hw.conf.channel,
+                                          local->hw.conf.channel->center_freq,
                                           ifsta->ssid, ifsta->ssid_len);
                if (bss) {
                        if (bss->has_erp_value)
-                               ieee80211_handle_erp_ie(dev, bss->erp_value);
+                               changed |= ieee80211_handle_erp_ie(
+                                               sdata, bss->erp_value);
                        ieee80211_rx_bss_put(dev, bss);
                }
 
@@ -492,6 +491,9 @@ static void ieee80211_set_associated(struct net_device *dev,
        wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
        ifsta->last_probe = jiffies;
        ieee80211_led_assoc(local, assoc);
+
+       sdata->bss_conf.assoc = assoc;
+       ieee80211_bss_info_change_notify(sdata, changed);
 }
 
 static void ieee80211_set_disassoc(struct net_device *dev,
@@ -591,7 +593,6 @@ static void ieee80211_send_assoc(struct net_device *dev,
                                 struct ieee80211_if_sta *ifsta)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-       struct ieee80211_hw_mode *mode;
        struct sk_buff *skb;
        struct ieee80211_mgmt *mgmt;
        u8 *pos, *ies;
@@ -599,6 +600,7 @@ static void ieee80211_send_assoc(struct net_device *dev,
        u16 capab;
        struct ieee80211_sta_bss *bss;
        int wmm = 0;
+       struct ieee80211_supported_band *sband;
 
        skb = dev_alloc_skb(local->hw.extra_tx_headroom +
                            sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
@@ -610,13 +612,19 @@ static void ieee80211_send_assoc(struct net_device *dev,
        }
        skb_reserve(skb, local->hw.extra_tx_headroom);
 
-       mode = local->oper_hw_mode;
+       sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
        capab = ifsta->capab;
-       if (mode->mode == MODE_IEEE80211G) {
-               capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
-                       WLAN_CAPABILITY_SHORT_PREAMBLE;
+
+       if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
+               if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
+                       capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
+               if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
+                       capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
        }
-       bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
+
+       bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
+                                  local->hw.conf.channel->center_freq,
                                   ifsta->ssid, ifsta->ssid_len);
        if (bss) {
                if (bss->capability & WLAN_CAPABILITY_PRIVACY)
@@ -655,23 +663,23 @@ static void ieee80211_send_assoc(struct net_device *dev,
        *pos++ = ifsta->ssid_len;
        memcpy(pos, ifsta->ssid, ifsta->ssid_len);
 
-       len = mode->num_rates;
+       len = sband->n_bitrates;
        if (len > 8)
                len = 8;
        pos = skb_put(skb, len + 2);
        *pos++ = WLAN_EID_SUPP_RATES;
        *pos++ = len;
        for (i = 0; i < len; i++) {
-               int rate = mode->rates[i].rate;
+               int rate = sband->bitrates[i].bitrate;
                *pos++ = (u8) (rate / 5);
        }
 
-       if (mode->num_rates > len) {
-               pos = skb_put(skb, mode->num_rates - len + 2);
+       if (sband->n_bitrates > len) {
+               pos = skb_put(skb, sband->n_bitrates - len + 2);
                *pos++ = WLAN_EID_EXT_SUPP_RATES;
-               *pos++ = mode->num_rates - len;
-               for (i = len; i < mode->num_rates; i++) {
-                       int rate = mode->rates[i].rate;
+               *pos++ = sband->n_bitrates - len;
+               for (i = len; i < sband->n_bitrates; i++) {
+                       int rate = sband->bitrates[i].bitrate;
                        *pos++ = (u8) (rate / 5);
                }
        }
@@ -694,17 +702,18 @@ static void ieee80211_send_assoc(struct net_device *dev,
                *pos++ = 0;
        }
        /* wmm support is a must to HT */
-       if (wmm && mode->ht_info.ht_supported) {
-               __le16 tmp = cpu_to_le16(mode->ht_info.cap);
+       if (wmm && sband->ht_info.ht_supported) {
+               __le16 tmp = cpu_to_le16(sband->ht_info.cap);
                pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
                *pos++ = WLAN_EID_HT_CAPABILITY;
                *pos++ = sizeof(struct ieee80211_ht_cap);
                memset(pos, 0, sizeof(struct ieee80211_ht_cap));
                memcpy(pos, &tmp, sizeof(u16));
                pos += sizeof(u16);
-               *pos++ = (mode->ht_info.ampdu_factor |
-                               (mode->ht_info.ampdu_density << 2));
-               memcpy(pos, mode->ht_info.supp_mcs_set, 16);
+               /* TODO: needs a define here for << 2 */
+               *pos++ = sband->ht_info.ampdu_factor |
+                        (sband->ht_info.ampdu_density << 2);
+               memcpy(pos, sband->ht_info.supp_mcs_set, 16);
        }
 
        kfree(ifsta->assocreq_ies);
@@ -787,7 +796,8 @@ static int ieee80211_privacy_mismatch(struct net_device *dev,
        if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
                return 0;
 
-       bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
+       bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
+                                  local->hw.conf.channel->center_freq,
                                   ifsta->ssid, ifsta->ssid_len);
        if (!bss)
                return 0;
@@ -897,7 +907,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
                                     u8 *ssid, size_t ssid_len)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-       struct ieee80211_hw_mode *mode;
+       struct ieee80211_supported_band *sband;
        struct sk_buff *skb;
        struct ieee80211_mgmt *mgmt;
        u8 *pos, *supp_rates, *esupp_rates = NULL;
@@ -931,11 +941,10 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
        supp_rates = skb_put(skb, 2);
        supp_rates[0] = WLAN_EID_SUPP_RATES;
        supp_rates[1] = 0;
-       mode = local->oper_hw_mode;
-       for (i = 0; i < mode->num_rates; i++) {
-               struct ieee80211_rate *rate = &mode->rates[i];
-               if (!(rate->flags & IEEE80211_RATE_SUPPORTED))
-                       continue;
+       sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
+       for (i = 0; i < sband->n_bitrates; i++) {
+               struct ieee80211_rate *rate = &sband->bitrates[i];
                if (esupp_rates) {
                        pos = skb_put(skb, 1);
                        esupp_rates[1]++;
@@ -948,7 +957,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
                        pos = skb_put(skb, 1);
                        supp_rates[1]++;
                }
-               *pos = rate->rate / 5;
+               *pos = rate->bitrate / 5;
        }
 
        ieee80211_sta_tx(dev, skb, 0);
@@ -1005,7 +1014,8 @@ static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
        struct ieee80211_mgmt *mgmt;
        u16 capab;
 
-       skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
+       skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
+                                       sizeof(mgmt->u.action.u.addba_resp));
        if (!skb) {
                printk(KERN_DEBUG "%s: failed to allocate buffer "
                       "for addba resp frame\n", dev->name);
@@ -1017,7 +1027,7 @@ static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
        memset(mgmt, 0, 24);
        memcpy(mgmt->da, da, ETH_ALEN);
        memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
-       if (sdata->type == IEEE80211_IF_TYPE_AP)
+       if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
                memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
        else
                memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
@@ -1042,14 +1052,71 @@ static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
        return;
 }
 
+void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
+                               u16 tid, u8 dialog_token, u16 start_seq_num,
+                               u16 agg_size, u16 timeout)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+       struct sk_buff *skb;
+       struct ieee80211_mgmt *mgmt;
+       u16 capab;
+
+       skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
+                               sizeof(mgmt->u.action.u.addba_req));
+
+
+       if (!skb) {
+               printk(KERN_ERR "%s: failed to allocate buffer "
+                               "for addba request frame\n", dev->name);
+               return;
+       }
+       skb_reserve(skb, local->hw.extra_tx_headroom);
+       mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
+       memset(mgmt, 0, 24);
+       memcpy(mgmt->da, da, ETH_ALEN);
+       memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+       if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
+               memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
+       else
+               memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
+
+       mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+                                       IEEE80211_STYPE_ACTION);
+
+       skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
+
+       mgmt->u.action.category = WLAN_CATEGORY_BACK;
+       mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
+
+       mgmt->u.action.u.addba_req.dialog_token = dialog_token;
+       capab = (u16)(1 << 1);          /* bit 1 aggregation policy */
+       capab |= (u16)(tid << 2);       /* bit 5:2 TID number */
+       capab |= (u16)(agg_size << 6);  /* bit 15:6 max size of aggergation */
+
+       mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
+
+       mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
+       mgmt->u.action.u.addba_req.start_seq_num =
+                                       cpu_to_le16(start_seq_num << 4);
+
+       ieee80211_sta_tx(dev, skb, 0);
+}
+
 static void ieee80211_sta_process_addba_request(struct net_device *dev,
                                                struct ieee80211_mgmt *mgmt,
                                                size_t len)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_hw *hw = &local->hw;
+       struct ieee80211_conf *conf = &hw->conf;
        struct sta_info *sta;
-       u16 capab, tid, timeout, ba_policy, buf_size, status;
+       struct tid_ampdu_rx *tid_agg_rx;
+       u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
        u8 dialog_token;
+       int ret = -EOPNOTSUPP;
+       DECLARE_MAC_BUF(mac);
 
        sta = sta_info_get(local, mgmt->sa);
        if (!sta)
@@ -1058,28 +1125,383 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
        /* extract session parameters from addba request frame */
        dialog_token = mgmt->u.action.u.addba_req.dialog_token;
        timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
+       start_seq_num =
+               le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
 
        capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
        ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
        tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
        buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
 
-       /* TODO - currently aggregation is declined (A-MPDU add BA request
-       * acceptance is not obligatory by 802.11n draft), but here is
-       * the entry point for dealing with it */
-#ifdef MAC80211_HT_DEBUG
-       if (net_ratelimit())
-               printk(KERN_DEBUG "Add Block Ack request arrived,"
-                                  " currently denying it\n");
-#endif /* MAC80211_HT_DEBUG */
-
        status = WLAN_STATUS_REQUEST_DECLINED;
 
+       /* sanity check for incoming parameters:
+        * check if configuration can support the BA policy
+        * and if buffer size does not exceeds max value */
+       if (((ba_policy != 1)
+               && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
+               || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
+               status = WLAN_STATUS_INVALID_QOS_PARAM;
+#ifdef CONFIG_MAC80211_HT_DEBUG
+               if (net_ratelimit())
+                       printk(KERN_DEBUG "Block Ack Req with bad params from "
+                               "%s on tid %u. policy %d, buffer size %d\n",
+                               print_mac(mac, mgmt->sa), tid, ba_policy,
+                               buf_size);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+               goto end_no_lock;
+       }
+       /* determine default buffer size */
+       if (buf_size == 0) {
+               struct ieee80211_supported_band *sband;
+
+               sband = local->hw.wiphy->bands[conf->channel->band];
+               buf_size = IEEE80211_MIN_AMPDU_BUF;
+               buf_size = buf_size << sband->ht_info.ampdu_factor;
+       }
+
+       tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid];
+
+       /* examine state machine */
+       spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
+
+       if (tid_agg_rx->state != HT_AGG_STATE_IDLE) {
+#ifdef CONFIG_MAC80211_HT_DEBUG
+               if (net_ratelimit())
+                       printk(KERN_DEBUG "unexpected Block Ack Req from "
+                               "%s on tid %u\n",
+                               print_mac(mac, mgmt->sa), tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+               goto end;
+       }
+
+       /* prepare reordering buffer */
+       tid_agg_rx->reorder_buf =
+               kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
+       if (!tid_agg_rx->reorder_buf) {
+               if (net_ratelimit())
+                       printk(KERN_ERR "can not allocate reordering buffer "
+                              "to tid %d\n", tid);
+               goto end;
+       }
+       memset(tid_agg_rx->reorder_buf, 0,
+               buf_size * sizeof(struct sk_buf *));
+
+       if (local->ops->ampdu_action)
+               ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
+                                              sta->addr, tid, &start_seq_num);
+#ifdef CONFIG_MAC80211_HT_DEBUG
+       printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+
+       if (ret) {
+               kfree(tid_agg_rx->reorder_buf);
+               goto end;
+       }
+
+       /* change state and send addba resp */
+       tid_agg_rx->state = HT_AGG_STATE_OPERATIONAL;
+       tid_agg_rx->dialog_token = dialog_token;
+       tid_agg_rx->ssn = start_seq_num;
+       tid_agg_rx->head_seq_num = start_seq_num;
+       tid_agg_rx->buf_size = buf_size;
+       tid_agg_rx->timeout = timeout;
+       tid_agg_rx->stored_mpdu_num = 0;
+       status = WLAN_STATUS_SUCCESS;
+end:
+       spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
+
+end_no_lock:
        ieee80211_send_addba_resp(sta->dev, sta->addr, tid, dialog_token,
                                status, 1, buf_size, timeout);
        sta_info_put(sta);
 }
 
+static void ieee80211_sta_process_addba_resp(struct net_device *dev,
+                                            struct ieee80211_mgmt *mgmt,
+                                            size_t len)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_hw *hw = &local->hw;
+       struct sta_info *sta;
+       u16 capab;
+       u16 tid;
+       u8 *state;
+
+       sta = sta_info_get(local, mgmt->sa);
+       if (!sta)
+               return;
+
+       capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
+       tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
+
+       state = &sta->ampdu_mlme.tid_tx[tid].state;
+
+       spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+
+       if (mgmt->u.action.u.addba_resp.dialog_token !=
+               sta->ampdu_mlme.tid_tx[tid].dialog_token) {
+               spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+#ifdef CONFIG_MAC80211_HT_DEBUG
+               printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+               sta_info_put(sta);
+               return;
+       }
+
+       del_timer_sync(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
+#ifdef CONFIG_MAC80211_HT_DEBUG
+       printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+       if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
+                       == WLAN_STATUS_SUCCESS) {
+               if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
+                       spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+                       printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
+                               "%d\n", *state);
+                       sta_info_put(sta);
+                       return;
+               }
+
+               if (*state & HT_ADDBA_RECEIVED_MSK)
+                       printk(KERN_DEBUG "double addBA response\n");
+
+               *state |= HT_ADDBA_RECEIVED_MSK;
+               sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
+
+               if (*state == HT_AGG_STATE_OPERATIONAL) {
+                       printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
+                       ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
+               }
+
+               spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+               printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
+       } else {
+               printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
+
+               sta->ampdu_mlme.tid_tx[tid].addba_req_num++;
+               /* this will allow the state check in stop_BA_session */
+               *state = HT_AGG_STATE_OPERATIONAL;
+               spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+               ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
+                                            WLAN_BACK_INITIATOR);
+       }
+       sta_info_put(sta);
+}
+
+void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
+                         u16 initiator, u16 reason_code)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+       struct sk_buff *skb;
+       struct ieee80211_mgmt *mgmt;
+       u16 params;
+
+       skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
+                                       sizeof(mgmt->u.action.u.delba));
+
+       if (!skb) {
+               printk(KERN_ERR "%s: failed to allocate buffer "
+                                       "for delba frame\n", dev->name);
+               return;
+       }
+
+       skb_reserve(skb, local->hw.extra_tx_headroom);
+       mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
+       memset(mgmt, 0, 24);
+       memcpy(mgmt->da, da, ETH_ALEN);
+       memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+       if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
+               memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
+       else
+               memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
+       mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+                                       IEEE80211_STYPE_ACTION);
+
+       skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
+
+       mgmt->u.action.category = WLAN_CATEGORY_BACK;
+       mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
+       params = (u16)(initiator << 11);        /* bit 11 initiator */
+       params |= (u16)(tid << 12);             /* bit 15:12 TID number */
+
+       mgmt->u.action.u.delba.params = cpu_to_le16(params);
+       mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
+
+       ieee80211_sta_tx(dev, skb, 0);
+}
+
+void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
+                                       u16 initiator, u16 reason)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_hw *hw = &local->hw;
+       struct sta_info *sta;
+       int ret, i;
+
+       sta = sta_info_get(local, ra);
+       if (!sta)
+               return;
+
+       /* check if TID is in operational state */
+       spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
+       if (sta->ampdu_mlme.tid_rx[tid].state
+                               != HT_AGG_STATE_OPERATIONAL) {
+               spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
+               sta_info_put(sta);
+               return;
+       }
+       sta->ampdu_mlme.tid_rx[tid].state =
+               HT_AGG_STATE_REQ_STOP_BA_MSK |
+               (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
+               spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
+
+       /* stop HW Rx aggregation. ampdu_action existence
+        * already verified in session init so we add the BUG_ON */
+       BUG_ON(!local->ops->ampdu_action);
+
+       ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
+                                       ra, tid, NULL);
+       if (ret)
+               printk(KERN_DEBUG "HW problem - can not stop rx "
+                               "aggergation for tid %d\n", tid);
+
+       /* shutdown timer has not expired */
+       if (initiator != WLAN_BACK_TIMER)
+               del_timer_sync(&sta->ampdu_mlme.tid_rx[tid].
+                                       session_timer);
+
+       /* check if this is a self generated aggregation halt */
+       if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
+               ieee80211_send_delba(dev, ra, tid, 0, reason);
+
+       /* free the reordering buffer */
+       for (i = 0; i < sta->ampdu_mlme.tid_rx[tid].buf_size; i++) {
+               if (sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]) {
+                       /* release the reordered frames */
+                       dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]);
+                       sta->ampdu_mlme.tid_rx[tid].stored_mpdu_num--;
+                       sta->ampdu_mlme.tid_rx[tid].reorder_buf[i] = NULL;
+               }
+       }
+       kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf);
+
+       sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE;
+       sta_info_put(sta);
+}
+
+
+static void ieee80211_sta_process_delba(struct net_device *dev,
+                       struct ieee80211_mgmt *mgmt, size_t len)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct sta_info *sta;
+       u16 tid, params;
+       u16 initiator;
+       DECLARE_MAC_BUF(mac);
+
+       sta = sta_info_get(local, mgmt->sa);
+       if (!sta)
+               return;
+
+       params = le16_to_cpu(mgmt->u.action.u.delba.params);
+       tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
+       initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
+
+#ifdef CONFIG_MAC80211_HT_DEBUG
+       if (net_ratelimit())
+               printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
+                       print_mac(mac, mgmt->sa),
+                       initiator ? "recipient" : "initiator", tid,
+                       mgmt->u.action.u.delba.reason_code);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+
+       if (initiator == WLAN_BACK_INITIATOR)
+               ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
+                                                WLAN_BACK_INITIATOR, 0);
+       else { /* WLAN_BACK_RECIPIENT */
+               spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+               sta->ampdu_mlme.tid_tx[tid].state =
+                               HT_AGG_STATE_OPERATIONAL;
+               spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+               ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
+                                            WLAN_BACK_RECIPIENT);
+       }
+       sta_info_put(sta);
+}
+
+/*
+ * After sending add Block Ack request we activated a timer until
+ * add Block Ack response will arrive from the recipient.
+ * If this timer expires sta_addba_resp_timer_expired will be executed.
+ */
+void sta_addba_resp_timer_expired(unsigned long data)
+{
+       /* not an elegant detour, but there is no choice as the timer passes
+        * only one argument, and both sta_info and TID are needed, so init
+        * flow in sta_info_add gives the TID as data, while the timer_to_id
+        * array gives the sta through container_of */
+       u16 tid = *(int *)data;
+       struct sta_info *temp_sta = container_of((void *)data,
+               struct sta_info, timer_to_tid[tid]);
+
+       struct ieee80211_local *local = temp_sta->local;
+       struct ieee80211_hw *hw = &local->hw;
+       struct sta_info *sta;
+       u8 *state;
+
+       sta = sta_info_get(local, temp_sta->addr);
+       if (!sta)
+               return;
+
+       state = &sta->ampdu_mlme.tid_tx[tid].state;
+       /* check if the TID waits for addBA response */
+       spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+       if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
+               spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+               *state = HT_AGG_STATE_IDLE;
+               printk(KERN_DEBUG "timer expired on tid %d but we are not "
+                               "expecting addBA response there", tid);
+               goto timer_expired_exit;
+       }
+
+       printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
+
+       /* go through the state check in stop_BA_session */
+       *state = HT_AGG_STATE_OPERATIONAL;
+       spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+       ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
+                                    WLAN_BACK_INITIATOR);
+
+timer_expired_exit:
+       sta_info_put(sta);
+}
+
+/*
+ * After receiving Block Ack Request (BAR) we activated a
+ * timer after each frame arrives from the originator.
+ * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
+ */
+void sta_rx_agg_session_timer_expired(unsigned long data)
+{
+       /* not an elegant detour, but there is no choice as the timer passes
+        * only one argument, and verious sta_info are needed here, so init
+        * flow in sta_info_add gives the TID as data, while the timer_to_id
+        * array gives the sta through container_of */
+       u8 *ptid = (u8 *)data;
+       u8 *timer_to_id = ptid - *ptid;
+       struct sta_info *sta = container_of(timer_to_id, struct sta_info,
+                                        timer_to_tid[0]);
+
+       printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
+       ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, (u16)*ptid,
+                                        WLAN_BACK_TIMER,
+                                        WLAN_REASON_QSTA_TIMEOUT);
+}
+
+
 static void ieee80211_rx_mgmt_auth(struct net_device *dev,
                                   struct ieee80211_if_sta *ifsta,
                                   struct ieee80211_mgmt *mgmt,
@@ -1090,7 +1512,7 @@ static void ieee80211_rx_mgmt_auth(struct net_device *dev,
        DECLARE_MAC_BUF(mac);
 
        if (ifsta->state != IEEE80211_AUTHENTICATE &&
-           sdata->type != IEEE80211_IF_TYPE_IBSS) {
+           sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
                printk(KERN_DEBUG "%s: authentication frame received from "
                       "%s, but not in authenticate state - ignored\n",
                       dev->name, print_mac(mac, mgmt->sa));
@@ -1104,7 +1526,7 @@ static void ieee80211_rx_mgmt_auth(struct net_device *dev,
                return;
        }
 
-       if (sdata->type != IEEE80211_IF_TYPE_IBSS &&
+       if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
            memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
                printk(KERN_DEBUG "%s: authentication frame received from "
                       "unknown AP (SA=%s BSSID=%s) - "
@@ -1113,7 +1535,7 @@ static void ieee80211_rx_mgmt_auth(struct net_device *dev,
                return;
        }
 
-       if (sdata->type != IEEE80211_IF_TYPE_IBSS &&
+       if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
            memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
                printk(KERN_DEBUG "%s: authentication frame received from "
                       "unknown BSSID (SA=%s BSSID=%s) - "
@@ -1131,7 +1553,7 @@ static void ieee80211_rx_mgmt_auth(struct net_device *dev,
               dev->name, print_mac(mac, mgmt->sa), auth_alg,
               auth_transaction, status_code);
 
-       if (sdata->type == IEEE80211_IF_TYPE_IBSS) {
+       if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
                /* IEEE 802.11 standard does not require authentication in IBSS
                 * networks and most implementations do not seem to use it.
                 * However, try to reply to authentication attempts if someone
@@ -1297,21 +1719,24 @@ static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
 }
 
 
-static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
+static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
                                         struct ieee80211_if_sta *ifsta,
                                         struct ieee80211_mgmt *mgmt,
                                         size_t len,
                                         int reassoc)
 {
-       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-       struct ieee80211_hw_mode *mode;
+       struct ieee80211_local *local = sdata->local;
+       struct net_device *dev = sdata->dev;
+       struct ieee80211_supported_band *sband;
        struct sta_info *sta;
-       u32 rates;
+       u64 rates, basic_rates;
        u16 capab_info, status_code, aid;
        struct ieee802_11_elems elems;
+       struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
        u8 *pos;
        int i, j;
        DECLARE_MAC_BUF(mac);
+       bool have_higher_than_11mbit = false;
 
        /* AssocResp and ReassocResp have identical structure, so process both
         * of them in this function. */
@@ -1371,20 +1796,6 @@ static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
                return;
        }
 
-       /* it probably doesn't, but if the frame includes an ERP value then
-        * update our stored copy */
-       if (elems.erp_info && elems.erp_info_len >= 1) {
-               struct ieee80211_sta_bss *bss
-                       = ieee80211_rx_bss_get(dev, ifsta->bssid,
-                                              local->hw.conf.channel,
-                                              ifsta->ssid, ifsta->ssid_len);
-               if (bss) {
-                       bss->erp_value = elems.erp_info[0];
-                       bss->has_erp_value = 1;
-                       ieee80211_rx_bss_put(dev, bss);
-               }
-       }
-
        printk(KERN_DEBUG "%s: associated\n", dev->name);
        ifsta->aid = aid;
        ifsta->ap_capab = capab_info;
@@ -1395,8 +1806,6 @@ static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
        if (ifsta->assocresp_ies)
                memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
 
-       ieee80211_set_associated(dev, ifsta, 1);
-
        /* Add STA entry for the AP */
        sta = sta_info_get(local, ifsta->bssid);
        if (!sta) {
@@ -1408,7 +1817,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
                        return;
                }
                bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
-                                          local->hw.conf.channel,
+                                          local->hw.conf.channel->center_freq,
                                           ifsta->ssid, ifsta->ssid_len);
                if (bss) {
                        sta->last_rssi = bss->rssi;
@@ -1422,20 +1831,46 @@ static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
        sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP;
 
        rates = 0;
-       mode = local->oper_hw_mode;
+       basic_rates = 0;
+       sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
        for (i = 0; i < elems.supp_rates_len; i++) {
                int rate = (elems.supp_rates[i] & 0x7f) * 5;
-               for (j = 0; j < mode->num_rates; j++)
-                       if (mode->rates[j].rate == rate)
+
+               if (rate > 110)
+                       have_higher_than_11mbit = true;
+
+               for (j = 0; j < sband->n_bitrates; j++) {
+                       if (sband->bitrates[j].bitrate == rate)
                                rates |= BIT(j);
+                       if (elems.supp_rates[i] & 0x80)
+                               basic_rates |= BIT(j);
+               }
        }
+
        for (i = 0; i < elems.ext_supp_rates_len; i++) {
                int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
-               for (j = 0; j < mode->num_rates; j++)
-                       if (mode->rates[j].rate == rate)
+
+               if (rate > 110)
+                       have_higher_than_11mbit = true;
+
+               for (j = 0; j < sband->n_bitrates; j++) {
+                       if (sband->bitrates[j].bitrate == rate)
                                rates |= BIT(j);
+                       if (elems.ext_supp_rates[i] & 0x80)
+                               basic_rates |= BIT(j);
+               }
        }
-       sta->supp_rates = rates;
+
+       sta->supp_rates[local->hw.conf.channel->band] = rates;
+       sdata->basic_rates = basic_rates;
+
+       /* cf. IEEE 802.11 9.2.12 */
+       if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
+           have_higher_than_11mbit)
+               sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
+       else
+               sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
 
        if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
            local->ops->conf_ht) {
@@ -1458,6 +1893,9 @@ static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
                                         elems.wmm_param_len);
        }
 
+       /* set AID, ieee80211_set_associated() will tell the driver */
+       bss_conf->aid = aid;
+       ieee80211_set_associated(dev, ifsta, 1);
 
        sta_info_put(sta);
 
@@ -1498,7 +1936,7 @@ static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
 
 
 static struct ieee80211_sta_bss *
-ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
+ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
                     u8 *ssid, u8 ssid_len)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1510,7 +1948,7 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
        atomic_inc(&bss->users);
        atomic_inc(&bss->users);
        memcpy(bss->bssid, bssid, ETH_ALEN);
-       bss->channel = channel;
+       bss->freq = freq;
        if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
                memcpy(bss->ssid, ssid, ssid_len);
                bss->ssid_len = ssid_len;
@@ -1526,7 +1964,7 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
 
 
 static struct ieee80211_sta_bss *
-ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
+ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
                     u8 *ssid, u8 ssid_len)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1536,7 +1974,7 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
        bss = local->sta_bss_hash[STA_HASH(bssid)];
        while (bss) {
                if (!memcmp(bss->bssid, bssid, ETH_ALEN) &&
-                   bss->channel == channel &&
+                   bss->freq == freq &&
                    bss->ssid_len == ssid_len &&
                    (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
                        atomic_inc(&bss->users);
@@ -1601,7 +2039,7 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
        struct ieee802_11_elems elems;
        size_t baselen;
-       int channel, clen;
+       int freq, clen;
        struct ieee80211_sta_bss *bss;
        struct sta_info *sta;
        struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -1624,7 +2062,7 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
 
        timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
 
-       if (sdata->type == IEEE80211_IF_TYPE_IBSS && beacon &&
+       if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
            memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
                static unsigned long last_tsf_debug = 0;
@@ -1649,29 +2087,25 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
 
        ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
 
-       if (sdata->type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
+       if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
            memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
            (sta = sta_info_get(local, mgmt->sa))) {
-               struct ieee80211_hw_mode *mode;
-               struct ieee80211_rate *rates;
+               struct ieee80211_supported_band *sband;
+               struct ieee80211_rate *bitrates;
                size_t num_rates;
-               u32 supp_rates, prev_rates;
+               u64 supp_rates, prev_rates;
                int i, j;
 
-               mode = local->sta_sw_scanning ?
-                      local->scan_hw_mode : local->oper_hw_mode;
+               sband = local->hw.wiphy->bands[rx_status->band];
 
-               if (local->sta_hw_scanning) {
-                       /* search for the correct mode matches the beacon */
-                       list_for_each_entry(mode, &local->modes_list, list)
-                               if (mode->mode == rx_status->phymode)
-                                       break;
-
-                       if (mode == NULL)
-                               mode = local->oper_hw_mode;
+               if (!sband) {
+                       WARN_ON(1);
+                       sband = local->hw.wiphy->bands[
+                                       local->hw.conf.channel->band];
                }
-               rates = mode->rates;
-               num_rates = mode->num_rates;
+
+               bitrates = sband->bitrates;
+               num_rates = sband->n_bitrates;
 
                supp_rates = 0;
                for (i = 0; i < elems.supp_rates_len +
@@ -1685,24 +2119,27 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
                                        [i - elems.supp_rates_len];
                        own_rate = 5 * (rate & 0x7f);
                        for (j = 0; j < num_rates; j++)
-                               if (rates[j].rate == own_rate)
+                               if (bitrates[j].bitrate == own_rate)
                                        supp_rates |= BIT(j);
                }
 
-               prev_rates = sta->supp_rates;
-               sta->supp_rates &= supp_rates;
-               if (sta->supp_rates == 0) {
+               prev_rates = sta->supp_rates[rx_status->band];
+               sta->supp_rates[rx_status->band] &= supp_rates;
+               if (sta->supp_rates[rx_status->band] == 0) {
                        /* No matching rates - this should not really happen.
                         * Make sure that at least one rate is marked
                         * supported to avoid issues with TX rate ctrl. */
-                       sta->supp_rates = sdata->u.sta.supp_rates_bits;
+                       sta->supp_rates[rx_status->band] =
+                               sdata->u.sta.supp_rates_bits[rx_status->band];
                }
-               if (sta->supp_rates != prev_rates) {
+               if (sta->supp_rates[rx_status->band] != prev_rates) {
                        printk(KERN_DEBUG "%s: updated supp_rates set for "
-                              "%s based on beacon info (0x%x & 0x%x -> "
-                              "0x%x)\n",
-                              dev->name, print_mac(mac, sta->addr), prev_rates,
-                              supp_rates, sta->supp_rates);
+                              "%s based on beacon info (0x%llx & 0x%llx -> "
+                              "0x%llx)\n",
+                              dev->name, print_mac(mac, sta->addr),
+                              (unsigned long long) prev_rates,
+                              (unsigned long long) supp_rates,
+                              (unsigned long long) sta->supp_rates[rx_status->band]);
                }
                sta_info_put(sta);
        }
@@ -1711,14 +2148,14 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
                return;
 
        if (elems.ds_params && elems.ds_params_len == 1)
-               channel = elems.ds_params[0];
+               freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
        else
-               channel = rx_status->channel;
+               freq = rx_status->freq;
 
-       bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel,
+       bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
                                   elems.ssid, elems.ssid_len);
        if (!bss) {
-               bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel,
+               bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
                                           elems.ssid, elems.ssid_len);
                if (!bss)
                        return;
@@ -1731,6 +2168,8 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
 #endif
        }
 
+       bss->band = rx_status->band;
+
        if (bss->probe_resp && beacon) {
                /* Do not allow beacon to override data from Probe Response. */
                ieee80211_rx_bss_put(dev, bss);
@@ -1829,20 +2268,6 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
                bss->ht_ie_len = 0;
        }
 
-       bss->hw_mode = rx_status->phymode;
-       bss->freq = rx_status->freq;
-       if (channel != rx_status->channel &&
-           (bss->hw_mode == MODE_IEEE80211G ||
-            bss->hw_mode == MODE_IEEE80211B) &&
-           channel >= 1 && channel <= 14) {
-               static const int freq_list[] = {
-                       2412, 2417, 2422, 2427, 2432, 2437, 2442,
-                       2447, 2452, 2457, 2462, 2467, 2472, 2484
-               };
-               /* IEEE 802.11g/b mode can receive packets from neighboring
-                * channels, so map the channel into frequency. */
-               bss->freq = freq_list[channel - 1];
-       }
        bss->timestamp = timestamp;
        bss->last_update = jiffies;
        bss->rssi = rx_status->ssi;
@@ -1874,11 +2299,12 @@ static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
        struct ieee802_11_elems elems;
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
        struct ieee80211_conf *conf = &local->hw.conf;
+       u32 changed = 0;
 
        ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
 
        sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       if (sdata->type != IEEE80211_IF_TYPE_STA)
+       if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
                return;
        ifsta = &sdata->u.sta;
 
@@ -1894,7 +2320,7 @@ static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
        ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
 
        if (elems.erp_info && elems.erp_info_len >= 1)
-               ieee80211_handle_erp_ie(dev, elems.erp_info[0]);
+               changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
 
        if (elems.ht_cap_elem && elems.ht_info_elem &&
            elems.wmm_param && local->ops->conf_ht &&
@@ -1917,6 +2343,8 @@ static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
                ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
                                         elems.wmm_param_len);
        }
+
+       ieee80211_bss_info_change_notify(sdata, changed);
 }
 
 
@@ -1938,7 +2366,7 @@ static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
        DECLARE_MAC_BUF(mac3);
 #endif
 
-       if (sdata->type != IEEE80211_IF_TYPE_IBSS ||
+       if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
            ifsta->state != IEEE80211_IBSS_JOINED ||
            len < 24 + 2 || !ifsta->probe_resp)
                return;
@@ -1994,10 +2422,10 @@ static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
        ieee80211_sta_tx(dev, skb, 0);
 }
 
-void ieee80211_rx_mgmt_action(struct net_device *dev,
-                            struct ieee80211_if_sta *ifsta,
-                            struct ieee80211_mgmt *mgmt,
-                            size_t len)
+static void ieee80211_rx_mgmt_action(struct net_device *dev,
+                                    struct ieee80211_if_sta *ifsta,
+                                    struct ieee80211_mgmt *mgmt,
+                                    size_t len)
 {
        if (len < IEEE80211_MIN_ACTION_SIZE)
                return;
@@ -2011,9 +2439,21 @@ void ieee80211_rx_mgmt_action(struct net_device *dev,
                                break;
                        ieee80211_sta_process_addba_request(dev, mgmt, len);
                        break;
+               case WLAN_ACTION_ADDBA_RESP:
+                       if (len < (IEEE80211_MIN_ACTION_SIZE +
+                                  sizeof(mgmt->u.action.u.addba_resp)))
+                               break;
+                       ieee80211_sta_process_addba_resp(dev, mgmt, len);
+                       break;
+               case WLAN_ACTION_DELBA:
+                       if (len < (IEEE80211_MIN_ACTION_SIZE +
+                                  sizeof(mgmt->u.action.u.delba)))
+                               break;
+                       ieee80211_sta_process_delba(dev, mgmt, len);
+                       break;
                default:
                        if (net_ratelimit())
-                          printk(KERN_DEBUG "%s: received unsupported BACK\n",
+                          printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
                                        dev->name);
                        break;
                }
@@ -2098,10 +2538,10 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
                ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
                break;
        case IEEE80211_STYPE_ASSOC_RESP:
-               ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 0);
+               ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
                break;
        case IEEE80211_STYPE_REASSOC_RESP:
-               ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 1);
+               ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
                break;
        case IEEE80211_STYPE_DEAUTH:
                ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
@@ -2243,10 +2683,10 @@ void ieee80211_sta_work(struct work_struct *work)
        if (local->sta_sw_scanning || local->sta_hw_scanning)
                return;
 
-       if (sdata->type != IEEE80211_IF_TYPE_STA &&
-           sdata->type != IEEE80211_IF_TYPE_IBSS) {
+       if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
+           sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
                printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
-                      "(type=%d)\n", dev->name, sdata->type);
+                      "(type=%d)\n", dev->name, sdata->vif.type);
                return;
        }
        ifsta = &sdata->u.sta;
@@ -2341,7 +2781,7 @@ void ieee80211_sta_req_auth(struct net_device *dev,
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
        struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 
-       if (sdata->type != IEEE80211_IF_TYPE_STA)
+       if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
                return;
 
        if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
@@ -2399,7 +2839,7 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
        }
 
        spin_lock_bh(&local->sta_bss_lock);
-       freq = local->oper_channel->freq;
+       freq = local->oper_channel->center_freq;
        list_for_each_entry(bss, &local->sta_bss_list, list) {
                if (!(bss->capability & WLAN_CAPABILITY_ESS))
                        continue;
@@ -2430,7 +2870,7 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
        spin_unlock_bh(&local->sta_bss_lock);
 
        if (selected) {
-               ieee80211_set_channel(local, -1, selected->freq);
+               ieee80211_set_freq(local, selected->freq);
                if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
                        ieee80211_sta_set_ssid(dev, selected->ssid,
                                               selected->ssid_len);
@@ -2463,11 +2903,12 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
        struct sk_buff *skb;
        struct ieee80211_mgmt *mgmt;
        struct ieee80211_tx_control control;
-       struct ieee80211_rate *rate;
-       struct ieee80211_hw_mode *mode;
-       struct rate_control_extra extra;
+       struct rate_selection ratesel;
        u8 *pos;
        struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_supported_band *sband;
+
+       sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
 
        /* Remove possible STA entries from other IBSS networks. */
        sta_info_flush(local, NULL);
@@ -2487,12 +2928,11 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
        sdata->drop_unencrypted = bss->capability &
                WLAN_CAPABILITY_PRIVACY ? 1 : 0;
 
-       res = ieee80211_set_channel(local, -1, bss->freq);
+       res = ieee80211_set_freq(local, bss->freq);
 
-       if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) {
-               printk(KERN_DEBUG "%s: IBSS not allowed on channel %d "
-                      "(%d MHz)\n", dev->name, local->hw.conf.channel,
-                      local->hw.conf.freq);
+       if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
+               printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
+                      "%d MHz\n", dev->name, local->oper_channel->center_freq);
                return -1;
        }
 
@@ -2529,10 +2969,12 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
                *pos++ = rates;
                memcpy(pos, bss->supp_rates, rates);
 
-               pos = skb_put(skb, 2 + 1);
-               *pos++ = WLAN_EID_DS_PARAMS;
-               *pos++ = 1;
-               *pos++ = bss->channel;
+               if (bss->band == IEEE80211_BAND_2GHZ) {
+                       pos = skb_put(skb, 2 + 1);
+                       *pos++ = WLAN_EID_DS_PARAMS;
+                       *pos++ = 1;
+                       *pos++ = ieee80211_frequency_to_channel(bss->freq);
+               }
 
                pos = skb_put(skb, 2 + 2);
                *pos++ = WLAN_EID_IBSS_PARAMS;
@@ -2550,20 +2992,18 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
                }
 
                memset(&control, 0, sizeof(control));
-               memset(&extra, 0, sizeof(extra));
-               extra.mode = local->oper_hw_mode;
-               rate = rate_control_get_rate(local, dev, skb, &extra);
-               if (!rate) {
+               rate_control_get_rate(dev, sband, skb, &ratesel);
+               if (!ratesel.rate) {
                        printk(KERN_DEBUG "%s: Failed to determine TX rate "
                               "for IBSS beacon\n", dev->name);
                        break;
                }
-               control.tx_rate =
-                       ((sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE) &&
-                       (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
-                       rate->val2 : rate->val;
+               control.vif = &sdata->vif;
+               control.tx_rate = ratesel.rate;
+               if (sdata->bss_conf.use_short_preamble &&
+                   ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
+                       control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
                control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
-               control.power_level = local->hw.conf.power_level;
                control.flags |= IEEE80211_TXCTL_NO_ACK;
                control.retry_limit = 1;
 
@@ -2588,14 +3028,14 @@ static int ieee80211_sta_join_ibss(struct net_device *dev,
                }
 
                rates = 0;
-               mode = local->oper_hw_mode;
+               sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
                for (i = 0; i < bss->supp_rates_len; i++) {
                        int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
-                       for (j = 0; j < mode->num_rates; j++)
-                               if (mode->rates[j].rate == bitrate)
+                       for (j = 0; j < sband->n_bitrates; j++)
+                               if (sband->bitrates[j].bitrate == bitrate)
                                        rates |= BIT(j);
                }
-               ifsta->supp_rates_bits = rates;
+               ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
        } while (0);
 
        if (skb) {
@@ -2619,7 +3059,7 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
        struct ieee80211_sta_bss *bss;
        struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       struct ieee80211_hw_mode *mode;
+       struct ieee80211_supported_band *sband;
        u8 bssid[ETH_ALEN], *pos;
        int i;
        DECLARE_MAC_BUF(mac);
@@ -2641,28 +3081,28 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
        printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
               dev->name, print_mac(mac, bssid));
 
-       bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel,
+       bss = ieee80211_rx_bss_add(dev, bssid,
+                                  local->hw.conf.channel->center_freq,
                                   sdata->u.sta.ssid, sdata->u.sta.ssid_len);
        if (!bss)
                return -ENOMEM;
 
-       mode = local->oper_hw_mode;
+       bss->band = local->hw.conf.channel->band;
+       sband = local->hw.wiphy->bands[bss->band];
 
        if (local->hw.conf.beacon_int == 0)
                local->hw.conf.beacon_int = 100;
        bss->beacon_int = local->hw.conf.beacon_int;
-       bss->hw_mode = local->hw.conf.phymode;
-       bss->freq = local->hw.conf.freq;
        bss->last_update = jiffies;
        bss->capability = WLAN_CAPABILITY_IBSS;
        if (sdata->default_key) {
                bss->capability |= WLAN_CAPABILITY_PRIVACY;
        } else
                sdata->drop_unencrypted = 0;
-       bss->supp_rates_len = mode->num_rates;
+       bss->supp_rates_len = sband->n_bitrates;
        pos = bss->supp_rates;
-       for (i = 0; i < mode->num_rates; i++) {
-               int rate = mode->rates[i].rate;
+       for (i = 0; i < sband->n_bitrates; i++) {
+               int rate = sband->bitrates[i].bitrate;
                *pos++ = (u8) (rate / 5);
        }
 
@@ -2711,7 +3151,8 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
               "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
        if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
-           (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel,
+           (bss = ieee80211_rx_bss_get(dev, bssid,
+                                       local->hw.conf.channel->center_freq,
                                        ifsta->ssid, ifsta->ssid_len))) {
                printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
                       " based on configured SSID\n",
@@ -2739,13 +3180,13 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
                if (time_after(jiffies, ifsta->ibss_join_req +
                               IEEE80211_IBSS_JOIN_TIMEOUT)) {
                        if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
-                           local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)
+                           (!(local->oper_channel->flags &
+                                       IEEE80211_CHAN_NO_IBSS)))
                                return ieee80211_sta_create_ibss(dev, ifsta);
                        if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
-                               printk(KERN_DEBUG "%s: IBSS not allowed on the"
-                                      " configured channel %d (%d MHz)\n",
-                                      dev->name, local->hw.conf.channel,
-                                      local->hw.conf.freq);
+                               printk(KERN_DEBUG "%s: IBSS not allowed on"
+                                      " %d MHz\n", dev->name,
+                                      local->hw.conf.channel->center_freq);
                        }
 
                        /* No IBSS found - decrease scan interval and continue
@@ -2764,7 +3205,7 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
 
 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
 {
-       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
        struct ieee80211_if_sta *ifsta;
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
 
@@ -2778,18 +3219,23 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
                int i;
 
                memset(&qparam, 0, sizeof(qparam));
-               /* TODO: are these ok defaults for all hw_modes? */
+
                qparam.aifs = 2;
-               qparam.cw_min =
-                       local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15;
+
+               if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
+                   !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
+                       qparam.cw_min = 31;
+               else
+                       qparam.cw_min = 15;
+
                qparam.cw_max = 1023;
                qparam.burst_time = 0;
+
                for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
-               {
                        local->ops->conf_tx(local_to_hw(local),
                                           i + IEEE80211_TX_QUEUE_DATA0,
                                           &qparam);
-               }
+
                /* IBSS uses different parameters for Beacon sending */
                qparam.cw_min++;
                qparam.cw_min *= 2;
@@ -2798,7 +3244,6 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
                                   IEEE80211_TX_QUEUE_BEACON, &qparam);
        }
 
-       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
        ifsta = &sdata->u.sta;
 
        if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
@@ -2811,7 +3256,7 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
                ifsta->flags |= IEEE80211_STA_SSID_SET;
        else
                ifsta->flags &= ~IEEE80211_STA_SSID_SET;
-       if (sdata->type == IEEE80211_IF_TYPE_IBSS &&
+       if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
            !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
                ifsta->ibss_join_req = jiffies;
                ifsta->state = IEEE80211_IBSS_SEARCH;
@@ -2929,7 +3374,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
                if (sdata->dev == local->mdev)
                        continue;
 
-               if (sdata->type == IEEE80211_IF_TYPE_STA) {
+               if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
                        if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
                                ieee80211_send_nullfunc(local, sdata, 0);
                        ieee80211_sta_timer((unsigned long)sdata);
@@ -2941,7 +3386,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
 
 done:
        sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       if (sdata->type == IEEE80211_IF_TYPE_IBSS) {
+       if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
                struct ieee80211_if_sta *ifsta = &sdata->u.sta;
                if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
                    (!ifsta->state == IEEE80211_IBSS_JOINED &&
@@ -2957,7 +3402,7 @@ void ieee80211_sta_scan_work(struct work_struct *work)
                container_of(work, struct ieee80211_local, scan_work.work);
        struct net_device *dev = local->scan_dev;
        struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       struct ieee80211_hw_mode *mode;
+       struct ieee80211_supported_band *sband;
        struct ieee80211_channel *chan;
        int skip;
        unsigned long next_delay = 0;
@@ -2967,44 +3412,47 @@ void ieee80211_sta_scan_work(struct work_struct *work)
 
        switch (local->scan_state) {
        case SCAN_SET_CHANNEL:
-               mode = local->scan_hw_mode;
-               if (local->scan_hw_mode->list.next == &local->modes_list &&
-                   local->scan_channel_idx >= mode->num_channels) {
+               /* get current scan band */
+               if (local->scan_band < IEEE80211_NUM_BANDS)
+                       sband = local->hw.wiphy->bands[local->scan_band];
+               else
+                       sband = NULL;
+
+               /* if we started at an unsupported one, advance */
+               while (!sband && local->scan_band < IEEE80211_NUM_BANDS) {
+                       local->scan_band++;
+                       sband = local->hw.wiphy->bands[local->scan_band];
+                       local->scan_channel_idx = 0;
+               }
+
+               if (!sband ||
+                   (local->scan_channel_idx >= sband->n_channels &&
+                    local->scan_band >= IEEE80211_NUM_BANDS)) {
                        ieee80211_scan_completed(local_to_hw(local));
                        return;
                }
-               skip = !(local->enabled_modes & (1 << mode->mode));
-               chan = &mode->channels[local->scan_channel_idx];
-               if (!(chan->flag & IEEE80211_CHAN_W_SCAN) ||
-                   (sdata->type == IEEE80211_IF_TYPE_IBSS &&
-                    !(chan->flag & IEEE80211_CHAN_W_IBSS)) ||
-                   (local->hw_modes & local->enabled_modes &
-                    (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
+               skip = 0;
+               chan = &sband->channels[local->scan_channel_idx];
+
+               if (chan->flags & IEEE80211_CHAN_DISABLED ||
+                   (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
+                    chan->flags & IEEE80211_CHAN_NO_IBSS))
                        skip = 1;
 
                if (!skip) {
-#if 0
-                       printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
-                              dev->name, chan->chan, chan->freq);
-#endif
-
                        local->scan_channel = chan;
                        if (ieee80211_hw_config(local)) {
-                               printk(KERN_DEBUG "%s: failed to set channel "
-                                      "%d (%d MHz) for scan\n", dev->name,
-                                      chan->chan, chan->freq);
+                               printk(KERN_DEBUG "%s: failed to set freq to "
+                                      "%d MHz for scan\n", dev->name,
+                                      chan->center_freq);
                                skip = 1;
                        }
                }
 
                local->scan_channel_idx++;
-               if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) {
-                       if (local->scan_hw_mode->list.next != &local->modes_list) {
-                               local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next,
-                                                                struct ieee80211_hw_mode,
-                                                                list);
-                               local->scan_channel_idx = 0;
-                       }
+               if (local->scan_channel_idx >= sband->n_channels) {
+                       local->scan_band++;
+                       local->scan_channel_idx = 0;
                }
 
                if (skip)
@@ -3015,13 +3463,14 @@ void ieee80211_sta_scan_work(struct work_struct *work)
                local->scan_state = SCAN_SEND_PROBE;
                break;
        case SCAN_SEND_PROBE:
-               if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) {
-                       ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
-                                                local->scan_ssid_len);
-                       next_delay = IEEE80211_CHANNEL_TIME;
-               } else
-                       next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
+               next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
                local->scan_state = SCAN_SET_CHANNEL;
+
+               if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
+                       break;
+               ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
+                                        local->scan_ssid_len);
+               next_delay = IEEE80211_CHANNEL_TIME;
                break;
        }
 
@@ -3084,7 +3533,7 @@ static int ieee80211_sta_start_scan(struct net_device *dev,
                        continue;
 
                netif_stop_queue(sdata->dev);
-               if (sdata->type == IEEE80211_IF_TYPE_STA &&
+               if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
                    (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
                        ieee80211_send_nullfunc(local, sdata, 1);
        }
@@ -3096,10 +3545,8 @@ static int ieee80211_sta_start_scan(struct net_device *dev,
        } else
                local->scan_ssid_len = 0;
        local->scan_state = SCAN_SET_CHANNEL;
-       local->scan_hw_mode = list_entry(local->modes_list.next,
-                                        struct ieee80211_hw_mode,
-                                        list);
        local->scan_channel_idx = 0;
+       local->scan_band = IEEE80211_BAND_2GHZ;
        local->scan_dev = dev;
 
        netif_tx_lock_bh(local->mdev);
@@ -3125,7 +3572,7 @@ int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
        struct ieee80211_if_sta *ifsta = &sdata->u.sta;
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
 
-       if (sdata->type != IEEE80211_IF_TYPE_STA)
+       if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
                return ieee80211_sta_start_scan(dev, ssid, ssid_len);
 
        if (local->sta_sw_scanning || local->sta_hw_scanning) {
@@ -3154,9 +3601,6 @@ ieee80211_sta_scan_result(struct net_device *dev,
                       bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
                return current_ev;
 
-       if (!(local->enabled_modes & (1 << bss->hw_mode)))
-               return current_ev;
-
        memset(&iwe, 0, sizeof(iwe));
        iwe.cmd = SIOCGIWAP;
        iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
@@ -3184,12 +3628,15 @@ ieee80211_sta_scan_result(struct net_device *dev,
 
        memset(&iwe, 0, sizeof(iwe));
        iwe.cmd = SIOCGIWFREQ;
-       iwe.u.freq.m = bss->channel;
-       iwe.u.freq.e = 0;
+       iwe.u.freq.m = bss->freq;
+       iwe.u.freq.e = 6;
        current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
                                          IW_EV_FREQ_LEN);
-       iwe.u.freq.m = bss->freq * 100000;
-       iwe.u.freq.e = 1;
+
+       memset(&iwe, 0, sizeof(iwe));
+       iwe.cmd = SIOCGIWFREQ;
+       iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
+       iwe.u.freq.e = 0;
        current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
                                          IW_EV_FREQ_LEN);
 
@@ -3332,7 +3779,8 @@ struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
        if (!sta)
                return NULL;
 
-       sta->supp_rates = sdata->u.sta.supp_rates_bits;
+       sta->supp_rates[local->hw.conf.channel->band] =
+               sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
 
        rate_control_rate_init(sta, local);
 
@@ -3348,8 +3796,8 @@ int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
        printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
               dev->name, reason);
 
-       if (sdata->type != IEEE80211_IF_TYPE_STA &&
-           sdata->type != IEEE80211_IF_TYPE_IBSS)
+       if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
+           sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
                return -EINVAL;
 
        ieee80211_send_deauth(dev, ifsta, reason);
@@ -3366,7 +3814,7 @@ int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
        printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
               dev->name, reason);
 
-       if (sdata->type != IEEE80211_IF_TYPE_STA)
+       if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
                return -EINVAL;
 
        if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))