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