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