Merge git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-2.6
[safe/jmp/linux-2.6] / net / mac80211 / ibss.c
index 9fe1f93..5bcde4c 100644 (file)
@@ -22,6 +22,7 @@
 #include <asm/unaligned.h>
 
 #include "ieee80211_i.h"
+#include "driver-ops.h"
 #include "rate.h"
 
 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
@@ -56,28 +57,28 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
         */
        if (auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1)
                ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0,
-                                   sdata->u.ibss.bssid, 0);
+                                   sdata->u.ibss.bssid, NULL, 0, 0);
 }
 
 static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
                                      const u8 *bssid, const int beacon_int,
                                      struct ieee80211_channel *chan,
-                                     const size_t supp_rates_len,
-                                     const u8 *supp_rates,
+                                     const u32 basic_rates,
                                      const u16 capability, u64 tsf)
 {
        struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
        struct ieee80211_local *local = sdata->local;
-       int rates, i, j;
+       int rates, i;
        struct sk_buff *skb;
        struct ieee80211_mgmt *mgmt;
        u8 *pos;
        struct ieee80211_supported_band *sband;
+       struct cfg80211_bss *bss;
+       u32 bss_change;
+       u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
 
-       if (local->ops->reset_tsf) {
-               /* Reset own TSF to allow time synchronization work. */
-               local->ops->reset_tsf(local_to_hw(local));
-       }
+       /* Reset own TSF to allow time synchronization work. */
+       drv_reset_tsf(local);
 
        skb = ifibss->skb;
        rcu_assign_pointer(ifibss->presp, NULL);
@@ -92,26 +93,33 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
 
        memcpy(ifibss->bssid, bssid, ETH_ALEN);
 
-       local->hw.conf.beacon_int = beacon_int >= 10 ? beacon_int : 10;
-
        sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
 
-       ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
-
        local->oper_channel = chan;
        local->oper_channel_type = NL80211_CHAN_NO_HT;
        ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
+
        sband = local->hw.wiphy->bands[chan->band];
 
+       /* build supported rates array */
+       pos = supp_rates;
+       for (i = 0; i < sband->n_bitrates; i++) {
+               int rate = sband->bitrates[i].bitrate;
+               u8 basic = 0;
+               if (basic_rates & BIT(i))
+                       basic = 0x80;
+               *pos++ = basic | (u8) (rate / 5);
+       }
+
        /* Build IBSS probe response */
        mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon));
        memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
        mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
                                          IEEE80211_STYPE_PROBE_RESP);
        memset(mgmt->da, 0xff, ETH_ALEN);
-       memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
+       memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
        memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
-       mgmt->u.beacon.beacon_int = cpu_to_le16(local->hw.conf.beacon_int);
+       mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int);
        mgmt->u.beacon.timestamp = cpu_to_le64(tsf);
        mgmt->u.beacon.capab_info = cpu_to_le16(capability);
 
@@ -120,7 +128,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
        *pos++ = ifibss->ssid_len;
        memcpy(pos, ifibss->ssid, ifibss->ssid_len);
 
-       rates = supp_rates_len;
+       rates = sband->n_bitrates;
        if (rates > 8)
                rates = 8;
        pos = skb_put(skb, 2 + rates);
@@ -142,8 +150,8 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
        *pos++ = 0;
        *pos++ = 0;
 
