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