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) |
| 34 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
| 35 | |
| 36 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 |
| 37 | |
| 38 | |
| 39 | static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata, |
| 40 | struct ieee80211_mgmt *mgmt, |
| 41 | size_t len) |
| 42 | { |
Rajkumar Manoharan | 0915cba | 2011-04-25 15:56:17 +0530 | [diff] [blame] | 43 | u16 auth_alg, auth_transaction; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 44 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 45 | lockdep_assert_held(&sdata->u.ibss.mtx); |
| 46 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 47 | if (len < 24 + 6) |
| 48 | return; |
| 49 | |
| 50 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 51 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 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]; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 80 | enum nl80211_channel_type channel_type; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 81 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 82 | lockdep_assert_held(&ifibss->mtx); |
| 83 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 84 | /* Reset own TSF to allow time synchronization work. */ |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 85 | drv_reset_tsf(local, sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 86 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 87 | skb = ifibss->skb; |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 88 | RCU_INIT_POINTER(ifibss->presp, NULL); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 89 | synchronize_rcu(); |
| 90 | skb->data = skb->head; |
| 91 | skb->len = 0; |
| 92 | skb_reset_tail_pointer(skb); |
| 93 | skb_reserve(skb, sdata->local->hw.extra_tx_headroom); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 94 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 95 | if (memcmp(ifibss->bssid, bssid, ETH_ALEN)) |
| 96 | sta_info_flush(sdata->local, sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 97 | |
Johannes Berg | 49b5c7f | 2010-04-29 21:34:01 +0200 | [diff] [blame] | 98 | /* if merging, indicate to driver that we leave the old IBSS */ |
| 99 | if (sdata->vif.bss_conf.ibss_joined) { |
| 100 | sdata->vif.bss_conf.ibss_joined = false; |
Eliad Peller | 86a2ea4 | 2011-11-08 15:36:59 +0200 | [diff] [blame] | 101 | netif_carrier_off(sdata->dev); |
Johannes Berg | 49b5c7f | 2010-04-29 21:34:01 +0200 | [diff] [blame] | 102 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS); |
| 103 | } |
| 104 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 105 | memcpy(ifibss->bssid, bssid, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 106 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 107 | sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 108 | |
Eliad Peller | ba19602 | 2012-01-10 15:19:54 +0200 | [diff] [blame] | 109 | local->oper_channel = chan; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 110 | channel_type = ifibss->channel_type; |
| 111 | if (channel_type > NL80211_CHAN_HT20 && |
| 112 | !cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type)) |
| 113 | channel_type = NL80211_CHAN_HT20; |
| 114 | if (!ieee80211_set_channel_type(local, sdata, channel_type)) { |
| 115 | /* can only fail due to HT40+/- mismatch */ |
| 116 | channel_type = NL80211_CHAN_HT20; |
| 117 | WARN_ON(!ieee80211_set_channel_type(local, sdata, |
| 118 | NL80211_CHAN_HT20)); |
| 119 | } |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 120 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 121 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 122 | sband = local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 123 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 124 | /* build supported rates array */ |
| 125 | pos = supp_rates; |
| 126 | for (i = 0; i < sband->n_bitrates; i++) { |
| 127 | int rate = sband->bitrates[i].bitrate; |
| 128 | u8 basic = 0; |
| 129 | if (basic_rates & BIT(i)) |
| 130 | basic = 0x80; |
| 131 | *pos++ = basic | (u8) (rate / 5); |
| 132 | } |
| 133 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 134 | /* Build IBSS probe response */ |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 135 | mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 136 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); |
| 137 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 138 | IEEE80211_STYPE_PROBE_RESP); |
| 139 | memset(mgmt->da, 0xff, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 140 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 141 | memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 142 | mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int); |
Sujith | 707c1b4 | 2009-03-03 10:15:10 +0530 | [diff] [blame] | 143 | mgmt->u.beacon.timestamp = cpu_to_le64(tsf); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 144 | mgmt->u.beacon.capab_info = cpu_to_le16(capability); |
| 145 | |
| 146 | pos = skb_put(skb, 2 + ifibss->ssid_len); |
| 147 | *pos++ = WLAN_EID_SSID; |
| 148 | *pos++ = ifibss->ssid_len; |
| 149 | memcpy(pos, ifibss->ssid, ifibss->ssid_len); |
| 150 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 151 | rates = sband->n_bitrates; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 152 | if (rates > 8) |
| 153 | rates = 8; |
| 154 | pos = skb_put(skb, 2 + rates); |
| 155 | *pos++ = WLAN_EID_SUPP_RATES; |
| 156 | *pos++ = rates; |
| 157 | memcpy(pos, supp_rates, rates); |
| 158 | |
| 159 | if (sband->band == IEEE80211_BAND_2GHZ) { |
| 160 | pos = skb_put(skb, 2 + 1); |
| 161 | *pos++ = WLAN_EID_DS_PARAMS; |
| 162 | *pos++ = 1; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 163 | *pos++ = ieee80211_frequency_to_channel(chan->center_freq); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | pos = skb_put(skb, 2 + 2); |
| 167 | *pos++ = WLAN_EID_IBSS_PARAMS; |
| 168 | *pos++ = 2; |
| 169 | /* FIX: set ATIM window based on scan results */ |
| 170 | *pos++ = 0; |
| 171 | *pos++ = 0; |
| 172 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 173 | if (sband->n_bitrates > 8) { |
| 174 | rates = sband->n_bitrates - 8; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 175 | pos = skb_put(skb, 2 + rates); |
| 176 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 177 | *pos++ = rates; |
| 178 | memcpy(pos, &supp_rates[8], rates); |
| 179 | } |
| 180 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 181 | if (ifibss->ie_len) |
| 182 | memcpy(skb_put(skb, ifibss->ie_len), |
| 183 | ifibss->ie, ifibss->ie_len); |
| 184 | |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 185 | /* add HT capability and information IEs */ |
| 186 | if (channel_type && sband->ht_cap.ht_supported) { |
| 187 | pos = skb_put(skb, 4 + |
| 188 | sizeof(struct ieee80211_ht_cap) + |
| 189 | sizeof(struct ieee80211_ht_info)); |
| 190 | pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, |
| 191 | sband->ht_cap.cap); |
| 192 | pos = ieee80211_ie_build_ht_info(pos, |
| 193 | &sband->ht_cap, |
| 194 | chan, |
| 195 | channel_type); |
| 196 | } |
| 197 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 198 | if (local->hw.queues >= 4) { |
| 199 | pos = skb_put(skb, 9); |
| 200 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 201 | *pos++ = 7; /* len */ |
| 202 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 203 | *pos++ = 0x50; |
| 204 | *pos++ = 0xf2; |
| 205 | *pos++ = 2; /* WME */ |
| 206 | *pos++ = 0; /* WME info */ |
| 207 | *pos++ = 1; /* WME ver */ |
| 208 | *pos++ = 0; /* U-APSD no in use */ |
| 209 | } |
| 210 | |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 211 | rcu_assign_pointer(ifibss->presp, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 212 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 213 | sdata->vif.bss_conf.beacon_int = beacon_int; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 214 | sdata->vif.bss_conf.basic_rates = basic_rates; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 215 | bss_change = BSS_CHANGED_BEACON_INT; |
| 216 | bss_change |= ieee80211_reset_erp_info(sdata); |
| 217 | bss_change |= BSS_CHANGED_BSSID; |
| 218 | bss_change |= BSS_CHANGED_BEACON; |
| 219 | bss_change |= BSS_CHANGED_BEACON_ENABLED; |
Teemu Paasikivi | 392cfdb | 2010-06-14 12:55:32 +0300 | [diff] [blame] | 220 | bss_change |= BSS_CHANGED_BASIC_RATES; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 221 | bss_change |= BSS_CHANGED_HT; |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 222 | bss_change |= BSS_CHANGED_IBSS; |
| 223 | sdata->vif.bss_conf.ibss_joined = true; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 224 | ieee80211_bss_info_change_notify(sdata, bss_change); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 225 | |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 226 | ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 227 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 228 | ifibss->state = IEEE80211_IBSS_MLME_JOINED; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 229 | mod_timer(&ifibss->timer, |
| 230 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 231 | |
Johannes Berg | f446d10 | 2009-10-28 15:12:32 +0100 | [diff] [blame] | 232 | bss = cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel, |
| 233 | mgmt, skb->len, 0, GFP_KERNEL); |
| 234 | cfg80211_put_bss(bss); |
Eliad Peller | 86a2ea4 | 2011-11-08 15:36:59 +0200 | [diff] [blame] | 235 | netif_carrier_on(sdata->dev); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 236 | cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 237 | } |
| 238 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 239 | static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
| 240 | struct ieee80211_bss *bss) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 241 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 242 | struct cfg80211_bss *cbss = |
| 243 | container_of((void *)bss, struct cfg80211_bss, priv); |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 244 | struct ieee80211_supported_band *sband; |
| 245 | u32 basic_rates; |
| 246 | int i, j; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 247 | u16 beacon_int = cbss->beacon_interval; |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 248 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 249 | lockdep_assert_held(&sdata->u.ibss.mtx); |
| 250 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 251 | if (beacon_int < 10) |
| 252 | beacon_int = 10; |
| 253 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 254 | sband = sdata->local->hw.wiphy->bands[cbss->channel->band]; |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 255 | |
| 256 | basic_rates = 0; |
| 257 | |
| 258 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 259 | int rate = (bss->supp_rates[i] & 0x7f) * 5; |
| 260 | bool is_basic = !!(bss->supp_rates[i] & 0x80); |
| 261 | |
| 262 | for (j = 0; j < sband->n_bitrates; j++) { |
| 263 | if (sband->bitrates[j].bitrate == rate) { |
| 264 | if (is_basic) |
| 265 | basic_rates |= BIT(j); |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 271 | __ieee80211_sta_join_ibss(sdata, cbss->bssid, |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 272 | beacon_int, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 273 | cbss->channel, |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 274 | basic_rates, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 275 | cbss->capability, |
| 276 | cbss->tsf); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 279 | static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta) |
| 280 | __acquires(RCU) |
| 281 | { |
| 282 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 283 | u8 addr[ETH_ALEN]; |
| 284 | |
| 285 | memcpy(addr, sta->sta.addr, ETH_ALEN); |
| 286 | |
| 287 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 288 | wiphy_debug(sdata->local->hw.wiphy, |
| 289 | "Adding new IBSS station %pM (dev=%s)\n", |
| 290 | addr, sdata->name); |
| 291 | #endif |
| 292 | |
| 293 | sta_info_move_state(sta, IEEE80211_STA_AUTH); |
| 294 | sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
| 295 | sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 296 | |
| 297 | rate_control_rate_init(sta); |
| 298 | |
| 299 | /* If it fails, maybe we raced another insertion? */ |
| 300 | if (sta_info_insert_rcu(sta)) |
| 301 | return sta_info_get(sdata, addr); |
| 302 | return sta; |
| 303 | } |
| 304 | |
| 305 | static struct sta_info * |
| 306 | ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, |
| 307 | const u8 *bssid, const u8 *addr, |
| 308 | u32 supp_rates) |
| 309 | __acquires(RCU) |
| 310 | { |
| 311 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 312 | struct ieee80211_local *local = sdata->local; |
| 313 | struct sta_info *sta; |
| 314 | int band = local->hw.conf.channel->band; |
| 315 | |
| 316 | /* |
| 317 | * XXX: Consider removing the least recently used entry and |
| 318 | * allow new one to be added. |
| 319 | */ |
| 320 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
| 321 | if (net_ratelimit()) |
| 322 | printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n", |
| 323 | sdata->name, addr); |
| 324 | rcu_read_lock(); |
| 325 | return NULL; |
| 326 | } |
| 327 | |
| 328 | if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) { |
| 329 | rcu_read_lock(); |
| 330 | return NULL; |
| 331 | } |
| 332 | |
| 333 | if (compare_ether_addr(bssid, sdata->u.ibss.bssid)) { |
| 334 | rcu_read_lock(); |
| 335 | return NULL; |
| 336 | } |
| 337 | |
| 338 | sta = sta_info_alloc(sdata, addr, GFP_KERNEL); |
| 339 | if (!sta) { |
| 340 | rcu_read_lock(); |
| 341 | return NULL; |
| 342 | } |
| 343 | |
| 344 | sta->last_rx = jiffies; |
| 345 | |
| 346 | /* make sure mandatory rates are always added */ |
| 347 | sta->sta.supp_rates[band] = supp_rates | |
| 348 | ieee80211_mandatory_rates(local, band); |
| 349 | |
| 350 | return ieee80211_ibss_finish_sta(sta); |
| 351 | } |
| 352 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 353 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
| 354 | struct ieee80211_mgmt *mgmt, |
| 355 | size_t len, |
| 356 | struct ieee80211_rx_status *rx_status, |
| 357 | struct ieee802_11_elems *elems, |
| 358 | bool beacon) |
| 359 | { |
| 360 | struct ieee80211_local *local = sdata->local; |
| 361 | int freq; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 362 | struct cfg80211_bss *cbss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 363 | struct ieee80211_bss *bss; |
| 364 | struct sta_info *sta; |
| 365 | struct ieee80211_channel *channel; |
| 366 | u64 beacon_timestamp, rx_timestamp; |
| 367 | u32 supp_rates = 0; |
| 368 | enum ieee80211_band band = rx_status->band; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 369 | struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band]; |
| 370 | bool rates_updated = false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 371 | |
| 372 | if (elems->ds_params && elems->ds_params_len == 1) |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 373 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], |
| 374 | band); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 375 | else |
| 376 | freq = rx_status->freq; |
| 377 | |
| 378 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 379 | |
| 380 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 381 | return; |
| 382 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 383 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 384 | memcmp(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 385 | |
| 386 | rcu_read_lock(); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 387 | sta = sta_info_get(sdata, mgmt->sa); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 388 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 389 | if (elems->supp_rates) { |
| 390 | supp_rates = ieee80211_sta_get_rates(local, elems, |
| 391 | band); |
| 392 | if (sta) { |
| 393 | u32 prev_rates; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 394 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 395 | prev_rates = sta->sta.supp_rates[band]; |
| 396 | /* make sure mandatory rates are always added */ |
| 397 | sta->sta.supp_rates[band] = supp_rates | |
| 398 | ieee80211_mandatory_rates(local, band); |
| 399 | |
| 400 | if (sta->sta.supp_rates[band] != prev_rates) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 401 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 402 | printk(KERN_DEBUG |
| 403 | "%s: updated supp_rates set " |
| 404 | "for %pM based on beacon" |
| 405 | "/probe_resp (0x%x -> 0x%x)\n", |
| 406 | sdata->name, sta->sta.addr, |
| 407 | prev_rates, |
| 408 | sta->sta.supp_rates[band]); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 409 | #endif |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 410 | rates_updated = true; |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 411 | } |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 412 | } else { |
| 413 | rcu_read_unlock(); |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 414 | sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid, |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 415 | mgmt->sa, supp_rates); |
| 416 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 417 | } |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 418 | |
| 419 | if (sta && elems->wmm_info) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 420 | set_sta_flag(sta, WLAN_STA_WME); |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 421 | |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 422 | if (sta && elems->ht_info_elem && elems->ht_cap_elem && |
| 423 | sdata->u.ibss.channel_type != NL80211_CHAN_NO_HT) { |
| 424 | /* we both use HT */ |
| 425 | struct ieee80211_sta_ht_cap sta_ht_cap_new; |
| 426 | enum nl80211_channel_type channel_type = |
| 427 | ieee80211_ht_info_to_channel_type( |
| 428 | elems->ht_info_elem); |
| 429 | |
| 430 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
| 431 | elems->ht_cap_elem, |
| 432 | &sta_ht_cap_new); |
| 433 | |
| 434 | /* |
| 435 | * fall back to HT20 if we don't use or use |
| 436 | * the other extension channel |
| 437 | */ |
| 438 | if ((channel_type == NL80211_CHAN_HT40MINUS || |
| 439 | channel_type == NL80211_CHAN_HT40PLUS) && |
| 440 | channel_type != sdata->u.ibss.channel_type) |
| 441 | sta_ht_cap_new.cap &= |
| 442 | ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 443 | |
| 444 | if (memcmp(&sta->sta.ht_cap, &sta_ht_cap_new, |
| 445 | sizeof(sta_ht_cap_new))) { |
| 446 | memcpy(&sta->sta.ht_cap, &sta_ht_cap_new, |
| 447 | sizeof(sta_ht_cap_new)); |
| 448 | rates_updated = true; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | if (sta && rates_updated) |
| 453 | rate_control_rate_init(sta); |
| 454 | |
Bruno Randolf | 9eba612 | 2010-10-04 11:17:30 +0900 | [diff] [blame] | 455 | rcu_read_unlock(); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
| 459 | channel, beacon); |
| 460 | if (!bss) |
| 461 | return; |
| 462 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 463 | cbss = container_of((void *)bss, struct cfg80211_bss, priv); |
| 464 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 465 | /* was just updated in ieee80211_bss_info_update */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 466 | beacon_timestamp = cbss->tsf; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 467 | |
| 468 | /* check if we need to merge IBSS */ |
| 469 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 470 | /* we use a fixed BSSID */ |
Benoit Papillault | a98bfec | 2010-01-17 22:45:24 +0100 | [diff] [blame] | 471 | if (sdata->u.ibss.fixed_bssid) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 472 | goto put_bss; |
| 473 | |
| 474 | /* not an IBSS */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 475 | if (!(cbss->capability & WLAN_CAPABILITY_IBSS)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 476 | goto put_bss; |
| 477 | |
| 478 | /* different channel */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 479 | if (cbss->channel != local->oper_channel) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 480 | goto put_bss; |
| 481 | |
| 482 | /* different SSID */ |
| 483 | if (elems->ssid_len != sdata->u.ibss.ssid_len || |
| 484 | memcmp(elems->ssid, sdata->u.ibss.ssid, |
| 485 | sdata->u.ibss.ssid_len)) |
| 486 | goto put_bss; |
| 487 | |
Alina Friedrichsen | 34e8f08 | 2009-02-22 00:07:28 +0100 | [diff] [blame] | 488 | /* same BSSID */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 489 | if (memcmp(cbss->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) |
Alina Friedrichsen | 34e8f08 | 2009-02-22 00:07:28 +0100 | [diff] [blame] | 490 | goto put_bss; |
| 491 | |
Johannes Berg | 6ebacbb | 2011-02-23 15:06:08 +0100 | [diff] [blame] | 492 | if (rx_status->flag & RX_FLAG_MACTIME_MPDU) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 493 | /* |
| 494 | * For correct IBSS merging we need mactime; since mactime is |
| 495 | * defined as the time the first data symbol of the frame hits |
| 496 | * the PHY, and the timestamp of the beacon is defined as "the |
| 497 | * time that the data symbol containing the first bit of the |
| 498 | * timestamp is transmitted to the PHY plus the transmitting |
| 499 | * STA's delays through its local PHY from the MAC-PHY |
| 500 | * interface to its interface with the WM" (802.11 11.1.2) |
| 501 | * - equals the time this bit arrives at the receiver - we have |
| 502 | * to take into account the offset between the two. |
| 503 | * |
| 504 | * E.g. at 1 MBit that means mactime is 192 usec earlier |
| 505 | * (=24 bytes * 8 usecs/byte) than the beacon timestamp. |
| 506 | */ |
| 507 | int rate; |
| 508 | |
| 509 | if (rx_status->flag & RX_FLAG_HT) |
| 510 | rate = 65; /* TODO: HT rates */ |
| 511 | else |
| 512 | rate = local->hw.wiphy->bands[band]-> |
| 513 | bitrates[rx_status->rate_idx].bitrate; |
| 514 | |
| 515 | rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 516 | } else { |
| 517 | /* |
| 518 | * second best option: get current TSF |
| 519 | * (will return -1 if not supported) |
| 520 | */ |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 521 | rx_timestamp = drv_get_tsf(local, sdata); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 522 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 523 | |
| 524 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 525 | printk(KERN_DEBUG "RX beacon SA=%pM BSSID=" |
| 526 | "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", |
| 527 | mgmt->sa, mgmt->bssid, |
| 528 | (unsigned long long)rx_timestamp, |
| 529 | (unsigned long long)beacon_timestamp, |
| 530 | (unsigned long long)(rx_timestamp - beacon_timestamp), |
| 531 | jiffies); |
| 532 | #endif |
| 533 | |
| 534 | if (beacon_timestamp > rx_timestamp) { |
| 535 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 536 | printk(KERN_DEBUG "%s: beacon TSF higher than " |
| 537 | "local TSF - IBSS merge with BSSID %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 538 | sdata->name, mgmt->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 539 | #endif |
| 540 | ieee80211_sta_join_ibss(sdata, bss); |
Bruno Randolf | 09a08cf | 2010-03-03 18:45:42 +0900 | [diff] [blame] | 541 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 542 | ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 543 | supp_rates); |
| 544 | rcu_read_unlock(); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | put_bss: |
| 548 | ieee80211_rx_bss_put(local, bss); |
| 549 | } |
| 550 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 551 | void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata, |
| 552 | const u8 *bssid, const u8 *addr, |
| 553 | u32 supp_rates) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 554 | { |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 555 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 556 | struct ieee80211_local *local = sdata->local; |
| 557 | struct sta_info *sta; |
| 558 | int band = local->hw.conf.channel->band; |
| 559 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 560 | /* |
| 561 | * XXX: Consider removing the least recently used entry and |
| 562 | * allow new one to be added. |
| 563 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 564 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 565 | if (net_ratelimit()) |
| 566 | 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] | 567 | sdata->name, addr); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 568 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 571 | if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 572 | return; |
Felix Fietkau | 2e10d33 | 2009-12-20 19:07:09 +0100 | [diff] [blame] | 573 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 574 | if (compare_ether_addr(bssid, sdata->u.ibss.bssid)) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 575 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 576 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 577 | sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 578 | if (!sta) |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 579 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 580 | |
Rajkumar Manoharan | c8716d9 | 2010-10-23 10:59:57 +0530 | [diff] [blame] | 581 | sta->last_rx = jiffies; |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 582 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 583 | /* make sure mandatory rates are always added */ |
| 584 | sta->sta.supp_rates[band] = supp_rates | |
| 585 | ieee80211_mandatory_rates(local, band); |
| 586 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 587 | spin_lock(&ifibss->incomplete_lock); |
| 588 | list_add(&sta->list, &ifibss->incomplete_stations); |
| 589 | spin_unlock(&ifibss->incomplete_lock); |
| 590 | ieee80211_queue_work(&local->hw, &sdata->work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) |
| 594 | { |
| 595 | struct ieee80211_local *local = sdata->local; |
| 596 | int active = 0; |
| 597 | struct sta_info *sta; |
| 598 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 599 | lockdep_assert_held(&sdata->u.ibss.mtx); |
| 600 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 601 | rcu_read_lock(); |
| 602 | |
| 603 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 604 | if (sta->sdata == sdata && |
| 605 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
| 606 | jiffies)) { |
| 607 | active++; |
| 608 | break; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | rcu_read_unlock(); |
| 613 | |
| 614 | return active; |
| 615 | } |
| 616 | |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 617 | /* |
| 618 | * This function is called with state == IEEE80211_IBSS_MLME_JOINED |
| 619 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 620 | |
| 621 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) |
| 622 | { |
| 623 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 624 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 625 | lockdep_assert_held(&ifibss->mtx); |
| 626 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 627 | mod_timer(&ifibss->timer, |
| 628 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 629 | |
| 630 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 631 | |
Sujith | 450aae3 | 2009-11-02 12:33:23 +0530 | [diff] [blame] | 632 | if (time_before(jiffies, ifibss->last_scan_completed + |
| 633 | IEEE80211_IBSS_MERGE_INTERVAL)) |
| 634 | return; |
| 635 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 636 | if (ieee80211_sta_active_ibss(sdata)) |
| 637 | return; |
| 638 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 639 | if (ifibss->fixed_channel) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 640 | return; |
| 641 | |
| 642 | 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] | 643 | "IBSS networks with same SSID (merge)\n", sdata->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 644 | |
Johannes Berg | be4a4b6 | 2010-05-03 08:49:48 +0200 | [diff] [blame] | 645 | ieee80211_request_internal_scan(sdata, |
| 646 | ifibss->ssid, ifibss->ssid_len, |
| 647 | ifibss->fixed_channel ? ifibss->channel : NULL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 650 | static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 651 | { |
| 652 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 653 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 654 | u16 capability; |
| 655 | int i; |
| 656 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 657 | lockdep_assert_held(&ifibss->mtx); |
| 658 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 659 | if (ifibss->fixed_bssid) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 660 | memcpy(bssid, ifibss->bssid, ETH_ALEN); |
| 661 | } else { |
| 662 | /* Generate random, not broadcast, locally administered BSSID. Mix in |
| 663 | * own MAC address to make sure that devices that do not have proper |
| 664 | * random number generator get different BSSID. */ |
| 665 | get_random_bytes(bssid, ETH_ALEN); |
| 666 | for (i = 0; i < ETH_ALEN; i++) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 667 | bssid[i] ^= sdata->vif.addr[i]; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 668 | bssid[0] &= ~0x01; |
| 669 | bssid[0] |= 0x02; |
| 670 | } |
| 671 | |
| 672 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 673 | sdata->name, bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 674 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 675 | capability = WLAN_CAPABILITY_IBSS; |
| 676 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 677 | if (ifibss->privacy) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 678 | capability |= WLAN_CAPABILITY_PRIVACY; |
| 679 | else |
| 680 | sdata->drop_unencrypted = 0; |
| 681 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 682 | __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int, |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 683 | ifibss->channel, ifibss->basic_rates, |
Johannes Berg | b59066a | 2009-05-12 21:18:38 +0200 | [diff] [blame] | 684 | capability, 0); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 685 | } |
| 686 | |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 687 | /* |
| 688 | * This function is called with state == IEEE80211_IBSS_MLME_SEARCH |
| 689 | */ |
| 690 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 691 | static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 692 | { |
| 693 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 694 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 695 | struct cfg80211_bss *cbss; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 696 | struct ieee80211_channel *chan = NULL; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 697 | const u8 *bssid = NULL; |
| 698 | int active_ibss; |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 699 | u16 capability; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 700 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 701 | lockdep_assert_held(&ifibss->mtx); |
| 702 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 703 | active_ibss = ieee80211_sta_active_ibss(sdata); |
| 704 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 705 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 706 | sdata->name, active_ibss); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 707 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 708 | |
| 709 | if (active_ibss) |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 710 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 711 | |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 712 | capability = WLAN_CAPABILITY_IBSS; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 713 | if (ifibss->privacy) |
Johannes Berg | e0d6188 | 2009-05-12 20:47:32 +0200 | [diff] [blame] | 714 | capability |= WLAN_CAPABILITY_PRIVACY; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 715 | if (ifibss->fixed_bssid) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 716 | bssid = ifibss->bssid; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 717 | if (ifibss->fixed_channel) |
| 718 | chan = ifibss->channel; |
| 719 | if (!is_zero_ether_addr(ifibss->bssid)) |
| 720 | bssid = ifibss->bssid; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 721 | cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid, |
| 722 | ifibss->ssid, ifibss->ssid_len, |
| 723 | WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY, |
| 724 | capability); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 725 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 726 | if (cbss) { |
| 727 | struct ieee80211_bss *bss; |
| 728 | |
| 729 | bss = (void *)cbss->priv; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 730 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 731 | printk(KERN_DEBUG " sta_find_ibss: selected %pM current " |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 732 | "%pM\n", cbss->bssid, ifibss->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 733 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 734 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 735 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM" |
| 736 | " based on configured SSID\n", |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 737 | sdata->name, cbss->bssid); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 738 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 739 | ieee80211_sta_join_ibss(sdata, bss); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 740 | ieee80211_rx_bss_put(local, bss); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 741 | return; |
Reinette Chatre | d419b9f | 2009-10-19 14:55:37 -0700 | [diff] [blame] | 742 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 743 | |
| 744 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 745 | printk(KERN_DEBUG " did not try to join ibss\n"); |
| 746 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 747 | |
| 748 | /* Selected IBSS not found in current scan results - try to scan */ |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 749 | if (time_after(jiffies, ifibss->last_scan_completed + |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 750 | IEEE80211_SCAN_INTERVAL)) { |
| 751 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 752 | "join\n", sdata->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 753 | |
Johannes Berg | be4a4b6 | 2010-05-03 08:49:48 +0200 | [diff] [blame] | 754 | ieee80211_request_internal_scan(sdata, |
| 755 | ifibss->ssid, ifibss->ssid_len, |
| 756 | ifibss->fixed_channel ? ifibss->channel : NULL); |
Benoit Papillault | ce9058a | 2010-01-17 22:45:23 +0100 | [diff] [blame] | 757 | } else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 758 | int interval = IEEE80211_SCAN_INTERVAL; |
| 759 | |
| 760 | if (time_after(jiffies, ifibss->ibss_join_req + |
| 761 | IEEE80211_IBSS_JOIN_TIMEOUT)) { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 762 | if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) { |
| 763 | ieee80211_sta_create_ibss(sdata); |
| 764 | return; |
| 765 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 766 | printk(KERN_DEBUG "%s: IBSS not allowed on" |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 767 | " %d MHz\n", sdata->name, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 768 | local->hw.conf.channel->center_freq); |
| 769 | |
| 770 | /* No IBSS found - decrease scan interval and continue |
| 771 | * scanning. */ |
| 772 | interval = IEEE80211_SCAN_INTERVAL_SLOW; |
| 773 | } |
| 774 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 775 | mod_timer(&ifibss->timer, |
| 776 | round_jiffies(jiffies + interval)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 777 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 781 | struct sk_buff *req) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 782 | { |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 783 | struct ieee80211_mgmt *mgmt = (void *)req->data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 784 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 785 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 786 | int tx_last_beacon, len = req->len; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 787 | struct sk_buff *skb; |
| 788 | struct ieee80211_mgmt *resp; |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 789 | struct sk_buff *presp; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 790 | u8 *pos, *end; |
| 791 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 792 | lockdep_assert_held(&ifibss->mtx); |
| 793 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 794 | presp = rcu_dereference_protected(ifibss->presp, |
| 795 | lockdep_is_held(&ifibss->mtx)); |
| 796 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 797 | if (ifibss->state != IEEE80211_IBSS_MLME_JOINED || |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 798 | len < 24 + 2 || !presp) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 799 | return; |
| 800 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 801 | tx_last_beacon = drv_tx_last_beacon(local); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 802 | |
| 803 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 804 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM" |
| 805 | " (tx_last_beacon=%d)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 806 | sdata->name, mgmt->sa, mgmt->da, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 807 | mgmt->bssid, tx_last_beacon); |
| 808 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 809 | |
Felix Fietkau | 1ed7648 | 2011-03-24 19:46:18 +0100 | [diff] [blame] | 810 | if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 811 | return; |
| 812 | |
| 813 | if (memcmp(mgmt->bssid, ifibss->bssid, ETH_ALEN) != 0 && |
| 814 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
| 815 | return; |
| 816 | |
| 817 | end = ((u8 *) mgmt) + len; |
| 818 | pos = mgmt->u.probe_req.variable; |
| 819 | if (pos[0] != WLAN_EID_SSID || |
| 820 | pos + 2 + pos[1] > end) { |
| 821 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 822 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " |
| 823 | "from %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 824 | sdata->name, mgmt->sa); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 825 | #endif |
| 826 | return; |
| 827 | } |
| 828 | if (pos[1] != 0 && |
| 829 | (pos[1] != ifibss->ssid_len || |
Benoit Papillault | 0da780c | 2010-02-05 01:21:03 +0100 | [diff] [blame] | 830 | memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 831 | /* Ignore ProbeReq for foreign SSID */ |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | /* Reply with ProbeResp */ |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 836 | skb = skb_copy(presp, GFP_KERNEL); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 837 | if (!skb) |
| 838 | return; |
| 839 | |
| 840 | resp = (struct ieee80211_mgmt *) skb->data; |
| 841 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
| 842 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 843 | printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 844 | sdata->name, resp->da); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 845 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 846 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 847 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
| 851 | struct ieee80211_mgmt *mgmt, |
| 852 | size_t len, |
| 853 | struct ieee80211_rx_status *rx_status) |
| 854 | { |
| 855 | size_t baselen; |
| 856 | struct ieee802_11_elems elems; |
| 857 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 858 | if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 859 | return; /* ignore ProbeResp to foreign address */ |
| 860 | |
| 861 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 862 | if (baselen > len) |
| 863 | return; |
| 864 | |
| 865 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 866 | &elems); |
| 867 | |
| 868 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
| 869 | } |
| 870 | |
| 871 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
| 872 | struct ieee80211_mgmt *mgmt, |
| 873 | size_t len, |
| 874 | struct ieee80211_rx_status *rx_status) |
| 875 | { |
| 876 | size_t baselen; |
| 877 | struct ieee802_11_elems elems; |
| 878 | |
| 879 | /* Process beacon from the current BSS */ |
| 880 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 881 | if (baselen > len) |
| 882 | return; |
| 883 | |
| 884 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); |
| 885 | |
| 886 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true); |
| 887 | } |
| 888 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 889 | void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 890 | struct sk_buff *skb) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 891 | { |
| 892 | struct ieee80211_rx_status *rx_status; |
| 893 | struct ieee80211_mgmt *mgmt; |
| 894 | u16 fc; |
| 895 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 896 | rx_status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 897 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 898 | fc = le16_to_cpu(mgmt->frame_control); |
| 899 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 900 | mutex_lock(&sdata->u.ibss.mtx); |
| 901 | |
Tim Harvey | c926d00 | 2010-12-09 10:43:13 -0800 | [diff] [blame] | 902 | if (!sdata->u.ibss.ssid_len) |
| 903 | goto mgmt_out; /* not ready to merge yet */ |
| 904 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 905 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 906 | case IEEE80211_STYPE_PROBE_REQ: |
Johannes Berg | c269a20 | 2011-02-14 12:20:22 +0100 | [diff] [blame] | 907 | ieee80211_rx_mgmt_probe_req(sdata, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 908 | break; |
| 909 | case IEEE80211_STYPE_PROBE_RESP: |
| 910 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, |
| 911 | rx_status); |
| 912 | break; |
| 913 | case IEEE80211_STYPE_BEACON: |
| 914 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, |
| 915 | rx_status); |
| 916 | break; |
| 917 | case IEEE80211_STYPE_AUTH: |
| 918 | ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len); |
| 919 | break; |
| 920 | } |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 921 | |
Tim Harvey | c926d00 | 2010-12-09 10:43:13 -0800 | [diff] [blame] | 922 | mgmt_out: |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 923 | mutex_unlock(&sdata->u.ibss.mtx); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 926 | void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 927 | { |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 928 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 929 | struct sta_info *sta; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 930 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 931 | mutex_lock(&ifibss->mtx); |
| 932 | |
| 933 | /* |
| 934 | * Work could be scheduled after scan or similar |
| 935 | * when we aren't even joined (or trying) with a |
| 936 | * network. |
| 937 | */ |
| 938 | if (!ifibss->ssid_len) |
| 939 | goto out; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 940 | |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 941 | spin_lock_bh(&ifibss->incomplete_lock); |
| 942 | while (!list_empty(&ifibss->incomplete_stations)) { |
| 943 | sta = list_first_entry(&ifibss->incomplete_stations, |
| 944 | struct sta_info, list); |
| 945 | list_del(&sta->list); |
| 946 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 947 | |
| 948 | ieee80211_ibss_finish_sta(sta); |
| 949 | rcu_read_unlock(); |
| 950 | spin_lock_bh(&ifibss->incomplete_lock); |
| 951 | } |
| 952 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 953 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 954 | switch (ifibss->state) { |
| 955 | case IEEE80211_IBSS_MLME_SEARCH: |
| 956 | ieee80211_sta_find_ibss(sdata); |
| 957 | break; |
| 958 | case IEEE80211_IBSS_MLME_JOINED: |
| 959 | ieee80211_sta_merge_ibss(sdata); |
| 960 | break; |
| 961 | default: |
| 962 | WARN_ON(1); |
| 963 | break; |
| 964 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 965 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 966 | out: |
| 967 | mutex_unlock(&ifibss->mtx); |
Johannes Berg | 3a4d4aa | 2010-05-26 16:41:40 +0200 | [diff] [blame] | 968 | } |
| 969 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 970 | static void ieee80211_ibss_timer(unsigned long data) |
| 971 | { |
| 972 | struct ieee80211_sub_if_data *sdata = |
| 973 | (struct ieee80211_sub_if_data *) data; |
| 974 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 975 | struct ieee80211_local *local = sdata->local; |
| 976 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 977 | if (local->quiescing) { |
| 978 | ifibss->timer_running = true; |
| 979 | return; |
| 980 | } |
| 981 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 982 | ieee80211_queue_work(&local->hw, &sdata->work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 983 | } |
| 984 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 985 | #ifdef CONFIG_PM |
| 986 | void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata) |
| 987 | { |
| 988 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 989 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 990 | if (del_timer_sync(&ifibss->timer)) |
| 991 | ifibss->timer_running = true; |
| 992 | } |
| 993 | |
| 994 | void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata) |
| 995 | { |
| 996 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 997 | |
| 998 | if (ifibss->timer_running) { |
| 999 | add_timer(&ifibss->timer); |
| 1000 | ifibss->timer_running = false; |
| 1001 | } |
| 1002 | } |
| 1003 | #endif |
| 1004 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1005 | void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 1006 | { |
| 1007 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 1008 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1009 | setup_timer(&ifibss->timer, ieee80211_ibss_timer, |
| 1010 | (unsigned long) sdata); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1011 | mutex_init(&ifibss->mtx); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1012 | INIT_LIST_HEAD(&ifibss->incomplete_stations); |
| 1013 | spin_lock_init(&ifibss->incomplete_lock); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | /* scan finished notification */ |
| 1017 | void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) |
| 1018 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1019 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1020 | |
Johannes Berg | 29b4a4f | 2009-04-21 00:30:49 +0200 | [diff] [blame] | 1021 | mutex_lock(&local->iflist_mtx); |
| 1022 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1023 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 1024 | continue; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1025 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC) |
| 1026 | continue; |
| 1027 | sdata->u.ibss.last_scan_completed = jiffies; |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1028 | ieee80211_queue_work(&local->hw, &sdata->work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1029 | } |
Johannes Berg | 29b4a4f | 2009-04-21 00:30:49 +0200 | [diff] [blame] | 1030 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1033 | int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, |
| 1034 | struct cfg80211_ibss_params *params) |
| 1035 | { |
| 1036 | struct sk_buff *skb; |
Simon Wunderlich | ff3cc5f | 2011-11-30 16:56:33 +0100 | [diff] [blame] | 1037 | u32 changed = 0; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1038 | |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1039 | skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 1040 | sizeof(struct ieee80211_hdr_3addr) + |
| 1041 | 12 /* struct ieee80211_mgmt.u.beacon */ + |
| 1042 | 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ + |
| 1043 | 2 + 8 /* max Supported Rates */ + |
| 1044 | 3 /* max DS params */ + |
| 1045 | 4 /* IBSS params */ + |
| 1046 | 2 + (IEEE80211_MAX_SUPP_RATES - 8) + |
| 1047 | 2 + sizeof(struct ieee80211_ht_cap) + |
| 1048 | 2 + sizeof(struct ieee80211_ht_info) + |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1049 | params->ie_len); |
| 1050 | if (!skb) |
| 1051 | return -ENOMEM; |
| 1052 | |
| 1053 | mutex_lock(&sdata->u.ibss.mtx); |
| 1054 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1055 | if (params->bssid) { |
| 1056 | memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN); |
| 1057 | sdata->u.ibss.fixed_bssid = true; |
| 1058 | } else |
| 1059 | sdata->u.ibss.fixed_bssid = false; |
| 1060 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1061 | sdata->u.ibss.privacy = params->privacy; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 1062 | sdata->u.ibss.basic_rates = params->basic_rates; |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 1063 | memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate, |
| 1064 | sizeof(params->mcast_rate)); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1065 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 1066 | sdata->vif.bss_conf.beacon_int = params->beacon_interval; |
| 1067 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1068 | sdata->u.ibss.channel = params->channel; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 1069 | sdata->u.ibss.channel_type = params->channel_type; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1070 | sdata->u.ibss.fixed_channel = params->channel_fixed; |
| 1071 | |
Johannes Berg | adfba3c | 2010-05-05 15:33:55 +0200 | [diff] [blame] | 1072 | /* fix ourselves to that channel now already */ |
| 1073 | if (params->channel_fixed) { |
| 1074 | sdata->local->oper_channel = params->channel; |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 1075 | if (!ieee80211_set_channel_type(sdata->local, sdata, |
Dan Carpenter | fb03c5e | 2011-12-08 09:49:03 +0300 | [diff] [blame] | 1076 | params->channel_type)) { |
| 1077 | mutex_unlock(&sdata->u.ibss.mtx); |
Simon Wunderlich | cb71b8d | 2011-12-14 13:33:30 +0100 | [diff] [blame] | 1078 | kfree_skb(skb); |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 1079 | return -EINVAL; |
Dan Carpenter | fb03c5e | 2011-12-08 09:49:03 +0300 | [diff] [blame] | 1080 | } |
Johannes Berg | adfba3c | 2010-05-05 15:33:55 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1083 | if (params->ie) { |
| 1084 | sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len, |
| 1085 | GFP_KERNEL); |
| 1086 | if (sdata->u.ibss.ie) |
| 1087 | sdata->u.ibss.ie_len = params->ie_len; |
| 1088 | } |
| 1089 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1090 | sdata->u.ibss.skb = skb; |
| 1091 | sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; |
| 1092 | sdata->u.ibss.ibss_join_req = jiffies; |
| 1093 | |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 1094 | memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN); |
Johannes Berg | 0e41f71 | 2009-04-23 11:48:56 +0200 | [diff] [blame] | 1095 | sdata->u.ibss.ssid_len = params->ssid_len; |
| 1096 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1097 | mutex_unlock(&sdata->u.ibss.mtx); |
| 1098 | |
| 1099 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1100 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1101 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1102 | |
Simon Wunderlich | ff3cc5f | 2011-11-30 16:56:33 +0100 | [diff] [blame] | 1103 | /* |
| 1104 | * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is |
| 1105 | * reserved, but an HT STA shall protect HT transmissions as though |
| 1106 | * the HT Protection field were set to non-HT mixed mode. |
| 1107 | * |
| 1108 | * In an IBSS, the RIFS Mode field of the HT Operation element is |
| 1109 | * also reserved, but an HT STA shall operate as though this field |
| 1110 | * were set to 1. |
| 1111 | */ |
| 1112 | |
| 1113 | sdata->vif.bss_conf.ht_operation_mode |= |
| 1114 | IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED |
| 1115 | | IEEE80211_HT_PARAM_RIFS_MODE; |
| 1116 | |
| 1117 | changed |= BSS_CHANGED_HT; |
| 1118 | ieee80211_bss_info_change_notify(sdata, changed); |
| 1119 | |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 1120 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata) |
| 1126 | { |
| 1127 | struct sk_buff *skb; |
Teemu Paasikivi | 5ea096c | 2010-06-14 12:55:33 +0300 | [diff] [blame] | 1128 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 1129 | struct ieee80211_local *local = sdata->local; |
| 1130 | struct cfg80211_bss *cbss; |
| 1131 | u16 capability; |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1132 | int active_ibss; |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1133 | struct sta_info *sta; |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1134 | |
| 1135 | mutex_lock(&sdata->u.ibss.mtx); |
Teemu Paasikivi | 5ea096c | 2010-06-14 12:55:33 +0300 | [diff] [blame] | 1136 | |
Johannes Berg | f3209be | 2011-06-08 13:27:29 +0200 | [diff] [blame] | 1137 | sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; |
| 1138 | memset(sdata->u.ibss.bssid, 0, ETH_ALEN); |
| 1139 | sdata->u.ibss.ssid_len = 0; |
| 1140 | |
Teemu Paasikivi | 5ea096c | 2010-06-14 12:55:33 +0300 | [diff] [blame] | 1141 | active_ibss = ieee80211_sta_active_ibss(sdata); |
| 1142 | |
| 1143 | if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) { |
| 1144 | capability = WLAN_CAPABILITY_IBSS; |
| 1145 | |
| 1146 | if (ifibss->privacy) |
| 1147 | capability |= WLAN_CAPABILITY_PRIVACY; |
| 1148 | |
| 1149 | cbss = cfg80211_get_bss(local->hw.wiphy, ifibss->channel, |
| 1150 | ifibss->bssid, ifibss->ssid, |
| 1151 | ifibss->ssid_len, WLAN_CAPABILITY_IBSS | |
| 1152 | WLAN_CAPABILITY_PRIVACY, |
| 1153 | capability); |
| 1154 | |
| 1155 | if (cbss) { |
| 1156 | cfg80211_unlink_bss(local->hw.wiphy, cbss); |
| 1157 | cfg80211_put_bss(cbss); |
| 1158 | } |
| 1159 | } |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1160 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1161 | sta_info_flush(sdata->local, sdata); |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1162 | |
| 1163 | spin_lock_bh(&ifibss->incomplete_lock); |
| 1164 | while (!list_empty(&ifibss->incomplete_stations)) { |
| 1165 | sta = list_first_entry(&ifibss->incomplete_stations, |
| 1166 | struct sta_info, list); |
| 1167 | list_del(&sta->list); |
| 1168 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 1169 | |
| 1170 | sta_info_free(local, sta); |
| 1171 | spin_lock_bh(&ifibss->incomplete_lock); |
| 1172 | } |
| 1173 | spin_unlock_bh(&ifibss->incomplete_lock); |
| 1174 | |
Eliad Peller | 86a2ea4 | 2011-11-08 15:36:59 +0200 | [diff] [blame] | 1175 | netif_carrier_off(sdata->dev); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1176 | |
| 1177 | /* remove beacon */ |
| 1178 | kfree(sdata->u.ibss.ie); |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 1179 | skb = rcu_dereference_protected(sdata->u.ibss.presp, |
| 1180 | lockdep_is_held(&sdata->u.ibss.mtx)); |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 1181 | RCU_INIT_POINTER(sdata->u.ibss.presp, NULL); |
Johannes Berg | 8fc214b | 2010-04-28 17:40:43 +0200 | [diff] [blame] | 1182 | sdata->vif.bss_conf.ibss_joined = false; |
| 1183 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | |
| 1184 | BSS_CHANGED_IBSS); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1185 | synchronize_rcu(); |
| 1186 | kfree_skb(skb); |
| 1187 | |
Johannes Berg | 35f20c1 | 2010-06-10 10:21:30 +0200 | [diff] [blame] | 1188 | skb_queue_purge(&sdata->skb_queue); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1189 | |
Johannes Berg | bc05d19 | 2010-07-21 10:52:40 +0200 | [diff] [blame] | 1190 | del_timer_sync(&sdata->u.ibss.timer); |
Johannes Berg | 7a17a33 | 2010-07-21 11:30:27 +0200 | [diff] [blame] | 1191 | |
| 1192 | mutex_unlock(&sdata->u.ibss.mtx); |
Johannes Berg | bc05d19 | 2010-07-21 10:52:40 +0200 | [diff] [blame] | 1193 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1194 | mutex_lock(&local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1195 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1196 | mutex_unlock(&local->mtx); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1197 | |
| 1198 | return 0; |
| 1199 | } |