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