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