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