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