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