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