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