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