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