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