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