mac80211: clean up mesh code
[deliverable/linux.git] / net / mac80211 / ieee80211_sta.c
index 2628222a5085f1f321f54b67f5b967f77eac67e7..9f933aeca719e0438dc7cba42fae290707c6cdbb 100644 (file)
 #include "ieee80211_i.h"
 #include "ieee80211_rate.h"
 #include "ieee80211_led.h"
+#include "mesh.h"
 
 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
 #define IEEE80211_AUTH_MAX_TRIES 3
 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
 #define IEEE80211_ASSOC_MAX_TRIES 3
 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
+#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
@@ -49,6 +51,7 @@
 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
+#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
 
 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
 
@@ -87,46 +90,8 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
                                     struct ieee80211_if_sta *ifsta);
 
 
-/* Parsed Information Elements */
-struct ieee802_11_elems {
-       /* pointers to IEs */
-       u8 *ssid;
-       u8 *supp_rates;
-       u8 *fh_params;
-       u8 *ds_params;
-       u8 *cf_params;
-       u8 *tim;
-       u8 *ibss_params;
-       u8 *challenge;
-       u8 *wpa;
-       u8 *rsn;
-       u8 *erp_info;
-       u8 *ext_supp_rates;
-       u8 *wmm_info;
-       u8 *wmm_param;
-       u8 *ht_cap_elem;
-       u8 *ht_info_elem;
-       /* length of them, respectively */
-       u8 ssid_len;
-       u8 supp_rates_len;
-       u8 fh_params_len;
-       u8 ds_params_len;
-       u8 cf_params_len;
-       u8 tim_len;
-       u8 ibss_params_len;
-       u8 challenge_len;
-       u8 wpa_len;
-       u8 rsn_len;
-       u8 erp_info_len;
-       u8 ext_supp_rates_len;
-       u8 wmm_info_len;
-       u8 wmm_param_len;
-       u8 ht_cap_elem_len;
-       u8 ht_info_elem_len;
-};
-
-static void ieee802_11_parse_elems(u8 *start, size_t len,
-                                  struct ieee802_11_elems *elems)
+void ieee802_11_parse_elems(u8 *start, size_t len,
+                           struct ieee802_11_elems *elems)
 {
        size_t left = len;
        u8 *pos = start;
@@ -215,6 +180,30 @@ static void ieee802_11_parse_elems(u8 *start, size_t len,
                        elems->ht_info_elem = pos;
                        elems->ht_info_elem_len = elen;
                        break;
+               case WLAN_EID_MESH_ID:
+                       elems->mesh_id = pos;
+                       elems->mesh_id_len = elen;
+                       break;
+               case WLAN_EID_MESH_CONFIG:
+                       elems->mesh_config = pos;
+                       elems->mesh_config_len = elen;
+                       break;
+               case WLAN_EID_PEER_LINK:
+                       elems->peer_link = pos;
+                       elems->peer_link_len = elen;
+                       break;
+               case WLAN_EID_PREQ:
+                       elems->preq = pos;
+                       elems->preq_len = elen;
+                       break;
+               case WLAN_EID_PREP:
+                       elems->prep = pos;
+                       elems->prep_len = elen;
+                       break;
+               case WLAN_EID_PERR:
+                       elems->perr = pos;
+                       elems->perr_len = elen;
+                       break;
                default:
                        break;
                }
@@ -227,12 +216,7 @@ static void ieee802_11_parse_elems(u8 *start, size_t len,
 
 static int ecw2cw(int ecw)
 {
-       int cw = 1;
-       while (ecw > 0) {
-               cw <<= 1;
-               ecw--;
-       }
-       return cw - 1;
+       return (1 << ecw) - 1;
 }
 
 static void ieee80211_sta_wmm_params(struct net_device *dev,
@@ -297,12 +281,13 @@ static void ieee80211_sta_wmm_params(struct net_device *dev,
                params.aifs = pos[0] & 0x0f;
                params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
                params.cw_min = ecw2cw(pos[1] & 0x0f);
-               /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
-               params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
+               params.txop = pos[2] | (pos[3] << 8);
+#ifdef CONFIG_MAC80211_DEBUG
                printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
-                      "cWmin=%d cWmax=%d burst=%d\n",
+                      "cWmin=%d cWmax=%d txop=%d\n",
                       dev->name, queue, aci, acm, params.aifs, params.cw_min,
-                      params.cw_max, params.burst_time);
+                      params.cw_max, params.txop);
+#endif
                /* TODO: handle ACM (block TX, fallback to next lowest allowed
                 * AC for now) */
                if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
@@ -505,8 +490,8 @@ static void ieee80211_set_disassoc(struct net_device *dev,
        ieee80211_set_associated(dev, ifsta, 0);
 }
 
-static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
-                            int encrypt)
+void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
+                     int encrypt)
 {
        struct ieee80211_sub_if_data *sdata;
        struct ieee80211_tx_packet_data *pkt_data;
@@ -1811,9 +1796,9 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
        if (!sta) {
                struct ieee80211_sta_bss *bss;
                sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL);
-               if (!sta) {
+               if (IS_ERR(sta)) {
                        printk(KERN_DEBUG "%s: failed to add STA entry for the"
-                              " AP\n", dev->name);
+                              " AP (error %ld)\n", dev->name, PTR_ERR(sta));
                        return;
                }
                bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
@@ -1828,7 +1813,8 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
        }
 
        sta->dev = dev;
