blob: c20ef89acad625f7006b267f9bd75e08d55a7e17 [file] [log] [blame]
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070028#include <net/iw_handler.h>
29#include <asm/types.h>
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -070030#include <asm/unaligned.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070031
32#include <net/mac80211.h>
33#include "ieee80211_i.h"
34#include "ieee80211_rate.h"
Michael Buesch47f0c502007-09-27 15:10:44 +020035#include "ieee80211_led.h"
Luis Carlos Cobof709fc62008-02-23 15:17:12 +010036#include "mesh.h"
Jiri Bencf0706e822007-05-05 11:45:53 -070037
38#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
39#define IEEE80211_AUTH_MAX_TRIES 3
40#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
41#define IEEE80211_ASSOC_MAX_TRIES 3
42#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +010043#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
Jiri Bencf0706e822007-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)
48#define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
49
50#define IEEE80211_PROBE_DELAY (HZ / 33)
51#define IEEE80211_CHANNEL_TIME (HZ / 33)
52#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
53#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
54#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
55#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +010056#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
Jiri Bencf0706e822007-05-05 11:45:53 -070057
58#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
59
60
61#define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
62
63#define ERP_INFO_USE_PROTECTION BIT(1)
64
Ron Rindjunsky9f985b02007-11-26 16:14:32 +020065/* mgmt header + 1 byte action code */
66#define IEEE80211_MIN_ACTION_SIZE (24 + 1)
67
68#define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
69#define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
70#define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
Ron Rindjunsky688b88a2007-12-25 17:00:37 +020071#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
72#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
Ron Rindjunsky9f985b02007-11-26 16:14:32 +020073
Ron Rindjunsky07db2182007-12-25 17:00:33 +020074/* next values represent the buffer size for A-MPDU frame.
75 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
76#define IEEE80211_MIN_AMPDU_BUF 0x8
77#define IEEE80211_MAX_AMPDU_BUF 0x40
78
Jiri Bencf0706e822007-05-05 11:45:53 -070079static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
80 u8 *ssid, size_t ssid_len);
81static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +010082ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -040083 u8 *ssid, u8 ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -070084static void ieee80211_rx_bss_put(struct net_device *dev,
85 struct ieee80211_sta_bss *bss);
86static int ieee80211_sta_find_ibss(struct net_device *dev,
87 struct ieee80211_if_sta *ifsta);
88static int ieee80211_sta_wep_configured(struct net_device *dev);
89static int ieee80211_sta_start_scan(struct net_device *dev,
90 u8 *ssid, size_t ssid_len);
91static int ieee80211_sta_config_auth(struct net_device *dev,
92 struct ieee80211_if_sta *ifsta);
93
94
Luis Carlos Coboee385852008-02-23 15:17:11 +010095void ieee802_11_parse_elems(u8 *start, size_t len,
96 struct ieee802_11_elems *elems)
Jiri Bencf0706e822007-05-05 11:45:53 -070097{
98 size_t left = len;
99 u8 *pos = start;
Jiri Bencf0706e822007-05-05 11:45:53 -0700100
101 memset(elems, 0, sizeof(*elems));
102
103 while (left >= 2) {
104 u8 id, elen;
105
106 id = *pos++;
107 elen = *pos++;
108 left -= 2;
109
John W. Linville67a4cce2007-10-12 16:40:37 -0400110 if (elen > left)
111 return;
Jiri Bencf0706e822007-05-05 11:45:53 -0700112
113 switch (id) {
114 case WLAN_EID_SSID:
115 elems->ssid = pos;
116 elems->ssid_len = elen;
117 break;
118 case WLAN_EID_SUPP_RATES:
119 elems->supp_rates = pos;
120 elems->supp_rates_len = elen;
121 break;
122 case WLAN_EID_FH_PARAMS:
123 elems->fh_params = pos;
124 elems->fh_params_len = elen;
125 break;
126 case WLAN_EID_DS_PARAMS:
127 elems->ds_params = pos;
128 elems->ds_params_len = elen;
129 break;
130 case WLAN_EID_CF_PARAMS:
131 elems->cf_params = pos;
132 elems->cf_params_len = elen;
133 break;
134 case WLAN_EID_TIM:
135 elems->tim = pos;
136 elems->tim_len = elen;
137 break;
138 case WLAN_EID_IBSS_PARAMS:
139 elems->ibss_params = pos;
140 elems->ibss_params_len = elen;
141 break;
142 case WLAN_EID_CHALLENGE:
143 elems->challenge = pos;
144 elems->challenge_len = elen;
145 break;
146 case WLAN_EID_WPA:
147 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
148 pos[2] == 0xf2) {
149 /* Microsoft OUI (00:50:F2) */
150 if (pos[3] == 1) {
151 /* OUI Type 1 - WPA IE */
152 elems->wpa = pos;
153 elems->wpa_len = elen;
154 } else if (elen >= 5 && pos[3] == 2) {
155 if (pos[4] == 0) {
156 elems->wmm_info = pos;
157 elems->wmm_info_len = elen;
158 } else if (pos[4] == 1) {
159 elems->wmm_param = pos;
160 elems->wmm_param_len = elen;
161 }
162 }
163 }
164 break;
165 case WLAN_EID_RSN:
166 elems->rsn = pos;
167 elems->rsn_len = elen;
168 break;
169 case WLAN_EID_ERP_INFO:
170 elems->erp_info = pos;
171 elems->erp_info_len = elen;
172 break;
173 case WLAN_EID_EXT_SUPP_RATES:
174 elems->ext_supp_rates = pos;
175 elems->ext_supp_rates_len = elen;
176 break;
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200177 case WLAN_EID_HT_CAPABILITY:
178 elems->ht_cap_elem = pos;
179 elems->ht_cap_elem_len = elen;
180 break;
181 case WLAN_EID_HT_EXTRA_INFO:
182 elems->ht_info_elem = pos;
183 elems->ht_info_elem_len = elen;
184 break;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100185 case WLAN_EID_MESH_ID:
186 elems->mesh_id = pos;
187 elems->mesh_id_len = elen;
188 break;
189 case WLAN_EID_MESH_CONFIG:
190 elems->mesh_config = pos;
191 elems->mesh_config_len = elen;
192 break;
193 case WLAN_EID_PEER_LINK:
194 elems->peer_link = pos;
195 elems->peer_link_len = elen;
196 break;
197 case WLAN_EID_PREQ:
198 elems->preq = pos;
199 elems->preq_len = elen;
200 break;
201 case WLAN_EID_PREP:
202 elems->prep = pos;
203 elems->prep_len = elen;
204 break;
205 case WLAN_EID_PERR:
206 elems->perr = pos;
207 elems->perr_len = elen;
208 break;
Jiri Bencf0706e822007-05-05 11:45:53 -0700209 default:
Jiri Bencf0706e822007-05-05 11:45:53 -0700210 break;
211 }
212
213 left -= elen;
214 pos += elen;
215 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700216}
217
218
Jiri Bencf0706e822007-05-05 11:45:53 -0700219static int ecw2cw(int ecw)
220{
Johannes Bergac2bf322008-02-14 00:30:35 +0100221 return (1 << ecw) - 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700222}
223
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100224
225static void ieee80211_sta_def_wmm_params(struct net_device *dev,
226 struct ieee80211_sta_bss *bss,
227 int ibss)
228{
229 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
230 struct ieee80211_local *local = sdata->local;
231 int i, have_higher_than_11mbit = 0;
232
233
234 /* cf. IEEE 802.11 9.2.12 */
235 for (i = 0; i < bss->supp_rates_len; i++)
236 if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
237 have_higher_than_11mbit = 1;
238
239 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
240 have_higher_than_11mbit)
241 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
242 else
243 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
244
245
246 if (local->ops->conf_tx) {
247 struct ieee80211_tx_queue_params qparam;
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100248
249 memset(&qparam, 0, sizeof(qparam));
250
251 qparam.aifs = 2;
252
253 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
254 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
255 qparam.cw_min = 31;
256 else
257 qparam.cw_min = 15;
258
259 qparam.cw_max = 1023;
260 qparam.txop = 0;
261
262 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
263 local->ops->conf_tx(local_to_hw(local),
264 i + IEEE80211_TX_QUEUE_DATA0,
265 &qparam);
266
267 if (ibss) {
268 /* IBSS uses different parameters for Beacon sending */
269 qparam.cw_min++;
270 qparam.cw_min *= 2;
271 qparam.cw_min--;
272 local->ops->conf_tx(local_to_hw(local),
273 IEEE80211_TX_QUEUE_BEACON, &qparam);
274 }
275 }
276}
277
Jiri Bencf0706e822007-05-05 11:45:53 -0700278static void ieee80211_sta_wmm_params(struct net_device *dev,
279 struct ieee80211_if_sta *ifsta,
280 u8 *wmm_param, size_t wmm_param_len)
281{
282 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
283 struct ieee80211_tx_queue_params params;
284 size_t left;
285 int count;
286 u8 *pos;
287
288 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
289 return;
290 count = wmm_param[6] & 0x0f;
291 if (count == ifsta->wmm_last_param_set)
292 return;
293 ifsta->wmm_last_param_set = count;
294
295 pos = wmm_param + 8;
296 left = wmm_param_len - 8;
297
298 memset(&params, 0, sizeof(params));
299
300 if (!local->ops->conf_tx)
301 return;
302
303 local->wmm_acm = 0;
304 for (; left >= 4; left -= 4, pos += 4) {
305 int aci = (pos[0] >> 5) & 0x03;
306 int acm = (pos[0] >> 4) & 0x01;
307 int queue;
308
309 switch (aci) {
310 case 1:
311 queue = IEEE80211_TX_QUEUE_DATA3;
312 if (acm) {
313 local->wmm_acm |= BIT(0) | BIT(3);
314 }
315 break;
316 case 2:
317 queue = IEEE80211_TX_QUEUE_DATA1;
318 if (acm) {
319 local->wmm_acm |= BIT(4) | BIT(5);
320 }
321 break;
322 case 3:
323 queue = IEEE80211_TX_QUEUE_DATA0;
324 if (acm) {
325 local->wmm_acm |= BIT(6) | BIT(7);
326 }
327 break;
328 case 0:
329 default:
330 queue = IEEE80211_TX_QUEUE_DATA2;
331 if (acm) {
332 local->wmm_acm |= BIT(1) | BIT(2);
333 }
334 break;
335 }
336
337 params.aifs = pos[0] & 0x0f;
338 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
339 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100340 params.txop = pos[2] | (pos[3] << 8);
341#ifdef CONFIG_MAC80211_DEBUG
Jiri Bencf0706e822007-05-05 11:45:53 -0700342 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100343 "cWmin=%d cWmax=%d txop=%d\n",
Jiri Bencf0706e822007-05-05 11:45:53 -0700344 dev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100345 params.cw_max, params.txop);
346#endif
Jiri Bencf0706e822007-05-05 11:45:53 -0700347 /* TODO: handle ACM (block TX, fallback to next lowest allowed
348 * AC for now) */
349 if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
350 printk(KERN_DEBUG "%s: failed to set TX queue "
351 "parameters for queue %d\n", dev->name, queue);
352 }
353 }
354}
355
356
Johannes Berg471b3ef2007-12-28 14:32:58 +0100357static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
358 u8 erp_value)
Daniel Drake56282212007-07-10 19:32:10 +0200359{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100360 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
Daniel Drake56282212007-07-10 19:32:10 +0200361 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100362 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200363 bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0;
Joe Perches0795af52007-10-03 17:59:30 -0700364 DECLARE_MAC_BUF(mac);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100365 u32 changed = 0;
Daniel Drake56282212007-07-10 19:32:10 +0200366
Johannes Berg471b3ef2007-12-28 14:32:58 +0100367 if (use_protection != bss_conf->use_cts_prot) {
Daniel Drake56282212007-07-10 19:32:10 +0200368 if (net_ratelimit()) {
369 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
Joe Perches0795af52007-10-03 17:59:30 -0700370 "%s)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100371 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200372 use_protection ? "enabled" : "disabled",
Joe Perches0795af52007-10-03 17:59:30 -0700373 print_mac(mac, ifsta->bssid));
Daniel Drake56282212007-07-10 19:32:10 +0200374 }
Johannes Berg471b3ef2007-12-28 14:32:58 +0100375 bss_conf->use_cts_prot = use_protection;
376 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200377 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200378
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200379 if (use_short_preamble != bss_conf->use_short_preamble) {
Daniel Drake7e9ed182007-07-27 15:43:24 +0200380 if (net_ratelimit()) {
381 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Joe Perches0795af52007-10-03 17:59:30 -0700382 " (BSSID=%s)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100383 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200384 use_short_preamble ? "short" : "long",
Joe Perches0795af52007-10-03 17:59:30 -0700385 print_mac(mac, ifsta->bssid));
Daniel Drake7e9ed182007-07-27 15:43:24 +0200386 }
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200387 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100388 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200389 }
Daniel Draked9430a32007-07-27 15:43:24 +0200390
Johannes Berg471b3ef2007-12-28 14:32:58 +0100391 return changed;
Daniel Drake56282212007-07-10 19:32:10 +0200392}
393
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200394int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
395 struct ieee80211_ht_info *ht_info)
396{
397
398 if (ht_info == NULL)
399 return -EINVAL;
400
401 memset(ht_info, 0, sizeof(*ht_info));
402
403 if (ht_cap_ie) {
404 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
405
406 ht_info->ht_supported = 1;
407 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
408 ht_info->ampdu_factor =
409 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
410 ht_info->ampdu_density =
411 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
412 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
413 } else
414 ht_info->ht_supported = 0;
415
416 return 0;
417}
418
419int ieee80211_ht_addt_info_ie_to_ht_bss_info(
420 struct ieee80211_ht_addt_info *ht_add_info_ie,
421 struct ieee80211_ht_bss_info *bss_info)
422{
423 if (bss_info == NULL)
424 return -EINVAL;
425
426 memset(bss_info, 0, sizeof(*bss_info));
427
428 if (ht_add_info_ie) {
429 u16 op_mode;
430 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
431
432 bss_info->primary_channel = ht_add_info_ie->control_chan;
433 bss_info->bss_cap = ht_add_info_ie->ht_param;
434 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
435 }
436
437 return 0;
438}
Daniel Drake56282212007-07-10 19:32:10 +0200439
Jiri Bencf0706e822007-05-05 11:45:53 -0700440static void ieee80211_sta_send_associnfo(struct net_device *dev,
441 struct ieee80211_if_sta *ifsta)
442{
443 char *buf;
444 size_t len;
445 int i;
446 union iwreq_data wrqu;
447
448 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
449 return;
450
451 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
Michael Wu0ec0b7a2007-07-27 15:43:24 +0200452 ifsta->assocresp_ies_len), GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -0700453 if (!buf)
454 return;
455
456 len = sprintf(buf, "ASSOCINFO(");
457 if (ifsta->assocreq_ies) {
458 len += sprintf(buf + len, "ReqIEs=");
459 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
460 len += sprintf(buf + len, "%02x",
461 ifsta->assocreq_ies[i]);
462 }
463 }
464 if (ifsta->assocresp_ies) {
465 if (ifsta->assocreq_ies)
466 len += sprintf(buf + len, " ");
467 len += sprintf(buf + len, "RespIEs=");
468 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
469 len += sprintf(buf + len, "%02x",
470 ifsta->assocresp_ies[i]);
471 }
472 }
473 len += sprintf(buf + len, ")");
474
475 if (len > IW_CUSTOM_MAX) {
476 len = sprintf(buf, "ASSOCRESPIE=");
477 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
478 len += sprintf(buf + len, "%02x",
479 ifsta->assocresp_ies[i]);
480 }
481 }
482
483 memset(&wrqu, 0, sizeof(wrqu));
484 wrqu.data.length = len;
485 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
486
487 kfree(buf);
488}
489
490
491static void ieee80211_set_associated(struct net_device *dev,
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400492 struct ieee80211_if_sta *ifsta,
Michael Buesch47f0c502007-09-27 15:10:44 +0200493 bool assoc)
Jiri Bencf0706e822007-05-05 11:45:53 -0700494{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100495 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
496 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e822007-05-05 11:45:53 -0700497 union iwreq_data wrqu;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100498 u32 changed = BSS_CHANGED_ASSOC;
Jiri Bencf0706e822007-05-05 11:45:53 -0700499
Jiri Bencf0706e822007-05-05 11:45:53 -0700500 if (assoc) {
Daniel Drake56282212007-07-10 19:32:10 +0200501 struct ieee80211_sta_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400502
503 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
504
Johannes Berg51fb61e2007-12-19 01:31:27 +0100505 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -0700506 return;
Daniel Drake56282212007-07-10 19:32:10 +0200507
John W. Linville65c107a2007-10-05 14:23:27 -0400508 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +0100509 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400510 ifsta->ssid, ifsta->ssid_len);
Daniel Drake56282212007-07-10 19:32:10 +0200511 if (bss) {
512 if (bss->has_erp_value)
Johannes Berg471b3ef2007-12-28 14:32:58 +0100513 changed |= ieee80211_handle_erp_ie(
514 sdata, bss->erp_value);
Daniel Drake56282212007-07-10 19:32:10 +0200515 ieee80211_rx_bss_put(dev, bss);
516 }
517
Jiri Bencf0706e822007-05-05 11:45:53 -0700518 netif_carrier_on(dev);
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400519 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e822007-05-05 11:45:53 -0700520 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
521 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
522 ieee80211_sta_send_associnfo(dev, ifsta);
523 } else {
Ron Rindjunsky85249e52008-03-18 15:00:32 -0700524 ieee80211_sta_tear_down_BA_sessions(dev, ifsta->bssid);
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400525 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
Jiri Bencf0706e822007-05-05 11:45:53 -0700526 netif_carrier_off(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200527 ieee80211_reset_erp_info(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -0700528 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
529 }
530 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
531 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
532 ifsta->last_probe = jiffies;
Michael Buesch47f0c502007-09-27 15:10:44 +0200533 ieee80211_led_assoc(local, assoc);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100534
Tomas Winklerb2205252008-01-27 16:18:22 +0200535 sdata->bss_conf.assoc = assoc;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100536 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e822007-05-05 11:45:53 -0700537}
538
539static void ieee80211_set_disassoc(struct net_device *dev,
540 struct ieee80211_if_sta *ifsta, int deauth)
541{
542 if (deauth)
543 ifsta->auth_tries = 0;
544 ifsta->assoc_tries = 0;
545 ieee80211_set_associated(dev, ifsta, 0);
546}
547
Luis Carlos Coboee385852008-02-23 15:17:11 +0100548void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
549 int encrypt)
Jiri Bencf0706e822007-05-05 11:45:53 -0700550{
551 struct ieee80211_sub_if_data *sdata;
552 struct ieee80211_tx_packet_data *pkt_data;
553
554 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555 skb->dev = sdata->local->mdev;
556 skb_set_mac_header(skb, 0);
557 skb_set_network_header(skb, 0);
558 skb_set_transport_header(skb, 0);
559
560 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
561 memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
562 pkt_data->ifindex = sdata->dev->ifindex;
Jiri Slabye8bf9642007-08-28 17:01:54 -0400563 if (!encrypt)
564 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
Jiri Bencf0706e822007-05-05 11:45:53 -0700565
566 dev_queue_xmit(skb);
567}
568
569
570static void ieee80211_send_auth(struct net_device *dev,
571 struct ieee80211_if_sta *ifsta,
572 int transaction, u8 *extra, size_t extra_len,
573 int encrypt)
574{
575 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
576 struct sk_buff *skb;
577 struct ieee80211_mgmt *mgmt;
578
579 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
580 sizeof(*mgmt) + 6 + extra_len);
581 if (!skb) {
582 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
583 "frame\n", dev->name);
584 return;
585 }
586 skb_reserve(skb, local->hw.extra_tx_headroom);
587
588 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
589 memset(mgmt, 0, 24 + 6);
590 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
591 IEEE80211_STYPE_AUTH);
592 if (encrypt)
593 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
594 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
595 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
596 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
597 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
598 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
599 ifsta->auth_transaction = transaction + 1;
600 mgmt->u.auth.status_code = cpu_to_le16(0);
601 if (extra)
602 memcpy(skb_put(skb, extra_len), extra, extra_len);
603
604 ieee80211_sta_tx(dev, skb, encrypt);
605}
606
607
608static void ieee80211_authenticate(struct net_device *dev,
609 struct ieee80211_if_sta *ifsta)
610{
Joe Perches0795af52007-10-03 17:59:30 -0700611 DECLARE_MAC_BUF(mac);
612
Jiri Bencf0706e822007-05-05 11:45:53 -0700613 ifsta->auth_tries++;
614 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Joe Perches0795af52007-10-03 17:59:30 -0700615 printk(KERN_DEBUG "%s: authentication with AP %s"
Jiri Bencf0706e822007-05-05 11:45:53 -0700616 " timed out\n",
Joe Perches0795af52007-10-03 17:59:30 -0700617 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -0700618 ifsta->state = IEEE80211_DISABLED;
619 return;
620 }
621
622 ifsta->state = IEEE80211_AUTHENTICATE;
Joe Perches0795af52007-10-03 17:59:30 -0700623 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
624 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -0700625
626 ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
627
628 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
629}
630
631
632static void ieee80211_send_assoc(struct net_device *dev,
633 struct ieee80211_if_sta *ifsta)
634{
635 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e822007-05-05 11:45:53 -0700636 struct sk_buff *skb;
637 struct ieee80211_mgmt *mgmt;
638 u8 *pos, *ies;
639 int i, len;
640 u16 capab;
641 struct ieee80211_sta_bss *bss;
642 int wmm = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100643 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -0700644
645 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
646 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
647 ifsta->ssid_len);
648 if (!skb) {
649 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
650 "frame\n", dev->name);
651 return;
652 }
653 skb_reserve(skb, local->hw.extra_tx_headroom);
654
Johannes Berg8318d782008-01-24 19:38:38 +0100655 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
656
Jiri Bencf0706e822007-05-05 11:45:53 -0700657 capab = ifsta->capab;
Johannes Berg8318d782008-01-24 19:38:38 +0100658
659 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
660 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
661 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
662 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
663 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Jiri Bencf0706e822007-05-05 11:45:53 -0700664 }
Johannes Berg8318d782008-01-24 19:38:38 +0100665
666 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
667 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400668 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700669 if (bss) {
670 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
671 capab |= WLAN_CAPABILITY_PRIVACY;
672 if (bss->wmm_ie) {
673 wmm = 1;
674 }
675 ieee80211_rx_bss_put(dev, bss);
676 }
677
678 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
679 memset(mgmt, 0, 24);
680 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
681 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
682 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
683
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400684 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700685 skb_put(skb, 10);
686 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
687 IEEE80211_STYPE_REASSOC_REQ);
688 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
689 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
690 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
691 ETH_ALEN);
692 } else {
693 skb_put(skb, 4);
694 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
695 IEEE80211_STYPE_ASSOC_REQ);
696 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
697 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
698 }
699
700 /* SSID */
701 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
702 *pos++ = WLAN_EID_SSID;
703 *pos++ = ifsta->ssid_len;
704 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
705
Johannes Berg8318d782008-01-24 19:38:38 +0100706 len = sband->n_bitrates;
Jiri Bencf0706e822007-05-05 11:45:53 -0700707 if (len > 8)
708 len = 8;
709 pos = skb_put(skb, len + 2);
710 *pos++ = WLAN_EID_SUPP_RATES;
711 *pos++ = len;
712 for (i = 0; i < len; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +0100713 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e822007-05-05 11:45:53 -0700714 *pos++ = (u8) (rate / 5);
715 }
716
Johannes Berg8318d782008-01-24 19:38:38 +0100717 if (sband->n_bitrates > len) {
718 pos = skb_put(skb, sband->n_bitrates - len + 2);
Jiri Bencf0706e822007-05-05 11:45:53 -0700719 *pos++ = WLAN_EID_EXT_SUPP_RATES;
Johannes Berg8318d782008-01-24 19:38:38 +0100720 *pos++ = sband->n_bitrates - len;
721 for (i = len; i < sband->n_bitrates; i++) {
722 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e822007-05-05 11:45:53 -0700723 *pos++ = (u8) (rate / 5);
724 }
725 }
726
727 if (ifsta->extra_ie) {
728 pos = skb_put(skb, ifsta->extra_ie_len);
729 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
730 }
731
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400732 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700733 pos = skb_put(skb, 9);
734 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
735 *pos++ = 7; /* len */
736 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
737 *pos++ = 0x50;
738 *pos++ = 0xf2;
739 *pos++ = 2; /* WME */
740 *pos++ = 0; /* WME info */
741 *pos++ = 1; /* WME ver */
742 *pos++ = 0;
743 }
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200744 /* wmm support is a must to HT */
Johannes Berg8318d782008-01-24 19:38:38 +0100745 if (wmm && sband->ht_info.ht_supported) {
746 __le16 tmp = cpu_to_le16(sband->ht_info.cap);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200747 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
748 *pos++ = WLAN_EID_HT_CAPABILITY;
749 *pos++ = sizeof(struct ieee80211_ht_cap);
750 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
751 memcpy(pos, &tmp, sizeof(u16));
752 pos += sizeof(u16);
Johannes Berg8318d782008-01-24 19:38:38 +0100753 /* TODO: needs a define here for << 2 */
754 *pos++ = sband->ht_info.ampdu_factor |
755 (sband->ht_info.ampdu_density << 2);
756 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200757 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700758
759 kfree(ifsta->assocreq_ies);
760 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
Michael Wu0ec0b7a2007-07-27 15:43:24 +0200761 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -0700762 if (ifsta->assocreq_ies)
763 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
764
765 ieee80211_sta_tx(dev, skb, 0);
766}
767
768
769static void ieee80211_send_deauth(struct net_device *dev,
770 struct ieee80211_if_sta *ifsta, u16 reason)
771{
772 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
773 struct sk_buff *skb;
774 struct ieee80211_mgmt *mgmt;
775
776 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
777 if (!skb) {
778 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
779 "frame\n", dev->name);
780 return;
781 }
782 skb_reserve(skb, local->hw.extra_tx_headroom);
783
784 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
785 memset(mgmt, 0, 24);
786 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
787 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
788 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
789 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
790 IEEE80211_STYPE_DEAUTH);
791 skb_put(skb, 2);
792 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
793
794 ieee80211_sta_tx(dev, skb, 0);
795}
796
797
798static void ieee80211_send_disassoc(struct net_device *dev,
799 struct ieee80211_if_sta *ifsta, u16 reason)
800{
801 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
802 struct sk_buff *skb;
803 struct ieee80211_mgmt *mgmt;
804
805 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
806 if (!skb) {
807 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
808 "frame\n", dev->name);
809 return;
810 }
811 skb_reserve(skb, local->hw.extra_tx_headroom);
812
813 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
814 memset(mgmt, 0, 24);
815 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
816 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
817 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
818 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
819 IEEE80211_STYPE_DISASSOC);
820 skb_put(skb, 2);
821 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
822
823 ieee80211_sta_tx(dev, skb, 0);
824}
825
826
827static int ieee80211_privacy_mismatch(struct net_device *dev,
828 struct ieee80211_if_sta *ifsta)
829{
John W. Linville65c107a2007-10-05 14:23:27 -0400830 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e822007-05-05 11:45:53 -0700831 struct ieee80211_sta_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000832 int bss_privacy;
833 int wep_privacy;
834 int privacy_invoked;
Jiri Bencf0706e822007-05-05 11:45:53 -0700835
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000836 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
Jiri Bencf0706e822007-05-05 11:45:53 -0700837 return 0;
838
Johannes Berg8318d782008-01-24 19:38:38 +0100839 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
840 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400841 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700842 if (!bss)
843 return 0;
844
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000845 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
846 wep_privacy = !!ieee80211_sta_wep_configured(dev);
847 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e822007-05-05 11:45:53 -0700848
849 ieee80211_rx_bss_put(dev, bss);
850
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000851 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
852 return 0;
853
854 return 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700855}
856
857
858static void ieee80211_associate(struct net_device *dev,
859 struct ieee80211_if_sta *ifsta)
860{
Joe Perches0795af52007-10-03 17:59:30 -0700861 DECLARE_MAC_BUF(mac);
862
Jiri Bencf0706e822007-05-05 11:45:53 -0700863 ifsta->assoc_tries++;
864 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Joe Perches0795af52007-10-03 17:59:30 -0700865 printk(KERN_DEBUG "%s: association with AP %s"
Jiri Bencf0706e822007-05-05 11:45:53 -0700866 " timed out\n",
Joe Perches0795af52007-10-03 17:59:30 -0700867 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -0700868 ifsta->state = IEEE80211_DISABLED;
869 return;
870 }
871
872 ifsta->state = IEEE80211_ASSOCIATE;
Joe Perches0795af52007-10-03 17:59:30 -0700873 printk(KERN_DEBUG "%s: associate with AP %s\n",
874 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -0700875 if (ieee80211_privacy_mismatch(dev, ifsta)) {
876 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
877 "mixed-cell disabled - abort association\n", dev->name);
878 ifsta->state = IEEE80211_DISABLED;
879 return;
880 }
881
882 ieee80211_send_assoc(dev, ifsta);
883
884 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
885}
886
887
888static void ieee80211_associated(struct net_device *dev,
889 struct ieee80211_if_sta *ifsta)
890{
891 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
892 struct sta_info *sta;
893 int disassoc;
Joe Perches0795af52007-10-03 17:59:30 -0700894 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -0700895
896 /* TODO: start monitoring current AP signal quality and number of
897 * missed beacons. Scan other channels every now and then and search
898 * for better APs. */
899 /* TODO: remove expired BSSes */
900
901 ifsta->state = IEEE80211_ASSOCIATED;
902
Johannes Bergd0709a62008-02-25 16:27:46 +0100903 rcu_read_lock();
904
Jiri Bencf0706e822007-05-05 11:45:53 -0700905 sta = sta_info_get(local, ifsta->bssid);
906 if (!sta) {
Joe Perches0795af52007-10-03 17:59:30 -0700907 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
908 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -0700909 disassoc = 1;
910 } else {
911 disassoc = 0;
912 if (time_after(jiffies,
913 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400914 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700915 printk(KERN_DEBUG "%s: No ProbeResp from "
Joe Perches0795af52007-10-03 17:59:30 -0700916 "current AP %s - assume out of "
Jiri Bencf0706e822007-05-05 11:45:53 -0700917 "range\n",
Joe Perches0795af52007-10-03 17:59:30 -0700918 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -0700919 disassoc = 1;
Johannes Bergd0709a62008-02-25 16:27:46 +0100920 sta_info_unlink(&sta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400921 } else
Jiri Bencf0706e822007-05-05 11:45:53 -0700922 ieee80211_send_probe_req(dev, ifsta->bssid,
923 local->scan_ssid,
924 local->scan_ssid_len);
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400925 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700926 } else {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400927 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700928 if (time_after(jiffies, ifsta->last_probe +
929 IEEE80211_PROBE_INTERVAL)) {
930 ifsta->last_probe = jiffies;
931 ieee80211_send_probe_req(dev, ifsta->bssid,
932 ifsta->ssid,
933 ifsta->ssid_len);
934 }
935 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700936 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100937
938 rcu_read_unlock();
939
940 if (disassoc && sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100941 rtnl_lock();
942 sta_info_destroy(sta);
943 rtnl_unlock();
944 }
945
Jiri Bencf0706e822007-05-05 11:45:53 -0700946 if (disassoc) {
Michael Wu2d192d92007-11-10 00:15:25 -0500947 ifsta->state = IEEE80211_DISABLED;
948 ieee80211_set_associated(dev, ifsta, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -0700949 } else {
950 mod_timer(&ifsta->timer, jiffies +
951 IEEE80211_MONITORING_INTERVAL);
952 }
953}
954
955
956static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
957 u8 *ssid, size_t ssid_len)
958{
959 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100960 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -0700961 struct sk_buff *skb;
962 struct ieee80211_mgmt *mgmt;
963 u8 *pos, *supp_rates, *esupp_rates = NULL;
964 int i;
965
966 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
967 if (!skb) {
968 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
969 "request\n", dev->name);
970 return;
971 }
972 skb_reserve(skb, local->hw.extra_tx_headroom);
973
974 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
975 memset(mgmt, 0, 24);
976 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
977 IEEE80211_STYPE_PROBE_REQ);
978 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
979 if (dst) {
980 memcpy(mgmt->da, dst, ETH_ALEN);
981 memcpy(mgmt->bssid, dst, ETH_ALEN);
982 } else {
983 memset(mgmt->da, 0xff, ETH_ALEN);
984 memset(mgmt->bssid, 0xff, ETH_ALEN);
985 }
986 pos = skb_put(skb, 2 + ssid_len);
987 *pos++ = WLAN_EID_SSID;
988 *pos++ = ssid_len;
989 memcpy(pos, ssid, ssid_len);
990
991 supp_rates = skb_put(skb, 2);
992 supp_rates[0] = WLAN_EID_SUPP_RATES;
993 supp_rates[1] = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100994 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
995
996 for (i = 0; i < sband->n_bitrates; i++) {
997 struct ieee80211_rate *rate = &sband->bitrates[i];
Jiri Bencf0706e822007-05-05 11:45:53 -0700998 if (esupp_rates) {
999 pos = skb_put(skb, 1);
1000 esupp_rates[1]++;
1001 } else if (supp_rates[1] == 8) {
1002 esupp_rates = skb_put(skb, 3);
1003 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
1004 esupp_rates[1] = 1;
1005 pos = &esupp_rates[2];
1006 } else {
1007 pos = skb_put(skb, 1);
1008 supp_rates[1]++;
1009 }
Johannes Berg8318d782008-01-24 19:38:38 +01001010 *pos = rate->bitrate / 5;
Jiri Bencf0706e822007-05-05 11:45:53 -07001011 }
1012
1013 ieee80211_sta_tx(dev, skb, 0);
1014}
1015
1016
1017static int ieee80211_sta_wep_configured(struct net_device *dev)
1018{
1019 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1020 if (!sdata || !sdata->default_key ||
Johannes Berg8f20fc22007-08-28 17:01:54 -04001021 sdata->default_key->conf.alg != ALG_WEP)
Jiri Bencf0706e822007-05-05 11:45:53 -07001022 return 0;
1023 return 1;
1024}
1025
1026
1027static void ieee80211_auth_completed(struct net_device *dev,
1028 struct ieee80211_if_sta *ifsta)
1029{
1030 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001031 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
Jiri Bencf0706e822007-05-05 11:45:53 -07001032 ieee80211_associate(dev, ifsta);
1033}
1034
1035
1036static void ieee80211_auth_challenge(struct net_device *dev,
1037 struct ieee80211_if_sta *ifsta,
1038 struct ieee80211_mgmt *mgmt,
1039 size_t len)
1040{
1041 u8 *pos;
1042 struct ieee802_11_elems elems;
1043
1044 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
1045 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001046 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07001047 if (!elems.challenge) {
1048 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
1049 "frame\n", dev->name);
1050 return;
1051 }
1052 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
1053 elems.challenge_len + 2, 1);
1054}
1055
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001056static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
1057 u8 dialog_token, u16 status, u16 policy,
1058 u16 buf_size, u16 timeout)
1059{
1060 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1061 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1062 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1063 struct sk_buff *skb;
1064 struct ieee80211_mgmt *mgmt;
1065 u16 capab;
1066
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001067 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1068 sizeof(mgmt->u.action.u.addba_resp));
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001069 if (!skb) {
1070 printk(KERN_DEBUG "%s: failed to allocate buffer "
1071 "for addba resp frame\n", dev->name);
1072 return;
1073 }
1074
1075 skb_reserve(skb, local->hw.extra_tx_headroom);
1076 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1077 memset(mgmt, 0, 24);
1078 memcpy(mgmt->da, da, ETH_ALEN);
1079 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001080 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001081 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1082 else
1083 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1084 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1085 IEEE80211_STYPE_ACTION);
1086
1087 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1088 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1089 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1090 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1091
1092 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1093 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1094 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1095
1096 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1097 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1098 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1099
1100 ieee80211_sta_tx(dev, skb, 0);
1101
1102 return;
1103}
1104
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001105void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1106 u16 tid, u8 dialog_token, u16 start_seq_num,
1107 u16 agg_size, u16 timeout)
1108{
1109 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1110 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1111 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1112 struct sk_buff *skb;
1113 struct ieee80211_mgmt *mgmt;
1114 u16 capab;
1115
1116 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1117 sizeof(mgmt->u.action.u.addba_req));
1118
1119
1120 if (!skb) {
1121 printk(KERN_ERR "%s: failed to allocate buffer "
1122 "for addba request frame\n", dev->name);
1123 return;
1124 }
1125 skb_reserve(skb, local->hw.extra_tx_headroom);
1126 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1127 memset(mgmt, 0, 24);
1128 memcpy(mgmt->da, da, ETH_ALEN);
1129 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1130 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1131 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1132 else
1133 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1134
1135 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1136 IEEE80211_STYPE_ACTION);
1137
1138 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1139
1140 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1141 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1142
1143 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1144 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1145 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1146 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1147
1148 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1149
1150 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1151 mgmt->u.action.u.addba_req.start_seq_num =
1152 cpu_to_le16(start_seq_num << 4);
1153
1154 ieee80211_sta_tx(dev, skb, 0);
1155}
1156
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001157static void ieee80211_sta_process_addba_request(struct net_device *dev,
1158 struct ieee80211_mgmt *mgmt,
1159 size_t len)
1160{
1161 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001162 struct ieee80211_hw *hw = &local->hw;
1163 struct ieee80211_conf *conf = &hw->conf;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001164 struct sta_info *sta;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001165 struct tid_ampdu_rx *tid_agg_rx;
1166 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001167 u8 dialog_token;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001168 int ret = -EOPNOTSUPP;
1169 DECLARE_MAC_BUF(mac);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001170
Johannes Bergd0709a62008-02-25 16:27:46 +01001171 rcu_read_lock();
1172
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001173 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001174 if (!sta) {
1175 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001176 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001177 }
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001178
1179 /* extract session parameters from addba request frame */
1180 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1181 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001182 start_seq_num =
1183 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001184
1185 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1186 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1187 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1188 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1189
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001190 status = WLAN_STATUS_REQUEST_DECLINED;
1191
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001192 /* sanity check for incoming parameters:
1193 * check if configuration can support the BA policy
1194 * and if buffer size does not exceeds max value */
1195 if (((ba_policy != 1)
1196 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1197 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1198 status = WLAN_STATUS_INVALID_QOS_PARAM;
1199#ifdef CONFIG_MAC80211_HT_DEBUG
1200 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001201 printk(KERN_DEBUG "AddBA Req with bad params from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001202 "%s on tid %u. policy %d, buffer size %d\n",
1203 print_mac(mac, mgmt->sa), tid, ba_policy,
1204 buf_size);
1205#endif /* CONFIG_MAC80211_HT_DEBUG */
1206 goto end_no_lock;
1207 }
1208 /* determine default buffer size */
1209 if (buf_size == 0) {
Johannes Berg8318d782008-01-24 19:38:38 +01001210 struct ieee80211_supported_band *sband;
1211
1212 sband = local->hw.wiphy->bands[conf->channel->band];
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001213 buf_size = IEEE80211_MIN_AMPDU_BUF;
Johannes Berg8318d782008-01-24 19:38:38 +01001214 buf_size = buf_size << sband->ht_info.ampdu_factor;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001215 }
1216
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001217
1218 /* examine state machine */
1219 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1220
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001221 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001222#ifdef CONFIG_MAC80211_HT_DEBUG
1223 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001224 printk(KERN_DEBUG "unexpected AddBA Req from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001225 "%s on tid %u\n",
1226 print_mac(mac, mgmt->sa), tid);
1227#endif /* CONFIG_MAC80211_HT_DEBUG */
1228 goto end;
1229 }
1230
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001231 /* prepare A-MPDU MLME for Rx aggregation */
1232 sta->ampdu_mlme.tid_rx[tid] =
1233 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
1234 if (!sta->ampdu_mlme.tid_rx[tid]) {
1235 if (net_ratelimit())
1236 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
1237 tid);
1238 goto end;
1239 }
1240 /* rx timer */
1241 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
1242 sta_rx_agg_session_timer_expired;
1243 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
1244 (unsigned long)&sta->timer_to_tid[tid];
1245 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1246
1247 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
1248
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001249 /* prepare reordering buffer */
1250 tid_agg_rx->reorder_buf =
1251 kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
Johannes Berg03147df2008-02-26 00:39:28 +01001252 if (!tid_agg_rx->reorder_buf) {
1253 if (net_ratelimit())
1254 printk(KERN_ERR "can not allocate reordering buffer "
1255 "to tid %d\n", tid);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001256 kfree(sta->ampdu_mlme.tid_rx[tid]);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001257 goto end;
1258 }
1259 memset(tid_agg_rx->reorder_buf, 0,
1260 buf_size * sizeof(struct sk_buf *));
1261
1262 if (local->ops->ampdu_action)
1263 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001264 sta->addr, tid, &start_seq_num);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001265#ifdef CONFIG_MAC80211_HT_DEBUG
1266 printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
1267#endif /* CONFIG_MAC80211_HT_DEBUG */
1268
1269 if (ret) {
1270 kfree(tid_agg_rx->reorder_buf);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001271 kfree(tid_agg_rx);
1272 sta->ampdu_mlme.tid_rx[tid] = NULL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001273 goto end;
1274 }
1275
1276 /* change state and send addba resp */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001277 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001278 tid_agg_rx->dialog_token = dialog_token;
1279 tid_agg_rx->ssn = start_seq_num;
1280 tid_agg_rx->head_seq_num = start_seq_num;
1281 tid_agg_rx->buf_size = buf_size;
1282 tid_agg_rx->timeout = timeout;
1283 tid_agg_rx->stored_mpdu_num = 0;
1284 status = WLAN_STATUS_SUCCESS;
1285end:
1286 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1287
1288end_no_lock:
Johannes Bergd0709a62008-02-25 16:27:46 +01001289 ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
1290 dialog_token, status, 1, buf_size, timeout);
1291 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001292}
Jiri Bencf0706e822007-05-05 11:45:53 -07001293
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001294static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1295 struct ieee80211_mgmt *mgmt,
1296 size_t len)
1297{
1298 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1299 struct ieee80211_hw *hw = &local->hw;
1300 struct sta_info *sta;
1301 u16 capab;
1302 u16 tid;
1303 u8 *state;
1304
Johannes Bergd0709a62008-02-25 16:27:46 +01001305 rcu_read_lock();
1306
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001307 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001308 if (!sta) {
1309 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001310 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001311 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001312
1313 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1314 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1315
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001316 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001317
1318 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1319
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001320 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1321 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1322 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1323 "%d\n", *state);
1324 goto addba_resp_exit;
1325 }
1326
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001327 if (mgmt->u.action.u.addba_resp.dialog_token !=
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001328 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001329 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1330#ifdef CONFIG_MAC80211_HT_DEBUG
1331 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1332#endif /* CONFIG_MAC80211_HT_DEBUG */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001333 goto addba_resp_exit;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001334 }
1335
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001336 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001337#ifdef CONFIG_MAC80211_HT_DEBUG
1338 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1339#endif /* CONFIG_MAC80211_HT_DEBUG */
1340 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1341 == WLAN_STATUS_SUCCESS) {
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001342 if (*state & HT_ADDBA_RECEIVED_MSK)
1343 printk(KERN_DEBUG "double addBA response\n");
1344
1345 *state |= HT_ADDBA_RECEIVED_MSK;
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001346 sta->ampdu_mlme.addba_req_num[tid] = 0;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001347
1348 if (*state == HT_AGG_STATE_OPERATIONAL) {
1349 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1350 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1351 }
1352
1353 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1354 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1355 } else {
1356 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1357
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001358 sta->ampdu_mlme.addba_req_num[tid]++;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001359 /* this will allow the state check in stop_BA_session */
1360 *state = HT_AGG_STATE_OPERATIONAL;
1361 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1362 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1363 WLAN_BACK_INITIATOR);
1364 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001365
1366addba_resp_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001367 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001368}
1369
1370void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1371 u16 initiator, u16 reason_code)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001372{
1373 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1374 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1375 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1376 struct sk_buff *skb;
1377 struct ieee80211_mgmt *mgmt;
1378 u16 params;
1379
1380 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1381 sizeof(mgmt->u.action.u.delba));
1382
1383 if (!skb) {
1384 printk(KERN_ERR "%s: failed to allocate buffer "
1385 "for delba frame\n", dev->name);
1386 return;
1387 }
1388
1389 skb_reserve(skb, local->hw.extra_tx_headroom);
1390 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1391 memset(mgmt, 0, 24);
1392 memcpy(mgmt->da, da, ETH_ALEN);
1393 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001394 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001395 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1396 else
1397 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1398 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1399 IEEE80211_STYPE_ACTION);
1400
1401 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1402
1403 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1404 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1405 params = (u16)(initiator << 11); /* bit 11 initiator */
1406 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1407
1408 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1409 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1410
1411 ieee80211_sta_tx(dev, skb, 0);
1412}
1413
1414void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1415 u16 initiator, u16 reason)
1416{
1417 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1418 struct ieee80211_hw *hw = &local->hw;
1419 struct sta_info *sta;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001420 int ret, i;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001421
Johannes Bergd0709a62008-02-25 16:27:46 +01001422 rcu_read_lock();
1423
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001424 sta = sta_info_get(local, ra);
Johannes Bergd0709a62008-02-25 16:27:46 +01001425 if (!sta) {
1426 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001427 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001428 }
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001429
1430 /* check if TID is in operational state */
1431 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001432 if (sta->ampdu_mlme.tid_state_rx[tid]
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001433 != HT_AGG_STATE_OPERATIONAL) {
1434 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
Johannes Bergd0709a62008-02-25 16:27:46 +01001435 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001436 return;
1437 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001438 sta->ampdu_mlme.tid_state_rx[tid] =
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001439 HT_AGG_STATE_REQ_STOP_BA_MSK |
1440 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
1441 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1442
1443 /* stop HW Rx aggregation. ampdu_action existence
1444 * already verified in session init so we add the BUG_ON */
1445 BUG_ON(!local->ops->ampdu_action);
1446
1447 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001448 ra, tid, NULL);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001449 if (ret)
1450 printk(KERN_DEBUG "HW problem - can not stop rx "
1451 "aggergation for tid %d\n", tid);
1452
1453 /* shutdown timer has not expired */
1454 if (initiator != WLAN_BACK_TIMER)
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001455 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001456
1457 /* check if this is a self generated aggregation halt */
1458 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1459 ieee80211_send_delba(dev, ra, tid, 0, reason);
1460
1461 /* free the reordering buffer */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001462 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
1463 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001464 /* release the reordered frames */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001465 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
1466 sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
1467 sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001468 }
1469 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001470 /* free resources */
1471 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
1472 kfree(sta->ampdu_mlme.tid_rx[tid]);
1473 sta->ampdu_mlme.tid_rx[tid] = NULL;
1474 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001475
Johannes Bergd0709a62008-02-25 16:27:46 +01001476 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001477}
1478
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001479
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001480static void ieee80211_sta_process_delba(struct net_device *dev,
1481 struct ieee80211_mgmt *mgmt, size_t len)
1482{
1483 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1484 struct sta_info *sta;
1485 u16 tid, params;
1486 u16 initiator;
1487 DECLARE_MAC_BUF(mac);
1488
Johannes Bergd0709a62008-02-25 16:27:46 +01001489 rcu_read_lock();
1490
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001491 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001492 if (!sta) {
1493 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001494 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001495 }
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001496
1497 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1498 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1499 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1500
1501#ifdef CONFIG_MAC80211_HT_DEBUG
1502 if (net_ratelimit())
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001503 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1504 print_mac(mac, mgmt->sa),
Ron Rindjunsky2e354ed2008-03-18 15:00:30 -07001505 initiator ? "initiator" : "recipient", tid,
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001506 mgmt->u.action.u.delba.reason_code);
1507#endif /* CONFIG_MAC80211_HT_DEBUG */
1508
1509 if (initiator == WLAN_BACK_INITIATOR)
1510 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1511 WLAN_BACK_INITIATOR, 0);
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001512 else { /* WLAN_BACK_RECIPIENT */
1513 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001514 sta->ampdu_mlme.tid_state_tx[tid] =
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001515 HT_AGG_STATE_OPERATIONAL;
1516 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1517 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1518 WLAN_BACK_RECIPIENT);
1519 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001520 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001521}
1522
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001523/*
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001524 * After sending add Block Ack request we activated a timer until
1525 * add Block Ack response will arrive from the recipient.
1526 * If this timer expires sta_addba_resp_timer_expired will be executed.
1527 */
1528void sta_addba_resp_timer_expired(unsigned long data)
1529{
1530 /* not an elegant detour, but there is no choice as the timer passes
1531 * only one argument, and both sta_info and TID are needed, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001532 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001533 * array gives the sta through container_of */
1534 u16 tid = *(int *)data;
1535 struct sta_info *temp_sta = container_of((void *)data,
1536 struct sta_info, timer_to_tid[tid]);
1537
1538 struct ieee80211_local *local = temp_sta->local;
1539 struct ieee80211_hw *hw = &local->hw;
1540 struct sta_info *sta;
1541 u8 *state;
1542
Johannes Bergd0709a62008-02-25 16:27:46 +01001543 rcu_read_lock();
1544
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001545 sta = sta_info_get(local, temp_sta->addr);
Johannes Bergd0709a62008-02-25 16:27:46 +01001546 if (!sta) {
1547 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001548 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001549 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001550
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001551 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001552 /* check if the TID waits for addBA response */
1553 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1554 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1555 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1556 *state = HT_AGG_STATE_IDLE;
1557 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1558 "expecting addBA response there", tid);
1559 goto timer_expired_exit;
1560 }
1561
1562 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1563
1564 /* go through the state check in stop_BA_session */
1565 *state = HT_AGG_STATE_OPERATIONAL;
1566 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1567 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1568 WLAN_BACK_INITIATOR);
1569
1570timer_expired_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001571 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001572}
1573
1574/*
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001575 * After accepting the AddBA Request we activated a timer,
1576 * resetting it after each frame that arrives from the originator.
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001577 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1578 */
1579void sta_rx_agg_session_timer_expired(unsigned long data)
1580{
1581 /* not an elegant detour, but there is no choice as the timer passes
1582 * only one argument, and verious sta_info are needed here, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001583 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001584 * array gives the sta through container_of */
1585 u8 *ptid = (u8 *)data;
1586 u8 *timer_to_id = ptid - *ptid;
1587 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1588 timer_to_tid[0]);
1589
1590 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
Johannes Bergd0709a62008-02-25 16:27:46 +01001591 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1592 (u16)*ptid, WLAN_BACK_TIMER,
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001593 WLAN_REASON_QSTA_TIMEOUT);
1594}
1595
Ron Rindjunsky85249e52008-03-18 15:00:32 -07001596void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr)
1597{
1598 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1599 int i;
1600
1601 for (i = 0; i < STA_TID_NUM; i++) {
1602 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
1603 WLAN_BACK_INITIATOR);
1604 ieee80211_sta_stop_rx_ba_session(dev, addr, i,
1605 WLAN_BACK_RECIPIENT,
1606 WLAN_REASON_QSTA_LEAVE_QBSS);
1607 }
1608}
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001609
Jiri Bencf0706e822007-05-05 11:45:53 -07001610static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1611 struct ieee80211_if_sta *ifsta,
1612 struct ieee80211_mgmt *mgmt,
1613 size_t len)
1614{
1615 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1616 u16 auth_alg, auth_transaction, status_code;
Joe Perches0795af52007-10-03 17:59:30 -07001617 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07001618
1619 if (ifsta->state != IEEE80211_AUTHENTICATE &&
Johannes Berg51fb61e2007-12-19 01:31:27 +01001620 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -07001621 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001622 "%s, but not in authenticate state - ignored\n",
1623 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001624 return;
1625 }
1626
1627 if (len < 24 + 6) {
1628 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
Joe Perches0795af52007-10-03 17:59:30 -07001629 "received from %s - ignored\n",
1630 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001631 return;
1632 }
1633
Johannes Berg51fb61e2007-12-19 01:31:27 +01001634 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Jiri Bencf0706e822007-05-05 11:45:53 -07001635 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1636 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001637 "unknown AP (SA=%s BSSID=%s) - "
1638 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1639 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001640 return;
1641 }
1642
Johannes Berg51fb61e2007-12-19 01:31:27 +01001643 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Jiri Bencf0706e822007-05-05 11:45:53 -07001644 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1645 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001646 "unknown BSSID (SA=%s BSSID=%s) - "
1647 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1648 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001649 return;
1650 }
1651
1652 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1653 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1654 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1655
Joe Perches0795af52007-10-03 17:59:30 -07001656 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
Jiri Bencf0706e822007-05-05 11:45:53 -07001657 "transaction=%d status=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001658 dev->name, print_mac(mac, mgmt->sa), auth_alg,
Jiri Bencf0706e822007-05-05 11:45:53 -07001659 auth_transaction, status_code);
1660
Johannes Berg51fb61e2007-12-19 01:31:27 +01001661 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -07001662 /* IEEE 802.11 standard does not require authentication in IBSS
1663 * networks and most implementations do not seem to use it.
1664 * However, try to reply to authentication attempts if someone
1665 * has actually implemented this.
1666 * TODO: Could implement shared key authentication. */
1667 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1668 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1669 "frame (alg=%d transaction=%d)\n",
1670 dev->name, auth_alg, auth_transaction);
1671 return;
1672 }
1673 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1674 }
1675
1676 if (auth_alg != ifsta->auth_alg ||
1677 auth_transaction != ifsta->auth_transaction) {
1678 printk(KERN_DEBUG "%s: unexpected authentication frame "
1679 "(alg=%d transaction=%d)\n",
1680 dev->name, auth_alg, auth_transaction);
1681 return;
1682 }
1683
1684 if (status_code != WLAN_STATUS_SUCCESS) {
1685 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1686 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1687 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1688 u8 algs[3];
1689 const int num_algs = ARRAY_SIZE(algs);
1690 int i, pos;
1691 algs[0] = algs[1] = algs[2] = 0xff;
1692 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1693 algs[0] = WLAN_AUTH_OPEN;
1694 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1695 algs[1] = WLAN_AUTH_SHARED_KEY;
1696 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1697 algs[2] = WLAN_AUTH_LEAP;
1698 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1699 pos = 0;
1700 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1701 pos = 1;
1702 else
1703 pos = 2;
1704 for (i = 0; i < num_algs; i++) {
1705 pos++;
1706 if (pos >= num_algs)
1707 pos = 0;
1708 if (algs[pos] == ifsta->auth_alg ||
1709 algs[pos] == 0xff)
1710 continue;
1711 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1712 !ieee80211_sta_wep_configured(dev))
1713 continue;
1714 ifsta->auth_alg = algs[pos];
1715 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1716 "next try\n",
1717 dev->name, ifsta->auth_alg);
1718 break;
1719 }
1720 }
1721 return;
1722 }
1723
1724 switch (ifsta->auth_alg) {
1725 case WLAN_AUTH_OPEN:
1726 case WLAN_AUTH_LEAP:
1727 ieee80211_auth_completed(dev, ifsta);
1728 break;
1729 case WLAN_AUTH_SHARED_KEY:
1730 if (ifsta->auth_transaction == 4)
1731 ieee80211_auth_completed(dev, ifsta);
1732 else
1733 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1734 break;
1735 }
1736}
1737
1738
1739static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1740 struct ieee80211_if_sta *ifsta,
1741 struct ieee80211_mgmt *mgmt,
1742 size_t len)
1743{
1744 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001745 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07001746
1747 if (len < 24 + 2) {
1748 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
Joe Perches0795af52007-10-03 17:59:30 -07001749 "received from %s - ignored\n",
1750 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001751 return;
1752 }
1753
1754 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1755 printk(KERN_DEBUG "%s: deauthentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001756 "unknown AP (SA=%s BSSID=%s) - "
1757 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1758 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001759 return;
1760 }
1761
1762 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1763
Joe Perches0795af52007-10-03 17:59:30 -07001764 printk(KERN_DEBUG "%s: RX deauthentication from %s"
Jiri Bencf0706e822007-05-05 11:45:53 -07001765 " (reason=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001766 dev->name, print_mac(mac, mgmt->sa), reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07001767
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001768 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) {
Jiri Bencf0706e822007-05-05 11:45:53 -07001769 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
1770 }
1771
1772 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1773 ifsta->state == IEEE80211_ASSOCIATE ||
1774 ifsta->state == IEEE80211_ASSOCIATED) {
1775 ifsta->state = IEEE80211_AUTHENTICATE;
1776 mod_timer(&ifsta->timer, jiffies +
1777 IEEE80211_RETRY_AUTH_INTERVAL);
1778 }
1779
1780 ieee80211_set_disassoc(dev, ifsta, 1);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001781 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jiri Bencf0706e822007-05-05 11:45:53 -07001782}
1783
1784
1785static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1786 struct ieee80211_if_sta *ifsta,
1787 struct ieee80211_mgmt *mgmt,
1788 size_t len)
1789{
1790 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001791 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07001792
1793 if (len < 24 + 2) {
1794 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
Joe Perches0795af52007-10-03 17:59:30 -07001795 "received from %s - ignored\n",
1796 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001797 return;
1798 }
1799
1800 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1801 printk(KERN_DEBUG "%s: disassociation frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001802 "unknown AP (SA=%s BSSID=%s) - "
1803 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1804 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001805 return;
1806 }
1807
1808 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1809
Joe Perches0795af52007-10-03 17:59:30 -07001810 printk(KERN_DEBUG "%s: RX disassociation from %s"
Jiri Bencf0706e822007-05-05 11:45:53 -07001811 " (reason=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001812 dev->name, print_mac(mac, mgmt->sa), reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07001813
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001814 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
Jiri Bencf0706e822007-05-05 11:45:53 -07001815 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1816
1817 if (ifsta->state == IEEE80211_ASSOCIATED) {
1818 ifsta->state = IEEE80211_ASSOCIATE;
1819 mod_timer(&ifsta->timer, jiffies +
1820 IEEE80211_RETRY_AUTH_INTERVAL);
1821 }
1822
1823 ieee80211_set_disassoc(dev, ifsta, 0);
1824}
1825
1826
Johannes Berg471b3ef2007-12-28 14:32:58 +01001827static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -07001828 struct ieee80211_if_sta *ifsta,
1829 struct ieee80211_mgmt *mgmt,
1830 size_t len,
1831 int reassoc)
1832{
Johannes Berg471b3ef2007-12-28 14:32:58 +01001833 struct ieee80211_local *local = sdata->local;
1834 struct net_device *dev = sdata->dev;
Johannes Berg8318d782008-01-24 19:38:38 +01001835 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07001836 struct sta_info *sta;
Johannes Berg8318d782008-01-24 19:38:38 +01001837 u64 rates, basic_rates;
Jiri Bencf0706e822007-05-05 11:45:53 -07001838 u16 capab_info, status_code, aid;
1839 struct ieee802_11_elems elems;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001840 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
Jiri Bencf0706e822007-05-05 11:45:53 -07001841 u8 *pos;
1842 int i, j;
Joe Perches0795af52007-10-03 17:59:30 -07001843 DECLARE_MAC_BUF(mac);
Johannes Berg8318d782008-01-24 19:38:38 +01001844 bool have_higher_than_11mbit = false;
Jiri Bencf0706e822007-05-05 11:45:53 -07001845
1846 /* AssocResp and ReassocResp have identical structure, so process both
1847 * of them in this function. */
1848
1849 if (ifsta->state != IEEE80211_ASSOCIATE) {
1850 printk(KERN_DEBUG "%s: association frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001851 "%s, but not in associate state - ignored\n",
1852 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001853 return;
1854 }
1855
1856 if (len < 24 + 6) {
1857 printk(KERN_DEBUG "%s: too short (%zd) association frame "
Joe Perches0795af52007-10-03 17:59:30 -07001858 "received from %s - ignored\n",
1859 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001860 return;
1861 }
1862
1863 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1864 printk(KERN_DEBUG "%s: association frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001865 "unknown AP (SA=%s BSSID=%s) - "
1866 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1867 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001868 return;
1869 }
1870
1871 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1872 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1873 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e822007-05-05 11:45:53 -07001874
Joe Perches0795af52007-10-03 17:59:30 -07001875 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
Jiri Bencf0706e822007-05-05 11:45:53 -07001876 "status=%d aid=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001877 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
Johannes Bergddd68582007-10-22 14:51:37 +02001878 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e822007-05-05 11:45:53 -07001879
1880 if (status_code != WLAN_STATUS_SUCCESS) {
1881 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1882 dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02001883 /* if this was a reassociation, ensure we try a "full"
1884 * association next time. This works around some broken APs
1885 * which do not correctly reject reassociation requests. */
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001886 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e822007-05-05 11:45:53 -07001887 return;
1888 }
1889
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001890 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1891 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1892 "set\n", dev->name, aid);
1893 aid &= ~(BIT(15) | BIT(14));
1894
Jiri Bencf0706e822007-05-05 11:45:53 -07001895 pos = mgmt->u.assoc_resp.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001896 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07001897
1898 if (!elems.supp_rates) {
1899 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1900 dev->name);
1901 return;
1902 }
1903
1904 printk(KERN_DEBUG "%s: associated\n", dev->name);
1905 ifsta->aid = aid;
1906 ifsta->ap_capab = capab_info;
1907
1908 kfree(ifsta->assocresp_ies);
1909 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
Michael Wu0ec0b7a2007-07-27 15:43:24 +02001910 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -07001911 if (ifsta->assocresp_ies)
1912 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1913
Johannes Bergd0709a62008-02-25 16:27:46 +01001914 rcu_read_lock();
1915
Jiri Bencf0706e822007-05-05 11:45:53 -07001916 /* Add STA entry for the AP */
1917 sta = sta_info_get(local, ifsta->bssid);
1918 if (!sta) {
1919 struct ieee80211_sta_bss *bss;
Johannes Berg73651ee2008-02-25 16:27:47 +01001920 int err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001921
Johannes Berg73651ee2008-02-25 16:27:47 +01001922 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
1923 if (!sta) {
1924 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1925 " the AP\n", dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01001926 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07001927 return;
1928 }
John W. Linville65c107a2007-10-05 14:23:27 -04001929 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01001930 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04001931 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07001932 if (bss) {
1933 sta->last_rssi = bss->rssi;
1934 sta->last_signal = bss->signal;
1935 sta->last_noise = bss->noise;
1936 ieee80211_rx_bss_put(dev, bss);
1937 }
Johannes Berg73651ee2008-02-25 16:27:47 +01001938
1939 err = sta_info_insert(sta);
1940 if (err) {
1941 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1942 " the AP (error %d)\n", dev->name, err);
Johannes Berg73651ee2008-02-25 16:27:47 +01001943 rcu_read_unlock();
1944 return;
1945 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001946 }
1947
Johannes Berg73651ee2008-02-25 16:27:47 +01001948 /*
1949 * FIXME: Do we really need to update the sta_info's information here?
1950 * We already know about the AP (we found it in our list) so it
1951 * should already be filled with the right info, no?
1952 * As is stands, all this is racy because typically we assume
1953 * the information that is filled in here (except flags) doesn't
1954 * change while a STA structure is alive. As such, it should move
1955 * to between the sta_info_alloc() and sta_info_insert() above.
1956 */
1957
Johannes Berg238814f2008-01-28 17:19:37 +01001958 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1959 WLAN_STA_AUTHORIZED;
Jiri Bencf0706e822007-05-05 11:45:53 -07001960
1961 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001962 basic_rates = 0;
1963 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1964
Jiri Bencf0706e822007-05-05 11:45:53 -07001965 for (i = 0; i < elems.supp_rates_len; i++) {
1966 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001967
1968 if (rate > 110)
1969 have_higher_than_11mbit = true;
1970
1971 for (j = 0; j < sband->n_bitrates; j++) {
1972 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e822007-05-05 11:45:53 -07001973 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01001974 if (elems.supp_rates[i] & 0x80)
1975 basic_rates |= BIT(j);
1976 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001977 }
Johannes Berg8318d782008-01-24 19:38:38 +01001978
Jiri Bencf0706e822007-05-05 11:45:53 -07001979 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1980 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001981
1982 if (rate > 110)
1983 have_higher_than_11mbit = true;
1984
1985 for (j = 0; j < sband->n_bitrates; j++) {
1986 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e822007-05-05 11:45:53 -07001987 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01001988 if (elems.ext_supp_rates[i] & 0x80)
1989 basic_rates |= BIT(j);
1990 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001991 }
Johannes Berg8318d782008-01-24 19:38:38 +01001992
1993 sta->supp_rates[local->hw.conf.channel->band] = rates;
1994 sdata->basic_rates = basic_rates;
1995
1996 /* cf. IEEE 802.11 9.2.12 */
1997 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1998 have_higher_than_11mbit)
1999 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
2000 else
2001 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e822007-05-05 11:45:53 -07002002
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002003 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
2004 local->ops->conf_ht) {
2005 struct ieee80211_ht_bss_info bss_info;
2006
2007 ieee80211_ht_cap_ie_to_ht_info(
2008 (struct ieee80211_ht_cap *)
2009 elems.ht_cap_elem, &sta->ht_info);
2010 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2011 (struct ieee80211_ht_addt_info *)
2012 elems.ht_info_elem, &bss_info);
2013 ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info);
2014 }
2015
Jiri Bencf0706e822007-05-05 11:45:53 -07002016 rate_control_rate_init(sta, local);
2017
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002018 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002019 sta->flags |= WLAN_STA_WME;
Johannes Berge5f98f22008-03-05 20:39:31 +01002020 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07002021 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2022 elems.wmm_param_len);
Johannes Berge5f98f22008-03-05 20:39:31 +01002023 } else
2024 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07002025
Johannes Berg8318d782008-01-24 19:38:38 +01002026 /* set AID, ieee80211_set_associated() will tell the driver */
2027 bss_conf->aid = aid;
2028 ieee80211_set_associated(dev, ifsta, 1);
Jiri Bencf0706e822007-05-05 11:45:53 -07002029
Jiri Bencf0706e822007-05-05 11:45:53 -07002030 ieee80211_associated(dev, ifsta);
2031}
2032
2033
2034/* Caller must hold local->sta_bss_lock */
2035static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
2036 struct ieee80211_sta_bss *bss)
2037{
2038 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002039 u8 hash_idx;
Johannes Berg902acc72008-02-23 15:17:19 +01002040
2041 if (bss_mesh_cfg(bss))
2042 hash_idx = mesh_id_hash(bss_mesh_id(bss),
2043 bss_mesh_id_len(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002044 else
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002045 hash_idx = STA_HASH(bss->bssid);
Johannes Berg902acc72008-02-23 15:17:19 +01002046
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002047 bss->hnext = local->sta_bss_hash[hash_idx];
2048 local->sta_bss_hash[hash_idx] = bss;
Jiri Bencf0706e822007-05-05 11:45:53 -07002049}
2050
2051
2052/* Caller must hold local->sta_bss_lock */
2053static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
2054 struct ieee80211_sta_bss *bss)
2055{
2056 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2057 struct ieee80211_sta_bss *b, *prev = NULL;
2058 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
2059 while (b) {
2060 if (b == bss) {
2061 if (!prev)
2062 local->sta_bss_hash[STA_HASH(bss->bssid)] =
2063 bss->hnext;
2064 else
2065 prev->hnext = bss->hnext;
2066 break;
2067 }
2068 prev = b;
2069 b = b->hnext;
2070 }
2071}
2072
2073
2074static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +01002075ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002076 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e822007-05-05 11:45:53 -07002077{
2078 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2079 struct ieee80211_sta_bss *bss;
2080
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002081 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
Jiri Bencf0706e822007-05-05 11:45:53 -07002082 if (!bss)
2083 return NULL;
Jiri Bencf0706e822007-05-05 11:45:53 -07002084 atomic_inc(&bss->users);
2085 atomic_inc(&bss->users);
2086 memcpy(bss->bssid, bssid, ETH_ALEN);
Johannes Berg8318d782008-01-24 19:38:38 +01002087 bss->freq = freq;
John W. Linvillecffdd302007-10-05 14:23:27 -04002088 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
2089 memcpy(bss->ssid, ssid, ssid_len);
2090 bss->ssid_len = ssid_len;
2091 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002092
2093 spin_lock_bh(&local->sta_bss_lock);
2094 /* TODO: order by RSSI? */
2095 list_add_tail(&bss->list, &local->sta_bss_list);
2096 __ieee80211_rx_bss_hash_add(dev, bss);
2097 spin_unlock_bh(&local->sta_bss_lock);
2098 return bss;
2099}
2100
Jiri Bencf0706e822007-05-05 11:45:53 -07002101static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +01002102ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002103 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e822007-05-05 11:45:53 -07002104{
2105 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2106 struct ieee80211_sta_bss *bss;
2107
2108 spin_lock_bh(&local->sta_bss_lock);
2109 bss = local->sta_bss_hash[STA_HASH(bssid)];
2110 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002111 if (!bss_mesh_cfg(bss) &&
2112 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
Johannes Berg8318d782008-01-24 19:38:38 +01002113 bss->freq == freq &&
John W. Linvillecffdd302007-10-05 14:23:27 -04002114 bss->ssid_len == ssid_len &&
2115 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002116 atomic_inc(&bss->users);
2117 break;
2118 }
2119 bss = bss->hnext;
2120 }
2121 spin_unlock_bh(&local->sta_bss_lock);
2122 return bss;
2123}
2124
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002125#ifdef CONFIG_MAC80211_MESH
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07002126static inline u32 bss_mesh_cfg_get(u8 *mesh_cfg, u8 offset)
2127{
2128 return be32_to_cpu(get_unaligned((__be32 *) (mesh_cfg + offset)));
2129}
2130
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002131static struct ieee80211_sta_bss *
2132ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2133 u8 *mesh_cfg, int freq)
2134{
2135 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2136 struct ieee80211_sta_bss *bss;
2137
2138 spin_lock_bh(&local->sta_bss_lock);
2139 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2140 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002141 if (bss_mesh_cfg(bss) &&
2142 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002143 bss->freq == freq &&
2144 mesh_id_len == bss->mesh_id_len &&
2145 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2146 mesh_id_len))) {
2147 atomic_inc(&bss->users);
2148 break;
2149 }
2150 bss = bss->hnext;
2151 }
2152 spin_unlock_bh(&local->sta_bss_lock);
2153 return bss;
2154}
2155
2156static struct ieee80211_sta_bss *
2157ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002158 u8 *mesh_cfg, int mesh_config_len, int freq)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002159{
2160 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2161 struct ieee80211_sta_bss *bss;
2162
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002163 if (mesh_config_len != MESH_CFG_LEN)
2164 return NULL;
2165
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002166 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2167 if (!bss)
2168 return NULL;
2169
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07002170 bss->mesh_cfg = kmalloc(sizeof(struct bss_mesh_config), GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002171 if (!bss->mesh_cfg) {
2172 kfree(bss);
2173 return NULL;
2174 }
2175
2176 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2177 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2178 if (!bss->mesh_id) {
2179 kfree(bss->mesh_cfg);
2180 kfree(bss);
2181 return NULL;
2182 }
2183 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2184 }
2185
2186 atomic_inc(&bss->users);
2187 atomic_inc(&bss->users);
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07002188 bss->mesh_cfg->mesh_version = mesh_cfg[0];
2189 bss->mesh_cfg->path_proto_id = bss_mesh_cfg_get(mesh_cfg, PP_OFFSET);
2190 bss->mesh_cfg->path_metric_id = bss_mesh_cfg_get(mesh_cfg, PM_OFFSET);
2191 bss->mesh_cfg->cong_control_id = bss_mesh_cfg_get(mesh_cfg, CC_OFFSET);
2192 bss->mesh_cfg->channel_precedence = bss_mesh_cfg_get(mesh_cfg,
2193 CP_OFFSET);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002194 bss->mesh_id_len = mesh_id_len;
2195 bss->freq = freq;
2196 spin_lock_bh(&local->sta_bss_lock);
2197 /* TODO: order by RSSI? */
2198 list_add_tail(&bss->list, &local->sta_bss_list);
2199 __ieee80211_rx_bss_hash_add(dev, bss);
2200 spin_unlock_bh(&local->sta_bss_lock);
2201 return bss;
2202}
2203#endif
Jiri Bencf0706e822007-05-05 11:45:53 -07002204
2205static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2206{
2207 kfree(bss->wpa_ie);
2208 kfree(bss->rsn_ie);
2209 kfree(bss->wmm_ie);
Ron Rindjunskyc7153502007-11-26 16:14:31 +02002210 kfree(bss->ht_ie);
Johannes Berg902acc72008-02-23 15:17:19 +01002211 kfree(bss_mesh_id(bss));
2212 kfree(bss_mesh_cfg(bss));
Jiri Bencf0706e822007-05-05 11:45:53 -07002213 kfree(bss);
2214}
2215
2216
2217static void ieee80211_rx_bss_put(struct net_device *dev,
2218 struct ieee80211_sta_bss *bss)
2219{
2220 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2221 if (!atomic_dec_and_test(&bss->users))
2222 return;
2223
2224 spin_lock_bh(&local->sta_bss_lock);
2225 __ieee80211_rx_bss_hash_del(dev, bss);
2226 list_del(&bss->list);
2227 spin_unlock_bh(&local->sta_bss_lock);
2228 ieee80211_rx_bss_free(bss);
2229}
2230
2231
2232void ieee80211_rx_bss_list_init(struct net_device *dev)
2233{
2234 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2235 spin_lock_init(&local->sta_bss_lock);
2236 INIT_LIST_HEAD(&local->sta_bss_list);
2237}
2238
2239
2240void ieee80211_rx_bss_list_deinit(struct net_device *dev)
2241{
2242 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2243 struct ieee80211_sta_bss *bss, *tmp;
2244
2245 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
2246 ieee80211_rx_bss_put(dev, bss);
2247}
2248
2249
Bruno Randolfa6072682008-02-18 11:21:15 +09002250static int ieee80211_sta_join_ibss(struct net_device *dev,
2251 struct ieee80211_if_sta *ifsta,
2252 struct ieee80211_sta_bss *bss)
2253{
2254 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2255 int res, rates, i, j;
2256 struct sk_buff *skb;
2257 struct ieee80211_mgmt *mgmt;
2258 struct ieee80211_tx_control control;
2259 struct rate_selection ratesel;
2260 u8 *pos;
2261 struct ieee80211_sub_if_data *sdata;
2262 struct ieee80211_supported_band *sband;
2263
2264 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2265
Johannes Berg9dd6aed2008-03-31 19:22:59 +02002266 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2267
Bruno Randolfa6072682008-02-18 11:21:15 +09002268 /* Remove possible STA entries from other IBSS networks. */
Johannes Bergdc6676b2008-03-31 19:23:03 +02002269 sta_info_flush_delayed(sdata);
Bruno Randolfa6072682008-02-18 11:21:15 +09002270
2271 if (local->ops->reset_tsf) {
2272 /* Reset own TSF to allow time synchronization work. */
2273 local->ops->reset_tsf(local_to_hw(local));
2274 }
2275 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2276 res = ieee80211_if_config(dev);
2277 if (res)
2278 return res;
2279
2280 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2281
Bruno Randolfa6072682008-02-18 11:21:15 +09002282 sdata->drop_unencrypted = bss->capability &
2283 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2284
2285 res = ieee80211_set_freq(local, bss->freq);
2286
2287 if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
2288 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
2289 "%d MHz\n", dev->name, local->oper_channel->center_freq);
2290 return -1;
2291 }
2292
2293 /* Set beacon template */
2294 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2295 do {
2296 if (!skb)
2297 break;
2298
2299 skb_reserve(skb, local->hw.extra_tx_headroom);
2300
2301 mgmt = (struct ieee80211_mgmt *)
2302 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2303 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2304 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2305 IEEE80211_STYPE_BEACON);
2306 memset(mgmt->da, 0xff, ETH_ALEN);
2307 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2308 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2309 mgmt->u.beacon.beacon_int =
2310 cpu_to_le16(local->hw.conf.beacon_int);
2311 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2312
2313 pos = skb_put(skb, 2 + ifsta->ssid_len);
2314 *pos++ = WLAN_EID_SSID;
2315 *pos++ = ifsta->ssid_len;
2316 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2317
2318 rates = bss->supp_rates_len;
2319 if (rates > 8)
2320 rates = 8;
2321 pos = skb_put(skb, 2 + rates);
2322 *pos++ = WLAN_EID_SUPP_RATES;
2323 *pos++ = rates;
2324 memcpy(pos, bss->supp_rates, rates);
2325
2326 if (bss->band == IEEE80211_BAND_2GHZ) {
2327 pos = skb_put(skb, 2 + 1);
2328 *pos++ = WLAN_EID_DS_PARAMS;
2329 *pos++ = 1;
2330 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2331 }
2332
2333 pos = skb_put(skb, 2 + 2);
2334 *pos++ = WLAN_EID_IBSS_PARAMS;
2335 *pos++ = 2;
2336 /* FIX: set ATIM window based on scan results */
2337 *pos++ = 0;
2338 *pos++ = 0;
2339
2340 if (bss->supp_rates_len > 8) {
2341 rates = bss->supp_rates_len - 8;
2342 pos = skb_put(skb, 2 + rates);
2343 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2344 *pos++ = rates;
2345 memcpy(pos, &bss->supp_rates[8], rates);
2346 }
2347
2348 memset(&control, 0, sizeof(control));
2349 rate_control_get_rate(dev, sband, skb, &ratesel);
2350 if (!ratesel.rate) {
2351 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2352 "for IBSS beacon\n", dev->name);
2353 break;
2354 }
2355 control.vif = &sdata->vif;
2356 control.tx_rate = ratesel.rate;
2357 if (sdata->bss_conf.use_short_preamble &&
2358 ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2359 control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
2360 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2361 control.flags |= IEEE80211_TXCTL_NO_ACK;
2362 control.retry_limit = 1;
2363
2364 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2365 if (ifsta->probe_resp) {
2366 mgmt = (struct ieee80211_mgmt *)
2367 ifsta->probe_resp->data;
2368 mgmt->frame_control =
2369 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2370 IEEE80211_STYPE_PROBE_RESP);
2371 } else {
2372 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2373 "template for IBSS\n", dev->name);
2374 }
2375
2376 if (local->ops->beacon_update &&
2377 local->ops->beacon_update(local_to_hw(local),
2378 skb, &control) == 0) {
2379 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2380 "template\n", dev->name);
2381 skb = NULL;
2382 }
2383
2384 rates = 0;
2385 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2386 for (i = 0; i < bss->supp_rates_len; i++) {
2387 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2388 for (j = 0; j < sband->n_bitrates; j++)
2389 if (sband->bitrates[j].bitrate == bitrate)
2390 rates |= BIT(j);
2391 }
2392 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
Vladimir Koutnye2839d82008-03-18 21:14:07 +01002393
2394 ieee80211_sta_def_wmm_params(dev, bss, 1);
Bruno Randolfa6072682008-02-18 11:21:15 +09002395 } while (0);
2396
2397 if (skb) {
2398 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2399 "template\n", dev->name);
2400 dev_kfree_skb(skb);
2401 }
2402
2403 ifsta->state = IEEE80211_IBSS_JOINED;
2404 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2405
2406 ieee80211_rx_bss_put(dev, bss);
2407
2408 return res;
2409}
2410
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002411u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2412 struct ieee802_11_elems *elems,
2413 enum ieee80211_band band)
2414{
2415 struct ieee80211_supported_band *sband;
2416 struct ieee80211_rate *bitrates;
2417 size_t num_rates;
2418 u64 supp_rates;
2419 int i, j;
2420 sband = local->hw.wiphy->bands[band];
2421
2422 if (!sband) {
2423 WARN_ON(1);
2424 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2425 }
2426
2427 bitrates = sband->bitrates;
2428 num_rates = sband->n_bitrates;
2429 supp_rates = 0;
2430 for (i = 0; i < elems->supp_rates_len +
2431 elems->ext_supp_rates_len; i++) {
2432 u8 rate = 0;
2433 int own_rate;
2434 if (i < elems->supp_rates_len)
2435 rate = elems->supp_rates[i];
2436 else if (elems->ext_supp_rates)
2437 rate = elems->ext_supp_rates
2438 [i - elems->supp_rates_len];
2439 own_rate = 5 * (rate & 0x7f);
2440 for (j = 0; j < num_rates; j++)
2441 if (bitrates[j].bitrate == own_rate)
2442 supp_rates |= BIT(j);
2443 }
2444 return supp_rates;
2445}
2446
Bruno Randolfa6072682008-02-18 11:21:15 +09002447
Jiri Bencf0706e822007-05-05 11:45:53 -07002448static void ieee80211_rx_bss_info(struct net_device *dev,
2449 struct ieee80211_mgmt *mgmt,
2450 size_t len,
2451 struct ieee80211_rx_status *rx_status,
2452 int beacon)
2453{
2454 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2455 struct ieee802_11_elems elems;
2456 size_t baselen;
Johannes Berg8318d782008-01-24 19:38:38 +01002457 int freq, clen;
Jiri Bencf0706e822007-05-05 11:45:53 -07002458 struct ieee80211_sta_bss *bss;
2459 struct sta_info *sta;
2460 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002461 u64 beacon_timestamp, rx_timestamp;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002462 struct ieee80211_channel *channel;
Joe Perches0795af52007-10-03 17:59:30 -07002463 DECLARE_MAC_BUF(mac);
2464 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e822007-05-05 11:45:53 -07002465
2466 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
2467 return; /* ignore ProbeResp to foreign address */
2468
2469#if 0
Joe Perches0795af52007-10-03 17:59:30 -07002470 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
Jiri Bencf0706e822007-05-05 11:45:53 -07002471 dev->name, beacon ? "Beacon" : "Probe Response",
Joe Perches0795af52007-10-03 17:59:30 -07002472 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
Jiri Bencf0706e822007-05-05 11:45:53 -07002473#endif
2474
2475 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2476 if (baselen > len)
2477 return;
2478
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002479 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
John W. Linville67a4cce2007-10-12 16:40:37 -04002480 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07002481
Johannes Berg902acc72008-02-23 15:17:19 +01002482 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
2483 elems.mesh_config && mesh_matches_local(&elems, dev)) {
2484 u64 rates = ieee80211_sta_get_rates(local, &elems,
2485 rx_status->band);
2486
2487 mesh_neighbour_update(mgmt->sa, rates, dev,
2488 mesh_peer_accepts_plinks(&elems, dev));
2489 }
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002490
Johannes Bergd0709a62008-02-25 16:27:46 +01002491 rcu_read_lock();
2492
Johannes Berg51fb61e2007-12-19 01:31:27 +01002493 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
Jiri Bencf0706e822007-05-05 11:45:53 -07002494 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2495 (sta = sta_info_get(local, mgmt->sa))) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002496 u64 prev_rates;
2497 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
2498 rx_status->band);
Jiri Bencf0706e822007-05-05 11:45:53 -07002499
Johannes Berg8318d782008-01-24 19:38:38 +01002500 prev_rates = sta->supp_rates[rx_status->band];
2501 sta->supp_rates[rx_status->band] &= supp_rates;
2502 if (sta->supp_rates[rx_status->band] == 0) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002503 /* No matching rates - this should not really happen.
2504 * Make sure that at least one rate is marked
2505 * supported to avoid issues with TX rate ctrl. */
Johannes Berg8318d782008-01-24 19:38:38 +01002506 sta->supp_rates[rx_status->band] =
2507 sdata->u.sta.supp_rates_bits[rx_status->band];
Jiri Bencf0706e822007-05-05 11:45:53 -07002508 }
Johannes Berg8318d782008-01-24 19:38:38 +01002509 if (sta->supp_rates[rx_status->band] != prev_rates) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002510 printk(KERN_DEBUG "%s: updated supp_rates set for "
Johannes Berg8318d782008-01-24 19:38:38 +01002511 "%s based on beacon info (0x%llx & 0x%llx -> "
2512 "0x%llx)\n",
2513 dev->name, print_mac(mac, sta->addr),
2514 (unsigned long long) prev_rates,
2515 (unsigned long long) supp_rates,
2516 (unsigned long long) sta->supp_rates[rx_status->band]);
Jiri Bencf0706e822007-05-05 11:45:53 -07002517 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002518 }
2519
Johannes Bergd0709a62008-02-25 16:27:46 +01002520 rcu_read_unlock();
2521
Jiri Bencf0706e822007-05-05 11:45:53 -07002522 if (elems.ds_params && elems.ds_params_len == 1)
Johannes Berg8318d782008-01-24 19:38:38 +01002523 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
Jiri Bencf0706e822007-05-05 11:45:53 -07002524 else
Johannes Berg8318d782008-01-24 19:38:38 +01002525 freq = rx_status->freq;
Jiri Bencf0706e822007-05-05 11:45:53 -07002526
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002527 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2528
2529 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2530 return;
2531
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002532#ifdef CONFIG_MAC80211_MESH
2533 if (elems.mesh_config)
2534 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
2535 elems.mesh_id_len, elems.mesh_config, freq);
2536 else
2537#endif
2538 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002539 elems.ssid, elems.ssid_len);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002540 if (!bss) {
2541#ifdef CONFIG_MAC80211_MESH
2542 if (elems.mesh_config)
2543 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002544 elems.mesh_id_len, elems.mesh_config,
2545 elems.mesh_config_len, freq);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002546 else
2547#endif
2548 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2549 elems.ssid, elems.ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07002550 if (!bss)
2551 return;
2552 } else {
2553#if 0
2554 /* TODO: order by RSSI? */
2555 spin_lock_bh(&local->sta_bss_lock);
2556 list_move_tail(&bss->list, &local->sta_bss_list);
2557 spin_unlock_bh(&local->sta_bss_lock);
2558#endif
2559 }
2560
Johannes Berg8318d782008-01-24 19:38:38 +01002561 bss->band = rx_status->band;
2562
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002563 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2564 bss->probe_resp && beacon) {
2565 /* STA mode:
2566 * Do not allow beacon to override data from Probe Response. */
Jiri Bencf0706e822007-05-05 11:45:53 -07002567 ieee80211_rx_bss_put(dev, bss);
2568 return;
2569 }
2570
Daniel Drake56282212007-07-10 19:32:10 +02002571 /* save the ERP value so that it is available at association time */
2572 if (elems.erp_info && elems.erp_info_len >= 1) {
2573 bss->erp_value = elems.erp_info[0];
2574 bss->has_erp_value = 1;
2575 }
2576
Jiri Bencf0706e822007-05-05 11:45:53 -07002577 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2578 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
Jiri Bencf0706e822007-05-05 11:45:53 -07002579
2580 bss->supp_rates_len = 0;
2581 if (elems.supp_rates) {
2582 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2583 if (clen > elems.supp_rates_len)
2584 clen = elems.supp_rates_len;
2585 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
2586 clen);
2587 bss->supp_rates_len += clen;
2588 }
2589 if (elems.ext_supp_rates) {
2590 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2591 if (clen > elems.ext_supp_rates_len)
2592 clen = elems.ext_supp_rates_len;
2593 memcpy(&bss->supp_rates[bss->supp_rates_len],
2594 elems.ext_supp_rates, clen);
2595 bss->supp_rates_len += clen;
2596 }
2597
2598 if (elems.wpa &&
2599 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
2600 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
2601 kfree(bss->wpa_ie);
2602 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
2603 if (bss->wpa_ie) {
2604 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
2605 bss->wpa_ie_len = elems.wpa_len + 2;
2606 } else
2607 bss->wpa_ie_len = 0;
2608 } else if (!elems.wpa && bss->wpa_ie) {
2609 kfree(bss->wpa_ie);
2610 bss->wpa_ie = NULL;
2611 bss->wpa_ie_len = 0;
2612 }
2613
2614 if (elems.rsn &&
2615 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2616 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2617 kfree(bss->rsn_ie);
2618 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2619 if (bss->rsn_ie) {
2620 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2621 bss->rsn_ie_len = elems.rsn_len + 2;
2622 } else
2623 bss->rsn_ie_len = 0;
2624 } else if (!elems.rsn && bss->rsn_ie) {
2625 kfree(bss->rsn_ie);
2626 bss->rsn_ie = NULL;
2627 bss->rsn_ie_len = 0;
2628 }
2629
2630 if (elems.wmm_param &&
2631 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2632 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2633 kfree(bss->wmm_ie);
2634 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2635 if (bss->wmm_ie) {
2636 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2637 elems.wmm_param_len + 2);
2638 bss->wmm_ie_len = elems.wmm_param_len + 2;
2639 } else
2640 bss->wmm_ie_len = 0;
2641 } else if (!elems.wmm_param && bss->wmm_ie) {
2642 kfree(bss->wmm_ie);
2643 bss->wmm_ie = NULL;
2644 bss->wmm_ie_len = 0;
2645 }
Ron Rindjunskyc7153502007-11-26 16:14:31 +02002646 if (elems.ht_cap_elem &&
2647 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2648 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2649 kfree(bss->ht_ie);
2650 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2651 if (bss->ht_ie) {
2652 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2653 elems.ht_cap_elem_len + 2);
2654 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2655 } else
2656 bss->ht_ie_len = 0;
2657 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2658 kfree(bss->ht_ie);
2659 bss->ht_ie = NULL;
2660 bss->ht_ie_len = 0;
2661 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002662
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002663 bss->timestamp = beacon_timestamp;
Jiri Bencf0706e822007-05-05 11:45:53 -07002664 bss->last_update = jiffies;
2665 bss->rssi = rx_status->ssi;
2666 bss->signal = rx_status->signal;
2667 bss->noise = rx_status->noise;
2668 if (!beacon)
2669 bss->probe_resp++;
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002670
2671 /* check if we need to merge IBSS */
2672 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2673 !local->sta_sw_scanning && !local->sta_hw_scanning &&
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002674 bss->capability & WLAN_CAPABILITY_IBSS &&
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002675 bss->freq == local->oper_channel->center_freq &&
2676 elems.ssid_len == sdata->u.sta.ssid_len &&
2677 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2678 if (rx_status->flag & RX_FLAG_TSFT) {
2679 /* in order for correct IBSS merging we need mactime
2680 *
2681 * since mactime is defined as the time the first data
2682 * symbol of the frame hits the PHY, and the timestamp
2683 * of the beacon is defined as "the time that the data
2684 * symbol containing the first bit of the timestamp is
2685 * transmitted to the PHY plus the transmitting STA’s
2686 * delays through its local PHY from the MAC-PHY
2687 * interface to its interface with the WM"
2688 * (802.11 11.1.2) - equals the time this bit arrives at
2689 * the receiver - we have to take into account the
2690 * offset between the two.
2691 * e.g: at 1 MBit that means mactime is 192 usec earlier
2692 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2693 */
2694 int rate = local->hw.wiphy->bands[rx_status->band]->
2695 bitrates[rx_status->rate_idx].bitrate;
2696 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2697 } else if (local && local->ops && local->ops->get_tsf)
2698 /* second best option: get current TSF */
2699 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2700 else
2701 /* can't merge without knowing the TSF */
2702 rx_timestamp = -1LLU;
2703#ifdef CONFIG_MAC80211_IBSS_DEBUG
2704 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2705 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2706 print_mac(mac, mgmt->sa),
2707 print_mac(mac2, mgmt->bssid),
2708 (unsigned long long)rx_timestamp,
2709 (unsigned long long)beacon_timestamp,
2710 (unsigned long long)(rx_timestamp - beacon_timestamp),
2711 jiffies);
2712#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2713 if (beacon_timestamp > rx_timestamp) {
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002714#ifndef CONFIG_MAC80211_IBSS_DEBUG
Pavel Roskind97cf012008-02-21 11:33:58 -05002715 if (net_ratelimit())
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002716#endif
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002717 printk(KERN_DEBUG "%s: beacon TSF higher than "
2718 "local TSF - IBSS merge with BSSID %s\n",
2719 dev->name, print_mac(mac, mgmt->bssid));
2720 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2721 ieee80211_ibss_add_sta(dev, NULL,
2722 mgmt->bssid, mgmt->sa);
2723 }
2724 }
2725
Jiri Bencf0706e822007-05-05 11:45:53 -07002726 ieee80211_rx_bss_put(dev, bss);
2727}
2728
2729
2730static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2731 struct ieee80211_mgmt *mgmt,
2732 size_t len,
2733 struct ieee80211_rx_status *rx_status)
2734{
2735 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2736}
2737
2738
2739static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2740 struct ieee80211_mgmt *mgmt,
2741 size_t len,
2742 struct ieee80211_rx_status *rx_status)
2743{
Jiri Bencf0706e822007-05-05 11:45:53 -07002744 struct ieee80211_sub_if_data *sdata;
2745 struct ieee80211_if_sta *ifsta;
Jiri Bencf0706e822007-05-05 11:45:53 -07002746 size_t baselen;
2747 struct ieee802_11_elems elems;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002748 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2749 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002750 u32 changed = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07002751
2752 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
2753
2754 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01002755 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07002756 return;
2757 ifsta = &sdata->u.sta;
2758
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002759 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
Jiri Bencf0706e822007-05-05 11:45:53 -07002760 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2761 return;
2762
2763 /* Process beacon from the current BSS */
2764 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2765 if (baselen > len)
2766 return;
2767
John W. Linville67a4cce2007-10-12 16:40:37 -04002768 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07002769
Daniel Drake56282212007-07-10 19:32:10 +02002770 if (elems.erp_info && elems.erp_info_len >= 1)
Johannes Berg471b3ef2007-12-28 14:32:58 +01002771 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
Jiri Bencf0706e822007-05-05 11:45:53 -07002772
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002773 if (elems.ht_cap_elem && elems.ht_info_elem &&
2774 elems.wmm_param && local->ops->conf_ht &&
2775 conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
2776 struct ieee80211_ht_bss_info bss_info;
2777
2778 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2779 (struct ieee80211_ht_addt_info *)
2780 elems.ht_info_elem, &bss_info);
2781 /* check if AP changed bss inforamation */
2782 if ((conf->ht_bss_conf.primary_channel !=
2783 bss_info.primary_channel) ||
2784 (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) ||
2785 (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode))
2786 ieee80211_hw_config_ht(local, 1, &conf->ht_conf,
2787 &bss_info);
2788 }
2789
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002790 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002791 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2792 elems.wmm_param_len);
2793 }
Johannes Berg471b3ef2007-12-28 14:32:58 +01002794
2795 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e822007-05-05 11:45:53 -07002796}
2797
2798
2799static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
2800 struct ieee80211_if_sta *ifsta,
2801 struct ieee80211_mgmt *mgmt,
2802 size_t len,
2803 struct ieee80211_rx_status *rx_status)
2804{
2805 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2806 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2807 int tx_last_beacon;
2808 struct sk_buff *skb;
2809 struct ieee80211_mgmt *resp;
2810 u8 *pos, *end;
Joe Perches0795af52007-10-03 17:59:30 -07002811 DECLARE_MAC_BUF(mac);
2812#ifdef CONFIG_MAC80211_IBSS_DEBUG
2813 DECLARE_MAC_BUF(mac2);
2814 DECLARE_MAC_BUF(mac3);
2815#endif
Jiri Bencf0706e822007-05-05 11:45:53 -07002816
Johannes Berg51fb61e2007-12-19 01:31:27 +01002817 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
Jiri Bencf0706e822007-05-05 11:45:53 -07002818 ifsta->state != IEEE80211_IBSS_JOINED ||
2819 len < 24 + 2 || !ifsta->probe_resp)
2820 return;
2821
2822 if (local->ops->tx_last_beacon)
2823 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
2824 else
2825 tx_last_beacon = 1;
2826
2827#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07002828 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
2829 "%s (tx_last_beacon=%d)\n",
2830 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
2831 print_mac(mac3, mgmt->bssid), tx_last_beacon);
Jiri Bencf0706e822007-05-05 11:45:53 -07002832#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2833
2834 if (!tx_last_beacon)
2835 return;
2836
2837 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
2838 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
2839 return;
2840
2841 end = ((u8 *) mgmt) + len;
2842 pos = mgmt->u.probe_req.variable;
2843 if (pos[0] != WLAN_EID_SSID ||
2844 pos + 2 + pos[1] > end) {
2845 if (net_ratelimit()) {
2846 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
Joe Perches0795af52007-10-03 17:59:30 -07002847 "from %s\n",
2848 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07002849 }
2850 return;
2851 }
2852 if (pos[1] != 0 &&
2853 (pos[1] != ifsta->ssid_len ||
2854 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
2855 /* Ignore ProbeReq for foreign SSID */
2856 return;
2857 }
2858
2859 /* Reply with ProbeResp */
Michael Wu0ec0b7a2007-07-27 15:43:24 +02002860 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -07002861 if (!skb)
2862 return;
2863
2864 resp = (struct ieee80211_mgmt *) skb->data;
2865 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2866#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07002867 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
2868 dev->name, print_mac(mac, resp->da));
Jiri Bencf0706e822007-05-05 11:45:53 -07002869#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2870 ieee80211_sta_tx(dev, skb, 0);
2871}
2872
Johannes Berg4e20cb22007-12-19 01:31:24 +01002873static void ieee80211_rx_mgmt_action(struct net_device *dev,
2874 struct ieee80211_if_sta *ifsta,
2875 struct ieee80211_mgmt *mgmt,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002876 size_t len,
2877 struct ieee80211_rx_status *rx_status)
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02002878{
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002879 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002880
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02002881 if (len < IEEE80211_MIN_ACTION_SIZE)
2882 return;
2883
2884 switch (mgmt->u.action.category) {
2885 case WLAN_CATEGORY_BACK:
2886 switch (mgmt->u.action.u.addba_req.action_code) {
2887 case WLAN_ACTION_ADDBA_REQ:
2888 if (len < (IEEE80211_MIN_ACTION_SIZE +
2889 sizeof(mgmt->u.action.u.addba_req)))
2890 break;
2891 ieee80211_sta_process_addba_request(dev, mgmt, len);
2892 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02002893 case WLAN_ACTION_ADDBA_RESP:
2894 if (len < (IEEE80211_MIN_ACTION_SIZE +
2895 sizeof(mgmt->u.action.u.addba_resp)))
2896 break;
2897 ieee80211_sta_process_addba_resp(dev, mgmt, len);
2898 break;
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02002899 case WLAN_ACTION_DELBA:
2900 if (len < (IEEE80211_MIN_ACTION_SIZE +
2901 sizeof(mgmt->u.action.u.delba)))
2902 break;
2903 ieee80211_sta_process_delba(dev, mgmt, len);
2904 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02002905 default:
2906 if (net_ratelimit())
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02002907 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02002908 dev->name);
2909 break;
2910 }
2911 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002912 case PLINK_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01002913 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002914 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
2915 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002916 case MESH_PATH_SEL_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01002917 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002918 mesh_rx_path_sel_frame(dev, mgmt, len);
2919 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02002920 default:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002921 if (net_ratelimit())
2922 printk(KERN_DEBUG "%s: Rx unknown action frame - "
2923 "category=%d\n", dev->name, mgmt->u.action.category);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02002924 break;
2925 }
2926}
Jiri Bencf0706e822007-05-05 11:45:53 -07002927
2928void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2929 struct ieee80211_rx_status *rx_status)
2930{
2931 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2932 struct ieee80211_sub_if_data *sdata;
2933 struct ieee80211_if_sta *ifsta;
2934 struct ieee80211_mgmt *mgmt;
2935 u16 fc;
2936
2937 if (skb->len < 24)
2938 goto fail;
2939
2940 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2941 ifsta = &sdata->u.sta;
2942
2943 mgmt = (struct ieee80211_mgmt *) skb->data;
2944 fc = le16_to_cpu(mgmt->frame_control);
2945
2946 switch (fc & IEEE80211_FCTL_STYPE) {
2947 case IEEE80211_STYPE_PROBE_REQ:
2948 case IEEE80211_STYPE_PROBE_RESP:
2949 case IEEE80211_STYPE_BEACON:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002950 case IEEE80211_STYPE_ACTION:
Jiri Bencf0706e822007-05-05 11:45:53 -07002951 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2952 case IEEE80211_STYPE_AUTH:
2953 case IEEE80211_STYPE_ASSOC_RESP:
2954 case IEEE80211_STYPE_REASSOC_RESP:
2955 case IEEE80211_STYPE_DEAUTH:
2956 case IEEE80211_STYPE_DISASSOC:
2957 skb_queue_tail(&ifsta->skb_queue, skb);
2958 queue_work(local->hw.workqueue, &ifsta->work);
2959 return;
2960 default:
2961 printk(KERN_DEBUG "%s: received unknown management frame - "
2962 "stype=%d\n", dev->name,
2963 (fc & IEEE80211_FCTL_STYPE) >> 4);
2964 break;
2965 }
2966
2967 fail:
2968 kfree_skb(skb);
2969}
2970
2971
2972static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2973 struct sk_buff *skb)
2974{
2975 struct ieee80211_rx_status *rx_status;
2976 struct ieee80211_sub_if_data *sdata;
2977 struct ieee80211_if_sta *ifsta;
2978 struct ieee80211_mgmt *mgmt;
2979 u16 fc;
2980
2981 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2982 ifsta = &sdata->u.sta;
2983
2984 rx_status = (struct ieee80211_rx_status *) skb->cb;
2985 mgmt = (struct ieee80211_mgmt *) skb->data;
2986 fc = le16_to_cpu(mgmt->frame_control);
2987
2988 switch (fc & IEEE80211_FCTL_STYPE) {
2989 case IEEE80211_STYPE_PROBE_REQ:
2990 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
2991 rx_status);
2992 break;
2993 case IEEE80211_STYPE_PROBE_RESP:
2994 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
2995 break;
2996 case IEEE80211_STYPE_BEACON:
2997 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
2998 break;
2999 case IEEE80211_STYPE_AUTH:
3000 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
3001 break;
3002 case IEEE80211_STYPE_ASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003003 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -07003004 break;
3005 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003006 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
Jiri Bencf0706e822007-05-05 11:45:53 -07003007 break;
3008 case IEEE80211_STYPE_DEAUTH:
3009 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
3010 break;
3011 case IEEE80211_STYPE_DISASSOC:
3012 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
3013 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003014 case IEEE80211_STYPE_ACTION:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003015 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003016 break;
Jiri Bencf0706e822007-05-05 11:45:53 -07003017 }
3018
3019 kfree_skb(skb);
3020}
3021
3022
Johannes Berg9ae54c82008-01-31 19:48:20 +01003023ieee80211_rx_result
Zhu Yiece8edd2007-11-22 10:53:21 +08003024ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
3025 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e822007-05-05 11:45:53 -07003026{
3027 struct ieee80211_mgmt *mgmt;
3028 u16 fc;
3029
Zhu Yiece8edd2007-11-22 10:53:21 +08003030 if (skb->len < 2)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003031 return RX_DROP_UNUSABLE;
Jiri Bencf0706e822007-05-05 11:45:53 -07003032
3033 mgmt = (struct ieee80211_mgmt *) skb->data;
3034 fc = le16_to_cpu(mgmt->frame_control);
3035
Zhu Yiece8edd2007-11-22 10:53:21 +08003036 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
Johannes Berg9ae54c82008-01-31 19:48:20 +01003037 return RX_CONTINUE;
Zhu Yiece8edd2007-11-22 10:53:21 +08003038
3039 if (skb->len < 24)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003040 return RX_DROP_MONITOR;
Zhu Yiece8edd2007-11-22 10:53:21 +08003041
Jiri Bencf0706e822007-05-05 11:45:53 -07003042 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
3043 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
3044 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
3045 skb->len, rx_status);
Zhu Yiece8edd2007-11-22 10:53:21 +08003046 dev_kfree_skb(skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +01003047 return RX_QUEUED;
Jiri Bencf0706e822007-05-05 11:45:53 -07003048 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
3049 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
3050 rx_status);
Zhu Yiece8edd2007-11-22 10:53:21 +08003051 dev_kfree_skb(skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +01003052 return RX_QUEUED;
Jiri Bencf0706e822007-05-05 11:45:53 -07003053 }
3054 }
Johannes Berg9ae54c82008-01-31 19:48:20 +01003055 return RX_CONTINUE;
Jiri Bencf0706e822007-05-05 11:45:53 -07003056}
3057
3058
3059static int ieee80211_sta_active_ibss(struct net_device *dev)
3060{
3061 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3062 int active = 0;
3063 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +01003064 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -07003065
Johannes Bergd0709a62008-02-25 16:27:46 +01003066 rcu_read_lock();
3067
3068 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3069 if (sta->sdata == sdata &&
Jiri Bencf0706e822007-05-05 11:45:53 -07003070 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
3071 jiffies)) {
3072 active++;
3073 break;
3074 }
3075 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003076
3077 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07003078
3079 return active;
3080}
3081
3082
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003083static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
Jiri Bencf0706e822007-05-05 11:45:53 -07003084{
3085 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3086 struct sta_info *sta, *tmp;
Michael Wube8755e2007-07-27 15:43:23 +02003087 LIST_HEAD(tmp_list);
Joe Perches0795af52007-10-03 17:59:30 -07003088 DECLARE_MAC_BUF(mac);
Johannes Bergd0709a62008-02-25 16:27:46 +01003089 unsigned long flags;
Jiri Bencf0706e822007-05-05 11:45:53 -07003090
Johannes Bergd0709a62008-02-25 16:27:46 +01003091 spin_lock_irqsave(&local->sta_lock, flags);
Jiri Bencf0706e822007-05-05 11:45:53 -07003092 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003093 if (time_after(jiffies, sta->last_rx + exp_time)) {
Joe Perches0795af52007-10-03 17:59:30 -07003094 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
3095 dev->name, print_mac(mac, sta->addr));
Luis Carlos Cobocb585bc2008-03-31 15:21:23 -07003096 __sta_info_unlink(&sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01003097 if (sta)
3098 list_add(&sta->list, &tmp_list);
Jiri Bencf0706e822007-05-05 11:45:53 -07003099 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003100 spin_unlock_irqrestore(&local->sta_lock, flags);
Michael Wube8755e2007-07-27 15:43:23 +02003101
Johannes Bergd0709a62008-02-25 16:27:46 +01003102 synchronize_rcu();
3103
3104 rtnl_lock();
3105 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
3106 sta_info_destroy(sta);
3107 rtnl_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07003108}
3109
3110
3111static void ieee80211_sta_merge_ibss(struct net_device *dev,
3112 struct ieee80211_if_sta *ifsta)
3113{
3114 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
3115
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003116 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
Jiri Bencf0706e822007-05-05 11:45:53 -07003117 if (ieee80211_sta_active_ibss(dev))
3118 return;
3119
3120 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
3121 "IBSS networks with same SSID (merge)\n", dev->name);
3122 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
3123}
3124
3125
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003126#ifdef CONFIG_MAC80211_MESH
3127static void ieee80211_mesh_housekeeping(struct net_device *dev,
3128 struct ieee80211_if_sta *ifsta)
3129{
3130 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3131 bool free_plinks;
3132
3133 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3134 mesh_path_expire(dev);
3135
3136 free_plinks = mesh_plink_availables(sdata);
3137 if (free_plinks != sdata->u.sta.accepting_plinks)
3138 ieee80211_if_config_beacon(dev);
3139
3140 mod_timer(&ifsta->timer, jiffies +
3141 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3142}
3143
3144
3145void ieee80211_start_mesh(struct net_device *dev)
3146{
3147 struct ieee80211_if_sta *ifsta;
3148 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3149 ifsta = &sdata->u.sta;
3150 ifsta->state = IEEE80211_MESH_UP;
3151 ieee80211_sta_timer((unsigned long)sdata);
3152}
3153#endif
3154
3155
Jiri Bencf0706e822007-05-05 11:45:53 -07003156void ieee80211_sta_timer(unsigned long data)
3157{
3158 struct ieee80211_sub_if_data *sdata =
3159 (struct ieee80211_sub_if_data *) data;
3160 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3161 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
3162
3163 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3164 queue_work(local->hw.workqueue, &ifsta->work);
3165}
3166
Jiri Bencf0706e822007-05-05 11:45:53 -07003167void ieee80211_sta_work(struct work_struct *work)
3168{
3169 struct ieee80211_sub_if_data *sdata =
3170 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
3171 struct net_device *dev = sdata->dev;
3172 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3173 struct ieee80211_if_sta *ifsta;
3174 struct sk_buff *skb;
3175
3176 if (!netif_running(dev))
3177 return;
3178
Zhu Yiece8edd2007-11-22 10:53:21 +08003179 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -07003180 return;
3181
Johannes Berg51fb61e2007-12-19 01:31:27 +01003182 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003183 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3184 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003185 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
Johannes Berg51fb61e2007-12-19 01:31:27 +01003186 "(type=%d)\n", dev->name, sdata->vif.type);
Jiri Bencf0706e822007-05-05 11:45:53 -07003187 return;
3188 }
3189 ifsta = &sdata->u.sta;
3190
3191 while ((skb = skb_dequeue(&ifsta->skb_queue)))
3192 ieee80211_sta_rx_queued_mgmt(dev, skb);
3193
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003194#ifdef CONFIG_MAC80211_MESH
Johannes Berg902acc72008-02-23 15:17:19 +01003195 if (ifsta->preq_queue_len &&
3196 time_after(jiffies,
3197 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003198 mesh_path_start_discovery(dev);
3199#endif
3200
Jiri Bencf0706e822007-05-05 11:45:53 -07003201 if (ifsta->state != IEEE80211_AUTHENTICATE &&
3202 ifsta->state != IEEE80211_ASSOCIATE &&
3203 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
Helmut Schaaa0af5f12007-11-09 16:25:08 +01003204 if (ifsta->scan_ssid_len)
3205 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
3206 else
3207 ieee80211_sta_start_scan(dev, NULL, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -07003208 return;
3209 }
3210
3211 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
3212 if (ieee80211_sta_config_auth(dev, ifsta))
3213 return;
3214 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3215 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3216 return;
3217
3218 switch (ifsta->state) {
3219 case IEEE80211_DISABLED:
3220 break;
3221 case IEEE80211_AUTHENTICATE:
3222 ieee80211_authenticate(dev, ifsta);
3223 break;
3224 case IEEE80211_ASSOCIATE:
3225 ieee80211_associate(dev, ifsta);
3226 break;
3227 case IEEE80211_ASSOCIATED:
3228 ieee80211_associated(dev, ifsta);
3229 break;
3230 case IEEE80211_IBSS_SEARCH:
3231 ieee80211_sta_find_ibss(dev, ifsta);
3232 break;
3233 case IEEE80211_IBSS_JOINED:
3234 ieee80211_sta_merge_ibss(dev, ifsta);
3235 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003236#ifdef CONFIG_MAC80211_MESH
3237 case IEEE80211_MESH_UP:
3238 ieee80211_mesh_housekeeping(dev, ifsta);
3239 break;
3240#endif
Jiri Bencf0706e822007-05-05 11:45:53 -07003241 default:
3242 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
3243 ifsta->state);
3244 break;
3245 }
3246
3247 if (ieee80211_privacy_mismatch(dev, ifsta)) {
3248 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
3249 "mixed-cell disabled - disassociate\n", dev->name);
3250
3251 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
3252 ieee80211_set_disassoc(dev, ifsta, 0);
3253 }
3254}
3255
3256
3257static void ieee80211_sta_reset_auth(struct net_device *dev,
3258 struct ieee80211_if_sta *ifsta)
3259{
3260 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3261
3262 if (local->ops->reset_tsf) {
3263 /* Reset own TSF to allow time synchronization work. */
3264 local->ops->reset_tsf(local_to_hw(local));
3265 }
3266
3267 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3268
3269
3270 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3271 ifsta->auth_alg = WLAN_AUTH_OPEN;
3272 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3273 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3274 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3275 ifsta->auth_alg = WLAN_AUTH_LEAP;
3276 else
3277 ifsta->auth_alg = WLAN_AUTH_OPEN;
3278 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
3279 ifsta->auth_alg);
3280 ifsta->auth_transaction = -1;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003281 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
3282 ifsta->auth_tries = ifsta->assoc_tries = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07003283 netif_carrier_off(dev);
3284}
3285
3286
3287void ieee80211_sta_req_auth(struct net_device *dev,
3288 struct ieee80211_if_sta *ifsta)
3289{
3290 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3291 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3292
Johannes Berg51fb61e2007-12-19 01:31:27 +01003293 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07003294 return;
3295
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003296 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3297 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3298 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3299 IEEE80211_STA_AUTO_SSID_SEL))) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003300 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3301 queue_work(local->hw.workqueue, &ifsta->work);
3302 }
3303}
3304
3305static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3306 const char *ssid, int ssid_len)
3307{
3308 int tmp, hidden_ssid;
3309
Michael Wu48225702007-10-19 17:14:36 -04003310 if (ssid_len == ifsta->ssid_len &&
3311 !memcmp(ifsta->ssid, ssid, ssid_len))
Jiri Bencf0706e822007-05-05 11:45:53 -07003312 return 1;
3313
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003314 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Jiri Bencf0706e822007-05-05 11:45:53 -07003315 return 0;
3316
3317 hidden_ssid = 1;
3318 tmp = ssid_len;
3319 while (tmp--) {
3320 if (ssid[tmp] != '\0') {
3321 hidden_ssid = 0;
3322 break;
3323 }
3324 }
3325
3326 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3327 return 1;
3328
3329 if (ssid_len == 1 && ssid[0] == ' ')
3330 return 1;
3331
3332 return 0;
3333}
3334
3335static int ieee80211_sta_config_auth(struct net_device *dev,
3336 struct ieee80211_if_sta *ifsta)
3337{
3338 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3339 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3340 struct ieee80211_sta_bss *bss, *selected = NULL;
3341 int top_rssi = 0, freq;
3342
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003343 if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3344 IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003345 ifsta->state = IEEE80211_AUTHENTICATE;
Jiri Bencf0706e822007-05-05 11:45:53 -07003346 ieee80211_sta_reset_auth(dev, ifsta);
3347 return 0;
3348 }
3349
3350 spin_lock_bh(&local->sta_bss_lock);
Johannes Berg8318d782008-01-24 19:38:38 +01003351 freq = local->oper_channel->center_freq;
Jiri Bencf0706e822007-05-05 11:45:53 -07003352 list_for_each_entry(bss, &local->sta_bss_list, list) {
3353 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3354 continue;
3355
3356 if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3357 !!sdata->default_key)
3358 continue;
3359
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003360 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3361 bss->freq != freq)
Jiri Bencf0706e822007-05-05 11:45:53 -07003362 continue;
3363
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003364 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
Jiri Bencf0706e822007-05-05 11:45:53 -07003365 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3366 continue;
3367
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003368 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
Jiri Bencf0706e822007-05-05 11:45:53 -07003369 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3370 continue;
3371
3372 if (!selected || top_rssi < bss->rssi) {
3373 selected = bss;
3374 top_rssi = bss->rssi;
3375 }
3376 }
3377 if (selected)
3378 atomic_inc(&selected->users);
3379 spin_unlock_bh(&local->sta_bss_lock);
3380
3381 if (selected) {
Johannes Berg8318d782008-01-24 19:38:38 +01003382 ieee80211_set_freq(local, selected->freq);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003383 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
Jiri Bencf0706e822007-05-05 11:45:53 -07003384 ieee80211_sta_set_ssid(dev, selected->ssid,
3385 selected->ssid_len);
3386 ieee80211_sta_set_bssid(dev, selected->bssid);
Vladimir Koutnye2839d82008-03-18 21:14:07 +01003387 ieee80211_sta_def_wmm_params(dev, selected, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -07003388 ieee80211_rx_bss_put(dev, selected);
3389 ifsta->state = IEEE80211_AUTHENTICATE;
Jiri Bencf0706e822007-05-05 11:45:53 -07003390 ieee80211_sta_reset_auth(dev, ifsta);
3391 return 0;
3392 } else {
3393 if (ifsta->state != IEEE80211_AUTHENTICATE) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003394 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
John W. Linvilleb9bf1e62007-08-07 16:33:15 -04003395 ieee80211_sta_start_scan(dev, NULL, 0);
3396 else
3397 ieee80211_sta_start_scan(dev, ifsta->ssid,
3398 ifsta->ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07003399 ifsta->state = IEEE80211_AUTHENTICATE;
3400 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3401 } else
3402 ifsta->state = IEEE80211_DISABLED;
3403 }
Jiri Bencf0706e822007-05-05 11:45:53 -07003404 return -1;
3405}
3406
Jiri Bencf0706e822007-05-05 11:45:53 -07003407
3408static int ieee80211_sta_create_ibss(struct net_device *dev,
3409 struct ieee80211_if_sta *ifsta)
3410{
3411 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3412 struct ieee80211_sta_bss *bss;
John W. Linvillecffdd302007-10-05 14:23:27 -04003413 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +01003414 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07003415 u8 bssid[ETH_ALEN], *pos;
3416 int i;
Joe Perches0795af52007-10-03 17:59:30 -07003417 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07003418
3419#if 0
3420 /* Easier testing, use fixed BSSID. */
3421 memset(bssid, 0xfe, ETH_ALEN);
3422#else
3423 /* Generate random, not broadcast, locally administered BSSID. Mix in
3424 * own MAC address to make sure that devices that do not have proper
3425 * random number generator get different BSSID. */
3426 get_random_bytes(bssid, ETH_ALEN);
3427 for (i = 0; i < ETH_ALEN; i++)
3428 bssid[i] ^= dev->dev_addr[i];
3429 bssid[0] &= ~0x01;
3430 bssid[0] |= 0x02;
3431#endif
3432
Joe Perches0795af52007-10-03 17:59:30 -07003433 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3434 dev->name, print_mac(mac, bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07003435
Johannes Berg8318d782008-01-24 19:38:38 +01003436 bss = ieee80211_rx_bss_add(dev, bssid,
3437 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04003438 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07003439 if (!bss)
3440 return -ENOMEM;
3441
Johannes Berg8318d782008-01-24 19:38:38 +01003442 bss->band = local->hw.conf.channel->band;
3443 sband = local->hw.wiphy->bands[bss->band];
Jiri Bencf0706e822007-05-05 11:45:53 -07003444
3445 if (local->hw.conf.beacon_int == 0)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003446 local->hw.conf.beacon_int = 10000;
Jiri Bencf0706e822007-05-05 11:45:53 -07003447 bss->beacon_int = local->hw.conf.beacon_int;
Jiri Bencf0706e822007-05-05 11:45:53 -07003448 bss->last_update = jiffies;
3449 bss->capability = WLAN_CAPABILITY_IBSS;
3450 if (sdata->default_key) {
3451 bss->capability |= WLAN_CAPABILITY_PRIVACY;
3452 } else
3453 sdata->drop_unencrypted = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003454 bss->supp_rates_len = sband->n_bitrates;
Jiri Bencf0706e822007-05-05 11:45:53 -07003455 pos = bss->supp_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01003456 for (i = 0; i < sband->n_bitrates; i++) {
3457 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e822007-05-05 11:45:53 -07003458 *pos++ = (u8) (rate / 5);
3459 }
3460
3461 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3462}
3463
3464
3465static int ieee80211_sta_find_ibss(struct net_device *dev,
3466 struct ieee80211_if_sta *ifsta)
3467{
3468 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3469 struct ieee80211_sta_bss *bss;
3470 int found = 0;
3471 u8 bssid[ETH_ALEN];
3472 int active_ibss;
Joe Perches0795af52007-10-03 17:59:30 -07003473 DECLARE_MAC_BUF(mac);
3474 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e822007-05-05 11:45:53 -07003475
3476 if (ifsta->ssid_len == 0)
3477 return -EINVAL;
3478
3479 active_ibss = ieee80211_sta_active_ibss(dev);
3480#ifdef CONFIG_MAC80211_IBSS_DEBUG
3481 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
3482 dev->name, active_ibss);
3483#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3484 spin_lock_bh(&local->sta_bss_lock);
3485 list_for_each_entry(bss, &local->sta_bss_list, list) {
3486 if (ifsta->ssid_len != bss->ssid_len ||
3487 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3488 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3489 continue;
3490#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003491 printk(KERN_DEBUG " bssid=%s found\n",
3492 print_mac(mac, bss->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07003493#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3494 memcpy(bssid, bss->bssid, ETH_ALEN);
3495 found = 1;
3496 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3497 break;
3498 }
3499 spin_unlock_bh(&local->sta_bss_lock);
3500
3501#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003502 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3503 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07003504#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3505 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
Johannes Berg8318d782008-01-24 19:38:38 +01003506 (bss = ieee80211_rx_bss_get(dev, bssid,
3507 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04003508 ifsta->ssid, ifsta->ssid_len))) {
Joe Perches0795af52007-10-03 17:59:30 -07003509 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
Jiri Bencf0706e822007-05-05 11:45:53 -07003510 " based on configured SSID\n",
Joe Perches0795af52007-10-03 17:59:30 -07003511 dev->name, print_mac(mac, bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07003512 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3513 }
3514#ifdef CONFIG_MAC80211_IBSS_DEBUG
3515 printk(KERN_DEBUG " did not try to join ibss\n");
3516#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3517
3518 /* Selected IBSS not found in current scan results - try to scan */
3519 if (ifsta->state == IEEE80211_IBSS_JOINED &&
3520 !ieee80211_sta_active_ibss(dev)) {
3521 mod_timer(&ifsta->timer, jiffies +
3522 IEEE80211_IBSS_MERGE_INTERVAL);
3523 } else if (time_after(jiffies, local->last_scan_completed +
3524 IEEE80211_SCAN_INTERVAL)) {
3525 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
3526 "join\n", dev->name);
3527 return ieee80211_sta_req_scan(dev, ifsta->ssid,
3528 ifsta->ssid_len);
3529 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
3530 int interval = IEEE80211_SCAN_INTERVAL;
3531
3532 if (time_after(jiffies, ifsta->ibss_join_req +
3533 IEEE80211_IBSS_JOIN_TIMEOUT)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003534 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
Johannes Berg8318d782008-01-24 19:38:38 +01003535 (!(local->oper_channel->flags &
3536 IEEE80211_CHAN_NO_IBSS)))
Jiri Bencf0706e822007-05-05 11:45:53 -07003537 return ieee80211_sta_create_ibss(dev, ifsta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003538 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
Johannes Berg8318d782008-01-24 19:38:38 +01003539 printk(KERN_DEBUG "%s: IBSS not allowed on"
3540 " %d MHz\n", dev->name,
3541 local->hw.conf.channel->center_freq);
Jiri Bencf0706e822007-05-05 11:45:53 -07003542 }
3543
3544 /* No IBSS found - decrease scan interval and continue
3545 * scanning. */
3546 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3547 }
3548
3549 ifsta->state = IEEE80211_IBSS_SEARCH;
3550 mod_timer(&ifsta->timer, jiffies + interval);
3551 return 0;
3552 }
3553
3554 return 0;
3555}
3556
3557
3558int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3559{
Johannes Berg8318d782008-01-24 19:38:38 +01003560 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -07003561 struct ieee80211_if_sta *ifsta;
Jiri Bencf0706e822007-05-05 11:45:53 -07003562
3563 if (len > IEEE80211_MAX_SSID_LEN)
3564 return -EINVAL;
3565
Jiri Bencf0706e822007-05-05 11:45:53 -07003566 ifsta = &sdata->u.sta;
3567
3568 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003569 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e822007-05-05 11:45:53 -07003570 memcpy(ifsta->ssid, ssid, len);
3571 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3572 ifsta->ssid_len = len;
3573
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003574 if (len)
3575 ifsta->flags |= IEEE80211_STA_SSID_SET;
3576 else
3577 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
Johannes Berg51fb61e2007-12-19 01:31:27 +01003578 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003579 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003580 ifsta->ibss_join_req = jiffies;
3581 ifsta->state = IEEE80211_IBSS_SEARCH;
3582 return ieee80211_sta_find_ibss(dev, ifsta);
3583 }
3584 return 0;
3585}
3586
3587
3588int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3589{
3590 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3591 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3592 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3593 *len = ifsta->ssid_len;
3594 return 0;
3595}
3596
3597
3598int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3599{
3600 struct ieee80211_sub_if_data *sdata;
3601 struct ieee80211_if_sta *ifsta;
3602 int res;
3603
3604 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3605 ifsta = &sdata->u.sta;
3606
3607 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3608 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3609 res = ieee80211_if_config(dev);
3610 if (res) {
3611 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3612 "the low-level driver\n", dev->name);
3613 return res;
3614 }
3615 }
3616
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003617 if (is_valid_ether_addr(bssid))
3618 ifsta->flags |= IEEE80211_STA_BSSID_SET;
Jiri Bencf0706e822007-05-05 11:45:53 -07003619 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003620 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3621
Jiri Bencf0706e822007-05-05 11:45:53 -07003622 return 0;
3623}
3624
3625
3626static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3627 struct ieee80211_sub_if_data *sdata,
3628 int powersave)
3629{
3630 struct sk_buff *skb;
3631 struct ieee80211_hdr *nullfunc;
3632 u16 fc;
3633
3634 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3635 if (!skb) {
3636 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3637 "frame\n", sdata->dev->name);
3638 return;
3639 }
3640 skb_reserve(skb, local->hw.extra_tx_headroom);
3641
3642 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3643 memset(nullfunc, 0, 24);
3644 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3645 IEEE80211_FCTL_TODS;
3646 if (powersave)
3647 fc |= IEEE80211_FCTL_PM;
3648 nullfunc->frame_control = cpu_to_le16(fc);
3649 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3650 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3651 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3652
3653 ieee80211_sta_tx(sdata->dev, skb, 0);
3654}
3655
3656
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003657static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3658{
3659 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3660 ieee80211_vif_is_mesh(&sdata->vif))
3661 ieee80211_sta_timer((unsigned long)sdata);
3662}
3663
Jiri Bencf0706e822007-05-05 11:45:53 -07003664void ieee80211_scan_completed(struct ieee80211_hw *hw)
3665{
3666 struct ieee80211_local *local = hw_to_local(hw);
3667 struct net_device *dev = local->scan_dev;
3668 struct ieee80211_sub_if_data *sdata;
3669 union iwreq_data wrqu;
3670
3671 local->last_scan_completed = jiffies;
Zhu Yiece8edd2007-11-22 10:53:21 +08003672 memset(&wrqu, 0, sizeof(wrqu));
3673 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
Jiri Bencf0706e822007-05-05 11:45:53 -07003674
Zhu Yiece8edd2007-11-22 10:53:21 +08003675 if (local->sta_hw_scanning) {
3676 local->sta_hw_scanning = 0;
Mohamed Abbas675ef582008-03-20 08:14:29 -07003677 if (ieee80211_hw_config(local))
3678 printk(KERN_DEBUG "%s: failed to restore operational "
3679 "channel after scan\n", dev->name);
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003680 /* Restart STA timer for HW scan case */
3681 rcu_read_lock();
3682 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3683 ieee80211_restart_sta_timer(sdata);
3684 rcu_read_unlock();
3685
Zhu Yiece8edd2007-11-22 10:53:21 +08003686 goto done;
3687 }
3688
3689 local->sta_sw_scanning = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07003690 if (ieee80211_hw_config(local))
Bruno Randolf4b50e382007-11-16 17:04:01 +09003691 printk(KERN_DEBUG "%s: failed to restore operational "
Jiri Bencf0706e822007-05-05 11:45:53 -07003692 "channel after scan\n", dev->name);
3693
Johannes Berg4150c572007-09-17 01:29:23 -04003694
3695 netif_tx_lock_bh(local->mdev);
3696 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3697 local->ops->configure_filter(local_to_hw(local),
3698 FIF_BCN_PRBRESP_PROMISC,
3699 &local->filter_flags,
3700 local->mdev->mc_count,
3701 local->mdev->mc_list);
3702
3703 netif_tx_unlock_bh(local->mdev);
Jiri Bencf0706e822007-05-05 11:45:53 -07003704
Johannes Berg79010422007-09-18 17:29:21 -04003705 rcu_read_lock();
3706 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Mattias Nissler14042cb2007-06-08 15:31:13 +02003707
3708 /* No need to wake the master device. */
3709 if (sdata->dev == local->mdev)
3710 continue;
3711
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003712 /* Tell AP we're back */
3713 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3714 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3715 ieee80211_send_nullfunc(local, sdata, 0);
Mattias Nissler14042cb2007-06-08 15:31:13 +02003716
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003717 ieee80211_restart_sta_timer(sdata);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003718
Jiri Bencf0706e822007-05-05 11:45:53 -07003719 netif_wake_queue(sdata->dev);
3720 }
Johannes Berg79010422007-09-18 17:29:21 -04003721 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07003722
Zhu Yiece8edd2007-11-22 10:53:21 +08003723done:
Jiri Bencf0706e822007-05-05 11:45:53 -07003724 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01003725 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003726 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003727 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
Jiri Bencf0706e822007-05-05 11:45:53 -07003728 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3729 !ieee80211_sta_active_ibss(dev)))
3730 ieee80211_sta_find_ibss(dev, ifsta);
3731 }
3732}
3733EXPORT_SYMBOL(ieee80211_scan_completed);
3734
3735void ieee80211_sta_scan_work(struct work_struct *work)
3736{
3737 struct ieee80211_local *local =
3738 container_of(work, struct ieee80211_local, scan_work.work);
3739 struct net_device *dev = local->scan_dev;
3740 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +01003741 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07003742 struct ieee80211_channel *chan;
3743 int skip;
3744 unsigned long next_delay = 0;
3745
Zhu Yiece8edd2007-11-22 10:53:21 +08003746 if (!local->sta_sw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -07003747 return;
3748
3749 switch (local->scan_state) {
3750 case SCAN_SET_CHANNEL:
Johannes Berg69d464d2008-01-28 17:08:56 +01003751 /*
3752 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3753 * after we successfully scanned the last channel of the last
3754 * band (and the last band is supported by the hw)
3755 */
Johannes Berg8318d782008-01-24 19:38:38 +01003756 if (local->scan_band < IEEE80211_NUM_BANDS)
3757 sband = local->hw.wiphy->bands[local->scan_band];
3758 else
3759 sband = NULL;
3760
Johannes Berg69d464d2008-01-28 17:08:56 +01003761 /*
3762 * If we are at an unsupported band and have more bands
3763 * left to scan, advance to the next supported one.
3764 */
3765 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
Johannes Berg8318d782008-01-24 19:38:38 +01003766 local->scan_band++;
3767 sband = local->hw.wiphy->bands[local->scan_band];
3768 local->scan_channel_idx = 0;
3769 }
3770
Johannes Berg69d464d2008-01-28 17:08:56 +01003771 /* if no more bands/channels left, complete scan */
3772 if (!sband || local->scan_channel_idx >= sband->n_channels) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003773 ieee80211_scan_completed(local_to_hw(local));
3774 return;
3775 }
Johannes Berg8318d782008-01-24 19:38:38 +01003776 skip = 0;
3777 chan = &sband->channels[local->scan_channel_idx];
3778
3779 if (chan->flags & IEEE80211_CHAN_DISABLED ||
Johannes Berg51fb61e2007-12-19 01:31:27 +01003780 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Johannes Berg8318d782008-01-24 19:38:38 +01003781 chan->flags & IEEE80211_CHAN_NO_IBSS))
Jiri Bencf0706e822007-05-05 11:45:53 -07003782 skip = 1;
3783
3784 if (!skip) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003785 local->scan_channel = chan;
3786 if (ieee80211_hw_config(local)) {
Johannes Berg8318d782008-01-24 19:38:38 +01003787 printk(KERN_DEBUG "%s: failed to set freq to "
3788 "%d MHz for scan\n", dev->name,
3789 chan->center_freq);
Jiri Bencf0706e822007-05-05 11:45:53 -07003790 skip = 1;
3791 }
3792 }
3793
Johannes Berg69d464d2008-01-28 17:08:56 +01003794 /* advance state machine to next channel/band */
Jiri Bencf0706e822007-05-05 11:45:53 -07003795 local->scan_channel_idx++;
Johannes Berg8318d782008-01-24 19:38:38 +01003796 if (local->scan_channel_idx >= sband->n_channels) {
Johannes Berg69d464d2008-01-28 17:08:56 +01003797 /*
3798 * scan_band may end up == IEEE80211_NUM_BANDS, but
3799 * we'll catch that case above and complete the scan
3800 * if that is the case.
3801 */
Johannes Berg8318d782008-01-24 19:38:38 +01003802 local->scan_band++;
3803 local->scan_channel_idx = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07003804 }
3805
3806 if (skip)
3807 break;
3808
3809 next_delay = IEEE80211_PROBE_DELAY +
3810 usecs_to_jiffies(local->hw.channel_change_time);
3811 local->scan_state = SCAN_SEND_PROBE;
3812 break;
3813 case SCAN_SEND_PROBE:
Johannes Berg8318d782008-01-24 19:38:38 +01003814 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
Jiri Bencf0706e822007-05-05 11:45:53 -07003815 local->scan_state = SCAN_SET_CHANNEL;
Johannes Berg8318d782008-01-24 19:38:38 +01003816
3817 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3818 break;
3819 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3820 local->scan_ssid_len);
3821 next_delay = IEEE80211_CHANNEL_TIME;
Jiri Bencf0706e822007-05-05 11:45:53 -07003822 break;
3823 }
3824
Zhu Yiece8edd2007-11-22 10:53:21 +08003825 if (local->sta_sw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -07003826 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3827 next_delay);
3828}
3829
3830
3831static int ieee80211_sta_start_scan(struct net_device *dev,
3832 u8 *ssid, size_t ssid_len)
3833{
3834 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3835 struct ieee80211_sub_if_data *sdata;
3836
3837 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3838 return -EINVAL;
3839
3840 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3841 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3842 * BSSID: MACAddress
3843 * SSID
3844 * ScanType: ACTIVE, PASSIVE
3845 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3846 * a Probe frame during active scanning
3847 * ChannelList
3848 * MinChannelTime (>= ProbeDelay), in TU
3849 * MaxChannelTime: (>= MinChannelTime), in TU
3850 */
3851
3852 /* MLME-SCAN.confirm
3853 * BSSDescriptionSet
3854 * ResultCode: SUCCESS, INVALID_PARAMETERS
3855 */
3856
Zhu Yiece8edd2007-11-22 10:53:21 +08003857 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003858 if (local->scan_dev == dev)
3859 return 0;
3860 return -EBUSY;
3861 }
3862
3863 if (local->ops->hw_scan) {
3864 int rc = local->ops->hw_scan(local_to_hw(local),
Zhu Yiece8edd2007-11-22 10:53:21 +08003865 ssid, ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07003866 if (!rc) {
Zhu Yiece8edd2007-11-22 10:53:21 +08003867 local->sta_hw_scanning = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07003868 local->scan_dev = dev;
3869 }
3870 return rc;
3871 }
3872
Zhu Yiece8edd2007-11-22 10:53:21 +08003873 local->sta_sw_scanning = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07003874
Johannes Berg79010422007-09-18 17:29:21 -04003875 rcu_read_lock();
3876 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Mattias Nissler14042cb2007-06-08 15:31:13 +02003877
3878 /* Don't stop the master interface, otherwise we can't transmit
3879 * probes! */
3880 if (sdata->dev == local->mdev)
3881 continue;
3882
Jiri Bencf0706e822007-05-05 11:45:53 -07003883 netif_stop_queue(sdata->dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01003884 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003885 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e822007-05-05 11:45:53 -07003886 ieee80211_send_nullfunc(local, sdata, 1);
3887 }
Johannes Berg79010422007-09-18 17:29:21 -04003888 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07003889
3890 if (ssid) {
3891 local->scan_ssid_len = ssid_len;
3892 memcpy(local->scan_ssid, ssid, ssid_len);
3893 } else
3894 local->scan_ssid_len = 0;
3895 local->scan_state = SCAN_SET_CHANNEL;
Jiri Bencf0706e822007-05-05 11:45:53 -07003896 local->scan_channel_idx = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003897 local->scan_band = IEEE80211_BAND_2GHZ;
Jiri Bencf0706e822007-05-05 11:45:53 -07003898 local->scan_dev = dev;
3899
Johannes Berg4150c572007-09-17 01:29:23 -04003900 netif_tx_lock_bh(local->mdev);
3901 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
3902 local->ops->configure_filter(local_to_hw(local),
3903 FIF_BCN_PRBRESP_PROMISC,
3904 &local->filter_flags,
3905 local->mdev->mc_count,
3906 local->mdev->mc_list);
3907 netif_tx_unlock_bh(local->mdev);
Jiri Bencf0706e822007-05-05 11:45:53 -07003908
3909 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3910 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3911 IEEE80211_CHANNEL_TIME);
3912
3913 return 0;
3914}
3915
3916
3917int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
3918{
3919 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3920 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3921 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3922
Johannes Berg51fb61e2007-12-19 01:31:27 +01003923 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07003924 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
3925
Zhu Yiece8edd2007-11-22 10:53:21 +08003926 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003927 if (local->scan_dev == dev)
3928 return 0;
3929 return -EBUSY;
3930 }
3931
Helmut Schaaa0af5f12007-11-09 16:25:08 +01003932 ifsta->scan_ssid_len = ssid_len;
3933 if (ssid_len)
3934 memcpy(ifsta->scan_ssid, ssid, ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07003935 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
3936 queue_work(local->hw.workqueue, &ifsta->work);
3937 return 0;
3938}
3939
3940static char *
3941ieee80211_sta_scan_result(struct net_device *dev,
3942 struct ieee80211_sta_bss *bss,
3943 char *current_ev, char *end_buf)
3944{
3945 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3946 struct iw_event iwe;
3947
3948 if (time_after(jiffies,
3949 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3950 return current_ev;
3951
Jiri Bencf0706e822007-05-05 11:45:53 -07003952 memset(&iwe, 0, sizeof(iwe));
3953 iwe.cmd = SIOCGIWAP;
3954 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3955 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
3956 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3957 IW_EV_ADDR_LEN);
3958
3959 memset(&iwe, 0, sizeof(iwe));
3960 iwe.cmd = SIOCGIWESSID;
Johannes Berg902acc72008-02-23 15:17:19 +01003961 if (bss_mesh_cfg(bss)) {
3962 iwe.u.data.length = bss_mesh_id_len(bss);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003963 iwe.u.data.flags = 1;
3964 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
Johannes Berg902acc72008-02-23 15:17:19 +01003965 bss_mesh_id(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003966 } else {
3967 iwe.u.data.length = bss->ssid_len;
3968 iwe.u.data.flags = 1;
3969 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3970 bss->ssid);
3971 }
Jiri Bencf0706e822007-05-05 11:45:53 -07003972
Luis Carlos Cobo1d1b5352008-02-29 12:15:28 -08003973 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
3974 || bss_mesh_cfg(bss)) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003975 memset(&iwe, 0, sizeof(iwe));
3976 iwe.cmd = SIOCGIWMODE;
Johannes Berg902acc72008-02-23 15:17:19 +01003977 if (bss_mesh_cfg(bss))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003978 iwe.u.mode = IW_MODE_MESH;
3979 else if (bss->capability & WLAN_CAPABILITY_ESS)
Jiri Bencf0706e822007-05-05 11:45:53 -07003980 iwe.u.mode = IW_MODE_MASTER;
3981 else
3982 iwe.u.mode = IW_MODE_ADHOC;
3983 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3984 IW_EV_UINT_LEN);
3985 }
3986
3987 memset(&iwe, 0, sizeof(iwe));
3988 iwe.cmd = SIOCGIWFREQ;
Johannes Berg8318d782008-01-24 19:38:38 +01003989 iwe.u.freq.m = bss->freq;
3990 iwe.u.freq.e = 6;
Jiri Bencf0706e822007-05-05 11:45:53 -07003991 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3992 IW_EV_FREQ_LEN);
Johannes Berg8318d782008-01-24 19:38:38 +01003993
3994 memset(&iwe, 0, sizeof(iwe));
3995 iwe.cmd = SIOCGIWFREQ;
3996 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
3997 iwe.u.freq.e = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07003998 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3999 IW_EV_FREQ_LEN);
4000
4001 memset(&iwe, 0, sizeof(iwe));
4002 iwe.cmd = IWEVQUAL;
4003 iwe.u.qual.qual = bss->signal;
4004 iwe.u.qual.level = bss->rssi;
4005 iwe.u.qual.noise = bss->noise;
4006 iwe.u.qual.updated = local->wstats_flags;
4007 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
4008 IW_EV_QUAL_LEN);
4009
4010 memset(&iwe, 0, sizeof(iwe));
4011 iwe.cmd = SIOCGIWENCODE;
4012 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
4013 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4014 else
4015 iwe.u.data.flags = IW_ENCODE_DISABLED;
4016 iwe.u.data.length = 0;
4017 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
4018
4019 if (bss && bss->wpa_ie) {
4020 memset(&iwe, 0, sizeof(iwe));
4021 iwe.cmd = IWEVGENIE;
4022 iwe.u.data.length = bss->wpa_ie_len;
4023 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
4024 bss->wpa_ie);
4025 }
4026
4027 if (bss && bss->rsn_ie) {
4028 memset(&iwe, 0, sizeof(iwe));
4029 iwe.cmd = IWEVGENIE;
4030 iwe.u.data.length = bss->rsn_ie_len;
4031 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
4032 bss->rsn_ie);
4033 }
4034
4035 if (bss && bss->supp_rates_len > 0) {
4036 /* display all supported rates in readable format */
4037 char *p = current_ev + IW_EV_LCP_LEN;
4038 int i;
4039
4040 memset(&iwe, 0, sizeof(iwe));
4041 iwe.cmd = SIOCGIWRATE;
4042 /* Those two flags are ignored... */
4043 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4044
4045 for (i = 0; i < bss->supp_rates_len; i++) {
4046 iwe.u.bitrate.value = ((bss->supp_rates[i] &
4047 0x7f) * 500000);
4048 p = iwe_stream_add_value(current_ev, p,
4049 end_buf, &iwe, IW_EV_PARAM_LEN);
4050 }
4051 current_ev = p;
4052 }
4053
4054 if (bss) {
4055 char *buf;
4056 buf = kmalloc(30, GFP_ATOMIC);
4057 if (buf) {
4058 memset(&iwe, 0, sizeof(iwe));
4059 iwe.cmd = IWEVCUSTOM;
4060 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
4061 iwe.u.data.length = strlen(buf);
4062 current_ev = iwe_stream_add_point(current_ev, end_buf,
4063 &iwe, buf);
4064 kfree(buf);
4065 }
4066 }
4067
Johannes Berg902acc72008-02-23 15:17:19 +01004068 if (bss_mesh_cfg(bss)) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004069 char *buf;
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07004070 struct bss_mesh_config *cfg = bss_mesh_cfg(bss);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004071 buf = kmalloc(50, GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004072 if (buf) {
4073 memset(&iwe, 0, sizeof(iwe));
4074 iwe.cmd = IWEVCUSTOM;
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07004075 sprintf(buf, "Mesh network (version %d)",
4076 cfg->mesh_version);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004077 iwe.u.data.length = strlen(buf);
4078 current_ev = iwe_stream_add_point(current_ev, end_buf,
4079 &iwe, buf);
4080 sprintf(buf, "Path Selection Protocol ID: "
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07004081 "0x%08X", cfg->path_proto_id);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004082 iwe.u.data.length = strlen(buf);
4083 current_ev = iwe_stream_add_point(current_ev, end_buf,
4084 &iwe, buf);
4085 sprintf(buf, "Path Selection Metric ID: "
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07004086 "0x%08X", cfg->path_metric_id);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004087 iwe.u.data.length = strlen(buf);
4088 current_ev = iwe_stream_add_point(current_ev, end_buf,
4089 &iwe, buf);
4090 sprintf(buf, "Congestion Control Mode ID: "
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07004091 "0x%08X", cfg->cong_control_id);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004092 iwe.u.data.length = strlen(buf);
4093 current_ev = iwe_stream_add_point(current_ev, end_buf,
4094 &iwe, buf);
4095 sprintf(buf, "Channel Precedence: "
Luis Carlos Cobo6c4711b2008-03-31 17:39:18 -07004096 "0x%08X", cfg->channel_precedence);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004097 iwe.u.data.length = strlen(buf);
4098 current_ev = iwe_stream_add_point(current_ev, end_buf,
4099 &iwe, buf);
4100 kfree(buf);
4101 }
4102 }
4103
Jiri Bencf0706e822007-05-05 11:45:53 -07004104 return current_ev;
4105}
4106
4107
4108int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
4109{
4110 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4111 char *current_ev = buf;
4112 char *end_buf = buf + len;
4113 struct ieee80211_sta_bss *bss;
4114
4115 spin_lock_bh(&local->sta_bss_lock);
4116 list_for_each_entry(bss, &local->sta_bss_list, list) {
4117 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
4118 spin_unlock_bh(&local->sta_bss_lock);
4119 return -E2BIG;
4120 }
4121 current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
4122 end_buf);
4123 }
4124 spin_unlock_bh(&local->sta_bss_lock);
4125 return current_ev - buf;
4126}
4127
4128
4129int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
4130{
4131 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4132 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4133 kfree(ifsta->extra_ie);
4134 if (len == 0) {
4135 ifsta->extra_ie = NULL;
4136 ifsta->extra_ie_len = 0;
4137 return 0;
4138 }
4139 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
4140 if (!ifsta->extra_ie) {
4141 ifsta->extra_ie_len = 0;
4142 return -ENOMEM;
4143 }
4144 memcpy(ifsta->extra_ie, ie, len);
4145 ifsta->extra_ie_len = len;
4146 return 0;
4147}
4148
4149
4150struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
4151 struct sk_buff *skb, u8 *bssid,
4152 u8 *addr)
4153{
4154 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4155 struct sta_info *sta;
John W. Linville91fa5582007-05-15 16:14:40 -04004156 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Joe Perches0795af52007-10-03 17:59:30 -07004157 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07004158
4159 /* TODO: Could consider removing the least recently used entry and
4160 * allow new one to be added. */
4161 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
4162 if (net_ratelimit()) {
4163 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
Joe Perches0795af52007-10-03 17:59:30 -07004164 "entry %s\n", dev->name, print_mac(mac, addr));
Jiri Bencf0706e822007-05-05 11:45:53 -07004165 }
4166 return NULL;
4167 }
4168
Joe Perches0795af52007-10-03 17:59:30 -07004169 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04004170 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
Jiri Bencf0706e822007-05-05 11:45:53 -07004171
Johannes Berg73651ee2008-02-25 16:27:47 +01004172 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
4173 if (!sta)
Jiri Bencf0706e822007-05-05 11:45:53 -07004174 return NULL;
4175
Johannes Berg238814f2008-01-28 17:19:37 +01004176 sta->flags |= WLAN_STA_AUTHORIZED;
4177
Johannes Berg8318d782008-01-24 19:38:38 +01004178 sta->supp_rates[local->hw.conf.channel->band] =
4179 sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
Jiri Bencf0706e822007-05-05 11:45:53 -07004180
4181 rate_control_rate_init(sta, local);
4182
Johannes Berg93e5deb2008-04-01 15:21:00 +02004183 if (sta_info_insert(sta))
Johannes Berg73651ee2008-02-25 16:27:47 +01004184 return NULL;
Johannes Berg73651ee2008-02-25 16:27:47 +01004185
Johannes Bergd0709a62008-02-25 16:27:46 +01004186 return sta;
Jiri Bencf0706e822007-05-05 11:45:53 -07004187}
4188
4189
4190int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
4191{
4192 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4193 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4194
4195 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
4196 dev->name, reason);
4197
Johannes Berg51fb61e2007-12-19 01:31:27 +01004198 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4199 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e822007-05-05 11:45:53 -07004200 return -EINVAL;
4201
4202 ieee80211_send_deauth(dev, ifsta, reason);
4203 ieee80211_set_disassoc(dev, ifsta, 1);
4204 return 0;
4205}
4206
4207
4208int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
4209{
4210 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4211 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4212
4213 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
4214 dev->name, reason);
4215
Johannes Berg51fb61e2007-12-19 01:31:27 +01004216 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07004217 return -EINVAL;
4218
Jiri Slabyd6f2da52007-08-28 17:01:54 -04004219 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e822007-05-05 11:45:53 -07004220 return -1;
4221
4222 ieee80211_send_disassoc(dev, ifsta, reason);
4223 ieee80211_set_disassoc(dev, ifsta, 0);
4224 return 0;
4225}