Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * IBSS mode implementation |
| 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
| 4 | * Copyright 2004, Instant802 Networks, Inc. |
| 5 | * Copyright 2005, Devicescape Software, Inc. |
| 6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 8 | * Copyright 2009, Johannes Berg <johannes@sipsolutions.net> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 17 | #include <linux/if_ether.h> |
| 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/if_arp.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <linux/rtnetlink.h> |
| 22 | #include <net/mac80211.h> |
| 23 | #include <asm/unaligned.h> |
| 24 | |
| 25 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 26 | #include "driver-ops.h" |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 27 | #include "rate.h" |
| 28 | |
| 29 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) |
| 30 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) |
| 31 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) |
| 32 | |
| 33 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) |
Alina Friedrichsen | 4a332a3 | 2009-02-22 18:19:33 +0100 | [diff] [blame] | 34 | #define IEEE80211_IBSS_MERGE_DELAY 0x400000 |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 35 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
| 36 | |
| 37 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 |
| 38 | |
| 39 | |
| 40 | static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata, |
| 41 | struct ieee80211_mgmt *mgmt, |
| 42 | size_t len) |
| 43 | { |
| 44 | u16 auth_alg, auth_transaction, status_code; |
| 45 | |
| 46 | if (len < 24 + 6) |
| 47 | return; |
| 48 | |
| 49 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 50 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 51 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 52 | |
| 53 | /* |
| 54 | * IEEE 802.11 standard does not require authentication in IBSS |
| 55 | * networks and most implementations do not seem to use it. |
| 56 | * However, try to reply to authentication attempts if someone |
| 57 | * has actually implemented this. |
| 58 | */ |
| 59 | if (auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) |
| 60 | ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 61 | sdata->u.ibss.bssid, NULL, 0, 0); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 64 | static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
| 65 | const u8 *bssid, const int beacon_int, |
| 66 | struct ieee80211_channel *chan, |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 67 | const u32 basic_rates, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 68 | const u16 capability, u64 tsf) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 69 | { |
| 70 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 71 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 72 | int rates, i; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 73 | struct sk_buff *skb; |
| 74 | struct ieee80211_mgmt *mgmt; |
| 75 | u8 *pos; |
| 76 | struct ieee80211_supported_band *sband; |
Johannes Berg | f446d10 | 2009-10-28 15:12:32 +0100 | [diff] [blame] | 77 | struct cfg80211_bss *bss; |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 78 | u32 bss_change; |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 79 | u8 supp_rates[IEEE80211_MAX_SUPP_RATES]; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 80 | |
| 81 | /* Reset own TSF to allow time synchronization work. */ |
| 82 | drv_reset_tsf(local); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 83 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 84 | skb = ifibss->skb; |
| 85 | rcu_assign_pointer(ifibss->presp, NULL); |
| 86 | synchronize_rcu(); |
| 87 | skb->data = skb->head; |
| 88 | skb->len = 0; |
| 89 | skb_reset_tail_pointer(skb); |
| 90 | skb_reserve(skb, sdata->local->hw.extra_tx_headroom); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 91 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 92 | if (memcmp(ifibss->bssid, bssid, ETH_ALEN)) |
| 93 | sta_info_flush(sdata->local, sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 94 | |
Johannes Berg | 49b5c7f | 2010-04-29 21:34:01 +0200 | [diff] [blame] | 95 | /* if merging, indicate to driver that we leave the old IBSS */ |
| 96 | if (sdata->vif.bss_conf.ibss_joined) { |
| 97 | sdata->vif.bss_conf.ibss_joined = false; |
| 98 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS); |
| 99 | } |
| 100 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 101 | memcpy(ifibss->bssid, bssid, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 102 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 103 | sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 104 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 105 | local->oper_channel = chan; |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 106 | WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT)); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 107 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 108 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 109 | sband = local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 110 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 111 | /* build supported rates array */ |
| 112 | pos = supp_rates; |
| 113 | for (i = 0; i < sband->n_bitrates; i++) { |
| 114 | int rate = sband->bitrates[i].bitrate; |
| 115 | u8 basic = 0; |
| 116 | if (basic_rates & BIT(i)) |
| 117 | basic = 0x80; |
| 118 | *pos++ = basic | (u8) (rate / 5); |
| 119 | } |
| 120 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 121 | /* Build IBSS probe response */ |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 122 | mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 123 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); |
| 124 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 125 | IEEE80211_STYPE_PROBE_RESP); |
| 126 | memset(mgmt->da, 0xff, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 127 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 128 | memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 129 | mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int); |
Sujith | 707c1b4 | 2009-03-03 10:15:10 +0530 | [diff] [blame] | 130 | mgmt->u.beacon.timestamp = cpu_to_le64(tsf); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 131 | mgmt->u.beacon.capab_info = cpu_to_le16(capability); |
| 132 | |
| 133 | pos = skb_put(skb, 2 + ifibss->ssid_len); |
| 134 | *pos++ = WLAN_EID_SSID; |
| 135 | *pos++ = ifibss->ssid_len; |
| 136 | memcpy(pos, ifibss->ssid, ifibss->ssid_len); |
| 137 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 138 | rates = sband->n_bitrates; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 139 | if (rates > 8) |
| 140 | rates = 8; |
| 141 | pos = skb_put(skb, 2 + rates); |
| 142 | *pos++ = WLAN_EID_SUPP_RATES; |
| 143 | *pos++ = rates; |
| 144 | memcpy(pos, supp_rates, rates); |
| 145 | |
| 146 | if (sband->band == IEEE80211_BAND_2GHZ) { |
| 147 | pos = skb_put(skb, 2 + 1); |
| 148 | *pos++ = WLAN_EID_DS_PARAMS; |
| 149 | *pos++ = 1; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 150 | *pos++ = ieee80211_frequency_to_channel(chan->center_freq); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | pos = skb_put(skb, 2 + 2); |
| 154 | *pos++ = WLAN_EID_IBSS_PARAMS; |
| 155 | *pos++ = 2; |
| 156 | /* FIX: set ATIM window based on scan results */ |
| 157 | *pos++ = 0; |
| 158 | *pos++ = 0; |
| 159 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 160 | if (sband->n_bitrates > 8) { |
| 161 | rates = sband->n_bitrates - 8; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 162 | pos = skb_put(skb, 2 + rates); |
| 163 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 164 | *pos++ = rates; |
| 165 | memcpy(pos, &supp_rates[8], rates); |
| 166 | } |
| 167 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 168 | if (ifibss->ie_len) |
| 169 | memcpy(skb_put(skb, ifibss->ie_len), |
| 170 | ifibss->ie, ifibss->ie_len); |
| 171 | |
| 172 | rcu_assign_pointer(ifibss->presp, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 173 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 174 | sdata->vif.bss_conf.beacon_int = beacon_int; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame^] | 175 | sdata->vif.bss_conf.basic_rates = basic_rates; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 176 | bss_change = BSS_CHANGED_BEACON_INT; |
| 177 | bss_change |= ieee80211_reset_erp_info(sdata); |
| 178 | bss_change |= BSS_CHANGED_BSSID; |
| 179 | bss_change |= BSS_CHANGED_BEACON; |
| 180 | bss_change |= BSS_CHANGED_BEACON_ENABLED; |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 181 | bss_change |= BSS_CHANGED_IBSS; |
| 182 | sdata->vif.bss_conf.ibss_joined = true; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 183 | ieee80211_bss_info_change_notify(sdata, bss_change); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 184 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 185 | ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 186 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 187 | ifibss->state = IEEE80211_IBSS_MLME_JOINED; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 188 | mod_timer(&ifibss->timer, |
| 189 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 190 | |
Johannes Berg | f446d10 | 2009-10-28 15:12:32 +0100 | [diff] [blame] | 191 | bss = cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel, |
| 192 | mgmt, skb->len, 0, GFP_KERNEL); |
| 193 | cfg80211_put_bss(bss); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 194 | cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 197 | static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
| 198 | struct ieee80211_bss *bss) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 199 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 200 | struct cfg80211_bss *cbss = |
| 201 | container_of((void *)bss, struct cfg80211_bss, priv); |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 202 | struct ieee80211_supported_band *sband; |
| 203 | u32 basic_rates; |
| 204 | int i, j; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 205 | u16 beacon_int = cbss->beacon_interval; |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 206 | |
| 207 | if (beacon_int < 10) |
| 208 | beacon_int = 10; |
| 209 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 210 | sband = sdata->local->hw.wiphy->bands[cbss->channel->band]; |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 211 | |
| 212 | basic_rates = 0; |
| 213 | |
| 214 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 215 | int rate = (bss->supp_rates[i] & 0x7f) * 5; |
| 216 | bool is_basic = !!(bss->supp_rates[i] & 0x80); |
| 217 | |
| 218 | for (j = 0; j < sband->n_bitrates; j++) { |
| 219 | if (sband->bitrates[j].bitrate == rate) { |
| 220 | if (is_basic) |
| 221 | basic_rates |= BIT(j); |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 227 | __ieee80211_sta_join_ibss(sdata, cbss->bssid, |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 228 | beacon_int, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 229 | cbss->channel, |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 230 | basic_rates, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 231 | cbss->capability, |
| 232 | cbss->tsf); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
| 236 | struct ieee80211_mgmt *mgmt, |
| 237 | size_t len, |
| 238 | struct ieee80211_rx_status *rx_status, |
| 239 | struct ieee802_11_elems *elems, |
| 240 | bool beacon) |
| 241 | { |
| 242 | struct ieee80211_local *local = sdata->local; |
| 243 | int freq; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 244 | struct cfg80211_bss *cbss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 245 | struct ieee80211_bss *bss; |
| 246 | struct sta_info *sta; |
| 247 | struct ieee80211_channel *channel; |
| 248 | u64 beacon_timestamp, rx_timestamp; |
| 249 | u32 supp_rates = 0; |
| 250 | enum ieee80211_band band = rx_status->band; |
| 251 | |
| 252 | if (elems->ds_params && elems->ds_params_len == 1) |
| 253 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); |
| 254 | else |
| 255 | freq = rx_status->freq; |
| 256 | |
| 257 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 258 | |
| 259 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 260 | return; |
| 261 | |
| 262 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && elems->supp_rates && |
| 263 | memcmp(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) { |
| 264 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
| 265 | |
| 266 | rcu_read_lock(); |
| 267 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 268 | sta = sta_info_get(sdata, mgmt->sa); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 269 | if (sta) { |
| 270 | u32 prev_rates; |
| 271 | |
| 272 | prev_rates = sta->sta.supp_rates[band]; |
| 273 | /* make sure mandatory rates are always added */ |
| 274 | sta->sta.supp_rates[band] = supp_rates | |
| 275 | ieee80211_mandatory_rates(local, band); |
| 276 | |
Bruno Randolf | 09a08cf | 2010-03-03 18:45:42 +0900 | [diff] [blame] | 277 | if (sta->sta.supp_rates[band] != prev_rates) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 278 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 279 | printk(KERN_DEBUG "%s: updated supp_rates set " |
Bruno Randolf | 09a08cf | 2010-03-03 18:45:42 +0900 | [diff] [blame] | 280 | "for %pM based on beacon/probe_response " |
| 281 | "(0x%x -> 0x%x)\n", |
| 282 | sdata->name, sta->sta.addr, |
| 283 | prev_rates, sta->sta.supp_rates[band]); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 284 | #endif |
Bruno Randolf | 09a08cf | 2010-03-03 18:45:42 +0900 | [diff] [blame] | 285 | rate_control_rate_init(sta); |
| 286 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 287 | rcu_read_unlock(); |
| 288 | } else { |
| 289 | rcu_read_unlock(); |
| 290 | ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, |
| 291 | supp_rates, GFP_KERNEL); |
| 292 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
| 296 | channel, beacon); |
| 297 | if (!bss) |
| 298 | return; |
| 299 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 300 | cbss = container_of((void *)bss, struct cfg80211_bss, priv); |
| 301 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 302 | /* was just updated in ieee80211_bss_info_update */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 303 | beacon_timestamp = cbss->tsf; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 304 | |
| 305 | /* check if we need to merge IBSS */ |
| 306 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 307 | /* we use a fixed BSSID */ |
Benoit Papillault | a98bfec | 2010-01-17 22:45:24 +0100 | [diff] [blame] | 308 | if (sdata->u.ibss.fixed_bssid) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 309 | goto put_bss; |
| 310 | |
| 311 | /* not an IBSS */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 312 | if (!(cbss->capability & WLAN_CAPABILITY_IBSS)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 313 | goto put_bss; |
| 314 | |
| 315 | /* different channel */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 316 | if (cbss->channel != local->oper_channel) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 317 | goto put_bss; |
| 318 | |
| 319 | /* different SSID */ |
| 320 | if (elems->ssid_len != sdata->u.ibss.ssid_len || |
| 321 | memcmp(elems->ssid, sdata->u.ibss.ssid, |
| 322 | sdata->u.ibss.ssid_len)) |
| 323 | goto put_bss; |
| 324 | |
Alina Friedrichsen | 34e8f08 | 2009-02-22 00:07:28 +0100 | [diff] [blame] | 325 | /* same BSSID */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 326 | if (memcmp(cbss->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) |
Alina Friedrichsen | 34e8f08 | 2009-02-22 00:07:28 +0100 | [diff] [blame] | 327 | goto put_bss; |
| 328 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 329 | if (rx_status->flag & RX_FLAG_TSFT) { |
| 330 | /* |
| 331 | * For correct IBSS merging we need mactime; since mactime is |
| 332 | * defined as the time the first data symbol of the frame hits |
| 333 | * the PHY, and the timestamp of the beacon is defined as "the |
| 334 | * time that the data symbol containing the first bit of the |
| 335 | * timestamp is transmitted to the PHY plus the transmitting |
| 336 | * STA's delays through its local PHY from the MAC-PHY |
| 337 | * interface to its interface with the WM" (802.11 11.1.2) |
| 338 | * - equals the time this bit arrives at the receiver - we have |
| 339 | * to take into account the offset between the two. |
| 340 | * |
| 341 | * E.g. at 1 MBit that means mactime is 192 usec earlier |
| 342 | * (=24 bytes * 8 usecs/byte) than the beacon timestamp. |
| 343 | */ |
| 344 | int rate; |
| 345 | |
| 346 | if (rx_status->flag & RX_FLAG_HT) |
| 347 | rate = 65; /* TODO: HT rates */ |
| 348 | else |
| 349 | rate = local->hw.wiphy->bands[band]-> |
| 350 | bitrates[rx_status->rate_idx].bitrate; |
| 351 | |
| 352 | rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 353 | } else { |
| 354 | /* |
| 355 | * second best option: get current TSF |
| 356 | * (will return -1 if not supported) |
| 357 | */ |
| 358 | rx_timestamp = drv_get_tsf(local); |
| 359 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 360 | |
| 361 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 362 | printk(KERN_DEBUG "RX beacon SA=%pM BSSID=" |
| 363 | "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", |
| 364 | mgmt->sa, mgmt->bssid, |
| 365 | (unsigned long long)rx_timestamp, |
| 366 | (unsigned long long)beacon_timestamp, |
| 367 | (unsigned long long)(rx_timestamp - beacon_timestamp), |
| 368 | jiffies); |
| 369 | #endif |
| 370 | |
Alina Friedrichsen | 4a332a3 | 2009-02-22 18:19:33 +0100 | [diff] [blame] | 371 | /* give slow hardware some time to do the TSF sync */ |
| 372 | if (rx_timestamp < IEEE80211_IBSS_MERGE_DELAY) |
| 373 | goto put_bss; |
| 374 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 375 | if (beacon_timestamp > rx_timestamp) { |
| 376 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 377 | printk(KERN_DEBUG "%s: beacon TSF higher than " |
| 378 | "local TSF - IBSS merge with BSSID %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 379 | sdata->name, mgmt->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 380 | #endif |
| 381 | ieee80211_sta_join_ibss(sdata, bss); |
Bruno Randolf | 09a08cf | 2010-03-03 18:45:42 +0900 | [diff] [blame] | 382 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 383 | ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, |
| 384 | supp_rates, GFP_KERNEL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | put_bss: |
| 388 | ieee80211_rx_bss_put(local, bss); |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Add a new IBSS station, will also be called by the RX code when, |
| 393 | * in IBSS mode, receiving a frame from a yet-unknown station, hence |
| 394 | * must be callable in atomic context. |
| 395 | */ |
| 396 | struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 397 | u8 *bssid,u8 *addr, u32 supp_rates, |
| 398 | gfp_t gfp) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 399 | { |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 400 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 401 | struct ieee80211_local *local = sdata->local; |
| 402 | struct sta_info *sta; |
| 403 | int band = local->hw.conf.channel->band; |
| 404 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 405 | /* |
| 406 | * XXX: Consider removing the least recently used entry and |
| 407 | * allow new one to be added. |
| 408 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 409 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 410 | if (net_ratelimit()) |
| 411 | printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 412 | sdata->name, addr); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 413 | return NULL; |
| 414 | } |
| 415 | |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 416 | if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) |
| 417 | return NULL; |
| 418 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 419 | if (compare_ether_addr(bssid, sdata->u.ibss.bssid)) |
| 420 | return NULL; |
| 421 | |
| 422 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 423 | printk(KERN_DEBUG "%s: Adding new IBSS station %pM (dev=%s)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 424 | wiphy_name(local->hw.wiphy), addr, sdata->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 425 | #endif |
| 426 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 427 | sta = sta_info_alloc(sdata, addr, gfp); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 428 | if (!sta) |
| 429 | return NULL; |
| 430 | |
| 431 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); |
| 432 | |
| 433 | /* make sure mandatory rates are always added */ |
| 434 | sta->sta.supp_rates[band] = supp_rates | |
| 435 | ieee80211_mandatory_rates(local, band); |
| 436 | |
| 437 | rate_control_rate_init(sta); |
| 438 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 439 | /* If it fails, maybe we raced another insertion? */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 440 | if (sta_info_insert(sta)) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 441 | return sta_info_get(sdata, addr); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 442 | return sta; |
| 443 | } |
| 444 | |
| 445 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) |
| 446 | { |
| 447 | struct ieee80211_local *local = sdata->local; |
| 448 | int active = 0; |
| 449 | struct sta_info *sta; |
| 450 | |
| 451 | rcu_read_lock(); |
| 452 | |
| 453 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 454 | if (sta->sdata == sdata && |
| 455 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
| 456 | jiffies)) { |
| 457 | active++; |
| 458 | break; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | rcu_read_unlock(); |
| 463 | |
| 464 | return active; |
| 465 | } |
| 466 | |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 467 | /* |
| 468 | * This function is called with state == IEEE80211_IBSS_MLME_JOINED |
| 469 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 470 | |
| 471 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) |
| 472 | { |
| 473 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 474 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 475 | mod_timer(&ifibss->timer, |
| 476 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 477 | |
| 478 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 479 | |
Sujith | 450aae3 | 2009-11-02 12:33:23 +0530 | [diff] [blame] | 480 | if (time_before(jiffies, ifibss->last_scan_completed + |
| 481 | IEEE80211_IBSS_MERGE_INTERVAL)) |
| 482 | return; |
| 483 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 484 | if (ieee80211_sta_active_ibss(sdata)) |
| 485 | return; |
| 486 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 487 | if (ifibss->fixed_channel) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 488 | return; |
| 489 | |
| 490 | printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 491 | "IBSS networks with same SSID (merge)\n", sdata->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 492 | |
Johannes Berg | be4a4b6 | 2010-05-03 08:49:48 +0200 | [diff] [blame] | 493 | ieee80211_request_internal_scan(sdata, |
| 494 | ifibss->ssid, ifibss->ssid_len, |
| 495 | ifibss->fixed_channel ? ifibss->channel : NULL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 498 | static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 499 | { |
| 500 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 501 | struct ieee80211_local *local = sdata->local; |
| 502 | struct ieee80211_supported_band *sband; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 503 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 504 | u16 capability; |
| 505 | int i; |
| 506 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 507 | if (ifibss->fixed_bssid) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 508 | memcpy(bssid, ifibss->bssid, ETH_ALEN); |
| 509 | } else { |
| 510 | /* Generate random, not broadcast, locally administered BSSID. Mix in |
| 511 | * own MAC address to make sure that devices that do not have proper |
| 512 | * random number generator get different BSSID. */ |
| 513 | get_random_bytes(bssid, ETH_ALEN); |
| 514 | for (i = 0; i < ETH_ALEN; i++) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 515 | bssid[i] ^= sdata->vif.addr[i]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 516 | bssid[0] &= ~0x01; |
| 517 | bssid[0] |= 0x02; |
| 518 | } |
| 519 | |
| 520 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 521 | sdata->name, bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 522 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 523 | sband = local->hw.wiphy->bands[ifibss->channel->band]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 524 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 525 | capability = WLAN_CAPABILITY_IBSS; |
| 526 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 527 | if (ifibss->privacy) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 528 | capability |= WLAN_CAPABILITY_PRIVACY; |
| 529 | else |
| 530 | sdata->drop_unencrypted = 0; |
| 531 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 532 | __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int, |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame^] | 533 | ifibss->channel, ifibss->basic_rates, |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 534 | capability, 0); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 537 | /* |
| 538 | * This function is called with state == IEEE80211_IBSS_MLME_SEARCH |
| 539 | */ |
| 540 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 541 | static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 542 | { |
| 543 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 544 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 545 | struct cfg80211_bss *cbss; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 546 | struct ieee80211_channel *chan = NULL; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 547 | const u8 *bssid = NULL; |
| 548 | int active_ibss; |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 549 | u16 capability; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 550 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 551 | active_ibss = ieee80211_sta_active_ibss(sdata); |
| 552 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 553 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 554 | sdata->name, active_ibss); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 555 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 556 | |
| 557 | if (active_ibss) |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 558 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 559 | |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 560 | capability = WLAN_CAPABILITY_IBSS; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 561 | if (ifibss->privacy) |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 562 | capability |= WLAN_CAPABILITY_PRIVACY; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 563 | if (ifibss->fixed_bssid) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 564 | bssid = ifibss->bssid; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 565 | if (ifibss->fixed_channel) |
| 566 | chan = ifibss->channel; |
| 567 | if (!is_zero_ether_addr(ifibss->bssid)) |
| 568 | bssid = ifibss->bssid; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 569 | cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid, |
| 570 | ifibss->ssid, ifibss->ssid_len, |
| 571 | WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY, |
| 572 | capability); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 573 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 574 | if (cbss) { |
| 575 | struct ieee80211_bss *bss; |
| 576 | |
| 577 | bss = (void *)cbss->priv; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 578 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 579 | printk(KERN_DEBUG " sta_find_ibss: selected %pM current " |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 580 | "%pM\n", cbss->bssid, ifibss->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 581 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 582 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 583 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM" |
| 584 | " based on configured SSID\n", |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 585 | sdata->name, cbss->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 586 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 587 | ieee80211_sta_join_ibss(sdata, bss); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 588 | ieee80211_rx_bss_put(local, bss); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 589 | return; |
Reinette Chatre | d419b9f | 2009-10-19 14:55:37 -0700 | [diff] [blame] | 590 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 591 | |
| 592 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 593 | printk(KERN_DEBUG " did not try to join ibss\n"); |
| 594 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 595 | |
| 596 | /* Selected IBSS not found in current scan results - try to scan */ |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 597 | if (time_after(jiffies, ifibss->last_scan_completed + |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 598 | IEEE80211_SCAN_INTERVAL)) { |
| 599 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 600 | "join\n", sdata->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 601 | |
Johannes Berg | be4a4b6 | 2010-05-03 08:49:48 +0200 | [diff] [blame] | 602 | ieee80211_request_internal_scan(sdata, |
| 603 | ifibss->ssid, ifibss->ssid_len, |
| 604 | ifibss->fixed_channel ? ifibss->channel : NULL); |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 605 | } else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 606 | int interval = IEEE80211_SCAN_INTERVAL; |
| 607 | |
| 608 | if (time_after(jiffies, ifibss->ibss_join_req + |
| 609 | IEEE80211_IBSS_JOIN_TIMEOUT)) { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 610 | if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) { |
| 611 | ieee80211_sta_create_ibss(sdata); |
| 612 | return; |
| 613 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 614 | printk(KERN_DEBUG "%s: IBSS not allowed on" |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 615 | " %d MHz\n", sdata->name, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 616 | local->hw.conf.channel->center_freq); |
| 617 | |
| 618 | /* No IBSS found - decrease scan interval and continue |
| 619 | * scanning. */ |
| 620 | interval = IEEE80211_SCAN_INTERVAL_SLOW; |
| 621 | } |
| 622 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 623 | mod_timer(&ifibss->timer, |
| 624 | round_jiffies(jiffies + interval)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 625 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, |
| 629 | struct ieee80211_mgmt *mgmt, |
| 630 | size_t len) |
| 631 | { |
| 632 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 633 | struct ieee80211_local *local = sdata->local; |
| 634 | int tx_last_beacon; |
| 635 | struct sk_buff *skb; |
| 636 | struct ieee80211_mgmt *resp; |
| 637 | u8 *pos, *end; |
| 638 | |
| 639 | if (ifibss->state != IEEE80211_IBSS_MLME_JOINED || |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 640 | len < 24 + 2 || !ifibss->presp) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 641 | return; |
| 642 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 643 | tx_last_beacon = drv_tx_last_beacon(local); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 644 | |
| 645 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 646 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM" |
| 647 | " (tx_last_beacon=%d)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 648 | sdata->name, mgmt->sa, mgmt->da, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 649 | mgmt->bssid, tx_last_beacon); |
| 650 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 651 | |
| 652 | if (!tx_last_beacon) |
| 653 | return; |
| 654 | |
| 655 | if (memcmp(mgmt->bssid, ifibss->bssid, ETH_ALEN) != 0 && |
| 656 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
| 657 | return; |
| 658 | |
| 659 | end = ((u8 *) mgmt) + len; |
| 660 | pos = mgmt->u.probe_req.variable; |
| 661 | if (pos[0] != WLAN_EID_SSID || |
| 662 | pos + 2 + pos[1] > end) { |
| 663 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 664 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " |
| 665 | "from %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 666 | sdata->name, mgmt->sa); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 667 | #endif |
| 668 | return; |
| 669 | } |
| 670 | if (pos[1] != 0 && |
| 671 | (pos[1] != ifibss->ssid_len || |
Benoit Papillault | 0da780c | 2010-02-05 01:21:03 +0100 | [diff] [blame] | 672 | memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 673 | /* Ignore ProbeReq for foreign SSID */ |
| 674 | return; |
| 675 | } |
| 676 | |
| 677 | /* Reply with ProbeResp */ |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 678 | skb = skb_copy(ifibss->presp, GFP_KERNEL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 679 | if (!skb) |
| 680 | return; |
| 681 | |
| 682 | resp = (struct ieee80211_mgmt *) skb->data; |
| 683 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
| 684 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 685 | printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 686 | sdata->name, resp->da); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 687 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 688 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 689 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
| 693 | struct ieee80211_mgmt *mgmt, |
| 694 | size_t len, |
| 695 | struct ieee80211_rx_status *rx_status) |
| 696 | { |
| 697 | size_t baselen; |
| 698 | struct ieee802_11_elems elems; |
| 699 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 700 | if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 701 | return; /* ignore ProbeResp to foreign address */ |
| 702 | |
| 703 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 704 | if (baselen > len) |
| 705 | return; |
| 706 | |
| 707 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 708 | &elems); |
| 709 | |
| 710 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
| 711 | } |
| 712 | |
| 713 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
| 714 | struct ieee80211_mgmt *mgmt, |
| 715 | size_t len, |
| 716 | struct ieee80211_rx_status *rx_status) |
| 717 | { |
| 718 | size_t baselen; |
| 719 | struct ieee802_11_elems elems; |
| 720 | |
| 721 | /* Process beacon from the current BSS */ |
| 722 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 723 | if (baselen > len) |
| 724 | return; |
| 725 | |
| 726 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); |
| 727 | |
| 728 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true); |
| 729 | } |
| 730 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 731 | void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 732 | struct sk_buff *skb) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 733 | { |
| 734 | struct ieee80211_rx_status *rx_status; |
| 735 | struct ieee80211_mgmt *mgmt; |
| 736 | u16 fc; |
| 737 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 738 | rx_status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 739 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 740 | fc = le16_to_cpu(mgmt->frame_control); |
| 741 | |
| 742 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 743 | case IEEE80211_STYPE_PROBE_REQ: |
| 744 | ieee80211_rx_mgmt_probe_req(sdata, mgmt, skb->len); |
| 745 | break; |
| 746 | case IEEE80211_STYPE_PROBE_RESP: |
| 747 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, |
| 748 | rx_status); |
| 749 | break; |
| 750 | case IEEE80211_STYPE_BEACON: |
| 751 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, |
| 752 | rx_status); |
| 753 | break; |
| 754 | case IEEE80211_STYPE_AUTH: |
| 755 | ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len); |
| 756 | break; |
| 757 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 760 | void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 761 | { |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 762 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 763 | |
| 764 | if (!test_and_clear_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request)) |
| 765 | return; |
| 766 | |
| 767 | switch (ifibss->state) { |
| 768 | case IEEE80211_IBSS_MLME_SEARCH: |
| 769 | ieee80211_sta_find_ibss(sdata); |
| 770 | break; |
| 771 | case IEEE80211_IBSS_MLME_JOINED: |
| 772 | ieee80211_sta_merge_ibss(sdata); |
| 773 | break; |
| 774 | default: |
| 775 | WARN_ON(1); |
| 776 | break; |
| 777 | } |
| 778 | } |
| 779 | |
Johannes Berg | 3a4d4aa | 2010-05-26 16:41:40 +0200 | [diff] [blame] | 780 | static void ieee80211_queue_ibss_work(struct ieee80211_sub_if_data *sdata) |
| 781 | { |
| 782 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 783 | struct ieee80211_local *local = sdata->local; |
| 784 | |
| 785 | set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request); |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 786 | ieee80211_queue_work(&local->hw, &sdata->work); |
Johannes Berg | 3a4d4aa | 2010-05-26 16:41:40 +0200 | [diff] [blame] | 787 | } |
| 788 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 789 | static void ieee80211_ibss_timer(unsigned long data) |
| 790 | { |
| 791 | struct ieee80211_sub_if_data *sdata = |
| 792 | (struct ieee80211_sub_if_data *) data; |
| 793 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 794 | struct ieee80211_local *local = sdata->local; |
| 795 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 796 | if (local->quiescing) { |
| 797 | ifibss->timer_running = true; |
| 798 | return; |
| 799 | } |
| 800 | |
Johannes Berg | 3a4d4aa | 2010-05-26 16:41:40 +0200 | [diff] [blame] | 801 | ieee80211_queue_ibss_work(sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 802 | } |
| 803 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 804 | #ifdef CONFIG_PM |
| 805 | void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata) |
| 806 | { |
| 807 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 808 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 809 | if (del_timer_sync(&ifibss->timer)) |
| 810 | ifibss->timer_running = true; |
| 811 | } |
| 812 | |
| 813 | void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata) |
| 814 | { |
| 815 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 816 | |
| 817 | if (ifibss->timer_running) { |
| 818 | add_timer(&ifibss->timer); |
| 819 | ifibss->timer_running = false; |
| 820 | } |
| 821 | } |
| 822 | #endif |
| 823 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 824 | void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 825 | { |
| 826 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 827 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 828 | setup_timer(&ifibss->timer, ieee80211_ibss_timer, |
| 829 | (unsigned long) sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /* scan finished notification */ |
| 833 | void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) |
| 834 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 835 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 836 | |
Johannes Berg | 29b4a4f | 2009-04-21 00:30:49 +0200 | [diff] [blame] | 837 | mutex_lock(&local->iflist_mtx); |
| 838 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 839 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 840 | continue; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 841 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC) |
| 842 | continue; |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 843 | if (!sdata->u.ibss.ssid_len) |
| 844 | continue; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 845 | sdata->u.ibss.last_scan_completed = jiffies; |
Johannes Berg | 3a4d4aa | 2010-05-26 16:41:40 +0200 | [diff] [blame] | 846 | ieee80211_queue_ibss_work(sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 847 | } |
Johannes Berg | 29b4a4f | 2009-04-21 00:30:49 +0200 | [diff] [blame] | 848 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 849 | } |
| 850 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 851 | int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, |
| 852 | struct cfg80211_ibss_params *params) |
| 853 | { |
| 854 | struct sk_buff *skb; |
| 855 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 856 | if (params->bssid) { |
| 857 | memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN); |
| 858 | sdata->u.ibss.fixed_bssid = true; |
| 859 | } else |
| 860 | sdata->u.ibss.fixed_bssid = false; |
| 861 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 862 | sdata->u.ibss.privacy = params->privacy; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame^] | 863 | sdata->u.ibss.basic_rates = params->basic_rates; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 864 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 865 | sdata->vif.bss_conf.beacon_int = params->beacon_interval; |
| 866 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 867 | sdata->u.ibss.channel = params->channel; |
| 868 | sdata->u.ibss.fixed_channel = params->channel_fixed; |
| 869 | |
Johannes Berg | adfba3c | 2010-05-05 15:33:55 +0200 | [diff] [blame] | 870 | /* fix ourselves to that channel now already */ |
| 871 | if (params->channel_fixed) { |
| 872 | sdata->local->oper_channel = params->channel; |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 873 | WARN_ON(!ieee80211_set_channel_type(sdata->local, sdata, |
| 874 | NL80211_CHAN_NO_HT)); |
Johannes Berg | adfba3c | 2010-05-05 15:33:55 +0200 | [diff] [blame] | 875 | } |
| 876 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 877 | if (params->ie) { |
| 878 | sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len, |
| 879 | GFP_KERNEL); |
| 880 | if (sdata->u.ibss.ie) |
| 881 | sdata->u.ibss.ie_len = params->ie_len; |
| 882 | } |
| 883 | |
| 884 | skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + |
| 885 | 36 /* bitrates */ + |
| 886 | 34 /* SSID */ + |
| 887 | 3 /* DS params */ + |
| 888 | 4 /* IBSS params */ + |
| 889 | params->ie_len); |
| 890 | if (!skb) |
| 891 | return -ENOMEM; |
| 892 | |
| 893 | sdata->u.ibss.skb = skb; |
| 894 | sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; |
| 895 | sdata->u.ibss.ibss_join_req = jiffies; |
| 896 | |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 897 | memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN); |
| 898 | |
| 899 | /* |
| 900 | * The ssid_len setting below is used to see whether |
| 901 | * we are active, and we need all other settings |
| 902 | * before that may get visible. |
| 903 | */ |
| 904 | mb(); |
| 905 | |
| 906 | sdata->u.ibss.ssid_len = params->ssid_len; |
| 907 | |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 908 | ieee80211_recalc_idle(sdata->local); |
| 909 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 910 | set_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request); |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 911 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 912 | |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata) |
| 917 | { |
| 918 | struct sk_buff *skb; |
| 919 | |
| 920 | del_timer_sync(&sdata->u.ibss.timer); |
| 921 | clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request); |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 922 | cancel_work_sync(&sdata->work); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 923 | clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request); |
| 924 | |
| 925 | sta_info_flush(sdata->local, sdata); |
| 926 | |
| 927 | /* remove beacon */ |
| 928 | kfree(sdata->u.ibss.ie); |
| 929 | skb = sdata->u.ibss.presp; |
| 930 | rcu_assign_pointer(sdata->u.ibss.presp, NULL); |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 931 | sdata->vif.bss_conf.ibss_joined = false; |
| 932 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | |
| 933 | BSS_CHANGED_IBSS); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 934 | synchronize_rcu(); |
| 935 | kfree_skb(skb); |
| 936 | |
Johannes Berg | 35f20c1 | 2010-06-10 10:21:30 +0200 | [diff] [blame] | 937 | skb_queue_purge(&sdata->skb_queue); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 938 | memset(sdata->u.ibss.bssid, 0, ETH_ALEN); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 939 | sdata->u.ibss.ssid_len = 0; |
| 940 | |
| 941 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 942 | |
| 943 | return 0; |
| 944 | } |