-       if (supp_rates_len > 8) {
-               rates = supp_rates_len - 8;
+       if (sband->n_bitrates > 8) {
+               rates = sband->n_bitrates - 8;
                pos = skb_put(skb, 2 + rates);
                *pos++ = WLAN_EID_EXT_SUPP_RATES;
                *pos++ = rates;
@@ -156,37 +164,62 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
 
        rcu_assign_pointer(ifibss->presp, skb);
 
-       ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON |
-                                  IEEE80211_IFCC_BEACON_ENABLED);
+       sdata->vif.bss_conf.beacon_int = beacon_int;
+       bss_change = BSS_CHANGED_BEACON_INT;
+       bss_change |= ieee80211_reset_erp_info(sdata);
+       bss_change |= BSS_CHANGED_BSSID;
+       bss_change |= BSS_CHANGED_BEACON;
+       bss_change |= BSS_CHANGED_BEACON_ENABLED;
+       ieee80211_bss_info_change_notify(sdata, bss_change);
 
-       rates = 0;
-       for (i = 0; i < supp_rates_len; i++) {
-               int bitrate = (supp_rates[i] & 0x7f) * 5;
-               for (j = 0; j < sband->n_bitrates; j++)
-                       if (sband->bitrates[j].bitrate == bitrate)
-                               rates |= BIT(j);
-       }
-
-       ieee80211_sta_def_wmm_params(sdata, supp_rates_len, supp_rates);
+       ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates);
 
        ifibss->state = IEEE80211_IBSS_MLME_JOINED;
        mod_timer(&ifibss->timer,
                  round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
 
-       cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel,
-                                 mgmt, skb->len, 0, GFP_KERNEL);
+       bss = cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel,
+                                       mgmt, skb->len, 0, GFP_KERNEL);
+       cfg80211_put_bss(bss);
        cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
 }
 
 static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
                                    struct ieee80211_bss *bss)
 {
-       __ieee80211_sta_join_ibss(sdata, bss->cbss.bssid,
-                                 bss->cbss.beacon_interval,
-                                 bss->cbss.channel,
-                                 bss->supp_rates_len, bss->supp_rates,
-                                 bss->cbss.capability,
-                                 bss->cbss.tsf);
+       struct cfg80211_bss *cbss =
+               container_of((void *)bss, struct cfg80211_bss, priv);
+       struct ieee80211_supported_band *sband;
+       u32 basic_rates;
+       int i, j;
+       u16 beacon_int = cbss->beacon_interval;
+
+       if (beacon_int < 10)
+               beacon_int = 10;
+
+       sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
+
+       basic_rates = 0;
+
+       for (i = 0; i < bss->supp_rates_len; i++) {
+               int rate = (bss->supp_rates[i] & 0x7f) * 5;
+               bool is_basic = !!(bss->supp_rates[i] & 0x80);
+
+               for (j = 0; j < sband->n_bitrates; j++) {
+                       if (sband->bitrates[j].bitrate == rate) {
+                               if (is_basic)
+                                       basic_rates |= BIT(j);
+                               break;
+                       }
+               }
+       }
+
+       __ieee80211_sta_join_ibss(sdata, cbss->bssid,
+                                 beacon_int,
+                                 cbss->channel,
+                                 basic_rates,
+                                 cbss->capability,
+                                 cbss->tsf);
 }
 
 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
@@ -198,6 +231,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
 {
        struct ieee80211_local *local = sdata->local;
        int freq;
+       struct cfg80211_bss *cbss;
        struct ieee80211_bss *bss;
        struct sta_info *sta;
        struct ieee80211_channel *channel;
@@ -221,7 +255,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
 
                rcu_read_lock();
 
-               sta = sta_info_get(local, mgmt->sa);
+               sta = sta_info_get(sdata, mgmt->sa);
                if (sta) {
                        u32 prev_rates;
 
@@ -235,7 +269,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
                                printk(KERN_DEBUG "%s: updated supp_rates set "
                                    "for %pM based on beacon info (0x%llx | "
                                    "0x%llx -> 0x%llx)\n",
-                                   sdata->dev->name,
+                                   sdata->name,
                                    sta->sta.addr,
                                    (unsigned long long) prev_rates,
                                    (unsigned long long) supp_rates,
@@ -252,8 +286,10 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
        if (!bss)
                return;
 
+       cbss = container_of((void *)bss, struct cfg80211_bss, priv);
+
        /* was just updated in ieee80211_bss_info_update */
-       beacon_timestamp = bss->cbss.tsf;
+       beacon_timestamp = cbss->tsf;
 
        /* check if we need to merge IBSS */
 
@@ -266,11 +302,11 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
                goto put_bss;
 
        /* not an IBSS */
-       if (!(bss->cbss.capability & WLAN_CAPABILITY_IBSS))
+       if (!(cbss->capability & WLAN_CAPABILITY_IBSS))
                goto put_bss;
 
        /* different channel */
-       if (bss->cbss.channel != local->oper_channel)
+       if (cbss->channel != local->oper_channel)
                goto put_bss;
 
        /* different SSID */
@@ -280,7 +316,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
                goto put_bss;
 
        /* same BSSID */
-       if (memcmp(bss->cbss.bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0)
+       if (memcmp(cbss->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0)
                goto put_bss;
 
        if (rx_status->flag & RX_FLAG_TSFT) {
@@ -307,12 +343,13 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
                                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;
+       } else {
+               /*
+                * second best option: get current TSF
+                * (will return -1 if not supported)
+                */
+               rx_timestamp = drv_get_tsf(local);
+       }
 
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
        printk(KERN_DEBUG "RX beacon SA=%pM BSSID="
@@ -332,7 +369,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
                printk(KERN_DEBUG "%s: beacon TSF higher than "
                       "local TSF - IBSS merge with BSSID %pM\n",
-                      sdata->dev->name, mgmt->bssid);
+                      sdata->name, mgmt->bssid);
 #endif
                ieee80211_sta_join_ibss(sdata, bss);
                ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates);
@@ -350,6 +387,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
 struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
                                        u8 *bssid,u8 *addr, u32 supp_rates)
 {
+       struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
        struct ieee80211_local *local = sdata->local;
        struct sta_info *sta;
        int band = local->hw.conf.channel->band;
@@ -361,16 +399,19 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
        if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
                if (net_ratelimit())
                        printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n",
-                              sdata->dev->name, addr);
+                              sdata->name, addr);
                return NULL;
        }
 
+       if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH)
+               return NULL;
+
        if (compare_ether_addr(bssid, sdata->u.ibss.bssid))
                return NULL;
 
 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
        printk(KERN_DEBUG "%s: Adding new IBSS station %pM (dev=%s)\n",
-              wiphy_name(local->hw.wiphy), addr, sdata->dev->name);
+              wiphy_name(local->hw.wiphy), addr, sdata->name);
 #endif
 
        sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
