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