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