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