/net/mac80211/ibss.c
C | 965 lines | 706 code | 176 blank | 83 comment | 110 complexity | 4ea87814a8888720b19741a53fe9b6a6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- * IBSS mode implementation
- * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
- * Copyright 2004, Instant802 Networks, Inc.
- * Copyright 2005, Devicescape Software, Inc.
- * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
- * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
- * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
- #include <linux/delay.h>
- #include <linux/slab.h>
- #include <linux/if_ether.h>
- #include <linux/skbuff.h>
- #include <linux/if_arp.h>
- #include <linux/etherdevice.h>
- #include <linux/rtnetlink.h>
- #include <net/mac80211.h>
- #include <asm/unaligned.h>
- #include "ieee80211_i.h"
- #include "driver-ops.h"
- #include "rate.h"
- #define IEEE80211_SCAN_INTERVAL (2 * HZ)
- #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
- #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
- #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
- #define IEEE80211_IBSS_MERGE_DELAY 0x400000
- #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
- #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
- static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
- struct ieee80211_mgmt *mgmt,
- size_t len)
- {
- u16 auth_alg, auth_transaction, status_code;
- if (len < 24 + 6)
- return;
- auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
- auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
- status_code = le16_to_cpu(mgmt->u.auth.status_code);
- /*
- * IEEE 802.11 standard does not require authentication in IBSS
- * networks and most implementations do not seem to use it.
- * However, try to reply to authentication attempts if someone
- * has actually implemented this.
- */
- if (auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1)
- ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 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 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;
- 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];
- /* Reset own TSF to allow time synchronization work. */
- drv_reset_tsf(local);
- skb = ifibss->skb;
- rcu_assign_pointer(ifibss->presp, NULL);
- synchronize_rcu();
- skb->data = skb->head;
- skb->len = 0;
- skb_reset_tail_pointer(skb);
- skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
- if (memcmp(ifibss->bssid, bssid, ETH_ALEN))
- sta_info_flush(sdata->local, sdata);
- memcpy(ifibss->bssid, bssid, ETH_ALEN);
- sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
- 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->vif.addr, ETH_ALEN);
- memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
- 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);
- pos = skb_put(skb, 2 + ifibss->ssid_len);
- *pos++ = WLAN_EID_SSID;
- *pos++ = ifibss->ssid_len;
- memcpy(pos, ifibss->ssid, ifibss->ssid_len);
- rates = sband->n_bitrates;
- if (rates > 8)
- rates = 8;
- pos = skb_put(skb, 2 + rates);
- *pos++ = WLAN_EID_SUPP_RATES;
- *pos++ = rates;
- memcpy(pos, supp_rates, rates);
- if (sband->band == IEEE80211_BAND_2GHZ) {
- pos = skb_put(skb, 2 + 1);
- *pos++ = WLAN_EID_DS_PARAMS;
- *pos++ = 1;
- *pos++ = ieee80211_frequency_to_channel(chan->center_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 (sband->n_bitrates > 8) {
- rates = sband->n_bitrates - 8;
- pos = skb_put(skb, 2 + rates);
- *pos++ = WLAN_EID_EXT_SUPP_RATES;
- *pos++ = rates;
- memcpy(pos, &supp_rates[8], rates);
- }
- if (ifibss->ie_len)
- memcpy(skb_put(skb, ifibss->ie_len),
- ifibss->ie, ifibss->ie_len);
- rcu_assign_pointer(ifibss->presp, skb);
- 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);
- 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));
- 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)
- {
- 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,
- struct ieee80211_mgmt *mgmt,
- size_t len,
- struct ieee80211_rx_status *rx_status,
- struct ieee802_11_elems *elems,
- bool beacon)
- {
- struct ieee80211_local *local = sdata->local;
- int freq;
- struct cfg80211_bss *cbss;
- struct ieee80211_bss *bss;
- struct sta_info *sta;
- struct ieee80211_channel *channel;
- u64 beacon_timestamp, rx_timestamp;
- u32 supp_rates = 0;
- enum ieee80211_band band = rx_status->band;
- if (elems->ds_params && elems->ds_params_len == 1)
- freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
- else
- freq = rx_status->freq;
-