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