-       sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP;
+       sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
+                     WLAN_STA_AUTHORIZED;
 
        rates = 0;
        basic_rates = 0;
@@ -1908,8 +1894,16 @@ static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
                                        struct ieee80211_sta_bss *bss)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-       bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)];
-       local->sta_bss_hash[STA_HASH(bss->bssid)] = bss;
+       u8 hash_idx;
+
+       if (bss_mesh_cfg(bss))
+               hash_idx = mesh_id_hash(bss_mesh_id(bss),
+                                       bss_mesh_id_len(bss));
+       else
+               hash_idx = STA_HASH(bss->bssid);
+
+       bss->hnext = local->sta_bss_hash[hash_idx];
+       local->sta_bss_hash[hash_idx] = bss;
 }
 
 
@@ -1962,7 +1956,6 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
        return bss;
 }
 
-
 static struct ieee80211_sta_bss *
 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
                     u8 *ssid, u8 ssid_len)
@@ -1973,7 +1966,8 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
        spin_lock_bh(&local->sta_bss_lock);
        bss = local->sta_bss_hash[STA_HASH(bssid)];
        while (bss) {
-               if (!memcmp(bss->bssid, bssid, ETH_ALEN) &&
+               if (!bss_mesh_cfg(bss) &&
+                   !memcmp(bss->bssid, bssid, ETH_ALEN) &&
                    bss->freq == freq &&
                    bss->ssid_len == ssid_len &&
                    (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
@@ -1986,6 +1980,72 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
        return bss;
 }
 
+#ifdef CONFIG_MAC80211_MESH
+static struct ieee80211_sta_bss *
+ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
+                         u8 *mesh_cfg, int freq)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sta_bss *bss;
+
+       spin_lock_bh(&local->sta_bss_lock);
+       bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
+       while (bss) {
+               if (bss_mesh_cfg(bss) &&
+                   !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
+                   bss->freq == freq &&
+                   mesh_id_len == bss->mesh_id_len &&
+                   (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
+                                                mesh_id_len))) {
+                       atomic_inc(&bss->users);
+                       break;
+               }
+               bss = bss->hnext;
+       }
+       spin_unlock_bh(&local->sta_bss_lock);
+       return bss;
+}
+
+static struct ieee80211_sta_bss *
+ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
+                         u8 *mesh_cfg, int freq)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sta_bss *bss;
+
+       bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
+       if (!bss)
+               return NULL;
+
+       bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
+       if (!bss->mesh_cfg) {
+               kfree(bss);
+               return NULL;
+       }
+
+       if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
+               bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
+               if (!bss->mesh_id) {
+                       kfree(bss->mesh_cfg);
+                       kfree(bss);
+                       return NULL;
+               }
+               memcpy(bss->mesh_id, mesh_id, mesh_id_len);
+       }
+
+       atomic_inc(&bss->users);
+       atomic_inc(&bss->users);
+       memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
+       bss->mesh_id_len = mesh_id_len;
+       bss->freq = freq;
+       spin_lock_bh(&local->sta_bss_lock);
+       /* TODO: order by RSSI? */
+       list_add_tail(&bss->list, &local->sta_bss_list);
+       __ieee80211_rx_bss_hash_add(dev, bss);
+       spin_unlock_bh(&local->sta_bss_lock);
+       return bss;
+}
+#endif
 
 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
 {
@@ -1993,6 +2053,8 @@ static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
        kfree(bss->rsn_ie);
        kfree(bss->wmm_ie);
        kfree(bss->ht_ie);
+       kfree(bss_mesh_id(bss));
+       kfree(bss_mesh_cfg(bss));
        kfree(bss);
 }
 
@@ -2030,6 +2092,201 @@ void ieee80211_rx_bss_list_deinit(struct net_device *dev)
 }
 
 
