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