ibss.c
Go to the documentation of this file.
00001 /*
00002  * IBSS mode implementation
00003  * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
00004  * Copyright 2004, Instant802 Networks, Inc.
00005  * Copyright 2005, Devicescape Software, Inc.
00006  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
00007  * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
00008  * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License version 2 as
00012  * published by the Free Software Foundation.
00013  */
00014 
00015 #include <linux/delay.h>
00016 #include <linux/slab.h>
00017 #include <linux/if_ether.h>
00018 #include <linux/skbuff.h>
00019 #include <linux/if_arp.h>
00020 #include <linux/etherdevice.h>
00021 #include <linux/rtnetlink.h>
00022 #include <net/mac80211.h>
00023 
00024 #include "ieee80211_i.h"
00025 #include "driver-ops.h"
00026 #include "rate.h"
00027 
00028 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
00029 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
00030 #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
00031 
00032 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
00033 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
00034 
00035 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
00036 
00037 
00038 static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
00039                                       const u8 *bssid, const int beacon_int,
00040                                       struct ieee80211_channel *chan,
00041                                       const u32 basic_rates,
00042                                       const u16 capability, u64 tsf)
00043 {
00044         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00045         struct ieee80211_local *local = sdata->local;
00046         int rates, i;
00047         struct sk_buff *skb;
00048         struct ieee80211_mgmt *mgmt;
00049         u8 *pos;
00050         struct ieee80211_supported_band *sband;
00051         struct cfg80211_bss *bss;
00052         u32 bss_change;
00053         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
00054         enum nl80211_channel_type channel_type;
00055 
00056         lockdep_assert_held(&ifibss->mtx);
00057 
00058         /* Reset own TSF to allow time synchronization work. */
00059         drv_reset_tsf(local, sdata);
00060 
00061         skb = ifibss->skb;
00062         RCU_INIT_POINTER(ifibss->presp, NULL);
00063         synchronize_rcu();
00064         skb->data = skb->head;
00065         skb->len = 0;
00066         skb_reset_tail_pointer(skb);
00067         skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
00068 
00069         if (!ether_addr_equal(ifibss->bssid, bssid))
00070                 sta_info_flush(sdata->local, sdata);
00071 
00072         /* if merging, indicate to driver that we leave the old IBSS */
00073         if (sdata->vif.bss_conf.ibss_joined) {
00074                 sdata->vif.bss_conf.ibss_joined = false;
00075                 netif_carrier_off(sdata->dev);
00076                 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS);
00077         }
00078 
00079         memcpy(ifibss->bssid, bssid, ETH_ALEN);
00080 
00081         sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
00082 
00083         local->oper_channel = chan;
00084         channel_type = ifibss->channel_type;
00085         if (channel_type > NL80211_CHAN_HT20 &&
00086             !cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
00087                 channel_type = NL80211_CHAN_HT20;
00088         if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
00089                 /* can only fail due to HT40+/- mismatch */
00090                 channel_type = NL80211_CHAN_HT20;
00091                 WARN_ON(!ieee80211_set_channel_type(local, sdata,
00092                                                     NL80211_CHAN_HT20));
00093         }
00094         ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
00095 
00096         sband = local->hw.wiphy->bands[chan->band];
00097 
00098         /* build supported rates array */
00099         pos = supp_rates;
00100         for (i = 0; i < sband->n_bitrates; i++) {
00101                 int rate = sband->bitrates[i].bitrate;
00102                 u8 basic = 0;
00103                 if (basic_rates & BIT(i))
00104                         basic = 0x80;
00105                 *pos++ = basic | (u8) (rate / 5);
00106         }
00107 
00108         /* Build IBSS probe response */
00109         mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon));
00110         memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
00111         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
00112                                           IEEE80211_STYPE_PROBE_RESP);
00113         memset(mgmt->da, 0xff, ETH_ALEN);
00114         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
00115         memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
00116         mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int);
00117         mgmt->u.beacon.timestamp = cpu_to_le64(tsf);
00118         mgmt->u.beacon.capab_info = cpu_to_le16(capability);
00119 
00120         pos = skb_put(skb, 2 + ifibss->ssid_len);
00121         *pos++ = WLAN_EID_SSID;
00122         *pos++ = ifibss->ssid_len;
00123         memcpy(pos, ifibss->ssid, ifibss->ssid_len);
00124 
00125         rates = sband->n_bitrates;
00126         if (rates > 8)
00127                 rates = 8;
00128         pos = skb_put(skb, 2 + rates);
00129         *pos++ = WLAN_EID_SUPP_RATES;
00130         *pos++ = rates;
00131         memcpy(pos, supp_rates, rates);
00132 
00133         if (sband->band == IEEE80211_BAND_2GHZ) {
00134                 pos = skb_put(skb, 2 + 1);
00135                 *pos++ = WLAN_EID_DS_PARAMS;
00136                 *pos++ = 1;
00137                 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
00138         }
00139 
00140         pos = skb_put(skb, 2 + 2);
00141         *pos++ = WLAN_EID_IBSS_PARAMS;
00142         *pos++ = 2;
00143         /* FIX: set ATIM window based on scan results */
00144         *pos++ = 0;
00145         *pos++ = 0;
00146 
00147         if (sband->n_bitrates > 8) {
00148                 rates = sband->n_bitrates - 8;
00149                 pos = skb_put(skb, 2 + rates);
00150                 *pos++ = WLAN_EID_EXT_SUPP_RATES;
00151                 *pos++ = rates;
00152                 memcpy(pos, &supp_rates[8], rates);
00153         }
00154 
00155         if (ifibss->ie_len)
00156                 memcpy(skb_put(skb, ifibss->ie_len),
00157                        ifibss->ie, ifibss->ie_len);
00158 
00159         /* add HT capability and information IEs */
00160         if (channel_type && sband->ht_cap.ht_supported) {
00161                 pos = skb_put(skb, 4 +
00162                                    sizeof(struct ieee80211_ht_cap) +
00163                                    sizeof(struct ieee80211_ht_operation));
00164                 pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
00165                                                 sband->ht_cap.cap);
00166                 /*
00167                  * Note: According to 802.11n-2009 9.13.3.1, HT Protection
00168                  * field and RIFS Mode are reserved in IBSS mode, therefore
00169                  * keep them at 0
00170                  */
00171                 pos = ieee80211_ie_build_ht_oper(pos, &sband->ht_cap,
00172                                                  chan, channel_type, 0);
00173         }
00174 
00175         if (local->hw.queues >= IEEE80211_NUM_ACS) {
00176                 pos = skb_put(skb, 9);
00177                 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
00178                 *pos++ = 7; /* len */
00179                 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
00180                 *pos++ = 0x50;
00181                 *pos++ = 0xf2;
00182                 *pos++ = 2; /* WME */
00183                 *pos++ = 0; /* WME info */
00184                 *pos++ = 1; /* WME ver */
00185                 *pos++ = 0; /* U-APSD no in use */
00186         }
00187 
00188         rcu_assign_pointer(ifibss->presp, skb);
00189 
00190         sdata->vif.bss_conf.beacon_int = beacon_int;
00191         sdata->vif.bss_conf.basic_rates = basic_rates;
00192         bss_change = BSS_CHANGED_BEACON_INT;
00193         bss_change |= ieee80211_reset_erp_info(sdata);
00194         bss_change |= BSS_CHANGED_BSSID;
00195         bss_change |= BSS_CHANGED_BEACON;
00196         bss_change |= BSS_CHANGED_BEACON_ENABLED;
00197         bss_change |= BSS_CHANGED_BASIC_RATES;
00198         bss_change |= BSS_CHANGED_HT;
00199         bss_change |= BSS_CHANGED_IBSS;
00200         sdata->vif.bss_conf.ibss_joined = true;
00201         ieee80211_bss_info_change_notify(sdata, bss_change);
00202 
00203         ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates);
00204 
00205         ifibss->state = IEEE80211_IBSS_MLME_JOINED;
00206         mod_timer(&ifibss->timer,
00207                   round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
00208 
00209         bss = cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel,
00210                                         mgmt, skb->len, 0, GFP_KERNEL);
00211         cfg80211_put_bss(bss);
00212         netif_carrier_on(sdata->dev);
00213         cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
00214 }
00215 
00216 static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
00217                                     struct ieee80211_bss *bss)
00218 {
00219         struct cfg80211_bss *cbss =
00220                 container_of((void *)bss, struct cfg80211_bss, priv);
00221         struct ieee80211_supported_band *sband;
00222         u32 basic_rates;
00223         int i, j;
00224         u16 beacon_int = cbss->beacon_interval;
00225 
00226         lockdep_assert_held(&sdata->u.ibss.mtx);
00227 
00228         if (beacon_int < 10)
00229                 beacon_int = 10;
00230 
00231         sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
00232 
00233         basic_rates = 0;
00234 
00235         for (i = 0; i < bss->supp_rates_len; i++) {
00236                 int rate = (bss->supp_rates[i] & 0x7f) * 5;
00237                 bool is_basic = !!(bss->supp_rates[i] & 0x80);
00238 
00239                 for (j = 0; j < sband->n_bitrates; j++) {
00240                         if (sband->bitrates[j].bitrate == rate) {
00241                                 if (is_basic)
00242                                         basic_rates |= BIT(j);
00243                                 break;
00244                         }
00245                 }
00246         }
00247 
00248         __ieee80211_sta_join_ibss(sdata, cbss->bssid,
00249                                   beacon_int,
00250                                   cbss->channel,
00251                                   basic_rates,
00252                                   cbss->capability,
00253                                   cbss->tsf);
00254 }
00255 
00256 static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta,
00257                                                   bool auth)
00258         __acquires(RCU)
00259 {
00260         struct ieee80211_sub_if_data *sdata = sta->sdata;
00261         u8 addr[ETH_ALEN];
00262 
00263         memcpy(addr, sta->sta.addr, ETH_ALEN);
00264 
00265 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00266         wiphy_debug(sdata->local->hw.wiphy,
00267                     "Adding new IBSS station %pM (dev=%s)\n",
00268                     addr, sdata->name);
00269 #endif
00270 
00271         sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
00272         sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
00273         /* authorize the station only if the network is not RSN protected. If
00274          * not wait for the userspace to authorize it */
00275         if (!sta->sdata->u.ibss.control_port)
00276                 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
00277 
00278         rate_control_rate_init(sta);
00279 
00280         /* If it fails, maybe we raced another insertion? */
00281         if (sta_info_insert_rcu(sta))
00282                 return sta_info_get(sdata, addr);
00283         if (auth) {
00284 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00285                 printk(KERN_DEBUG "TX Auth SA=%pM DA=%pM BSSID=%pM"
00286                        "(auth_transaction=1)\n", sdata->vif.addr,
00287                        sdata->u.ibss.bssid, addr);
00288 #endif
00289                 ieee80211_send_auth(sdata, 1, WLAN_AUTH_OPEN, NULL, 0,
00290                                     addr, sdata->u.ibss.bssid, NULL, 0, 0);
00291         }
00292         return sta;
00293 }
00294 
00295 static struct sta_info *
00296 ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
00297                        const u8 *bssid, const u8 *addr,
00298                        u32 supp_rates, bool auth)
00299         __acquires(RCU)
00300 {
00301         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00302         struct ieee80211_local *local = sdata->local;
00303         struct sta_info *sta;
00304         int band = local->hw.conf.channel->band;
00305 
00306         /*
00307          * XXX: Consider removing the least recently used entry and
00308          *      allow new one to be added.
00309          */
00310         if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
00311                 net_dbg_ratelimited("%s: No room for a new IBSS STA entry %pM\n",
00312                                     sdata->name, addr);
00313                 rcu_read_lock();
00314                 return NULL;
00315         }
00316 
00317         if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) {
00318                 rcu_read_lock();
00319                 return NULL;
00320         }
00321 
00322         if (!ether_addr_equal(bssid, sdata->u.ibss.bssid)) {
00323                 rcu_read_lock();
00324                 return NULL;
00325         }
00326 
00327         sta = sta_info_alloc(sdata, addr, GFP_KERNEL);
00328         if (!sta) {
00329                 rcu_read_lock();
00330                 return NULL;
00331         }
00332 
00333         sta->last_rx = jiffies;
00334 
00335         /* make sure mandatory rates are always added */
00336         sta->sta.supp_rates[band] = supp_rates |
00337                         ieee80211_mandatory_rates(local, band);
00338 
00339         return ieee80211_ibss_finish_sta(sta, auth);
00340 }
00341 
00342 static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
00343                                         struct ieee80211_mgmt *mgmt,
00344                                         size_t len)
00345 {
00346         u16 auth_alg, auth_transaction;
00347 
00348         lockdep_assert_held(&sdata->u.ibss.mtx);
00349 
00350         if (len < 24 + 6)
00351                 return;
00352 
00353         auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
00354         auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
00355 
00356         if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1)
00357                 return;
00358 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00359         printk(KERN_DEBUG "%s: RX Auth SA=%pM DA=%pM BSSID=%pM."
00360                "(auth_transaction=%d)\n",
00361                sdata->name, mgmt->sa, mgmt->da, mgmt->bssid, auth_transaction);
00362 #endif
00363         sta_info_destroy_addr(sdata, mgmt->sa);
00364         ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, 0, false);
00365         rcu_read_unlock();
00366 
00367         /*
00368          * IEEE 802.11 standard does not require authentication in IBSS
00369          * networks and most implementations do not seem to use it.
00370          * However, try to reply to authentication attempts if someone
00371          * has actually implemented this.
00372          */
00373         ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0,
00374                             mgmt->sa, sdata->u.ibss.bssid, NULL, 0, 0);
00375 }
00376 
00377 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
00378                                   struct ieee80211_mgmt *mgmt,
00379                                   size_t len,
00380                                   struct ieee80211_rx_status *rx_status,
00381                                   struct ieee802_11_elems *elems,
00382                                   bool beacon)
00383 {
00384         struct ieee80211_local *local = sdata->local;
00385         int freq;
00386         struct cfg80211_bss *cbss;
00387         struct ieee80211_bss *bss;
00388         struct sta_info *sta;
00389         struct ieee80211_channel *channel;
00390         u64 beacon_timestamp, rx_timestamp;
00391         u32 supp_rates = 0;
00392         enum ieee80211_band band = rx_status->band;
00393         struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
00394         bool rates_updated = false;
00395 
00396         if (elems->ds_params && elems->ds_params_len == 1)
00397                 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
00398                                                       band);
00399         else
00400                 freq = rx_status->freq;
00401 
00402         channel = ieee80211_get_channel(local->hw.wiphy, freq);
00403 
00404         if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
00405                 return;
00406 
00407         if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
00408             ether_addr_equal(mgmt->bssid, sdata->u.ibss.bssid)) {
00409 
00410                 rcu_read_lock();
00411                 sta = sta_info_get(sdata, mgmt->sa);
00412 
00413                 if (elems->supp_rates) {
00414                         supp_rates = ieee80211_sta_get_rates(local, elems,
00415                                                              band, NULL);
00416                         if (sta) {
00417                                 u32 prev_rates;
00418 
00419                                 prev_rates = sta->sta.supp_rates[band];
00420                                 /* make sure mandatory rates are always added */
00421                                 sta->sta.supp_rates[band] = supp_rates |
00422                                         ieee80211_mandatory_rates(local, band);
00423 
00424                                 if (sta->sta.supp_rates[band] != prev_rates) {
00425 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00426                                         printk(KERN_DEBUG
00427                                                 "%s: updated supp_rates set "
00428                                                 "for %pM based on beacon"
00429                                                 "/probe_resp (0x%x -> 0x%x)\n",
00430                                                 sdata->name, sta->sta.addr,
00431                                                 prev_rates,
00432                                                 sta->sta.supp_rates[band]);
00433 #endif
00434                                         rates_updated = true;
00435                                 }
00436                         } else {
00437                                 rcu_read_unlock();
00438                                 sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid,
00439                                                 mgmt->sa, supp_rates, true);
00440                         }
00441                 }
00442 
00443                 if (sta && elems->wmm_info)
00444                         set_sta_flag(sta, WLAN_STA_WME);
00445 
00446                 if (sta && elems->ht_operation && elems->ht_cap_elem &&
00447                     sdata->u.ibss.channel_type != NL80211_CHAN_NO_HT) {
00448                         /* we both use HT */
00449                         struct ieee80211_sta_ht_cap sta_ht_cap_new;
00450                         enum nl80211_channel_type channel_type =
00451                                 ieee80211_ht_oper_to_channel_type(
00452                                                         elems->ht_operation);
00453 
00454                         ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
00455                                                           elems->ht_cap_elem,
00456                                                           &sta_ht_cap_new);
00457 
00458                         /*
00459                          * fall back to HT20 if we don't use or use
00460                          * the other extension channel
00461                          */
00462                         if (!(channel_type == NL80211_CHAN_HT40MINUS ||
00463                               channel_type == NL80211_CHAN_HT40PLUS) ||
00464                             channel_type != sdata->u.ibss.channel_type)
00465                                 sta_ht_cap_new.cap &=
00466                                         ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
00467 
00468                         if (memcmp(&sta->sta.ht_cap, &sta_ht_cap_new,
00469                                    sizeof(sta_ht_cap_new))) {
00470                                 memcpy(&sta->sta.ht_cap, &sta_ht_cap_new,
00471                                        sizeof(sta_ht_cap_new));
00472                                 rates_updated = true;
00473                         }
00474                 }
00475 
00476                 if (sta && rates_updated)
00477                         rate_control_rate_init(sta);
00478 
00479                 rcu_read_unlock();
00480         }
00481 
00482         bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
00483                                         channel, beacon);
00484         if (!bss)
00485                 return;
00486 
00487         cbss = container_of((void *)bss, struct cfg80211_bss, priv);
00488 
00489         /* was just updated in ieee80211_bss_info_update */
00490         beacon_timestamp = cbss->tsf;
00491 
00492         /* check if we need to merge IBSS */
00493 
00494         /* we use a fixed BSSID */
00495         if (sdata->u.ibss.fixed_bssid)
00496                 goto put_bss;
00497 
00498         /* not an IBSS */
00499         if (!(cbss->capability & WLAN_CAPABILITY_IBSS))
00500                 goto put_bss;
00501 
00502         /* different channel */
00503         if (cbss->channel != local->oper_channel)
00504                 goto put_bss;
00505 
00506         /* different SSID */
00507         if (elems->ssid_len != sdata->u.ibss.ssid_len ||
00508             memcmp(elems->ssid, sdata->u.ibss.ssid,
00509                                 sdata->u.ibss.ssid_len))
00510                 goto put_bss;
00511 
00512         /* same BSSID */
00513         if (ether_addr_equal(cbss->bssid, sdata->u.ibss.bssid))
00514                 goto put_bss;
00515 
00516         if (rx_status->flag & RX_FLAG_MACTIME_MPDU) {
00517                 /*
00518                  * For correct IBSS merging we need mactime; since mactime is
00519                  * defined as the time the first data symbol of the frame hits
00520                  * the PHY, and the timestamp of the beacon is defined as "the
00521                  * time that the data symbol containing the first bit of the
00522                  * timestamp is transmitted to the PHY plus the transmitting
00523                  * STA's delays through its local PHY from the MAC-PHY
00524                  * interface to its interface with the WM" (802.11 11.1.2)
00525                  * - equals the time this bit arrives at the receiver - we have
00526                  * to take into account the offset between the two.
00527                  *
00528                  * E.g. at 1 MBit that means mactime is 192 usec earlier
00529                  * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
00530                  */
00531                 int rate;
00532 
00533                 if (rx_status->flag & RX_FLAG_HT)
00534                         rate = 65; /* TODO: HT rates */
00535                 else
00536                         rate = local->hw.wiphy->bands[band]->
00537                                 bitrates[rx_status->rate_idx].bitrate;
00538 
00539                 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
00540         } else {
00541                 /*
00542                  * second best option: get current TSF
00543                  * (will return -1 if not supported)
00544                  */
00545                 rx_timestamp = drv_get_tsf(local, sdata);
00546         }
00547 
00548 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00549         printk(KERN_DEBUG "RX beacon SA=%pM BSSID="
00550                "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
00551                mgmt->sa, mgmt->bssid,
00552                (unsigned long long)rx_timestamp,
00553                (unsigned long long)beacon_timestamp,
00554                (unsigned long long)(rx_timestamp - beacon_timestamp),
00555                jiffies);
00556 #endif
00557 
00558         if (beacon_timestamp > rx_timestamp) {
00559 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00560                 printk(KERN_DEBUG "%s: beacon TSF higher than "
00561                        "local TSF - IBSS merge with BSSID %pM\n",
00562                        sdata->name, mgmt->bssid);
00563 #endif
00564                 ieee80211_sta_join_ibss(sdata, bss);
00565                 supp_rates = ieee80211_sta_get_rates(local, elems, band, NULL);
00566                 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa,
00567                                        supp_rates, true);
00568                 rcu_read_unlock();
00569         }
00570 
00571  put_bss:
00572         ieee80211_rx_bss_put(local, bss);
00573 }
00574 
00575 void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
00576                               const u8 *bssid, const u8 *addr,
00577                               u32 supp_rates)
00578 {
00579         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00580         struct ieee80211_local *local = sdata->local;
00581         struct sta_info *sta;
00582         int band = local->hw.conf.channel->band;
00583 
00584         /*
00585          * XXX: Consider removing the least recently used entry and
00586          *      allow new one to be added.
00587          */
00588         if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
00589                 net_dbg_ratelimited("%s: No room for a new IBSS STA entry %pM\n",
00590                                     sdata->name, addr);
00591                 return;
00592         }
00593 
00594         if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH)
00595                 return;
00596 
00597         if (!ether_addr_equal(bssid, sdata->u.ibss.bssid))
00598                 return;
00599 
00600         sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
00601         if (!sta)
00602                 return;
00603 
00604         sta->last_rx = jiffies;
00605 
00606         /* make sure mandatory rates are always added */
00607         sta->sta.supp_rates[band] = supp_rates |
00608                         ieee80211_mandatory_rates(local, band);
00609 
00610         spin_lock(&ifibss->incomplete_lock);
00611         list_add(&sta->list, &ifibss->incomplete_stations);
00612         spin_unlock(&ifibss->incomplete_lock);
00613         ieee80211_queue_work(&local->hw, &sdata->work);
00614 }
00615 
00616 static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
00617 {
00618         struct ieee80211_local *local = sdata->local;
00619         int active = 0;
00620         struct sta_info *sta;
00621 
00622         lockdep_assert_held(&sdata->u.ibss.mtx);
00623 
00624         rcu_read_lock();
00625 
00626         list_for_each_entry_rcu(sta, &local->sta_list, list) {
00627                 if (sta->sdata == sdata &&
00628                     time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
00629                                jiffies)) {
00630                         active++;
00631                         break;
00632                 }
00633         }
00634 
00635         rcu_read_unlock();
00636 
00637         return active;
00638 }
00639 
00640 /*
00641  * This function is called with state == IEEE80211_IBSS_MLME_JOINED
00642  */
00643 
00644 static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
00645 {
00646         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00647 
00648         lockdep_assert_held(&ifibss->mtx);
00649 
00650         mod_timer(&ifibss->timer,
00651                   round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
00652 
00653         ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
00654 
00655         if (time_before(jiffies, ifibss->last_scan_completed +
00656                        IEEE80211_IBSS_MERGE_INTERVAL))
00657                 return;
00658 
00659         if (ieee80211_sta_active_ibss(sdata))
00660                 return;
00661 
00662         if (ifibss->fixed_channel)
00663                 return;
00664 
00665         printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
00666                "IBSS networks with same SSID (merge)\n", sdata->name);
00667 
00668         ieee80211_request_internal_scan(sdata,
00669                         ifibss->ssid, ifibss->ssid_len, NULL);
00670 }
00671 
00672 static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
00673 {
00674         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00675         u8 bssid[ETH_ALEN];
00676         u16 capability;
00677         int i;
00678 
00679         lockdep_assert_held(&ifibss->mtx);
00680 
00681         if (ifibss->fixed_bssid) {
00682                 memcpy(bssid, ifibss->bssid, ETH_ALEN);
00683         } else {
00684                 /* Generate random, not broadcast, locally administered BSSID. Mix in
00685                  * own MAC address to make sure that devices that do not have proper
00686                  * random number generator get different BSSID. */
00687                 get_random_bytes(bssid, ETH_ALEN);
00688                 for (i = 0; i < ETH_ALEN; i++)
00689                         bssid[i] ^= sdata->vif.addr[i];
00690                 bssid[0] &= ~0x01;
00691                 bssid[0] |= 0x02;
00692         }
00693 
00694         printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
00695                sdata->name, bssid);
00696 
00697         capability = WLAN_CAPABILITY_IBSS;
00698 
00699         if (ifibss->privacy)
00700                 capability |= WLAN_CAPABILITY_PRIVACY;
00701         else
00702                 sdata->drop_unencrypted = 0;
00703 
00704         __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int,
00705                                   ifibss->channel, ifibss->basic_rates,
00706                                   capability, 0);
00707 }
00708 
00709 /*
00710  * This function is called with state == IEEE80211_IBSS_MLME_SEARCH
00711  */
00712 
00713 static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
00714 {
00715         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00716         struct ieee80211_local *local = sdata->local;
00717         struct cfg80211_bss *cbss;
00718         struct ieee80211_channel *chan = NULL;
00719         const u8 *bssid = NULL;
00720         int active_ibss;
00721         u16 capability;
00722 
00723         lockdep_assert_held(&ifibss->mtx);
00724 
00725         active_ibss = ieee80211_sta_active_ibss(sdata);
00726 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00727         printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
00728                sdata->name, active_ibss);
00729 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
00730 
00731         if (active_ibss)
00732                 return;
00733 
00734         capability = WLAN_CAPABILITY_IBSS;
00735         if (ifibss->privacy)
00736                 capability |= WLAN_CAPABILITY_PRIVACY;
00737         if (ifibss->fixed_bssid)
00738                 bssid = ifibss->bssid;
00739         if (ifibss->fixed_channel)
00740                 chan = ifibss->channel;
00741         if (!is_zero_ether_addr(ifibss->bssid))
00742                 bssid = ifibss->bssid;
00743         cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid,
00744                                 ifibss->ssid, ifibss->ssid_len,
00745                                 WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY,
00746                                 capability);
00747 
00748         if (cbss) {
00749                 struct ieee80211_bss *bss;
00750 
00751                 bss = (void *)cbss->priv;
00752 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00753                 printk(KERN_DEBUG "   sta_find_ibss: selected %pM current "
00754                        "%pM\n", cbss->bssid, ifibss->bssid);
00755 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
00756 
00757                 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
00758                        " based on configured SSID\n",
00759                        sdata->name, cbss->bssid);
00760 
00761                 ieee80211_sta_join_ibss(sdata, bss);
00762                 ieee80211_rx_bss_put(local, bss);
00763                 return;
00764         }
00765 
00766 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00767         printk(KERN_DEBUG "   did not try to join ibss\n");
00768 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
00769 
00770         /* Selected IBSS not found in current scan results - try to scan */
00771         if (time_after(jiffies, ifibss->last_scan_completed +
00772                                         IEEE80211_SCAN_INTERVAL)) {
00773                 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
00774                        "join\n", sdata->name);
00775 
00776                 ieee80211_request_internal_scan(sdata,
00777                                 ifibss->ssid, ifibss->ssid_len,
00778                                 ifibss->fixed_channel ? ifibss->channel : NULL);
00779         } else {
00780                 int interval = IEEE80211_SCAN_INTERVAL;
00781 
00782                 if (time_after(jiffies, ifibss->ibss_join_req +
00783                                IEEE80211_IBSS_JOIN_TIMEOUT)) {
00784                         if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) {
00785                                 ieee80211_sta_create_ibss(sdata);
00786                                 return;
00787                         }
00788                         printk(KERN_DEBUG "%s: IBSS not allowed on"
00789                                " %d MHz\n", sdata->name,
00790                                local->hw.conf.channel->center_freq);
00791 
00792                         /* No IBSS found - decrease scan interval and continue
00793                          * scanning. */
00794                         interval = IEEE80211_SCAN_INTERVAL_SLOW;
00795                 }
00796 
00797                 mod_timer(&ifibss->timer,
00798                           round_jiffies(jiffies + interval));
00799         }
00800 }
00801 
00802 static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
00803                                         struct sk_buff *req)
00804 {
00805         struct ieee80211_mgmt *mgmt = (void *)req->data;
00806         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00807         struct ieee80211_local *local = sdata->local;
00808         int tx_last_beacon, len = req->len;
00809         struct sk_buff *skb;
00810         struct ieee80211_mgmt *resp;
00811         struct sk_buff *presp;
00812         u8 *pos, *end;
00813 
00814         lockdep_assert_held(&ifibss->mtx);
00815 
00816         presp = rcu_dereference_protected(ifibss->presp,
00817                                           lockdep_is_held(&ifibss->mtx));
00818 
00819         if (ifibss->state != IEEE80211_IBSS_MLME_JOINED ||
00820             len < 24 + 2 || !presp)
00821                 return;
00822 
00823         tx_last_beacon = drv_tx_last_beacon(local);
00824 
00825 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00826         printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
00827                " (tx_last_beacon=%d)\n",
00828                sdata->name, mgmt->sa, mgmt->da,
00829                mgmt->bssid, tx_last_beacon);
00830 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
00831 
00832         if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da))
00833                 return;
00834 
00835         if (!ether_addr_equal(mgmt->bssid, ifibss->bssid) &&
00836             !is_broadcast_ether_addr(mgmt->bssid))
00837                 return;
00838 
00839         end = ((u8 *) mgmt) + len;
00840         pos = mgmt->u.probe_req.variable;
00841         if (pos[0] != WLAN_EID_SSID ||
00842             pos + 2 + pos[1] > end) {
00843 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00844                 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
00845                        "from %pM\n",
00846                        sdata->name, mgmt->sa);
00847 #endif
00848                 return;
00849         }
00850         if (pos[1] != 0 &&
00851             (pos[1] != ifibss->ssid_len ||
00852              memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) {
00853                 /* Ignore ProbeReq for foreign SSID */
00854                 return;
00855         }
00856 
00857         /* Reply with ProbeResp */
00858         skb = skb_copy(presp, GFP_KERNEL);
00859         if (!skb)
00860                 return;
00861 
00862         resp = (struct ieee80211_mgmt *) skb->data;
00863         memcpy(resp->da, mgmt->sa, ETH_ALEN);
00864 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00865         printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
00866                sdata->name, resp->da);
00867 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
00868         IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00869         ieee80211_tx_skb(sdata, skb);
00870 }
00871 
00872 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
00873                                          struct ieee80211_mgmt *mgmt,
00874                                          size_t len,
00875                                          struct ieee80211_rx_status *rx_status)
00876 {
00877         size_t baselen;
00878         struct ieee802_11_elems elems;
00879 
00880         baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
00881         if (baselen > len)
00882                 return;
00883 
00884         ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
00885                                 &elems);
00886 
00887         ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
00888 }
00889 
00890 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
00891                                      struct ieee80211_mgmt *mgmt,
00892                                      size_t len,
00893                                      struct ieee80211_rx_status *rx_status)
00894 {
00895         size_t baselen;
00896         struct ieee802_11_elems elems;
00897 
00898         /* Process beacon from the current BSS */
00899         baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
00900         if (baselen > len)
00901                 return;
00902 
00903         ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
00904 
00905         ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
00906 }
00907 
00908 void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
00909                                    struct sk_buff *skb)
00910 {
00911         struct ieee80211_rx_status *rx_status;
00912         struct ieee80211_mgmt *mgmt;
00913         u16 fc;
00914 
00915         rx_status = IEEE80211_SKB_RXCB(skb);
00916         mgmt = (struct ieee80211_mgmt *) skb->data;
00917         fc = le16_to_cpu(mgmt->frame_control);
00918 
00919         mutex_lock(&sdata->u.ibss.mtx);
00920 
00921         if (!sdata->u.ibss.ssid_len)
00922                 goto mgmt_out; /* not ready to merge yet */
00923 
00924         switch (fc & IEEE80211_FCTL_STYPE) {
00925         case IEEE80211_STYPE_PROBE_REQ:
00926                 ieee80211_rx_mgmt_probe_req(sdata, skb);
00927                 break;
00928         case IEEE80211_STYPE_PROBE_RESP:
00929                 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
00930                                              rx_status);
00931                 break;
00932         case IEEE80211_STYPE_BEACON:
00933                 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
00934                                          rx_status);
00935                 break;
00936         case IEEE80211_STYPE_AUTH:
00937                 ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len);
00938                 break;
00939         }
00940 
00941  mgmt_out:
00942         mutex_unlock(&sdata->u.ibss.mtx);
00943 }
00944 
00945 void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata)
00946 {
00947         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00948         struct sta_info *sta;
00949 
00950         mutex_lock(&ifibss->mtx);
00951 
00952         /*
00953          * Work could be scheduled after scan or similar
00954          * when we aren't even joined (or trying) with a
00955          * network.
00956          */
00957         if (!ifibss->ssid_len)
00958                 goto out;
00959 
00960         spin_lock_bh(&ifibss->incomplete_lock);
00961         while (!list_empty(&ifibss->incomplete_stations)) {
00962                 sta = list_first_entry(&ifibss->incomplete_stations,
00963                                        struct sta_info, list);
00964                 list_del(&sta->list);
00965                 spin_unlock_bh(&ifibss->incomplete_lock);
00966 
00967                 ieee80211_ibss_finish_sta(sta, true);
00968                 rcu_read_unlock();
00969                 spin_lock_bh(&ifibss->incomplete_lock);
00970         }
00971         spin_unlock_bh(&ifibss->incomplete_lock);
00972 
00973         switch (ifibss->state) {
00974         case IEEE80211_IBSS_MLME_SEARCH:
00975                 ieee80211_sta_find_ibss(sdata);
00976                 break;
00977         case IEEE80211_IBSS_MLME_JOINED:
00978                 ieee80211_sta_merge_ibss(sdata);
00979                 break;
00980         default:
00981                 WARN_ON(1);
00982                 break;
00983         }
00984 
00985  out:
00986         mutex_unlock(&ifibss->mtx);
00987 }
00988 
00989 static void ieee80211_ibss_timer(unsigned long data)
00990 {
00991         struct ieee80211_sub_if_data *sdata =
00992                 (struct ieee80211_sub_if_data *) data;
00993         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
00994         struct ieee80211_local *local = sdata->local;
00995 
00996         if (local->quiescing) {
00997                 ifibss->timer_running = true;
00998                 return;
00999         }
01000 
01001         ieee80211_queue_work(&local->hw, &sdata->work);
01002 }
01003 
01004 #ifdef CONFIG_PM
01005 void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata)
01006 {
01007         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
01008 
01009         if (del_timer_sync(&ifibss->timer))
01010                 ifibss->timer_running = true;
01011 }
01012 
01013 void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata)
01014 {
01015         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
01016 
01017         if (ifibss->timer_running) {
01018                 add_timer(&ifibss->timer);
01019                 ifibss->timer_running = false;
01020         }
01021 }
01022 #endif
01023 
01024 void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
01025 {
01026         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
01027 
01028         setup_timer(&ifibss->timer, ieee80211_ibss_timer,
01029                     (unsigned long) sdata);
01030         mutex_init(&ifibss->mtx);
01031         INIT_LIST_HEAD(&ifibss->incomplete_stations);
01032         spin_lock_init(&ifibss->incomplete_lock);
01033 }
01034 
01035 /* scan finished notification */
01036 void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
01037 {
01038         struct ieee80211_sub_if_data *sdata;
01039 
01040         mutex_lock(&local->iflist_mtx);
01041         list_for_each_entry(sdata, &local->interfaces, list) {
01042                 if (!ieee80211_sdata_running(sdata))
01043                         continue;
01044                 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
01045                         continue;
01046                 sdata->u.ibss.last_scan_completed = jiffies;
01047                 ieee80211_queue_work(&local->hw, &sdata->work);
01048         }
01049         mutex_unlock(&local->iflist_mtx);
01050 }
01051 
01052 int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
01053                         struct cfg80211_ibss_params *params)
01054 {
01055         struct sk_buff *skb;
01056         u32 changed = 0;
01057 
01058         skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
01059                             sizeof(struct ieee80211_hdr_3addr) +
01060                             12 /* struct ieee80211_mgmt.u.beacon */ +
01061                             2 + IEEE80211_MAX_SSID_LEN /* max SSID */ +
01062                             2 + 8 /* max Supported Rates */ +
01063                             3 /* max DS params */ +
01064                             4 /* IBSS params */ +
01065                             2 + (IEEE80211_MAX_SUPP_RATES - 8) +
01066                             2 + sizeof(struct ieee80211_ht_cap) +
01067                             2 + sizeof(struct ieee80211_ht_operation) +
01068                             params->ie_len);
01069         if (!skb)
01070                 return -ENOMEM;
01071 
01072         mutex_lock(&sdata->u.ibss.mtx);
01073 
01074         if (params->bssid) {
01075                 memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
01076                 sdata->u.ibss.fixed_bssid = true;
01077         } else
01078                 sdata->u.ibss.fixed_bssid = false;
01079 
01080         sdata->u.ibss.privacy = params->privacy;
01081         sdata->u.ibss.control_port = params->control_port;
01082         sdata->u.ibss.basic_rates = params->basic_rates;
01083         memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate,
01084                sizeof(params->mcast_rate));
01085 
01086         sdata->vif.bss_conf.beacon_int = params->beacon_interval;
01087 
01088         sdata->u.ibss.channel = params->channel;
01089         sdata->u.ibss.channel_type = params->channel_type;
01090         sdata->u.ibss.fixed_channel = params->channel_fixed;
01091 
01092         /* fix ourselves to that channel now already */
01093         if (params->channel_fixed) {
01094                 sdata->local->oper_channel = params->channel;
01095                 if (!ieee80211_set_channel_type(sdata->local, sdata,
01096                                                params->channel_type)) {
01097                         mutex_unlock(&sdata->u.ibss.mtx);
01098                         kfree_skb(skb);
01099                         return -EINVAL;
01100                 }
01101         }
01102 
01103         if (params->ie) {
01104                 sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len,
01105                                            GFP_KERNEL);
01106                 if (sdata->u.ibss.ie)
01107                         sdata->u.ibss.ie_len = params->ie_len;
01108         }
01109 
01110         sdata->u.ibss.skb = skb;
01111         sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
01112         sdata->u.ibss.ibss_join_req = jiffies;
01113 
01114         memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
01115         sdata->u.ibss.ssid_len = params->ssid_len;
01116 
01117         mutex_unlock(&sdata->u.ibss.mtx);
01118 
01119         mutex_lock(&sdata->local->mtx);
01120         ieee80211_recalc_idle(sdata->local);
01121         mutex_unlock(&sdata->local->mtx);
01122 
01123         /*
01124          * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is
01125          * reserved, but an HT STA shall protect HT transmissions as though
01126          * the HT Protection field were set to non-HT mixed mode.
01127          *
01128          * In an IBSS, the RIFS Mode field of the HT Operation element is
01129          * also reserved, but an HT STA shall operate as though this field
01130          * were set to 1.
01131          */
01132 
01133         sdata->vif.bss_conf.ht_operation_mode |=
01134                   IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
01135                 | IEEE80211_HT_PARAM_RIFS_MODE;
01136 
01137         changed |= BSS_CHANGED_HT;
01138         ieee80211_bss_info_change_notify(sdata, changed);
01139 
01140         ieee80211_queue_work(&sdata->local->hw, &sdata->work);
01141 
01142         return 0;
01143 }
01144 
01145 int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
01146 {
01147         struct sk_buff *skb;
01148         struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
01149         struct ieee80211_local *local = sdata->local;
01150         struct cfg80211_bss *cbss;
01151         u16 capability;
01152         int active_ibss;
01153         struct sta_info *sta;
01154 
01155         mutex_lock(&sdata->u.ibss.mtx);
01156 
01157         sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
01158         memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
01159         sdata->u.ibss.ssid_len = 0;
01160 
01161         active_ibss = ieee80211_sta_active_ibss(sdata);
01162 
01163         if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) {
01164                 capability = WLAN_CAPABILITY_IBSS;
01165 
01166                 if (ifibss->privacy)
01167                         capability |= WLAN_CAPABILITY_PRIVACY;
01168 
01169                 cbss = cfg80211_get_bss(local->hw.wiphy, ifibss->channel,
01170                                         ifibss->bssid, ifibss->ssid,
01171                                         ifibss->ssid_len, WLAN_CAPABILITY_IBSS |
01172                                         WLAN_CAPABILITY_PRIVACY,
01173                                         capability);
01174 
01175                 if (cbss) {
01176                         cfg80211_unlink_bss(local->hw.wiphy, cbss);
01177                         cfg80211_put_bss(cbss);
01178                 }
01179         }
01180 
01181         sta_info_flush(sdata->local, sdata);
01182 
01183         spin_lock_bh(&ifibss->incomplete_lock);
01184         while (!list_empty(&ifibss->incomplete_stations)) {
01185                 sta = list_first_entry(&ifibss->incomplete_stations,
01186                                        struct sta_info, list);
01187                 list_del(&sta->list);
01188                 spin_unlock_bh(&ifibss->incomplete_lock);
01189 
01190                 sta_info_free(local, sta);
01191                 spin_lock_bh(&ifibss->incomplete_lock);
01192         }
01193         spin_unlock_bh(&ifibss->incomplete_lock);
01194 
01195         netif_carrier_off(sdata->dev);
01196 
01197         /* remove beacon */
01198         kfree(sdata->u.ibss.ie);
01199         skb = rcu_dereference_protected(sdata->u.ibss.presp,
01200                                         lockdep_is_held(&sdata->u.ibss.mtx));
01201         RCU_INIT_POINTER(sdata->u.ibss.presp, NULL);
01202         sdata->vif.bss_conf.ibss_joined = false;
01203         ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
01204                                                 BSS_CHANGED_IBSS);
01205         synchronize_rcu();
01206         kfree_skb(skb);
01207 
01208         skb_queue_purge(&sdata->skb_queue);
01209 
01210         del_timer_sync(&sdata->u.ibss.timer);
01211 
01212         mutex_unlock(&sdata->u.ibss.mtx);
01213 
01214         mutex_lock(&local->mtx);
01215         ieee80211_recalc_idle(sdata->local);
01216         mutex_unlock(&local->mtx);
01217 
01218         return 0;
01219 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:10