Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSS client mode implementation |
| 3 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.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 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | /* TODO: |
| 15 | * BSS table: use <BSSID,SSID> as the key to support multi-SSID APs |
| 16 | * order BSS list by RSSI(?) ("quality of AP") |
| 17 | * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE, |
| 18 | * SSID) |
| 19 | */ |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 21 | #include <linux/if_ether.h> |
| 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/if_arp.h> |
| 25 | #include <linux/wireless.h> |
| 26 | #include <linux/random.h> |
| 27 | #include <linux/etherdevice.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | #include <net/iw_handler.h> |
| 29 | #include <asm/types.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | |
| 31 | #include <net/mac80211.h> |
| 32 | #include "ieee80211_i.h" |
| 33 | #include "ieee80211_rate.h" |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 34 | #include "ieee80211_led.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 35 | |
| 36 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
| 37 | #define IEEE80211_AUTH_MAX_TRIES 3 |
| 38 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) |
| 39 | #define IEEE80211_ASSOC_MAX_TRIES 3 |
| 40 | #define IEEE80211_MONITORING_INTERVAL (2 * HZ) |
| 41 | #define IEEE80211_PROBE_INTERVAL (60 * HZ) |
| 42 | #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) |
| 43 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) |
| 44 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) |
| 45 | #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ) |
| 46 | |
| 47 | #define IEEE80211_PROBE_DELAY (HZ / 33) |
| 48 | #define IEEE80211_CHANNEL_TIME (HZ / 33) |
| 49 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) |
| 50 | #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) |
| 51 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) |
| 52 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
| 53 | |
| 54 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 |
| 55 | |
| 56 | |
| 57 | #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype) |
| 58 | |
| 59 | #define ERP_INFO_USE_PROTECTION BIT(1) |
| 60 | |
| 61 | static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst, |
| 62 | u8 *ssid, size_t ssid_len); |
| 63 | static struct ieee80211_sta_bss * |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 64 | ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 65 | static void ieee80211_rx_bss_put(struct net_device *dev, |
| 66 | struct ieee80211_sta_bss *bss); |
| 67 | static int ieee80211_sta_find_ibss(struct net_device *dev, |
| 68 | struct ieee80211_if_sta *ifsta); |
| 69 | static int ieee80211_sta_wep_configured(struct net_device *dev); |
| 70 | static int ieee80211_sta_start_scan(struct net_device *dev, |
| 71 | u8 *ssid, size_t ssid_len); |
| 72 | static int ieee80211_sta_config_auth(struct net_device *dev, |
| 73 | struct ieee80211_if_sta *ifsta); |
| 74 | |
| 75 | |
| 76 | /* Parsed Information Elements */ |
| 77 | struct ieee802_11_elems { |
Johannes Berg | 5558235 | 2007-07-10 19:32:09 +0200 | [diff] [blame] | 78 | /* pointers to IEs */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 79 | u8 *ssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 80 | u8 *supp_rates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 81 | u8 *fh_params; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 82 | u8 *ds_params; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 83 | u8 *cf_params; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 84 | u8 *tim; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 85 | u8 *ibss_params; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 86 | u8 *challenge; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 87 | u8 *wpa; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 88 | u8 *rsn; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 89 | u8 *erp_info; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 90 | u8 *ext_supp_rates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 91 | u8 *wmm_info; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 92 | u8 *wmm_param; |
Johannes Berg | 5558235 | 2007-07-10 19:32:09 +0200 | [diff] [blame] | 93 | |
| 94 | /* length of them, respectively */ |
| 95 | u8 ssid_len; |
| 96 | u8 supp_rates_len; |
| 97 | u8 fh_params_len; |
| 98 | u8 ds_params_len; |
| 99 | u8 cf_params_len; |
| 100 | u8 tim_len; |
| 101 | u8 ibss_params_len; |
| 102 | u8 challenge_len; |
| 103 | u8 wpa_len; |
| 104 | u8 rsn_len; |
| 105 | u8 erp_info_len; |
| 106 | u8 ext_supp_rates_len; |
| 107 | u8 wmm_info_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 108 | u8 wmm_param_len; |
| 109 | }; |
| 110 | |
Johannes Berg | c095df5 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 111 | enum ParseRes { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 }; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 112 | |
Johannes Berg | c095df5 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 113 | static enum ParseRes ieee802_11_parse_elems(u8 *start, size_t len, |
| 114 | struct ieee802_11_elems *elems) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 115 | { |
| 116 | size_t left = len; |
| 117 | u8 *pos = start; |
| 118 | int unknown = 0; |
| 119 | |
| 120 | memset(elems, 0, sizeof(*elems)); |
| 121 | |
| 122 | while (left >= 2) { |
| 123 | u8 id, elen; |
| 124 | |
| 125 | id = *pos++; |
| 126 | elen = *pos++; |
| 127 | left -= 2; |
| 128 | |
| 129 | if (elen > left) { |
| 130 | #if 0 |
| 131 | if (net_ratelimit()) |
| 132 | printk(KERN_DEBUG "IEEE 802.11 element parse " |
| 133 | "failed (id=%d elen=%d left=%d)\n", |
| 134 | id, elen, left); |
| 135 | #endif |
| 136 | return ParseFailed; |
| 137 | } |
| 138 | |
| 139 | switch (id) { |
| 140 | case WLAN_EID_SSID: |
| 141 | elems->ssid = pos; |
| 142 | elems->ssid_len = elen; |
| 143 | break; |
| 144 | case WLAN_EID_SUPP_RATES: |
| 145 | elems->supp_rates = pos; |
| 146 | elems->supp_rates_len = elen; |
| 147 | break; |
| 148 | case WLAN_EID_FH_PARAMS: |
| 149 | elems->fh_params = pos; |
| 150 | elems->fh_params_len = elen; |
| 151 | break; |
| 152 | case WLAN_EID_DS_PARAMS: |
| 153 | elems->ds_params = pos; |
| 154 | elems->ds_params_len = elen; |
| 155 | break; |
| 156 | case WLAN_EID_CF_PARAMS: |
| 157 | elems->cf_params = pos; |
| 158 | elems->cf_params_len = elen; |
| 159 | break; |
| 160 | case WLAN_EID_TIM: |
| 161 | elems->tim = pos; |
| 162 | elems->tim_len = elen; |
| 163 | break; |
| 164 | case WLAN_EID_IBSS_PARAMS: |
| 165 | elems->ibss_params = pos; |
| 166 | elems->ibss_params_len = elen; |
| 167 | break; |
| 168 | case WLAN_EID_CHALLENGE: |
| 169 | elems->challenge = pos; |
| 170 | elems->challenge_len = elen; |
| 171 | break; |
| 172 | case WLAN_EID_WPA: |
| 173 | if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && |
| 174 | pos[2] == 0xf2) { |
| 175 | /* Microsoft OUI (00:50:F2) */ |
| 176 | if (pos[3] == 1) { |
| 177 | /* OUI Type 1 - WPA IE */ |
| 178 | elems->wpa = pos; |
| 179 | elems->wpa_len = elen; |
| 180 | } else if (elen >= 5 && pos[3] == 2) { |
| 181 | if (pos[4] == 0) { |
| 182 | elems->wmm_info = pos; |
| 183 | elems->wmm_info_len = elen; |
| 184 | } else if (pos[4] == 1) { |
| 185 | elems->wmm_param = pos; |
| 186 | elems->wmm_param_len = elen; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | break; |
| 191 | case WLAN_EID_RSN: |
| 192 | elems->rsn = pos; |
| 193 | elems->rsn_len = elen; |
| 194 | break; |
| 195 | case WLAN_EID_ERP_INFO: |
| 196 | elems->erp_info = pos; |
| 197 | elems->erp_info_len = elen; |
| 198 | break; |
| 199 | case WLAN_EID_EXT_SUPP_RATES: |
| 200 | elems->ext_supp_rates = pos; |
| 201 | elems->ext_supp_rates_len = elen; |
| 202 | break; |
| 203 | default: |
| 204 | #if 0 |
| 205 | printk(KERN_DEBUG "IEEE 802.11 element parse ignored " |
| 206 | "unknown element (id=%d elen=%d)\n", |
| 207 | id, elen); |
| 208 | #endif |
| 209 | unknown++; |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | left -= elen; |
| 214 | pos += elen; |
| 215 | } |
| 216 | |
| 217 | /* Do not trigger error if left == 1 as Apple Airport base stations |
| 218 | * send AssocResps that are one spurious byte too long. */ |
| 219 | |
| 220 | return unknown ? ParseUnknown : ParseOK; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | static int ecw2cw(int ecw) |
| 227 | { |
| 228 | int cw = 1; |
| 229 | while (ecw > 0) { |
| 230 | cw <<= 1; |
| 231 | ecw--; |
| 232 | } |
| 233 | return cw - 1; |
| 234 | } |
| 235 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 236 | static void ieee80211_sta_wmm_params(struct net_device *dev, |
| 237 | struct ieee80211_if_sta *ifsta, |
| 238 | u8 *wmm_param, size_t wmm_param_len) |
| 239 | { |
| 240 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 241 | struct ieee80211_tx_queue_params params; |
| 242 | size_t left; |
| 243 | int count; |
| 244 | u8 *pos; |
| 245 | |
| 246 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
| 247 | return; |
| 248 | count = wmm_param[6] & 0x0f; |
| 249 | if (count == ifsta->wmm_last_param_set) |
| 250 | return; |
| 251 | ifsta->wmm_last_param_set = count; |
| 252 | |
| 253 | pos = wmm_param + 8; |
| 254 | left = wmm_param_len - 8; |
| 255 | |
| 256 | memset(¶ms, 0, sizeof(params)); |
| 257 | |
| 258 | if (!local->ops->conf_tx) |
| 259 | return; |
| 260 | |
| 261 | local->wmm_acm = 0; |
| 262 | for (; left >= 4; left -= 4, pos += 4) { |
| 263 | int aci = (pos[0] >> 5) & 0x03; |
| 264 | int acm = (pos[0] >> 4) & 0x01; |
| 265 | int queue; |
| 266 | |
| 267 | switch (aci) { |
| 268 | case 1: |
| 269 | queue = IEEE80211_TX_QUEUE_DATA3; |
| 270 | if (acm) { |
| 271 | local->wmm_acm |= BIT(0) | BIT(3); |
| 272 | } |
| 273 | break; |
| 274 | case 2: |
| 275 | queue = IEEE80211_TX_QUEUE_DATA1; |
| 276 | if (acm) { |
| 277 | local->wmm_acm |= BIT(4) | BIT(5); |
| 278 | } |
| 279 | break; |
| 280 | case 3: |
| 281 | queue = IEEE80211_TX_QUEUE_DATA0; |
| 282 | if (acm) { |
| 283 | local->wmm_acm |= BIT(6) | BIT(7); |
| 284 | } |
| 285 | break; |
| 286 | case 0: |
| 287 | default: |
| 288 | queue = IEEE80211_TX_QUEUE_DATA2; |
| 289 | if (acm) { |
| 290 | local->wmm_acm |= BIT(1) | BIT(2); |
| 291 | } |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | params.aifs = pos[0] & 0x0f; |
| 296 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 297 | params.cw_min = ecw2cw(pos[1] & 0x0f); |
| 298 | /* TXOP is in units of 32 usec; burst_time in 0.1 ms */ |
| 299 | params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100; |
| 300 | printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " |
| 301 | "cWmin=%d cWmax=%d burst=%d\n", |
| 302 | dev->name, queue, aci, acm, params.aifs, params.cw_min, |
| 303 | params.cw_max, params.burst_time); |
| 304 | /* TODO: handle ACM (block TX, fallback to next lowest allowed |
| 305 | * AC for now) */ |
| 306 | if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) { |
| 307 | printk(KERN_DEBUG "%s: failed to set TX queue " |
| 308 | "parameters for queue %d\n", dev->name, queue); |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 314 | static void ieee80211_handle_erp_ie(struct net_device *dev, u8 erp_value) |
| 315 | { |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 316 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 317 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 318 | int use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 319 | int preamble_mode = (erp_value & WLAN_ERP_BARKER_PREAMBLE) != 0; |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 320 | u8 changes = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 321 | DECLARE_MAC_BUF(mac); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 322 | |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 323 | if (use_protection != !!(sdata->flags & IEEE80211_SDATA_USE_PROTECTION)) { |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 324 | if (net_ratelimit()) { |
| 325 | printk(KERN_DEBUG "%s: CTS protection %s (BSSID=" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 326 | "%s)\n", |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 327 | dev->name, |
| 328 | use_protection ? "enabled" : "disabled", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 329 | print_mac(mac, ifsta->bssid)); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 330 | } |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 331 | if (use_protection) |
| 332 | sdata->flags |= IEEE80211_SDATA_USE_PROTECTION; |
| 333 | else |
| 334 | sdata->flags &= ~IEEE80211_SDATA_USE_PROTECTION; |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 335 | changes |= IEEE80211_ERP_CHANGE_PROTECTION; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 336 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 337 | |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 338 | if (preamble_mode != !(sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE)) { |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 339 | if (net_ratelimit()) { |
| 340 | printk(KERN_DEBUG "%s: switched to %s barker preamble" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 341 | " (BSSID=%s)\n", |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 342 | dev->name, |
| 343 | (preamble_mode == WLAN_ERP_PREAMBLE_SHORT) ? |
| 344 | "short" : "long", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 345 | print_mac(mac, ifsta->bssid)); |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 346 | } |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 347 | if (preamble_mode) |
| 348 | sdata->flags &= ~IEEE80211_SDATA_SHORT_PREAMBLE; |
| 349 | else |
| 350 | sdata->flags |= IEEE80211_SDATA_SHORT_PREAMBLE; |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 351 | changes |= IEEE80211_ERP_CHANGE_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 352 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 353 | |
| 354 | if (changes) |
| 355 | ieee80211_erp_info_change_notify(dev, changes); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 359 | static void ieee80211_sta_send_associnfo(struct net_device *dev, |
| 360 | struct ieee80211_if_sta *ifsta) |
| 361 | { |
| 362 | char *buf; |
| 363 | size_t len; |
| 364 | int i; |
| 365 | union iwreq_data wrqu; |
| 366 | |
| 367 | if (!ifsta->assocreq_ies && !ifsta->assocresp_ies) |
| 368 | return; |
| 369 | |
| 370 | buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len + |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 371 | ifsta->assocresp_ies_len), GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 372 | if (!buf) |
| 373 | return; |
| 374 | |
| 375 | len = sprintf(buf, "ASSOCINFO("); |
| 376 | if (ifsta->assocreq_ies) { |
| 377 | len += sprintf(buf + len, "ReqIEs="); |
| 378 | for (i = 0; i < ifsta->assocreq_ies_len; i++) { |
| 379 | len += sprintf(buf + len, "%02x", |
| 380 | ifsta->assocreq_ies[i]); |
| 381 | } |
| 382 | } |
| 383 | if (ifsta->assocresp_ies) { |
| 384 | if (ifsta->assocreq_ies) |
| 385 | len += sprintf(buf + len, " "); |
| 386 | len += sprintf(buf + len, "RespIEs="); |
| 387 | for (i = 0; i < ifsta->assocresp_ies_len; i++) { |
| 388 | len += sprintf(buf + len, "%02x", |
| 389 | ifsta->assocresp_ies[i]); |
| 390 | } |
| 391 | } |
| 392 | len += sprintf(buf + len, ")"); |
| 393 | |
| 394 | if (len > IW_CUSTOM_MAX) { |
| 395 | len = sprintf(buf, "ASSOCRESPIE="); |
| 396 | for (i = 0; i < ifsta->assocresp_ies_len; i++) { |
| 397 | len += sprintf(buf + len, "%02x", |
| 398 | ifsta->assocresp_ies[i]); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | memset(&wrqu, 0, sizeof(wrqu)); |
| 403 | wrqu.data.length = len; |
| 404 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); |
| 405 | |
| 406 | kfree(buf); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | static void ieee80211_set_associated(struct net_device *dev, |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 411 | struct ieee80211_if_sta *ifsta, |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 412 | bool assoc) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 413 | { |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 414 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 415 | union iwreq_data wrqu; |
| 416 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 417 | if (!!(ifsta->flags & IEEE80211_STA_ASSOCIATED) == assoc) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 418 | return; |
| 419 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 420 | if (assoc) { |
| 421 | struct ieee80211_sub_if_data *sdata; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 422 | struct ieee80211_sta_bss *bss; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 423 | |
| 424 | ifsta->flags |= IEEE80211_STA_ASSOCIATED; |
| 425 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 426 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 427 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 428 | return; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 429 | |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 430 | bss = ieee80211_rx_bss_get(dev, ifsta->bssid, |
| 431 | local->hw.conf.channel); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 432 | if (bss) { |
| 433 | if (bss->has_erp_value) |
| 434 | ieee80211_handle_erp_ie(dev, bss->erp_value); |
| 435 | ieee80211_rx_bss_put(dev, bss); |
| 436 | } |
| 437 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 438 | netif_carrier_on(dev); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 439 | ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 440 | memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN); |
| 441 | memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN); |
| 442 | ieee80211_sta_send_associnfo(dev, ifsta); |
| 443 | } else { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 444 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
| 445 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 446 | netif_carrier_off(dev); |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 447 | ieee80211_reset_erp_info(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 448 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 449 | } |
| 450 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 451 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 452 | ifsta->last_probe = jiffies; |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 453 | ieee80211_led_assoc(local, assoc); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static void ieee80211_set_disassoc(struct net_device *dev, |
| 457 | struct ieee80211_if_sta *ifsta, int deauth) |
| 458 | { |
| 459 | if (deauth) |
| 460 | ifsta->auth_tries = 0; |
| 461 | ifsta->assoc_tries = 0; |
| 462 | ieee80211_set_associated(dev, ifsta, 0); |
| 463 | } |
| 464 | |
| 465 | static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb, |
| 466 | int encrypt) |
| 467 | { |
| 468 | struct ieee80211_sub_if_data *sdata; |
| 469 | struct ieee80211_tx_packet_data *pkt_data; |
| 470 | |
| 471 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 472 | skb->dev = sdata->local->mdev; |
| 473 | skb_set_mac_header(skb, 0); |
| 474 | skb_set_network_header(skb, 0); |
| 475 | skb_set_transport_header(skb, 0); |
| 476 | |
| 477 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; |
| 478 | memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data)); |
| 479 | pkt_data->ifindex = sdata->dev->ifindex; |
Jiri Slaby | e8bf964 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 480 | if (!encrypt) |
| 481 | pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 482 | |
| 483 | dev_queue_xmit(skb); |
| 484 | } |
| 485 | |
| 486 | |
| 487 | static void ieee80211_send_auth(struct net_device *dev, |
| 488 | struct ieee80211_if_sta *ifsta, |
| 489 | int transaction, u8 *extra, size_t extra_len, |
| 490 | int encrypt) |
| 491 | { |
| 492 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 493 | struct sk_buff *skb; |
| 494 | struct ieee80211_mgmt *mgmt; |
| 495 | |
| 496 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 497 | sizeof(*mgmt) + 6 + extra_len); |
| 498 | if (!skb) { |
| 499 | printk(KERN_DEBUG "%s: failed to allocate buffer for auth " |
| 500 | "frame\n", dev->name); |
| 501 | return; |
| 502 | } |
| 503 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 504 | |
| 505 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); |
| 506 | memset(mgmt, 0, 24 + 6); |
| 507 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 508 | IEEE80211_STYPE_AUTH); |
| 509 | if (encrypt) |
| 510 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 511 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 512 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 513 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 514 | mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg); |
| 515 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); |
| 516 | ifsta->auth_transaction = transaction + 1; |
| 517 | mgmt->u.auth.status_code = cpu_to_le16(0); |
| 518 | if (extra) |
| 519 | memcpy(skb_put(skb, extra_len), extra, extra_len); |
| 520 | |
| 521 | ieee80211_sta_tx(dev, skb, encrypt); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | static void ieee80211_authenticate(struct net_device *dev, |
| 526 | struct ieee80211_if_sta *ifsta) |
| 527 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 528 | DECLARE_MAC_BUF(mac); |
| 529 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 530 | ifsta->auth_tries++; |
| 531 | if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 532 | printk(KERN_DEBUG "%s: authentication with AP %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 533 | " timed out\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 534 | dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 535 | ifsta->state = IEEE80211_DISABLED; |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | ifsta->state = IEEE80211_AUTHENTICATE; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 540 | printk(KERN_DEBUG "%s: authenticate with AP %s\n", |
| 541 | dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 542 | |
| 543 | ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0); |
| 544 | |
| 545 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); |
| 546 | } |
| 547 | |
| 548 | |
| 549 | static void ieee80211_send_assoc(struct net_device *dev, |
| 550 | struct ieee80211_if_sta *ifsta) |
| 551 | { |
| 552 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 553 | struct ieee80211_hw_mode *mode; |
| 554 | struct sk_buff *skb; |
| 555 | struct ieee80211_mgmt *mgmt; |
| 556 | u8 *pos, *ies; |
| 557 | int i, len; |
| 558 | u16 capab; |
| 559 | struct ieee80211_sta_bss *bss; |
| 560 | int wmm = 0; |
| 561 | |
| 562 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 563 | sizeof(*mgmt) + 200 + ifsta->extra_ie_len + |
| 564 | ifsta->ssid_len); |
| 565 | if (!skb) { |
| 566 | printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " |
| 567 | "frame\n", dev->name); |
| 568 | return; |
| 569 | } |
| 570 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 571 | |
| 572 | mode = local->oper_hw_mode; |
| 573 | capab = ifsta->capab; |
| 574 | if (mode->mode == MODE_IEEE80211G) { |
| 575 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME | |
| 576 | WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 577 | } |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 578 | bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 579 | if (bss) { |
| 580 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
| 581 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 582 | if (bss->wmm_ie) { |
| 583 | wmm = 1; |
| 584 | } |
| 585 | ieee80211_rx_bss_put(dev, bss); |
| 586 | } |
| 587 | |
| 588 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 589 | memset(mgmt, 0, 24); |
| 590 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 591 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 592 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 593 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 594 | if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 595 | skb_put(skb, 10); |
| 596 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 597 | IEEE80211_STYPE_REASSOC_REQ); |
| 598 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 599 | mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1); |
| 600 | memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid, |
| 601 | ETH_ALEN); |
| 602 | } else { |
| 603 | skb_put(skb, 4); |
| 604 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 605 | IEEE80211_STYPE_ASSOC_REQ); |
| 606 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 607 | mgmt->u.assoc_req.listen_interval = cpu_to_le16(1); |
| 608 | } |
| 609 | |
| 610 | /* SSID */ |
| 611 | ies = pos = skb_put(skb, 2 + ifsta->ssid_len); |
| 612 | *pos++ = WLAN_EID_SSID; |
| 613 | *pos++ = ifsta->ssid_len; |
| 614 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); |
| 615 | |
| 616 | len = mode->num_rates; |
| 617 | if (len > 8) |
| 618 | len = 8; |
| 619 | pos = skb_put(skb, len + 2); |
| 620 | *pos++ = WLAN_EID_SUPP_RATES; |
| 621 | *pos++ = len; |
| 622 | for (i = 0; i < len; i++) { |
| 623 | int rate = mode->rates[i].rate; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 624 | *pos++ = (u8) (rate / 5); |
| 625 | } |
| 626 | |
| 627 | if (mode->num_rates > len) { |
| 628 | pos = skb_put(skb, mode->num_rates - len + 2); |
| 629 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 630 | *pos++ = mode->num_rates - len; |
| 631 | for (i = len; i < mode->num_rates; i++) { |
| 632 | int rate = mode->rates[i].rate; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 633 | *pos++ = (u8) (rate / 5); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | if (ifsta->extra_ie) { |
| 638 | pos = skb_put(skb, ifsta->extra_ie_len); |
| 639 | memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len); |
| 640 | } |
| 641 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 642 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 643 | pos = skb_put(skb, 9); |
| 644 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 645 | *pos++ = 7; /* len */ |
| 646 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 647 | *pos++ = 0x50; |
| 648 | *pos++ = 0xf2; |
| 649 | *pos++ = 2; /* WME */ |
| 650 | *pos++ = 0; /* WME info */ |
| 651 | *pos++ = 1; /* WME ver */ |
| 652 | *pos++ = 0; |
| 653 | } |
| 654 | |
| 655 | kfree(ifsta->assocreq_ies); |
| 656 | ifsta->assocreq_ies_len = (skb->data + skb->len) - ies; |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 657 | ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 658 | if (ifsta->assocreq_ies) |
| 659 | memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len); |
| 660 | |
| 661 | ieee80211_sta_tx(dev, skb, 0); |
| 662 | } |
| 663 | |
| 664 | |
| 665 | static void ieee80211_send_deauth(struct net_device *dev, |
| 666 | struct ieee80211_if_sta *ifsta, u16 reason) |
| 667 | { |
| 668 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 669 | struct sk_buff *skb; |
| 670 | struct ieee80211_mgmt *mgmt; |
| 671 | |
| 672 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
| 673 | if (!skb) { |
| 674 | printk(KERN_DEBUG "%s: failed to allocate buffer for deauth " |
| 675 | "frame\n", dev->name); |
| 676 | return; |
| 677 | } |
| 678 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 679 | |
| 680 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 681 | memset(mgmt, 0, 24); |
| 682 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 683 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 684 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 685 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 686 | IEEE80211_STYPE_DEAUTH); |
| 687 | skb_put(skb, 2); |
| 688 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
| 689 | |
| 690 | ieee80211_sta_tx(dev, skb, 0); |
| 691 | } |
| 692 | |
| 693 | |
| 694 | static void ieee80211_send_disassoc(struct net_device *dev, |
| 695 | struct ieee80211_if_sta *ifsta, u16 reason) |
| 696 | { |
| 697 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 698 | struct sk_buff *skb; |
| 699 | struct ieee80211_mgmt *mgmt; |
| 700 | |
| 701 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
| 702 | if (!skb) { |
| 703 | printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc " |
| 704 | "frame\n", dev->name); |
| 705 | return; |
| 706 | } |
| 707 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 708 | |
| 709 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 710 | memset(mgmt, 0, 24); |
| 711 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 712 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 713 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 714 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 715 | IEEE80211_STYPE_DISASSOC); |
| 716 | skb_put(skb, 2); |
| 717 | mgmt->u.disassoc.reason_code = cpu_to_le16(reason); |
| 718 | |
| 719 | ieee80211_sta_tx(dev, skb, 0); |
| 720 | } |
| 721 | |
| 722 | |
| 723 | static int ieee80211_privacy_mismatch(struct net_device *dev, |
| 724 | struct ieee80211_if_sta *ifsta) |
| 725 | { |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 726 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 727 | struct ieee80211_sta_bss *bss; |
| 728 | int res = 0; |
| 729 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 730 | if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL) || |
| 731 | ifsta->key_management_enabled) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 732 | return 0; |
| 733 | |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 734 | bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 735 | if (!bss) |
| 736 | return 0; |
| 737 | |
| 738 | if (ieee80211_sta_wep_configured(dev) != |
| 739 | !!(bss->capability & WLAN_CAPABILITY_PRIVACY)) |
| 740 | res = 1; |
| 741 | |
| 742 | ieee80211_rx_bss_put(dev, bss); |
| 743 | |
| 744 | return res; |
| 745 | } |
| 746 | |
| 747 | |
| 748 | static void ieee80211_associate(struct net_device *dev, |
| 749 | struct ieee80211_if_sta *ifsta) |
| 750 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 751 | DECLARE_MAC_BUF(mac); |
| 752 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 753 | ifsta->assoc_tries++; |
| 754 | if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 755 | printk(KERN_DEBUG "%s: association with AP %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 756 | " timed out\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 757 | dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 758 | ifsta->state = IEEE80211_DISABLED; |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | ifsta->state = IEEE80211_ASSOCIATE; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 763 | printk(KERN_DEBUG "%s: associate with AP %s\n", |
| 764 | dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 765 | if (ieee80211_privacy_mismatch(dev, ifsta)) { |
| 766 | printk(KERN_DEBUG "%s: mismatch in privacy configuration and " |
| 767 | "mixed-cell disabled - abort association\n", dev->name); |
| 768 | ifsta->state = IEEE80211_DISABLED; |
| 769 | return; |
| 770 | } |
| 771 | |
| 772 | ieee80211_send_assoc(dev, ifsta); |
| 773 | |
| 774 | mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); |
| 775 | } |
| 776 | |
| 777 | |
| 778 | static void ieee80211_associated(struct net_device *dev, |
| 779 | struct ieee80211_if_sta *ifsta) |
| 780 | { |
| 781 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 782 | struct sta_info *sta; |
| 783 | int disassoc; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 784 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 785 | |
| 786 | /* TODO: start monitoring current AP signal quality and number of |
| 787 | * missed beacons. Scan other channels every now and then and search |
| 788 | * for better APs. */ |
| 789 | /* TODO: remove expired BSSes */ |
| 790 | |
| 791 | ifsta->state = IEEE80211_ASSOCIATED; |
| 792 | |
| 793 | sta = sta_info_get(local, ifsta->bssid); |
| 794 | if (!sta) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 795 | printk(KERN_DEBUG "%s: No STA entry for own AP %s\n", |
| 796 | dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 797 | disassoc = 1; |
| 798 | } else { |
| 799 | disassoc = 0; |
| 800 | if (time_after(jiffies, |
| 801 | sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 802 | if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 803 | printk(KERN_DEBUG "%s: No ProbeResp from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 804 | "current AP %s - assume out of " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 805 | "range\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 806 | dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 807 | disassoc = 1; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 808 | sta_info_free(sta); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 809 | } else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 810 | ieee80211_send_probe_req(dev, ifsta->bssid, |
| 811 | local->scan_ssid, |
| 812 | local->scan_ssid_len); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 813 | ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 814 | } else { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 815 | ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 816 | if (time_after(jiffies, ifsta->last_probe + |
| 817 | IEEE80211_PROBE_INTERVAL)) { |
| 818 | ifsta->last_probe = jiffies; |
| 819 | ieee80211_send_probe_req(dev, ifsta->bssid, |
| 820 | ifsta->ssid, |
| 821 | ifsta->ssid_len); |
| 822 | } |
| 823 | } |
| 824 | sta_info_put(sta); |
| 825 | } |
| 826 | if (disassoc) { |
| 827 | union iwreq_data wrqu; |
| 828 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 829 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 830 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); |
| 831 | mod_timer(&ifsta->timer, jiffies + |
| 832 | IEEE80211_MONITORING_INTERVAL + 30 * HZ); |
| 833 | } else { |
| 834 | mod_timer(&ifsta->timer, jiffies + |
| 835 | IEEE80211_MONITORING_INTERVAL); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | |
| 840 | static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst, |
| 841 | u8 *ssid, size_t ssid_len) |
| 842 | { |
| 843 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 844 | struct ieee80211_hw_mode *mode; |
| 845 | struct sk_buff *skb; |
| 846 | struct ieee80211_mgmt *mgmt; |
| 847 | u8 *pos, *supp_rates, *esupp_rates = NULL; |
| 848 | int i; |
| 849 | |
| 850 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200); |
| 851 | if (!skb) { |
| 852 | printk(KERN_DEBUG "%s: failed to allocate buffer for probe " |
| 853 | "request\n", dev->name); |
| 854 | return; |
| 855 | } |
| 856 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 857 | |
| 858 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 859 | memset(mgmt, 0, 24); |
| 860 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 861 | IEEE80211_STYPE_PROBE_REQ); |
| 862 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 863 | if (dst) { |
| 864 | memcpy(mgmt->da, dst, ETH_ALEN); |
| 865 | memcpy(mgmt->bssid, dst, ETH_ALEN); |
| 866 | } else { |
| 867 | memset(mgmt->da, 0xff, ETH_ALEN); |
| 868 | memset(mgmt->bssid, 0xff, ETH_ALEN); |
| 869 | } |
| 870 | pos = skb_put(skb, 2 + ssid_len); |
| 871 | *pos++ = WLAN_EID_SSID; |
| 872 | *pos++ = ssid_len; |
| 873 | memcpy(pos, ssid, ssid_len); |
| 874 | |
| 875 | supp_rates = skb_put(skb, 2); |
| 876 | supp_rates[0] = WLAN_EID_SUPP_RATES; |
| 877 | supp_rates[1] = 0; |
| 878 | mode = local->oper_hw_mode; |
| 879 | for (i = 0; i < mode->num_rates; i++) { |
| 880 | struct ieee80211_rate *rate = &mode->rates[i]; |
| 881 | if (!(rate->flags & IEEE80211_RATE_SUPPORTED)) |
| 882 | continue; |
| 883 | if (esupp_rates) { |
| 884 | pos = skb_put(skb, 1); |
| 885 | esupp_rates[1]++; |
| 886 | } else if (supp_rates[1] == 8) { |
| 887 | esupp_rates = skb_put(skb, 3); |
| 888 | esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES; |
| 889 | esupp_rates[1] = 1; |
| 890 | pos = &esupp_rates[2]; |
| 891 | } else { |
| 892 | pos = skb_put(skb, 1); |
| 893 | supp_rates[1]++; |
| 894 | } |
Johannes Berg | b708e61 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 895 | *pos = rate->rate / 5; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | ieee80211_sta_tx(dev, skb, 0); |
| 899 | } |
| 900 | |
| 901 | |
| 902 | static int ieee80211_sta_wep_configured(struct net_device *dev) |
| 903 | { |
| 904 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 905 | if (!sdata || !sdata->default_key || |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 906 | sdata->default_key->conf.alg != ALG_WEP) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 907 | return 0; |
| 908 | return 1; |
| 909 | } |
| 910 | |
| 911 | |
| 912 | static void ieee80211_auth_completed(struct net_device *dev, |
| 913 | struct ieee80211_if_sta *ifsta) |
| 914 | { |
| 915 | printk(KERN_DEBUG "%s: authenticated\n", dev->name); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 916 | ifsta->flags |= IEEE80211_STA_AUTHENTICATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 917 | ieee80211_associate(dev, ifsta); |
| 918 | } |
| 919 | |
| 920 | |
| 921 | static void ieee80211_auth_challenge(struct net_device *dev, |
| 922 | struct ieee80211_if_sta *ifsta, |
| 923 | struct ieee80211_mgmt *mgmt, |
| 924 | size_t len) |
| 925 | { |
| 926 | u8 *pos; |
| 927 | struct ieee802_11_elems elems; |
| 928 | |
| 929 | printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name); |
| 930 | pos = mgmt->u.auth.variable; |
| 931 | if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems) |
| 932 | == ParseFailed) { |
| 933 | printk(KERN_DEBUG "%s: failed to parse Auth(challenge)\n", |
| 934 | dev->name); |
| 935 | return; |
| 936 | } |
| 937 | if (!elems.challenge) { |
| 938 | printk(KERN_DEBUG "%s: no challenge IE in shared key auth " |
| 939 | "frame\n", dev->name); |
| 940 | return; |
| 941 | } |
| 942 | ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2, |
| 943 | elems.challenge_len + 2, 1); |
| 944 | } |
| 945 | |
| 946 | |
| 947 | static void ieee80211_rx_mgmt_auth(struct net_device *dev, |
| 948 | struct ieee80211_if_sta *ifsta, |
| 949 | struct ieee80211_mgmt *mgmt, |
| 950 | size_t len) |
| 951 | { |
| 952 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 953 | u16 auth_alg, auth_transaction, status_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 954 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 955 | |
| 956 | if (ifsta->state != IEEE80211_AUTHENTICATE && |
| 957 | sdata->type != IEEE80211_IF_TYPE_IBSS) { |
| 958 | printk(KERN_DEBUG "%s: authentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 959 | "%s, but not in authenticate state - ignored\n", |
| 960 | dev->name, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 961 | return; |
| 962 | } |
| 963 | |
| 964 | if (len < 24 + 6) { |
| 965 | printk(KERN_DEBUG "%s: too short (%zd) authentication frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 966 | "received from %s - ignored\n", |
| 967 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 968 | return; |
| 969 | } |
| 970 | |
| 971 | if (sdata->type != IEEE80211_IF_TYPE_IBSS && |
| 972 | memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 973 | printk(KERN_DEBUG "%s: authentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 974 | "unknown AP (SA=%s BSSID=%s) - " |
| 975 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 976 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
| 980 | if (sdata->type != IEEE80211_IF_TYPE_IBSS && |
| 981 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) { |
| 982 | printk(KERN_DEBUG "%s: authentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 983 | "unknown BSSID (SA=%s BSSID=%s) - " |
| 984 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 985 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 986 | return; |
| 987 | } |
| 988 | |
| 989 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 990 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 991 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 992 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 993 | printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 994 | "transaction=%d status=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 995 | dev->name, print_mac(mac, mgmt->sa), auth_alg, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 996 | auth_transaction, status_code); |
| 997 | |
| 998 | if (sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 999 | /* IEEE 802.11 standard does not require authentication in IBSS |
| 1000 | * networks and most implementations do not seem to use it. |
| 1001 | * However, try to reply to authentication attempts if someone |
| 1002 | * has actually implemented this. |
| 1003 | * TODO: Could implement shared key authentication. */ |
| 1004 | if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) { |
| 1005 | printk(KERN_DEBUG "%s: unexpected IBSS authentication " |
| 1006 | "frame (alg=%d transaction=%d)\n", |
| 1007 | dev->name, auth_alg, auth_transaction); |
| 1008 | return; |
| 1009 | } |
| 1010 | ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0); |
| 1011 | } |
| 1012 | |
| 1013 | if (auth_alg != ifsta->auth_alg || |
| 1014 | auth_transaction != ifsta->auth_transaction) { |
| 1015 | printk(KERN_DEBUG "%s: unexpected authentication frame " |
| 1016 | "(alg=%d transaction=%d)\n", |
| 1017 | dev->name, auth_alg, auth_transaction); |
| 1018 | return; |
| 1019 | } |
| 1020 | |
| 1021 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 1022 | printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d " |
| 1023 | "code=%d)\n", dev->name, ifsta->auth_alg, status_code); |
| 1024 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { |
| 1025 | u8 algs[3]; |
| 1026 | const int num_algs = ARRAY_SIZE(algs); |
| 1027 | int i, pos; |
| 1028 | algs[0] = algs[1] = algs[2] = 0xff; |
| 1029 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 1030 | algs[0] = WLAN_AUTH_OPEN; |
| 1031 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 1032 | algs[1] = WLAN_AUTH_SHARED_KEY; |
| 1033 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 1034 | algs[2] = WLAN_AUTH_LEAP; |
| 1035 | if (ifsta->auth_alg == WLAN_AUTH_OPEN) |
| 1036 | pos = 0; |
| 1037 | else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY) |
| 1038 | pos = 1; |
| 1039 | else |
| 1040 | pos = 2; |
| 1041 | for (i = 0; i < num_algs; i++) { |
| 1042 | pos++; |
| 1043 | if (pos >= num_algs) |
| 1044 | pos = 0; |
| 1045 | if (algs[pos] == ifsta->auth_alg || |
| 1046 | algs[pos] == 0xff) |
| 1047 | continue; |
| 1048 | if (algs[pos] == WLAN_AUTH_SHARED_KEY && |
| 1049 | !ieee80211_sta_wep_configured(dev)) |
| 1050 | continue; |
| 1051 | ifsta->auth_alg = algs[pos]; |
| 1052 | printk(KERN_DEBUG "%s: set auth_alg=%d for " |
| 1053 | "next try\n", |
| 1054 | dev->name, ifsta->auth_alg); |
| 1055 | break; |
| 1056 | } |
| 1057 | } |
| 1058 | return; |
| 1059 | } |
| 1060 | |
| 1061 | switch (ifsta->auth_alg) { |
| 1062 | case WLAN_AUTH_OPEN: |
| 1063 | case WLAN_AUTH_LEAP: |
| 1064 | ieee80211_auth_completed(dev, ifsta); |
| 1065 | break; |
| 1066 | case WLAN_AUTH_SHARED_KEY: |
| 1067 | if (ifsta->auth_transaction == 4) |
| 1068 | ieee80211_auth_completed(dev, ifsta); |
| 1069 | else |
| 1070 | ieee80211_auth_challenge(dev, ifsta, mgmt, len); |
| 1071 | break; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | |
| 1076 | static void ieee80211_rx_mgmt_deauth(struct net_device *dev, |
| 1077 | struct ieee80211_if_sta *ifsta, |
| 1078 | struct ieee80211_mgmt *mgmt, |
| 1079 | size_t len) |
| 1080 | { |
| 1081 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1082 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1083 | |
| 1084 | if (len < 24 + 2) { |
| 1085 | printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1086 | "received from %s - ignored\n", |
| 1087 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1088 | return; |
| 1089 | } |
| 1090 | |
| 1091 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 1092 | printk(KERN_DEBUG "%s: deauthentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1093 | "unknown AP (SA=%s BSSID=%s) - " |
| 1094 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1095 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 1100 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1101 | printk(KERN_DEBUG "%s: RX deauthentication from %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1102 | " (reason=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1103 | dev->name, print_mac(mac, mgmt->sa), reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1104 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1105 | if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1106 | printk(KERN_DEBUG "%s: deauthenticated\n", dev->name); |
| 1107 | } |
| 1108 | |
| 1109 | if (ifsta->state == IEEE80211_AUTHENTICATE || |
| 1110 | ifsta->state == IEEE80211_ASSOCIATE || |
| 1111 | ifsta->state == IEEE80211_ASSOCIATED) { |
| 1112 | ifsta->state = IEEE80211_AUTHENTICATE; |
| 1113 | mod_timer(&ifsta->timer, jiffies + |
| 1114 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1115 | } |
| 1116 | |
| 1117 | ieee80211_set_disassoc(dev, ifsta, 1); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1118 | ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | static void ieee80211_rx_mgmt_disassoc(struct net_device *dev, |
| 1123 | struct ieee80211_if_sta *ifsta, |
| 1124 | struct ieee80211_mgmt *mgmt, |
| 1125 | size_t len) |
| 1126 | { |
| 1127 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1128 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1129 | |
| 1130 | if (len < 24 + 2) { |
| 1131 | printk(KERN_DEBUG "%s: too short (%zd) disassociation frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1132 | "received from %s - ignored\n", |
| 1133 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1134 | return; |
| 1135 | } |
| 1136 | |
| 1137 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 1138 | printk(KERN_DEBUG "%s: disassociation frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1139 | "unknown AP (SA=%s BSSID=%s) - " |
| 1140 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1141 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1142 | return; |
| 1143 | } |
| 1144 | |
| 1145 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 1146 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1147 | printk(KERN_DEBUG "%s: RX disassociation from %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1148 | " (reason=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1149 | dev->name, print_mac(mac, mgmt->sa), reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1150 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1151 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1152 | printk(KERN_DEBUG "%s: disassociated\n", dev->name); |
| 1153 | |
| 1154 | if (ifsta->state == IEEE80211_ASSOCIATED) { |
| 1155 | ifsta->state = IEEE80211_ASSOCIATE; |
| 1156 | mod_timer(&ifsta->timer, jiffies + |
| 1157 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1158 | } |
| 1159 | |
| 1160 | ieee80211_set_disassoc(dev, ifsta, 0); |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev, |
| 1165 | struct ieee80211_if_sta *ifsta, |
| 1166 | struct ieee80211_mgmt *mgmt, |
| 1167 | size_t len, |
| 1168 | int reassoc) |
| 1169 | { |
| 1170 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1171 | struct ieee80211_hw_mode *mode; |
| 1172 | struct sta_info *sta; |
| 1173 | u32 rates; |
| 1174 | u16 capab_info, status_code, aid; |
| 1175 | struct ieee802_11_elems elems; |
| 1176 | u8 *pos; |
| 1177 | int i, j; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1178 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1179 | |
| 1180 | /* AssocResp and ReassocResp have identical structure, so process both |
| 1181 | * of them in this function. */ |
| 1182 | |
| 1183 | if (ifsta->state != IEEE80211_ASSOCIATE) { |
| 1184 | printk(KERN_DEBUG "%s: association frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1185 | "%s, but not in associate state - ignored\n", |
| 1186 | dev->name, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1187 | return; |
| 1188 | } |
| 1189 | |
| 1190 | if (len < 24 + 6) { |
| 1191 | printk(KERN_DEBUG "%s: too short (%zd) association frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1192 | "received from %s - ignored\n", |
| 1193 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1194 | return; |
| 1195 | } |
| 1196 | |
| 1197 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 1198 | printk(KERN_DEBUG "%s: association frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1199 | "unknown AP (SA=%s BSSID=%s) - " |
| 1200 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1201 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 1206 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 1207 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1208 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1209 | printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1210 | "status=%d aid=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1211 | dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa), |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1212 | capab_info, status_code, aid & ~(BIT(15) | BIT(14))); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1213 | |
| 1214 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 1215 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", |
| 1216 | dev->name, status_code); |
Daniel Drake | 8a69aa9 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1217 | /* if this was a reassociation, ensure we try a "full" |
| 1218 | * association next time. This works around some broken APs |
| 1219 | * which do not correctly reject reassociation requests. */ |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1220 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1221 | return; |
| 1222 | } |
| 1223 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1224 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
| 1225 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " |
| 1226 | "set\n", dev->name, aid); |
| 1227 | aid &= ~(BIT(15) | BIT(14)); |
| 1228 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1229 | pos = mgmt->u.assoc_resp.variable; |
| 1230 | if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems) |
| 1231 | == ParseFailed) { |
| 1232 | printk(KERN_DEBUG "%s: failed to parse AssocResp\n", |
| 1233 | dev->name); |
| 1234 | return; |
| 1235 | } |
| 1236 | |
| 1237 | if (!elems.supp_rates) { |
| 1238 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", |
| 1239 | dev->name); |
| 1240 | return; |
| 1241 | } |
| 1242 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1243 | /* it probably doesn't, but if the frame includes an ERP value then |
| 1244 | * update our stored copy */ |
| 1245 | if (elems.erp_info && elems.erp_info_len >= 1) { |
| 1246 | struct ieee80211_sta_bss *bss |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1247 | = ieee80211_rx_bss_get(dev, ifsta->bssid, |
| 1248 | local->hw.conf.channel); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1249 | if (bss) { |
| 1250 | bss->erp_value = elems.erp_info[0]; |
| 1251 | bss->has_erp_value = 1; |
| 1252 | ieee80211_rx_bss_put(dev, bss); |
| 1253 | } |
| 1254 | } |
| 1255 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1256 | printk(KERN_DEBUG "%s: associated\n", dev->name); |
| 1257 | ifsta->aid = aid; |
| 1258 | ifsta->ap_capab = capab_info; |
| 1259 | |
| 1260 | kfree(ifsta->assocresp_ies); |
| 1261 | ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt); |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1262 | ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1263 | if (ifsta->assocresp_ies) |
| 1264 | memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); |
| 1265 | |
| 1266 | ieee80211_set_associated(dev, ifsta, 1); |
| 1267 | |
| 1268 | /* Add STA entry for the AP */ |
| 1269 | sta = sta_info_get(local, ifsta->bssid); |
| 1270 | if (!sta) { |
| 1271 | struct ieee80211_sta_bss *bss; |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1272 | sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1273 | if (!sta) { |
| 1274 | printk(KERN_DEBUG "%s: failed to add STA entry for the" |
| 1275 | " AP\n", dev->name); |
| 1276 | return; |
| 1277 | } |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1278 | bss = ieee80211_rx_bss_get(dev, ifsta->bssid, |
| 1279 | local->hw.conf.channel); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1280 | if (bss) { |
| 1281 | sta->last_rssi = bss->rssi; |
| 1282 | sta->last_signal = bss->signal; |
| 1283 | sta->last_noise = bss->noise; |
| 1284 | ieee80211_rx_bss_put(dev, bss); |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | sta->dev = dev; |
Johannes Berg | c9ee23d | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 1289 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1290 | |
| 1291 | rates = 0; |
| 1292 | mode = local->oper_hw_mode; |
| 1293 | for (i = 0; i < elems.supp_rates_len; i++) { |
| 1294 | int rate = (elems.supp_rates[i] & 0x7f) * 5; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1295 | for (j = 0; j < mode->num_rates; j++) |
| 1296 | if (mode->rates[j].rate == rate) |
| 1297 | rates |= BIT(j); |
| 1298 | } |
| 1299 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
| 1300 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1301 | for (j = 0; j < mode->num_rates; j++) |
| 1302 | if (mode->rates[j].rate == rate) |
| 1303 | rates |= BIT(j); |
| 1304 | } |
| 1305 | sta->supp_rates = rates; |
| 1306 | |
| 1307 | rate_control_rate_init(sta, local); |
| 1308 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1309 | if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1310 | sta->flags |= WLAN_STA_WME; |
| 1311 | ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param, |
| 1312 | elems.wmm_param_len); |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | sta_info_put(sta); |
| 1317 | |
| 1318 | ieee80211_associated(dev, ifsta); |
| 1319 | } |
| 1320 | |
| 1321 | |
| 1322 | /* Caller must hold local->sta_bss_lock */ |
| 1323 | static void __ieee80211_rx_bss_hash_add(struct net_device *dev, |
| 1324 | struct ieee80211_sta_bss *bss) |
| 1325 | { |
| 1326 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1327 | bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)]; |
| 1328 | local->sta_bss_hash[STA_HASH(bss->bssid)] = bss; |
| 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | /* Caller must hold local->sta_bss_lock */ |
| 1333 | static void __ieee80211_rx_bss_hash_del(struct net_device *dev, |
| 1334 | struct ieee80211_sta_bss *bss) |
| 1335 | { |
| 1336 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1337 | struct ieee80211_sta_bss *b, *prev = NULL; |
| 1338 | b = local->sta_bss_hash[STA_HASH(bss->bssid)]; |
| 1339 | while (b) { |
| 1340 | if (b == bss) { |
| 1341 | if (!prev) |
| 1342 | local->sta_bss_hash[STA_HASH(bss->bssid)] = |
| 1343 | bss->hnext; |
| 1344 | else |
| 1345 | prev->hnext = bss->hnext; |
| 1346 | break; |
| 1347 | } |
| 1348 | prev = b; |
| 1349 | b = b->hnext; |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | static struct ieee80211_sta_bss * |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1355 | ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1356 | { |
| 1357 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1358 | struct ieee80211_sta_bss *bss; |
| 1359 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1360 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1361 | if (!bss) |
| 1362 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1363 | atomic_inc(&bss->users); |
| 1364 | atomic_inc(&bss->users); |
| 1365 | memcpy(bss->bssid, bssid, ETH_ALEN); |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1366 | bss->channel = channel; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1367 | |
| 1368 | spin_lock_bh(&local->sta_bss_lock); |
| 1369 | /* TODO: order by RSSI? */ |
| 1370 | list_add_tail(&bss->list, &local->sta_bss_list); |
| 1371 | __ieee80211_rx_bss_hash_add(dev, bss); |
| 1372 | spin_unlock_bh(&local->sta_bss_lock); |
| 1373 | return bss; |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | static struct ieee80211_sta_bss * |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1378 | ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1379 | { |
| 1380 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1381 | struct ieee80211_sta_bss *bss; |
| 1382 | |
| 1383 | spin_lock_bh(&local->sta_bss_lock); |
| 1384 | bss = local->sta_bss_hash[STA_HASH(bssid)]; |
| 1385 | while (bss) { |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1386 | if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0 && |
| 1387 | bss->channel == channel) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1388 | atomic_inc(&bss->users); |
| 1389 | break; |
| 1390 | } |
| 1391 | bss = bss->hnext; |
| 1392 | } |
| 1393 | spin_unlock_bh(&local->sta_bss_lock); |
| 1394 | return bss; |
| 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) |
| 1399 | { |
| 1400 | kfree(bss->wpa_ie); |
| 1401 | kfree(bss->rsn_ie); |
| 1402 | kfree(bss->wmm_ie); |
| 1403 | kfree(bss); |
| 1404 | } |
| 1405 | |
| 1406 | |
| 1407 | static void ieee80211_rx_bss_put(struct net_device *dev, |
| 1408 | struct ieee80211_sta_bss *bss) |
| 1409 | { |
| 1410 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1411 | if (!atomic_dec_and_test(&bss->users)) |
| 1412 | return; |
| 1413 | |
| 1414 | spin_lock_bh(&local->sta_bss_lock); |
| 1415 | __ieee80211_rx_bss_hash_del(dev, bss); |
| 1416 | list_del(&bss->list); |
| 1417 | spin_unlock_bh(&local->sta_bss_lock); |
| 1418 | ieee80211_rx_bss_free(bss); |
| 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | void ieee80211_rx_bss_list_init(struct net_device *dev) |
| 1423 | { |
| 1424 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1425 | spin_lock_init(&local->sta_bss_lock); |
| 1426 | INIT_LIST_HEAD(&local->sta_bss_list); |
| 1427 | } |
| 1428 | |
| 1429 | |
| 1430 | void ieee80211_rx_bss_list_deinit(struct net_device *dev) |
| 1431 | { |
| 1432 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1433 | struct ieee80211_sta_bss *bss, *tmp; |
| 1434 | |
| 1435 | list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) |
| 1436 | ieee80211_rx_bss_put(dev, bss); |
| 1437 | } |
| 1438 | |
| 1439 | |
| 1440 | static void ieee80211_rx_bss_info(struct net_device *dev, |
| 1441 | struct ieee80211_mgmt *mgmt, |
| 1442 | size_t len, |
| 1443 | struct ieee80211_rx_status *rx_status, |
| 1444 | int beacon) |
| 1445 | { |
| 1446 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1447 | struct ieee802_11_elems elems; |
| 1448 | size_t baselen; |
| 1449 | int channel, invalid = 0, clen; |
| 1450 | struct ieee80211_sta_bss *bss; |
| 1451 | struct sta_info *sta; |
| 1452 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1453 | u64 timestamp; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1454 | DECLARE_MAC_BUF(mac); |
| 1455 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1456 | |
| 1457 | if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN)) |
| 1458 | return; /* ignore ProbeResp to foreign address */ |
| 1459 | |
| 1460 | #if 0 |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1461 | printk(KERN_DEBUG "%s: RX %s from %s to %s\n", |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1462 | dev->name, beacon ? "Beacon" : "Probe Response", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1463 | print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1464 | #endif |
| 1465 | |
| 1466 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 1467 | if (baselen > len) |
| 1468 | return; |
| 1469 | |
| 1470 | timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); |
| 1471 | |
| 1472 | if (sdata->type == IEEE80211_IF_TYPE_IBSS && beacon && |
| 1473 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { |
| 1474 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 1475 | static unsigned long last_tsf_debug = 0; |
| 1476 | u64 tsf; |
| 1477 | if (local->ops->get_tsf) |
| 1478 | tsf = local->ops->get_tsf(local_to_hw(local)); |
| 1479 | else |
| 1480 | tsf = -1LLU; |
| 1481 | if (time_after(jiffies, last_tsf_debug + 5 * HZ)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1482 | printk(KERN_DEBUG "RX beacon SA=%s BSSID=" |
| 1483 | "%s TSF=0x%llx BCN=0x%llx diff=%lld " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1484 | "@%lu\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1485 | print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1486 | (unsigned long long)tsf, |
| 1487 | (unsigned long long)timestamp, |
| 1488 | (unsigned long long)(tsf - timestamp), |
| 1489 | jiffies); |
| 1490 | last_tsf_debug = jiffies; |
| 1491 | } |
| 1492 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 1493 | } |
| 1494 | |
| 1495 | if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, |
| 1496 | &elems) == ParseFailed) |
| 1497 | invalid = 1; |
| 1498 | |
| 1499 | if (sdata->type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates && |
| 1500 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 && |
| 1501 | (sta = sta_info_get(local, mgmt->sa))) { |
| 1502 | struct ieee80211_hw_mode *mode; |
| 1503 | struct ieee80211_rate *rates; |
| 1504 | size_t num_rates; |
| 1505 | u32 supp_rates, prev_rates; |
| 1506 | int i, j; |
| 1507 | |
| 1508 | mode = local->sta_scanning ? |
| 1509 | local->scan_hw_mode : local->oper_hw_mode; |
| 1510 | rates = mode->rates; |
| 1511 | num_rates = mode->num_rates; |
| 1512 | |
| 1513 | supp_rates = 0; |
| 1514 | for (i = 0; i < elems.supp_rates_len + |
| 1515 | elems.ext_supp_rates_len; i++) { |
| 1516 | u8 rate = 0; |
| 1517 | int own_rate; |
| 1518 | if (i < elems.supp_rates_len) |
| 1519 | rate = elems.supp_rates[i]; |
| 1520 | else if (elems.ext_supp_rates) |
| 1521 | rate = elems.ext_supp_rates |
| 1522 | [i - elems.supp_rates_len]; |
| 1523 | own_rate = 5 * (rate & 0x7f); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1524 | for (j = 0; j < num_rates; j++) |
| 1525 | if (rates[j].rate == own_rate) |
| 1526 | supp_rates |= BIT(j); |
| 1527 | } |
| 1528 | |
| 1529 | prev_rates = sta->supp_rates; |
| 1530 | sta->supp_rates &= supp_rates; |
| 1531 | if (sta->supp_rates == 0) { |
| 1532 | /* No matching rates - this should not really happen. |
| 1533 | * Make sure that at least one rate is marked |
| 1534 | * supported to avoid issues with TX rate ctrl. */ |
| 1535 | sta->supp_rates = sdata->u.sta.supp_rates_bits; |
| 1536 | } |
| 1537 | if (sta->supp_rates != prev_rates) { |
| 1538 | printk(KERN_DEBUG "%s: updated supp_rates set for " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1539 | "%s based on beacon info (0x%x & 0x%x -> " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1540 | "0x%x)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1541 | dev->name, print_mac(mac, sta->addr), prev_rates, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1542 | supp_rates, sta->supp_rates); |
| 1543 | } |
| 1544 | sta_info_put(sta); |
| 1545 | } |
| 1546 | |
| 1547 | if (!elems.ssid) |
| 1548 | return; |
| 1549 | |
| 1550 | if (elems.ds_params && elems.ds_params_len == 1) |
| 1551 | channel = elems.ds_params[0]; |
| 1552 | else |
| 1553 | channel = rx_status->channel; |
| 1554 | |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1555 | bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1556 | if (!bss) { |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 1557 | bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1558 | if (!bss) |
| 1559 | return; |
| 1560 | } else { |
| 1561 | #if 0 |
| 1562 | /* TODO: order by RSSI? */ |
| 1563 | spin_lock_bh(&local->sta_bss_lock); |
| 1564 | list_move_tail(&bss->list, &local->sta_bss_list); |
| 1565 | spin_unlock_bh(&local->sta_bss_lock); |
| 1566 | #endif |
| 1567 | } |
| 1568 | |
| 1569 | if (bss->probe_resp && beacon) { |
| 1570 | /* Do not allow beacon to override data from Probe Response. */ |
| 1571 | ieee80211_rx_bss_put(dev, bss); |
| 1572 | return; |
| 1573 | } |
| 1574 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1575 | /* save the ERP value so that it is available at association time */ |
| 1576 | if (elems.erp_info && elems.erp_info_len >= 1) { |
| 1577 | bss->erp_value = elems.erp_info[0]; |
| 1578 | bss->has_erp_value = 1; |
| 1579 | } |
| 1580 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1581 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); |
| 1582 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); |
| 1583 | if (elems.ssid && elems.ssid_len <= IEEE80211_MAX_SSID_LEN) { |
| 1584 | memcpy(bss->ssid, elems.ssid, elems.ssid_len); |
| 1585 | bss->ssid_len = elems.ssid_len; |
| 1586 | } |
| 1587 | |
| 1588 | bss->supp_rates_len = 0; |
| 1589 | if (elems.supp_rates) { |
| 1590 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 1591 | if (clen > elems.supp_rates_len) |
| 1592 | clen = elems.supp_rates_len; |
| 1593 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates, |
| 1594 | clen); |
| 1595 | bss->supp_rates_len += clen; |
| 1596 | } |
| 1597 | if (elems.ext_supp_rates) { |
| 1598 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 1599 | if (clen > elems.ext_supp_rates_len) |
| 1600 | clen = elems.ext_supp_rates_len; |
| 1601 | memcpy(&bss->supp_rates[bss->supp_rates_len], |
| 1602 | elems.ext_supp_rates, clen); |
| 1603 | bss->supp_rates_len += clen; |
| 1604 | } |
| 1605 | |
| 1606 | if (elems.wpa && |
| 1607 | (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len || |
| 1608 | memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) { |
| 1609 | kfree(bss->wpa_ie); |
| 1610 | bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC); |
| 1611 | if (bss->wpa_ie) { |
| 1612 | memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2); |
| 1613 | bss->wpa_ie_len = elems.wpa_len + 2; |
| 1614 | } else |
| 1615 | bss->wpa_ie_len = 0; |
| 1616 | } else if (!elems.wpa && bss->wpa_ie) { |
| 1617 | kfree(bss->wpa_ie); |
| 1618 | bss->wpa_ie = NULL; |
| 1619 | bss->wpa_ie_len = 0; |
| 1620 | } |
| 1621 | |
| 1622 | if (elems.rsn && |
| 1623 | (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len || |
| 1624 | memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) { |
| 1625 | kfree(bss->rsn_ie); |
| 1626 | bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC); |
| 1627 | if (bss->rsn_ie) { |
| 1628 | memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2); |
| 1629 | bss->rsn_ie_len = elems.rsn_len + 2; |
| 1630 | } else |
| 1631 | bss->rsn_ie_len = 0; |
| 1632 | } else if (!elems.rsn && bss->rsn_ie) { |
| 1633 | kfree(bss->rsn_ie); |
| 1634 | bss->rsn_ie = NULL; |
| 1635 | bss->rsn_ie_len = 0; |
| 1636 | } |
| 1637 | |
| 1638 | if (elems.wmm_param && |
| 1639 | (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len || |
| 1640 | memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) { |
| 1641 | kfree(bss->wmm_ie); |
| 1642 | bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC); |
| 1643 | if (bss->wmm_ie) { |
| 1644 | memcpy(bss->wmm_ie, elems.wmm_param - 2, |
| 1645 | elems.wmm_param_len + 2); |
| 1646 | bss->wmm_ie_len = elems.wmm_param_len + 2; |
| 1647 | } else |
| 1648 | bss->wmm_ie_len = 0; |
| 1649 | } else if (!elems.wmm_param && bss->wmm_ie) { |
| 1650 | kfree(bss->wmm_ie); |
| 1651 | bss->wmm_ie = NULL; |
| 1652 | bss->wmm_ie_len = 0; |
| 1653 | } |
| 1654 | |
| 1655 | |
| 1656 | bss->hw_mode = rx_status->phymode; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1657 | bss->freq = rx_status->freq; |
| 1658 | if (channel != rx_status->channel && |
| 1659 | (bss->hw_mode == MODE_IEEE80211G || |
| 1660 | bss->hw_mode == MODE_IEEE80211B) && |
| 1661 | channel >= 1 && channel <= 14) { |
| 1662 | static const int freq_list[] = { |
| 1663 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, |
| 1664 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 |
| 1665 | }; |
| 1666 | /* IEEE 802.11g/b mode can receive packets from neighboring |
| 1667 | * channels, so map the channel into frequency. */ |
| 1668 | bss->freq = freq_list[channel - 1]; |
| 1669 | } |
| 1670 | bss->timestamp = timestamp; |
| 1671 | bss->last_update = jiffies; |
| 1672 | bss->rssi = rx_status->ssi; |
| 1673 | bss->signal = rx_status->signal; |
| 1674 | bss->noise = rx_status->noise; |
| 1675 | if (!beacon) |
| 1676 | bss->probe_resp++; |
| 1677 | ieee80211_rx_bss_put(dev, bss); |
| 1678 | } |
| 1679 | |
| 1680 | |
| 1681 | static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev, |
| 1682 | struct ieee80211_mgmt *mgmt, |
| 1683 | size_t len, |
| 1684 | struct ieee80211_rx_status *rx_status) |
| 1685 | { |
| 1686 | ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0); |
| 1687 | } |
| 1688 | |
| 1689 | |
| 1690 | static void ieee80211_rx_mgmt_beacon(struct net_device *dev, |
| 1691 | struct ieee80211_mgmt *mgmt, |
| 1692 | size_t len, |
| 1693 | struct ieee80211_rx_status *rx_status) |
| 1694 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1695 | struct ieee80211_sub_if_data *sdata; |
| 1696 | struct ieee80211_if_sta *ifsta; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1697 | size_t baselen; |
| 1698 | struct ieee802_11_elems elems; |
| 1699 | |
| 1700 | ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1); |
| 1701 | |
| 1702 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1703 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 1704 | return; |
| 1705 | ifsta = &sdata->u.sta; |
| 1706 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1707 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1708 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
| 1709 | return; |
| 1710 | |
| 1711 | /* Process beacon from the current BSS */ |
| 1712 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 1713 | if (baselen > len) |
| 1714 | return; |
| 1715 | |
| 1716 | if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, |
| 1717 | &elems) == ParseFailed) |
| 1718 | return; |
| 1719 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1720 | if (elems.erp_info && elems.erp_info_len >= 1) |
| 1721 | ieee80211_handle_erp_ie(dev, elems.erp_info[0]); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1722 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1723 | if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1724 | ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param, |
| 1725 | elems.wmm_param_len); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | |
| 1730 | static void ieee80211_rx_mgmt_probe_req(struct net_device *dev, |
| 1731 | struct ieee80211_if_sta *ifsta, |
| 1732 | struct ieee80211_mgmt *mgmt, |
| 1733 | size_t len, |
| 1734 | struct ieee80211_rx_status *rx_status) |
| 1735 | { |
| 1736 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1737 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1738 | int tx_last_beacon; |
| 1739 | struct sk_buff *skb; |
| 1740 | struct ieee80211_mgmt *resp; |
| 1741 | u8 *pos, *end; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1742 | DECLARE_MAC_BUF(mac); |
| 1743 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 1744 | DECLARE_MAC_BUF(mac2); |
| 1745 | DECLARE_MAC_BUF(mac3); |
| 1746 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1747 | |
| 1748 | if (sdata->type != IEEE80211_IF_TYPE_IBSS || |
| 1749 | ifsta->state != IEEE80211_IBSS_JOINED || |
| 1750 | len < 24 + 2 || !ifsta->probe_resp) |
| 1751 | return; |
| 1752 | |
| 1753 | if (local->ops->tx_last_beacon) |
| 1754 | tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local)); |
| 1755 | else |
| 1756 | tx_last_beacon = 1; |
| 1757 | |
| 1758 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1759 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID=" |
| 1760 | "%s (tx_last_beacon=%d)\n", |
| 1761 | dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da), |
| 1762 | print_mac(mac3, mgmt->bssid), tx_last_beacon); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1763 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 1764 | |
| 1765 | if (!tx_last_beacon) |
| 1766 | return; |
| 1767 | |
| 1768 | if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 && |
| 1769 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
| 1770 | return; |
| 1771 | |
| 1772 | end = ((u8 *) mgmt) + len; |
| 1773 | pos = mgmt->u.probe_req.variable; |
| 1774 | if (pos[0] != WLAN_EID_SSID || |
| 1775 | pos + 2 + pos[1] > end) { |
| 1776 | if (net_ratelimit()) { |
| 1777 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1778 | "from %s\n", |
| 1779 | dev->name, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1780 | } |
| 1781 | return; |
| 1782 | } |
| 1783 | if (pos[1] != 0 && |
| 1784 | (pos[1] != ifsta->ssid_len || |
| 1785 | memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) { |
| 1786 | /* Ignore ProbeReq for foreign SSID */ |
| 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | /* Reply with ProbeResp */ |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1791 | skb = skb_copy(ifsta->probe_resp, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1792 | if (!skb) |
| 1793 | return; |
| 1794 | |
| 1795 | resp = (struct ieee80211_mgmt *) skb->data; |
| 1796 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
| 1797 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1798 | printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n", |
| 1799 | dev->name, print_mac(mac, resp->da)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1800 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 1801 | ieee80211_sta_tx(dev, skb, 0); |
| 1802 | } |
| 1803 | |
| 1804 | |
| 1805 | void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb, |
| 1806 | struct ieee80211_rx_status *rx_status) |
| 1807 | { |
| 1808 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1809 | struct ieee80211_sub_if_data *sdata; |
| 1810 | struct ieee80211_if_sta *ifsta; |
| 1811 | struct ieee80211_mgmt *mgmt; |
| 1812 | u16 fc; |
| 1813 | |
| 1814 | if (skb->len < 24) |
| 1815 | goto fail; |
| 1816 | |
| 1817 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1818 | ifsta = &sdata->u.sta; |
| 1819 | |
| 1820 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1821 | fc = le16_to_cpu(mgmt->frame_control); |
| 1822 | |
| 1823 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1824 | case IEEE80211_STYPE_PROBE_REQ: |
| 1825 | case IEEE80211_STYPE_PROBE_RESP: |
| 1826 | case IEEE80211_STYPE_BEACON: |
| 1827 | memcpy(skb->cb, rx_status, sizeof(*rx_status)); |
| 1828 | case IEEE80211_STYPE_AUTH: |
| 1829 | case IEEE80211_STYPE_ASSOC_RESP: |
| 1830 | case IEEE80211_STYPE_REASSOC_RESP: |
| 1831 | case IEEE80211_STYPE_DEAUTH: |
| 1832 | case IEEE80211_STYPE_DISASSOC: |
| 1833 | skb_queue_tail(&ifsta->skb_queue, skb); |
| 1834 | queue_work(local->hw.workqueue, &ifsta->work); |
| 1835 | return; |
| 1836 | default: |
| 1837 | printk(KERN_DEBUG "%s: received unknown management frame - " |
| 1838 | "stype=%d\n", dev->name, |
| 1839 | (fc & IEEE80211_FCTL_STYPE) >> 4); |
| 1840 | break; |
| 1841 | } |
| 1842 | |
| 1843 | fail: |
| 1844 | kfree_skb(skb); |
| 1845 | } |
| 1846 | |
| 1847 | |
| 1848 | static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev, |
| 1849 | struct sk_buff *skb) |
| 1850 | { |
| 1851 | struct ieee80211_rx_status *rx_status; |
| 1852 | struct ieee80211_sub_if_data *sdata; |
| 1853 | struct ieee80211_if_sta *ifsta; |
| 1854 | struct ieee80211_mgmt *mgmt; |
| 1855 | u16 fc; |
| 1856 | |
| 1857 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1858 | ifsta = &sdata->u.sta; |
| 1859 | |
| 1860 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 1861 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1862 | fc = le16_to_cpu(mgmt->frame_control); |
| 1863 | |
| 1864 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1865 | case IEEE80211_STYPE_PROBE_REQ: |
| 1866 | ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len, |
| 1867 | rx_status); |
| 1868 | break; |
| 1869 | case IEEE80211_STYPE_PROBE_RESP: |
| 1870 | ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status); |
| 1871 | break; |
| 1872 | case IEEE80211_STYPE_BEACON: |
| 1873 | ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status); |
| 1874 | break; |
| 1875 | case IEEE80211_STYPE_AUTH: |
| 1876 | ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len); |
| 1877 | break; |
| 1878 | case IEEE80211_STYPE_ASSOC_RESP: |
| 1879 | ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 0); |
| 1880 | break; |
| 1881 | case IEEE80211_STYPE_REASSOC_RESP: |
| 1882 | ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 1); |
| 1883 | break; |
| 1884 | case IEEE80211_STYPE_DEAUTH: |
| 1885 | ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len); |
| 1886 | break; |
| 1887 | case IEEE80211_STYPE_DISASSOC: |
| 1888 | ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len); |
| 1889 | break; |
| 1890 | } |
| 1891 | |
| 1892 | kfree_skb(skb); |
| 1893 | } |
| 1894 | |
| 1895 | |
| 1896 | void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb, |
| 1897 | struct ieee80211_rx_status *rx_status) |
| 1898 | { |
| 1899 | struct ieee80211_mgmt *mgmt; |
| 1900 | u16 fc; |
| 1901 | |
| 1902 | if (skb->len < 24) { |
| 1903 | dev_kfree_skb(skb); |
| 1904 | return; |
| 1905 | } |
| 1906 | |
| 1907 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1908 | fc = le16_to_cpu(mgmt->frame_control); |
| 1909 | |
| 1910 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 1911 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) { |
| 1912 | ieee80211_rx_mgmt_probe_resp(dev, mgmt, |
| 1913 | skb->len, rx_status); |
| 1914 | } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) { |
| 1915 | ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, |
| 1916 | rx_status); |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | dev_kfree_skb(skb); |
| 1921 | } |
| 1922 | |
| 1923 | |
| 1924 | static int ieee80211_sta_active_ibss(struct net_device *dev) |
| 1925 | { |
| 1926 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1927 | int active = 0; |
| 1928 | struct sta_info *sta; |
| 1929 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1930 | read_lock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1931 | list_for_each_entry(sta, &local->sta_list, list) { |
| 1932 | if (sta->dev == dev && |
| 1933 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
| 1934 | jiffies)) { |
| 1935 | active++; |
| 1936 | break; |
| 1937 | } |
| 1938 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1939 | read_unlock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1940 | |
| 1941 | return active; |
| 1942 | } |
| 1943 | |
| 1944 | |
| 1945 | static void ieee80211_sta_expire(struct net_device *dev) |
| 1946 | { |
| 1947 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1948 | struct sta_info *sta, *tmp; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1949 | LIST_HEAD(tmp_list); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1950 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1951 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1952 | write_lock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1953 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
| 1954 | if (time_after(jiffies, sta->last_rx + |
| 1955 | IEEE80211_IBSS_INACTIVITY_LIMIT)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1956 | printk(KERN_DEBUG "%s: expiring inactive STA %s\n", |
| 1957 | dev->name, print_mac(mac, sta->addr)); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1958 | __sta_info_get(sta); |
| 1959 | sta_info_remove(sta); |
| 1960 | list_add(&sta->list, &tmp_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1961 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1962 | write_unlock_bh(&local->sta_lock); |
| 1963 | |
| 1964 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) { |
| 1965 | sta_info_free(sta); |
| 1966 | sta_info_put(sta); |
| 1967 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | |
| 1971 | static void ieee80211_sta_merge_ibss(struct net_device *dev, |
| 1972 | struct ieee80211_if_sta *ifsta) |
| 1973 | { |
| 1974 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 1975 | |
| 1976 | ieee80211_sta_expire(dev); |
| 1977 | if (ieee80211_sta_active_ibss(dev)) |
| 1978 | return; |
| 1979 | |
| 1980 | printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " |
| 1981 | "IBSS networks with same SSID (merge)\n", dev->name); |
| 1982 | ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len); |
| 1983 | } |
| 1984 | |
| 1985 | |
| 1986 | void ieee80211_sta_timer(unsigned long data) |
| 1987 | { |
| 1988 | struct ieee80211_sub_if_data *sdata = |
| 1989 | (struct ieee80211_sub_if_data *) data; |
| 1990 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 1991 | struct ieee80211_local *local = wdev_priv(&sdata->wdev); |
| 1992 | |
| 1993 | set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 1994 | queue_work(local->hw.workqueue, &ifsta->work); |
| 1995 | } |
| 1996 | |
| 1997 | |
| 1998 | void ieee80211_sta_work(struct work_struct *work) |
| 1999 | { |
| 2000 | struct ieee80211_sub_if_data *sdata = |
| 2001 | container_of(work, struct ieee80211_sub_if_data, u.sta.work); |
| 2002 | struct net_device *dev = sdata->dev; |
| 2003 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2004 | struct ieee80211_if_sta *ifsta; |
| 2005 | struct sk_buff *skb; |
| 2006 | |
| 2007 | if (!netif_running(dev)) |
| 2008 | return; |
| 2009 | |
| 2010 | if (local->sta_scanning) |
| 2011 | return; |
| 2012 | |
| 2013 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 2014 | sdata->type != IEEE80211_IF_TYPE_IBSS) { |
| 2015 | printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface " |
| 2016 | "(type=%d)\n", dev->name, sdata->type); |
| 2017 | return; |
| 2018 | } |
| 2019 | ifsta = &sdata->u.sta; |
| 2020 | |
| 2021 | while ((skb = skb_dequeue(&ifsta->skb_queue))) |
| 2022 | ieee80211_sta_rx_queued_mgmt(dev, skb); |
| 2023 | |
| 2024 | if (ifsta->state != IEEE80211_AUTHENTICATE && |
| 2025 | ifsta->state != IEEE80211_ASSOCIATE && |
| 2026 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { |
| 2027 | ieee80211_sta_start_scan(dev, NULL, 0); |
| 2028 | return; |
| 2029 | } |
| 2030 | |
| 2031 | if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) { |
| 2032 | if (ieee80211_sta_config_auth(dev, ifsta)) |
| 2033 | return; |
| 2034 | clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 2035 | } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request)) |
| 2036 | return; |
| 2037 | |
| 2038 | switch (ifsta->state) { |
| 2039 | case IEEE80211_DISABLED: |
| 2040 | break; |
| 2041 | case IEEE80211_AUTHENTICATE: |
| 2042 | ieee80211_authenticate(dev, ifsta); |
| 2043 | break; |
| 2044 | case IEEE80211_ASSOCIATE: |
| 2045 | ieee80211_associate(dev, ifsta); |
| 2046 | break; |
| 2047 | case IEEE80211_ASSOCIATED: |
| 2048 | ieee80211_associated(dev, ifsta); |
| 2049 | break; |
| 2050 | case IEEE80211_IBSS_SEARCH: |
| 2051 | ieee80211_sta_find_ibss(dev, ifsta); |
| 2052 | break; |
| 2053 | case IEEE80211_IBSS_JOINED: |
| 2054 | ieee80211_sta_merge_ibss(dev, ifsta); |
| 2055 | break; |
| 2056 | default: |
| 2057 | printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n", |
| 2058 | ifsta->state); |
| 2059 | break; |
| 2060 | } |
| 2061 | |
| 2062 | if (ieee80211_privacy_mismatch(dev, ifsta)) { |
| 2063 | printk(KERN_DEBUG "%s: privacy configuration mismatch and " |
| 2064 | "mixed-cell disabled - disassociate\n", dev->name); |
| 2065 | |
| 2066 | ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED); |
| 2067 | ieee80211_set_disassoc(dev, ifsta, 0); |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | |
| 2072 | static void ieee80211_sta_reset_auth(struct net_device *dev, |
| 2073 | struct ieee80211_if_sta *ifsta) |
| 2074 | { |
| 2075 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2076 | |
| 2077 | if (local->ops->reset_tsf) { |
| 2078 | /* Reset own TSF to allow time synchronization work. */ |
| 2079 | local->ops->reset_tsf(local_to_hw(local)); |
| 2080 | } |
| 2081 | |
| 2082 | ifsta->wmm_last_param_set = -1; /* allow any WMM update */ |
| 2083 | |
| 2084 | |
| 2085 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 2086 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
| 2087 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 2088 | ifsta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 2089 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 2090 | ifsta->auth_alg = WLAN_AUTH_LEAP; |
| 2091 | else |
| 2092 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
| 2093 | printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name, |
| 2094 | ifsta->auth_alg); |
| 2095 | ifsta->auth_transaction = -1; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2096 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
| 2097 | ifsta->auth_tries = ifsta->assoc_tries = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2098 | netif_carrier_off(dev); |
| 2099 | } |
| 2100 | |
| 2101 | |
| 2102 | void ieee80211_sta_req_auth(struct net_device *dev, |
| 2103 | struct ieee80211_if_sta *ifsta) |
| 2104 | { |
| 2105 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2106 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2107 | |
| 2108 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 2109 | return; |
| 2110 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2111 | if ((ifsta->flags & (IEEE80211_STA_BSSID_SET | |
| 2112 | IEEE80211_STA_AUTO_BSSID_SEL)) && |
| 2113 | (ifsta->flags & (IEEE80211_STA_SSID_SET | |
| 2114 | IEEE80211_STA_AUTO_SSID_SEL))) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2115 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 2116 | queue_work(local->hw.workqueue, &ifsta->work); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, |
| 2121 | const char *ssid, int ssid_len) |
| 2122 | { |
| 2123 | int tmp, hidden_ssid; |
| 2124 | |
| 2125 | if (!memcmp(ifsta->ssid, ssid, ssid_len)) |
| 2126 | return 1; |
| 2127 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2128 | if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2129 | return 0; |
| 2130 | |
| 2131 | hidden_ssid = 1; |
| 2132 | tmp = ssid_len; |
| 2133 | while (tmp--) { |
| 2134 | if (ssid[tmp] != '\0') { |
| 2135 | hidden_ssid = 0; |
| 2136 | break; |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | if (hidden_ssid && ifsta->ssid_len == ssid_len) |
| 2141 | return 1; |
| 2142 | |
| 2143 | if (ssid_len == 1 && ssid[0] == ' ') |
| 2144 | return 1; |
| 2145 | |
| 2146 | return 0; |
| 2147 | } |
| 2148 | |
| 2149 | static int ieee80211_sta_config_auth(struct net_device *dev, |
| 2150 | struct ieee80211_if_sta *ifsta) |
| 2151 | { |
| 2152 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2153 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2154 | struct ieee80211_sta_bss *bss, *selected = NULL; |
| 2155 | int top_rssi = 0, freq; |
| 2156 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2157 | if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL | |
| 2158 | IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2159 | ifsta->state = IEEE80211_AUTHENTICATE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2160 | ieee80211_sta_reset_auth(dev, ifsta); |
| 2161 | return 0; |
| 2162 | } |
| 2163 | |
| 2164 | spin_lock_bh(&local->sta_bss_lock); |
| 2165 | freq = local->oper_channel->freq; |
| 2166 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 2167 | if (!(bss->capability & WLAN_CAPABILITY_ESS)) |
| 2168 | continue; |
| 2169 | |
| 2170 | if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^ |
| 2171 | !!sdata->default_key) |
| 2172 | continue; |
| 2173 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2174 | if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) && |
| 2175 | bss->freq != freq) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2176 | continue; |
| 2177 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2178 | if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2179 | memcmp(bss->bssid, ifsta->bssid, ETH_ALEN)) |
| 2180 | continue; |
| 2181 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2182 | if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2183 | !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len)) |
| 2184 | continue; |
| 2185 | |
| 2186 | if (!selected || top_rssi < bss->rssi) { |
| 2187 | selected = bss; |
| 2188 | top_rssi = bss->rssi; |
| 2189 | } |
| 2190 | } |
| 2191 | if (selected) |
| 2192 | atomic_inc(&selected->users); |
| 2193 | spin_unlock_bh(&local->sta_bss_lock); |
| 2194 | |
| 2195 | if (selected) { |
| 2196 | ieee80211_set_channel(local, -1, selected->freq); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2197 | if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2198 | ieee80211_sta_set_ssid(dev, selected->ssid, |
| 2199 | selected->ssid_len); |
| 2200 | ieee80211_sta_set_bssid(dev, selected->bssid); |
| 2201 | ieee80211_rx_bss_put(dev, selected); |
| 2202 | ifsta->state = IEEE80211_AUTHENTICATE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2203 | ieee80211_sta_reset_auth(dev, ifsta); |
| 2204 | return 0; |
| 2205 | } else { |
| 2206 | if (ifsta->state != IEEE80211_AUTHENTICATE) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2207 | if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) |
John W. Linville | b9bf1e6 | 2007-08-07 16:33:15 -0400 | [diff] [blame] | 2208 | ieee80211_sta_start_scan(dev, NULL, 0); |
| 2209 | else |
| 2210 | ieee80211_sta_start_scan(dev, ifsta->ssid, |
| 2211 | ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2212 | ifsta->state = IEEE80211_AUTHENTICATE; |
| 2213 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 2214 | } else |
| 2215 | ifsta->state = IEEE80211_DISABLED; |
| 2216 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2217 | return -1; |
| 2218 | } |
| 2219 | |
| 2220 | static int ieee80211_sta_join_ibss(struct net_device *dev, |
| 2221 | struct ieee80211_if_sta *ifsta, |
| 2222 | struct ieee80211_sta_bss *bss) |
| 2223 | { |
| 2224 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2225 | int res, rates, i, j; |
| 2226 | struct sk_buff *skb; |
| 2227 | struct ieee80211_mgmt *mgmt; |
| 2228 | struct ieee80211_tx_control control; |
| 2229 | struct ieee80211_rate *rate; |
| 2230 | struct ieee80211_hw_mode *mode; |
| 2231 | struct rate_control_extra extra; |
| 2232 | u8 *pos; |
| 2233 | struct ieee80211_sub_if_data *sdata; |
| 2234 | |
| 2235 | /* Remove possible STA entries from other IBSS networks. */ |
| 2236 | sta_info_flush(local, NULL); |
| 2237 | |
| 2238 | if (local->ops->reset_tsf) { |
| 2239 | /* Reset own TSF to allow time synchronization work. */ |
| 2240 | local->ops->reset_tsf(local_to_hw(local)); |
| 2241 | } |
| 2242 | memcpy(ifsta->bssid, bss->bssid, ETH_ALEN); |
| 2243 | res = ieee80211_if_config(dev); |
| 2244 | if (res) |
| 2245 | return res; |
| 2246 | |
| 2247 | local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10; |
| 2248 | |
| 2249 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2250 | sdata->drop_unencrypted = bss->capability & |
| 2251 | WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
| 2252 | |
| 2253 | res = ieee80211_set_channel(local, -1, bss->freq); |
| 2254 | |
| 2255 | if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) { |
| 2256 | printk(KERN_DEBUG "%s: IBSS not allowed on channel %d " |
| 2257 | "(%d MHz)\n", dev->name, local->hw.conf.channel, |
| 2258 | local->hw.conf.freq); |
| 2259 | return -1; |
| 2260 | } |
| 2261 | |
| 2262 | /* Set beacon template based on scan results */ |
| 2263 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
| 2264 | do { |
| 2265 | if (!skb) |
| 2266 | break; |
| 2267 | |
| 2268 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 2269 | |
| 2270 | mgmt = (struct ieee80211_mgmt *) |
| 2271 | skb_put(skb, 24 + sizeof(mgmt->u.beacon)); |
| 2272 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); |
| 2273 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 2274 | IEEE80211_STYPE_BEACON); |
| 2275 | memset(mgmt->da, 0xff, ETH_ALEN); |
| 2276 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 2277 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 2278 | mgmt->u.beacon.beacon_int = |
| 2279 | cpu_to_le16(local->hw.conf.beacon_int); |
| 2280 | mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability); |
| 2281 | |
| 2282 | pos = skb_put(skb, 2 + ifsta->ssid_len); |
| 2283 | *pos++ = WLAN_EID_SSID; |
| 2284 | *pos++ = ifsta->ssid_len; |
| 2285 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); |
| 2286 | |
| 2287 | rates = bss->supp_rates_len; |
| 2288 | if (rates > 8) |
| 2289 | rates = 8; |
| 2290 | pos = skb_put(skb, 2 + rates); |
| 2291 | *pos++ = WLAN_EID_SUPP_RATES; |
| 2292 | *pos++ = rates; |
| 2293 | memcpy(pos, bss->supp_rates, rates); |
| 2294 | |
| 2295 | pos = skb_put(skb, 2 + 1); |
| 2296 | *pos++ = WLAN_EID_DS_PARAMS; |
| 2297 | *pos++ = 1; |
| 2298 | *pos++ = bss->channel; |
| 2299 | |
| 2300 | pos = skb_put(skb, 2 + 2); |
| 2301 | *pos++ = WLAN_EID_IBSS_PARAMS; |
| 2302 | *pos++ = 2; |
| 2303 | /* FIX: set ATIM window based on scan results */ |
| 2304 | *pos++ = 0; |
| 2305 | *pos++ = 0; |
| 2306 | |
| 2307 | if (bss->supp_rates_len > 8) { |
| 2308 | rates = bss->supp_rates_len - 8; |
| 2309 | pos = skb_put(skb, 2 + rates); |
| 2310 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 2311 | *pos++ = rates; |
| 2312 | memcpy(pos, &bss->supp_rates[8], rates); |
| 2313 | } |
| 2314 | |
| 2315 | memset(&control, 0, sizeof(control)); |
| 2316 | memset(&extra, 0, sizeof(extra)); |
| 2317 | extra.mode = local->oper_hw_mode; |
| 2318 | rate = rate_control_get_rate(local, dev, skb, &extra); |
| 2319 | if (!rate) { |
| 2320 | printk(KERN_DEBUG "%s: Failed to determine TX rate " |
| 2321 | "for IBSS beacon\n", dev->name); |
| 2322 | break; |
| 2323 | } |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2324 | control.tx_rate = |
| 2325 | ((sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE) && |
| 2326 | (rate->flags & IEEE80211_RATE_PREAMBLE2)) ? |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2327 | rate->val2 : rate->val; |
| 2328 | control.antenna_sel_tx = local->hw.conf.antenna_sel_tx; |
| 2329 | control.power_level = local->hw.conf.power_level; |
| 2330 | control.flags |= IEEE80211_TXCTL_NO_ACK; |
| 2331 | control.retry_limit = 1; |
| 2332 | |
| 2333 | ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC); |
| 2334 | if (ifsta->probe_resp) { |
| 2335 | mgmt = (struct ieee80211_mgmt *) |
| 2336 | ifsta->probe_resp->data; |
| 2337 | mgmt->frame_control = |
| 2338 | IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 2339 | IEEE80211_STYPE_PROBE_RESP); |
| 2340 | } else { |
| 2341 | printk(KERN_DEBUG "%s: Could not allocate ProbeResp " |
| 2342 | "template for IBSS\n", dev->name); |
| 2343 | } |
| 2344 | |
| 2345 | if (local->ops->beacon_update && |
| 2346 | local->ops->beacon_update(local_to_hw(local), |
| 2347 | skb, &control) == 0) { |
| 2348 | printk(KERN_DEBUG "%s: Configured IBSS beacon " |
| 2349 | "template based on scan results\n", dev->name); |
| 2350 | skb = NULL; |
| 2351 | } |
| 2352 | |
| 2353 | rates = 0; |
| 2354 | mode = local->oper_hw_mode; |
| 2355 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 2356 | int bitrate = (bss->supp_rates[i] & 0x7f) * 5; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2357 | for (j = 0; j < mode->num_rates; j++) |
| 2358 | if (mode->rates[j].rate == bitrate) |
| 2359 | rates |= BIT(j); |
| 2360 | } |
| 2361 | ifsta->supp_rates_bits = rates; |
| 2362 | } while (0); |
| 2363 | |
| 2364 | if (skb) { |
| 2365 | printk(KERN_DEBUG "%s: Failed to configure IBSS beacon " |
| 2366 | "template\n", dev->name); |
| 2367 | dev_kfree_skb(skb); |
| 2368 | } |
| 2369 | |
| 2370 | ifsta->state = IEEE80211_IBSS_JOINED; |
| 2371 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 2372 | |
| 2373 | ieee80211_rx_bss_put(dev, bss); |
| 2374 | |
| 2375 | return res; |
| 2376 | } |
| 2377 | |
| 2378 | |
| 2379 | static int ieee80211_sta_create_ibss(struct net_device *dev, |
| 2380 | struct ieee80211_if_sta *ifsta) |
| 2381 | { |
| 2382 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2383 | struct ieee80211_sta_bss *bss; |
| 2384 | struct ieee80211_sub_if_data *sdata; |
| 2385 | struct ieee80211_hw_mode *mode; |
| 2386 | u8 bssid[ETH_ALEN], *pos; |
| 2387 | int i; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2388 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2389 | |
| 2390 | #if 0 |
| 2391 | /* Easier testing, use fixed BSSID. */ |
| 2392 | memset(bssid, 0xfe, ETH_ALEN); |
| 2393 | #else |
| 2394 | /* Generate random, not broadcast, locally administered BSSID. Mix in |
| 2395 | * own MAC address to make sure that devices that do not have proper |
| 2396 | * random number generator get different BSSID. */ |
| 2397 | get_random_bytes(bssid, ETH_ALEN); |
| 2398 | for (i = 0; i < ETH_ALEN; i++) |
| 2399 | bssid[i] ^= dev->dev_addr[i]; |
| 2400 | bssid[0] &= ~0x01; |
| 2401 | bssid[0] |= 0x02; |
| 2402 | #endif |
| 2403 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2404 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", |
| 2405 | dev->name, print_mac(mac, bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2406 | |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 2407 | bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2408 | if (!bss) |
| 2409 | return -ENOMEM; |
| 2410 | |
| 2411 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2412 | mode = local->oper_hw_mode; |
| 2413 | |
| 2414 | if (local->hw.conf.beacon_int == 0) |
| 2415 | local->hw.conf.beacon_int = 100; |
| 2416 | bss->beacon_int = local->hw.conf.beacon_int; |
| 2417 | bss->hw_mode = local->hw.conf.phymode; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2418 | bss->freq = local->hw.conf.freq; |
| 2419 | bss->last_update = jiffies; |
| 2420 | bss->capability = WLAN_CAPABILITY_IBSS; |
| 2421 | if (sdata->default_key) { |
| 2422 | bss->capability |= WLAN_CAPABILITY_PRIVACY; |
| 2423 | } else |
| 2424 | sdata->drop_unencrypted = 0; |
| 2425 | bss->supp_rates_len = mode->num_rates; |
| 2426 | pos = bss->supp_rates; |
| 2427 | for (i = 0; i < mode->num_rates; i++) { |
| 2428 | int rate = mode->rates[i].rate; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2429 | *pos++ = (u8) (rate / 5); |
| 2430 | } |
| 2431 | |
| 2432 | return ieee80211_sta_join_ibss(dev, ifsta, bss); |
| 2433 | } |
| 2434 | |
| 2435 | |
| 2436 | static int ieee80211_sta_find_ibss(struct net_device *dev, |
| 2437 | struct ieee80211_if_sta *ifsta) |
| 2438 | { |
| 2439 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2440 | struct ieee80211_sta_bss *bss; |
| 2441 | int found = 0; |
| 2442 | u8 bssid[ETH_ALEN]; |
| 2443 | int active_ibss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2444 | DECLARE_MAC_BUF(mac); |
| 2445 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2446 | |
| 2447 | if (ifsta->ssid_len == 0) |
| 2448 | return -EINVAL; |
| 2449 | |
| 2450 | active_ibss = ieee80211_sta_active_ibss(dev); |
| 2451 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2452 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", |
| 2453 | dev->name, active_ibss); |
| 2454 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2455 | spin_lock_bh(&local->sta_bss_lock); |
| 2456 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 2457 | if (ifsta->ssid_len != bss->ssid_len || |
| 2458 | memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 |
| 2459 | || !(bss->capability & WLAN_CAPABILITY_IBSS)) |
| 2460 | continue; |
| 2461 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2462 | printk(KERN_DEBUG " bssid=%s found\n", |
| 2463 | print_mac(mac, bss->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2464 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2465 | memcpy(bssid, bss->bssid, ETH_ALEN); |
| 2466 | found = 1; |
| 2467 | if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) |
| 2468 | break; |
| 2469 | } |
| 2470 | spin_unlock_bh(&local->sta_bss_lock); |
| 2471 | |
| 2472 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2473 | printk(KERN_DEBUG " sta_find_ibss: selected %s current " |
| 2474 | "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2475 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2476 | if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 && |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame^] | 2477 | (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel))) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2478 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2479 | " based on configured SSID\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2480 | dev->name, print_mac(mac, bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2481 | return ieee80211_sta_join_ibss(dev, ifsta, bss); |
| 2482 | } |
| 2483 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2484 | printk(KERN_DEBUG " did not try to join ibss\n"); |
| 2485 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2486 | |
| 2487 | /* Selected IBSS not found in current scan results - try to scan */ |
| 2488 | if (ifsta->state == IEEE80211_IBSS_JOINED && |
| 2489 | !ieee80211_sta_active_ibss(dev)) { |
| 2490 | mod_timer(&ifsta->timer, jiffies + |
| 2491 | IEEE80211_IBSS_MERGE_INTERVAL); |
| 2492 | } else if (time_after(jiffies, local->last_scan_completed + |
| 2493 | IEEE80211_SCAN_INTERVAL)) { |
| 2494 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " |
| 2495 | "join\n", dev->name); |
| 2496 | return ieee80211_sta_req_scan(dev, ifsta->ssid, |
| 2497 | ifsta->ssid_len); |
| 2498 | } else if (ifsta->state != IEEE80211_IBSS_JOINED) { |
| 2499 | int interval = IEEE80211_SCAN_INTERVAL; |
| 2500 | |
| 2501 | if (time_after(jiffies, ifsta->ibss_join_req + |
| 2502 | IEEE80211_IBSS_JOIN_TIMEOUT)) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2503 | if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2504 | local->oper_channel->flag & IEEE80211_CHAN_W_IBSS) |
| 2505 | return ieee80211_sta_create_ibss(dev, ifsta); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2506 | if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2507 | printk(KERN_DEBUG "%s: IBSS not allowed on the" |
| 2508 | " configured channel %d (%d MHz)\n", |
| 2509 | dev->name, local->hw.conf.channel, |
| 2510 | local->hw.conf.freq); |
| 2511 | } |
| 2512 | |
| 2513 | /* No IBSS found - decrease scan interval and continue |
| 2514 | * scanning. */ |
| 2515 | interval = IEEE80211_SCAN_INTERVAL_SLOW; |
| 2516 | } |
| 2517 | |
| 2518 | ifsta->state = IEEE80211_IBSS_SEARCH; |
| 2519 | mod_timer(&ifsta->timer, jiffies + interval); |
| 2520 | return 0; |
| 2521 | } |
| 2522 | |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
| 2526 | |
| 2527 | int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len) |
| 2528 | { |
| 2529 | struct ieee80211_sub_if_data *sdata; |
| 2530 | struct ieee80211_if_sta *ifsta; |
| 2531 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2532 | |
| 2533 | if (len > IEEE80211_MAX_SSID_LEN) |
| 2534 | return -EINVAL; |
| 2535 | |
| 2536 | /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is |
| 2537 | * not defined. */ |
| 2538 | if (local->ops->conf_tx) { |
| 2539 | struct ieee80211_tx_queue_params qparam; |
| 2540 | int i; |
| 2541 | |
| 2542 | memset(&qparam, 0, sizeof(qparam)); |
| 2543 | /* TODO: are these ok defaults for all hw_modes? */ |
| 2544 | qparam.aifs = 2; |
| 2545 | qparam.cw_min = |
| 2546 | local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15; |
| 2547 | qparam.cw_max = 1023; |
| 2548 | qparam.burst_time = 0; |
| 2549 | for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++) |
| 2550 | { |
| 2551 | local->ops->conf_tx(local_to_hw(local), |
| 2552 | i + IEEE80211_TX_QUEUE_DATA0, |
| 2553 | &qparam); |
| 2554 | } |
| 2555 | /* IBSS uses different parameters for Beacon sending */ |
| 2556 | qparam.cw_min++; |
| 2557 | qparam.cw_min *= 2; |
| 2558 | qparam.cw_min--; |
| 2559 | local->ops->conf_tx(local_to_hw(local), |
| 2560 | IEEE80211_TX_QUEUE_BEACON, &qparam); |
| 2561 | } |
| 2562 | |
| 2563 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2564 | ifsta = &sdata->u.sta; |
| 2565 | |
| 2566 | if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2567 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2568 | memcpy(ifsta->ssid, ssid, len); |
| 2569 | memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len); |
| 2570 | ifsta->ssid_len = len; |
| 2571 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2572 | if (len) |
| 2573 | ifsta->flags |= IEEE80211_STA_SSID_SET; |
| 2574 | else |
| 2575 | ifsta->flags &= ~IEEE80211_STA_SSID_SET; |
| 2576 | if (sdata->type == IEEE80211_IF_TYPE_IBSS && |
| 2577 | !(ifsta->flags & IEEE80211_STA_BSSID_SET)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2578 | ifsta->ibss_join_req = jiffies; |
| 2579 | ifsta->state = IEEE80211_IBSS_SEARCH; |
| 2580 | return ieee80211_sta_find_ibss(dev, ifsta); |
| 2581 | } |
| 2582 | return 0; |
| 2583 | } |
| 2584 | |
| 2585 | |
| 2586 | int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len) |
| 2587 | { |
| 2588 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2589 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 2590 | memcpy(ssid, ifsta->ssid, ifsta->ssid_len); |
| 2591 | *len = ifsta->ssid_len; |
| 2592 | return 0; |
| 2593 | } |
| 2594 | |
| 2595 | |
| 2596 | int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid) |
| 2597 | { |
| 2598 | struct ieee80211_sub_if_data *sdata; |
| 2599 | struct ieee80211_if_sta *ifsta; |
| 2600 | int res; |
| 2601 | |
| 2602 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2603 | ifsta = &sdata->u.sta; |
| 2604 | |
| 2605 | if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { |
| 2606 | memcpy(ifsta->bssid, bssid, ETH_ALEN); |
| 2607 | res = ieee80211_if_config(dev); |
| 2608 | if (res) { |
| 2609 | printk(KERN_DEBUG "%s: Failed to config new BSSID to " |
| 2610 | "the low-level driver\n", dev->name); |
| 2611 | return res; |
| 2612 | } |
| 2613 | } |
| 2614 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2615 | if (is_valid_ether_addr(bssid)) |
| 2616 | ifsta->flags |= IEEE80211_STA_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2617 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2618 | ifsta->flags &= ~IEEE80211_STA_BSSID_SET; |
| 2619 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2620 | return 0; |
| 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 2625 | struct ieee80211_sub_if_data *sdata, |
| 2626 | int powersave) |
| 2627 | { |
| 2628 | struct sk_buff *skb; |
| 2629 | struct ieee80211_hdr *nullfunc; |
| 2630 | u16 fc; |
| 2631 | |
| 2632 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); |
| 2633 | if (!skb) { |
| 2634 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " |
| 2635 | "frame\n", sdata->dev->name); |
| 2636 | return; |
| 2637 | } |
| 2638 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 2639 | |
| 2640 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); |
| 2641 | memset(nullfunc, 0, 24); |
| 2642 | fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 2643 | IEEE80211_FCTL_TODS; |
| 2644 | if (powersave) |
| 2645 | fc |= IEEE80211_FCTL_PM; |
| 2646 | nullfunc->frame_control = cpu_to_le16(fc); |
| 2647 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); |
| 2648 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); |
| 2649 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); |
| 2650 | |
| 2651 | ieee80211_sta_tx(sdata->dev, skb, 0); |
| 2652 | } |
| 2653 | |
| 2654 | |
| 2655 | void ieee80211_scan_completed(struct ieee80211_hw *hw) |
| 2656 | { |
| 2657 | struct ieee80211_local *local = hw_to_local(hw); |
| 2658 | struct net_device *dev = local->scan_dev; |
| 2659 | struct ieee80211_sub_if_data *sdata; |
| 2660 | union iwreq_data wrqu; |
| 2661 | |
| 2662 | local->last_scan_completed = jiffies; |
| 2663 | wmb(); |
| 2664 | local->sta_scanning = 0; |
| 2665 | |
| 2666 | if (ieee80211_hw_config(local)) |
| 2667 | printk(KERN_DEBUG "%s: failed to restore operational" |
| 2668 | "channel after scan\n", dev->name); |
| 2669 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 2670 | |
| 2671 | netif_tx_lock_bh(local->mdev); |
| 2672 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; |
| 2673 | local->ops->configure_filter(local_to_hw(local), |
| 2674 | FIF_BCN_PRBRESP_PROMISC, |
| 2675 | &local->filter_flags, |
| 2676 | local->mdev->mc_count, |
| 2677 | local->mdev->mc_list); |
| 2678 | |
| 2679 | netif_tx_unlock_bh(local->mdev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2680 | |
| 2681 | memset(&wrqu, 0, sizeof(wrqu)); |
| 2682 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); |
| 2683 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 2684 | rcu_read_lock(); |
| 2685 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Mattias Nissler | 14042cbe | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 2686 | |
| 2687 | /* No need to wake the master device. */ |
| 2688 | if (sdata->dev == local->mdev) |
| 2689 | continue; |
| 2690 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2691 | if (sdata->type == IEEE80211_IF_TYPE_STA) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2692 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2693 | ieee80211_send_nullfunc(local, sdata, 0); |
| 2694 | ieee80211_sta_timer((unsigned long)sdata); |
| 2695 | } |
Mattias Nissler | 14042cbe | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 2696 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2697 | netif_wake_queue(sdata->dev); |
| 2698 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 2699 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2700 | |
| 2701 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2702 | if (sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 2703 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2704 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2705 | (!ifsta->state == IEEE80211_IBSS_JOINED && |
| 2706 | !ieee80211_sta_active_ibss(dev))) |
| 2707 | ieee80211_sta_find_ibss(dev, ifsta); |
| 2708 | } |
| 2709 | } |
| 2710 | EXPORT_SYMBOL(ieee80211_scan_completed); |
| 2711 | |
| 2712 | void ieee80211_sta_scan_work(struct work_struct *work) |
| 2713 | { |
| 2714 | struct ieee80211_local *local = |
| 2715 | container_of(work, struct ieee80211_local, scan_work.work); |
| 2716 | struct net_device *dev = local->scan_dev; |
| 2717 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2718 | struct ieee80211_hw_mode *mode; |
| 2719 | struct ieee80211_channel *chan; |
| 2720 | int skip; |
| 2721 | unsigned long next_delay = 0; |
| 2722 | |
| 2723 | if (!local->sta_scanning) |
| 2724 | return; |
| 2725 | |
| 2726 | switch (local->scan_state) { |
| 2727 | case SCAN_SET_CHANNEL: |
| 2728 | mode = local->scan_hw_mode; |
| 2729 | if (local->scan_hw_mode->list.next == &local->modes_list && |
| 2730 | local->scan_channel_idx >= mode->num_channels) { |
| 2731 | ieee80211_scan_completed(local_to_hw(local)); |
| 2732 | return; |
| 2733 | } |
| 2734 | skip = !(local->enabled_modes & (1 << mode->mode)); |
| 2735 | chan = &mode->channels[local->scan_channel_idx]; |
| 2736 | if (!(chan->flag & IEEE80211_CHAN_W_SCAN) || |
| 2737 | (sdata->type == IEEE80211_IF_TYPE_IBSS && |
| 2738 | !(chan->flag & IEEE80211_CHAN_W_IBSS)) || |
| 2739 | (local->hw_modes & local->enabled_modes & |
| 2740 | (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B)) |
| 2741 | skip = 1; |
| 2742 | |
| 2743 | if (!skip) { |
| 2744 | #if 0 |
| 2745 | printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n", |
| 2746 | dev->name, chan->chan, chan->freq); |
| 2747 | #endif |
| 2748 | |
| 2749 | local->scan_channel = chan; |
| 2750 | if (ieee80211_hw_config(local)) { |
| 2751 | printk(KERN_DEBUG "%s: failed to set channel " |
| 2752 | "%d (%d MHz) for scan\n", dev->name, |
| 2753 | chan->chan, chan->freq); |
| 2754 | skip = 1; |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | local->scan_channel_idx++; |
| 2759 | if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) { |
| 2760 | if (local->scan_hw_mode->list.next != &local->modes_list) { |
| 2761 | local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next, |
| 2762 | struct ieee80211_hw_mode, |
| 2763 | list); |
| 2764 | local->scan_channel_idx = 0; |
| 2765 | } |
| 2766 | } |
| 2767 | |
| 2768 | if (skip) |
| 2769 | break; |
| 2770 | |
| 2771 | next_delay = IEEE80211_PROBE_DELAY + |
| 2772 | usecs_to_jiffies(local->hw.channel_change_time); |
| 2773 | local->scan_state = SCAN_SEND_PROBE; |
| 2774 | break; |
| 2775 | case SCAN_SEND_PROBE: |
| 2776 | if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) { |
| 2777 | ieee80211_send_probe_req(dev, NULL, local->scan_ssid, |
| 2778 | local->scan_ssid_len); |
| 2779 | next_delay = IEEE80211_CHANNEL_TIME; |
| 2780 | } else |
| 2781 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; |
| 2782 | local->scan_state = SCAN_SET_CHANNEL; |
| 2783 | break; |
| 2784 | } |
| 2785 | |
| 2786 | if (local->sta_scanning) |
| 2787 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 2788 | next_delay); |
| 2789 | } |
| 2790 | |
| 2791 | |
| 2792 | static int ieee80211_sta_start_scan(struct net_device *dev, |
| 2793 | u8 *ssid, size_t ssid_len) |
| 2794 | { |
| 2795 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2796 | struct ieee80211_sub_if_data *sdata; |
| 2797 | |
| 2798 | if (ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2799 | return -EINVAL; |
| 2800 | |
| 2801 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) |
| 2802 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS |
| 2803 | * BSSID: MACAddress |
| 2804 | * SSID |
| 2805 | * ScanType: ACTIVE, PASSIVE |
| 2806 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting |
| 2807 | * a Probe frame during active scanning |
| 2808 | * ChannelList |
| 2809 | * MinChannelTime (>= ProbeDelay), in TU |
| 2810 | * MaxChannelTime: (>= MinChannelTime), in TU |
| 2811 | */ |
| 2812 | |
| 2813 | /* MLME-SCAN.confirm |
| 2814 | * BSSDescriptionSet |
| 2815 | * ResultCode: SUCCESS, INVALID_PARAMETERS |
| 2816 | */ |
| 2817 | |
| 2818 | if (local->sta_scanning) { |
| 2819 | if (local->scan_dev == dev) |
| 2820 | return 0; |
| 2821 | return -EBUSY; |
| 2822 | } |
| 2823 | |
| 2824 | if (local->ops->hw_scan) { |
| 2825 | int rc = local->ops->hw_scan(local_to_hw(local), |
| 2826 | ssid, ssid_len); |
| 2827 | if (!rc) { |
| 2828 | local->sta_scanning = 1; |
| 2829 | local->scan_dev = dev; |
| 2830 | } |
| 2831 | return rc; |
| 2832 | } |
| 2833 | |
| 2834 | local->sta_scanning = 1; |
| 2835 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 2836 | rcu_read_lock(); |
| 2837 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Mattias Nissler | 14042cbe | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 2838 | |
| 2839 | /* Don't stop the master interface, otherwise we can't transmit |
| 2840 | * probes! */ |
| 2841 | if (sdata->dev == local->mdev) |
| 2842 | continue; |
| 2843 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2844 | netif_stop_queue(sdata->dev); |
| 2845 | if (sdata->type == IEEE80211_IF_TYPE_STA && |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2846 | (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2847 | ieee80211_send_nullfunc(local, sdata, 1); |
| 2848 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 2849 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2850 | |
| 2851 | if (ssid) { |
| 2852 | local->scan_ssid_len = ssid_len; |
| 2853 | memcpy(local->scan_ssid, ssid, ssid_len); |
| 2854 | } else |
| 2855 | local->scan_ssid_len = 0; |
| 2856 | local->scan_state = SCAN_SET_CHANNEL; |
| 2857 | local->scan_hw_mode = list_entry(local->modes_list.next, |
| 2858 | struct ieee80211_hw_mode, |
| 2859 | list); |
| 2860 | local->scan_channel_idx = 0; |
| 2861 | local->scan_dev = dev; |
| 2862 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 2863 | netif_tx_lock_bh(local->mdev); |
| 2864 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; |
| 2865 | local->ops->configure_filter(local_to_hw(local), |
| 2866 | FIF_BCN_PRBRESP_PROMISC, |
| 2867 | &local->filter_flags, |
| 2868 | local->mdev->mc_count, |
| 2869 | local->mdev->mc_list); |
| 2870 | netif_tx_unlock_bh(local->mdev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2871 | |
| 2872 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ |
| 2873 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 2874 | IEEE80211_CHANNEL_TIME); |
| 2875 | |
| 2876 | return 0; |
| 2877 | } |
| 2878 | |
| 2879 | |
| 2880 | int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len) |
| 2881 | { |
| 2882 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2883 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 2884 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2885 | |
| 2886 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 2887 | return ieee80211_sta_start_scan(dev, ssid, ssid_len); |
| 2888 | |
| 2889 | if (local->sta_scanning) { |
| 2890 | if (local->scan_dev == dev) |
| 2891 | return 0; |
| 2892 | return -EBUSY; |
| 2893 | } |
| 2894 | |
| 2895 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); |
| 2896 | queue_work(local->hw.workqueue, &ifsta->work); |
| 2897 | return 0; |
| 2898 | } |
| 2899 | |
| 2900 | static char * |
| 2901 | ieee80211_sta_scan_result(struct net_device *dev, |
| 2902 | struct ieee80211_sta_bss *bss, |
| 2903 | char *current_ev, char *end_buf) |
| 2904 | { |
| 2905 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2906 | struct iw_event iwe; |
| 2907 | |
| 2908 | if (time_after(jiffies, |
| 2909 | bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) |
| 2910 | return current_ev; |
| 2911 | |
| 2912 | if (!(local->enabled_modes & (1 << bss->hw_mode))) |
| 2913 | return current_ev; |
| 2914 | |
| 2915 | if (local->scan_flags & IEEE80211_SCAN_WPA_ONLY && |
| 2916 | !bss->wpa_ie && !bss->rsn_ie) |
| 2917 | return current_ev; |
| 2918 | |
| 2919 | if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID && |
| 2920 | (local->scan_ssid_len != bss->ssid_len || |
| 2921 | memcmp(local->scan_ssid, bss->ssid, bss->ssid_len) != 0)) |
| 2922 | return current_ev; |
| 2923 | |
| 2924 | memset(&iwe, 0, sizeof(iwe)); |
| 2925 | iwe.cmd = SIOCGIWAP; |
| 2926 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 2927 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
| 2928 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 2929 | IW_EV_ADDR_LEN); |
| 2930 | |
| 2931 | memset(&iwe, 0, sizeof(iwe)); |
| 2932 | iwe.cmd = SIOCGIWESSID; |
| 2933 | iwe.u.data.length = bss->ssid_len; |
| 2934 | iwe.u.data.flags = 1; |
| 2935 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 2936 | bss->ssid); |
| 2937 | |
| 2938 | if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) { |
| 2939 | memset(&iwe, 0, sizeof(iwe)); |
| 2940 | iwe.cmd = SIOCGIWMODE; |
| 2941 | if (bss->capability & WLAN_CAPABILITY_ESS) |
| 2942 | iwe.u.mode = IW_MODE_MASTER; |
| 2943 | else |
| 2944 | iwe.u.mode = IW_MODE_ADHOC; |
| 2945 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 2946 | IW_EV_UINT_LEN); |
| 2947 | } |
| 2948 | |
| 2949 | memset(&iwe, 0, sizeof(iwe)); |
| 2950 | iwe.cmd = SIOCGIWFREQ; |
| 2951 | iwe.u.freq.m = bss->channel; |
| 2952 | iwe.u.freq.e = 0; |
| 2953 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 2954 | IW_EV_FREQ_LEN); |
| 2955 | iwe.u.freq.m = bss->freq * 100000; |
| 2956 | iwe.u.freq.e = 1; |
| 2957 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 2958 | IW_EV_FREQ_LEN); |
| 2959 | |
| 2960 | memset(&iwe, 0, sizeof(iwe)); |
| 2961 | iwe.cmd = IWEVQUAL; |
| 2962 | iwe.u.qual.qual = bss->signal; |
| 2963 | iwe.u.qual.level = bss->rssi; |
| 2964 | iwe.u.qual.noise = bss->noise; |
| 2965 | iwe.u.qual.updated = local->wstats_flags; |
| 2966 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 2967 | IW_EV_QUAL_LEN); |
| 2968 | |
| 2969 | memset(&iwe, 0, sizeof(iwe)); |
| 2970 | iwe.cmd = SIOCGIWENCODE; |
| 2971 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
| 2972 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 2973 | else |
| 2974 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 2975 | iwe.u.data.length = 0; |
| 2976 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ""); |
| 2977 | |
| 2978 | if (bss && bss->wpa_ie) { |
| 2979 | memset(&iwe, 0, sizeof(iwe)); |
| 2980 | iwe.cmd = IWEVGENIE; |
| 2981 | iwe.u.data.length = bss->wpa_ie_len; |
| 2982 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 2983 | bss->wpa_ie); |
| 2984 | } |
| 2985 | |
| 2986 | if (bss && bss->rsn_ie) { |
| 2987 | memset(&iwe, 0, sizeof(iwe)); |
| 2988 | iwe.cmd = IWEVGENIE; |
| 2989 | iwe.u.data.length = bss->rsn_ie_len; |
| 2990 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 2991 | bss->rsn_ie); |
| 2992 | } |
| 2993 | |
| 2994 | if (bss && bss->supp_rates_len > 0) { |
| 2995 | /* display all supported rates in readable format */ |
| 2996 | char *p = current_ev + IW_EV_LCP_LEN; |
| 2997 | int i; |
| 2998 | |
| 2999 | memset(&iwe, 0, sizeof(iwe)); |
| 3000 | iwe.cmd = SIOCGIWRATE; |
| 3001 | /* Those two flags are ignored... */ |
| 3002 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; |
| 3003 | |
| 3004 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 3005 | iwe.u.bitrate.value = ((bss->supp_rates[i] & |
| 3006 | 0x7f) * 500000); |
| 3007 | p = iwe_stream_add_value(current_ev, p, |
| 3008 | end_buf, &iwe, IW_EV_PARAM_LEN); |
| 3009 | } |
| 3010 | current_ev = p; |
| 3011 | } |
| 3012 | |
| 3013 | if (bss) { |
| 3014 | char *buf; |
| 3015 | buf = kmalloc(30, GFP_ATOMIC); |
| 3016 | if (buf) { |
| 3017 | memset(&iwe, 0, sizeof(iwe)); |
| 3018 | iwe.cmd = IWEVCUSTOM; |
| 3019 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); |
| 3020 | iwe.u.data.length = strlen(buf); |
| 3021 | current_ev = iwe_stream_add_point(current_ev, end_buf, |
| 3022 | &iwe, buf); |
| 3023 | kfree(buf); |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | do { |
| 3028 | char *buf; |
| 3029 | |
| 3030 | if (!(local->scan_flags & IEEE80211_SCAN_EXTRA_INFO)) |
| 3031 | break; |
| 3032 | |
| 3033 | buf = kmalloc(100, GFP_ATOMIC); |
| 3034 | if (!buf) |
| 3035 | break; |
| 3036 | |
| 3037 | memset(&iwe, 0, sizeof(iwe)); |
| 3038 | iwe.cmd = IWEVCUSTOM; |
| 3039 | sprintf(buf, "bcn_int=%d", bss->beacon_int); |
| 3040 | iwe.u.data.length = strlen(buf); |
| 3041 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 3042 | buf); |
| 3043 | |
| 3044 | memset(&iwe, 0, sizeof(iwe)); |
| 3045 | iwe.cmd = IWEVCUSTOM; |
| 3046 | sprintf(buf, "capab=0x%04x", bss->capability); |
| 3047 | iwe.u.data.length = strlen(buf); |
| 3048 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 3049 | buf); |
| 3050 | |
| 3051 | kfree(buf); |
| 3052 | break; |
| 3053 | } while (0); |
| 3054 | |
| 3055 | return current_ev; |
| 3056 | } |
| 3057 | |
| 3058 | |
| 3059 | int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len) |
| 3060 | { |
| 3061 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 3062 | char *current_ev = buf; |
| 3063 | char *end_buf = buf + len; |
| 3064 | struct ieee80211_sta_bss *bss; |
| 3065 | |
| 3066 | spin_lock_bh(&local->sta_bss_lock); |
| 3067 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 3068 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { |
| 3069 | spin_unlock_bh(&local->sta_bss_lock); |
| 3070 | return -E2BIG; |
| 3071 | } |
| 3072 | current_ev = ieee80211_sta_scan_result(dev, bss, current_ev, |
| 3073 | end_buf); |
| 3074 | } |
| 3075 | spin_unlock_bh(&local->sta_bss_lock); |
| 3076 | return current_ev - buf; |
| 3077 | } |
| 3078 | |
| 3079 | |
| 3080 | int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len) |
| 3081 | { |
| 3082 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3083 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3084 | kfree(ifsta->extra_ie); |
| 3085 | if (len == 0) { |
| 3086 | ifsta->extra_ie = NULL; |
| 3087 | ifsta->extra_ie_len = 0; |
| 3088 | return 0; |
| 3089 | } |
| 3090 | ifsta->extra_ie = kmalloc(len, GFP_KERNEL); |
| 3091 | if (!ifsta->extra_ie) { |
| 3092 | ifsta->extra_ie_len = 0; |
| 3093 | return -ENOMEM; |
| 3094 | } |
| 3095 | memcpy(ifsta->extra_ie, ie, len); |
| 3096 | ifsta->extra_ie_len = len; |
| 3097 | return 0; |
| 3098 | } |
| 3099 | |
| 3100 | |
| 3101 | struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev, |
| 3102 | struct sk_buff *skb, u8 *bssid, |
| 3103 | u8 *addr) |
| 3104 | { |
| 3105 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 3106 | struct sta_info *sta; |
John W. Linville | 91fa558 | 2007-05-15 16:14:40 -0400 | [diff] [blame] | 3107 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3108 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3109 | |
| 3110 | /* TODO: Could consider removing the least recently used entry and |
| 3111 | * allow new one to be added. */ |
| 3112 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
| 3113 | if (net_ratelimit()) { |
| 3114 | printk(KERN_DEBUG "%s: No room for a new IBSS STA " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3115 | "entry %s\n", dev->name, print_mac(mac, addr)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3116 | } |
| 3117 | return NULL; |
| 3118 | } |
| 3119 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3120 | printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 3121 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3122 | |
| 3123 | sta = sta_info_add(local, dev, addr, GFP_ATOMIC); |
| 3124 | if (!sta) |
| 3125 | return NULL; |
| 3126 | |
| 3127 | sta->supp_rates = sdata->u.sta.supp_rates_bits; |
| 3128 | |
| 3129 | rate_control_rate_init(sta, local); |
| 3130 | |
| 3131 | return sta; /* caller will call sta_info_put() */ |
| 3132 | } |
| 3133 | |
| 3134 | |
| 3135 | int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason) |
| 3136 | { |
| 3137 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3138 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3139 | |
| 3140 | printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n", |
| 3141 | dev->name, reason); |
| 3142 | |
| 3143 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 3144 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 3145 | return -EINVAL; |
| 3146 | |
| 3147 | ieee80211_send_deauth(dev, ifsta, reason); |
| 3148 | ieee80211_set_disassoc(dev, ifsta, 1); |
| 3149 | return 0; |
| 3150 | } |
| 3151 | |
| 3152 | |
| 3153 | int ieee80211_sta_disassociate(struct net_device *dev, u16 reason) |
| 3154 | { |
| 3155 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3156 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3157 | |
| 3158 | printk(KERN_DEBUG "%s: disassociate(reason=%d)\n", |
| 3159 | dev->name, reason); |
| 3160 | |
| 3161 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 3162 | return -EINVAL; |
| 3163 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3164 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3165 | return -1; |
| 3166 | |
| 3167 | ieee80211_send_disassoc(dev, ifsta, reason); |
| 3168 | ieee80211_set_disassoc(dev, ifsta, 0); |
| 3169 | return 0; |
| 3170 | } |