blob: e821d1ac5b006cab91d0a643c9983a9614a76445 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
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 Bencf0706e82007-05-05 11:45:53 -070015 * 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 Uytterhoeven5b323ed2007-05-08 18:40:27 -070019#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070020#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 Bergd0709a62008-02-25 16:27:46 +010027#include <linux/rtnetlink.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070028#include <net/iw_handler.h>
29#include <asm/types.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070030
31#include <net/mac80211.h>
32#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040033#include "rate.h"
34#include "led.h"
Luis Carlos Cobof709fc62008-02-23 15:17:12 +010035#include "mesh.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070036
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +030037#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
Jiri Bencf0706e82007-05-05 11:45:53 -070038#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 Cobof709fc62008-02-23 15:17:12 +010043#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070044#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 Williams872ba532008-06-04 13:59:34 -040048#define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070049
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 Cobof709fc62008-02-23 15:17:12 +010056#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070057
58#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
59
60
Jiri Bencf0706e82007-05-05 11:45:53 -070061#define ERP_INFO_USE_PROTECTION BIT(1)
62
Ron Rindjunsky9f985b02007-11-26 16:14:32 +020063/* mgmt header + 1 byte action code */
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 Rindjunsky688b88a2007-12-25 17:00:37 +020069#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
70#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
Ron Rindjunsky9f985b02007-11-26 16:14:32 +020071
Ron Rindjunsky07db2182007-12-25 17:00:33 +020072/* 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-Greenef698d852008-08-03 12:04:37 +120077static void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
Jiri Bencf0706e82007-05-05 11:45:53 -070078 u8 *ssid, size_t ssid_len);
79static struct ieee80211_sta_bss *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120080ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -040081 u8 *ssid, u8 ssid_len);
Johannes Berg3e122be2008-07-09 14:40:34 +020082static void ieee80211_rx_bss_put(struct ieee80211_local *local,
Jiri Bencf0706e82007-05-05 11:45:53 -070083 struct ieee80211_sta_bss *bss);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120084static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -070085 struct ieee80211_if_sta *ifsta);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120086static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata);
87static int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -070088 u8 *ssid, size_t ssid_len);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120089static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -070090 struct ieee80211_if_sta *ifsta);
Adrian Bunk712590d2008-04-21 11:47:51 +030091static void sta_rx_agg_session_timer_expired(unsigned long data);
Jiri Bencf0706e82007-05-05 11:45:53 -070092
93
Luis Carlos Coboee385852008-02-23 15:17:11 +010094void ieee802_11_parse_elems(u8 *start, size_t len,
95 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -070096{
97 size_t left = len;
98 u8 *pos = start;
Jiri Bencf0706e82007-05-05 11:45:53 -070099
100 memset(elems, 0, sizeof(*elems));
101
102 while (left >= 2) {
103 u8 id, elen;
104
105 id = *pos++;
106 elen = *pos++;
107 left -= 2;
108
John W. Linville67a4cce2007-10-12 16:40:37 -0400109 if (elen > left)
110 return;
Jiri Bencf0706e82007-05-05 11:45:53 -0700111
112 switch (id) {
113 case WLAN_EID_SSID:
114 elems->ssid = pos;
115 elems->ssid_len = elen;
116 break;
117 case WLAN_EID_SUPP_RATES:
118 elems->supp_rates = pos;
119 elems->supp_rates_len = elen;
120 break;
121 case WLAN_EID_FH_PARAMS:
122 elems->fh_params = pos;
123 elems->fh_params_len = elen;
124 break;
125 case WLAN_EID_DS_PARAMS:
126 elems->ds_params = pos;
127 elems->ds_params_len = elen;
128 break;
129 case WLAN_EID_CF_PARAMS:
130 elems->cf_params = pos;
131 elems->cf_params_len = elen;
132 break;
133 case WLAN_EID_TIM:
134 elems->tim = pos;
135 elems->tim_len = elen;
136 break;
137 case WLAN_EID_IBSS_PARAMS:
138 elems->ibss_params = pos;
139 elems->ibss_params_len = elen;
140 break;
141 case WLAN_EID_CHALLENGE:
142 elems->challenge = pos;
143 elems->challenge_len = elen;
144 break;
145 case WLAN_EID_WPA:
146 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
147 pos[2] == 0xf2) {
148 /* Microsoft OUI (00:50:F2) */
149 if (pos[3] == 1) {
150 /* OUI Type 1 - WPA IE */
151 elems->wpa = pos;
152 elems->wpa_len = elen;
153 } else if (elen >= 5 && pos[3] == 2) {
154 if (pos[4] == 0) {
155 elems->wmm_info = pos;
156 elems->wmm_info_len = elen;
157 } else if (pos[4] == 1) {
158 elems->wmm_param = pos;
159 elems->wmm_param_len = elen;
160 }
161 }
162 }
163 break;
164 case WLAN_EID_RSN:
165 elems->rsn = pos;
166 elems->rsn_len = elen;
167 break;
168 case WLAN_EID_ERP_INFO:
169 elems->erp_info = pos;
170 elems->erp_info_len = elen;
171 break;
172 case WLAN_EID_EXT_SUPP_RATES:
173 elems->ext_supp_rates = pos;
174 elems->ext_supp_rates_len = elen;
175 break;
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200176 case WLAN_EID_HT_CAPABILITY:
177 elems->ht_cap_elem = pos;
178 elems->ht_cap_elem_len = elen;
179 break;
180 case WLAN_EID_HT_EXTRA_INFO:
181 elems->ht_info_elem = pos;
182 elems->ht_info_elem_len = elen;
183 break;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100184 case WLAN_EID_MESH_ID:
185 elems->mesh_id = pos;
186 elems->mesh_id_len = elen;
187 break;
188 case WLAN_EID_MESH_CONFIG:
189 elems->mesh_config = pos;
190 elems->mesh_config_len = elen;
191 break;
192 case WLAN_EID_PEER_LINK:
193 elems->peer_link = pos;
194 elems->peer_link_len = elen;
195 break;
196 case WLAN_EID_PREQ:
197 elems->preq = pos;
198 elems->preq_len = elen;
199 break;
200 case WLAN_EID_PREP:
201 elems->prep = pos;
202 elems->prep_len = elen;
203 break;
204 case WLAN_EID_PERR:
205 elems->perr = pos;
206 elems->perr_len = elen;
207 break;
Assaf Kraussf2df3852008-06-15 18:23:29 +0300208 case WLAN_EID_CHANNEL_SWITCH:
209 elems->ch_switch_elem = pos;
210 elems->ch_switch_elem_len = elen;
211 break;
212 case WLAN_EID_QUIET:
213 if (!elems->quiet_elem) {
214 elems->quiet_elem = pos;
215 elems->quiet_elem_len = elen;
216 }
217 elems->num_of_quiet_elem++;
218 break;
219 case WLAN_EID_COUNTRY:
220 elems->country_elem = pos;
221 elems->country_elem_len = elen;
222 break;
223 case WLAN_EID_PWR_CONSTRAINT:
224 elems->pwr_constr_elem = pos;
225 elems->pwr_constr_elem_len = elen;
226 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700227 default:
Jiri Bencf0706e82007-05-05 11:45:53 -0700228 break;
229 }
230
231 left -= elen;
232 pos += elen;
233 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700234}
235
236
Jiri Bencf0706e82007-05-05 11:45:53 -0700237static int ecw2cw(int ecw)
238{
Johannes Bergac2bf322008-02-14 00:30:35 +0100239 return (1 << ecw) - 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700240}
241
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100242
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200243static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100244 struct ieee80211_sta_bss *bss,
245 int ibss)
246{
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100247 struct ieee80211_local *local = sdata->local;
248 int i, have_higher_than_11mbit = 0;
249
250
251 /* cf. IEEE 802.11 9.2.12 */
252 for (i = 0; i < bss->supp_rates_len; i++)
253 if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
254 have_higher_than_11mbit = 1;
255
256 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
257 have_higher_than_11mbit)
258 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
259 else
260 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
261
262
263 if (local->ops->conf_tx) {
264 struct ieee80211_tx_queue_params qparam;
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100265
266 memset(&qparam, 0, sizeof(qparam));
267
268 qparam.aifs = 2;
269
270 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
271 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
272 qparam.cw_min = 31;
273 else
274 qparam.cw_min = 15;
275
276 qparam.cw_max = 1023;
277 qparam.txop = 0;
278
Johannes Berge100bb62008-04-30 18:51:21 +0200279 for (i = 0; i < local_to_hw(local)->queues; i++)
280 local->ops->conf_tx(local_to_hw(local), i, &qparam);
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100281 }
282}
283
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200284static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Jiri Bencf0706e82007-05-05 11:45:53 -0700285 struct ieee80211_if_sta *ifsta,
286 u8 *wmm_param, size_t wmm_param_len)
287{
Jiri Bencf0706e82007-05-05 11:45:53 -0700288 struct ieee80211_tx_queue_params params;
289 size_t left;
290 int count;
291 u8 *pos;
292
Johannes Berg3434fbd2008-05-03 00:59:37 +0200293 if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED))
294 return;
295
296 if (!wmm_param)
297 return;
298
Jiri Bencf0706e82007-05-05 11:45:53 -0700299 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
300 return;
301 count = wmm_param[6] & 0x0f;
302 if (count == ifsta->wmm_last_param_set)
303 return;
304 ifsta->wmm_last_param_set = count;
305
306 pos = wmm_param + 8;
307 left = wmm_param_len - 8;
308
309 memset(&params, 0, sizeof(params));
310
311 if (!local->ops->conf_tx)
312 return;
313
314 local->wmm_acm = 0;
315 for (; left >= 4; left -= 4, pos += 4) {
316 int aci = (pos[0] >> 5) & 0x03;
317 int acm = (pos[0] >> 4) & 0x01;
318 int queue;
319
320 switch (aci) {
321 case 1:
Johannes Berge100bb62008-04-30 18:51:21 +0200322 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200323 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700324 local->wmm_acm |= BIT(0) | BIT(3);
Jiri Bencf0706e82007-05-05 11:45:53 -0700325 break;
326 case 2:
Johannes Berge100bb62008-04-30 18:51:21 +0200327 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200328 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700329 local->wmm_acm |= BIT(4) | BIT(5);
Jiri Bencf0706e82007-05-05 11:45:53 -0700330 break;
331 case 3:
Johannes Berge100bb62008-04-30 18:51:21 +0200332 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200333 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700334 local->wmm_acm |= BIT(6) | BIT(7);
Jiri Bencf0706e82007-05-05 11:45:53 -0700335 break;
336 case 0:
337 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200338 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200339 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700340 local->wmm_acm |= BIT(1) | BIT(2);
Jiri Bencf0706e82007-05-05 11:45:53 -0700341 break;
342 }
343
344 params.aifs = pos[0] & 0x0f;
345 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
346 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200347 params.txop = get_unaligned_le16(pos + 2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200348#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700349 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100350 "cWmin=%d cWmax=%d txop=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200351 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100352 params.cw_max, params.txop);
353#endif
Jiri Bencf0706e82007-05-05 11:45:53 -0700354 /* TODO: handle ACM (block TX, fallback to next lowest allowed
355 * AC for now) */
356 if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
357 printk(KERN_DEBUG "%s: failed to set TX queue "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200358 "parameters for queue %d\n", local->mdev->name, queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700359 }
360 }
361}
362
John W. Linville50c4afb2008-04-15 14:09:27 -0400363static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata,
364 bool use_protection,
365 bool use_short_preamble)
Daniel Drake56282212007-07-10 19:32:10 +0200366{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100367 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
Tomas Winklerebd74482008-07-01 10:44:50 +0300368#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake56282212007-07-10 19:32:10 +0200369 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Joe Perches0795af52007-10-03 17:59:30 -0700370 DECLARE_MAC_BUF(mac);
Tomas Winklerebd74482008-07-01 10:44:50 +0300371#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100372 u32 changed = 0;
Daniel Drake56282212007-07-10 19:32:10 +0200373
Johannes Berg471b3ef2007-12-28 14:32:58 +0100374 if (use_protection != bss_conf->use_cts_prot) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200375#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake56282212007-07-10 19:32:10 +0200376 if (net_ratelimit()) {
377 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
Joe Perches0795af52007-10-03 17:59:30 -0700378 "%s)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100379 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200380 use_protection ? "enabled" : "disabled",
Joe Perches0795af52007-10-03 17:59:30 -0700381 print_mac(mac, ifsta->bssid));
Daniel Drake56282212007-07-10 19:32:10 +0200382 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200383#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100384 bss_conf->use_cts_prot = use_protection;
385 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200386 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200387
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200388 if (use_short_preamble != bss_conf->use_short_preamble) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200389#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake7e9ed182007-07-27 15:43:24 +0200390 if (net_ratelimit()) {
391 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Joe Perches0795af52007-10-03 17:59:30 -0700392 " (BSSID=%s)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100393 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200394 use_short_preamble ? "short" : "long",
Joe Perches0795af52007-10-03 17:59:30 -0700395 print_mac(mac, ifsta->bssid));
Daniel Drake7e9ed182007-07-27 15:43:24 +0200396 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200397#endif
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200398 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100399 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200400 }
Daniel Draked9430a32007-07-27 15:43:24 +0200401
Johannes Berg471b3ef2007-12-28 14:32:58 +0100402 return changed;
Daniel Drake56282212007-07-10 19:32:10 +0200403}
404
John W. Linville50c4afb2008-04-15 14:09:27 -0400405static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
406 u8 erp_value)
407{
408 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
409 bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0;
410
411 return ieee80211_handle_protect_preamb(sdata,
412 use_protection, use_short_preamble);
413}
414
415static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
416 struct ieee80211_sta_bss *bss)
417{
418 u32 changed = 0;
419
420 if (bss->has_erp_value)
421 changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value);
422 else {
423 u16 capab = bss->capability;
424 changed |= ieee80211_handle_protect_preamb(sdata, false,
425 (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
426 }
427
428 return changed;
429}
430
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200431int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
432 struct ieee80211_ht_info *ht_info)
433{
434
435 if (ht_info == NULL)
436 return -EINVAL;
437
438 memset(ht_info, 0, sizeof(*ht_info));
439
440 if (ht_cap_ie) {
441 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
442
443 ht_info->ht_supported = 1;
444 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
445 ht_info->ampdu_factor =
446 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
447 ht_info->ampdu_density =
448 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
449 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
450 } else
451 ht_info->ht_supported = 0;
452
453 return 0;
454}
455
456int ieee80211_ht_addt_info_ie_to_ht_bss_info(
457 struct ieee80211_ht_addt_info *ht_add_info_ie,
458 struct ieee80211_ht_bss_info *bss_info)
459{
460 if (bss_info == NULL)
461 return -EINVAL;
462
463 memset(bss_info, 0, sizeof(*bss_info));
464
465 if (ht_add_info_ie) {
466 u16 op_mode;
467 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
468
469 bss_info->primary_channel = ht_add_info_ie->control_chan;
470 bss_info->bss_cap = ht_add_info_ie->ht_param;
471 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
472 }
473
474 return 0;
475}
Daniel Drake56282212007-07-10 19:32:10 +0200476
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200477static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700478 struct ieee80211_if_sta *ifsta)
479{
480 char *buf;
481 size_t len;
482 int i;
483 union iwreq_data wrqu;
484
485 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
486 return;
487
488 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
Michael Wu0ec0b7a2007-07-27 15:43:24 +0200489 ifsta->assocresp_ies_len), GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700490 if (!buf)
491 return;
492
493 len = sprintf(buf, "ASSOCINFO(");
494 if (ifsta->assocreq_ies) {
495 len += sprintf(buf + len, "ReqIEs=");
496 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
497 len += sprintf(buf + len, "%02x",
498 ifsta->assocreq_ies[i]);
499 }
500 }
501 if (ifsta->assocresp_ies) {
502 if (ifsta->assocreq_ies)
503 len += sprintf(buf + len, " ");
504 len += sprintf(buf + len, "RespIEs=");
505 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
506 len += sprintf(buf + len, "%02x",
507 ifsta->assocresp_ies[i]);
508 }
509 }
510 len += sprintf(buf + len, ")");
511
512 if (len > IW_CUSTOM_MAX) {
513 len = sprintf(buf, "ASSOCRESPIE=");
514 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
515 len += sprintf(buf + len, "%02x",
516 ifsta->assocresp_ies[i]);
517 }
518 }
519
520 memset(&wrqu, 0, sizeof(wrqu));
521 wrqu.data.length = len;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200522 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
Jiri Bencf0706e82007-05-05 11:45:53 -0700523
524 kfree(buf);
525}
526
527
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200528static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400529 struct ieee80211_if_sta *ifsta,
Michael Buesch47f0c502007-09-27 15:10:44 +0200530 bool assoc)
Jiri Bencf0706e82007-05-05 11:45:53 -0700531{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100532 struct ieee80211_local *local = sdata->local;
Tomas Winkler38668c02008-03-28 16:33:32 -0700533 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
Jiri Bencf0706e82007-05-05 11:45:53 -0700534 union iwreq_data wrqu;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100535 u32 changed = BSS_CHANGED_ASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -0700536
Jiri Bencf0706e82007-05-05 11:45:53 -0700537 if (assoc) {
Daniel Drake56282212007-07-10 19:32:10 +0200538 struct ieee80211_sta_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400539
540 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
541
Johannes Berg51fb61e2007-12-19 01:31:27 +0100542 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700543 return;
Daniel Drake56282212007-07-10 19:32:10 +0200544
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200545 bss = ieee80211_rx_bss_get(local, ifsta->bssid,
Tomas Winkler38668c02008-03-28 16:33:32 -0700546 conf->channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400547 ifsta->ssid, ifsta->ssid_len);
Daniel Drake56282212007-07-10 19:32:10 +0200548 if (bss) {
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700549 /* set timing information */
550 sdata->bss_conf.beacon_int = bss->beacon_int;
551 sdata->bss_conf.timestamp = bss->timestamp;
Emmanuel Grumbach98f7dfd2008-07-18 13:52:59 +0800552 sdata->bss_conf.dtim_period = bss->dtim_period;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700553
John W. Linville50c4afb2008-04-15 14:09:27 -0400554 changed |= ieee80211_handle_bss_capability(sdata, bss);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700555
Johannes Berg3e122be2008-07-09 14:40:34 +0200556 ieee80211_rx_bss_put(local, bss);
Daniel Drake56282212007-07-10 19:32:10 +0200557 }
558
Tomas Winkler38668c02008-03-28 16:33:32 -0700559 if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
560 changed |= BSS_CHANGED_HT;
561 sdata->bss_conf.assoc_ht = 1;
562 sdata->bss_conf.ht_conf = &conf->ht_conf;
563 sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf;
564 }
565
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400566 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -0700567 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
568 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200569 ieee80211_sta_send_associnfo(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700570 } else {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200571 netif_carrier_off(sdata->dev);
572 ieee80211_sta_tear_down_BA_sessions(sdata, ifsta->bssid);
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400573 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200574 changed |= ieee80211_reset_erp_info(sdata);
Tomas Winkler38668c02008-03-28 16:33:32 -0700575
576 sdata->bss_conf.assoc_ht = 0;
577 sdata->bss_conf.ht_conf = NULL;
578 sdata->bss_conf.ht_bss_conf = NULL;
579
Jiri Bencf0706e82007-05-05 11:45:53 -0700580 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
581 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700582 ifsta->last_probe = jiffies;
Michael Buesch47f0c502007-09-27 15:10:44 +0200583 ieee80211_led_assoc(local, assoc);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100584
Tomas Winklerb2205252008-01-27 16:18:22 +0200585 sdata->bss_conf.assoc = assoc;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100586 ieee80211_bss_info_change_notify(sdata, changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300587
588 if (assoc)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200589 netif_carrier_on(sdata->dev);
Guy Cohen8db93692008-07-03 19:56:13 +0300590
Reinette Chatre41a7be42008-04-03 16:08:49 -0700591 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200592 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700593}
594
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200595static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700596 struct ieee80211_if_sta *ifsta, int deauth)
597{
598 if (deauth)
599 ifsta->auth_tries = 0;
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +0300600 ifsta->assoc_scan_tries = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700601 ifsta->assoc_tries = 0;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200602 ieee80211_set_associated(sdata, ifsta, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -0700603}
604
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200605void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
Luis Carlos Coboee385852008-02-23 15:17:11 +0100606 int encrypt)
Jiri Bencf0706e82007-05-05 11:45:53 -0700607{
Jiri Bencf0706e82007-05-05 11:45:53 -0700608 skb->dev = sdata->local->mdev;
609 skb_set_mac_header(skb, 0);
610 skb_set_network_header(skb, 0);
611 skb_set_transport_header(skb, 0);
612
Johannes Bergd0f09802008-07-29 11:32:07 +0200613 skb->iif = sdata->dev->ifindex;
614 skb->do_not_encrypt = !encrypt;
Jiri Bencf0706e82007-05-05 11:45:53 -0700615
616 dev_queue_xmit(skb);
617}
618
619
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200620static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700621 struct ieee80211_if_sta *ifsta,
622 int transaction, u8 *extra, size_t extra_len,
623 int encrypt)
624{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200625 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700626 struct sk_buff *skb;
627 struct ieee80211_mgmt *mgmt;
628
629 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
630 sizeof(*mgmt) + 6 + extra_len);
631 if (!skb) {
632 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200633 "frame\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -0700634 return;
635 }
636 skb_reserve(skb, local->hw.extra_tx_headroom);
637
638 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
639 memset(mgmt, 0, 24 + 6);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700640 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
641 IEEE80211_STYPE_AUTH);
Jiri Bencf0706e82007-05-05 11:45:53 -0700642 if (encrypt)
643 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
644 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200645 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Jiri Bencf0706e82007-05-05 11:45:53 -0700646 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
647 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
648 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
649 ifsta->auth_transaction = transaction + 1;
650 mgmt->u.auth.status_code = cpu_to_le16(0);
651 if (extra)
652 memcpy(skb_put(skb, extra_len), extra, extra_len);
653
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200654 ieee80211_sta_tx(sdata, skb, encrypt);
Jiri Bencf0706e82007-05-05 11:45:53 -0700655}
656
657
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200658static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700659 struct ieee80211_if_sta *ifsta)
660{
Joe Perches0795af52007-10-03 17:59:30 -0700661 DECLARE_MAC_BUF(mac);
662
Jiri Bencf0706e82007-05-05 11:45:53 -0700663 ifsta->auth_tries++;
664 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Joe Perches0795af52007-10-03 17:59:30 -0700665 printk(KERN_DEBUG "%s: authentication with AP %s"
Jiri Bencf0706e82007-05-05 11:45:53 -0700666 " timed out\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200667 sdata->dev->name, print_mac(mac, ifsta->bssid));
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300668 ifsta->state = IEEE80211_STA_MLME_DISABLED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700669 return;
670 }
671
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300672 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
Joe Perches0795af52007-10-03 17:59:30 -0700673 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200674 sdata->dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -0700675
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200676 ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -0700677
678 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
679}
680
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200681static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss,
682 struct ieee80211_supported_band *sband,
683 u64 *rates)
684{
685 int i, j, count;
686 *rates = 0;
687 count = 0;
688 for (i = 0; i < bss->supp_rates_len; i++) {
689 int rate = (bss->supp_rates[i] & 0x7F) * 5;
690
691 for (j = 0; j < sband->n_bitrates; j++)
692 if (sband->bitrates[j].bitrate == rate) {
693 *rates |= BIT(j);
694 count++;
695 break;
696 }
697 }
698
699 return count;
700}
Jiri Bencf0706e82007-05-05 11:45:53 -0700701
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200702static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700703 struct ieee80211_if_sta *ifsta)
704{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200705 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700706 struct sk_buff *skb;
707 struct ieee80211_mgmt *mgmt;
708 u8 *pos, *ies;
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200709 int i, len, count, rates_len, supp_rates_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700710 u16 capab;
711 struct ieee80211_sta_bss *bss;
712 int wmm = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100713 struct ieee80211_supported_band *sband;
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200714 u64 rates = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700715
716 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
717 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
718 ifsta->ssid_len);
719 if (!skb) {
720 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200721 "frame\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -0700722 return;
723 }
724 skb_reserve(skb, local->hw.extra_tx_headroom);
725
Johannes Berg8318d782008-01-24 19:38:38 +0100726 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
727
Jiri Bencf0706e82007-05-05 11:45:53 -0700728 capab = ifsta->capab;
Johannes Berg8318d782008-01-24 19:38:38 +0100729
730 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
731 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
732 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
733 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
734 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Jiri Bencf0706e82007-05-05 11:45:53 -0700735 }
Johannes Berg8318d782008-01-24 19:38:38 +0100736
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200737 bss = ieee80211_rx_bss_get(local, ifsta->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +0100738 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400739 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700740 if (bss) {
741 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
742 capab |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg988c0f72008-04-17 19:21:22 +0200743 if (bss->wmm_ie)
Jiri Bencf0706e82007-05-05 11:45:53 -0700744 wmm = 1;
Helmut Schaa0d580a72008-05-20 09:56:37 +0200745
746 /* get all rates supported by the device and the AP as
747 * some APs don't like getting a superset of their rates
748 * in the association request (e.g. D-Link DAP 1353 in
749 * b-only mode) */
750 rates_len = ieee80211_compatible_rates(bss, sband, &rates);
751
Tomas Winkler06ff47b2008-06-18 17:53:44 +0300752 if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
753 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
754 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
755
Johannes Berg3e122be2008-07-09 14:40:34 +0200756 ieee80211_rx_bss_put(local, bss);
Helmut Schaa0d580a72008-05-20 09:56:37 +0200757 } else {
758 rates = ~0;
759 rates_len = sband->n_bitrates;
Jiri Bencf0706e82007-05-05 11:45:53 -0700760 }
761
762 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
763 memset(mgmt, 0, 24);
764 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200765 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Jiri Bencf0706e82007-05-05 11:45:53 -0700766 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
767
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400768 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700769 skb_put(skb, 10);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700770 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
771 IEEE80211_STYPE_REASSOC_REQ);
Jiri Bencf0706e82007-05-05 11:45:53 -0700772 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
Tomas Winklerea95bba2008-07-18 13:53:00 +0800773 mgmt->u.reassoc_req.listen_interval =
774 cpu_to_le16(local->hw.conf.listen_interval);
Jiri Bencf0706e82007-05-05 11:45:53 -0700775 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
776 ETH_ALEN);
777 } else {
778 skb_put(skb, 4);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700779 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
780 IEEE80211_STYPE_ASSOC_REQ);
Jiri Bencf0706e82007-05-05 11:45:53 -0700781 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
Tomas Winklerea95bba2008-07-18 13:53:00 +0800782 mgmt->u.reassoc_req.listen_interval =
783 cpu_to_le16(local->hw.conf.listen_interval);
Jiri Bencf0706e82007-05-05 11:45:53 -0700784 }
785
786 /* SSID */
787 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
788 *pos++ = WLAN_EID_SSID;
789 *pos++ = ifsta->ssid_len;
790 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
791
Helmut Schaa0d580a72008-05-20 09:56:37 +0200792 /* add all rates which were marked to be used above */
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200793 supp_rates_len = rates_len;
794 if (supp_rates_len > 8)
795 supp_rates_len = 8;
Jiri Bencf0706e82007-05-05 11:45:53 -0700796
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200797 len = sband->n_bitrates;
798 pos = skb_put(skb, supp_rates_len + 2);
799 *pos++ = WLAN_EID_SUPP_RATES;
800 *pos++ = supp_rates_len;
801
802 count = 0;
803 for (i = 0; i < sband->n_bitrates; i++) {
804 if (BIT(i) & rates) {
Johannes Berg8318d782008-01-24 19:38:38 +0100805 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e82007-05-05 11:45:53 -0700806 *pos++ = (u8) (rate / 5);
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200807 if (++count == 8)
808 break;
809 }
810 }
811
812 if (count == 8) {
813 pos = skb_put(skb, rates_len - count + 2);
814 *pos++ = WLAN_EID_EXT_SUPP_RATES;
815 *pos++ = rates_len - count;
816
817 for (i++; i < sband->n_bitrates; i++) {
818 if (BIT(i) & rates) {
819 int rate = sband->bitrates[i].bitrate;
820 *pos++ = (u8) (rate / 5);
821 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700822 }
823 }
824
Tomas Winkler06ff47b2008-06-18 17:53:44 +0300825 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
826 /* 1. power capabilities */
827 pos = skb_put(skb, 4);
828 *pos++ = WLAN_EID_PWR_CAPABILITY;
829 *pos++ = 2;
830 *pos++ = 0; /* min tx power */
831 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
832
833 /* 2. supported channels */
834 /* TODO: get this in reg domain format */
835 pos = skb_put(skb, 2 * sband->n_channels + 2);
836 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
837 *pos++ = 2 * sband->n_channels;
838 for (i = 0; i < sband->n_channels; i++) {
839 *pos++ = ieee80211_frequency_to_channel(
840 sband->channels[i].center_freq);
841 *pos++ = 1; /* one channel in the subband*/
842 }
843 }
844
Jiri Bencf0706e82007-05-05 11:45:53 -0700845 if (ifsta->extra_ie) {
846 pos = skb_put(skb, ifsta->extra_ie_len);
847 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
848 }
849
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400850 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700851 pos = skb_put(skb, 9);
852 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
853 *pos++ = 7; /* len */
854 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
855 *pos++ = 0x50;
856 *pos++ = 0xf2;
857 *pos++ = 2; /* WME */
858 *pos++ = 0; /* WME info */
859 *pos++ = 1; /* WME ver */
860 *pos++ = 0;
861 }
Johannes Berg3434fbd2008-05-03 00:59:37 +0200862
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200863 /* wmm support is a must to HT */
Johannes Berg3434fbd2008-05-03 00:59:37 +0200864 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) &&
Emmanuel Grumbach93061022008-05-29 16:35:23 +0800865 sband->ht_info.ht_supported && bss->ht_add_ie) {
866 struct ieee80211_ht_addt_info *ht_add_info =
867 (struct ieee80211_ht_addt_info *)bss->ht_add_ie;
868 u16 cap = sband->ht_info.cap;
869 __le16 tmp;
870 u32 flags = local->hw.conf.channel->flags;
871
872 switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) {
873 case IEEE80211_HT_IE_CHA_SEC_ABOVE:
874 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
875 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
876 cap &= ~IEEE80211_HT_CAP_SGI_40;
877 }
878 break;
879 case IEEE80211_HT_IE_CHA_SEC_BELOW:
880 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
881 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
882 cap &= ~IEEE80211_HT_CAP_SGI_40;
883 }
884 break;
885 }
886
887 tmp = cpu_to_le16(cap);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200888 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
889 *pos++ = WLAN_EID_HT_CAPABILITY;
890 *pos++ = sizeof(struct ieee80211_ht_cap);
891 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
892 memcpy(pos, &tmp, sizeof(u16));
893 pos += sizeof(u16);
Johannes Berg8318d782008-01-24 19:38:38 +0100894 /* TODO: needs a define here for << 2 */
895 *pos++ = sband->ht_info.ampdu_factor |
896 (sband->ht_info.ampdu_density << 2);
897 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200898 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700899
900 kfree(ifsta->assocreq_ies);
901 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
Michael Wu0ec0b7a2007-07-27 15:43:24 +0200902 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700903 if (ifsta->assocreq_ies)
904 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
905
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200906 ieee80211_sta_tx(sdata, skb, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -0700907}
908
909
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200910static void ieee80211_send_deauth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700911 struct ieee80211_if_sta *ifsta, u16 reason)
912{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200913 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700914 struct sk_buff *skb;
915 struct ieee80211_mgmt *mgmt;
916
917 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
918 if (!skb) {
919 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200920 "frame\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -0700921 return;
922 }
923 skb_reserve(skb, local->hw.extra_tx_headroom);
924
925 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
926 memset(mgmt, 0, 24);
927 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200928 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Jiri Bencf0706e82007-05-05 11:45:53 -0700929 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700930 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
931 IEEE80211_STYPE_DEAUTH);
Jiri Bencf0706e82007-05-05 11:45:53 -0700932 skb_put(skb, 2);
933 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
934
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200935 ieee80211_sta_tx(sdata, skb, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -0700936}
937
938
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200939static void ieee80211_send_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700940 struct ieee80211_if_sta *ifsta, u16 reason)
941{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200942 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700943 struct sk_buff *skb;
944 struct ieee80211_mgmt *mgmt;
945
946 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
947 if (!skb) {
948 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200949 "frame\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -0700950 return;
951 }
952 skb_reserve(skb, local->hw.extra_tx_headroom);
953
954 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
955 memset(mgmt, 0, 24);
956 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200957 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Jiri Bencf0706e82007-05-05 11:45:53 -0700958 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700959 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
960 IEEE80211_STYPE_DISASSOC);
Jiri Bencf0706e82007-05-05 11:45:53 -0700961 skb_put(skb, 2);
962 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
963
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200964 ieee80211_sta_tx(sdata, skb, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -0700965}
966
967
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200968static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700969 struct ieee80211_if_sta *ifsta)
970{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200971 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700972 struct ieee80211_sta_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000973 int bss_privacy;
974 int wep_privacy;
975 int privacy_invoked;
Jiri Bencf0706e82007-05-05 11:45:53 -0700976
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000977 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
Jiri Bencf0706e82007-05-05 11:45:53 -0700978 return 0;
979
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200980 bss = ieee80211_rx_bss_get(local, ifsta->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +0100981 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400982 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700983 if (!bss)
984 return 0;
985
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000986 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200987 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000988 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e82007-05-05 11:45:53 -0700989
Johannes Berg3e122be2008-07-09 14:40:34 +0200990 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700991
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000992 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
993 return 0;
994
995 return 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700996}
997
998
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200999static void ieee80211_associate(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001000 struct ieee80211_if_sta *ifsta)
1001{
Joe Perches0795af52007-10-03 17:59:30 -07001002 DECLARE_MAC_BUF(mac);
1003
Jiri Bencf0706e82007-05-05 11:45:53 -07001004 ifsta->assoc_tries++;
1005 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Joe Perches0795af52007-10-03 17:59:30 -07001006 printk(KERN_DEBUG "%s: association with AP %s"
Jiri Bencf0706e82007-05-05 11:45:53 -07001007 " timed out\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001008 sdata->dev->name, print_mac(mac, ifsta->bssid));
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001009 ifsta->state = IEEE80211_STA_MLME_DISABLED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001010 return;
1011 }
1012
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001013 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
Joe Perches0795af52007-10-03 17:59:30 -07001014 printk(KERN_DEBUG "%s: associate with AP %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001015 sdata->dev->name, print_mac(mac, ifsta->bssid));
1016 if (ieee80211_privacy_mismatch(sdata, ifsta)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001017 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001018 "mixed-cell disabled - abort association\n", sdata->dev->name);
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001019 ifsta->state = IEEE80211_STA_MLME_DISABLED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001020 return;
1021 }
1022
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001023 ieee80211_send_assoc(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001024
1025 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
1026}
1027
1028
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001029static void ieee80211_associated(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001030 struct ieee80211_if_sta *ifsta)
1031{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001032 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001033 struct sta_info *sta;
1034 int disassoc;
Joe Perches0795af52007-10-03 17:59:30 -07001035 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001036
1037 /* TODO: start monitoring current AP signal quality and number of
1038 * missed beacons. Scan other channels every now and then and search
1039 * for better APs. */
1040 /* TODO: remove expired BSSes */
1041
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001042 ifsta->state = IEEE80211_STA_MLME_ASSOCIATED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001043
Johannes Bergd0709a62008-02-25 16:27:46 +01001044 rcu_read_lock();
1045
Jiri Bencf0706e82007-05-05 11:45:53 -07001046 sta = sta_info_get(local, ifsta->bssid);
1047 if (!sta) {
Joe Perches0795af52007-10-03 17:59:30 -07001048 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001049 sdata->dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001050 disassoc = 1;
1051 } else {
1052 disassoc = 0;
1053 if (time_after(jiffies,
1054 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001055 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001056 printk(KERN_DEBUG "%s: No ProbeResp from "
Joe Perches0795af52007-10-03 17:59:30 -07001057 "current AP %s - assume out of "
Jiri Bencf0706e82007-05-05 11:45:53 -07001058 "range\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001059 sdata->dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001060 disassoc = 1;
Johannes Bergd0709a62008-02-25 16:27:46 +01001061 sta_info_unlink(&sta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001062 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001063 ieee80211_send_probe_req(sdata, ifsta->bssid,
Jiri Bencf0706e82007-05-05 11:45:53 -07001064 local->scan_ssid,
1065 local->scan_ssid_len);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001066 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001067 } else {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001068 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001069 if (time_after(jiffies, ifsta->last_probe +
1070 IEEE80211_PROBE_INTERVAL)) {
1071 ifsta->last_probe = jiffies;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001072 ieee80211_send_probe_req(sdata, ifsta->bssid,
Jiri Bencf0706e82007-05-05 11:45:53 -07001073 ifsta->ssid,
1074 ifsta->ssid_len);
1075 }
1076 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001077 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001078
1079 rcu_read_unlock();
1080
Johannes Berg3b967662008-04-08 17:56:52 +02001081 if (disassoc && sta)
Johannes Bergd0709a62008-02-25 16:27:46 +01001082 sta_info_destroy(sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001083
Jiri Bencf0706e82007-05-05 11:45:53 -07001084 if (disassoc) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001085 ifsta->state = IEEE80211_STA_MLME_DISABLED;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001086 ieee80211_set_associated(sdata, ifsta, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07001087 } else {
1088 mod_timer(&ifsta->timer, jiffies +
1089 IEEE80211_MONITORING_INTERVAL);
1090 }
1091}
1092
1093
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001094static void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
Jiri Bencf0706e82007-05-05 11:45:53 -07001095 u8 *ssid, size_t ssid_len)
1096{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001097 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001098 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001099 struct sk_buff *skb;
1100 struct ieee80211_mgmt *mgmt;
1101 u8 *pos, *supp_rates, *esupp_rates = NULL;
1102 int i;
1103
1104 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
1105 if (!skb) {
1106 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001107 "request\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001108 return;
1109 }
1110 skb_reserve(skb, local->hw.extra_tx_headroom);
1111
1112 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1113 memset(mgmt, 0, 24);
Harvey Harrisone7827a72008-07-15 18:44:13 -07001114 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1115 IEEE80211_STYPE_PROBE_REQ);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001116 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Jiri Bencf0706e82007-05-05 11:45:53 -07001117 if (dst) {
1118 memcpy(mgmt->da, dst, ETH_ALEN);
1119 memcpy(mgmt->bssid, dst, ETH_ALEN);
1120 } else {
1121 memset(mgmt->da, 0xff, ETH_ALEN);
1122 memset(mgmt->bssid, 0xff, ETH_ALEN);
1123 }
1124 pos = skb_put(skb, 2 + ssid_len);
1125 *pos++ = WLAN_EID_SSID;
1126 *pos++ = ssid_len;
1127 memcpy(pos, ssid, ssid_len);
1128
1129 supp_rates = skb_put(skb, 2);
1130 supp_rates[0] = WLAN_EID_SUPP_RATES;
1131 supp_rates[1] = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001132 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1133
1134 for (i = 0; i < sband->n_bitrates; i++) {
1135 struct ieee80211_rate *rate = &sband->bitrates[i];
Jiri Bencf0706e82007-05-05 11:45:53 -07001136 if (esupp_rates) {
1137 pos = skb_put(skb, 1);
1138 esupp_rates[1]++;
1139 } else if (supp_rates[1] == 8) {
1140 esupp_rates = skb_put(skb, 3);
1141 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
1142 esupp_rates[1] = 1;
1143 pos = &esupp_rates[2];
1144 } else {
1145 pos = skb_put(skb, 1);
1146 supp_rates[1]++;
1147 }
Johannes Berg8318d782008-01-24 19:38:38 +01001148 *pos = rate->bitrate / 5;
Jiri Bencf0706e82007-05-05 11:45:53 -07001149 }
1150
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001151 ieee80211_sta_tx(sdata, skb, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07001152}
1153
1154
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001155static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001156{
Jiri Bencf0706e82007-05-05 11:45:53 -07001157 if (!sdata || !sdata->default_key ||
Johannes Berg8f20fc22007-08-28 17:01:54 -04001158 sdata->default_key->conf.alg != ALG_WEP)
Jiri Bencf0706e82007-05-05 11:45:53 -07001159 return 0;
1160 return 1;
1161}
1162
1163
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001164static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001165 struct ieee80211_if_sta *ifsta)
1166{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001167 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001168 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001169 ieee80211_associate(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001170}
1171
1172
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001173static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001174 struct ieee80211_if_sta *ifsta,
1175 struct ieee80211_mgmt *mgmt,
1176 size_t len)
1177{
1178 u8 *pos;
1179 struct ieee802_11_elems elems;
1180
Jiri Bencf0706e82007-05-05 11:45:53 -07001181 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001182 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001183 if (!elems.challenge)
Jiri Bencf0706e82007-05-05 11:45:53 -07001184 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001185 ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2,
Jiri Bencf0706e82007-05-05 11:45:53 -07001186 elems.challenge_len + 2, 1);
1187}
1188
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001189static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001190 u8 dialog_token, u16 status, u16 policy,
1191 u16 buf_size, u16 timeout)
1192{
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001193 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001194 struct ieee80211_local *local = sdata->local;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001195 struct sk_buff *skb;
1196 struct ieee80211_mgmt *mgmt;
1197 u16 capab;
1198
Ester Kummer3acea5b2008-04-17 16:05:14 -07001199 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
1200
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001201 if (!skb) {
1202 printk(KERN_DEBUG "%s: failed to allocate buffer "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001203 "for addba resp frame\n", sdata->dev->name);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001204 return;
1205 }
1206
1207 skb_reserve(skb, local->hw.extra_tx_headroom);
1208 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1209 memset(mgmt, 0, 24);
1210 memcpy(mgmt->da, da, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001211 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001212 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001213 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001214 else
1215 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
Harvey Harrisone7827a72008-07-15 18:44:13 -07001216 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1217 IEEE80211_STYPE_ACTION);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001218
1219 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1220 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1221 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1222 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1223
1224 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1225 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1226 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1227
1228 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1229 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1230 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1231
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001232 ieee80211_sta_tx(sdata, skb, 0);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001233
1234 return;
1235}
1236
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001237void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, const u8 *da,
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001238 u16 tid, u8 dialog_token, u16 start_seq_num,
1239 u16 agg_size, u16 timeout)
1240{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001241 struct ieee80211_local *local = sdata->local;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001242 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1243 struct sk_buff *skb;
1244 struct ieee80211_mgmt *mgmt;
1245 u16 capab;
1246
Ester Kummer3acea5b2008-04-17 16:05:14 -07001247 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001248
1249 if (!skb) {
1250 printk(KERN_ERR "%s: failed to allocate buffer "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001251 "for addba request frame\n", sdata->dev->name);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001252 return;
1253 }
1254 skb_reserve(skb, local->hw.extra_tx_headroom);
1255 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1256 memset(mgmt, 0, 24);
1257 memcpy(mgmt->da, da, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001258 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001259 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001260 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001261 else
1262 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1263
Harvey Harrisone7827a72008-07-15 18:44:13 -07001264 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1265 IEEE80211_STYPE_ACTION);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001266
1267 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1268
1269 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1270 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1271
1272 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1273 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1274 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1275 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1276
1277 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1278
1279 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1280 mgmt->u.action.u.addba_req.start_seq_num =
1281 cpu_to_le16(start_seq_num << 4);
1282
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001283 ieee80211_sta_tx(sdata, skb, 0);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001284}
1285
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001286static void ieee80211_sta_process_addba_request(struct ieee80211_local *local,
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001287 struct ieee80211_mgmt *mgmt,
1288 size_t len)
1289{
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001290 struct ieee80211_hw *hw = &local->hw;
1291 struct ieee80211_conf *conf = &hw->conf;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001292 struct sta_info *sta;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001293 struct tid_ampdu_rx *tid_agg_rx;
1294 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001295 u8 dialog_token;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001296 int ret = -EOPNOTSUPP;
1297 DECLARE_MAC_BUF(mac);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001298
Johannes Bergd0709a62008-02-25 16:27:46 +01001299 rcu_read_lock();
1300
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001301 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001302 if (!sta) {
1303 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001304 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001305 }
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001306
1307 /* extract session parameters from addba request frame */
1308 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1309 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001310 start_seq_num =
1311 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001312
1313 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1314 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1315 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1316 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1317
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001318 status = WLAN_STATUS_REQUEST_DECLINED;
1319
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001320 /* sanity check for incoming parameters:
1321 * check if configuration can support the BA policy
1322 * and if buffer size does not exceeds max value */
1323 if (((ba_policy != 1)
1324 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1325 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1326 status = WLAN_STATUS_INVALID_QOS_PARAM;
1327#ifdef CONFIG_MAC80211_HT_DEBUG
1328 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001329 printk(KERN_DEBUG "AddBA Req with bad params from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001330 "%s on tid %u. policy %d, buffer size %d\n",
1331 print_mac(mac, mgmt->sa), tid, ba_policy,
1332 buf_size);
1333#endif /* CONFIG_MAC80211_HT_DEBUG */
1334 goto end_no_lock;
1335 }
1336 /* determine default buffer size */
1337 if (buf_size == 0) {
Johannes Berg8318d782008-01-24 19:38:38 +01001338 struct ieee80211_supported_band *sband;
1339
1340 sband = local->hw.wiphy->bands[conf->channel->band];
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001341 buf_size = IEEE80211_MIN_AMPDU_BUF;
Johannes Berg8318d782008-01-24 19:38:38 +01001342 buf_size = buf_size << sband->ht_info.ampdu_factor;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001343 }
1344
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001345
1346 /* examine state machine */
Johannes Berg07346f812008-05-03 01:02:02 +02001347 spin_lock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001348
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001349 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001350#ifdef CONFIG_MAC80211_HT_DEBUG
1351 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001352 printk(KERN_DEBUG "unexpected AddBA Req from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001353 "%s on tid %u\n",
1354 print_mac(mac, mgmt->sa), tid);
1355#endif /* CONFIG_MAC80211_HT_DEBUG */
1356 goto end;
1357 }
1358
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001359 /* prepare A-MPDU MLME for Rx aggregation */
1360 sta->ampdu_mlme.tid_rx[tid] =
1361 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
1362 if (!sta->ampdu_mlme.tid_rx[tid]) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001363#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001364 if (net_ratelimit())
1365 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
1366 tid);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001367#endif
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001368 goto end;
1369 }
1370 /* rx timer */
1371 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
1372 sta_rx_agg_session_timer_expired;
1373 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
1374 (unsigned long)&sta->timer_to_tid[tid];
1375 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1376
1377 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
1378
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001379 /* prepare reordering buffer */
1380 tid_agg_rx->reorder_buf =
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301381 kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC);
Johannes Berg03147df2008-02-26 00:39:28 +01001382 if (!tid_agg_rx->reorder_buf) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001383#ifdef CONFIG_MAC80211_HT_DEBUG
Johannes Berg03147df2008-02-26 00:39:28 +01001384 if (net_ratelimit())
1385 printk(KERN_ERR "can not allocate reordering buffer "
1386 "to tid %d\n", tid);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001387#endif
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001388 kfree(sta->ampdu_mlme.tid_rx[tid]);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001389 goto end;
1390 }
1391 memset(tid_agg_rx->reorder_buf, 0,
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301392 buf_size * sizeof(struct sk_buff *));
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001393
1394 if (local->ops->ampdu_action)
1395 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001396 sta->addr, tid, &start_seq_num);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001397#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001398 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001399#endif /* CONFIG_MAC80211_HT_DEBUG */
1400
1401 if (ret) {
1402 kfree(tid_agg_rx->reorder_buf);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001403 kfree(tid_agg_rx);
1404 sta->ampdu_mlme.tid_rx[tid] = NULL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001405 goto end;
1406 }
1407
1408 /* change state and send addba resp */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001409 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001410 tid_agg_rx->dialog_token = dialog_token;
1411 tid_agg_rx->ssn = start_seq_num;
1412 tid_agg_rx->head_seq_num = start_seq_num;
1413 tid_agg_rx->buf_size = buf_size;
1414 tid_agg_rx->timeout = timeout;
1415 tid_agg_rx->stored_mpdu_num = 0;
1416 status = WLAN_STATUS_SUCCESS;
1417end:
Johannes Berg07346f812008-05-03 01:02:02 +02001418 spin_unlock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001419
1420end_no_lock:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001421 ieee80211_send_addba_resp(sta->sdata, sta->addr, tid,
Johannes Bergd0709a62008-02-25 16:27:46 +01001422 dialog_token, status, 1, buf_size, timeout);
1423 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001424}
Jiri Bencf0706e82007-05-05 11:45:53 -07001425
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001426static void ieee80211_sta_process_addba_resp(struct ieee80211_local *local,
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001427 struct ieee80211_mgmt *mgmt,
1428 size_t len)
1429{
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001430 struct ieee80211_hw *hw = &local->hw;
1431 struct sta_info *sta;
1432 u16 capab;
1433 u16 tid;
1434 u8 *state;
1435
Johannes Bergd0709a62008-02-25 16:27:46 +01001436 rcu_read_lock();
1437
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001438 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001439 if (!sta) {
1440 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001441 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001442 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001443
1444 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1445 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1446
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001447 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001448
Johannes Berg07346f812008-05-03 01:02:02 +02001449 spin_lock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001450
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001451 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
Johannes Berg07346f812008-05-03 01:02:02 +02001452 spin_unlock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001453 goto addba_resp_exit;
1454 }
1455
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001456 if (mgmt->u.action.u.addba_resp.dialog_token !=
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001457 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
Johannes Berg07346f812008-05-03 01:02:02 +02001458 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001459#ifdef CONFIG_MAC80211_HT_DEBUG
1460 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1461#endif /* CONFIG_MAC80211_HT_DEBUG */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001462 goto addba_resp_exit;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001463 }
1464
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001465 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001466#ifdef CONFIG_MAC80211_HT_DEBUG
1467 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1468#endif /* CONFIG_MAC80211_HT_DEBUG */
1469 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1470 == WLAN_STATUS_SUCCESS) {
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001471 *state |= HT_ADDBA_RECEIVED_MSK;
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001472 sta->ampdu_mlme.addba_req_num[tid] = 0;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001473
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001474 if (*state == HT_AGG_STATE_OPERATIONAL)
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001475 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001476
Johannes Berg07346f812008-05-03 01:02:02 +02001477 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001478 } else {
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001479 sta->ampdu_mlme.addba_req_num[tid]++;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001480 /* this will allow the state check in stop_BA_session */
1481 *state = HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001482 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001483 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1484 WLAN_BACK_INITIATOR);
1485 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001486
1487addba_resp_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001488 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001489}
1490
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001491void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, const u8 *da, u16 tid,
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001492 u16 initiator, u16 reason_code)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001493{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001494 struct ieee80211_local *local = sdata->local;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001495 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1496 struct sk_buff *skb;
1497 struct ieee80211_mgmt *mgmt;
1498 u16 params;
1499
Ester Kummer3acea5b2008-04-17 16:05:14 -07001500 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001501
1502 if (!skb) {
1503 printk(KERN_ERR "%s: failed to allocate buffer "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001504 "for delba frame\n", sdata->dev->name);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001505 return;
1506 }
1507
1508 skb_reserve(skb, local->hw.extra_tx_headroom);
1509 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1510 memset(mgmt, 0, 24);
1511 memcpy(mgmt->da, da, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001512 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001513 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001514 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001515 else
1516 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
Harvey Harrisone7827a72008-07-15 18:44:13 -07001517 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1518 IEEE80211_STYPE_ACTION);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001519
1520 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1521
1522 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1523 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1524 params = (u16)(initiator << 11); /* bit 11 initiator */
1525 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1526
1527 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1528 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1529
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001530 ieee80211_sta_tx(sdata, skb, 0);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001531}
1532
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001533void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
Ron Rindjunsky429a3802008-07-01 14:16:03 +03001534{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001535 struct ieee80211_local *local = sdata->local;
Ron Rindjunsky429a3802008-07-01 14:16:03 +03001536 struct sk_buff *skb;
1537 struct ieee80211_bar *bar;
1538 u16 bar_control = 0;
1539
1540 skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
1541 if (!skb) {
1542 printk(KERN_ERR "%s: failed to allocate buffer for "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001543 "bar frame\n", sdata->dev->name);
Ron Rindjunsky429a3802008-07-01 14:16:03 +03001544 return;
1545 }
1546 skb_reserve(skb, local->hw.extra_tx_headroom);
1547 bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
1548 memset(bar, 0, sizeof(*bar));
Harvey Harrisone7827a72008-07-15 18:44:13 -07001549 bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
1550 IEEE80211_STYPE_BACK_REQ);
Ron Rindjunsky429a3802008-07-01 14:16:03 +03001551 memcpy(bar->ra, ra, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001552 memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN);
Ron Rindjunsky429a3802008-07-01 14:16:03 +03001553 bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
1554 bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
1555 bar_control |= (u16)(tid << 12);
1556 bar->control = cpu_to_le16(bar_control);
1557 bar->start_seq_num = cpu_to_le16(ssn);
1558
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001559 ieee80211_sta_tx(sdata, skb, 0);
Ron Rindjunsky429a3802008-07-01 14:16:03 +03001560}
1561
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001562void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid,
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001563 u16 initiator, u16 reason)
1564{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001565 struct ieee80211_local *local = sdata->local;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001566 struct ieee80211_hw *hw = &local->hw;
1567 struct sta_info *sta;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001568 int ret, i;
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001569 DECLARE_MAC_BUF(mac);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001570
Johannes Bergd0709a62008-02-25 16:27:46 +01001571 rcu_read_lock();
1572
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001573 sta = sta_info_get(local, ra);
Johannes Bergd0709a62008-02-25 16:27:46 +01001574 if (!sta) {
1575 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001576 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001577 }
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001578
1579 /* check if TID is in operational state */
Johannes Berg07346f812008-05-03 01:02:02 +02001580 spin_lock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001581 if (sta->ampdu_mlme.tid_state_rx[tid]
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001582 != HT_AGG_STATE_OPERATIONAL) {
Johannes Berg07346f812008-05-03 01:02:02 +02001583 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +01001584 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001585 return;
1586 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001587 sta->ampdu_mlme.tid_state_rx[tid] =
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001588 HT_AGG_STATE_REQ_STOP_BA_MSK |
1589 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
Johannes Berg07346f812008-05-03 01:02:02 +02001590 spin_unlock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001591
1592 /* stop HW Rx aggregation. ampdu_action existence
1593 * already verified in session init so we add the BUG_ON */
1594 BUG_ON(!local->ops->ampdu_action);
1595
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001596#ifdef CONFIG_MAC80211_HT_DEBUG
1597 printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n",
1598 print_mac(mac, ra), tid);
1599#endif /* CONFIG_MAC80211_HT_DEBUG */
1600
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001601 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001602 ra, tid, NULL);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001603 if (ret)
1604 printk(KERN_DEBUG "HW problem - can not stop rx "
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001605 "aggregation for tid %d\n", tid);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001606
1607 /* shutdown timer has not expired */
1608 if (initiator != WLAN_BACK_TIMER)
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001609 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001610
1611 /* check if this is a self generated aggregation halt */
1612 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001613 ieee80211_send_delba(sdata, ra, tid, 0, reason);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001614
1615 /* free the reordering buffer */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001616 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
1617 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001618 /* release the reordered frames */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001619 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
1620 sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
1621 sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001622 }
1623 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001624 /* free resources */
1625 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
1626 kfree(sta->ampdu_mlme.tid_rx[tid]);
1627 sta->ampdu_mlme.tid_rx[tid] = NULL;
1628 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001629
Johannes Bergd0709a62008-02-25 16:27:46 +01001630 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001631}
1632
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001633
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001634static void ieee80211_sta_process_delba(struct ieee80211_sub_if_data *sdata,
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001635 struct ieee80211_mgmt *mgmt, size_t len)
1636{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001637 struct ieee80211_local *local = sdata->local;
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001638 struct sta_info *sta;
1639 u16 tid, params;
1640 u16 initiator;
1641 DECLARE_MAC_BUF(mac);
1642
Johannes Bergd0709a62008-02-25 16:27:46 +01001643 rcu_read_lock();
1644
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001645 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001646 if (!sta) {
1647 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001648 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001649 }
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001650
1651 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1652 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1653 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1654
1655#ifdef CONFIG_MAC80211_HT_DEBUG
1656 if (net_ratelimit())
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001657 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1658 print_mac(mac, mgmt->sa),
Ron Rindjunsky2e354ed2008-03-18 15:00:30 -07001659 initiator ? "initiator" : "recipient", tid,
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001660 mgmt->u.action.u.delba.reason_code);
1661#endif /* CONFIG_MAC80211_HT_DEBUG */
1662
1663 if (initiator == WLAN_BACK_INITIATOR)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001664 ieee80211_sta_stop_rx_ba_session(sdata, sta->addr, tid,
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001665 WLAN_BACK_INITIATOR, 0);
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001666 else { /* WLAN_BACK_RECIPIENT */
Johannes Berg07346f812008-05-03 01:02:02 +02001667 spin_lock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001668 sta->ampdu_mlme.tid_state_tx[tid] =
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001669 HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001670 spin_unlock_bh(&sta->lock);
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001671 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1672 WLAN_BACK_RECIPIENT);
1673 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001674 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001675}
1676
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001677/*
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001678 * After sending add Block Ack request we activated a timer until
1679 * add Block Ack response will arrive from the recipient.
1680 * If this timer expires sta_addba_resp_timer_expired will be executed.
1681 */
1682void sta_addba_resp_timer_expired(unsigned long data)
1683{
1684 /* not an elegant detour, but there is no choice as the timer passes
1685 * only one argument, and both sta_info and TID are needed, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001686 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001687 * array gives the sta through container_of */
Senthil Balasubramanian70d251b2008-05-28 20:08:12 +05301688 u16 tid = *(u8 *)data;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001689 struct sta_info *temp_sta = container_of((void *)data,
1690 struct sta_info, timer_to_tid[tid]);
1691
1692 struct ieee80211_local *local = temp_sta->local;
1693 struct ieee80211_hw *hw = &local->hw;
1694 struct sta_info *sta;
1695 u8 *state;
1696
Johannes Bergd0709a62008-02-25 16:27:46 +01001697 rcu_read_lock();
1698
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001699 sta = sta_info_get(local, temp_sta->addr);
Johannes Bergd0709a62008-02-25 16:27:46 +01001700 if (!sta) {
1701 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001702 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001703 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001704
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001705 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001706 /* check if the TID waits for addBA response */
Johannes Berg07346f812008-05-03 01:02:02 +02001707 spin_lock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001708 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
Johannes Berg07346f812008-05-03 01:02:02 +02001709 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001710 *state = HT_AGG_STATE_IDLE;
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001711#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001712 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1713 "expecting addBA response there", tid);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001714#endif
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001715 goto timer_expired_exit;
1716 }
1717
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001718#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001719 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001720#endif
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001721
1722 /* go through the state check in stop_BA_session */
1723 *state = HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001724 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001725 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1726 WLAN_BACK_INITIATOR);
1727
1728timer_expired_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001729 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001730}
1731
1732/*
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001733 * After accepting the AddBA Request we activated a timer,
1734 * resetting it after each frame that arrives from the originator.
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001735 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1736 */
Adrian Bunk712590d2008-04-21 11:47:51 +03001737static void sta_rx_agg_session_timer_expired(unsigned long data)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001738{
1739 /* not an elegant detour, but there is no choice as the timer passes
Senthil Balasubramanian70d251b2008-05-28 20:08:12 +05301740 * only one argument, and various sta_info are needed here, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001741 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001742 * array gives the sta through container_of */
1743 u8 *ptid = (u8 *)data;
1744 u8 *timer_to_id = ptid - *ptid;
1745 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1746 timer_to_tid[0]);
1747
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001748#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001749 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001750#endif
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001751 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->addr,
Johannes Bergd0709a62008-02-25 16:27:46 +01001752 (u16)*ptid, WLAN_BACK_TIMER,
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001753 WLAN_REASON_QSTA_TIMEOUT);
1754}
1755
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001756void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr)
Ron Rindjunsky85249e52008-03-18 15:00:32 -07001757{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001758 struct ieee80211_local *local = sdata->local;
Ron Rindjunsky85249e52008-03-18 15:00:32 -07001759 int i;
1760
1761 for (i = 0; i < STA_TID_NUM; i++) {
1762 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
1763 WLAN_BACK_INITIATOR);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001764 ieee80211_sta_stop_rx_ba_session(sdata, addr, i,
Ron Rindjunsky85249e52008-03-18 15:00:32 -07001765 WLAN_BACK_RECIPIENT,
1766 WLAN_REASON_QSTA_LEAVE_QBSS);
1767 }
1768}
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001769
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001770static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_data *sdata,
Assaf Kraussb6623482008-06-16 16:09:49 +03001771 struct ieee80211_msrment_ie *request_ie,
1772 const u8 *da, const u8 *bssid,
1773 u8 dialog_token)
1774{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001775 struct ieee80211_local *local = sdata->local;
Assaf Kraussb6623482008-06-16 16:09:49 +03001776 struct sk_buff *skb;
1777 struct ieee80211_mgmt *msr_report;
1778
1779 skb = dev_alloc_skb(sizeof(*msr_report) + local->hw.extra_tx_headroom +
1780 sizeof(struct ieee80211_msrment_ie));
1781
1782 if (!skb) {
1783 printk(KERN_ERR "%s: failed to allocate buffer for "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001784 "measurement report frame\n", sdata->dev->name);
Assaf Kraussb6623482008-06-16 16:09:49 +03001785 return;
1786 }
1787
1788 skb_reserve(skb, local->hw.extra_tx_headroom);
1789 msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24);
1790 memset(msr_report, 0, 24);
1791 memcpy(msr_report->da, da, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001792 memcpy(msr_report->sa, sdata->dev->dev_addr, ETH_ALEN);
Assaf Kraussb6623482008-06-16 16:09:49 +03001793 memcpy(msr_report->bssid, bssid, ETH_ALEN);
Harvey Harrisone7827a72008-07-15 18:44:13 -07001794 msr_report->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
Assaf Kraussb6623482008-06-16 16:09:49 +03001795 IEEE80211_STYPE_ACTION);
1796
1797 skb_put(skb, 1 + sizeof(msr_report->u.action.u.measurement));
1798 msr_report->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT;
1799 msr_report->u.action.u.measurement.action_code =
1800 WLAN_ACTION_SPCT_MSR_RPRT;
1801 msr_report->u.action.u.measurement.dialog_token = dialog_token;
1802
1803 msr_report->u.action.u.measurement.element_id = WLAN_EID_MEASURE_REPORT;
1804 msr_report->u.action.u.measurement.length =
1805 sizeof(struct ieee80211_msrment_ie);
1806
1807 memset(&msr_report->u.action.u.measurement.msr_elem, 0,
1808 sizeof(struct ieee80211_msrment_ie));
1809 msr_report->u.action.u.measurement.msr_elem.token = request_ie->token;
1810 msr_report->u.action.u.measurement.msr_elem.mode |=
1811 IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED;
1812 msr_report->u.action.u.measurement.msr_elem.type = request_ie->type;
1813
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001814 ieee80211_sta_tx(sdata, skb, 0);
Assaf Kraussb6623482008-06-16 16:09:49 +03001815}
1816
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001817static void ieee80211_sta_process_measurement_req(struct ieee80211_sub_if_data *sdata,
Assaf Kraussb6623482008-06-16 16:09:49 +03001818 struct ieee80211_mgmt *mgmt,
1819 size_t len)
1820{
1821 /*
1822 * Ignoring measurement request is spec violation.
1823 * Mandatory measurements must be reported optional
1824 * measurements might be refused or reported incapable
1825 * For now just refuse
1826 * TODO: Answer basic measurement as unmeasured
1827 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001828 ieee80211_send_refuse_measurement_request(sdata,
Assaf Kraussb6623482008-06-16 16:09:49 +03001829 &mgmt->u.action.u.measurement.msr_elem,
1830 mgmt->sa, mgmt->bssid,
1831 mgmt->u.action.u.measurement.dialog_token);
1832}
1833
1834
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001835static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001836 struct ieee80211_if_sta *ifsta,
1837 struct ieee80211_mgmt *mgmt,
1838 size_t len)
1839{
Jiri Bencf0706e82007-05-05 11:45:53 -07001840 u16 auth_alg, auth_transaction, status_code;
Joe Perches0795af52007-10-03 17:59:30 -07001841 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001842
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001843 if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001844 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001845 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001846
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001847 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001848 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001849
Johannes Berg51fb61e2007-12-19 01:31:27 +01001850 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001851 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001852 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001853
Johannes Berg51fb61e2007-12-19 01:31:27 +01001854 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001855 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001856 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001857
1858 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1859 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1860 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1861
Johannes Berg51fb61e2007-12-19 01:31:27 +01001862 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Johannes Berg135a2112008-06-16 20:55:29 +02001863 /*
1864 * IEEE 802.11 standard does not require authentication in IBSS
Jiri Bencf0706e82007-05-05 11:45:53 -07001865 * networks and most implementations do not seem to use it.
1866 * However, try to reply to authentication attempts if someone
1867 * has actually implemented this.
Johannes Berg135a2112008-06-16 20:55:29 +02001868 */
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001869 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1)
Jiri Bencf0706e82007-05-05 11:45:53 -07001870 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001871 ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07001872 }
1873
1874 if (auth_alg != ifsta->auth_alg ||
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001875 auth_transaction != ifsta->auth_transaction)
Jiri Bencf0706e82007-05-05 11:45:53 -07001876 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001877
1878 if (status_code != WLAN_STATUS_SUCCESS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001879 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1880 u8 algs[3];
1881 const int num_algs = ARRAY_SIZE(algs);
1882 int i, pos;
1883 algs[0] = algs[1] = algs[2] = 0xff;
1884 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1885 algs[0] = WLAN_AUTH_OPEN;
1886 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1887 algs[1] = WLAN_AUTH_SHARED_KEY;
1888 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1889 algs[2] = WLAN_AUTH_LEAP;
1890 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1891 pos = 0;
1892 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1893 pos = 1;
1894 else
1895 pos = 2;
1896 for (i = 0; i < num_algs; i++) {
1897 pos++;
1898 if (pos >= num_algs)
1899 pos = 0;
1900 if (algs[pos] == ifsta->auth_alg ||
1901 algs[pos] == 0xff)
1902 continue;
1903 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001904 !ieee80211_sta_wep_configured(sdata))
Jiri Bencf0706e82007-05-05 11:45:53 -07001905 continue;
1906 ifsta->auth_alg = algs[pos];
Jiri Bencf0706e82007-05-05 11:45:53 -07001907 break;
1908 }
1909 }
1910 return;
1911 }
1912
1913 switch (ifsta->auth_alg) {
1914 case WLAN_AUTH_OPEN:
1915 case WLAN_AUTH_LEAP:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001916 ieee80211_auth_completed(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001917 break;
1918 case WLAN_AUTH_SHARED_KEY:
1919 if (ifsta->auth_transaction == 4)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001920 ieee80211_auth_completed(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001921 else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001922 ieee80211_auth_challenge(sdata, ifsta, mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001923 break;
1924 }
1925}
1926
1927
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001928static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001929 struct ieee80211_if_sta *ifsta,
1930 struct ieee80211_mgmt *mgmt,
1931 size_t len)
1932{
1933 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001934 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001935
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001936 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001937 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001938
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001939 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001940 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001941
1942 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1943
Johannes Berg988c0f72008-04-17 19:21:22 +02001944 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001945 printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001946
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001947 if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1948 ifsta->state == IEEE80211_STA_MLME_ASSOCIATE ||
1949 ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
1950 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001951 mod_timer(&ifsta->timer, jiffies +
1952 IEEE80211_RETRY_AUTH_INTERVAL);
1953 }
1954
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001955 ieee80211_set_disassoc(sdata, ifsta, 1);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001956 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001957}
1958
1959
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001960static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001961 struct ieee80211_if_sta *ifsta,
1962 struct ieee80211_mgmt *mgmt,
1963 size_t len)
1964{
1965 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001966 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001967
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001968 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001969 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001970
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001971 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001972 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001973
1974 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1975
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001976 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001977 printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001978
Tomas Winkler48c2fc52008-08-06 14:22:01 +03001979 if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
1980 ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001981 mod_timer(&ifsta->timer, jiffies +
1982 IEEE80211_RETRY_AUTH_INTERVAL);
1983 }
1984
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001985 ieee80211_set_disassoc(sdata, ifsta, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07001986}
1987
1988
Johannes Berg471b3ef2007-12-28 14:32:58 +01001989static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001990 struct ieee80211_if_sta *ifsta,
1991 struct ieee80211_mgmt *mgmt,
1992 size_t len,
1993 int reassoc)
1994{
Johannes Berg471b3ef2007-12-28 14:32:58 +01001995 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001996 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001997 struct sta_info *sta;
Johannes Berg8318d782008-01-24 19:38:38 +01001998 u64 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07001999 u16 capab_info, status_code, aid;
2000 struct ieee802_11_elems elems;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002001 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07002002 u8 *pos;
2003 int i, j;
Joe Perches0795af52007-10-03 17:59:30 -07002004 DECLARE_MAC_BUF(mac);
Johannes Berg8318d782008-01-24 19:38:38 +01002005 bool have_higher_than_11mbit = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002006
2007 /* AssocResp and ReassocResp have identical structure, so process both
2008 * of them in this function. */
2009
Tomas Winkler48c2fc52008-08-06 14:22:01 +03002010 if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07002011 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002012
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002013 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07002014 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002015
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002016 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07002017 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002018
2019 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2020 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2021 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e82007-05-05 11:45:53 -07002022
Joe Perches0795af52007-10-03 17:59:30 -07002023 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07002024 "status=%d aid=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002025 sdata->dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
Johannes Bergddd68582007-10-22 14:51:37 +02002026 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07002027
2028 if (status_code != WLAN_STATUS_SUCCESS) {
2029 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002030 sdata->dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02002031 /* if this was a reassociation, ensure we try a "full"
2032 * association next time. This works around some broken APs
2033 * which do not correctly reject reassociation requests. */
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002034 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -07002035 return;
2036 }
2037
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002038 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2039 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002040 "set\n", sdata->dev->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002041 aid &= ~(BIT(15) | BIT(14));
2042
Jiri Bencf0706e82007-05-05 11:45:53 -07002043 pos = mgmt->u.assoc_resp.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04002044 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Jiri Bencf0706e82007-05-05 11:45:53 -07002045
2046 if (!elems.supp_rates) {
2047 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002048 sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07002049 return;
2050 }
2051
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002052 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07002053 ifsta->aid = aid;
2054 ifsta->ap_capab = capab_info;
2055
2056 kfree(ifsta->assocresp_ies);
2057 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
Michael Wu0ec0b7a2007-07-27 15:43:24 +02002058 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07002059 if (ifsta->assocresp_ies)
2060 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
2061
Johannes Bergd0709a62008-02-25 16:27:46 +01002062 rcu_read_lock();
2063
Jiri Bencf0706e82007-05-05 11:45:53 -07002064 /* Add STA entry for the AP */
2065 sta = sta_info_get(local, ifsta->bssid);
2066 if (!sta) {
2067 struct ieee80211_sta_bss *bss;
Johannes Berg73651ee2008-02-25 16:27:47 +01002068 int err;
Johannes Bergd0709a62008-02-25 16:27:46 +01002069
Johannes Berg73651ee2008-02-25 16:27:47 +01002070 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
2071 if (!sta) {
2072 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002073 " the AP\n", sdata->dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01002074 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002075 return;
2076 }
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002077 bss = ieee80211_rx_bss_get(local, ifsta->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01002078 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002079 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002080 if (bss) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002081 sta->last_signal = bss->signal;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002082 sta->last_qual = bss->qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07002083 sta->last_noise = bss->noise;
Johannes Berg3e122be2008-07-09 14:40:34 +02002084 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07002085 }
Johannes Berg73651ee2008-02-25 16:27:47 +01002086
2087 err = sta_info_insert(sta);
2088 if (err) {
2089 printk(KERN_DEBUG "%s: failed to insert STA entry for"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002090 " the AP (error %d)\n", sdata->dev->name, err);
Johannes Berg73651ee2008-02-25 16:27:47 +01002091 rcu_read_unlock();
2092 return;
2093 }
Ron Rindjunskya61dae12008-08-10 00:54:34 +03002094 /* update new sta with its last rx activity */
2095 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -07002096 }
2097
Johannes Berg73651ee2008-02-25 16:27:47 +01002098 /*
2099 * FIXME: Do we really need to update the sta_info's information here?
2100 * We already know about the AP (we found it in our list) so it
2101 * should already be filled with the right info, no?
2102 * As is stands, all this is racy because typically we assume
2103 * the information that is filled in here (except flags) doesn't
2104 * change while a STA structure is alive. As such, it should move
2105 * to between the sta_info_alloc() and sta_info_insert() above.
2106 */
2107
Johannes Berg07346f812008-05-03 01:02:02 +02002108 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
2109 WLAN_STA_AUTHORIZED);
Jiri Bencf0706e82007-05-05 11:45:53 -07002110
2111 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002112 basic_rates = 0;
2113 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2114
Jiri Bencf0706e82007-05-05 11:45:53 -07002115 for (i = 0; i < elems.supp_rates_len; i++) {
2116 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01002117
2118 if (rate > 110)
2119 have_higher_than_11mbit = true;
2120
2121 for (j = 0; j < sband->n_bitrates; j++) {
2122 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e82007-05-05 11:45:53 -07002123 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01002124 if (elems.supp_rates[i] & 0x80)
2125 basic_rates |= BIT(j);
2126 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002127 }
Johannes Berg8318d782008-01-24 19:38:38 +01002128
Jiri Bencf0706e82007-05-05 11:45:53 -07002129 for (i = 0; i < elems.ext_supp_rates_len; i++) {
2130 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01002131
2132 if (rate > 110)
2133 have_higher_than_11mbit = true;
2134
2135 for (j = 0; j < sband->n_bitrates; j++) {
2136 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e82007-05-05 11:45:53 -07002137 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01002138 if (elems.ext_supp_rates[i] & 0x80)
2139 basic_rates |= BIT(j);
2140 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002141 }
Johannes Berg8318d782008-01-24 19:38:38 +01002142
2143 sta->supp_rates[local->hw.conf.channel->band] = rates;
2144 sdata->basic_rates = basic_rates;
2145
2146 /* cf. IEEE 802.11 9.2.12 */
2147 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
2148 have_higher_than_11mbit)
2149 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
2150 else
2151 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002152
Johannes Berg3434fbd2008-05-03 00:59:37 +02002153 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
2154 (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002155 struct ieee80211_ht_bss_info bss_info;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002156 ieee80211_ht_cap_ie_to_ht_info(
2157 (struct ieee80211_ht_cap *)
2158 elems.ht_cap_elem, &sta->ht_info);
2159 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2160 (struct ieee80211_ht_addt_info *)
2161 elems.ht_info_elem, &bss_info);
Tomas Winkler38668c02008-03-28 16:33:32 -07002162 ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002163 }
2164
Jiri Bencf0706e82007-05-05 11:45:53 -07002165 rate_control_rate_init(sta, local);
2166
Johannes Berg3434fbd2008-05-03 00:59:37 +02002167 if (elems.wmm_param) {
Johannes Berg07346f812008-05-03 01:02:02 +02002168 set_sta_flags(sta, WLAN_STA_WME);
Johannes Berge5f98f22008-03-05 20:39:31 +01002169 rcu_read_unlock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002170 ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07002171 elems.wmm_param_len);
Johannes Berge5f98f22008-03-05 20:39:31 +01002172 } else
2173 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002174
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002175 /* set AID and assoc capability,
2176 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002177 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002178 bss_conf->assoc_capability = capab_info;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002179 ieee80211_set_associated(sdata, ifsta, 1);
Jiri Bencf0706e82007-05-05 11:45:53 -07002180
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002181 ieee80211_associated(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07002182}
2183
2184
2185/* Caller must hold local->sta_bss_lock */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002186static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local,
Jiri Bencf0706e82007-05-05 11:45:53 -07002187 struct ieee80211_sta_bss *bss)
2188{
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002189 u8 hash_idx;
Johannes Berg902acc72008-02-23 15:17:19 +01002190
2191 if (bss_mesh_cfg(bss))
2192 hash_idx = mesh_id_hash(bss_mesh_id(bss),
2193 bss_mesh_id_len(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002194 else
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002195 hash_idx = STA_HASH(bss->bssid);
Johannes Berg902acc72008-02-23 15:17:19 +01002196
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002197 bss->hnext = local->sta_bss_hash[hash_idx];
2198 local->sta_bss_hash[hash_idx] = bss;
Jiri Bencf0706e82007-05-05 11:45:53 -07002199}
2200
2201
2202/* Caller must hold local->sta_bss_lock */
Johannes Berg3e122be2008-07-09 14:40:34 +02002203static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local,
Jiri Bencf0706e82007-05-05 11:45:53 -07002204 struct ieee80211_sta_bss *bss)
2205{
Jiri Bencf0706e82007-05-05 11:45:53 -07002206 struct ieee80211_sta_bss *b, *prev = NULL;
2207 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
2208 while (b) {
2209 if (b == bss) {
2210 if (!prev)
2211 local->sta_bss_hash[STA_HASH(bss->bssid)] =
2212 bss->hnext;
2213 else
2214 prev->hnext = bss->hnext;
2215 break;
2216 }
2217 prev = b;
2218 b = b->hnext;
2219 }
2220}
2221
2222
2223static struct ieee80211_sta_bss *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002224ieee80211_rx_bss_add(struct ieee80211_sub_if_data *sdata, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002225 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002226{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002227 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002228 struct ieee80211_sta_bss *bss;
2229
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002230 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
Jiri Bencf0706e82007-05-05 11:45:53 -07002231 if (!bss)
2232 return NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07002233 atomic_inc(&bss->users);
2234 atomic_inc(&bss->users);
2235 memcpy(bss->bssid, bssid, ETH_ALEN);
Johannes Berg8318d782008-01-24 19:38:38 +01002236 bss->freq = freq;
John W. Linvillecffdd302007-10-05 14:23:27 -04002237 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
2238 memcpy(bss->ssid, ssid, ssid_len);
2239 bss->ssid_len = ssid_len;
2240 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002241
2242 spin_lock_bh(&local->sta_bss_lock);
2243 /* TODO: order by RSSI? */
2244 list_add_tail(&bss->list, &local->sta_bss_list);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002245 __ieee80211_rx_bss_hash_add(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07002246 spin_unlock_bh(&local->sta_bss_lock);
2247 return bss;
2248}
2249
Jiri Bencf0706e82007-05-05 11:45:53 -07002250static struct ieee80211_sta_bss *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002251ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002252 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002253{
Jiri Bencf0706e82007-05-05 11:45:53 -07002254 struct ieee80211_sta_bss *bss;
2255
2256 spin_lock_bh(&local->sta_bss_lock);
2257 bss = local->sta_bss_hash[STA_HASH(bssid)];
2258 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002259 if (!bss_mesh_cfg(bss) &&
2260 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
Johannes Berg8318d782008-01-24 19:38:38 +01002261 bss->freq == freq &&
John W. Linvillecffdd302007-10-05 14:23:27 -04002262 bss->ssid_len == ssid_len &&
2263 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002264 atomic_inc(&bss->users);
2265 break;
2266 }
2267 bss = bss->hnext;
2268 }
2269 spin_unlock_bh(&local->sta_bss_lock);
2270 return bss;
2271}
2272
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002273#ifdef CONFIG_MAC80211_MESH
2274static struct ieee80211_sta_bss *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002275ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002276 u8 *mesh_cfg, int freq)
2277{
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002278 struct ieee80211_sta_bss *bss;
2279
2280 spin_lock_bh(&local->sta_bss_lock);
2281 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2282 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002283 if (bss_mesh_cfg(bss) &&
2284 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002285 bss->freq == freq &&
2286 mesh_id_len == bss->mesh_id_len &&
2287 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2288 mesh_id_len))) {
2289 atomic_inc(&bss->users);
2290 break;
2291 }
2292 bss = bss->hnext;
2293 }
2294 spin_unlock_bh(&local->sta_bss_lock);
2295 return bss;
2296}
2297
2298static struct ieee80211_sta_bss *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002299ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002300 u8 *mesh_cfg, int mesh_config_len, int freq)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002301{
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002302 struct ieee80211_sta_bss *bss;
2303
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002304 if (mesh_config_len != MESH_CFG_LEN)
2305 return NULL;
2306
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002307 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2308 if (!bss)
2309 return NULL;
2310
John W. Linville24736702008-04-08 14:15:46 -04002311 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002312 if (!bss->mesh_cfg) {
2313 kfree(bss);
2314 return NULL;
2315 }
2316
2317 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2318 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2319 if (!bss->mesh_id) {
2320 kfree(bss->mesh_cfg);
2321 kfree(bss);
2322 return NULL;
2323 }
2324 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2325 }
2326
2327 atomic_inc(&bss->users);
2328 atomic_inc(&bss->users);
John W. Linville24736702008-04-08 14:15:46 -04002329 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002330 bss->mesh_id_len = mesh_id_len;
2331 bss->freq = freq;
2332 spin_lock_bh(&local->sta_bss_lock);
2333 /* TODO: order by RSSI? */
2334 list_add_tail(&bss->list, &local->sta_bss_list);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002335 __ieee80211_rx_bss_hash_add(local, bss);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002336 spin_unlock_bh(&local->sta_bss_lock);
2337 return bss;
2338}
2339#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07002340
2341static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2342{
2343 kfree(bss->wpa_ie);
2344 kfree(bss->rsn_ie);
2345 kfree(bss->wmm_ie);
Ron Rindjunskyc7153502007-11-26 16:14:31 +02002346 kfree(bss->ht_ie);
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002347 kfree(bss->ht_add_ie);
Johannes Berg902acc72008-02-23 15:17:19 +01002348 kfree(bss_mesh_id(bss));
2349 kfree(bss_mesh_cfg(bss));
Jiri Bencf0706e82007-05-05 11:45:53 -07002350 kfree(bss);
2351}
2352
2353
Johannes Berg3e122be2008-07-09 14:40:34 +02002354static void ieee80211_rx_bss_put(struct ieee80211_local *local,
Jiri Bencf0706e82007-05-05 11:45:53 -07002355 struct ieee80211_sta_bss *bss)
2356{
Pavel Emelyanov1ebebea2008-04-23 11:47:15 +04002357 local_bh_disable();
2358 if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
2359 local_bh_enable();
2360 return;
2361 }
2362
Johannes Berg3e122be2008-07-09 14:40:34 +02002363 __ieee80211_rx_bss_hash_del(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07002364 list_del(&bss->list);
2365 spin_unlock_bh(&local->sta_bss_lock);
2366 ieee80211_rx_bss_free(bss);
2367}
2368
2369
Johannes Berg3e122be2008-07-09 14:40:34 +02002370void ieee80211_rx_bss_list_init(struct ieee80211_local *local)
Jiri Bencf0706e82007-05-05 11:45:53 -07002371{
Jiri Bencf0706e82007-05-05 11:45:53 -07002372 spin_lock_init(&local->sta_bss_lock);
2373 INIT_LIST_HEAD(&local->sta_bss_list);
2374}
2375
2376
Johannes Berg3e122be2008-07-09 14:40:34 +02002377void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local)
Jiri Bencf0706e82007-05-05 11:45:53 -07002378{
Jiri Bencf0706e82007-05-05 11:45:53 -07002379 struct ieee80211_sta_bss *bss, *tmp;
2380
2381 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
Johannes Berg3e122be2008-07-09 14:40:34 +02002382 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07002383}
2384
2385
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002386static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
Bruno Randolfa6072682008-02-18 11:21:15 +09002387 struct ieee80211_if_sta *ifsta,
2388 struct ieee80211_sta_bss *bss)
2389{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002390 struct ieee80211_local *local = sdata->local;
Bruno Randolfa6072682008-02-18 11:21:15 +09002391 int res, rates, i, j;
2392 struct sk_buff *skb;
2393 struct ieee80211_mgmt *mgmt;
Bruno Randolfa6072682008-02-18 11:21:15 +09002394 u8 *pos;
Bruno Randolfa6072682008-02-18 11:21:15 +09002395 struct ieee80211_supported_band *sband;
Dan Williams507b06d2008-06-03 23:39:55 -04002396 union iwreq_data wrqu;
Bruno Randolfa6072682008-02-18 11:21:15 +09002397
2398 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2399
2400 /* Remove possible STA entries from other IBSS networks. */
Johannes Bergdc6676b2008-03-31 19:23:03 +02002401 sta_info_flush_delayed(sdata);
Bruno Randolfa6072682008-02-18 11:21:15 +09002402
2403 if (local->ops->reset_tsf) {
2404 /* Reset own TSF to allow time synchronization work. */
2405 local->ops->reset_tsf(local_to_hw(local));
2406 }
2407 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
Johannes Berg9d139c82008-07-09 14:40:37 +02002408 res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
Bruno Randolfa6072682008-02-18 11:21:15 +09002409 if (res)
2410 return res;
2411
2412 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2413
Bruno Randolfa6072682008-02-18 11:21:15 +09002414 sdata->drop_unencrypted = bss->capability &
2415 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2416
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002417 res = ieee80211_set_freq(sdata, bss->freq);
Bruno Randolfa6072682008-02-18 11:21:15 +09002418
Assaf Kraussbe038b32008-06-05 19:55:21 +03002419 if (res)
2420 return res;
Bruno Randolfa6072682008-02-18 11:21:15 +09002421
Johannes Berg9d139c82008-07-09 14:40:37 +02002422 /* Build IBSS probe response */
Bruno Randolfa6072682008-02-18 11:21:15 +09002423 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
Johannes Berg9d139c82008-07-09 14:40:37 +02002424 if (skb) {
Bruno Randolfa6072682008-02-18 11:21:15 +09002425 skb_reserve(skb, local->hw.extra_tx_headroom);
2426
2427 mgmt = (struct ieee80211_mgmt *)
2428 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2429 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
Harvey Harrisone7827a72008-07-15 18:44:13 -07002430 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2431 IEEE80211_STYPE_PROBE_RESP);
Bruno Randolfa6072682008-02-18 11:21:15 +09002432 memset(mgmt->da, 0xff, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002433 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Bruno Randolfa6072682008-02-18 11:21:15 +09002434 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2435 mgmt->u.beacon.beacon_int =
2436 cpu_to_le16(local->hw.conf.beacon_int);
Assaf Krauss4faeb862008-06-30 17:23:16 +08002437 mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp);
Bruno Randolfa6072682008-02-18 11:21:15 +09002438 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2439
2440 pos = skb_put(skb, 2 + ifsta->ssid_len);
2441 *pos++ = WLAN_EID_SSID;
2442 *pos++ = ifsta->ssid_len;
2443 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2444
2445 rates = bss->supp_rates_len;
2446 if (rates > 8)
2447 rates = 8;
2448 pos = skb_put(skb, 2 + rates);
2449 *pos++ = WLAN_EID_SUPP_RATES;
2450 *pos++ = rates;
2451 memcpy(pos, bss->supp_rates, rates);
2452
2453 if (bss->band == IEEE80211_BAND_2GHZ) {
2454 pos = skb_put(skb, 2 + 1);
2455 *pos++ = WLAN_EID_DS_PARAMS;
2456 *pos++ = 1;
2457 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2458 }
2459
2460 pos = skb_put(skb, 2 + 2);
2461 *pos++ = WLAN_EID_IBSS_PARAMS;
2462 *pos++ = 2;
2463 /* FIX: set ATIM window based on scan results */
2464 *pos++ = 0;
2465 *pos++ = 0;
2466
2467 if (bss->supp_rates_len > 8) {
2468 rates = bss->supp_rates_len - 8;
2469 pos = skb_put(skb, 2 + rates);
2470 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2471 *pos++ = rates;
2472 memcpy(pos, &bss->supp_rates[8], rates);
2473 }
2474
Johannes Berg9d139c82008-07-09 14:40:37 +02002475 ifsta->probe_resp = skb;
Johannes Berge039fa42008-05-15 12:55:29 +02002476
Johannes Berg9d139c82008-07-09 14:40:37 +02002477 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Bruno Randolfa6072682008-02-18 11:21:15 +09002478 }
2479
Johannes Berg9d139c82008-07-09 14:40:37 +02002480 rates = 0;
2481 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2482 for (i = 0; i < bss->supp_rates_len; i++) {
2483 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2484 for (j = 0; j < sband->n_bitrates; j++)
2485 if (sband->bitrates[j].bitrate == bitrate)
2486 rates |= BIT(j);
2487 }
2488 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
2489
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002490 ieee80211_sta_def_wmm_params(sdata, bss, 1);
Johannes Berg9d139c82008-07-09 14:40:37 +02002491
Tomas Winkler48c2fc52008-08-06 14:22:01 +03002492 ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED;
Bruno Randolfa6072682008-02-18 11:21:15 +09002493 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2494
Dan Williams507b06d2008-06-03 23:39:55 -04002495 memset(&wrqu, 0, sizeof(wrqu));
2496 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002497 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
Bruno Randolfa6072682008-02-18 11:21:15 +09002498
2499 return res;
2500}
2501
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002502u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2503 struct ieee802_11_elems *elems,
2504 enum ieee80211_band band)
2505{
2506 struct ieee80211_supported_band *sband;
2507 struct ieee80211_rate *bitrates;
2508 size_t num_rates;
2509 u64 supp_rates;
2510 int i, j;
2511 sband = local->hw.wiphy->bands[band];
2512
2513 if (!sband) {
2514 WARN_ON(1);
2515 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2516 }
2517
2518 bitrates = sband->bitrates;
2519 num_rates = sband->n_bitrates;
2520 supp_rates = 0;
2521 for (i = 0; i < elems->supp_rates_len +
2522 elems->ext_supp_rates_len; i++) {
2523 u8 rate = 0;
2524 int own_rate;
2525 if (i < elems->supp_rates_len)
2526 rate = elems->supp_rates[i];
2527 else if (elems->ext_supp_rates)
2528 rate = elems->ext_supp_rates
2529 [i - elems->supp_rates_len];
2530 own_rate = 5 * (rate & 0x7f);
2531 for (j = 0; j < num_rates; j++)
2532 if (bitrates[j].bitrate == own_rate)
2533 supp_rates |= BIT(j);
2534 }
2535 return supp_rates;
2536}
2537
Bruno Randolfa6072682008-02-18 11:21:15 +09002538
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002539static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002540 struct ieee80211_mgmt *mgmt,
2541 size_t len,
2542 struct ieee80211_rx_status *rx_status,
Ester Kummerae6a44e2008-06-27 18:54:48 +03002543 struct ieee802_11_elems *elems,
Jiri Bencf0706e82007-05-05 11:45:53 -07002544 int beacon)
2545{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002546 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002547 int freq, clen;
Jiri Bencf0706e82007-05-05 11:45:53 -07002548 struct ieee80211_sta_bss *bss;
2549 struct sta_info *sta;
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002550 u64 beacon_timestamp, rx_timestamp;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002551 struct ieee80211_channel *channel;
Joe Perches0795af52007-10-03 17:59:30 -07002552 DECLARE_MAC_BUF(mac);
2553 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e82007-05-05 11:45:53 -07002554
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002555 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
Jiri Bencf0706e82007-05-05 11:45:53 -07002556
Ester Kummerae6a44e2008-06-27 18:54:48 +03002557 if (ieee80211_vif_is_mesh(&sdata->vif) && elems->mesh_id &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002558 elems->mesh_config && mesh_matches_local(elems, sdata)) {
Ester Kummerae6a44e2008-06-27 18:54:48 +03002559 u64 rates = ieee80211_sta_get_rates(local, elems,
Johannes Berg902acc72008-02-23 15:17:19 +01002560 rx_status->band);
2561
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002562 mesh_neighbour_update(mgmt->sa, rates, sdata,
2563 mesh_peer_accepts_plinks(elems));
Johannes Berg902acc72008-02-23 15:17:19 +01002564 }
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002565
Johannes Bergd0709a62008-02-25 16:27:46 +01002566 rcu_read_lock();
2567
Ester Kummerae6a44e2008-06-27 18:54:48 +03002568 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems->supp_rates &&
Jiri Bencf0706e82007-05-05 11:45:53 -07002569 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2570 (sta = sta_info_get(local, mgmt->sa))) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002571 u64 prev_rates;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002572 u64 supp_rates = ieee80211_sta_get_rates(local, elems,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002573 rx_status->band);
Jiri Bencf0706e82007-05-05 11:45:53 -07002574
Johannes Berg8318d782008-01-24 19:38:38 +01002575 prev_rates = sta->supp_rates[rx_status->band];
2576 sta->supp_rates[rx_status->band] &= supp_rates;
2577 if (sta->supp_rates[rx_status->band] == 0) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002578 /* No matching rates - this should not really happen.
2579 * Make sure that at least one rate is marked
2580 * supported to avoid issues with TX rate ctrl. */
Johannes Berg8318d782008-01-24 19:38:38 +01002581 sta->supp_rates[rx_status->band] =
2582 sdata->u.sta.supp_rates_bits[rx_status->band];
Jiri Bencf0706e82007-05-05 11:45:53 -07002583 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002584 }
2585
Johannes Bergd0709a62008-02-25 16:27:46 +01002586 rcu_read_unlock();
2587
Ester Kummerae6a44e2008-06-27 18:54:48 +03002588 if (elems->ds_params && elems->ds_params_len == 1)
2589 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
Jiri Bencf0706e82007-05-05 11:45:53 -07002590 else
Johannes Berg8318d782008-01-24 19:38:38 +01002591 freq = rx_status->freq;
Jiri Bencf0706e82007-05-05 11:45:53 -07002592
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002593 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2594
2595 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2596 return;
2597
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002598#ifdef CONFIG_MAC80211_MESH
Ester Kummerae6a44e2008-06-27 18:54:48 +03002599 if (elems->mesh_config)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002600 bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id,
Ester Kummerae6a44e2008-06-27 18:54:48 +03002601 elems->mesh_id_len, elems->mesh_config, freq);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002602 else
2603#endif
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002604 bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq,
Ester Kummerae6a44e2008-06-27 18:54:48 +03002605 elems->ssid, elems->ssid_len);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002606 if (!bss) {
2607#ifdef CONFIG_MAC80211_MESH
Ester Kummerae6a44e2008-06-27 18:54:48 +03002608 if (elems->mesh_config)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002609 bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id,
Ester Kummerae6a44e2008-06-27 18:54:48 +03002610 elems->mesh_id_len, elems->mesh_config,
2611 elems->mesh_config_len, freq);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002612 else
2613#endif
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002614 bss = ieee80211_rx_bss_add(sdata, mgmt->bssid, freq,
Ester Kummerae6a44e2008-06-27 18:54:48 +03002615 elems->ssid, elems->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002616 if (!bss)
2617 return;
2618 } else {
2619#if 0
2620 /* TODO: order by RSSI? */
2621 spin_lock_bh(&local->sta_bss_lock);
2622 list_move_tail(&bss->list, &local->sta_bss_list);
2623 spin_unlock_bh(&local->sta_bss_lock);
2624#endif
2625 }
2626
Daniel Drake56282212007-07-10 19:32:10 +02002627 /* save the ERP value so that it is available at association time */
Ester Kummerae6a44e2008-06-27 18:54:48 +03002628 if (elems->erp_info && elems->erp_info_len >= 1) {
2629 bss->erp_value = elems->erp_info[0];
Daniel Drake56282212007-07-10 19:32:10 +02002630 bss->has_erp_value = 1;
2631 }
2632
Ester Kummerae6a44e2008-06-27 18:54:48 +03002633 if (elems->ht_cap_elem &&
2634 (!bss->ht_ie || bss->ht_ie_len != elems->ht_cap_elem_len ||
2635 memcmp(bss->ht_ie, elems->ht_cap_elem, elems->ht_cap_elem_len))) {
Johannes Berg30b89b02008-04-16 17:43:20 +02002636 kfree(bss->ht_ie);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002637 bss->ht_ie = kmalloc(elems->ht_cap_elem_len + 2, GFP_ATOMIC);
Johannes Berg30b89b02008-04-16 17:43:20 +02002638 if (bss->ht_ie) {
Ester Kummerae6a44e2008-06-27 18:54:48 +03002639 memcpy(bss->ht_ie, elems->ht_cap_elem - 2,
2640 elems->ht_cap_elem_len + 2);
2641 bss->ht_ie_len = elems->ht_cap_elem_len + 2;
Johannes Berg30b89b02008-04-16 17:43:20 +02002642 } else
2643 bss->ht_ie_len = 0;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002644 } else if (!elems->ht_cap_elem && bss->ht_ie) {
Johannes Berg30b89b02008-04-16 17:43:20 +02002645 kfree(bss->ht_ie);
2646 bss->ht_ie = NULL;
2647 bss->ht_ie_len = 0;
2648 }
2649
Ester Kummerae6a44e2008-06-27 18:54:48 +03002650 if (elems->ht_info_elem &&
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002651 (!bss->ht_add_ie ||
Ester Kummerae6a44e2008-06-27 18:54:48 +03002652 bss->ht_add_ie_len != elems->ht_info_elem_len ||
2653 memcmp(bss->ht_add_ie, elems->ht_info_elem,
2654 elems->ht_info_elem_len))) {
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002655 kfree(bss->ht_add_ie);
2656 bss->ht_add_ie =
Ester Kummerae6a44e2008-06-27 18:54:48 +03002657 kmalloc(elems->ht_info_elem_len + 2, GFP_ATOMIC);
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002658 if (bss->ht_add_ie) {
Ester Kummerae6a44e2008-06-27 18:54:48 +03002659 memcpy(bss->ht_add_ie, elems->ht_info_elem - 2,
2660 elems->ht_info_elem_len + 2);
2661 bss->ht_add_ie_len = elems->ht_info_elem_len + 2;
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002662 } else
2663 bss->ht_add_ie_len = 0;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002664 } else if (!elems->ht_info_elem && bss->ht_add_ie) {
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002665 kfree(bss->ht_add_ie);
2666 bss->ht_add_ie = NULL;
2667 bss->ht_add_ie_len = 0;
2668 }
2669
Jiri Bencf0706e82007-05-05 11:45:53 -07002670 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2671 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07002672
Emmanuel Grumbach98f7dfd2008-07-18 13:52:59 +08002673 if (elems->tim) {
2674 struct ieee80211_tim_ie *tim_ie =
2675 (struct ieee80211_tim_ie *)elems->tim;
2676 bss->dtim_period = tim_ie->dtim_period;
2677 }
2678
2679 /* set default value for buggy APs */
2680 if (!elems->tim || bss->dtim_period == 0)
2681 bss->dtim_period = 1;
2682
Jiri Bencf0706e82007-05-05 11:45:53 -07002683 bss->supp_rates_len = 0;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002684 if (elems->supp_rates) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002685 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002686 if (clen > elems->supp_rates_len)
2687 clen = elems->supp_rates_len;
2688 memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates,
Jiri Bencf0706e82007-05-05 11:45:53 -07002689 clen);
2690 bss->supp_rates_len += clen;
2691 }
Ester Kummerae6a44e2008-06-27 18:54:48 +03002692 if (elems->ext_supp_rates) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002693 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002694 if (clen > elems->ext_supp_rates_len)
2695 clen = elems->ext_supp_rates_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07002696 memcpy(&bss->supp_rates[bss->supp_rates_len],
Ester Kummerae6a44e2008-06-27 18:54:48 +03002697 elems->ext_supp_rates, clen);
Jiri Bencf0706e82007-05-05 11:45:53 -07002698 bss->supp_rates_len += clen;
2699 }
2700
Johannes Berg30b89b02008-04-16 17:43:20 +02002701 bss->band = rx_status->band;
2702
2703 bss->timestamp = beacon_timestamp;
2704 bss->last_update = jiffies;
Johannes Berg30b89b02008-04-16 17:43:20 +02002705 bss->signal = rx_status->signal;
2706 bss->noise = rx_status->noise;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002707 bss->qual = rx_status->qual;
Johannes Berg30b89b02008-04-16 17:43:20 +02002708 if (!beacon && !bss->probe_resp)
2709 bss->probe_resp = true;
2710
2711 /*
2712 * In STA mode, the remaining parameters should not be overridden
2713 * by beacons because they're not necessarily accurate there.
2714 */
2715 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2716 bss->probe_resp && beacon) {
Johannes Berg3e122be2008-07-09 14:40:34 +02002717 ieee80211_rx_bss_put(local, bss);
Johannes Berg30b89b02008-04-16 17:43:20 +02002718 return;
2719 }
2720
Ester Kummerae6a44e2008-06-27 18:54:48 +03002721 if (elems->wpa &&
2722 (!bss->wpa_ie || bss->wpa_ie_len != elems->wpa_len ||
2723 memcmp(bss->wpa_ie, elems->wpa, elems->wpa_len))) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002724 kfree(bss->wpa_ie);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002725 bss->wpa_ie = kmalloc(elems->wpa_len + 2, GFP_ATOMIC);
Jiri Bencf0706e82007-05-05 11:45:53 -07002726 if (bss->wpa_ie) {
Ester Kummerae6a44e2008-06-27 18:54:48 +03002727 memcpy(bss->wpa_ie, elems->wpa - 2, elems->wpa_len + 2);
2728 bss->wpa_ie_len = elems->wpa_len + 2;
Jiri Bencf0706e82007-05-05 11:45:53 -07002729 } else
2730 bss->wpa_ie_len = 0;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002731 } else if (!elems->wpa && bss->wpa_ie) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002732 kfree(bss->wpa_ie);
2733 bss->wpa_ie = NULL;
2734 bss->wpa_ie_len = 0;
2735 }
2736
Ester Kummerae6a44e2008-06-27 18:54:48 +03002737 if (elems->rsn &&
2738 (!bss->rsn_ie || bss->rsn_ie_len != elems->rsn_len ||
2739 memcmp(bss->rsn_ie, elems->rsn, elems->rsn_len))) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002740 kfree(bss->rsn_ie);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002741 bss->rsn_ie = kmalloc(elems->rsn_len + 2, GFP_ATOMIC);
Jiri Bencf0706e82007-05-05 11:45:53 -07002742 if (bss->rsn_ie) {
Ester Kummerae6a44e2008-06-27 18:54:48 +03002743 memcpy(bss->rsn_ie, elems->rsn - 2, elems->rsn_len + 2);
2744 bss->rsn_ie_len = elems->rsn_len + 2;
Jiri Bencf0706e82007-05-05 11:45:53 -07002745 } else
2746 bss->rsn_ie_len = 0;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002747 } else if (!elems->rsn && bss->rsn_ie) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002748 kfree(bss->rsn_ie);
2749 bss->rsn_ie = NULL;
2750 bss->rsn_ie_len = 0;
2751 }
2752
Johannes Berg30b89b02008-04-16 17:43:20 +02002753 /*
2754 * Cf.
2755 * http://www.wipo.int/pctdb/en/wo.jsp?wo=2007047181&IA=WO2007047181&DISPLAY=DESC
2756 *
2757 * quoting:
2758 *
2759 * In particular, "Wi-Fi CERTIFIED for WMM - Support for Multimedia
2760 * Applications with Quality of Service in Wi-Fi Networks," Wi- Fi
2761 * Alliance (September 1, 2004) is incorporated by reference herein.
2762 * The inclusion of the WMM Parameters in probe responses and
2763 * association responses is mandatory for WMM enabled networks. The
2764 * inclusion of the WMM Parameters in beacons, however, is optional.
2765 */
2766
Ester Kummerae6a44e2008-06-27 18:54:48 +03002767 if (elems->wmm_param &&
2768 (!bss->wmm_ie || bss->wmm_ie_len != elems->wmm_param_len ||
2769 memcmp(bss->wmm_ie, elems->wmm_param, elems->wmm_param_len))) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002770 kfree(bss->wmm_ie);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002771 bss->wmm_ie = kmalloc(elems->wmm_param_len + 2, GFP_ATOMIC);
Jiri Bencf0706e82007-05-05 11:45:53 -07002772 if (bss->wmm_ie) {
Ester Kummerae6a44e2008-06-27 18:54:48 +03002773 memcpy(bss->wmm_ie, elems->wmm_param - 2,
2774 elems->wmm_param_len + 2);
2775 bss->wmm_ie_len = elems->wmm_param_len + 2;
Jiri Bencf0706e82007-05-05 11:45:53 -07002776 } else
2777 bss->wmm_ie_len = 0;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002778 } else if (elems->wmm_info &&
2779 (!bss->wmm_ie || bss->wmm_ie_len != elems->wmm_info_len ||
2780 memcmp(bss->wmm_ie, elems->wmm_info,
2781 elems->wmm_info_len))) {
Abhijeet Kolekara46f0252008-04-16 14:02:04 -07002782 /* As for certain AP's Fifth bit is not set in WMM IE in
2783 * beacon frames.So while parsing the beacon frame the
2784 * wmm_info structure is used instead of wmm_param.
2785 * wmm_info structure was never used to set bss->wmm_ie.
2786 * This code fixes this problem by copying the WME
2787 * information from wmm_info to bss->wmm_ie and enabling
2788 * n-band association.
2789 */
2790 kfree(bss->wmm_ie);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002791 bss->wmm_ie = kmalloc(elems->wmm_info_len + 2, GFP_ATOMIC);
Abhijeet Kolekara46f0252008-04-16 14:02:04 -07002792 if (bss->wmm_ie) {
Ester Kummerae6a44e2008-06-27 18:54:48 +03002793 memcpy(bss->wmm_ie, elems->wmm_info - 2,
2794 elems->wmm_info_len + 2);
2795 bss->wmm_ie_len = elems->wmm_info_len + 2;
Abhijeet Kolekara46f0252008-04-16 14:02:04 -07002796 } else
2797 bss->wmm_ie_len = 0;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002798 } else if (!elems->wmm_param && !elems->wmm_info && bss->wmm_ie) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002799 kfree(bss->wmm_ie);
2800 bss->wmm_ie = NULL;
2801 bss->wmm_ie_len = 0;
2802 }
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002803
2804 /* check if we need to merge IBSS */
2805 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2806 !local->sta_sw_scanning && !local->sta_hw_scanning &&
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002807 bss->capability & WLAN_CAPABILITY_IBSS &&
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002808 bss->freq == local->oper_channel->center_freq &&
Ester Kummerae6a44e2008-06-27 18:54:48 +03002809 elems->ssid_len == sdata->u.sta.ssid_len &&
2810 memcmp(elems->ssid, sdata->u.sta.ssid,
2811 sdata->u.sta.ssid_len) == 0) {
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002812 if (rx_status->flag & RX_FLAG_TSFT) {
2813 /* in order for correct IBSS merging we need mactime
2814 *
2815 * since mactime is defined as the time the first data
2816 * symbol of the frame hits the PHY, and the timestamp
2817 * of the beacon is defined as "the time that the data
2818 * symbol containing the first bit of the timestamp is
2819 * transmitted to the PHY plus the transmitting STA’s
2820 * delays through its local PHY from the MAC-PHY
2821 * interface to its interface with the WM"
2822 * (802.11 11.1.2) - equals the time this bit arrives at
2823 * the receiver - we have to take into account the
2824 * offset between the two.
2825 * e.g: at 1 MBit that means mactime is 192 usec earlier
2826 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2827 */
2828 int rate = local->hw.wiphy->bands[rx_status->band]->
2829 bitrates[rx_status->rate_idx].bitrate;
2830 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2831 } else if (local && local->ops && local->ops->get_tsf)
2832 /* second best option: get current TSF */
2833 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2834 else
2835 /* can't merge without knowing the TSF */
2836 rx_timestamp = -1LLU;
2837#ifdef CONFIG_MAC80211_IBSS_DEBUG
2838 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2839 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2840 print_mac(mac, mgmt->sa),
2841 print_mac(mac2, mgmt->bssid),
2842 (unsigned long long)rx_timestamp,
2843 (unsigned long long)beacon_timestamp,
2844 (unsigned long long)(rx_timestamp - beacon_timestamp),
2845 jiffies);
2846#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2847 if (beacon_timestamp > rx_timestamp) {
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002848#ifndef CONFIG_MAC80211_IBSS_DEBUG
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002849 printk(KERN_DEBUG "%s: beacon TSF higher than "
2850 "local TSF - IBSS merge with BSSID %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002851 sdata->dev->name, print_mac(mac, mgmt->bssid));
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002852#endif
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002853 ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss);
2854 ieee80211_ibss_add_sta(sdata, NULL,
Vladimir Koutny87291c02008-06-13 16:50:44 +02002855 mgmt->bssid, mgmt->sa,
2856 BIT(rx_status->rate_idx));
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002857 }
2858 }
2859
Johannes Berg3e122be2008-07-09 14:40:34 +02002860 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07002861}
2862
2863
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002864static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002865 struct ieee80211_mgmt *mgmt,
2866 size_t len,
2867 struct ieee80211_rx_status *rx_status)
2868{
Ester Kummerae6a44e2008-06-27 18:54:48 +03002869 size_t baselen;
2870 struct ieee802_11_elems elems;
2871
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03002872 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
2873 return; /* ignore ProbeResp to foreign address */
2874
Ester Kummerae6a44e2008-06-27 18:54:48 +03002875 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2876 if (baselen > len)
2877 return;
2878
2879 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2880 &elems);
2881
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002882 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07002883}
2884
2885
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002886static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002887 struct ieee80211_mgmt *mgmt,
2888 size_t len,
2889 struct ieee80211_rx_status *rx_status)
2890{
Jiri Bencf0706e82007-05-05 11:45:53 -07002891 struct ieee80211_if_sta *ifsta;
Jiri Bencf0706e82007-05-05 11:45:53 -07002892 size_t baselen;
2893 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002894 struct ieee80211_local *local = sdata->local;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002895 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002896 u32 changed = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07002897
Ester Kummerae6a44e2008-06-27 18:54:48 +03002898 /* Process beacon from the current BSS */
2899 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2900 if (baselen > len)
2901 return;
2902
2903 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2904
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002905 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, 1);
Jiri Bencf0706e82007-05-05 11:45:53 -07002906
Johannes Berg51fb61e2007-12-19 01:31:27 +01002907 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07002908 return;
2909 ifsta = &sdata->u.sta;
2910
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002911 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
Jiri Bencf0706e82007-05-05 11:45:53 -07002912 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2913 return;
2914
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002915 ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
Johannes Berg3434fbd2008-05-03 00:59:37 +02002916 elems.wmm_param_len);
Reinette Chatred18ef292008-04-09 16:56:15 -07002917
2918 /* Do not send changes to driver if we are scanning. This removes
2919 * requirement that driver's bss_info_changed function needs to be
2920 * atomic. */
2921 if (local->sta_sw_scanning || local->sta_hw_scanning)
2922 return;
2923
Daniel Drake56282212007-07-10 19:32:10 +02002924 if (elems.erp_info && elems.erp_info_len >= 1)
Johannes Berg471b3ef2007-12-28 14:32:58 +01002925 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
John W. Linville50c4afb2008-04-15 14:09:27 -04002926 else {
2927 u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info);
2928 changed |= ieee80211_handle_protect_preamb(sdata, false,
2929 (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
2930 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002931
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002932 if (elems.ht_cap_elem && elems.ht_info_elem &&
Tomas Winkler38668c02008-03-28 16:33:32 -07002933 elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002934 struct ieee80211_ht_bss_info bss_info;
2935
2936 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2937 (struct ieee80211_ht_addt_info *)
2938 elems.ht_info_elem, &bss_info);
Tomas Winkler38668c02008-03-28 16:33:32 -07002939 changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf,
2940 &bss_info);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002941 }
2942
Johannes Berg471b3ef2007-12-28 14:32:58 +01002943 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002944}
2945
2946
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002947static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002948 struct ieee80211_if_sta *ifsta,
2949 struct ieee80211_mgmt *mgmt,
2950 size_t len,
2951 struct ieee80211_rx_status *rx_status)
2952{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002953 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002954 int tx_last_beacon;
2955 struct sk_buff *skb;
2956 struct ieee80211_mgmt *resp;
2957 u8 *pos, *end;
Joe Perches0795af52007-10-03 17:59:30 -07002958 DECLARE_MAC_BUF(mac);
2959#ifdef CONFIG_MAC80211_IBSS_DEBUG
2960 DECLARE_MAC_BUF(mac2);
2961 DECLARE_MAC_BUF(mac3);
2962#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07002963
Johannes Berg51fb61e2007-12-19 01:31:27 +01002964 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
Tomas Winkler48c2fc52008-08-06 14:22:01 +03002965 ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED ||
Jiri Bencf0706e82007-05-05 11:45:53 -07002966 len < 24 + 2 || !ifsta->probe_resp)
2967 return;
2968
2969 if (local->ops->tx_last_beacon)
2970 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
2971 else
2972 tx_last_beacon = 1;
2973
2974#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07002975 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
2976 "%s (tx_last_beacon=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002977 sdata->dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
Joe Perches0795af52007-10-03 17:59:30 -07002978 print_mac(mac3, mgmt->bssid), tx_last_beacon);
Jiri Bencf0706e82007-05-05 11:45:53 -07002979#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2980
2981 if (!tx_last_beacon)
2982 return;
2983
2984 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
2985 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
2986 return;
2987
2988 end = ((u8 *) mgmt) + len;
2989 pos = mgmt->u.probe_req.variable;
2990 if (pos[0] != WLAN_EID_SSID ||
2991 pos + 2 + pos[1] > end) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002992#ifdef CONFIG_MAC80211_IBSS_DEBUG
2993 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
2994 "from %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002995 sdata->dev->name, print_mac(mac, mgmt->sa));
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002996#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07002997 return;
2998 }
2999 if (pos[1] != 0 &&
3000 (pos[1] != ifsta->ssid_len ||
3001 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
3002 /* Ignore ProbeReq for foreign SSID */
3003 return;
3004 }
3005
3006 /* Reply with ProbeResp */
Michael Wu0ec0b7a2007-07-27 15:43:24 +02003007 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07003008 if (!skb)
3009 return;
3010
3011 resp = (struct ieee80211_mgmt *) skb->data;
3012 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3013#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003014 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003015 sdata->dev->name, print_mac(mac, resp->da));
Jiri Bencf0706e82007-05-05 11:45:53 -07003016#endif /* CONFIG_MAC80211_IBSS_DEBUG */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003017 ieee80211_sta_tx(sdata, skb, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003018}
3019
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003020static void ieee80211_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
Johannes Berg4e20cb22007-12-19 01:31:24 +01003021 struct ieee80211_if_sta *ifsta,
3022 struct ieee80211_mgmt *mgmt,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003023 size_t len,
3024 struct ieee80211_rx_status *rx_status)
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003025{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003026 struct ieee80211_local *local = sdata->local;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003027
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003028 if (len < IEEE80211_MIN_ACTION_SIZE)
3029 return;
3030
3031 switch (mgmt->u.action.category) {
Assaf Kraussb6623482008-06-16 16:09:49 +03003032 case WLAN_CATEGORY_SPECTRUM_MGMT:
3033 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
3034 break;
3035 switch (mgmt->u.action.u.chan_switch.action_code) {
3036 case WLAN_ACTION_SPCT_MSR_REQ:
3037 if (len < (IEEE80211_MIN_ACTION_SIZE +
3038 sizeof(mgmt->u.action.u.measurement)))
3039 break;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003040 ieee80211_sta_process_measurement_req(sdata, mgmt, len);
Assaf Kraussb6623482008-06-16 16:09:49 +03003041 break;
3042 }
3043 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003044 case WLAN_CATEGORY_BACK:
3045 switch (mgmt->u.action.u.addba_req.action_code) {
3046 case WLAN_ACTION_ADDBA_REQ:
3047 if (len < (IEEE80211_MIN_ACTION_SIZE +
3048 sizeof(mgmt->u.action.u.addba_req)))
3049 break;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003050 ieee80211_sta_process_addba_request(local, mgmt, len);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003051 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02003052 case WLAN_ACTION_ADDBA_RESP:
3053 if (len < (IEEE80211_MIN_ACTION_SIZE +
3054 sizeof(mgmt->u.action.u.addba_resp)))
3055 break;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003056 ieee80211_sta_process_addba_resp(local, mgmt, len);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02003057 break;
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02003058 case WLAN_ACTION_DELBA:
3059 if (len < (IEEE80211_MIN_ACTION_SIZE +
3060 sizeof(mgmt->u.action.u.delba)))
3061 break;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003062 ieee80211_sta_process_delba(sdata, mgmt, len);
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02003063 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003064 }
3065 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003066 case PLINK_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01003067 if (ieee80211_vif_is_mesh(&sdata->vif))
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003068 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003069 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003070 case MESH_PATH_SEL_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01003071 if (ieee80211_vif_is_mesh(&sdata->vif))
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003072 mesh_rx_path_sel_frame(sdata, mgmt, len);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003073 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003074 }
3075}
Jiri Bencf0706e82007-05-05 11:45:53 -07003076
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003077void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
Jiri Bencf0706e82007-05-05 11:45:53 -07003078 struct ieee80211_rx_status *rx_status)
3079{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003080 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003081 struct ieee80211_if_sta *ifsta;
3082 struct ieee80211_mgmt *mgmt;
3083 u16 fc;
3084
3085 if (skb->len < 24)
3086 goto fail;
3087
Jiri Bencf0706e82007-05-05 11:45:53 -07003088 ifsta = &sdata->u.sta;
3089
3090 mgmt = (struct ieee80211_mgmt *) skb->data;
3091 fc = le16_to_cpu(mgmt->frame_control);
3092
3093 switch (fc & IEEE80211_FCTL_STYPE) {
3094 case IEEE80211_STYPE_PROBE_REQ:
3095 case IEEE80211_STYPE_PROBE_RESP:
3096 case IEEE80211_STYPE_BEACON:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003097 case IEEE80211_STYPE_ACTION:
Jiri Bencf0706e82007-05-05 11:45:53 -07003098 memcpy(skb->cb, rx_status, sizeof(*rx_status));
3099 case IEEE80211_STYPE_AUTH:
3100 case IEEE80211_STYPE_ASSOC_RESP:
3101 case IEEE80211_STYPE_REASSOC_RESP:
3102 case IEEE80211_STYPE_DEAUTH:
3103 case IEEE80211_STYPE_DISASSOC:
3104 skb_queue_tail(&ifsta->skb_queue, skb);
3105 queue_work(local->hw.workqueue, &ifsta->work);
3106 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003107 }
3108
3109 fail:
3110 kfree_skb(skb);
3111}
3112
3113
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003114static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003115 struct sk_buff *skb)
3116{
3117 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003118 struct ieee80211_if_sta *ifsta;
3119 struct ieee80211_mgmt *mgmt;
3120 u16 fc;
3121
Jiri Bencf0706e82007-05-05 11:45:53 -07003122 ifsta = &sdata->u.sta;
3123
3124 rx_status = (struct ieee80211_rx_status *) skb->cb;
3125 mgmt = (struct ieee80211_mgmt *) skb->data;
3126 fc = le16_to_cpu(mgmt->frame_control);
3127
3128 switch (fc & IEEE80211_FCTL_STYPE) {
3129 case IEEE80211_STYPE_PROBE_REQ:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003130 ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len,
Jiri Bencf0706e82007-05-05 11:45:53 -07003131 rx_status);
3132 break;
3133 case IEEE80211_STYPE_PROBE_RESP:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003134 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status);
Jiri Bencf0706e82007-05-05 11:45:53 -07003135 break;
3136 case IEEE80211_STYPE_BEACON:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003137 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Jiri Bencf0706e82007-05-05 11:45:53 -07003138 break;
3139 case IEEE80211_STYPE_AUTH:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003140 ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len);
Jiri Bencf0706e82007-05-05 11:45:53 -07003141 break;
3142 case IEEE80211_STYPE_ASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003143 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003144 break;
3145 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003146 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
Jiri Bencf0706e82007-05-05 11:45:53 -07003147 break;
3148 case IEEE80211_STYPE_DEAUTH:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003149 ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len);
Jiri Bencf0706e82007-05-05 11:45:53 -07003150 break;
3151 case IEEE80211_STYPE_DISASSOC:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003152 ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len);
Jiri Bencf0706e82007-05-05 11:45:53 -07003153 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003154 case IEEE80211_STYPE_ACTION:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003155 ieee80211_rx_mgmt_action(sdata, ifsta, mgmt, skb->len, rx_status);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003156 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07003157 }
3158
3159 kfree_skb(skb);
3160}
3161
3162
Johannes Berg9ae54c82008-01-31 19:48:20 +01003163ieee80211_rx_result
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003164ieee80211_sta_rx_scan(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
Zhu Yiece8edd2007-11-22 10:53:21 +08003165 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003166{
3167 struct ieee80211_mgmt *mgmt;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003168 __le16 fc;
Jiri Bencf0706e82007-05-05 11:45:53 -07003169
Zhu Yiece8edd2007-11-22 10:53:21 +08003170 if (skb->len < 2)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003171 return RX_DROP_UNUSABLE;
Jiri Bencf0706e82007-05-05 11:45:53 -07003172
3173 mgmt = (struct ieee80211_mgmt *) skb->data;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003174 fc = mgmt->frame_control;
Jiri Bencf0706e82007-05-05 11:45:53 -07003175
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003176 if (ieee80211_is_ctl(fc))
Johannes Berg9ae54c82008-01-31 19:48:20 +01003177 return RX_CONTINUE;
Zhu Yiece8edd2007-11-22 10:53:21 +08003178
3179 if (skb->len < 24)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003180 return RX_DROP_MONITOR;
Zhu Yiece8edd2007-11-22 10:53:21 +08003181
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003182 if (ieee80211_is_probe_resp(fc)) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003183 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status);
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003184 dev_kfree_skb(skb);
3185 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07003186 }
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003187
3188 if (ieee80211_is_beacon(fc)) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003189 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003190 dev_kfree_skb(skb);
3191 return RX_QUEUED;
3192 }
3193
Johannes Berg9ae54c82008-01-31 19:48:20 +01003194 return RX_CONTINUE;
Jiri Bencf0706e82007-05-05 11:45:53 -07003195}
3196
3197
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003198static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07003199{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003200 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003201 int active = 0;
3202 struct sta_info *sta;
3203
Johannes Bergd0709a62008-02-25 16:27:46 +01003204 rcu_read_lock();
3205
3206 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3207 if (sta->sdata == sdata &&
Jiri Bencf0706e82007-05-05 11:45:53 -07003208 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
3209 jiffies)) {
3210 active++;
3211 break;
3212 }
3213 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003214
3215 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07003216
3217 return active;
3218}
3219
3220
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003221static void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, unsigned long exp_time)
Jiri Bencf0706e82007-05-05 11:45:53 -07003222{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003223 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003224 struct sta_info *sta, *tmp;
Michael Wube8755e2007-07-27 15:43:23 +02003225 LIST_HEAD(tmp_list);
Joe Perches0795af52007-10-03 17:59:30 -07003226 DECLARE_MAC_BUF(mac);
Johannes Bergd0709a62008-02-25 16:27:46 +01003227 unsigned long flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07003228
Johannes Bergd0709a62008-02-25 16:27:46 +01003229 spin_lock_irqsave(&local->sta_lock, flags);
Jiri Bencf0706e82007-05-05 11:45:53 -07003230 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003231 if (time_after(jiffies, sta->last_rx + exp_time)) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003232#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003233 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003234 sdata->dev->name, print_mac(mac, sta->addr));
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003235#endif
Luis Carlos Cobocb585bc2008-03-31 15:21:23 -07003236 __sta_info_unlink(&sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01003237 if (sta)
3238 list_add(&sta->list, &tmp_list);
Jiri Bencf0706e82007-05-05 11:45:53 -07003239 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003240 spin_unlock_irqrestore(&local->sta_lock, flags);
Michael Wube8755e2007-07-27 15:43:23 +02003241
Johannes Bergd0709a62008-02-25 16:27:46 +01003242 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
3243 sta_info_destroy(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003244}
3245
3246
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003247static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003248 struct ieee80211_if_sta *ifsta)
3249{
3250 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
3251
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003252 ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
3253 if (ieee80211_sta_active_ibss(sdata))
Jiri Bencf0706e82007-05-05 11:45:53 -07003254 return;
3255
3256 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003257 "IBSS networks with same SSID (merge)\n", sdata->dev->name);
3258 ieee80211_sta_req_scan(sdata, ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07003259}
3260
3261
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003262#ifdef CONFIG_MAC80211_MESH
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003263static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003264 struct ieee80211_if_sta *ifsta)
3265{
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003266 bool free_plinks;
3267
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003268 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3269 mesh_path_expire(sdata);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003270
3271 free_plinks = mesh_plink_availables(sdata);
3272 if (free_plinks != sdata->u.sta.accepting_plinks)
Johannes Berg9d139c82008-07-09 14:40:37 +02003273 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003274
3275 mod_timer(&ifsta->timer, jiffies +
3276 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3277}
3278
3279
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003280void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003281{
3282 struct ieee80211_if_sta *ifsta;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003283 ifsta = &sdata->u.sta;
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003284 ifsta->state = IEEE80211_STA_MLME_MESH_UP;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003285 ieee80211_sta_timer((unsigned long)sdata);
Luis Carlos Cobo56a6d132008-07-29 19:59:31 +02003286 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003287}
3288#endif
3289
3290
Jiri Bencf0706e82007-05-05 11:45:53 -07003291void ieee80211_sta_timer(unsigned long data)
3292{
3293 struct ieee80211_sub_if_data *sdata =
3294 (struct ieee80211_sub_if_data *) data;
3295 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003296 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003297
3298 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3299 queue_work(local->hw.workqueue, &ifsta->work);
3300}
3301
Jiri Bencf0706e82007-05-05 11:45:53 -07003302void ieee80211_sta_work(struct work_struct *work)
3303{
3304 struct ieee80211_sub_if_data *sdata =
3305 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003306 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003307 struct ieee80211_if_sta *ifsta;
3308 struct sk_buff *skb;
3309
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003310 if (!netif_running(sdata->dev))
Jiri Bencf0706e82007-05-05 11:45:53 -07003311 return;
3312
Zhu Yiece8edd2007-11-22 10:53:21 +08003313 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -07003314 return;
3315
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003316 if (WARN_ON(sdata->vif.type != IEEE80211_IF_TYPE_STA &&
3317 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3318 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT))
Jiri Bencf0706e82007-05-05 11:45:53 -07003319 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003320 ifsta = &sdata->u.sta;
3321
3322 while ((skb = skb_dequeue(&ifsta->skb_queue)))
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003323 ieee80211_sta_rx_queued_mgmt(sdata, skb);
Jiri Bencf0706e82007-05-05 11:45:53 -07003324
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003325#ifdef CONFIG_MAC80211_MESH
Johannes Berg902acc72008-02-23 15:17:19 +01003326 if (ifsta->preq_queue_len &&
3327 time_after(jiffies,
3328 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003329 mesh_path_start_discovery(sdata);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003330#endif
3331
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003332 if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
3333 ifsta->state != IEEE80211_STA_MLME_ASSOCIATE &&
Jiri Bencf0706e82007-05-05 11:45:53 -07003334 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
Helmut Schaaa0af5f12007-11-09 16:25:08 +01003335 if (ifsta->scan_ssid_len)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003336 ieee80211_sta_start_scan(sdata, ifsta->scan_ssid, ifsta->scan_ssid_len);
Helmut Schaaa0af5f12007-11-09 16:25:08 +01003337 else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003338 ieee80211_sta_start_scan(sdata, NULL, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003339 return;
3340 }
3341
3342 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003343 if (ieee80211_sta_config_auth(sdata, ifsta))
Jiri Bencf0706e82007-05-05 11:45:53 -07003344 return;
3345 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3346 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3347 return;
3348
3349 switch (ifsta->state) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003350 case IEEE80211_STA_MLME_DISABLED:
Jiri Bencf0706e82007-05-05 11:45:53 -07003351 break;
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003352 case IEEE80211_STA_MLME_AUTHENTICATE:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003353 ieee80211_authenticate(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003354 break;
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003355 case IEEE80211_STA_MLME_ASSOCIATE:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003356 ieee80211_associate(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003357 break;
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003358 case IEEE80211_STA_MLME_ASSOCIATED:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003359 ieee80211_associated(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003360 break;
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003361 case IEEE80211_STA_MLME_IBSS_SEARCH:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003362 ieee80211_sta_find_ibss(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003363 break;
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003364 case IEEE80211_STA_MLME_IBSS_JOINED:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003365 ieee80211_sta_merge_ibss(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003366 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003367#ifdef CONFIG_MAC80211_MESH
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003368 case IEEE80211_STA_MLME_MESH_UP:
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003369 ieee80211_mesh_housekeeping(sdata, ifsta);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003370 break;
3371#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07003372 default:
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003373 WARN_ON(1);
Jiri Bencf0706e82007-05-05 11:45:53 -07003374 break;
3375 }
3376
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003377 if (ieee80211_privacy_mismatch(sdata, ifsta)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003378 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003379 "mixed-cell disabled - disassociate\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07003380
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003381 ieee80211_send_disassoc(sdata, ifsta, WLAN_REASON_UNSPECIFIED);
3382 ieee80211_set_disassoc(sdata, ifsta, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003383 }
3384}
3385
3386
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003387static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003388 struct ieee80211_if_sta *ifsta)
3389{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003390 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003391
3392 if (local->ops->reset_tsf) {
3393 /* Reset own TSF to allow time synchronization work. */
3394 local->ops->reset_tsf(local_to_hw(local));
3395 }
3396
3397 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3398
3399
3400 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3401 ifsta->auth_alg = WLAN_AUTH_OPEN;
3402 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3403 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3404 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3405 ifsta->auth_alg = WLAN_AUTH_LEAP;
3406 else
3407 ifsta->auth_alg = WLAN_AUTH_OPEN;
Jiri Bencf0706e82007-05-05 11:45:53 -07003408 ifsta->auth_transaction = -1;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003409 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +03003410 ifsta->assoc_scan_tries = 0;
3411 ifsta->auth_tries = 0;
3412 ifsta->assoc_tries = 0;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003413 netif_carrier_off(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07003414}
3415
3416
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003417void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003418 struct ieee80211_if_sta *ifsta)
3419{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003420 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003421
Johannes Berg51fb61e2007-12-19 01:31:27 +01003422 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07003423 return;
3424
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003425 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3426 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3427 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3428 IEEE80211_STA_AUTO_SSID_SEL))) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003429 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3430 queue_work(local->hw.workqueue, &ifsta->work);
3431 }
3432}
3433
3434static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3435 const char *ssid, int ssid_len)
3436{
3437 int tmp, hidden_ssid;
3438
Michael Wu48225702007-10-19 17:14:36 -04003439 if (ssid_len == ifsta->ssid_len &&
3440 !memcmp(ifsta->ssid, ssid, ssid_len))
Jiri Bencf0706e82007-05-05 11:45:53 -07003441 return 1;
3442
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003443 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Jiri Bencf0706e82007-05-05 11:45:53 -07003444 return 0;
3445
3446 hidden_ssid = 1;
3447 tmp = ssid_len;
3448 while (tmp--) {
3449 if (ssid[tmp] != '\0') {
3450 hidden_ssid = 0;
3451 break;
3452 }
3453 }
3454
3455 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3456 return 1;
3457
3458 if (ssid_len == 1 && ssid[0] == ' ')
3459 return 1;
3460
3461 return 0;
3462}
3463
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003464static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003465 struct ieee80211_if_sta *ifsta)
3466{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003467 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003468 struct ieee80211_sta_bss *bss, *selected = NULL;
3469 int top_rssi = 0, freq;
3470
Jiri Bencf0706e82007-05-05 11:45:53 -07003471 spin_lock_bh(&local->sta_bss_lock);
Johannes Berg8318d782008-01-24 19:38:38 +01003472 freq = local->oper_channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -07003473 list_for_each_entry(bss, &local->sta_bss_list, list) {
3474 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3475 continue;
3476
Abhijeet Kolekar34a961f2008-05-09 09:35:41 -07003477 if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3478 IEEE80211_STA_AUTO_BSSID_SEL |
3479 IEEE80211_STA_AUTO_CHANNEL_SEL)) &&
3480 (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3481 !!sdata->default_key))
Jiri Bencf0706e82007-05-05 11:45:53 -07003482 continue;
3483
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003484 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3485 bss->freq != freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07003486 continue;
3487
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003488 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
Jiri Bencf0706e82007-05-05 11:45:53 -07003489 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3490 continue;
3491
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003492 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
Jiri Bencf0706e82007-05-05 11:45:53 -07003493 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3494 continue;
3495
Bruno Randolf566bfe52008-05-08 19:15:40 +02003496 if (!selected || top_rssi < bss->signal) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003497 selected = bss;
Bruno Randolf566bfe52008-05-08 19:15:40 +02003498 top_rssi = bss->signal;
Jiri Bencf0706e82007-05-05 11:45:53 -07003499 }
3500 }
3501 if (selected)
3502 atomic_inc(&selected->users);
3503 spin_unlock_bh(&local->sta_bss_lock);
3504
3505 if (selected) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003506 ieee80211_set_freq(sdata, selected->freq);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003507 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003508 ieee80211_sta_set_ssid(sdata, selected->ssid,
Jiri Bencf0706e82007-05-05 11:45:53 -07003509 selected->ssid_len);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003510 ieee80211_sta_set_bssid(sdata, selected->bssid);
3511 ieee80211_sta_def_wmm_params(sdata, selected, 0);
Johannes Berg3e122be2008-07-09 14:40:34 +02003512 ieee80211_rx_bss_put(local, selected);
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003513 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003514 ieee80211_sta_reset_auth(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003515 return 0;
3516 } else {
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +03003517 if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
3518 ifsta->assoc_scan_tries++;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003519 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003520 ieee80211_sta_start_scan(sdata, NULL, 0);
John W. Linvilleb9bf1e62007-08-07 16:33:15 -04003521 else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003522 ieee80211_sta_start_scan(sdata, ifsta->ssid,
John W. Linvilleb9bf1e62007-08-07 16:33:15 -04003523 ifsta->ssid_len);
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003524 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
Jiri Bencf0706e82007-05-05 11:45:53 -07003525 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3526 } else
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003527 ifsta->state = IEEE80211_STA_MLME_DISABLED;
Jiri Bencf0706e82007-05-05 11:45:53 -07003528 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003529 return -1;
3530}
3531
Jiri Bencf0706e82007-05-05 11:45:53 -07003532
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003533static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003534 struct ieee80211_if_sta *ifsta)
3535{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003536 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003537 struct ieee80211_sta_bss *bss;
Johannes Berg8318d782008-01-24 19:38:38 +01003538 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003539 u8 bssid[ETH_ALEN], *pos;
3540 int i;
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003541 int ret;
Joe Perches0795af52007-10-03 17:59:30 -07003542 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07003543
3544#if 0
3545 /* Easier testing, use fixed BSSID. */
3546 memset(bssid, 0xfe, ETH_ALEN);
3547#else
3548 /* Generate random, not broadcast, locally administered BSSID. Mix in
3549 * own MAC address to make sure that devices that do not have proper
3550 * random number generator get different BSSID. */
3551 get_random_bytes(bssid, ETH_ALEN);
3552 for (i = 0; i < ETH_ALEN; i++)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003553 bssid[i] ^= sdata->dev->dev_addr[i];
Jiri Bencf0706e82007-05-05 11:45:53 -07003554 bssid[0] &= ~0x01;
3555 bssid[0] |= 0x02;
3556#endif
3557
Joe Perches0795af52007-10-03 17:59:30 -07003558 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003559 sdata->dev->name, print_mac(mac, bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07003560
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003561 bss = ieee80211_rx_bss_add(sdata, bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01003562 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04003563 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07003564 if (!bss)
3565 return -ENOMEM;
3566
Johannes Berg8318d782008-01-24 19:38:38 +01003567 bss->band = local->hw.conf.channel->band;
3568 sband = local->hw.wiphy->bands[bss->band];
Jiri Bencf0706e82007-05-05 11:45:53 -07003569
3570 if (local->hw.conf.beacon_int == 0)
Tomas Winklerdc0ae302008-06-12 22:38:37 +03003571 local->hw.conf.beacon_int = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -07003572 bss->beacon_int = local->hw.conf.beacon_int;
Jiri Bencf0706e82007-05-05 11:45:53 -07003573 bss->last_update = jiffies;
3574 bss->capability = WLAN_CAPABILITY_IBSS;
Johannes Berg988c0f72008-04-17 19:21:22 +02003575
3576 if (sdata->default_key)
Jiri Bencf0706e82007-05-05 11:45:53 -07003577 bss->capability |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg988c0f72008-04-17 19:21:22 +02003578 else
Jiri Bencf0706e82007-05-05 11:45:53 -07003579 sdata->drop_unencrypted = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02003580
Johannes Berg8318d782008-01-24 19:38:38 +01003581 bss->supp_rates_len = sband->n_bitrates;
Jiri Bencf0706e82007-05-05 11:45:53 -07003582 pos = bss->supp_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01003583 for (i = 0; i < sband->n_bitrates; i++) {
3584 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e82007-05-05 11:45:53 -07003585 *pos++ = (u8) (rate / 5);
3586 }
3587
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003588 ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
Johannes Berg3e122be2008-07-09 14:40:34 +02003589 ieee80211_rx_bss_put(local, bss);
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003590 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003591}
3592
3593
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003594static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003595 struct ieee80211_if_sta *ifsta)
3596{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003597 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003598 struct ieee80211_sta_bss *bss;
3599 int found = 0;
3600 u8 bssid[ETH_ALEN];
3601 int active_ibss;
Joe Perches0795af52007-10-03 17:59:30 -07003602 DECLARE_MAC_BUF(mac);
3603 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e82007-05-05 11:45:53 -07003604
3605 if (ifsta->ssid_len == 0)
3606 return -EINVAL;
3607
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003608 active_ibss = ieee80211_sta_active_ibss(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003609#ifdef CONFIG_MAC80211_IBSS_DEBUG
3610 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003611 sdata->dev->name, active_ibss);
Jiri Bencf0706e82007-05-05 11:45:53 -07003612#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3613 spin_lock_bh(&local->sta_bss_lock);
3614 list_for_each_entry(bss, &local->sta_bss_list, list) {
3615 if (ifsta->ssid_len != bss->ssid_len ||
3616 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3617 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3618 continue;
3619#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003620 printk(KERN_DEBUG " bssid=%s found\n",
3621 print_mac(mac, bss->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07003622#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3623 memcpy(bssid, bss->bssid, ETH_ALEN);
3624 found = 1;
3625 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3626 break;
3627 }
3628 spin_unlock_bh(&local->sta_bss_lock);
3629
3630#ifdef CONFIG_MAC80211_IBSS_DEBUG
Vladimir Koutny6e438292008-07-07 14:23:01 +02003631 if (found)
3632 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3633 "%s\n", print_mac(mac, bssid),
3634 print_mac(mac2, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07003635#endif /* CONFIG_MAC80211_IBSS_DEBUG */
Daniel Drake80693ce2008-07-19 23:31:17 +01003636
3637 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003638 int ret;
Daniel Drake80693ce2008-07-19 23:31:17 +01003639 int search_freq;
3640
3641 if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
3642 search_freq = bss->freq;
3643 else
3644 search_freq = local->hw.conf.channel->center_freq;
3645
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003646 bss = ieee80211_rx_bss_get(local, bssid, search_freq,
Daniel Drake80693ce2008-07-19 23:31:17 +01003647 ifsta->ssid, ifsta->ssid_len);
3648 if (!bss)
3649 goto dont_join;
3650
Joe Perches0795af52007-10-03 17:59:30 -07003651 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
Jiri Bencf0706e82007-05-05 11:45:53 -07003652 " based on configured SSID\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003653 sdata->dev->name, print_mac(mac, bssid));
3654 ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
Johannes Berg3e122be2008-07-09 14:40:34 +02003655 ieee80211_rx_bss_put(local, bss);
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003656 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003657 }
Daniel Drake80693ce2008-07-19 23:31:17 +01003658
3659dont_join:
Jiri Bencf0706e82007-05-05 11:45:53 -07003660#ifdef CONFIG_MAC80211_IBSS_DEBUG
3661 printk(KERN_DEBUG " did not try to join ibss\n");
3662#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3663
3664 /* Selected IBSS not found in current scan results - try to scan */
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003665 if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003666 !ieee80211_sta_active_ibss(sdata)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003667 mod_timer(&ifsta->timer, jiffies +
3668 IEEE80211_IBSS_MERGE_INTERVAL);
3669 } else if (time_after(jiffies, local->last_scan_completed +
3670 IEEE80211_SCAN_INTERVAL)) {
3671 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003672 "join\n", sdata->dev->name);
3673 return ieee80211_sta_req_scan(sdata, ifsta->ssid,
Jiri Bencf0706e82007-05-05 11:45:53 -07003674 ifsta->ssid_len);
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003675 } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003676 int interval = IEEE80211_SCAN_INTERVAL;
3677
3678 if (time_after(jiffies, ifsta->ibss_join_req +
3679 IEEE80211_IBSS_JOIN_TIMEOUT)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003680 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
Johannes Berg8318d782008-01-24 19:38:38 +01003681 (!(local->oper_channel->flags &
3682 IEEE80211_CHAN_NO_IBSS)))
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003683 return ieee80211_sta_create_ibss(sdata, ifsta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003684 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
Johannes Berg8318d782008-01-24 19:38:38 +01003685 printk(KERN_DEBUG "%s: IBSS not allowed on"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003686 " %d MHz\n", sdata->dev->name,
Johannes Berg8318d782008-01-24 19:38:38 +01003687 local->hw.conf.channel->center_freq);
Jiri Bencf0706e82007-05-05 11:45:53 -07003688 }
3689
3690 /* No IBSS found - decrease scan interval and continue
3691 * scanning. */
3692 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3693 }
3694
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003695 ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
Jiri Bencf0706e82007-05-05 11:45:53 -07003696 mod_timer(&ifsta->timer, jiffies + interval);
3697 return 0;
3698 }
3699
3700 return 0;
3701}
3702
3703
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003704int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003705{
Jiri Bencf0706e82007-05-05 11:45:53 -07003706 struct ieee80211_if_sta *ifsta;
Johannes Berg9d139c82008-07-09 14:40:37 +02003707 int res;
Jiri Bencf0706e82007-05-05 11:45:53 -07003708
3709 if (len > IEEE80211_MAX_SSID_LEN)
3710 return -EINVAL;
3711
Jiri Bencf0706e82007-05-05 11:45:53 -07003712 ifsta = &sdata->u.sta;
3713
Johannes Berg9d139c82008-07-09 14:40:37 +02003714 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) {
3715 memset(ifsta->ssid, 0, sizeof(ifsta->ssid));
3716 memcpy(ifsta->ssid, ssid, len);
3717 ifsta->ssid_len = len;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003718 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Johannes Berg9d139c82008-07-09 14:40:37 +02003719
3720 res = 0;
3721 /*
3722 * Hack! MLME code needs to be cleaned up to have different
3723 * entry points for configuration and internal selection change
3724 */
3725 if (netif_running(sdata->dev))
3726 res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
3727 if (res) {
3728 printk(KERN_DEBUG "%s: Failed to config new SSID to "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003729 "the low-level driver\n", sdata->dev->name);
Johannes Berg9d139c82008-07-09 14:40:37 +02003730 return res;
3731 }
3732 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003733
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003734 if (len)
3735 ifsta->flags |= IEEE80211_STA_SSID_SET;
3736 else
3737 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
Johannes Berg9d139c82008-07-09 14:40:37 +02003738
Johannes Berg51fb61e2007-12-19 01:31:27 +01003739 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003740 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003741 ifsta->ibss_join_req = jiffies;
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003742 ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003743 return ieee80211_sta_find_ibss(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003744 }
Johannes Berg9d139c82008-07-09 14:40:37 +02003745
Jiri Bencf0706e82007-05-05 11:45:53 -07003746 return 0;
3747}
3748
3749
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003750int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003751{
Jiri Bencf0706e82007-05-05 11:45:53 -07003752 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3753 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3754 *len = ifsta->ssid_len;
3755 return 0;
3756}
3757
3758
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003759int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
Jiri Bencf0706e82007-05-05 11:45:53 -07003760{
Jiri Bencf0706e82007-05-05 11:45:53 -07003761 struct ieee80211_if_sta *ifsta;
3762 int res;
3763
Jiri Bencf0706e82007-05-05 11:45:53 -07003764 ifsta = &sdata->u.sta;
3765
3766 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3767 memcpy(ifsta->bssid, bssid, ETH_ALEN);
Johannes Berg9d139c82008-07-09 14:40:37 +02003768 res = 0;
3769 /*
3770 * Hack! See also ieee80211_sta_set_ssid.
3771 */
3772 if (netif_running(sdata->dev))
3773 res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
Jiri Bencf0706e82007-05-05 11:45:53 -07003774 if (res) {
3775 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003776 "the low-level driver\n", sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07003777 return res;
3778 }
3779 }
3780
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003781 if (is_valid_ether_addr(bssid))
3782 ifsta->flags |= IEEE80211_STA_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -07003783 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003784 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3785
Jiri Bencf0706e82007-05-05 11:45:53 -07003786 return 0;
3787}
3788
3789
3790static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3791 struct ieee80211_sub_if_data *sdata,
3792 int powersave)
3793{
3794 struct sk_buff *skb;
3795 struct ieee80211_hdr *nullfunc;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003796 __le16 fc;
Jiri Bencf0706e82007-05-05 11:45:53 -07003797
3798 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3799 if (!skb) {
3800 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3801 "frame\n", sdata->dev->name);
3802 return;
3803 }
3804 skb_reserve(skb, local->hw.extra_tx_headroom);
3805
3806 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3807 memset(nullfunc, 0, 24);
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003808 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3809 IEEE80211_FCTL_TODS);
Jiri Bencf0706e82007-05-05 11:45:53 -07003810 if (powersave)
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003811 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
3812 nullfunc->frame_control = fc;
Jiri Bencf0706e82007-05-05 11:45:53 -07003813 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3814 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3815 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3816
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003817 ieee80211_sta_tx(sdata, skb, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003818}
3819
3820
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003821static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3822{
3823 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3824 ieee80211_vif_is_mesh(&sdata->vif))
3825 ieee80211_sta_timer((unsigned long)sdata);
3826}
3827
Jiri Bencf0706e82007-05-05 11:45:53 -07003828void ieee80211_scan_completed(struct ieee80211_hw *hw)
3829{
3830 struct ieee80211_local *local = hw_to_local(hw);
3831 struct net_device *dev = local->scan_dev;
3832 struct ieee80211_sub_if_data *sdata;
3833 union iwreq_data wrqu;
3834
3835 local->last_scan_completed = jiffies;
Zhu Yiece8edd2007-11-22 10:53:21 +08003836 memset(&wrqu, 0, sizeof(wrqu));
3837 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -07003838
Zhu Yiece8edd2007-11-22 10:53:21 +08003839 if (local->sta_hw_scanning) {
3840 local->sta_hw_scanning = 0;
Mohamed Abbas675ef582008-03-20 08:14:29 -07003841 if (ieee80211_hw_config(local))
3842 printk(KERN_DEBUG "%s: failed to restore operational "
3843 "channel after scan\n", dev->name);
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003844 /* Restart STA timer for HW scan case */
3845 rcu_read_lock();
3846 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3847 ieee80211_restart_sta_timer(sdata);
3848 rcu_read_unlock();
3849
Zhu Yiece8edd2007-11-22 10:53:21 +08003850 goto done;
3851 }
3852
3853 local->sta_sw_scanning = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07003854 if (ieee80211_hw_config(local))
Bruno Randolf4b50e382007-11-16 17:04:01 +09003855 printk(KERN_DEBUG "%s: failed to restore operational "
Jiri Bencf0706e82007-05-05 11:45:53 -07003856 "channel after scan\n", dev->name);
3857
Johannes Berg4150c572007-09-17 01:29:23 -04003858
3859 netif_tx_lock_bh(local->mdev);
David S. Millere308a5d2008-07-15 00:13:44 -07003860 netif_addr_lock(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -04003861 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3862 local->ops->configure_filter(local_to_hw(local),
3863 FIF_BCN_PRBRESP_PROMISC,
3864 &local->filter_flags,
3865 local->mdev->mc_count,
3866 local->mdev->mc_list);
3867
David S. Millere308a5d2008-07-15 00:13:44 -07003868 netif_addr_unlock(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -04003869 netif_tx_unlock_bh(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -07003870
Johannes Berg79010422007-09-18 17:29:21 -04003871 rcu_read_lock();
3872 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003873 /* Tell AP we're back */
3874 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3875 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3876 ieee80211_send_nullfunc(local, sdata, 0);
Mattias Nissler14042cbe2007-06-08 15:31:13 +02003877
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003878 ieee80211_restart_sta_timer(sdata);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003879
Jiri Bencf0706e82007-05-05 11:45:53 -07003880 netif_wake_queue(sdata->dev);
3881 }
Johannes Berg79010422007-09-18 17:29:21 -04003882 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07003883
Zhu Yiece8edd2007-11-22 10:53:21 +08003884done:
Jiri Bencf0706e82007-05-05 11:45:53 -07003885 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01003886 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003887 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003888 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
Tomas Winkler48c2fc52008-08-06 14:22:01 +03003889 (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003890 !ieee80211_sta_active_ibss(sdata)))
3891 ieee80211_sta_find_ibss(sdata, ifsta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003892 }
3893}
3894EXPORT_SYMBOL(ieee80211_scan_completed);
3895
3896void ieee80211_sta_scan_work(struct work_struct *work)
3897{
3898 struct ieee80211_local *local =
3899 container_of(work, struct ieee80211_local, scan_work.work);
3900 struct net_device *dev = local->scan_dev;
3901 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +01003902 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003903 struct ieee80211_channel *chan;
3904 int skip;
3905 unsigned long next_delay = 0;
3906
Zhu Yiece8edd2007-11-22 10:53:21 +08003907 if (!local->sta_sw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -07003908 return;
3909
3910 switch (local->scan_state) {
3911 case SCAN_SET_CHANNEL:
Johannes Berg69d464d2008-01-28 17:08:56 +01003912 /*
3913 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3914 * after we successfully scanned the last channel of the last
3915 * band (and the last band is supported by the hw)
3916 */
Johannes Berg8318d782008-01-24 19:38:38 +01003917 if (local->scan_band < IEEE80211_NUM_BANDS)
3918 sband = local->hw.wiphy->bands[local->scan_band];
3919 else
3920 sband = NULL;
3921
Johannes Berg69d464d2008-01-28 17:08:56 +01003922 /*
3923 * If we are at an unsupported band and have more bands
3924 * left to scan, advance to the next supported one.
3925 */
3926 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
Johannes Berg8318d782008-01-24 19:38:38 +01003927 local->scan_band++;
3928 sband = local->hw.wiphy->bands[local->scan_band];
3929 local->scan_channel_idx = 0;
3930 }
3931
Johannes Berg69d464d2008-01-28 17:08:56 +01003932 /* if no more bands/channels left, complete scan */
3933 if (!sband || local->scan_channel_idx >= sband->n_channels) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003934 ieee80211_scan_completed(local_to_hw(local));
3935 return;
3936 }
Johannes Berg8318d782008-01-24 19:38:38 +01003937 skip = 0;
3938 chan = &sband->channels[local->scan_channel_idx];
3939
3940 if (chan->flags & IEEE80211_CHAN_DISABLED ||
Johannes Berg51fb61e2007-12-19 01:31:27 +01003941 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Johannes Berg8318d782008-01-24 19:38:38 +01003942 chan->flags & IEEE80211_CHAN_NO_IBSS))
Jiri Bencf0706e82007-05-05 11:45:53 -07003943 skip = 1;
3944
3945 if (!skip) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003946 local->scan_channel = chan;
3947 if (ieee80211_hw_config(local)) {
Johannes Berg8318d782008-01-24 19:38:38 +01003948 printk(KERN_DEBUG "%s: failed to set freq to "
3949 "%d MHz for scan\n", dev->name,
3950 chan->center_freq);
Jiri Bencf0706e82007-05-05 11:45:53 -07003951 skip = 1;
3952 }
3953 }
3954
Johannes Berg69d464d2008-01-28 17:08:56 +01003955 /* advance state machine to next channel/band */
Jiri Bencf0706e82007-05-05 11:45:53 -07003956 local->scan_channel_idx++;
Johannes Berg8318d782008-01-24 19:38:38 +01003957 if (local->scan_channel_idx >= sband->n_channels) {
Johannes Berg69d464d2008-01-28 17:08:56 +01003958 /*
3959 * scan_band may end up == IEEE80211_NUM_BANDS, but
3960 * we'll catch that case above and complete the scan
3961 * if that is the case.
3962 */
Johannes Berg8318d782008-01-24 19:38:38 +01003963 local->scan_band++;
3964 local->scan_channel_idx = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07003965 }
3966
3967 if (skip)
3968 break;
3969
3970 next_delay = IEEE80211_PROBE_DELAY +
3971 usecs_to_jiffies(local->hw.channel_change_time);
3972 local->scan_state = SCAN_SEND_PROBE;
3973 break;
3974 case SCAN_SEND_PROBE:
Johannes Berg8318d782008-01-24 19:38:38 +01003975 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
Jiri Bencf0706e82007-05-05 11:45:53 -07003976 local->scan_state = SCAN_SET_CHANNEL;
Johannes Berg8318d782008-01-24 19:38:38 +01003977
3978 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3979 break;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003980 ieee80211_send_probe_req(sdata, NULL, local->scan_ssid,
Johannes Berg8318d782008-01-24 19:38:38 +01003981 local->scan_ssid_len);
3982 next_delay = IEEE80211_CHANNEL_TIME;
Jiri Bencf0706e82007-05-05 11:45:53 -07003983 break;
3984 }
3985
Zhu Yiece8edd2007-11-22 10:53:21 +08003986 if (local->sta_sw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -07003987 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3988 next_delay);
3989}
3990
3991
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003992static int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07003993 u8 *ssid, size_t ssid_len)
3994{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003995 struct ieee80211_local *local = scan_sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07003996 struct ieee80211_sub_if_data *sdata;
3997
3998 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3999 return -EINVAL;
4000
4001 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
4002 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
4003 * BSSID: MACAddress
4004 * SSID
4005 * ScanType: ACTIVE, PASSIVE
4006 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
4007 * a Probe frame during active scanning
4008 * ChannelList
4009 * MinChannelTime (>= ProbeDelay), in TU
4010 * MaxChannelTime: (>= MinChannelTime), in TU
4011 */
4012
4013 /* MLME-SCAN.confirm
4014 * BSSDescriptionSet
4015 * ResultCode: SUCCESS, INVALID_PARAMETERS
4016 */
4017
Zhu Yiece8edd2007-11-22 10:53:21 +08004018 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004019 if (local->scan_dev == scan_sdata->dev)
Jiri Bencf0706e82007-05-05 11:45:53 -07004020 return 0;
4021 return -EBUSY;
4022 }
4023
4024 if (local->ops->hw_scan) {
4025 int rc = local->ops->hw_scan(local_to_hw(local),
Zhu Yiece8edd2007-11-22 10:53:21 +08004026 ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07004027 if (!rc) {
Zhu Yiece8edd2007-11-22 10:53:21 +08004028 local->sta_hw_scanning = 1;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004029 local->scan_dev = scan_sdata->dev;
Jiri Bencf0706e82007-05-05 11:45:53 -07004030 }
4031 return rc;
4032 }
4033
Zhu Yiece8edd2007-11-22 10:53:21 +08004034 local->sta_sw_scanning = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07004035
Johannes Berg79010422007-09-18 17:29:21 -04004036 rcu_read_lock();
4037 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Jiri Bencf0706e82007-05-05 11:45:53 -07004038 netif_stop_queue(sdata->dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01004039 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04004040 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e82007-05-05 11:45:53 -07004041 ieee80211_send_nullfunc(local, sdata, 1);
4042 }
Johannes Berg79010422007-09-18 17:29:21 -04004043 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07004044
4045 if (ssid) {
4046 local->scan_ssid_len = ssid_len;
4047 memcpy(local->scan_ssid, ssid, ssid_len);
4048 } else
4049 local->scan_ssid_len = 0;
4050 local->scan_state = SCAN_SET_CHANNEL;
Jiri Bencf0706e82007-05-05 11:45:53 -07004051 local->scan_channel_idx = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01004052 local->scan_band = IEEE80211_BAND_2GHZ;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004053 local->scan_dev = scan_sdata->dev;
Jiri Bencf0706e82007-05-05 11:45:53 -07004054
David S. Millerb9e40852008-07-15 00:15:08 -07004055 netif_addr_lock_bh(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -04004056 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
4057 local->ops->configure_filter(local_to_hw(local),
4058 FIF_BCN_PRBRESP_PROMISC,
4059 &local->filter_flags,
4060 local->mdev->mc_count,
4061 local->mdev->mc_list);
David S. Millerb9e40852008-07-15 00:15:08 -07004062 netif_addr_unlock_bh(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -07004063
4064 /* TODO: start scan as soon as all nullfunc frames are ACKed */
4065 queue_delayed_work(local->hw.workqueue, &local->scan_work,
4066 IEEE80211_CHANNEL_TIME);
4067
4068 return 0;
4069}
4070
4071
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004072int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07004073{
Jiri Bencf0706e82007-05-05 11:45:53 -07004074 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004075 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07004076
Johannes Berg51fb61e2007-12-19 01:31:27 +01004077 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004078 return ieee80211_sta_start_scan(sdata, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07004079
Zhu Yiece8edd2007-11-22 10:53:21 +08004080 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004081 if (local->scan_dev == sdata->dev)
Jiri Bencf0706e82007-05-05 11:45:53 -07004082 return 0;
4083 return -EBUSY;
4084 }
4085
Helmut Schaaa0af5f12007-11-09 16:25:08 +01004086 ifsta->scan_ssid_len = ssid_len;
4087 if (ssid_len)
4088 memcpy(ifsta->scan_ssid, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07004089 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
4090 queue_work(local->hw.workqueue, &ifsta->work);
4091 return 0;
4092}
4093
4094static char *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004095ieee80211_sta_scan_result(struct ieee80211_local *local,
David S. Millerccc58052008-06-16 18:50:49 -07004096 struct iw_request_info *info,
Jiri Bencf0706e82007-05-05 11:45:53 -07004097 struct ieee80211_sta_bss *bss,
4098 char *current_ev, char *end_buf)
4099{
Jiri Bencf0706e82007-05-05 11:45:53 -07004100 struct iw_event iwe;
4101
4102 if (time_after(jiffies,
4103 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
4104 return current_ev;
4105
Jiri Bencf0706e82007-05-05 11:45:53 -07004106 memset(&iwe, 0, sizeof(iwe));
4107 iwe.cmd = SIOCGIWAP;
4108 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4109 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07004110 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e82007-05-05 11:45:53 -07004111 IW_EV_ADDR_LEN);
4112
4113 memset(&iwe, 0, sizeof(iwe));
4114 iwe.cmd = SIOCGIWESSID;
Johannes Berg902acc72008-02-23 15:17:19 +01004115 if (bss_mesh_cfg(bss)) {
4116 iwe.u.data.length = bss_mesh_id_len(bss);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004117 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004118 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4119 &iwe, bss_mesh_id(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004120 } else {
4121 iwe.u.data.length = bss->ssid_len;
4122 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004123 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4124 &iwe, bss->ssid);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004125 }
Jiri Bencf0706e82007-05-05 11:45:53 -07004126
Luis Carlos Cobo1d1b5352008-02-29 12:15:28 -08004127 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
4128 || bss_mesh_cfg(bss)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07004129 memset(&iwe, 0, sizeof(iwe));
4130 iwe.cmd = SIOCGIWMODE;
Johannes Berg902acc72008-02-23 15:17:19 +01004131 if (bss_mesh_cfg(bss))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004132 iwe.u.mode = IW_MODE_MESH;
4133 else if (bss->capability & WLAN_CAPABILITY_ESS)
Jiri Bencf0706e82007-05-05 11:45:53 -07004134 iwe.u.mode = IW_MODE_MASTER;
4135 else
4136 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07004137 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4138 &iwe, IW_EV_UINT_LEN);
Jiri Bencf0706e82007-05-05 11:45:53 -07004139 }
4140
4141 memset(&iwe, 0, sizeof(iwe));
4142 iwe.cmd = SIOCGIWFREQ;
Johannes Berg8318d782008-01-24 19:38:38 +01004143 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
4144 iwe.u.freq.e = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004145 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e82007-05-05 11:45:53 -07004146 IW_EV_FREQ_LEN);
4147
4148 memset(&iwe, 0, sizeof(iwe));
Tomas Winkler9381be02008-05-23 01:36:36 +03004149 iwe.cmd = SIOCGIWFREQ;
4150 iwe.u.freq.m = bss->freq;
4151 iwe.u.freq.e = 6;
David S. Millerccc58052008-06-16 18:50:49 -07004152 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Tomas Winkler9381be02008-05-23 01:36:36 +03004153 IW_EV_FREQ_LEN);
4154 memset(&iwe, 0, sizeof(iwe));
Jiri Bencf0706e82007-05-05 11:45:53 -07004155 iwe.cmd = IWEVQUAL;
Bruno Randolf566bfe52008-05-08 19:15:40 +02004156 iwe.u.qual.qual = bss->qual;
4157 iwe.u.qual.level = bss->signal;
Jiri Bencf0706e82007-05-05 11:45:53 -07004158 iwe.u.qual.noise = bss->noise;
4159 iwe.u.qual.updated = local->wstats_flags;
David S. Millerccc58052008-06-16 18:50:49 -07004160 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e82007-05-05 11:45:53 -07004161 IW_EV_QUAL_LEN);
4162
4163 memset(&iwe, 0, sizeof(iwe));
4164 iwe.cmd = SIOCGIWENCODE;
4165 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
4166 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4167 else
4168 iwe.u.data.flags = IW_ENCODE_DISABLED;
4169 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004170 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4171 &iwe, "");
Jiri Bencf0706e82007-05-05 11:45:53 -07004172
4173 if (bss && bss->wpa_ie) {
4174 memset(&iwe, 0, sizeof(iwe));
4175 iwe.cmd = IWEVGENIE;
4176 iwe.u.data.length = bss->wpa_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004177 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4178 &iwe, bss->wpa_ie);
Jiri Bencf0706e82007-05-05 11:45:53 -07004179 }
4180
4181 if (bss && bss->rsn_ie) {
4182 memset(&iwe, 0, sizeof(iwe));
4183 iwe.cmd = IWEVGENIE;
4184 iwe.u.data.length = bss->rsn_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004185 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4186 &iwe, bss->rsn_ie);
Jiri Bencf0706e82007-05-05 11:45:53 -07004187 }
4188
Emmanuel Grumbache6231572008-05-27 20:00:11 +03004189 if (bss && bss->ht_ie) {
4190 memset(&iwe, 0, sizeof(iwe));
4191 iwe.cmd = IWEVGENIE;
4192 iwe.u.data.length = bss->ht_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004193 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4194 &iwe, bss->ht_ie);
Emmanuel Grumbache6231572008-05-27 20:00:11 +03004195 }
4196
Jiri Bencf0706e82007-05-05 11:45:53 -07004197 if (bss && bss->supp_rates_len > 0) {
4198 /* display all supported rates in readable format */
David S. Millerccc58052008-06-16 18:50:49 -07004199 char *p = current_ev + iwe_stream_lcp_len(info);
Jiri Bencf0706e82007-05-05 11:45:53 -07004200 int i;
4201
4202 memset(&iwe, 0, sizeof(iwe));
4203 iwe.cmd = SIOCGIWRATE;
4204 /* Those two flags are ignored... */
4205 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4206
4207 for (i = 0; i < bss->supp_rates_len; i++) {
4208 iwe.u.bitrate.value = ((bss->supp_rates[i] &
4209 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07004210 p = iwe_stream_add_value(info, current_ev, p,
Jiri Bencf0706e82007-05-05 11:45:53 -07004211 end_buf, &iwe, IW_EV_PARAM_LEN);
4212 }
4213 current_ev = p;
4214 }
4215
4216 if (bss) {
4217 char *buf;
4218 buf = kmalloc(30, GFP_ATOMIC);
4219 if (buf) {
4220 memset(&iwe, 0, sizeof(iwe));
4221 iwe.cmd = IWEVCUSTOM;
4222 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
4223 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004224 current_ev = iwe_stream_add_point(info, current_ev,
4225 end_buf,
Jiri Bencf0706e82007-05-05 11:45:53 -07004226 &iwe, buf);
Emmanuel Grumbachbf998f62008-06-24 13:38:00 +03004227 memset(&iwe, 0, sizeof(iwe));
4228 iwe.cmd = IWEVCUSTOM;
4229 sprintf(buf, " Last beacon: %dms ago",
4230 jiffies_to_msecs(jiffies - bss->last_update));
4231 iwe.u.data.length = strlen(buf);
4232 current_ev = iwe_stream_add_point(info, current_ev,
4233 end_buf, &iwe, buf);
Jiri Bencf0706e82007-05-05 11:45:53 -07004234 kfree(buf);
4235 }
4236 }
4237
Johannes Berg902acc72008-02-23 15:17:19 +01004238 if (bss_mesh_cfg(bss)) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004239 char *buf;
John W. Linville24736702008-04-08 14:15:46 -04004240 u8 *cfg = bss_mesh_cfg(bss);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004241 buf = kmalloc(50, GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004242 if (buf) {
4243 memset(&iwe, 0, sizeof(iwe));
4244 iwe.cmd = IWEVCUSTOM;
John W. Linville24736702008-04-08 14:15:46 -04004245 sprintf(buf, "Mesh network (version %d)", cfg[0]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004246 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004247 current_ev = iwe_stream_add_point(info, current_ev,
4248 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004249 &iwe, buf);
4250 sprintf(buf, "Path Selection Protocol ID: "
John W. Linville24736702008-04-08 14:15:46 -04004251 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
4252 cfg[4]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004253 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004254 current_ev = iwe_stream_add_point(info, current_ev,
4255 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004256 &iwe, buf);
4257 sprintf(buf, "Path Selection Metric ID: "
John W. Linville24736702008-04-08 14:15:46 -04004258 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
4259 cfg[8]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004260 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004261 current_ev = iwe_stream_add_point(info, current_ev,
4262 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004263 &iwe, buf);
4264 sprintf(buf, "Congestion Control Mode ID: "
John W. Linville24736702008-04-08 14:15:46 -04004265 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
4266 cfg[11], cfg[12]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004267 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004268 current_ev = iwe_stream_add_point(info, current_ev,
4269 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004270 &iwe, buf);
4271 sprintf(buf, "Channel Precedence: "
John W. Linville24736702008-04-08 14:15:46 -04004272 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
4273 cfg[15], cfg[16]);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004274 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004275 current_ev = iwe_stream_add_point(info, current_ev,
4276 end_buf,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004277 &iwe, buf);
4278 kfree(buf);
4279 }
4280 }
4281
Jiri Bencf0706e82007-05-05 11:45:53 -07004282 return current_ev;
4283}
4284
4285
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004286int ieee80211_sta_scan_results(struct ieee80211_local *local,
David S. Millerccc58052008-06-16 18:50:49 -07004287 struct iw_request_info *info,
4288 char *buf, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07004289{
Jiri Bencf0706e82007-05-05 11:45:53 -07004290 char *current_ev = buf;
4291 char *end_buf = buf + len;
4292 struct ieee80211_sta_bss *bss;
4293
4294 spin_lock_bh(&local->sta_bss_lock);
4295 list_for_each_entry(bss, &local->sta_bss_list, list) {
4296 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
4297 spin_unlock_bh(&local->sta_bss_lock);
4298 return -E2BIG;
4299 }
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004300 current_ev = ieee80211_sta_scan_result(local, info, bss,
David S. Millerccc58052008-06-16 18:50:49 -07004301 current_ev, end_buf);
Jiri Bencf0706e82007-05-05 11:45:53 -07004302 }
4303 spin_unlock_bh(&local->sta_bss_lock);
4304 return current_ev - buf;
4305}
4306
4307
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004308int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07004309{
Jiri Bencf0706e82007-05-05 11:45:53 -07004310 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Johannes Berg988c0f72008-04-17 19:21:22 +02004311
Jiri Bencf0706e82007-05-05 11:45:53 -07004312 kfree(ifsta->extra_ie);
4313 if (len == 0) {
4314 ifsta->extra_ie = NULL;
4315 ifsta->extra_ie_len = 0;
4316 return 0;
4317 }
4318 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
4319 if (!ifsta->extra_ie) {
4320 ifsta->extra_ie_len = 0;
4321 return -ENOMEM;
4322 }
4323 memcpy(ifsta->extra_ie, ie, len);
4324 ifsta->extra_ie_len = len;
4325 return 0;
4326}
4327
4328
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004329struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
Johannes Berg988c0f72008-04-17 19:21:22 +02004330 struct sk_buff *skb, u8 *bssid,
Vladimir Koutny87291c02008-06-13 16:50:44 +02004331 u8 *addr, u64 supp_rates)
Jiri Bencf0706e82007-05-05 11:45:53 -07004332{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004333 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07004334 struct sta_info *sta;
Joe Perches0795af52007-10-03 17:59:30 -07004335 DECLARE_MAC_BUF(mac);
Vladimir Koutny87291c02008-06-13 16:50:44 +02004336 int band = local->hw.conf.channel->band;
Jiri Bencf0706e82007-05-05 11:45:53 -07004337
4338 /* TODO: Could consider removing the least recently used entry and
4339 * allow new one to be added. */
4340 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
4341 if (net_ratelimit()) {
4342 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004343 "entry %s\n", sdata->dev->name, print_mac(mac, addr));
Jiri Bencf0706e82007-05-05 11:45:53 -07004344 }
4345 return NULL;
4346 }
4347
Emmanuel Grumbach1e188632008-07-10 17:54:14 +03004348 if (compare_ether_addr(bssid, sdata->u.sta.bssid))
Vladimir Koutny87291c02008-06-13 16:50:44 +02004349 return NULL;
4350
Johannes Bergf4ea83d2008-06-30 15:10:46 +02004351#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07004352 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004353 wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02004354#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07004355
Johannes Berg73651ee2008-02-25 16:27:47 +01004356 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
4357 if (!sta)
Jiri Bencf0706e82007-05-05 11:45:53 -07004358 return NULL;
4359
Johannes Berg07346f812008-05-03 01:02:02 +02004360 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
Johannes Berg238814f2008-01-28 17:19:37 +01004361
Vladimir Koutny87291c02008-06-13 16:50:44 +02004362 if (supp_rates)
4363 sta->supp_rates[band] = supp_rates;
4364 else
4365 sta->supp_rates[band] = sdata->u.sta.supp_rates_bits[band];
Jiri Bencf0706e82007-05-05 11:45:53 -07004366
4367 rate_control_rate_init(sta, local);
4368
Johannes Berg93e5deb2008-04-01 15:21:00 +02004369 if (sta_info_insert(sta))
Johannes Berg73651ee2008-02-25 16:27:47 +01004370 return NULL;
Johannes Berg73651ee2008-02-25 16:27:47 +01004371
Johannes Bergd0709a62008-02-25 16:27:46 +01004372 return sta;
Jiri Bencf0706e82007-05-05 11:45:53 -07004373}
4374
4375
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004376int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
Jiri Bencf0706e82007-05-05 11:45:53 -07004377{
Jiri Bencf0706e82007-05-05 11:45:53 -07004378 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4379
Johannes Bergf4ea83d2008-06-30 15:10:46 +02004380 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004381 sdata->dev->name, reason);
Jiri Bencf0706e82007-05-05 11:45:53 -07004382
Johannes Berg51fb61e2007-12-19 01:31:27 +01004383 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4384 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07004385 return -EINVAL;
4386
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004387 ieee80211_send_deauth(sdata, ifsta, reason);
4388 ieee80211_set_disassoc(sdata, ifsta, 1);
Jiri Bencf0706e82007-05-05 11:45:53 -07004389 return 0;
4390}
4391
4392
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004393int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
Jiri Bencf0706e82007-05-05 11:45:53 -07004394{
Jiri Bencf0706e82007-05-05 11:45:53 -07004395 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4396
Johannes Bergf4ea83d2008-06-30 15:10:46 +02004397 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004398 sdata->dev->name, reason);
Jiri Bencf0706e82007-05-05 11:45:53 -07004399
Johannes Berg51fb61e2007-12-19 01:31:27 +01004400 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07004401 return -EINVAL;
4402
Jiri Slabyd6f2da52007-08-28 17:01:54 -04004403 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e82007-05-05 11:45:53 -07004404 return -1;
4405
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004406 ieee80211_send_disassoc(sdata, ifsta, reason);
4407 ieee80211_set_disassoc(sdata, ifsta, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07004408 return 0;
4409}
Mohamed Abbas84363e62008-04-04 16:59:58 -07004410
4411void ieee80211_notify_mac(struct ieee80211_hw *hw,
4412 enum ieee80211_notification_types notif_type)
4413{
4414 struct ieee80211_local *local = hw_to_local(hw);
4415 struct ieee80211_sub_if_data *sdata;
4416
4417 switch (notif_type) {
4418 case IEEE80211_NOTIFY_RE_ASSOC:
4419 rcu_read_lock();
4420 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg3e122be2008-07-09 14:40:34 +02004421 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
4422 continue;
Mohamed Abbas84363e62008-04-04 16:59:58 -07004423
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12004424 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Mohamed Abbas84363e62008-04-04 16:59:58 -07004425 }
4426 rcu_read_unlock();
4427 break;
4428 }
4429}
4430EXPORT_SYMBOL(ieee80211_notify_mac);