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