+static int ieee80211_sta_join_ibss(struct net_device *dev,
+                                  struct ieee80211_if_sta *ifsta,
+                                  struct ieee80211_sta_bss *bss)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       int res, rates, i, j;
+       struct sk_buff *skb;
+       struct ieee80211_mgmt *mgmt;
+       struct ieee80211_tx_control control;
+       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);
+
+       if (local->ops->reset_tsf) {
+               /* Reset own TSF to allow time synchronization work. */
+               local->ops->reset_tsf(local_to_hw(local));
+       }
+       memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
+       res = ieee80211_if_config(dev);
+       if (res)
+               return res;
+
+       local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       sdata->drop_unencrypted = bss->capability &
+               WLAN_CAPABILITY_PRIVACY ? 1 : 0;
+
+       res = ieee80211_set_freq(local, bss->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;
+       }
+
+       /* Set beacon template */
+       skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
+       do {
+               if (!skb)
+                       break;
+
+               skb_reserve(skb, local->hw.extra_tx_headroom);
+
+               mgmt = (struct ieee80211_mgmt *)
+                       skb_put(skb, 24 + sizeof(mgmt->u.beacon));
+               memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
+               mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+                                                  IEEE80211_STYPE_BEACON);
+               memset(mgmt->da, 0xff, ETH_ALEN);
+               memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+               memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
+               mgmt->u.beacon.beacon_int =
+                       cpu_to_le16(local->hw.conf.beacon_int);
+               mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
+
+               pos = skb_put(skb, 2 + ifsta->ssid_len);
+               *pos++ = WLAN_EID_SSID;
+               *pos++ = ifsta->ssid_len;
+               memcpy(pos, ifsta->ssid, ifsta->ssid_len);
+
+               rates = bss->supp_rates_len;
+               if (rates > 8)
+                       rates = 8;
+               pos = skb_put(skb, 2 + rates);
+               *pos++ = WLAN_EID_SUPP_RATES;
+               *pos++ = rates;
+               memcpy(pos, bss->supp_rates, rates);
+
+               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;
+               *pos++ = 2;
+               /* FIX: set ATIM window based on scan results */
+               *pos++ = 0;
+               *pos++ = 0;
+
+               if (bss->supp_rates_len > 8) {
+                       rates = bss->supp_rates_len - 8;
+                       pos = skb_put(skb, 2 + rates);
+                       *pos++ = WLAN_EID_EXT_SUPP_RATES;
+                       *pos++ = rates;
+                       memcpy(pos, &bss->supp_rates[8], rates);
+               }
+
+               memset(&control, 0, sizeof(control));
+               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.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.flags |= IEEE80211_TXCTL_NO_ACK;
+               control.retry_limit = 1;
+
+               ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
+               if (ifsta->probe_resp) {
+                       mgmt = (struct ieee80211_mgmt *)
+                               ifsta->probe_resp->data;
+                       mgmt->frame_control =
+                               IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+                                            IEEE80211_STYPE_PROBE_RESP);
+               } else {
+                       printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
+                              "template for IBSS\n", dev->name);
+               }
+
+               if (local->ops->beacon_update &&
+                   local->ops->beacon_update(local_to_hw(local),
+                                            skb, &control) == 0) {
+                       printk(KERN_DEBUG "%s: Configured IBSS beacon "
+                              "template\n", dev->name);
+                       skb = NULL;
+               }
+
+               rates = 0;
+               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 < sband->n_bitrates; j++)
+                               if (sband->bitrates[j].bitrate == bitrate)
+                                       rates |= BIT(j);
+               }
+               ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
+       } while (0);
+
+       if (skb) {
+               printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
+                      "template\n", dev->name);
+               dev_kfree_skb(skb);
+       }
+
+       ifsta->state = IEEE80211_IBSS_JOINED;
+       mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
+
+       ieee80211_rx_bss_put(dev, bss);
+
+       return res;
+}
+
+u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
+                           struct ieee802_11_elems *elems,
+                           enum ieee80211_band band)
+{
+       struct ieee80211_supported_band *sband;
+       struct ieee80211_rate *bitrates;
+       size_t num_rates;
+       u64 supp_rates;
+       int i, j;
+       sband = local->hw.wiphy->bands[band];
+
+       if (!sband) {
+               WARN_ON(1);
+               sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+       }
+
+       bitrates = sband->bitrates;
+       num_rates = sband->n_bitrates;
+       supp_rates = 0;
+       for (i = 0; i < elems->supp_rates_len +
+                    elems->ext_supp_rates_len; i++) {
+               u8 rate = 0;
+               int own_rate;
+               if (i < elems->supp_rates_len)
+                       rate = elems->supp_rates[i];
+               else if (elems->ext_supp_rates)
+                       rate = elems->ext_supp_rates
+                               [i - elems->supp_rates_len];
+               own_rate = 5 * (rate & 0x7f);
+               for (j = 0; j < num_rates; j++)
+                       if (bitrates[j].bitrate == own_rate)
+                               supp_rates |= BIT(j);
+       }
+       return supp_rates;
+}
+
+
 static void ieee80211_rx_bss_info(struct net_device *dev,
                                  struct ieee80211_mgmt *mgmt,
                                  size_t len,
@@ -2043,7 +2300,7 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
        struct ieee80211_sta_bss *bss;
        struct sta_info *sta;
        struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       u64 timestamp;
+       u64 beacon_timestamp, rx_timestamp;
        DECLARE_MAC_BUF(mac);
        DECLARE_MAC_BUF(mac2);
 
@@ -2060,68 +2317,24 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
        if (baselen > len)
                return;
 
-       timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
+       beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
+       ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
 
-       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;
-               u64 tsf;
-               if (local->ops->get_tsf)
-                       tsf = local->ops->get_tsf(local_to_hw(local));
-               else
-                       tsf = -1LLU;
-               if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
-                       printk(KERN_DEBUG "RX beacon SA=%s BSSID="
-                              "%s TSF=0x%llx BCN=0x%llx diff=%lld "
-                              "@%lu\n",
-                              print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid),
-                              (unsigned long long)tsf,
-                              (unsigned long long)timestamp,
-                              (unsigned long long)(tsf - timestamp),
-                              jiffies);
-                       last_tsf_debug = jiffies;
-               }
-#endif /* CONFIG_MAC80211_IBSS_DEBUG */
-       }
+       if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
+           elems.mesh_config && mesh_matches_local(&elems, dev)) {
+               u64 rates = ieee80211_sta_get_rates(local, &elems,
+                                               rx_status->band);
 
-       ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
+               mesh_neighbour_update(mgmt->sa, rates, dev,
+                                     mesh_peer_accepts_plinks(&elems, dev));
+       }
 
        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_supported_band *sband;