@@ -423,6 +464,10 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
 
        ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
 
+       if (time_before(jiffies, ifibss->last_scan_completed +
+                      IEEE80211_IBSS_MERGE_INTERVAL))
+               return;
+
        if (ieee80211_sta_active_ibss(sdata))
                return;
 
@@ -430,17 +475,9 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
                return;
 
        printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
-              "IBSS networks with same SSID (merge)\n", sdata->dev->name);
+              "IBSS networks with same SSID (merge)\n", sdata->name);
 
-       /* XXX maybe racy? */
-       if (sdata->local->scan_req)
-               return;
-
-       memcpy(sdata->local->int_scan_req.ssids[0].ssid,
-              ifibss->ssid, IEEE80211_MAX_SSID_LEN);
-       sdata->local->int_scan_req.ssids[0].ssid_len = ifibss->ssid_len;
-       if (ieee80211_request_scan(sdata, &sdata->local->int_scan_req))
-               ieee80211_scan_failed(sdata->local);
+       ieee80211_request_internal_scan(sdata, ifibss->ssid, ifibss->ssid_len);
 }
 
 static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
@@ -448,9 +485,7 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
        struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
        struct ieee80211_local *local = sdata->local;
        struct ieee80211_supported_band *sband;
-       u8 *pos;
        u8 bssid[ETH_ALEN];
-       u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
        u16 capability;
        int i;
 
@@ -462,82 +497,78 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
                 * random number generator get different BSSID. */
                get_random_bytes(bssid, ETH_ALEN);
                for (i = 0; i < ETH_ALEN; i++)
-                       bssid[i] ^= sdata->dev->dev_addr[i];
+                       bssid[i] ^= sdata->vif.addr[i];
                bssid[0] &= ~0x01;
                bssid[0] |= 0x02;
        }
 
        printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
-              sdata->dev->name, bssid);
+              sdata->name, bssid);
 
        sband = local->hw.wiphy->bands[ifibss->channel->band];
 
-       if (local->hw.conf.beacon_int == 0)
-               local->hw.conf.beacon_int = 100;
-
        capability = WLAN_CAPABILITY_IBSS;
 
-       if (sdata->default_key)
+       if (ifibss->privacy)
                capability |= WLAN_CAPABILITY_PRIVACY;
        else
                sdata->drop_unencrypted = 0;
 
-       pos = supp_rates;
-       for (i = 0; i < sband->n_bitrates; i++) {
-               int rate = sband->bitrates[i].bitrate;
-               *pos++ = (u8) (rate / 5);
-       }
-
-       __ieee80211_sta_join_ibss(sdata, bssid, local->hw.conf.beacon_int,
-                                 ifibss->channel, sband->n_bitrates,
-                                 supp_rates, capability, 0);
+       __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int,
+                                 ifibss->channel, 3, /* first two are basic */
+                                 capability, 0);
 }
 
 static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
 {
        struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
        struct ieee80211_local *local = sdata->local;
-       struct ieee80211_bss *bss;
+       struct cfg80211_bss *cbss;
        struct ieee80211_channel *chan = NULL;
        const u8 *bssid = NULL;
        int active_ibss;
+       u16 capability;
 
        active_ibss = ieee80211_sta_active_ibss(sdata);
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
        printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
-              sdata->dev->name, active_ibss);
+              sdata->name, active_ibss);
 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
 
        if (active_ibss)
                return;
 
