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