-               struct ieee80211_rate *bitrates;
-               size_t num_rates;
-               u64 supp_rates, prev_rates;
-               int i, j;
-
-               sband = local->hw.wiphy->bands[rx_status->band];
-
-               if (!sband) {
-                       WARN_ON(1);
-                       sband = local->hw.wiphy->bands[
-                                       local->hw.conf.channel->band];
-               }
-
-               bitrates = sband->bitrates;
-               num_rates = sband->n_bitrates;
-
-               supp_rates = 0;
-               for (i = 0; i < elems.supp_rates_len +
-                            elems.ext_supp_rates_len; i++) {
-                       u8 rate = 0;
-                       int own_rate;
-                       if (i < elems.supp_rates_len)
-                               rate = elems.supp_rates[i];
-                       else if (elems.ext_supp_rates)
-                               rate = elems.ext_supp_rates
-                                       [i - elems.supp_rates_len];
-                       own_rate = 5 * (rate & 0x7f);
-                       for (j = 0; j < num_rates; j++)
-                               if (bitrates[j].bitrate == own_rate)
-                                       supp_rates |= BIT(j);
-               }
+               u64 prev_rates;
+               u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
+                                                       rx_status->band);
 
                prev_rates = sta->supp_rates[rx_status->band];
                sta->supp_rates[rx_status->band] &= supp_rates;
@@ -2144,19 +2357,28 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
                sta_info_put(sta);
        }
 
-       if (!elems.ssid)
-               return;
-
        if (elems.ds_params && elems.ds_params_len == 1)
                freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
        else
                freq = rx_status->freq;
 
-       bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
-                                  elems.ssid, elems.ssid_len);
-       if (!bss) {
-               bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
+#ifdef CONFIG_MAC80211_MESH
+       if (elems.mesh_config)
+               bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
+                               elems.mesh_id_len, elems.mesh_config, freq);
+       else
+#endif
+               bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
                                           elems.ssid, elems.ssid_len);
+       if (!bss) {
+#ifdef CONFIG_MAC80211_MESH
+               if (elems.mesh_config)
+                       bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
+                               elems.mesh_id_len, elems.mesh_config, freq);
+               else
+#endif
+                       bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
+                                                  elems.ssid, elems.ssid_len);
                if (!bss)
                        return;
        } else {
@@ -2170,8 +2392,10 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
 
        bss->band = rx_status->band;
 
-       if (bss->probe_resp && beacon) {
-               /* Do not allow beacon to override data from Probe Response. */
+       if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
+           bss->probe_resp && beacon) {
+               /* STA mode:
+                * Do not allow beacon to override data from Probe Response. */
                ieee80211_rx_bss_put(dev, bss);
                return;
        }
@@ -2268,13 +2492,69 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
                bss->ht_ie_len = 0;
        }
 
-       bss->timestamp = timestamp;
+       bss->timestamp = beacon_timestamp;
        bss->last_update = jiffies;
        bss->rssi = rx_status->ssi;
        bss->signal = rx_status->signal;
        bss->noise = rx_status->noise;
        if (!beacon)
                bss->probe_resp++;