+       capability = WLAN_CAPABILITY_IBSS;
+       if (ifibss->privacy)
+               capability |= WLAN_CAPABILITY_PRIVACY;
        if (ifibss->fixed_bssid)
                bssid = ifibss->bssid;
        if (ifibss->fixed_channel)
                chan = ifibss->channel;
        if (!is_zero_ether_addr(ifibss->bssid))
                bssid = ifibss->bssid;
-       bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan, bssid,
-                                      ifibss->ssid, ifibss->ssid_len,
-                                      WLAN_CAPABILITY_IBSS,
-                                      WLAN_CAPABILITY_IBSS);
+       cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid,
+                               ifibss->ssid, ifibss->ssid_len,
+                               WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY,
+                               capability);
 
+       if (cbss) {
+               struct ieee80211_bss *bss;
+
+               bss = (void *)cbss->priv;
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
-       if (bss)
                printk(KERN_DEBUG "   sta_find_ibss: selected %pM current "
-                      "%pM\n", bss->cbss.bssid, ifibss->bssid);
+                      "%pM\n", cbss->bssid, ifibss->bssid);
 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
 
-       if (bss && memcmp(ifibss->bssid, bss->cbss.bssid, ETH_ALEN)) {
                printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
                       " based on configured SSID\n",
-                      sdata->dev->name, bss->cbss.bssid);
+                      sdata->name, cbss->bssid);
 
                ieee80211_sta_join_ibss(sdata, bss);
                ieee80211_rx_bss_put(local, bss);
                return;
-       } else if (bss)
-               ieee80211_rx_bss_put(local, bss);
+       }
 
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
        printk(KERN_DEBUG "   did not try to join ibss\n");
@@ -551,18 +582,10 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
        } else if (time_after(jiffies, ifibss->last_scan_completed +
                                        IEEE80211_SCAN_INTERVAL)) {
                printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
-                      "join\n", sdata->dev->name);
-
-               /* XXX maybe racy? */
-               if (local->scan_req)
-                       return;
-
-               memcpy(local->int_scan_req.ssids[0].ssid,
-                      ifibss->ssid, IEEE80211_MAX_SSID_LEN);
-               local->int_scan_req.ssids[0].ssid_len =
-                       ifibss->ssid_len;
-               if (ieee80211_request_scan(sdata, &local->int_scan_req))
-                       ieee80211_scan_failed(local);
+                      "join\n", sdata->name);
+
+               ieee80211_request_internal_scan(sdata, ifibss->ssid,
+                                               ifibss->ssid_len);
        } else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) {
                int interval = IEEE80211_SCAN_INTERVAL;
 
@@ -573,7 +596,7 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
                                return;
                        }
                        printk(KERN_DEBUG "%s: IBSS not allowed on"
-                              " %d MHz\n", sdata->dev->name,
+                              " %d MHz\n", sdata->name,
                               local->hw.conf.channel->center_freq);
 
                        /* No IBSS found - decrease scan interval and continue
@@ -602,15 +625,12 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
            len < 24 + 2 || !ifibss->presp)
                return;
 
-       if (local->ops->tx_last_beacon)
-               tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
-       else
-               tx_last_beacon = 1;
+       tx_last_beacon = drv_tx_last_beacon(local);
 
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
        printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
               " (tx_last_beacon=%d)\n",
-              sdata->dev->name, mgmt->sa, mgmt->da,
+              sdata->name, mgmt->sa, mgmt->da,
               mgmt->bssid, tx_last_beacon);
 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
 
@@ -628,7 +648,7 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
                printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
                       "from %pM\n",
-                      sdata->dev->name, mgmt->sa);
+                      sdata->name, mgmt->sa);
 #endif
                return;
        }
@@ -648,9 +668,10 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
        memcpy(resp->da, mgmt->sa, ETH_ALEN);
 #ifdef CONFIG_MAC80211_IBSS_DEBUG
        printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
-              sdata->dev->name, resp->da);
+              sdata->name, resp->da);
 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
-       ieee80211_tx_skb(sdata, skb, 0);
+       IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
+       ieee80211_tx_skb(sdata, skb);
 }
 
 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
@@ -661,7 +682,7 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
        size_t baselen;
        struct ieee802_11_elems elems;
 
-       if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
+       if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
                return; /* ignore ProbeResp to foreign address */
 
        baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
@@ -699,7 +720,7 @@ static void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
        struct ieee80211_mgmt *mgmt;
        u16 fc;
 
