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