+
+       /* check if we need to merge IBSS */
+       if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
+           !local->sta_sw_scanning && !local->sta_hw_scanning &&
+           bss->capability & WLAN_CAPABILITY_IBSS &&
+           bss->freq == local->oper_channel->center_freq &&
+           elems.ssid_len == sdata->u.sta.ssid_len &&
+           memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
+               if (rx_status->flag & RX_FLAG_TSFT) {
+                       /* in order for correct IBSS merging we need mactime
+                        *
+                        * since mactime is defined as the time the first data
+                        * symbol of the frame hits the PHY, and the timestamp
+                        * of the beacon is defined as "the time that the data
+                        * symbol containing the first bit of the timestamp is
+                        * transmitted to the PHY plus the transmitting STA’s
+                        * delays through its local PHY from the MAC-PHY
+                        * interface to its interface with the WM"
+                        * (802.11 11.1.2) - equals the time this bit arrives at
+                        * the receiver - we have to take into account the
+                        * offset between the two.
+                        * e.g: at 1 MBit that means mactime is 192 usec earlier
+                        * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
+                        */
+                       int rate = local->hw.wiphy->bands[rx_status->band]->
+                                       bitrates[rx_status->rate_idx].bitrate;
+                       rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
+               } else if (local && local->ops && local->ops->get_tsf)
+                       /* second best option: get current TSF */
+                       rx_timestamp = local->ops->get_tsf(local_to_hw(local));
+               else
+                       /* can't merge without knowing the TSF */
+                       rx_timestamp = -1LLU;
+#ifdef CONFIG_MAC80211_IBSS_DEBUG
+               printk(KERN_DEBUG "RX beacon SA=%s BSSID="
+                      "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
+                      print_mac(mac, mgmt->sa),
+                      print_mac(mac2, mgmt->bssid),
+                      (unsigned long long)rx_timestamp,
+                      (unsigned long long)beacon_timestamp,
+                      (unsigned long long)(rx_timestamp - beacon_timestamp),
+                      jiffies);
+#endif /* CONFIG_MAC80211_IBSS_DEBUG */
+               if (beacon_timestamp > rx_timestamp) {
+#ifndef CONFIG_MAC80211_IBSS_DEBUG
+                       if (net_ratelimit())
+#endif
+                               printk(KERN_DEBUG "%s: beacon TSF higher than "
+                                      "local TSF - IBSS merge with BSSID %s\n",
+                                      dev->name, print_mac(mac, mgmt->bssid));
+                       ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
+                       ieee80211_ibss_add_sta(dev, NULL,
+                                              mgmt->bssid, mgmt->sa);
+               }
+       }
+
        ieee80211_rx_bss_put(dev, bss);
 }
 
@@ -2425,8 +2705,11 @@ static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
 static void ieee80211_rx_mgmt_action(struct net_device *dev,
                                     struct ieee80211_if_sta *ifsta,
                                     struct ieee80211_mgmt *mgmt,
-                                    size_t len)
+                                    size_t len,
+                                    struct ieee80211_rx_status *rx_status)
 {
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
        if (len < IEEE80211_MIN_ACTION_SIZE)
                return;
 
@@ -2458,7 +2741,18 @@ static void ieee80211_rx_mgmt_action(struct net_device *dev,
                        break;
                }
                break;
+       case PLINK_CATEGORY:
+               if (ieee80211_vif_is_mesh(&sdata->vif))
+                       mesh_rx_plink_frame(dev, mgmt, len, rx_status);
+               break;
+       case MESH_PATH_SEL_CATEGORY:
+               if (ieee80211_vif_is_mesh(&sdata->vif))
+                       mesh_rx_path_sel_frame(dev, mgmt, len);
+               break;
        default:
+               if (net_ratelimit())
+                       printk(KERN_DEBUG "%s: Rx unknown action frame - "
+                       "category=%d\n", dev->name, mgmt->u.action.category);
                break;
        }
 }
@@ -2485,13 +2779,13 @@ void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
        case IEEE80211_STYPE_PROBE_REQ:
        case IEEE80211_STYPE_PROBE_RESP:
        case IEEE80211_STYPE_BEACON:
+       case IEEE80211_STYPE_ACTION:
                memcpy(skb->cb, rx_status, sizeof(*rx_status));
        case IEEE80211_STYPE_AUTH:
        case IEEE80211_STYPE_ASSOC_RESP:
        case IEEE80211_STYPE_REASSOC_RESP:
        case IEEE80211_STYPE_DEAUTH:
        case IEEE80211_STYPE_DISASSOC:
-       case IEEE80211_STYPE_ACTION:
                skb_queue_tail(&ifsta->skb_queue, skb);
                queue_work(local->hw.workqueue, &ifsta->work);
                return;
@@ -2550,7 +2844,7 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
                ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
                break;
        case IEEE80211_STYPE_ACTION:
-               ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len);
+               ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
                break;
        }
 
@@ -2558,7 +2852,7 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
 }
 
 