-       rx_status = (struct ieee80211_rx_status *) skb->cb;
+       rx_status = IEEE80211_SKB_RXCB(skb);
        mgmt = (struct ieee80211_mgmt *) skb->data;
        fc = le16_to_cpu(mgmt->frame_control);
 
@@ -731,10 +752,13 @@ static void ieee80211_ibss_work(struct work_struct *work)
        struct ieee80211_if_ibss *ifibss;
        struct sk_buff *skb;
 
-       if (!netif_running(sdata->dev))
+       if (WARN_ON(local->suspended))
                return;
 
-       if (local->sw_scanning || local->hw_scanning)
+       if (!ieee80211_sdata_running(sdata))
+               return;
+
+       if (local->scanning)
                return;
 
        if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_ADHOC))
@@ -767,9 +791,35 @@ static void ieee80211_ibss_timer(unsigned long data)
        struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
        struct ieee80211_local *local = sdata->local;
 
+       if (local->quiescing) {
+               ifibss->timer_running = true;
+               return;
+       }
+
        set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request);
-       queue_work(local->hw.workqueue, &ifibss->work);
+       ieee80211_queue_work(&local->hw, &ifibss->work);
+}
+
+#ifdef CONFIG_PM
+void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata)
+{
+       struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
+
+       cancel_work_sync(&ifibss->work);
+       if (del_timer_sync(&ifibss->timer))
+               ifibss->timer_running = true;
+}
+
+void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata)
+{
+       struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
+
+       if (ifibss->timer_running) {
+               add_timer(&ifibss->timer);
+               ifibss->timer_running = false;
+       }
 }
+#endif
 
 void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
 {
@@ -788,21 +838,20 @@ void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
 
        mutex_lock(&local->iflist_mtx);
        list_for_each_entry(sdata, &local->interfaces, list) {
-               if (!netif_running(sdata->dev))
+               if (!ieee80211_sdata_running(sdata))
                        continue;
                if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
                        continue;
                if (!sdata->u.ibss.ssid_len)
                        continue;
                sdata->u.ibss.last_scan_completed = jiffies;
-               ieee80211_sta_find_ibss(sdata);
+               mod_timer(&sdata->u.ibss.timer, 0);
        }
        mutex_unlock(&local->iflist_mtx);
 }
 
 ieee80211_rx_result
-ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
-                      struct ieee80211_rx_status *rx_status)
+ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
 {
        struct ieee80211_local *local = sdata->local;
        struct ieee80211_mgmt *mgmt;
@@ -817,11 +866,10 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
        switch (fc & IEEE80211_FCTL_STYPE) {
        case IEEE80211_STYPE_PROBE_RESP:
        case IEEE80211_STYPE_BEACON:
-               memcpy(skb->cb, rx_status, sizeof(*rx_status));
        case IEEE80211_STYPE_PROBE_REQ:
        case IEEE80211_STYPE_AUTH:
                skb_queue_tail(&sdata->u.ibss.skb_queue, skb);
-               queue_work(local->hw.workqueue, &sdata->u.ibss.work);
+               ieee80211_queue_work(&local->hw, &sdata->u.ibss.work);
                return RX_QUEUED;
        }
 
@@ -839,6 +887,10 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
        } else
                sdata->u.ibss.fixed_bssid = false;
 
+       sdata->u.ibss.privacy = params->privacy;
+
+       sdata->vif.bss_conf.beacon_int = params->beacon_interval;
+
        sdata->u.ibss.channel = params->channel;
        sdata->u.ibss.fixed_channel = params->channel_fixed;
 
@@ -873,8 +925,10 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
 
        sdata->u.ibss.ssid_len = params->ssid_len;
 
+       ieee80211_recalc_idle(sdata->local);
+
        set_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
-       queue_work(sdata->local->hw.workqueue, &sdata->u.ibss.work);
+       ieee80211_queue_work(&sdata->local->hw, &sdata->u.ibss.work);
 
        return 0;
 }
@@ -894,12 +948,15 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
        kfree(sdata->u.ibss.ie);
        skb = sdata->u.ibss.presp;
        rcu_assign_pointer(sdata->u.ibss.presp, NULL);
-       ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED);
+       ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
        synchronize_rcu();
        kfree_skb(skb);
 
        skb_queue_purge(&sdata->u.ibss.skb_queue);
        memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
+       sdata->u.ibss.ssid_len = 0;
+
+       ieee80211_recalc_idle(sdata->local);
 
        return 0;
 }