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 | |
| 1048 | static void ieee80211_sta_process_addba_request(struct net_device *dev, |
| 1049 | struct ieee80211_mgmt *mgmt, |
| 1050 | size_t len) |
| 1051 | { |
| 1052 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1053 | struct ieee80211_hw *hw = &local->hw; |
| 1054 | struct ieee80211_conf *conf = &hw->conf; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1055 | struct sta_info *sta; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1056 | struct tid_ampdu_rx *tid_agg_rx; |
| 1057 | u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1058 | u8 dialog_token; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1059 | int ret = -EOPNOTSUPP; |
| 1060 | DECLARE_MAC_BUF(mac); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1061 | |
| 1062 | sta = sta_info_get(local, mgmt->sa); |
| 1063 | if (!sta) |
| 1064 | return; |
| 1065 | |
| 1066 | /* extract session parameters from addba request frame */ |
| 1067 | dialog_token = mgmt->u.action.u.addba_req.dialog_token; |
| 1068 | timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1069 | start_seq_num = |
| 1070 | 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] | 1071 | |
| 1072 | capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 1073 | ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1; |
| 1074 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1075 | buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6; |
| 1076 | |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1077 | status = WLAN_STATUS_REQUEST_DECLINED; |
| 1078 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1079 | /* sanity check for incoming parameters: |
| 1080 | * check if configuration can support the BA policy |
| 1081 | * and if buffer size does not exceeds max value */ |
| 1082 | if (((ba_policy != 1) |
| 1083 | && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA))) |
| 1084 | || (buf_size > IEEE80211_MAX_AMPDU_BUF)) { |
| 1085 | status = WLAN_STATUS_INVALID_QOS_PARAM; |
| 1086 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1087 | if (net_ratelimit()) |
| 1088 | printk(KERN_DEBUG "Block Ack Req with bad params from " |
| 1089 | "%s on tid %u. policy %d, buffer size %d\n", |
| 1090 | print_mac(mac, mgmt->sa), tid, ba_policy, |
| 1091 | buf_size); |
| 1092 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1093 | goto end_no_lock; |
| 1094 | } |
| 1095 | /* determine default buffer size */ |
| 1096 | if (buf_size == 0) { |
| 1097 | struct ieee80211_hw_mode *mode = conf->mode; |
| 1098 | buf_size = IEEE80211_MIN_AMPDU_BUF; |
| 1099 | buf_size = buf_size << mode->ht_info.ampdu_factor; |
| 1100 | } |
| 1101 | |
| 1102 | tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid]; |
| 1103 | |
| 1104 | /* examine state machine */ |
| 1105 | spin_lock_bh(&sta->ampdu_mlme.ampdu_rx); |
| 1106 | |
| 1107 | if (tid_agg_rx->state != HT_AGG_STATE_IDLE) { |
| 1108 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1109 | if (net_ratelimit()) |
| 1110 | printk(KERN_DEBUG "unexpected Block Ack Req from " |
| 1111 | "%s on tid %u\n", |
| 1112 | print_mac(mac, mgmt->sa), tid); |
| 1113 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1114 | goto end; |
| 1115 | } |
| 1116 | |
| 1117 | /* prepare reordering buffer */ |
| 1118 | tid_agg_rx->reorder_buf = |
| 1119 | kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC); |
Johannes Berg | 03147df | 2008-02-26 00:39:28 +0100 | [diff] [blame] | 1120 | if (!tid_agg_rx->reorder_buf) { |
| 1121 | if (net_ratelimit()) |
| 1122 | printk(KERN_ERR "can not allocate reordering buffer " |
| 1123 | "to tid %d\n", tid); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1124 | goto end; |
| 1125 | } |
| 1126 | memset(tid_agg_rx->reorder_buf, 0, |
| 1127 | buf_size * sizeof(struct sk_buf *)); |
| 1128 | |
| 1129 | if (local->ops->ampdu_action) |
| 1130 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START, |
| 1131 | sta->addr, tid, start_seq_num); |
| 1132 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1133 | printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret); |
| 1134 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1135 | |
| 1136 | if (ret) { |
| 1137 | kfree(tid_agg_rx->reorder_buf); |
| 1138 | goto end; |
| 1139 | } |
| 1140 | |
| 1141 | /* change state and send addba resp */ |
| 1142 | tid_agg_rx->state = HT_AGG_STATE_OPERATIONAL; |
| 1143 | tid_agg_rx->dialog_token = dialog_token; |
| 1144 | tid_agg_rx->ssn = start_seq_num; |
| 1145 | tid_agg_rx->head_seq_num = start_seq_num; |
| 1146 | tid_agg_rx->buf_size = buf_size; |
| 1147 | tid_agg_rx->timeout = timeout; |
| 1148 | tid_agg_rx->stored_mpdu_num = 0; |
| 1149 | status = WLAN_STATUS_SUCCESS; |
| 1150 | end: |
| 1151 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx); |
| 1152 | |
| 1153 | end_no_lock: |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1154 | ieee80211_send_addba_resp(sta->dev, sta->addr, tid, dialog_token, |
| 1155 | status, 1, buf_size, timeout); |
| 1156 | sta_info_put(sta); |
| 1157 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1158 | |
Ron Rindjunsky | 71ebb4a | 2008-01-21 12:39:12 +0200 | [diff] [blame] | 1159 | static void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid, |
| 1160 | u16 initiator, u16 reason_code) |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1161 | { |
| 1162 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1163 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1164 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 1165 | struct sk_buff *skb; |
| 1166 | struct ieee80211_mgmt *mgmt; |
| 1167 | u16 params; |
| 1168 | |
| 1169 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 + |
| 1170 | sizeof(mgmt->u.action.u.delba)); |
| 1171 | |
| 1172 | if (!skb) { |
| 1173 | printk(KERN_ERR "%s: failed to allocate buffer " |
| 1174 | "for delba frame\n", dev->name); |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1179 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 1180 | memset(mgmt, 0, 24); |
| 1181 | memcpy(mgmt->da, da, ETH_ALEN); |
| 1182 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1183 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1184 | memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN); |
| 1185 | else |
| 1186 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 1187 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 1188 | IEEE80211_STYPE_ACTION); |
| 1189 | |
| 1190 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba)); |
| 1191 | |
| 1192 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 1193 | mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA; |
| 1194 | params = (u16)(initiator << 11); /* bit 11 initiator */ |
| 1195 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
| 1196 | |
| 1197 | mgmt->u.action.u.delba.params = cpu_to_le16(params); |
| 1198 | mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code); |
| 1199 | |
| 1200 | ieee80211_sta_tx(dev, skb, 0); |
| 1201 | } |
| 1202 | |
| 1203 | void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid, |
| 1204 | u16 initiator, u16 reason) |
| 1205 | { |
| 1206 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1207 | struct ieee80211_hw *hw = &local->hw; |
| 1208 | struct sta_info *sta; |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 1209 | int ret, i; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1210 | |
| 1211 | sta = sta_info_get(local, ra); |
| 1212 | if (!sta) |
| 1213 | return; |
| 1214 | |
| 1215 | /* check if TID is in operational state */ |
| 1216 | spin_lock_bh(&sta->ampdu_mlme.ampdu_rx); |
| 1217 | if (sta->ampdu_mlme.tid_rx[tid].state |
| 1218 | != HT_AGG_STATE_OPERATIONAL) { |
| 1219 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1220 | sta_info_put(sta); |
| 1221 | return; |
| 1222 | } |
| 1223 | sta->ampdu_mlme.tid_rx[tid].state = |
| 1224 | HT_AGG_STATE_REQ_STOP_BA_MSK | |
| 1225 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); |
| 1226 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx); |
| 1227 | |
| 1228 | /* stop HW Rx aggregation. ampdu_action existence |
| 1229 | * already verified in session init so we add the BUG_ON */ |
| 1230 | BUG_ON(!local->ops->ampdu_action); |
| 1231 | |
| 1232 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, |
| 1233 | ra, tid, EINVAL); |
| 1234 | if (ret) |
| 1235 | printk(KERN_DEBUG "HW problem - can not stop rx " |
| 1236 | "aggergation for tid %d\n", tid); |
| 1237 | |
| 1238 | /* shutdown timer has not expired */ |
| 1239 | if (initiator != WLAN_BACK_TIMER) |
| 1240 | del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]. |
| 1241 | session_timer); |
| 1242 | |
| 1243 | /* check if this is a self generated aggregation halt */ |
| 1244 | if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER) |
| 1245 | ieee80211_send_delba(dev, ra, tid, 0, reason); |
| 1246 | |
| 1247 | /* free the reordering buffer */ |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 1248 | for (i = 0; i < sta->ampdu_mlme.tid_rx[tid].buf_size; i++) { |
| 1249 | if (sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]) { |
| 1250 | /* release the reordered frames */ |
| 1251 | dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]); |
| 1252 | sta->ampdu_mlme.tid_rx[tid].stored_mpdu_num--; |
| 1253 | sta->ampdu_mlme.tid_rx[tid].reorder_buf[i] = NULL; |
| 1254 | } |
| 1255 | } |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1256 | kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf); |
| 1257 | |
| 1258 | sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE; |
| 1259 | sta_info_put(sta); |
| 1260 | } |
| 1261 | |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1262 | static void ieee80211_sta_process_delba(struct net_device *dev, |
| 1263 | struct ieee80211_mgmt *mgmt, size_t len) |
| 1264 | { |
| 1265 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1266 | struct sta_info *sta; |
| 1267 | u16 tid, params; |
| 1268 | u16 initiator; |
| 1269 | DECLARE_MAC_BUF(mac); |
| 1270 | |
| 1271 | sta = sta_info_get(local, mgmt->sa); |
| 1272 | if (!sta) |
| 1273 | return; |
| 1274 | |
| 1275 | params = le16_to_cpu(mgmt->u.action.u.delba.params); |
| 1276 | tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12; |
| 1277 | initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11; |
| 1278 | |
| 1279 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1280 | if (net_ratelimit()) |
| 1281 | printk(KERN_DEBUG "delba from %s on tid %d reason code %d\n", |
| 1282 | print_mac(mac, mgmt->sa), tid, |
| 1283 | mgmt->u.action.u.delba.reason_code); |
| 1284 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1285 | |
| 1286 | if (initiator == WLAN_BACK_INITIATOR) |
| 1287 | ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid, |
| 1288 | WLAN_BACK_INITIATOR, 0); |
| 1289 | sta_info_put(sta); |
| 1290 | } |
| 1291 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1292 | /* |
| 1293 | * After receiving Block Ack Request (BAR) we activated a |
| 1294 | * timer after each frame arrives from the originator. |
| 1295 | * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed. |
| 1296 | */ |
| 1297 | void sta_rx_agg_session_timer_expired(unsigned long data) |
| 1298 | { |
| 1299 | /* not an elegant detour, but there is no choice as the timer passes |
| 1300 | * only one argument, and verious sta_info are needed here, so init |
| 1301 | * flow in sta_info_add gives the TID as data, while the timer_to_id |
| 1302 | * array gives the sta through container_of */ |
| 1303 | u8 *ptid = (u8 *)data; |
| 1304 | u8 *timer_to_id = ptid - *ptid; |
| 1305 | struct sta_info *sta = container_of(timer_to_id, struct sta_info, |
| 1306 | timer_to_tid[0]); |
| 1307 | |
| 1308 | printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); |
| 1309 | ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, (u16)*ptid, |
| 1310 | WLAN_BACK_TIMER, |
| 1311 | WLAN_REASON_QSTA_TIMEOUT); |
| 1312 | } |
| 1313 | |
| 1314 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1315 | static void ieee80211_rx_mgmt_auth(struct net_device *dev, |
| 1316 | struct ieee80211_if_sta *ifsta, |
| 1317 | struct ieee80211_mgmt *mgmt, |
| 1318 | size_t len) |
| 1319 | { |
| 1320 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1321 | u16 auth_alg, auth_transaction, status_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1322 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1323 | |
| 1324 | if (ifsta->state != IEEE80211_AUTHENTICATE && |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1325 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1326 | printk(KERN_DEBUG "%s: authentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1327 | "%s, but not in authenticate state - ignored\n", |
| 1328 | dev->name, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1329 | return; |
| 1330 | } |
| 1331 | |
| 1332 | if (len < 24 + 6) { |
| 1333 | printk(KERN_DEBUG "%s: too short (%zd) authentication frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1334 | "received from %s - ignored\n", |
| 1335 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1336 | return; |
| 1337 | } |
| 1338 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1339 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1340 | memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 1341 | printk(KERN_DEBUG "%s: authentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1342 | "unknown AP (SA=%s BSSID=%s) - " |
| 1343 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1344 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1345 | return; |
| 1346 | } |
| 1347 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1348 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1349 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) { |
| 1350 | printk(KERN_DEBUG "%s: authentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1351 | "unknown BSSID (SA=%s BSSID=%s) - " |
| 1352 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1353 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1354 | return; |
| 1355 | } |
| 1356 | |
| 1357 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 1358 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 1359 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 1360 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1361 | printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1362 | "transaction=%d status=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1363 | dev->name, print_mac(mac, mgmt->sa), auth_alg, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1364 | auth_transaction, status_code); |
| 1365 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1366 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1367 | /* IEEE 802.11 standard does not require authentication in IBSS |
| 1368 | * networks and most implementations do not seem to use it. |
| 1369 | * However, try to reply to authentication attempts if someone |
| 1370 | * has actually implemented this. |
| 1371 | * TODO: Could implement shared key authentication. */ |
| 1372 | if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) { |
| 1373 | printk(KERN_DEBUG "%s: unexpected IBSS authentication " |
| 1374 | "frame (alg=%d transaction=%d)\n", |
| 1375 | dev->name, auth_alg, auth_transaction); |
| 1376 | return; |
| 1377 | } |
| 1378 | ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0); |
| 1379 | } |
| 1380 | |
| 1381 | if (auth_alg != ifsta->auth_alg || |
| 1382 | auth_transaction != ifsta->auth_transaction) { |
| 1383 | printk(KERN_DEBUG "%s: unexpected authentication frame " |
| 1384 | "(alg=%d transaction=%d)\n", |
| 1385 | dev->name, auth_alg, auth_transaction); |
| 1386 | return; |
| 1387 | } |
| 1388 | |
| 1389 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 1390 | printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d " |
| 1391 | "code=%d)\n", dev->name, ifsta->auth_alg, status_code); |
| 1392 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { |
| 1393 | u8 algs[3]; |
| 1394 | const int num_algs = ARRAY_SIZE(algs); |
| 1395 | int i, pos; |
| 1396 | algs[0] = algs[1] = algs[2] = 0xff; |
| 1397 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 1398 | algs[0] = WLAN_AUTH_OPEN; |
| 1399 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 1400 | algs[1] = WLAN_AUTH_SHARED_KEY; |
| 1401 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 1402 | algs[2] = WLAN_AUTH_LEAP; |
| 1403 | if (ifsta->auth_alg == WLAN_AUTH_OPEN) |
| 1404 | pos = 0; |
| 1405 | else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY) |
| 1406 | pos = 1; |
| 1407 | else |
| 1408 | pos = 2; |
| 1409 | for (i = 0; i < num_algs; i++) { |
| 1410 | pos++; |
| 1411 | if (pos >= num_algs) |
| 1412 | pos = 0; |
| 1413 | if (algs[pos] == ifsta->auth_alg || |
| 1414 | algs[pos] == 0xff) |
| 1415 | continue; |
| 1416 | if (algs[pos] == WLAN_AUTH_SHARED_KEY && |
| 1417 | !ieee80211_sta_wep_configured(dev)) |
| 1418 | continue; |
| 1419 | ifsta->auth_alg = algs[pos]; |
| 1420 | printk(KERN_DEBUG "%s: set auth_alg=%d for " |
| 1421 | "next try\n", |
| 1422 | dev->name, ifsta->auth_alg); |
| 1423 | break; |
| 1424 | } |
| 1425 | } |
| 1426 | return; |
| 1427 | } |
| 1428 | |
| 1429 | switch (ifsta->auth_alg) { |
| 1430 | case WLAN_AUTH_OPEN: |
| 1431 | case WLAN_AUTH_LEAP: |
| 1432 | ieee80211_auth_completed(dev, ifsta); |
| 1433 | break; |
| 1434 | case WLAN_AUTH_SHARED_KEY: |
| 1435 | if (ifsta->auth_transaction == 4) |
| 1436 | ieee80211_auth_completed(dev, ifsta); |
| 1437 | else |
| 1438 | ieee80211_auth_challenge(dev, ifsta, mgmt, len); |
| 1439 | break; |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | static void ieee80211_rx_mgmt_deauth(struct net_device *dev, |
| 1445 | struct ieee80211_if_sta *ifsta, |
| 1446 | struct ieee80211_mgmt *mgmt, |
| 1447 | size_t len) |
| 1448 | { |
| 1449 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1450 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1451 | |
| 1452 | if (len < 24 + 2) { |
| 1453 | printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1454 | "received from %s - ignored\n", |
| 1455 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1456 | return; |
| 1457 | } |
| 1458 | |
| 1459 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 1460 | printk(KERN_DEBUG "%s: deauthentication frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1461 | "unknown AP (SA=%s BSSID=%s) - " |
| 1462 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1463 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1464 | return; |
| 1465 | } |
| 1466 | |
| 1467 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 1468 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1469 | printk(KERN_DEBUG "%s: RX deauthentication from %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1470 | " (reason=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1471 | dev->name, print_mac(mac, mgmt->sa), reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1472 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1473 | if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1474 | printk(KERN_DEBUG "%s: deauthenticated\n", dev->name); |
| 1475 | } |
| 1476 | |
| 1477 | if (ifsta->state == IEEE80211_AUTHENTICATE || |
| 1478 | ifsta->state == IEEE80211_ASSOCIATE || |
| 1479 | ifsta->state == IEEE80211_ASSOCIATED) { |
| 1480 | ifsta->state = IEEE80211_AUTHENTICATE; |
| 1481 | mod_timer(&ifsta->timer, jiffies + |
| 1482 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1483 | } |
| 1484 | |
| 1485 | ieee80211_set_disassoc(dev, ifsta, 1); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1486 | ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | |
| 1490 | static void ieee80211_rx_mgmt_disassoc(struct net_device *dev, |
| 1491 | struct ieee80211_if_sta *ifsta, |
| 1492 | struct ieee80211_mgmt *mgmt, |
| 1493 | size_t len) |
| 1494 | { |
| 1495 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1496 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1497 | |
| 1498 | if (len < 24 + 2) { |
| 1499 | printk(KERN_DEBUG "%s: too short (%zd) disassociation frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1500 | "received from %s - ignored\n", |
| 1501 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 1506 | printk(KERN_DEBUG "%s: disassociation frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1507 | "unknown AP (SA=%s BSSID=%s) - " |
| 1508 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1509 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1510 | return; |
| 1511 | } |
| 1512 | |
| 1513 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 1514 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1515 | printk(KERN_DEBUG "%s: RX disassociation from %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1516 | " (reason=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1517 | dev->name, print_mac(mac, mgmt->sa), reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1518 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1519 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1520 | printk(KERN_DEBUG "%s: disassociated\n", dev->name); |
| 1521 | |
| 1522 | if (ifsta->state == IEEE80211_ASSOCIATED) { |
| 1523 | ifsta->state = IEEE80211_ASSOCIATE; |
| 1524 | mod_timer(&ifsta->timer, jiffies + |
| 1525 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1526 | } |
| 1527 | |
| 1528 | ieee80211_set_disassoc(dev, ifsta, 0); |
| 1529 | } |
| 1530 | |
| 1531 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1532 | 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] | 1533 | struct ieee80211_if_sta *ifsta, |
| 1534 | struct ieee80211_mgmt *mgmt, |
| 1535 | size_t len, |
| 1536 | int reassoc) |
| 1537 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1538 | struct ieee80211_local *local = sdata->local; |
| 1539 | struct net_device *dev = sdata->dev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1540 | struct ieee80211_hw_mode *mode; |
| 1541 | struct sta_info *sta; |
| 1542 | u32 rates; |
| 1543 | u16 capab_info, status_code, aid; |
| 1544 | struct ieee802_11_elems elems; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1545 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1546 | u8 *pos; |
| 1547 | int i, j; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1548 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1549 | |
| 1550 | /* AssocResp and ReassocResp have identical structure, so process both |
| 1551 | * of them in this function. */ |
| 1552 | |
| 1553 | if (ifsta->state != IEEE80211_ASSOCIATE) { |
| 1554 | printk(KERN_DEBUG "%s: association frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1555 | "%s, but not in associate state - ignored\n", |
| 1556 | dev->name, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1557 | return; |
| 1558 | } |
| 1559 | |
| 1560 | if (len < 24 + 6) { |
| 1561 | printk(KERN_DEBUG "%s: too short (%zd) association frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1562 | "received from %s - ignored\n", |
| 1563 | dev->name, len, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1564 | return; |
| 1565 | } |
| 1566 | |
| 1567 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { |
| 1568 | printk(KERN_DEBUG "%s: association frame received from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1569 | "unknown AP (SA=%s BSSID=%s) - " |
| 1570 | "ignored\n", dev->name, print_mac(mac, mgmt->sa), |
| 1571 | print_mac(mac, mgmt->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1572 | return; |
| 1573 | } |
| 1574 | |
| 1575 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 1576 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 1577 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1578 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1579 | printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1580 | "status=%d aid=%d)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1581 | dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa), |
Johannes Berg | ddd6858 | 2007-10-22 14:51:37 +0200 | [diff] [blame] | 1582 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1583 | |
| 1584 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 1585 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", |
| 1586 | dev->name, status_code); |
Daniel Drake | 8a69aa9 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1587 | /* if this was a reassociation, ensure we try a "full" |
| 1588 | * association next time. This works around some broken APs |
| 1589 | * which do not correctly reject reassociation requests. */ |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1590 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1591 | return; |
| 1592 | } |
| 1593 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1594 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
| 1595 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " |
| 1596 | "set\n", dev->name, aid); |
| 1597 | aid &= ~(BIT(15) | BIT(14)); |
| 1598 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1599 | pos = mgmt->u.assoc_resp.variable; |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 1600 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1601 | |
| 1602 | if (!elems.supp_rates) { |
| 1603 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", |
| 1604 | dev->name); |
| 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | printk(KERN_DEBUG "%s: associated\n", dev->name); |
| 1609 | ifsta->aid = aid; |
| 1610 | ifsta->ap_capab = capab_info; |
| 1611 | |
| 1612 | kfree(ifsta->assocresp_ies); |
| 1613 | ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt); |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1614 | ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1615 | if (ifsta->assocresp_ies) |
| 1616 | memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); |
| 1617 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1618 | /* set AID, ieee80211_set_associated() will tell the driver */ |
| 1619 | bss_conf->aid = aid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1620 | ieee80211_set_associated(dev, ifsta, 1); |
| 1621 | |
| 1622 | /* Add STA entry for the AP */ |
| 1623 | sta = sta_info_get(local, ifsta->bssid); |
| 1624 | if (!sta) { |
| 1625 | struct ieee80211_sta_bss *bss; |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1626 | sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1627 | if (!sta) { |
| 1628 | printk(KERN_DEBUG "%s: failed to add STA entry for the" |
| 1629 | " AP\n", dev->name); |
| 1630 | return; |
| 1631 | } |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1632 | bss = ieee80211_rx_bss_get(dev, ifsta->bssid, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1633 | local->hw.conf.channel, |
| 1634 | ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1635 | if (bss) { |
| 1636 | sta->last_rssi = bss->rssi; |
| 1637 | sta->last_signal = bss->signal; |
| 1638 | sta->last_noise = bss->noise; |
| 1639 | ieee80211_rx_bss_put(dev, bss); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | sta->dev = dev; |
Johannes Berg | c9ee23d | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 1644 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1645 | |
| 1646 | rates = 0; |
| 1647 | mode = local->oper_hw_mode; |
| 1648 | for (i = 0; i < elems.supp_rates_len; i++) { |
| 1649 | int rate = (elems.supp_rates[i] & 0x7f) * 5; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1650 | for (j = 0; j < mode->num_rates; j++) |
| 1651 | if (mode->rates[j].rate == rate) |
| 1652 | rates |= BIT(j); |
| 1653 | } |
| 1654 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
| 1655 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1656 | for (j = 0; j < mode->num_rates; j++) |
| 1657 | if (mode->rates[j].rate == rate) |
| 1658 | rates |= BIT(j); |
| 1659 | } |
| 1660 | sta->supp_rates = rates; |
| 1661 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1662 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
| 1663 | local->ops->conf_ht) { |
| 1664 | struct ieee80211_ht_bss_info bss_info; |
| 1665 | |
| 1666 | ieee80211_ht_cap_ie_to_ht_info( |
| 1667 | (struct ieee80211_ht_cap *) |
| 1668 | elems.ht_cap_elem, &sta->ht_info); |
| 1669 | ieee80211_ht_addt_info_ie_to_ht_bss_info( |
| 1670 | (struct ieee80211_ht_addt_info *) |
| 1671 | elems.ht_info_elem, &bss_info); |
| 1672 | ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info); |
| 1673 | } |
| 1674 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1675 | rate_control_rate_init(sta, local); |
| 1676 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1677 | if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1678 | sta->flags |= WLAN_STA_WME; |
| 1679 | ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param, |
| 1680 | elems.wmm_param_len); |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | sta_info_put(sta); |
| 1685 | |
| 1686 | ieee80211_associated(dev, ifsta); |
| 1687 | } |
| 1688 | |
| 1689 | |
| 1690 | /* Caller must hold local->sta_bss_lock */ |
| 1691 | static void __ieee80211_rx_bss_hash_add(struct net_device *dev, |
| 1692 | struct ieee80211_sta_bss *bss) |
| 1693 | { |
| 1694 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1695 | bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)]; |
| 1696 | local->sta_bss_hash[STA_HASH(bss->bssid)] = bss; |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | /* Caller must hold local->sta_bss_lock */ |
| 1701 | static void __ieee80211_rx_bss_hash_del(struct net_device *dev, |
| 1702 | struct ieee80211_sta_bss *bss) |
| 1703 | { |
| 1704 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1705 | struct ieee80211_sta_bss *b, *prev = NULL; |
| 1706 | b = local->sta_bss_hash[STA_HASH(bss->bssid)]; |
| 1707 | while (b) { |
| 1708 | if (b == bss) { |
| 1709 | if (!prev) |
| 1710 | local->sta_bss_hash[STA_HASH(bss->bssid)] = |
| 1711 | bss->hnext; |
| 1712 | else |
| 1713 | prev->hnext = bss->hnext; |
| 1714 | break; |
| 1715 | } |
| 1716 | prev = b; |
| 1717 | b = b->hnext; |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | static struct ieee80211_sta_bss * |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1723 | ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel, |
| 1724 | u8 *ssid, u8 ssid_len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1725 | { |
| 1726 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1727 | struct ieee80211_sta_bss *bss; |
| 1728 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1729 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1730 | if (!bss) |
| 1731 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1732 | atomic_inc(&bss->users); |
| 1733 | atomic_inc(&bss->users); |
| 1734 | memcpy(bss->bssid, bssid, ETH_ALEN); |
John W. Linville | 65c107a | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1735 | bss->channel = channel; |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1736 | if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { |
| 1737 | memcpy(bss->ssid, ssid, ssid_len); |
| 1738 | bss->ssid_len = ssid_len; |
| 1739 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1740 | |
| 1741 | spin_lock_bh(&local->sta_bss_lock); |
| 1742 | /* TODO: order by RSSI? */ |
| 1743 | list_add_tail(&bss->list, &local->sta_bss_list); |
| 1744 | __ieee80211_rx_bss_hash_add(dev, bss); |
| 1745 | spin_unlock_bh(&local->sta_bss_lock); |
| 1746 | return bss; |
| 1747 | } |
| 1748 | |
| 1749 | |
| 1750 | static struct ieee80211_sta_bss * |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1751 | ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel, |
| 1752 | u8 *ssid, u8 ssid_len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1753 | { |
| 1754 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1755 | struct ieee80211_sta_bss *bss; |
| 1756 | |
| 1757 | spin_lock_bh(&local->sta_bss_lock); |
| 1758 | bss = local->sta_bss_hash[STA_HASH(bssid)]; |
| 1759 | while (bss) { |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1760 | if (!memcmp(bss->bssid, bssid, ETH_ALEN) && |
| 1761 | bss->channel == channel && |
| 1762 | bss->ssid_len == ssid_len && |
| 1763 | (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1764 | atomic_inc(&bss->users); |
| 1765 | break; |
| 1766 | } |
| 1767 | bss = bss->hnext; |
| 1768 | } |
| 1769 | spin_unlock_bh(&local->sta_bss_lock); |
| 1770 | return bss; |
| 1771 | } |
| 1772 | |
| 1773 | |
| 1774 | static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) |
| 1775 | { |
| 1776 | kfree(bss->wpa_ie); |
| 1777 | kfree(bss->rsn_ie); |
| 1778 | kfree(bss->wmm_ie); |
Ron Rindjunsky | c715350 | 2007-11-26 16:14:31 +0200 | [diff] [blame] | 1779 | kfree(bss->ht_ie); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1780 | kfree(bss); |
| 1781 | } |
| 1782 | |
| 1783 | |
| 1784 | static void ieee80211_rx_bss_put(struct net_device *dev, |
| 1785 | struct ieee80211_sta_bss *bss) |
| 1786 | { |
| 1787 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1788 | if (!atomic_dec_and_test(&bss->users)) |
| 1789 | return; |
| 1790 | |
| 1791 | spin_lock_bh(&local->sta_bss_lock); |
| 1792 | __ieee80211_rx_bss_hash_del(dev, bss); |
| 1793 | list_del(&bss->list); |
| 1794 | spin_unlock_bh(&local->sta_bss_lock); |
| 1795 | ieee80211_rx_bss_free(bss); |
| 1796 | } |
| 1797 | |
| 1798 | |
| 1799 | void ieee80211_rx_bss_list_init(struct net_device *dev) |
| 1800 | { |
| 1801 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1802 | spin_lock_init(&local->sta_bss_lock); |
| 1803 | INIT_LIST_HEAD(&local->sta_bss_list); |
| 1804 | } |
| 1805 | |
| 1806 | |
| 1807 | void ieee80211_rx_bss_list_deinit(struct net_device *dev) |
| 1808 | { |
| 1809 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1810 | struct ieee80211_sta_bss *bss, *tmp; |
| 1811 | |
| 1812 | list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) |
| 1813 | ieee80211_rx_bss_put(dev, bss); |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | static void ieee80211_rx_bss_info(struct net_device *dev, |
| 1818 | struct ieee80211_mgmt *mgmt, |
| 1819 | size_t len, |
| 1820 | struct ieee80211_rx_status *rx_status, |
| 1821 | int beacon) |
| 1822 | { |
| 1823 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1824 | struct ieee802_11_elems elems; |
| 1825 | size_t baselen; |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 1826 | int channel, clen; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1827 | struct ieee80211_sta_bss *bss; |
| 1828 | struct sta_info *sta; |
| 1829 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1830 | u64 timestamp; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1831 | DECLARE_MAC_BUF(mac); |
| 1832 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1833 | |
| 1834 | if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN)) |
| 1835 | return; /* ignore ProbeResp to foreign address */ |
| 1836 | |
| 1837 | #if 0 |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1838 | printk(KERN_DEBUG "%s: RX %s from %s to %s\n", |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1839 | dev->name, beacon ? "Beacon" : "Probe Response", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1840 | print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1841 | #endif |
| 1842 | |
| 1843 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 1844 | if (baselen > len) |
| 1845 | return; |
| 1846 | |
| 1847 | timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); |
| 1848 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1849 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1850 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { |
| 1851 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 1852 | static unsigned long last_tsf_debug = 0; |
| 1853 | u64 tsf; |
| 1854 | if (local->ops->get_tsf) |
| 1855 | tsf = local->ops->get_tsf(local_to_hw(local)); |
| 1856 | else |
| 1857 | tsf = -1LLU; |
| 1858 | if (time_after(jiffies, last_tsf_debug + 5 * HZ)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1859 | printk(KERN_DEBUG "RX beacon SA=%s BSSID=" |
| 1860 | "%s TSF=0x%llx BCN=0x%llx diff=%lld " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1861 | "@%lu\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1862 | print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1863 | (unsigned long long)tsf, |
| 1864 | (unsigned long long)timestamp, |
| 1865 | (unsigned long long)(tsf - timestamp), |
| 1866 | jiffies); |
| 1867 | last_tsf_debug = jiffies; |
| 1868 | } |
| 1869 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 1870 | } |
| 1871 | |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 1872 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1873 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1874 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1875 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 && |
| 1876 | (sta = sta_info_get(local, mgmt->sa))) { |
| 1877 | struct ieee80211_hw_mode *mode; |
| 1878 | struct ieee80211_rate *rates; |
| 1879 | size_t num_rates; |
| 1880 | u32 supp_rates, prev_rates; |
| 1881 | int i, j; |
| 1882 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 1883 | mode = local->sta_sw_scanning ? |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1884 | local->scan_hw_mode : local->oper_hw_mode; |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 1885 | |
| 1886 | if (local->sta_hw_scanning) { |
| 1887 | /* search for the correct mode matches the beacon */ |
| 1888 | list_for_each_entry(mode, &local->modes_list, list) |
| 1889 | if (mode->mode == rx_status->phymode) |
| 1890 | break; |
| 1891 | |
| 1892 | if (mode == NULL) |
| 1893 | mode = local->oper_hw_mode; |
| 1894 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1895 | rates = mode->rates; |
| 1896 | num_rates = mode->num_rates; |
| 1897 | |
| 1898 | supp_rates = 0; |
| 1899 | for (i = 0; i < elems.supp_rates_len + |
| 1900 | elems.ext_supp_rates_len; i++) { |
| 1901 | u8 rate = 0; |
| 1902 | int own_rate; |
| 1903 | if (i < elems.supp_rates_len) |
| 1904 | rate = elems.supp_rates[i]; |
| 1905 | else if (elems.ext_supp_rates) |
| 1906 | rate = elems.ext_supp_rates |
| 1907 | [i - elems.supp_rates_len]; |
| 1908 | own_rate = 5 * (rate & 0x7f); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1909 | for (j = 0; j < num_rates; j++) |
| 1910 | if (rates[j].rate == own_rate) |
| 1911 | supp_rates |= BIT(j); |
| 1912 | } |
| 1913 | |
| 1914 | prev_rates = sta->supp_rates; |
| 1915 | sta->supp_rates &= supp_rates; |
| 1916 | if (sta->supp_rates == 0) { |
| 1917 | /* No matching rates - this should not really happen. |
| 1918 | * Make sure that at least one rate is marked |
| 1919 | * supported to avoid issues with TX rate ctrl. */ |
| 1920 | sta->supp_rates = sdata->u.sta.supp_rates_bits; |
| 1921 | } |
| 1922 | if (sta->supp_rates != prev_rates) { |
| 1923 | printk(KERN_DEBUG "%s: updated supp_rates set for " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1924 | "%s based on beacon info (0x%x & 0x%x -> " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1925 | "0x%x)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1926 | dev->name, print_mac(mac, sta->addr), prev_rates, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1927 | supp_rates, sta->supp_rates); |
| 1928 | } |
| 1929 | sta_info_put(sta); |
| 1930 | } |
| 1931 | |
| 1932 | if (!elems.ssid) |
| 1933 | return; |
| 1934 | |
| 1935 | if (elems.ds_params && elems.ds_params_len == 1) |
| 1936 | channel = elems.ds_params[0]; |
| 1937 | else |
| 1938 | channel = rx_status->channel; |
| 1939 | |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1940 | bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel, |
| 1941 | elems.ssid, elems.ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1942 | if (!bss) { |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1943 | bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel, |
| 1944 | elems.ssid, elems.ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1945 | if (!bss) |
| 1946 | return; |
| 1947 | } else { |
| 1948 | #if 0 |
| 1949 | /* TODO: order by RSSI? */ |
| 1950 | spin_lock_bh(&local->sta_bss_lock); |
| 1951 | list_move_tail(&bss->list, &local->sta_bss_list); |
| 1952 | spin_unlock_bh(&local->sta_bss_lock); |
| 1953 | #endif |
| 1954 | } |
| 1955 | |
| 1956 | if (bss->probe_resp && beacon) { |
| 1957 | /* Do not allow beacon to override data from Probe Response. */ |
| 1958 | ieee80211_rx_bss_put(dev, bss); |
| 1959 | return; |
| 1960 | } |
| 1961 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1962 | /* save the ERP value so that it is available at association time */ |
| 1963 | if (elems.erp_info && elems.erp_info_len >= 1) { |
| 1964 | bss->erp_value = elems.erp_info[0]; |
| 1965 | bss->has_erp_value = 1; |
| 1966 | } |
| 1967 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1968 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); |
| 1969 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1970 | |
| 1971 | bss->supp_rates_len = 0; |
| 1972 | if (elems.supp_rates) { |
| 1973 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 1974 | if (clen > elems.supp_rates_len) |
| 1975 | clen = elems.supp_rates_len; |
| 1976 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates, |
| 1977 | clen); |
| 1978 | bss->supp_rates_len += clen; |
| 1979 | } |
| 1980 | if (elems.ext_supp_rates) { |
| 1981 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 1982 | if (clen > elems.ext_supp_rates_len) |
| 1983 | clen = elems.ext_supp_rates_len; |
| 1984 | memcpy(&bss->supp_rates[bss->supp_rates_len], |
| 1985 | elems.ext_supp_rates, clen); |
| 1986 | bss->supp_rates_len += clen; |
| 1987 | } |
| 1988 | |
| 1989 | if (elems.wpa && |
| 1990 | (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len || |
| 1991 | memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) { |
| 1992 | kfree(bss->wpa_ie); |
| 1993 | bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC); |
| 1994 | if (bss->wpa_ie) { |
| 1995 | memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2); |
| 1996 | bss->wpa_ie_len = elems.wpa_len + 2; |
| 1997 | } else |
| 1998 | bss->wpa_ie_len = 0; |
| 1999 | } else if (!elems.wpa && bss->wpa_ie) { |
| 2000 | kfree(bss->wpa_ie); |
| 2001 | bss->wpa_ie = NULL; |
| 2002 | bss->wpa_ie_len = 0; |
| 2003 | } |
| 2004 | |
| 2005 | if (elems.rsn && |
| 2006 | (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len || |
| 2007 | memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) { |
| 2008 | kfree(bss->rsn_ie); |
| 2009 | bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC); |
| 2010 | if (bss->rsn_ie) { |
| 2011 | memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2); |
| 2012 | bss->rsn_ie_len = elems.rsn_len + 2; |
| 2013 | } else |
| 2014 | bss->rsn_ie_len = 0; |
| 2015 | } else if (!elems.rsn && bss->rsn_ie) { |
| 2016 | kfree(bss->rsn_ie); |
| 2017 | bss->rsn_ie = NULL; |
| 2018 | bss->rsn_ie_len = 0; |
| 2019 | } |
| 2020 | |
| 2021 | if (elems.wmm_param && |
| 2022 | (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len || |
| 2023 | memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) { |
| 2024 | kfree(bss->wmm_ie); |
| 2025 | bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC); |
| 2026 | if (bss->wmm_ie) { |
| 2027 | memcpy(bss->wmm_ie, elems.wmm_param - 2, |
| 2028 | elems.wmm_param_len + 2); |
| 2029 | bss->wmm_ie_len = elems.wmm_param_len + 2; |
| 2030 | } else |
| 2031 | bss->wmm_ie_len = 0; |
| 2032 | } else if (!elems.wmm_param && bss->wmm_ie) { |
| 2033 | kfree(bss->wmm_ie); |
| 2034 | bss->wmm_ie = NULL; |
| 2035 | bss->wmm_ie_len = 0; |
| 2036 | } |
Ron Rindjunsky | c715350 | 2007-11-26 16:14:31 +0200 | [diff] [blame] | 2037 | if (elems.ht_cap_elem && |
| 2038 | (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len || |
| 2039 | memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) { |
| 2040 | kfree(bss->ht_ie); |
| 2041 | bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC); |
| 2042 | if (bss->ht_ie) { |
| 2043 | memcpy(bss->ht_ie, elems.ht_cap_elem - 2, |
| 2044 | elems.ht_cap_elem_len + 2); |
| 2045 | bss->ht_ie_len = elems.ht_cap_elem_len + 2; |
| 2046 | } else |
| 2047 | bss->ht_ie_len = 0; |
| 2048 | } else if (!elems.ht_cap_elem && bss->ht_ie) { |
| 2049 | kfree(bss->ht_ie); |
| 2050 | bss->ht_ie = NULL; |
| 2051 | bss->ht_ie_len = 0; |
| 2052 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2053 | |
| 2054 | bss->hw_mode = rx_status->phymode; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2055 | bss->freq = rx_status->freq; |
| 2056 | if (channel != rx_status->channel && |
| 2057 | (bss->hw_mode == MODE_IEEE80211G || |
| 2058 | bss->hw_mode == MODE_IEEE80211B) && |
| 2059 | channel >= 1 && channel <= 14) { |
| 2060 | static const int freq_list[] = { |
| 2061 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, |
| 2062 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 |
| 2063 | }; |
| 2064 | /* IEEE 802.11g/b mode can receive packets from neighboring |
| 2065 | * channels, so map the channel into frequency. */ |
| 2066 | bss->freq = freq_list[channel - 1]; |
| 2067 | } |
| 2068 | bss->timestamp = timestamp; |
| 2069 | bss->last_update = jiffies; |
| 2070 | bss->rssi = rx_status->ssi; |
| 2071 | bss->signal = rx_status->signal; |
| 2072 | bss->noise = rx_status->noise; |
| 2073 | if (!beacon) |
| 2074 | bss->probe_resp++; |
| 2075 | ieee80211_rx_bss_put(dev, bss); |
| 2076 | } |
| 2077 | |
| 2078 | |
| 2079 | static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev, |
| 2080 | struct ieee80211_mgmt *mgmt, |
| 2081 | size_t len, |
| 2082 | struct ieee80211_rx_status *rx_status) |
| 2083 | { |
| 2084 | ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0); |
| 2085 | } |
| 2086 | |
| 2087 | |
| 2088 | static void ieee80211_rx_mgmt_beacon(struct net_device *dev, |
| 2089 | struct ieee80211_mgmt *mgmt, |
| 2090 | size_t len, |
| 2091 | struct ieee80211_rx_status *rx_status) |
| 2092 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2093 | struct ieee80211_sub_if_data *sdata; |
| 2094 | struct ieee80211_if_sta *ifsta; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2095 | size_t baselen; |
| 2096 | struct ieee802_11_elems elems; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2097 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2098 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2099 | u32 changed = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2100 | |
| 2101 | ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1); |
| 2102 | |
| 2103 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2104 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2105 | return; |
| 2106 | ifsta = &sdata->u.sta; |
| 2107 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2108 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2109 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
| 2110 | return; |
| 2111 | |
| 2112 | /* Process beacon from the current BSS */ |
| 2113 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 2114 | if (baselen > len) |
| 2115 | return; |
| 2116 | |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 2117 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2118 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2119 | if (elems.erp_info && elems.erp_info_len >= 1) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2120 | changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2121 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2122 | if (elems.ht_cap_elem && elems.ht_info_elem && |
| 2123 | elems.wmm_param && local->ops->conf_ht && |
| 2124 | conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
| 2125 | struct ieee80211_ht_bss_info bss_info; |
| 2126 | |
| 2127 | ieee80211_ht_addt_info_ie_to_ht_bss_info( |
| 2128 | (struct ieee80211_ht_addt_info *) |
| 2129 | elems.ht_info_elem, &bss_info); |
| 2130 | /* check if AP changed bss inforamation */ |
| 2131 | if ((conf->ht_bss_conf.primary_channel != |
| 2132 | bss_info.primary_channel) || |
| 2133 | (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) || |
| 2134 | (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode)) |
| 2135 | ieee80211_hw_config_ht(local, 1, &conf->ht_conf, |
| 2136 | &bss_info); |
| 2137 | } |
| 2138 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2139 | if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2140 | ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param, |
| 2141 | elems.wmm_param_len); |
| 2142 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2143 | |
| 2144 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | |
| 2148 | static void ieee80211_rx_mgmt_probe_req(struct net_device *dev, |
| 2149 | struct ieee80211_if_sta *ifsta, |
| 2150 | struct ieee80211_mgmt *mgmt, |
| 2151 | size_t len, |
| 2152 | struct ieee80211_rx_status *rx_status) |
| 2153 | { |
| 2154 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2155 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2156 | int tx_last_beacon; |
| 2157 | struct sk_buff *skb; |
| 2158 | struct ieee80211_mgmt *resp; |
| 2159 | u8 *pos, *end; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2160 | DECLARE_MAC_BUF(mac); |
| 2161 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2162 | DECLARE_MAC_BUF(mac2); |
| 2163 | DECLARE_MAC_BUF(mac3); |
| 2164 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2165 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2166 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2167 | ifsta->state != IEEE80211_IBSS_JOINED || |
| 2168 | len < 24 + 2 || !ifsta->probe_resp) |
| 2169 | return; |
| 2170 | |
| 2171 | if (local->ops->tx_last_beacon) |
| 2172 | tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local)); |
| 2173 | else |
| 2174 | tx_last_beacon = 1; |
| 2175 | |
| 2176 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2177 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID=" |
| 2178 | "%s (tx_last_beacon=%d)\n", |
| 2179 | dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da), |
| 2180 | print_mac(mac3, mgmt->bssid), tx_last_beacon); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2181 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2182 | |
| 2183 | if (!tx_last_beacon) |
| 2184 | return; |
| 2185 | |
| 2186 | if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 && |
| 2187 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
| 2188 | return; |
| 2189 | |
| 2190 | end = ((u8 *) mgmt) + len; |
| 2191 | pos = mgmt->u.probe_req.variable; |
| 2192 | if (pos[0] != WLAN_EID_SSID || |
| 2193 | pos + 2 + pos[1] > end) { |
| 2194 | if (net_ratelimit()) { |
| 2195 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2196 | "from %s\n", |
| 2197 | dev->name, print_mac(mac, mgmt->sa)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2198 | } |
| 2199 | return; |
| 2200 | } |
| 2201 | if (pos[1] != 0 && |
| 2202 | (pos[1] != ifsta->ssid_len || |
| 2203 | memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) { |
| 2204 | /* Ignore ProbeReq for foreign SSID */ |
| 2205 | return; |
| 2206 | } |
| 2207 | |
| 2208 | /* Reply with ProbeResp */ |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2209 | skb = skb_copy(ifsta->probe_resp, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2210 | if (!skb) |
| 2211 | return; |
| 2212 | |
| 2213 | resp = (struct ieee80211_mgmt *) skb->data; |
| 2214 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
| 2215 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2216 | printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n", |
| 2217 | dev->name, print_mac(mac, resp->da)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2218 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2219 | ieee80211_sta_tx(dev, skb, 0); |
| 2220 | } |
| 2221 | |
Johannes Berg | 4e20cb2 | 2007-12-19 01:31:24 +0100 | [diff] [blame] | 2222 | static void ieee80211_rx_mgmt_action(struct net_device *dev, |
| 2223 | struct ieee80211_if_sta *ifsta, |
| 2224 | struct ieee80211_mgmt *mgmt, |
| 2225 | size_t len) |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2226 | { |
| 2227 | if (len < IEEE80211_MIN_ACTION_SIZE) |
| 2228 | return; |
| 2229 | |
| 2230 | switch (mgmt->u.action.category) { |
| 2231 | case WLAN_CATEGORY_BACK: |
| 2232 | switch (mgmt->u.action.u.addba_req.action_code) { |
| 2233 | case WLAN_ACTION_ADDBA_REQ: |
| 2234 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2235 | sizeof(mgmt->u.action.u.addba_req))) |
| 2236 | break; |
| 2237 | ieee80211_sta_process_addba_request(dev, mgmt, len); |
| 2238 | break; |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 2239 | case WLAN_ACTION_DELBA: |
| 2240 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2241 | sizeof(mgmt->u.action.u.delba))) |
| 2242 | break; |
| 2243 | ieee80211_sta_process_delba(dev, mgmt, len); |
| 2244 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2245 | default: |
| 2246 | if (net_ratelimit()) |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 2247 | printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n", |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2248 | dev->name); |
| 2249 | break; |
| 2250 | } |
| 2251 | break; |
| 2252 | default: |
| 2253 | break; |
| 2254 | } |
| 2255 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2256 | |
| 2257 | void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb, |
| 2258 | struct ieee80211_rx_status *rx_status) |
| 2259 | { |
| 2260 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2261 | struct ieee80211_sub_if_data *sdata; |
| 2262 | struct ieee80211_if_sta *ifsta; |
| 2263 | struct ieee80211_mgmt *mgmt; |
| 2264 | u16 fc; |
| 2265 | |
| 2266 | if (skb->len < 24) |
| 2267 | goto fail; |
| 2268 | |
| 2269 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2270 | ifsta = &sdata->u.sta; |
| 2271 | |
| 2272 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 2273 | fc = le16_to_cpu(mgmt->frame_control); |
| 2274 | |
| 2275 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2276 | case IEEE80211_STYPE_PROBE_REQ: |
| 2277 | case IEEE80211_STYPE_PROBE_RESP: |
| 2278 | case IEEE80211_STYPE_BEACON: |
| 2279 | memcpy(skb->cb, rx_status, sizeof(*rx_status)); |
| 2280 | case IEEE80211_STYPE_AUTH: |
| 2281 | case IEEE80211_STYPE_ASSOC_RESP: |
| 2282 | case IEEE80211_STYPE_REASSOC_RESP: |
| 2283 | case IEEE80211_STYPE_DEAUTH: |
| 2284 | case IEEE80211_STYPE_DISASSOC: |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2285 | case IEEE80211_STYPE_ACTION: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2286 | skb_queue_tail(&ifsta->skb_queue, skb); |
| 2287 | queue_work(local->hw.workqueue, &ifsta->work); |
| 2288 | return; |
| 2289 | default: |
| 2290 | printk(KERN_DEBUG "%s: received unknown management frame - " |
| 2291 | "stype=%d\n", dev->name, |
| 2292 | (fc & IEEE80211_FCTL_STYPE) >> 4); |
| 2293 | break; |
| 2294 | } |
| 2295 | |
| 2296 | fail: |
| 2297 | kfree_skb(skb); |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev, |
| 2302 | struct sk_buff *skb) |
| 2303 | { |
| 2304 | struct ieee80211_rx_status *rx_status; |
| 2305 | struct ieee80211_sub_if_data *sdata; |
| 2306 | struct ieee80211_if_sta *ifsta; |
| 2307 | struct ieee80211_mgmt *mgmt; |
| 2308 | u16 fc; |
| 2309 | |
| 2310 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2311 | ifsta = &sdata->u.sta; |
| 2312 | |
| 2313 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 2314 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 2315 | fc = le16_to_cpu(mgmt->frame_control); |
| 2316 | |
| 2317 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2318 | case IEEE80211_STYPE_PROBE_REQ: |
| 2319 | ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len, |
| 2320 | rx_status); |
| 2321 | break; |
| 2322 | case IEEE80211_STYPE_PROBE_RESP: |
| 2323 | ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status); |
| 2324 | break; |
| 2325 | case IEEE80211_STYPE_BEACON: |
| 2326 | ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status); |
| 2327 | break; |
| 2328 | case IEEE80211_STYPE_AUTH: |
| 2329 | ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len); |
| 2330 | break; |
| 2331 | case IEEE80211_STYPE_ASSOC_RESP: |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2332 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2333 | break; |
| 2334 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2335 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2336 | break; |
| 2337 | case IEEE80211_STYPE_DEAUTH: |
| 2338 | ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len); |
| 2339 | break; |
| 2340 | case IEEE80211_STYPE_DISASSOC: |
| 2341 | ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len); |
| 2342 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2343 | case IEEE80211_STYPE_ACTION: |
| 2344 | ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len); |
| 2345 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | kfree_skb(skb); |
| 2349 | } |
| 2350 | |
| 2351 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2352 | ieee80211_txrx_result |
| 2353 | ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb, |
| 2354 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2355 | { |
| 2356 | struct ieee80211_mgmt *mgmt; |
| 2357 | u16 fc; |
| 2358 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2359 | if (skb->len < 2) |
| 2360 | return TXRX_DROP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2361 | |
| 2362 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 2363 | fc = le16_to_cpu(mgmt->frame_control); |
| 2364 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2365 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
| 2366 | return TXRX_CONTINUE; |
| 2367 | |
| 2368 | if (skb->len < 24) |
| 2369 | return TXRX_DROP; |
| 2370 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2371 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2372 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) { |
| 2373 | ieee80211_rx_mgmt_probe_resp(dev, mgmt, |
| 2374 | skb->len, rx_status); |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2375 | dev_kfree_skb(skb); |
| 2376 | return TXRX_QUEUED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2377 | } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) { |
| 2378 | ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, |
| 2379 | rx_status); |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2380 | dev_kfree_skb(skb); |
| 2381 | return TXRX_QUEUED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2382 | } |
| 2383 | } |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2384 | return TXRX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | |
| 2388 | static int ieee80211_sta_active_ibss(struct net_device *dev) |
| 2389 | { |
| 2390 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2391 | int active = 0; |
| 2392 | struct sta_info *sta; |
| 2393 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 2394 | read_lock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2395 | list_for_each_entry(sta, &local->sta_list, list) { |
| 2396 | if (sta->dev == dev && |
| 2397 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
| 2398 | jiffies)) { |
| 2399 | active++; |
| 2400 | break; |
| 2401 | } |
| 2402 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 2403 | read_unlock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2404 | |
| 2405 | return active; |
| 2406 | } |
| 2407 | |
| 2408 | |
| 2409 | static void ieee80211_sta_expire(struct net_device *dev) |
| 2410 | { |
| 2411 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2412 | struct sta_info *sta, *tmp; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 2413 | LIST_HEAD(tmp_list); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2414 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2415 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 2416 | write_lock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2417 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
| 2418 | if (time_after(jiffies, sta->last_rx + |
| 2419 | IEEE80211_IBSS_INACTIVITY_LIMIT)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2420 | printk(KERN_DEBUG "%s: expiring inactive STA %s\n", |
| 2421 | dev->name, print_mac(mac, sta->addr)); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 2422 | __sta_info_get(sta); |
| 2423 | sta_info_remove(sta); |
| 2424 | list_add(&sta->list, &tmp_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2425 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 2426 | write_unlock_bh(&local->sta_lock); |
| 2427 | |
| 2428 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) { |
| 2429 | sta_info_free(sta); |
| 2430 | sta_info_put(sta); |
| 2431 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | |
| 2435 | static void ieee80211_sta_merge_ibss(struct net_device *dev, |
| 2436 | struct ieee80211_if_sta *ifsta) |
| 2437 | { |
| 2438 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 2439 | |
| 2440 | ieee80211_sta_expire(dev); |
| 2441 | if (ieee80211_sta_active_ibss(dev)) |
| 2442 | return; |
| 2443 | |
| 2444 | printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " |
| 2445 | "IBSS networks with same SSID (merge)\n", dev->name); |
| 2446 | ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len); |
| 2447 | } |
| 2448 | |
| 2449 | |
| 2450 | void ieee80211_sta_timer(unsigned long data) |
| 2451 | { |
| 2452 | struct ieee80211_sub_if_data *sdata = |
| 2453 | (struct ieee80211_sub_if_data *) data; |
| 2454 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 2455 | struct ieee80211_local *local = wdev_priv(&sdata->wdev); |
| 2456 | |
| 2457 | set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 2458 | queue_work(local->hw.workqueue, &ifsta->work); |
| 2459 | } |
| 2460 | |
| 2461 | |
| 2462 | void ieee80211_sta_work(struct work_struct *work) |
| 2463 | { |
| 2464 | struct ieee80211_sub_if_data *sdata = |
| 2465 | container_of(work, struct ieee80211_sub_if_data, u.sta.work); |
| 2466 | struct net_device *dev = sdata->dev; |
| 2467 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2468 | struct ieee80211_if_sta *ifsta; |
| 2469 | struct sk_buff *skb; |
| 2470 | |
| 2471 | if (!netif_running(dev)) |
| 2472 | return; |
| 2473 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2474 | if (local->sta_sw_scanning || local->sta_hw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2475 | return; |
| 2476 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2477 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
| 2478 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2479 | printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface " |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2480 | "(type=%d)\n", dev->name, sdata->vif.type); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2481 | return; |
| 2482 | } |
| 2483 | ifsta = &sdata->u.sta; |
| 2484 | |
| 2485 | while ((skb = skb_dequeue(&ifsta->skb_queue))) |
| 2486 | ieee80211_sta_rx_queued_mgmt(dev, skb); |
| 2487 | |
| 2488 | if (ifsta->state != IEEE80211_AUTHENTICATE && |
| 2489 | ifsta->state != IEEE80211_ASSOCIATE && |
| 2490 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { |
Helmut Schaa | a0af5f1 | 2007-11-09 16:25:08 +0100 | [diff] [blame] | 2491 | if (ifsta->scan_ssid_len) |
| 2492 | ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len); |
| 2493 | else |
| 2494 | ieee80211_sta_start_scan(dev, NULL, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2495 | return; |
| 2496 | } |
| 2497 | |
| 2498 | if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) { |
| 2499 | if (ieee80211_sta_config_auth(dev, ifsta)) |
| 2500 | return; |
| 2501 | clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 2502 | } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request)) |
| 2503 | return; |
| 2504 | |
| 2505 | switch (ifsta->state) { |
| 2506 | case IEEE80211_DISABLED: |
| 2507 | break; |
| 2508 | case IEEE80211_AUTHENTICATE: |
| 2509 | ieee80211_authenticate(dev, ifsta); |
| 2510 | break; |
| 2511 | case IEEE80211_ASSOCIATE: |
| 2512 | ieee80211_associate(dev, ifsta); |
| 2513 | break; |
| 2514 | case IEEE80211_ASSOCIATED: |
| 2515 | ieee80211_associated(dev, ifsta); |
| 2516 | break; |
| 2517 | case IEEE80211_IBSS_SEARCH: |
| 2518 | ieee80211_sta_find_ibss(dev, ifsta); |
| 2519 | break; |
| 2520 | case IEEE80211_IBSS_JOINED: |
| 2521 | ieee80211_sta_merge_ibss(dev, ifsta); |
| 2522 | break; |
| 2523 | default: |
| 2524 | printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n", |
| 2525 | ifsta->state); |
| 2526 | break; |
| 2527 | } |
| 2528 | |
| 2529 | if (ieee80211_privacy_mismatch(dev, ifsta)) { |
| 2530 | printk(KERN_DEBUG "%s: privacy configuration mismatch and " |
| 2531 | "mixed-cell disabled - disassociate\n", dev->name); |
| 2532 | |
| 2533 | ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED); |
| 2534 | ieee80211_set_disassoc(dev, ifsta, 0); |
| 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | |
| 2539 | static void ieee80211_sta_reset_auth(struct net_device *dev, |
| 2540 | struct ieee80211_if_sta *ifsta) |
| 2541 | { |
| 2542 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2543 | |
| 2544 | if (local->ops->reset_tsf) { |
| 2545 | /* Reset own TSF to allow time synchronization work. */ |
| 2546 | local->ops->reset_tsf(local_to_hw(local)); |
| 2547 | } |
| 2548 | |
| 2549 | ifsta->wmm_last_param_set = -1; /* allow any WMM update */ |
| 2550 | |
| 2551 | |
| 2552 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 2553 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
| 2554 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 2555 | ifsta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 2556 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 2557 | ifsta->auth_alg = WLAN_AUTH_LEAP; |
| 2558 | else |
| 2559 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
| 2560 | printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name, |
| 2561 | ifsta->auth_alg); |
| 2562 | ifsta->auth_transaction = -1; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2563 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
| 2564 | ifsta->auth_tries = ifsta->assoc_tries = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2565 | netif_carrier_off(dev); |
| 2566 | } |
| 2567 | |
| 2568 | |
| 2569 | void ieee80211_sta_req_auth(struct net_device *dev, |
| 2570 | struct ieee80211_if_sta *ifsta) |
| 2571 | { |
| 2572 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2573 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2574 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2575 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2576 | return; |
| 2577 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2578 | if ((ifsta->flags & (IEEE80211_STA_BSSID_SET | |
| 2579 | IEEE80211_STA_AUTO_BSSID_SEL)) && |
| 2580 | (ifsta->flags & (IEEE80211_STA_SSID_SET | |
| 2581 | IEEE80211_STA_AUTO_SSID_SEL))) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2582 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 2583 | queue_work(local->hw.workqueue, &ifsta->work); |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, |
| 2588 | const char *ssid, int ssid_len) |
| 2589 | { |
| 2590 | int tmp, hidden_ssid; |
| 2591 | |
Michael Wu | 4822570 | 2007-10-19 17:14:36 -0400 | [diff] [blame] | 2592 | if (ssid_len == ifsta->ssid_len && |
| 2593 | !memcmp(ifsta->ssid, ssid, ssid_len)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2594 | return 1; |
| 2595 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2596 | if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2597 | return 0; |
| 2598 | |
| 2599 | hidden_ssid = 1; |
| 2600 | tmp = ssid_len; |
| 2601 | while (tmp--) { |
| 2602 | if (ssid[tmp] != '\0') { |
| 2603 | hidden_ssid = 0; |
| 2604 | break; |
| 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | if (hidden_ssid && ifsta->ssid_len == ssid_len) |
| 2609 | return 1; |
| 2610 | |
| 2611 | if (ssid_len == 1 && ssid[0] == ' ') |
| 2612 | return 1; |
| 2613 | |
| 2614 | return 0; |
| 2615 | } |
| 2616 | |
| 2617 | static int ieee80211_sta_config_auth(struct net_device *dev, |
| 2618 | struct ieee80211_if_sta *ifsta) |
| 2619 | { |
| 2620 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2621 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2622 | struct ieee80211_sta_bss *bss, *selected = NULL; |
| 2623 | int top_rssi = 0, freq; |
| 2624 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2625 | if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL | |
| 2626 | IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2627 | ifsta->state = IEEE80211_AUTHENTICATE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2628 | ieee80211_sta_reset_auth(dev, ifsta); |
| 2629 | return 0; |
| 2630 | } |
| 2631 | |
| 2632 | spin_lock_bh(&local->sta_bss_lock); |
| 2633 | freq = local->oper_channel->freq; |
| 2634 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 2635 | if (!(bss->capability & WLAN_CAPABILITY_ESS)) |
| 2636 | continue; |
| 2637 | |
| 2638 | if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^ |
| 2639 | !!sdata->default_key) |
| 2640 | continue; |
| 2641 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2642 | if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) && |
| 2643 | bss->freq != freq) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2644 | continue; |
| 2645 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2646 | if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2647 | memcmp(bss->bssid, ifsta->bssid, ETH_ALEN)) |
| 2648 | continue; |
| 2649 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2650 | if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2651 | !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len)) |
| 2652 | continue; |
| 2653 | |
| 2654 | if (!selected || top_rssi < bss->rssi) { |
| 2655 | selected = bss; |
| 2656 | top_rssi = bss->rssi; |
| 2657 | } |
| 2658 | } |
| 2659 | if (selected) |
| 2660 | atomic_inc(&selected->users); |
| 2661 | spin_unlock_bh(&local->sta_bss_lock); |
| 2662 | |
| 2663 | if (selected) { |
| 2664 | ieee80211_set_channel(local, -1, selected->freq); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2665 | if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2666 | ieee80211_sta_set_ssid(dev, selected->ssid, |
| 2667 | selected->ssid_len); |
| 2668 | ieee80211_sta_set_bssid(dev, selected->bssid); |
| 2669 | ieee80211_rx_bss_put(dev, selected); |
| 2670 | ifsta->state = IEEE80211_AUTHENTICATE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2671 | ieee80211_sta_reset_auth(dev, ifsta); |
| 2672 | return 0; |
| 2673 | } else { |
| 2674 | if (ifsta->state != IEEE80211_AUTHENTICATE) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2675 | if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) |
John W. Linville | b9bf1e6 | 2007-08-07 16:33:15 -0400 | [diff] [blame] | 2676 | ieee80211_sta_start_scan(dev, NULL, 0); |
| 2677 | else |
| 2678 | ieee80211_sta_start_scan(dev, ifsta->ssid, |
| 2679 | ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2680 | ifsta->state = IEEE80211_AUTHENTICATE; |
| 2681 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 2682 | } else |
| 2683 | ifsta->state = IEEE80211_DISABLED; |
| 2684 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2685 | return -1; |
| 2686 | } |
| 2687 | |
| 2688 | static int ieee80211_sta_join_ibss(struct net_device *dev, |
| 2689 | struct ieee80211_if_sta *ifsta, |
| 2690 | struct ieee80211_sta_bss *bss) |
| 2691 | { |
| 2692 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2693 | int res, rates, i, j; |
| 2694 | struct sk_buff *skb; |
| 2695 | struct ieee80211_mgmt *mgmt; |
| 2696 | struct ieee80211_tx_control control; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2697 | struct ieee80211_hw_mode *mode; |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 2698 | struct rate_selection ratesel; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2699 | u8 *pos; |
| 2700 | struct ieee80211_sub_if_data *sdata; |
| 2701 | |
| 2702 | /* Remove possible STA entries from other IBSS networks. */ |
| 2703 | sta_info_flush(local, NULL); |
| 2704 | |
| 2705 | if (local->ops->reset_tsf) { |
| 2706 | /* Reset own TSF to allow time synchronization work. */ |
| 2707 | local->ops->reset_tsf(local_to_hw(local)); |
| 2708 | } |
| 2709 | memcpy(ifsta->bssid, bss->bssid, ETH_ALEN); |
| 2710 | res = ieee80211_if_config(dev); |
| 2711 | if (res) |
| 2712 | return res; |
| 2713 | |
| 2714 | local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10; |
| 2715 | |
| 2716 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2717 | sdata->drop_unencrypted = bss->capability & |
| 2718 | WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
| 2719 | |
| 2720 | res = ieee80211_set_channel(local, -1, bss->freq); |
| 2721 | |
| 2722 | if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) { |
| 2723 | printk(KERN_DEBUG "%s: IBSS not allowed on channel %d " |
| 2724 | "(%d MHz)\n", dev->name, local->hw.conf.channel, |
| 2725 | local->hw.conf.freq); |
| 2726 | return -1; |
| 2727 | } |
| 2728 | |
| 2729 | /* Set beacon template based on scan results */ |
| 2730 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
| 2731 | do { |
| 2732 | if (!skb) |
| 2733 | break; |
| 2734 | |
| 2735 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 2736 | |
| 2737 | mgmt = (struct ieee80211_mgmt *) |
| 2738 | skb_put(skb, 24 + sizeof(mgmt->u.beacon)); |
| 2739 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); |
| 2740 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 2741 | IEEE80211_STYPE_BEACON); |
| 2742 | memset(mgmt->da, 0xff, ETH_ALEN); |
| 2743 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 2744 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 2745 | mgmt->u.beacon.beacon_int = |
| 2746 | cpu_to_le16(local->hw.conf.beacon_int); |
| 2747 | mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability); |
| 2748 | |
| 2749 | pos = skb_put(skb, 2 + ifsta->ssid_len); |
| 2750 | *pos++ = WLAN_EID_SSID; |
| 2751 | *pos++ = ifsta->ssid_len; |
| 2752 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); |
| 2753 | |
| 2754 | rates = bss->supp_rates_len; |
| 2755 | if (rates > 8) |
| 2756 | rates = 8; |
| 2757 | pos = skb_put(skb, 2 + rates); |
| 2758 | *pos++ = WLAN_EID_SUPP_RATES; |
| 2759 | *pos++ = rates; |
| 2760 | memcpy(pos, bss->supp_rates, rates); |
| 2761 | |
| 2762 | pos = skb_put(skb, 2 + 1); |
| 2763 | *pos++ = WLAN_EID_DS_PARAMS; |
| 2764 | *pos++ = 1; |
| 2765 | *pos++ = bss->channel; |
| 2766 | |
| 2767 | pos = skb_put(skb, 2 + 2); |
| 2768 | *pos++ = WLAN_EID_IBSS_PARAMS; |
| 2769 | *pos++ = 2; |
| 2770 | /* FIX: set ATIM window based on scan results */ |
| 2771 | *pos++ = 0; |
| 2772 | *pos++ = 0; |
| 2773 | |
| 2774 | if (bss->supp_rates_len > 8) { |
| 2775 | rates = bss->supp_rates_len - 8; |
| 2776 | pos = skb_put(skb, 2 + rates); |
| 2777 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 2778 | *pos++ = rates; |
| 2779 | memcpy(pos, &bss->supp_rates[8], rates); |
| 2780 | } |
| 2781 | |
| 2782 | memset(&control, 0, sizeof(control)); |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 2783 | rate_control_get_rate(dev, local->oper_hw_mode, skb, &ratesel); |
| 2784 | if (!ratesel.rate) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2785 | printk(KERN_DEBUG "%s: Failed to determine TX rate " |
| 2786 | "for IBSS beacon\n", dev->name); |
| 2787 | break; |
| 2788 | } |
Ivo van Doorn | 0f7054e | 2008-01-13 14:16:47 +0100 | [diff] [blame] | 2789 | control.vif = &sdata->vif; |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2790 | control.tx_rate = |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2791 | (sdata->bss_conf.use_short_preamble && |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 2792 | (ratesel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ? |
| 2793 | ratesel.rate->val2 : ratesel.rate->val; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2794 | control.antenna_sel_tx = local->hw.conf.antenna_sel_tx; |
| 2795 | control.power_level = local->hw.conf.power_level; |
| 2796 | control.flags |= IEEE80211_TXCTL_NO_ACK; |
| 2797 | control.retry_limit = 1; |
| 2798 | |
| 2799 | ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC); |
| 2800 | if (ifsta->probe_resp) { |
| 2801 | mgmt = (struct ieee80211_mgmt *) |
| 2802 | ifsta->probe_resp->data; |
| 2803 | mgmt->frame_control = |
| 2804 | IEEE80211_FC(IEEE80211_FTYPE_MGMT, |
| 2805 | IEEE80211_STYPE_PROBE_RESP); |
| 2806 | } else { |
| 2807 | printk(KERN_DEBUG "%s: Could not allocate ProbeResp " |
| 2808 | "template for IBSS\n", dev->name); |
| 2809 | } |
| 2810 | |
| 2811 | if (local->ops->beacon_update && |
| 2812 | local->ops->beacon_update(local_to_hw(local), |
| 2813 | skb, &control) == 0) { |
| 2814 | printk(KERN_DEBUG "%s: Configured IBSS beacon " |
| 2815 | "template based on scan results\n", dev->name); |
| 2816 | skb = NULL; |
| 2817 | } |
| 2818 | |
| 2819 | rates = 0; |
| 2820 | mode = local->oper_hw_mode; |
| 2821 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 2822 | int bitrate = (bss->supp_rates[i] & 0x7f) * 5; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2823 | for (j = 0; j < mode->num_rates; j++) |
| 2824 | if (mode->rates[j].rate == bitrate) |
| 2825 | rates |= BIT(j); |
| 2826 | } |
| 2827 | ifsta->supp_rates_bits = rates; |
| 2828 | } while (0); |
| 2829 | |
| 2830 | if (skb) { |
| 2831 | printk(KERN_DEBUG "%s: Failed to configure IBSS beacon " |
| 2832 | "template\n", dev->name); |
| 2833 | dev_kfree_skb(skb); |
| 2834 | } |
| 2835 | |
| 2836 | ifsta->state = IEEE80211_IBSS_JOINED; |
| 2837 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 2838 | |
| 2839 | ieee80211_rx_bss_put(dev, bss); |
| 2840 | |
| 2841 | return res; |
| 2842 | } |
| 2843 | |
| 2844 | |
| 2845 | static int ieee80211_sta_create_ibss(struct net_device *dev, |
| 2846 | struct ieee80211_if_sta *ifsta) |
| 2847 | { |
| 2848 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2849 | struct ieee80211_sta_bss *bss; |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 2850 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2851 | struct ieee80211_hw_mode *mode; |
| 2852 | u8 bssid[ETH_ALEN], *pos; |
| 2853 | int i; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2854 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2855 | |
| 2856 | #if 0 |
| 2857 | /* Easier testing, use fixed BSSID. */ |
| 2858 | memset(bssid, 0xfe, ETH_ALEN); |
| 2859 | #else |
| 2860 | /* Generate random, not broadcast, locally administered BSSID. Mix in |
| 2861 | * own MAC address to make sure that devices that do not have proper |
| 2862 | * random number generator get different BSSID. */ |
| 2863 | get_random_bytes(bssid, ETH_ALEN); |
| 2864 | for (i = 0; i < ETH_ALEN; i++) |
| 2865 | bssid[i] ^= dev->dev_addr[i]; |
| 2866 | bssid[0] &= ~0x01; |
| 2867 | bssid[0] |= 0x02; |
| 2868 | #endif |
| 2869 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2870 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", |
| 2871 | dev->name, print_mac(mac, bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2872 | |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 2873 | bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel, |
| 2874 | sdata->u.sta.ssid, sdata->u.sta.ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2875 | if (!bss) |
| 2876 | return -ENOMEM; |
| 2877 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2878 | mode = local->oper_hw_mode; |
| 2879 | |
| 2880 | if (local->hw.conf.beacon_int == 0) |
| 2881 | local->hw.conf.beacon_int = 100; |
| 2882 | bss->beacon_int = local->hw.conf.beacon_int; |
| 2883 | bss->hw_mode = local->hw.conf.phymode; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2884 | bss->freq = local->hw.conf.freq; |
| 2885 | bss->last_update = jiffies; |
| 2886 | bss->capability = WLAN_CAPABILITY_IBSS; |
| 2887 | if (sdata->default_key) { |
| 2888 | bss->capability |= WLAN_CAPABILITY_PRIVACY; |
| 2889 | } else |
| 2890 | sdata->drop_unencrypted = 0; |
| 2891 | bss->supp_rates_len = mode->num_rates; |
| 2892 | pos = bss->supp_rates; |
| 2893 | for (i = 0; i < mode->num_rates; i++) { |
| 2894 | int rate = mode->rates[i].rate; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2895 | *pos++ = (u8) (rate / 5); |
| 2896 | } |
| 2897 | |
| 2898 | return ieee80211_sta_join_ibss(dev, ifsta, bss); |
| 2899 | } |
| 2900 | |
| 2901 | |
| 2902 | static int ieee80211_sta_find_ibss(struct net_device *dev, |
| 2903 | struct ieee80211_if_sta *ifsta) |
| 2904 | { |
| 2905 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2906 | struct ieee80211_sta_bss *bss; |
| 2907 | int found = 0; |
| 2908 | u8 bssid[ETH_ALEN]; |
| 2909 | int active_ibss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2910 | DECLARE_MAC_BUF(mac); |
| 2911 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2912 | |
| 2913 | if (ifsta->ssid_len == 0) |
| 2914 | return -EINVAL; |
| 2915 | |
| 2916 | active_ibss = ieee80211_sta_active_ibss(dev); |
| 2917 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2918 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", |
| 2919 | dev->name, active_ibss); |
| 2920 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2921 | spin_lock_bh(&local->sta_bss_lock); |
| 2922 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 2923 | if (ifsta->ssid_len != bss->ssid_len || |
| 2924 | memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 |
| 2925 | || !(bss->capability & WLAN_CAPABILITY_IBSS)) |
| 2926 | continue; |
| 2927 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2928 | printk(KERN_DEBUG " bssid=%s found\n", |
| 2929 | print_mac(mac, bss->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2930 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2931 | memcpy(bssid, bss->bssid, ETH_ALEN); |
| 2932 | found = 1; |
| 2933 | if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) |
| 2934 | break; |
| 2935 | } |
| 2936 | spin_unlock_bh(&local->sta_bss_lock); |
| 2937 | |
| 2938 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2939 | printk(KERN_DEBUG " sta_find_ibss: selected %s current " |
| 2940 | "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2941 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2942 | if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 && |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 2943 | (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel, |
| 2944 | ifsta->ssid, ifsta->ssid_len))) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2945 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2946 | " based on configured SSID\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2947 | dev->name, print_mac(mac, bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2948 | return ieee80211_sta_join_ibss(dev, ifsta, bss); |
| 2949 | } |
| 2950 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2951 | printk(KERN_DEBUG " did not try to join ibss\n"); |
| 2952 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2953 | |
| 2954 | /* Selected IBSS not found in current scan results - try to scan */ |
| 2955 | if (ifsta->state == IEEE80211_IBSS_JOINED && |
| 2956 | !ieee80211_sta_active_ibss(dev)) { |
| 2957 | mod_timer(&ifsta->timer, jiffies + |
| 2958 | IEEE80211_IBSS_MERGE_INTERVAL); |
| 2959 | } else if (time_after(jiffies, local->last_scan_completed + |
| 2960 | IEEE80211_SCAN_INTERVAL)) { |
| 2961 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " |
| 2962 | "join\n", dev->name); |
| 2963 | return ieee80211_sta_req_scan(dev, ifsta->ssid, |
| 2964 | ifsta->ssid_len); |
| 2965 | } else if (ifsta->state != IEEE80211_IBSS_JOINED) { |
| 2966 | int interval = IEEE80211_SCAN_INTERVAL; |
| 2967 | |
| 2968 | if (time_after(jiffies, ifsta->ibss_join_req + |
| 2969 | IEEE80211_IBSS_JOIN_TIMEOUT)) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2970 | if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2971 | local->oper_channel->flag & IEEE80211_CHAN_W_IBSS) |
| 2972 | return ieee80211_sta_create_ibss(dev, ifsta); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2973 | if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2974 | printk(KERN_DEBUG "%s: IBSS not allowed on the" |
| 2975 | " configured channel %d (%d MHz)\n", |
| 2976 | dev->name, local->hw.conf.channel, |
| 2977 | local->hw.conf.freq); |
| 2978 | } |
| 2979 | |
| 2980 | /* No IBSS found - decrease scan interval and continue |
| 2981 | * scanning. */ |
| 2982 | interval = IEEE80211_SCAN_INTERVAL_SLOW; |
| 2983 | } |
| 2984 | |
| 2985 | ifsta->state = IEEE80211_IBSS_SEARCH; |
| 2986 | mod_timer(&ifsta->timer, jiffies + interval); |
| 2987 | return 0; |
| 2988 | } |
| 2989 | |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
| 2993 | |
| 2994 | int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len) |
| 2995 | { |
| 2996 | struct ieee80211_sub_if_data *sdata; |
| 2997 | struct ieee80211_if_sta *ifsta; |
| 2998 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 2999 | |
| 3000 | if (len > IEEE80211_MAX_SSID_LEN) |
| 3001 | return -EINVAL; |
| 3002 | |
| 3003 | /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is |
| 3004 | * not defined. */ |
| 3005 | if (local->ops->conf_tx) { |
| 3006 | struct ieee80211_tx_queue_params qparam; |
| 3007 | int i; |
| 3008 | |
| 3009 | memset(&qparam, 0, sizeof(qparam)); |
| 3010 | /* TODO: are these ok defaults for all hw_modes? */ |
| 3011 | qparam.aifs = 2; |
| 3012 | qparam.cw_min = |
| 3013 | local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15; |
| 3014 | qparam.cw_max = 1023; |
| 3015 | qparam.burst_time = 0; |
| 3016 | for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++) |
| 3017 | { |
| 3018 | local->ops->conf_tx(local_to_hw(local), |
| 3019 | i + IEEE80211_TX_QUEUE_DATA0, |
| 3020 | &qparam); |
| 3021 | } |
| 3022 | /* IBSS uses different parameters for Beacon sending */ |
| 3023 | qparam.cw_min++; |
| 3024 | qparam.cw_min *= 2; |
| 3025 | qparam.cw_min--; |
| 3026 | local->ops->conf_tx(local_to_hw(local), |
| 3027 | IEEE80211_TX_QUEUE_BEACON, &qparam); |
| 3028 | } |
| 3029 | |
| 3030 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3031 | ifsta = &sdata->u.sta; |
| 3032 | |
| 3033 | if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3034 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3035 | memcpy(ifsta->ssid, ssid, len); |
| 3036 | memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len); |
| 3037 | ifsta->ssid_len = len; |
| 3038 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3039 | if (len) |
| 3040 | ifsta->flags |= IEEE80211_STA_SSID_SET; |
| 3041 | else |
| 3042 | ifsta->flags &= ~IEEE80211_STA_SSID_SET; |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3043 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3044 | !(ifsta->flags & IEEE80211_STA_BSSID_SET)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3045 | ifsta->ibss_join_req = jiffies; |
| 3046 | ifsta->state = IEEE80211_IBSS_SEARCH; |
| 3047 | return ieee80211_sta_find_ibss(dev, ifsta); |
| 3048 | } |
| 3049 | return 0; |
| 3050 | } |
| 3051 | |
| 3052 | |
| 3053 | int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len) |
| 3054 | { |
| 3055 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3056 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3057 | memcpy(ssid, ifsta->ssid, ifsta->ssid_len); |
| 3058 | *len = ifsta->ssid_len; |
| 3059 | return 0; |
| 3060 | } |
| 3061 | |
| 3062 | |
| 3063 | int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid) |
| 3064 | { |
| 3065 | struct ieee80211_sub_if_data *sdata; |
| 3066 | struct ieee80211_if_sta *ifsta; |
| 3067 | int res; |
| 3068 | |
| 3069 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3070 | ifsta = &sdata->u.sta; |
| 3071 | |
| 3072 | if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { |
| 3073 | memcpy(ifsta->bssid, bssid, ETH_ALEN); |
| 3074 | res = ieee80211_if_config(dev); |
| 3075 | if (res) { |
| 3076 | printk(KERN_DEBUG "%s: Failed to config new BSSID to " |
| 3077 | "the low-level driver\n", dev->name); |
| 3078 | return res; |
| 3079 | } |
| 3080 | } |
| 3081 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3082 | if (is_valid_ether_addr(bssid)) |
| 3083 | ifsta->flags |= IEEE80211_STA_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3084 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3085 | ifsta->flags &= ~IEEE80211_STA_BSSID_SET; |
| 3086 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3087 | return 0; |
| 3088 | } |
| 3089 | |
| 3090 | |
| 3091 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 3092 | struct ieee80211_sub_if_data *sdata, |
| 3093 | int powersave) |
| 3094 | { |
| 3095 | struct sk_buff *skb; |
| 3096 | struct ieee80211_hdr *nullfunc; |
| 3097 | u16 fc; |
| 3098 | |
| 3099 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); |
| 3100 | if (!skb) { |
| 3101 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " |
| 3102 | "frame\n", sdata->dev->name); |
| 3103 | return; |
| 3104 | } |
| 3105 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 3106 | |
| 3107 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); |
| 3108 | memset(nullfunc, 0, 24); |
| 3109 | fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 3110 | IEEE80211_FCTL_TODS; |
| 3111 | if (powersave) |
| 3112 | fc |= IEEE80211_FCTL_PM; |
| 3113 | nullfunc->frame_control = cpu_to_le16(fc); |
| 3114 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); |
| 3115 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); |
| 3116 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); |
| 3117 | |
| 3118 | ieee80211_sta_tx(sdata->dev, skb, 0); |
| 3119 | } |
| 3120 | |
| 3121 | |
| 3122 | void ieee80211_scan_completed(struct ieee80211_hw *hw) |
| 3123 | { |
| 3124 | struct ieee80211_local *local = hw_to_local(hw); |
| 3125 | struct net_device *dev = local->scan_dev; |
| 3126 | struct ieee80211_sub_if_data *sdata; |
| 3127 | union iwreq_data wrqu; |
| 3128 | |
| 3129 | local->last_scan_completed = jiffies; |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3130 | memset(&wrqu, 0, sizeof(wrqu)); |
| 3131 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3132 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3133 | if (local->sta_hw_scanning) { |
| 3134 | local->sta_hw_scanning = 0; |
| 3135 | goto done; |
| 3136 | } |
| 3137 | |
| 3138 | local->sta_sw_scanning = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3139 | if (ieee80211_hw_config(local)) |
Bruno Randolf | 4b50e38 | 2007-11-16 17:04:01 +0900 | [diff] [blame] | 3140 | printk(KERN_DEBUG "%s: failed to restore operational " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3141 | "channel after scan\n", dev->name); |
| 3142 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3143 | |
| 3144 | netif_tx_lock_bh(local->mdev); |
| 3145 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; |
| 3146 | local->ops->configure_filter(local_to_hw(local), |
| 3147 | FIF_BCN_PRBRESP_PROMISC, |
| 3148 | &local->filter_flags, |
| 3149 | local->mdev->mc_count, |
| 3150 | local->mdev->mc_list); |
| 3151 | |
| 3152 | netif_tx_unlock_bh(local->mdev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3153 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3154 | rcu_read_lock(); |
| 3155 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Mattias Nissler | 14042cbe | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 3156 | |
| 3157 | /* No need to wake the master device. */ |
| 3158 | if (sdata->dev == local->mdev) |
| 3159 | continue; |
| 3160 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3161 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3162 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3163 | ieee80211_send_nullfunc(local, sdata, 0); |
| 3164 | ieee80211_sta_timer((unsigned long)sdata); |
| 3165 | } |
Mattias Nissler | 14042cbe | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 3166 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3167 | netif_wake_queue(sdata->dev); |
| 3168 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3169 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3170 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3171 | done: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3172 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3173 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3174 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3175 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3176 | (!ifsta->state == IEEE80211_IBSS_JOINED && |
| 3177 | !ieee80211_sta_active_ibss(dev))) |
| 3178 | ieee80211_sta_find_ibss(dev, ifsta); |
| 3179 | } |
| 3180 | } |
| 3181 | EXPORT_SYMBOL(ieee80211_scan_completed); |
| 3182 | |
| 3183 | void ieee80211_sta_scan_work(struct work_struct *work) |
| 3184 | { |
| 3185 | struct ieee80211_local *local = |
| 3186 | container_of(work, struct ieee80211_local, scan_work.work); |
| 3187 | struct net_device *dev = local->scan_dev; |
| 3188 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3189 | struct ieee80211_hw_mode *mode; |
| 3190 | struct ieee80211_channel *chan; |
| 3191 | int skip; |
| 3192 | unsigned long next_delay = 0; |
| 3193 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3194 | if (!local->sta_sw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3195 | return; |
| 3196 | |
| 3197 | switch (local->scan_state) { |
| 3198 | case SCAN_SET_CHANNEL: |
| 3199 | mode = local->scan_hw_mode; |
| 3200 | if (local->scan_hw_mode->list.next == &local->modes_list && |
| 3201 | local->scan_channel_idx >= mode->num_channels) { |
| 3202 | ieee80211_scan_completed(local_to_hw(local)); |
| 3203 | return; |
| 3204 | } |
| 3205 | skip = !(local->enabled_modes & (1 << mode->mode)); |
| 3206 | chan = &mode->channels[local->scan_channel_idx]; |
| 3207 | if (!(chan->flag & IEEE80211_CHAN_W_SCAN) || |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3208 | (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3209 | !(chan->flag & IEEE80211_CHAN_W_IBSS)) || |
| 3210 | (local->hw_modes & local->enabled_modes & |
| 3211 | (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B)) |
| 3212 | skip = 1; |
| 3213 | |
| 3214 | if (!skip) { |
| 3215 | #if 0 |
| 3216 | printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n", |
| 3217 | dev->name, chan->chan, chan->freq); |
| 3218 | #endif |
| 3219 | |
| 3220 | local->scan_channel = chan; |
| 3221 | if (ieee80211_hw_config(local)) { |
| 3222 | printk(KERN_DEBUG "%s: failed to set channel " |
| 3223 | "%d (%d MHz) for scan\n", dev->name, |
| 3224 | chan->chan, chan->freq); |
| 3225 | skip = 1; |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | local->scan_channel_idx++; |
| 3230 | if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) { |
| 3231 | if (local->scan_hw_mode->list.next != &local->modes_list) { |
| 3232 | local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next, |
| 3233 | struct ieee80211_hw_mode, |
| 3234 | list); |
| 3235 | local->scan_channel_idx = 0; |
| 3236 | } |
| 3237 | } |
| 3238 | |
| 3239 | if (skip) |
| 3240 | break; |
| 3241 | |
| 3242 | next_delay = IEEE80211_PROBE_DELAY + |
| 3243 | usecs_to_jiffies(local->hw.channel_change_time); |
| 3244 | local->scan_state = SCAN_SEND_PROBE; |
| 3245 | break; |
| 3246 | case SCAN_SEND_PROBE: |
| 3247 | if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) { |
| 3248 | ieee80211_send_probe_req(dev, NULL, local->scan_ssid, |
| 3249 | local->scan_ssid_len); |
| 3250 | next_delay = IEEE80211_CHANNEL_TIME; |
| 3251 | } else |
| 3252 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; |
| 3253 | local->scan_state = SCAN_SET_CHANNEL; |
| 3254 | break; |
| 3255 | } |
| 3256 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3257 | if (local->sta_sw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3258 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 3259 | next_delay); |
| 3260 | } |
| 3261 | |
| 3262 | |
| 3263 | static int ieee80211_sta_start_scan(struct net_device *dev, |
| 3264 | u8 *ssid, size_t ssid_len) |
| 3265 | { |
| 3266 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 3267 | struct ieee80211_sub_if_data *sdata; |
| 3268 | |
| 3269 | if (ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3270 | return -EINVAL; |
| 3271 | |
| 3272 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) |
| 3273 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS |
| 3274 | * BSSID: MACAddress |
| 3275 | * SSID |
| 3276 | * ScanType: ACTIVE, PASSIVE |
| 3277 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting |
| 3278 | * a Probe frame during active scanning |
| 3279 | * ChannelList |
| 3280 | * MinChannelTime (>= ProbeDelay), in TU |
| 3281 | * MaxChannelTime: (>= MinChannelTime), in TU |
| 3282 | */ |
| 3283 | |
| 3284 | /* MLME-SCAN.confirm |
| 3285 | * BSSDescriptionSet |
| 3286 | * ResultCode: SUCCESS, INVALID_PARAMETERS |
| 3287 | */ |
| 3288 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3289 | if (local->sta_sw_scanning || local->sta_hw_scanning) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3290 | if (local->scan_dev == dev) |
| 3291 | return 0; |
| 3292 | return -EBUSY; |
| 3293 | } |
| 3294 | |
| 3295 | if (local->ops->hw_scan) { |
| 3296 | int rc = local->ops->hw_scan(local_to_hw(local), |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3297 | ssid, ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3298 | if (!rc) { |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3299 | local->sta_hw_scanning = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3300 | local->scan_dev = dev; |
| 3301 | } |
| 3302 | return rc; |
| 3303 | } |
| 3304 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3305 | local->sta_sw_scanning = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3306 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3307 | rcu_read_lock(); |
| 3308 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Mattias Nissler | 14042cbe | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 3309 | |
| 3310 | /* Don't stop the master interface, otherwise we can't transmit |
| 3311 | * probes! */ |
| 3312 | if (sdata->dev == local->mdev) |
| 3313 | continue; |
| 3314 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3315 | netif_stop_queue(sdata->dev); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3316 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA && |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3317 | (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3318 | ieee80211_send_nullfunc(local, sdata, 1); |
| 3319 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3320 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3321 | |
| 3322 | if (ssid) { |
| 3323 | local->scan_ssid_len = ssid_len; |
| 3324 | memcpy(local->scan_ssid, ssid, ssid_len); |
| 3325 | } else |
| 3326 | local->scan_ssid_len = 0; |
| 3327 | local->scan_state = SCAN_SET_CHANNEL; |
| 3328 | local->scan_hw_mode = list_entry(local->modes_list.next, |
| 3329 | struct ieee80211_hw_mode, |
| 3330 | list); |
| 3331 | local->scan_channel_idx = 0; |
| 3332 | local->scan_dev = dev; |
| 3333 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3334 | netif_tx_lock_bh(local->mdev); |
| 3335 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; |
| 3336 | local->ops->configure_filter(local_to_hw(local), |
| 3337 | FIF_BCN_PRBRESP_PROMISC, |
| 3338 | &local->filter_flags, |
| 3339 | local->mdev->mc_count, |
| 3340 | local->mdev->mc_list); |
| 3341 | netif_tx_unlock_bh(local->mdev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3342 | |
| 3343 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ |
| 3344 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 3345 | IEEE80211_CHANNEL_TIME); |
| 3346 | |
| 3347 | return 0; |
| 3348 | } |
| 3349 | |
| 3350 | |
| 3351 | int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len) |
| 3352 | { |
| 3353 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3354 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3355 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 3356 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3357 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3358 | return ieee80211_sta_start_scan(dev, ssid, ssid_len); |
| 3359 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3360 | if (local->sta_sw_scanning || local->sta_hw_scanning) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3361 | if (local->scan_dev == dev) |
| 3362 | return 0; |
| 3363 | return -EBUSY; |
| 3364 | } |
| 3365 | |
Helmut Schaa | a0af5f1 | 2007-11-09 16:25:08 +0100 | [diff] [blame] | 3366 | ifsta->scan_ssid_len = ssid_len; |
| 3367 | if (ssid_len) |
| 3368 | memcpy(ifsta->scan_ssid, ssid, ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3369 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); |
| 3370 | queue_work(local->hw.workqueue, &ifsta->work); |
| 3371 | return 0; |
| 3372 | } |
| 3373 | |
| 3374 | static char * |
| 3375 | ieee80211_sta_scan_result(struct net_device *dev, |
| 3376 | struct ieee80211_sta_bss *bss, |
| 3377 | char *current_ev, char *end_buf) |
| 3378 | { |
| 3379 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 3380 | struct iw_event iwe; |
| 3381 | |
| 3382 | if (time_after(jiffies, |
| 3383 | bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) |
| 3384 | return current_ev; |
| 3385 | |
| 3386 | if (!(local->enabled_modes & (1 << bss->hw_mode))) |
| 3387 | return current_ev; |
| 3388 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3389 | memset(&iwe, 0, sizeof(iwe)); |
| 3390 | iwe.cmd = SIOCGIWAP; |
| 3391 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 3392 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
| 3393 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 3394 | IW_EV_ADDR_LEN); |
| 3395 | |
| 3396 | memset(&iwe, 0, sizeof(iwe)); |
| 3397 | iwe.cmd = SIOCGIWESSID; |
| 3398 | iwe.u.data.length = bss->ssid_len; |
| 3399 | iwe.u.data.flags = 1; |
| 3400 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 3401 | bss->ssid); |
| 3402 | |
| 3403 | if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) { |
| 3404 | memset(&iwe, 0, sizeof(iwe)); |
| 3405 | iwe.cmd = SIOCGIWMODE; |
| 3406 | if (bss->capability & WLAN_CAPABILITY_ESS) |
| 3407 | iwe.u.mode = IW_MODE_MASTER; |
| 3408 | else |
| 3409 | iwe.u.mode = IW_MODE_ADHOC; |
| 3410 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 3411 | IW_EV_UINT_LEN); |
| 3412 | } |
| 3413 | |
| 3414 | memset(&iwe, 0, sizeof(iwe)); |
| 3415 | iwe.cmd = SIOCGIWFREQ; |
| 3416 | iwe.u.freq.m = bss->channel; |
| 3417 | iwe.u.freq.e = 0; |
| 3418 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 3419 | IW_EV_FREQ_LEN); |
| 3420 | iwe.u.freq.m = bss->freq * 100000; |
| 3421 | iwe.u.freq.e = 1; |
| 3422 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 3423 | IW_EV_FREQ_LEN); |
| 3424 | |
| 3425 | memset(&iwe, 0, sizeof(iwe)); |
| 3426 | iwe.cmd = IWEVQUAL; |
| 3427 | iwe.u.qual.qual = bss->signal; |
| 3428 | iwe.u.qual.level = bss->rssi; |
| 3429 | iwe.u.qual.noise = bss->noise; |
| 3430 | iwe.u.qual.updated = local->wstats_flags; |
| 3431 | current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 3432 | IW_EV_QUAL_LEN); |
| 3433 | |
| 3434 | memset(&iwe, 0, sizeof(iwe)); |
| 3435 | iwe.cmd = SIOCGIWENCODE; |
| 3436 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
| 3437 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 3438 | else |
| 3439 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 3440 | iwe.u.data.length = 0; |
| 3441 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ""); |
| 3442 | |
| 3443 | if (bss && bss->wpa_ie) { |
| 3444 | memset(&iwe, 0, sizeof(iwe)); |
| 3445 | iwe.cmd = IWEVGENIE; |
| 3446 | iwe.u.data.length = bss->wpa_ie_len; |
| 3447 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 3448 | bss->wpa_ie); |
| 3449 | } |
| 3450 | |
| 3451 | if (bss && bss->rsn_ie) { |
| 3452 | memset(&iwe, 0, sizeof(iwe)); |
| 3453 | iwe.cmd = IWEVGENIE; |
| 3454 | iwe.u.data.length = bss->rsn_ie_len; |
| 3455 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, |
| 3456 | bss->rsn_ie); |
| 3457 | } |
| 3458 | |
| 3459 | if (bss && bss->supp_rates_len > 0) { |
| 3460 | /* display all supported rates in readable format */ |
| 3461 | char *p = current_ev + IW_EV_LCP_LEN; |
| 3462 | int i; |
| 3463 | |
| 3464 | memset(&iwe, 0, sizeof(iwe)); |
| 3465 | iwe.cmd = SIOCGIWRATE; |
| 3466 | /* Those two flags are ignored... */ |
| 3467 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; |
| 3468 | |
| 3469 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 3470 | iwe.u.bitrate.value = ((bss->supp_rates[i] & |
| 3471 | 0x7f) * 500000); |
| 3472 | p = iwe_stream_add_value(current_ev, p, |
| 3473 | end_buf, &iwe, IW_EV_PARAM_LEN); |
| 3474 | } |
| 3475 | current_ev = p; |
| 3476 | } |
| 3477 | |
| 3478 | if (bss) { |
| 3479 | char *buf; |
| 3480 | buf = kmalloc(30, GFP_ATOMIC); |
| 3481 | if (buf) { |
| 3482 | memset(&iwe, 0, sizeof(iwe)); |
| 3483 | iwe.cmd = IWEVCUSTOM; |
| 3484 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); |
| 3485 | iwe.u.data.length = strlen(buf); |
| 3486 | current_ev = iwe_stream_add_point(current_ev, end_buf, |
| 3487 | &iwe, buf); |
| 3488 | kfree(buf); |
| 3489 | } |
| 3490 | } |
| 3491 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3492 | return current_ev; |
| 3493 | } |
| 3494 | |
| 3495 | |
| 3496 | int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len) |
| 3497 | { |
| 3498 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 3499 | char *current_ev = buf; |
| 3500 | char *end_buf = buf + len; |
| 3501 | struct ieee80211_sta_bss *bss; |
| 3502 | |
| 3503 | spin_lock_bh(&local->sta_bss_lock); |
| 3504 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 3505 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { |
| 3506 | spin_unlock_bh(&local->sta_bss_lock); |
| 3507 | return -E2BIG; |
| 3508 | } |
| 3509 | current_ev = ieee80211_sta_scan_result(dev, bss, current_ev, |
| 3510 | end_buf); |
| 3511 | } |
| 3512 | spin_unlock_bh(&local->sta_bss_lock); |
| 3513 | return current_ev - buf; |
| 3514 | } |
| 3515 | |
| 3516 | |
| 3517 | int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len) |
| 3518 | { |
| 3519 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3520 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3521 | kfree(ifsta->extra_ie); |
| 3522 | if (len == 0) { |
| 3523 | ifsta->extra_ie = NULL; |
| 3524 | ifsta->extra_ie_len = 0; |
| 3525 | return 0; |
| 3526 | } |
| 3527 | ifsta->extra_ie = kmalloc(len, GFP_KERNEL); |
| 3528 | if (!ifsta->extra_ie) { |
| 3529 | ifsta->extra_ie_len = 0; |
| 3530 | return -ENOMEM; |
| 3531 | } |
| 3532 | memcpy(ifsta->extra_ie, ie, len); |
| 3533 | ifsta->extra_ie_len = len; |
| 3534 | return 0; |
| 3535 | } |
| 3536 | |
| 3537 | |
| 3538 | struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev, |
| 3539 | struct sk_buff *skb, u8 *bssid, |
| 3540 | u8 *addr) |
| 3541 | { |
| 3542 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 3543 | struct sta_info *sta; |
John W. Linville | 91fa558 | 2007-05-15 16:14:40 -0400 | [diff] [blame] | 3544 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3545 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3546 | |
| 3547 | /* TODO: Could consider removing the least recently used entry and |
| 3548 | * allow new one to be added. */ |
| 3549 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
| 3550 | if (net_ratelimit()) { |
| 3551 | printk(KERN_DEBUG "%s: No room for a new IBSS STA " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3552 | "entry %s\n", dev->name, print_mac(mac, addr)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3553 | } |
| 3554 | return NULL; |
| 3555 | } |
| 3556 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3557 | printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 3558 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3559 | |
| 3560 | sta = sta_info_add(local, dev, addr, GFP_ATOMIC); |
| 3561 | if (!sta) |
| 3562 | return NULL; |
| 3563 | |
| 3564 | sta->supp_rates = sdata->u.sta.supp_rates_bits; |
| 3565 | |
| 3566 | rate_control_rate_init(sta, local); |
| 3567 | |
| 3568 | return sta; /* caller will call sta_info_put() */ |
| 3569 | } |
| 3570 | |
| 3571 | |
| 3572 | int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason) |
| 3573 | { |
| 3574 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3575 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3576 | |
| 3577 | printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n", |
| 3578 | dev->name, reason); |
| 3579 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3580 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
| 3581 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3582 | return -EINVAL; |
| 3583 | |
| 3584 | ieee80211_send_deauth(dev, ifsta, reason); |
| 3585 | ieee80211_set_disassoc(dev, ifsta, 1); |
| 3586 | return 0; |
| 3587 | } |
| 3588 | |
| 3589 | |
| 3590 | int ieee80211_sta_disassociate(struct net_device *dev, u16 reason) |
| 3591 | { |
| 3592 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3593 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3594 | |
| 3595 | printk(KERN_DEBUG "%s: disassociate(reason=%d)\n", |
| 3596 | dev->name, reason); |
| 3597 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3598 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3599 | return -EINVAL; |
| 3600 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3601 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3602 | return -1; |
| 3603 | |
| 3604 | ieee80211_send_disassoc(dev, ifsta, reason); |
| 3605 | ieee80211_set_disassoc(dev, ifsta, 0); |
| 3606 | return 0; |
| 3607 | } |