-ieee80211_txrx_result
+ieee80211_rx_result
 ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
                      struct ieee80211_rx_status *rx_status)
 {
@@ -2566,31 +2860,31 @@ ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
        u16 fc;
 
        if (skb->len < 2)
-               return TXRX_DROP;
+               return RX_DROP_UNUSABLE;
 
        mgmt = (struct ieee80211_mgmt *) skb->data;
        fc = le16_to_cpu(mgmt->frame_control);
 
        if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
-               return TXRX_CONTINUE;
+               return RX_CONTINUE;
 
        if (skb->len < 24)
-               return TXRX_DROP;
+               return RX_DROP_MONITOR;
 
        if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
                if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
                        ieee80211_rx_mgmt_probe_resp(dev, mgmt,
                                                     skb->len, rx_status);
                        dev_kfree_skb(skb);
-                       return TXRX_QUEUED;
+                       return RX_QUEUED;
                } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
                        ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
                                                 rx_status);
                        dev_kfree_skb(skb);
-                       return TXRX_QUEUED;
+                       return RX_QUEUED;
                }
        }
-       return TXRX_CONTINUE;
+       return RX_CONTINUE;
 }
 
 
@@ -2615,7 +2909,7 @@ static int ieee80211_sta_active_ibss(struct net_device *dev)
 }
 
 
