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