-static void ieee80211_sta_expire(struct net_device *dev)
+static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
 {
        struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
        struct sta_info *sta, *tmp;
@@ -2624,8 +2918,7 @@ static void ieee80211_sta_expire(struct net_device *dev)
 
        write_lock_bh(&local->sta_lock);
        list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
-               if (time_after(jiffies, sta->last_rx +
-                              IEEE80211_IBSS_INACTIVITY_LIMIT)) {
+               if (time_after(jiffies, sta->last_rx + exp_time)) {
                        printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
                               dev->name, print_mac(mac, sta->addr));
                        __sta_info_get(sta);
@@ -2646,7 +2939,7 @@ static void ieee80211_sta_merge_ibss(struct net_device *dev,
 {
        mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
 
-       ieee80211_sta_expire(dev);
+       ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
        if (ieee80211_sta_active_ibss(dev))
                return;
 
@@ -2656,6 +2949,36 @@ static void ieee80211_sta_merge_ibss(struct net_device *dev,
 }
 
 
+#ifdef CONFIG_MAC80211_MESH
+static void ieee80211_mesh_housekeeping(struct net_device *dev,
+                          struct ieee80211_if_sta *ifsta)
+{
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       bool free_plinks;
+
+       ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
+       mesh_path_expire(dev);
+
+       free_plinks = mesh_plink_availables(sdata);
+       if (free_plinks != sdata->u.sta.accepting_plinks)
+               ieee80211_if_config_beacon(dev);
+
+       mod_timer(&ifsta->timer, jiffies +
+                       IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
+}
+
+
+void ieee80211_start_mesh(struct net_device *dev)
+{
+       struct ieee80211_if_sta *ifsta;
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       ifsta = &sdata->u.sta;
+       ifsta->state = IEEE80211_MESH_UP;
+       ieee80211_sta_timer((unsigned long)sdata);
+}
+#endif
+
+
 void ieee80211_sta_timer(unsigned long data)
 {
        struct ieee80211_sub_if_data *sdata =
@@ -2667,7 +2990,6 @@ void ieee80211_sta_timer(unsigned long data)
        queue_work(local->hw.workqueue, &ifsta->work);
 }
 
-
 void ieee80211_sta_work(struct work_struct *work)
 {
        struct ieee80211_sub_if_data *sdata =
@@ -2684,7 +3006,8 @@ void ieee80211_sta_work(struct work_struct *work)
                return;
 
        if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
-           sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
+           sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
+           sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
                printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
                       "(type=%d)\n", dev->name, sdata->vif.type);
                return;
@@ -2694,6 +3017,13 @@ void ieee80211_sta_work(struct work_struct *work)
        while ((skb = skb_dequeue(&ifsta->skb_queue)))
                ieee80211_sta_rx_queued_mgmt(dev, skb);
 
+#ifdef CONFIG_MAC80211_MESH
+       if (ifsta->preq_queue_len &&
+           time_after(jiffies,
+                      ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
+               mesh_path_start_discovery(dev);
+#endif
+
        if (ifsta->state != IEEE80211_AUTHENTICATE &&
            ifsta->state != IEEE80211_ASSOCIATE &&
            test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
@@ -2729,6 +3059,11 @@ void ieee80211_sta_work(struct work_struct *work)
        case IEEE80211_IBSS_JOINED:
                ieee80211_sta_merge_ibss(dev, ifsta);
                break;
+#ifdef CONFIG_MAC80211_MESH
+       case IEEE80211_MESH_UP:
+               ieee80211_mesh_housekeeping(dev, ifsta);
+               break;
+#endif
        default:
                printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
                       ifsta->state);
@@ -2894,164 +3229,6 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
        return -1;
 }
 
-static int ieee80211_sta_join_ibss(struct net_device *dev,
-                                  struct ieee80211_if_sta *ifsta,
-                                  struct ieee80211_sta_bss *bss)
-{
-       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-       int res, rates, i, j;
-       struct sk_buff *skb;
-       struct ieee80211_mgmt *mgmt;
-       struct ieee80211_tx_control control;
-       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);
-
-       if (local->ops->reset_tsf) {
-               /* Reset own TSF to allow time synchronization work. */
-               local->ops->reset_tsf(local_to_hw(local));
-       }
-       memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
-       res = ieee80211_if_config(dev);
-       if (res)
-               return res;
-
-       local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
-
-       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       sdata->drop_unencrypted = bss->capability &
-               WLAN_CAPABILITY_PRIVACY ? 1 : 0;
-
-       res = ieee80211_set_freq(local, bss->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;
-       }
-
-       /* Set beacon template based on scan results */
-       skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
-       do {
-               if (!skb)
-                       break;
-
-               skb_reserve(skb, local->hw.extra_tx_headroom);
-
-               mgmt = (struct ieee80211_mgmt *)
-                       skb_put(skb, 24 + sizeof(mgmt->u.beacon));
-               memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
-               mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
-                                                  IEEE80211_STYPE_BEACON);
-               memset(mgmt->da, 0xff, ETH_ALEN);
-               memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
-               memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
-               mgmt->u.beacon.beacon_int =
-                       cpu_to_le16(local->hw.conf.beacon_int);
-               mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
-
-               pos = skb_put(skb, 2 + ifsta->ssid_len);
-               *pos++ = WLAN_EID_SSID;
-               *pos++ = ifsta->ssid_len;
-               memcpy(pos, ifsta->ssid, ifsta->ssid_len);
-
-               rates = bss->supp_rates_len;
-               if (rates > 8)
-                       rates = 8;
-               pos = skb_put(skb, 2 + rates);
-               *pos++ = WLAN_EID_SUPP_RATES;
-               *pos++ = rates;
-               memcpy(pos, bss->supp_rates, rates);
-
-               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;
-               *pos++ = 2;
-               /* FIX: set ATIM window based on scan results */
-               *pos++ = 0;
-               *pos++ = 0;
-
-               if (bss->supp_rates_len > 8) {
-                       rates = bss->supp_rates_len - 8;
-                       pos = skb_put(skb, 2 + rates);
-                       *pos++ = WLAN_EID_EXT_SUPP_RATES;
-                       *pos++ = rates;
-                       memcpy(pos, &bss->supp_rates[8], rates);
-               }
-
-               memset(&control, 0, sizeof(control));
-               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.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.flags |= IEEE80211_TXCTL_NO_ACK;
-               control.retry_limit = 1;
-
-               ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
-               if (ifsta->probe_resp) {
-                       mgmt = (struct ieee80211_mgmt *)
-                               ifsta->probe_resp->data;
-                       mgmt->frame_control =
-                               IEEE80211_FC(IEEE80211_FTYPE_MGMT,
-                                            IEEE80211_STYPE_PROBE_RESP);
-               } else {
-                       printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
-                              "template for IBSS\n", dev->name);
-               }
-
-               if (local->ops->beacon_update &&
-                   local->ops->beacon_update(local_to_hw(local),
-                                            skb, &control) == 0) {
-                       printk(KERN_DEBUG "%s: Configured IBSS beacon "
-                              "template based on scan results\n", dev->name);
-                       skb = NULL;
-               }
-
-               rates = 0;
-               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 < sband->n_bitrates; j++)
-                               if (sband->bitrates[j].bitrate == bitrate)
-                                       rates |= BIT(j);
-               }
-               ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
-       } while (0);
-
-       if (skb) {
-               printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
-                      "template\n", dev->name);
-               dev_kfree_skb(skb);
-       }
-
-       ifsta->state = IEEE80211_IBSS_JOINED;
-       mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
-
-       ieee80211_rx_bss_put(dev, bss);
-
-       return res;
-}
-
 
 static int ieee80211_sta_create_ibss(struct net_device *dev,
                                     struct ieee80211_if_sta *ifsta)
@@ -3091,7 +3268,7 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
        sband = local->hw.wiphy->bands[bss->band];
 
        if (local->hw.conf.beacon_int == 0)
-               local->hw.conf.beacon_int = 100;
+               local->hw.conf.beacon_int = 10000;
        bss->beacon_int = local->hw.conf.beacon_int;
        bss->last_update = jiffies;
        bss->capability = WLAN_CAPABILITY_IBSS;
@@ -3229,7 +3406,7 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
                        qparam.cw_min = 15;
 
                qparam.cw_max = 1023;
-               qparam.burst_time = 0;
+               qparam.txop = 0;
 
                for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
                        local->ops->conf_tx(local_to_hw(local),
@@ -3380,6 +3557,9 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
                        ieee80211_sta_timer((unsigned long)sdata);
                }
 
+               if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
+                       ieee80211_sta_timer((unsigned long)sdata);
+
                netif_wake_queue(sdata->dev);
        }
        rcu_read_unlock();
@@ -3412,22 +3592,28 @@ void ieee80211_sta_scan_work(struct work_struct *work)
 
        switch (local->scan_state) {
        case SCAN_SET_CHANNEL:
-               /* get current scan band */
+               /*
+                * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
+                * after we successfully scanned the last channel of the last
+                * band (and the last band is supported by the hw)
+                */
                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) {
+               /*
+                * If we are at an unsupported band and have more bands
+                * left to scan, advance to the next supported one.
+                */
+               while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
                        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)) {
+               /* if no more bands/channels left, complete scan */
+               if (!sband || local->scan_channel_idx >= sband->n_channels) {
                        ieee80211_scan_completed(local_to_hw(local));
                        return;
                }
@@ -3449,8 +3635,14 @@ void ieee80211_sta_scan_work(struct work_struct *work)
                        }
                }
 
+               /* advance state machine to next channel/band */
                local->scan_channel_idx++;
                if (local->scan_channel_idx >= sband->n_channels) {
+                       /*
+                        * scan_band may end up == IEEE80211_NUM_BANDS, but
+                        * we'll catch that case above and complete the scan
+                        * if that is the case.
+                        */
                        local->scan_band++;
                        local->scan_channel_idx = 0;
                }
@@ -3610,15 +3802,25 @@ ieee80211_sta_scan_result(struct net_device *dev,
 
        memset(&iwe, 0, sizeof(iwe));
        iwe.cmd = SIOCGIWESSID;
-       iwe.u.data.length = bss->ssid_len;
-       iwe.u.data.flags = 1;
-       current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
-                                         bss->ssid);
+       if (bss_mesh_cfg(bss)) {
+               iwe.u.data.length = bss_mesh_id_len(bss);
+               iwe.u.data.flags = 1;
+               current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
+                                                 bss_mesh_id(bss));
+       } else {
+               iwe.u.data.length = bss->ssid_len;
+               iwe.u.data.flags = 1;
+               current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
+                                                 bss->ssid);
+       }
 
-       if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
+       if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS
+           || bss_mesh_cfg(bss))) {
                memset(&iwe, 0, sizeof(iwe));
                iwe.cmd = SIOCGIWMODE;
-               if (bss->capability & WLAN_CAPABILITY_ESS)
+               if (bss_mesh_cfg(bss))
+                       iwe.u.mode = IW_MODE_MESH;
+               else if (bss->capability & WLAN_CAPABILITY_ESS)
                        iwe.u.mode = IW_MODE_MASTER;
                else
                        iwe.u.mode = IW_MODE_ADHOC;
@@ -3707,6 +3909,28 @@ ieee80211_sta_scan_result(struct net_device *dev,
                }
        }
 
+       if (bss_mesh_cfg(bss)) {
+               char *buf;
+               u8 *cfg = bss_mesh_cfg(bss);
+               buf = kmalloc(200, GFP_ATOMIC);
+               if (buf) {
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = IWEVCUSTOM;
+                       sprintf(buf, "Mesh network (version %d)\n"
+                       "\t\t\tPath Selection Protocol ID: 0x%02X%02X%02X%02X\n"
+                       "\t\t\tPath Selection Metric ID: 0x%02X%02X%02X%02X\n"
+                       "\t\t\tCongestion Control Mode ID: 0x%02X%02X%02X%02X\n"
+                       "\t\t\tChannel Precedence: 0x%02X%02X%02X%02X",
+                       cfg[0], cfg[1], cfg[2], cfg[3], cfg[4], cfg[5], cfg[6],
+                       cfg[7], cfg[8], cfg[9], cfg[10], cfg[11], cfg[12],
+                       cfg[13], cfg[14], cfg[15], cfg[16]);
+                       iwe.u.data.length = strlen(buf);
+                       current_ev = iwe_stream_add_point(current_ev, end_buf,
+                                                         &iwe, buf);
+                       kfree(buf);
+               }
+       }
+
        return current_ev;
 }
 
@@ -3776,9 +4000,11 @@ struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
               wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
 
        sta = sta_info_add(local, dev, addr, GFP_ATOMIC);
-       if (!sta)
+       if (IS_ERR(sta))
                return NULL;
 
+       sta->flags |= WLAN_STA_AUTHORIZED;
+
        sta->supp_rates[local->hw.conf.channel->band] =
                sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
 
This page took 0.060681 seconds and 5 git commands to generate.