blob: 7b4d4d46843b4eebaa9bd98af6a8f363d88620bf [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14/* TODO:
Jiri Bencf0706e82007-05-05 11:45:53 -070015 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
17 * SSID)
18 */
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070019#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070020#include <linux/if_ether.h>
21#include <linux/skbuff.h>
22#include <linux/netdevice.h>
23#include <linux/if_arp.h>
24#include <linux/wireless.h>
25#include <linux/random.h>
26#include <linux/etherdevice.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010027#include <linux/rtnetlink.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070028#include <net/iw_handler.h>
29#include <asm/types.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070030
31#include <net/mac80211.h>
32#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040033#include "rate.h"
34#include "led.h"
Luis Carlos Cobof709fc62008-02-23 15:17:12 +010035#include "mesh.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070036
37#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
38#define IEEE80211_AUTH_MAX_TRIES 3
39#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
40#define IEEE80211_ASSOC_MAX_TRIES 3
41#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +010042#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070043#define IEEE80211_PROBE_INTERVAL (60 * HZ)
44#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
45#define IEEE80211_SCAN_INTERVAL (2 * HZ)
46#define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
Dan Williams872ba532008-06-04 13:59:34 -040047#define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070048
49#define IEEE80211_PROBE_DELAY (HZ / 33)
50#define IEEE80211_CHANNEL_TIME (HZ / 33)
51#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
52#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
53#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
54#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +010055#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070056
57#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
58
59
Jiri Bencf0706e82007-05-05 11:45:53 -070060#define ERP_INFO_USE_PROTECTION BIT(1)
61
Ron Rindjunsky9f985b02007-11-26 16:14:32 +020062/* mgmt header + 1 byte action code */
63#define IEEE80211_MIN_ACTION_SIZE (24 + 1)
64
65#define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
66#define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
67#define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
Ron Rindjunsky688b88a2007-12-25 17:00:37 +020068#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
69#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
Ron Rindjunsky9f985b02007-11-26 16:14:32 +020070
Ron Rindjunsky07db2182007-12-25 17:00:33 +020071/* next values represent the buffer size for A-MPDU frame.
72 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
73#define IEEE80211_MIN_AMPDU_BUF 0x8
74#define IEEE80211_MAX_AMPDU_BUF 0x40
75
Jiri Bencf0706e82007-05-05 11:45:53 -070076static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
77 u8 *ssid, size_t ssid_len);
78static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +010079ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -040080 u8 *ssid, u8 ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -070081static void ieee80211_rx_bss_put(struct net_device *dev,
82 struct ieee80211_sta_bss *bss);
83static int ieee80211_sta_find_ibss(struct net_device *dev,
84 struct ieee80211_if_sta *ifsta);
85static int ieee80211_sta_wep_configured(struct net_device *dev);
86static int ieee80211_sta_start_scan(struct net_device *dev,
87 u8 *ssid, size_t ssid_len);
88static int ieee80211_sta_config_auth(struct net_device *dev,
89 struct ieee80211_if_sta *ifsta);
Adrian Bunk712590d2008-04-21 11:47:51 +030090static void sta_rx_agg_session_timer_expired(unsigned long data);
Jiri Bencf0706e82007-05-05 11:45:53 -070091
92
Luis Carlos Coboee385852008-02-23 15:17:11 +010093void ieee802_11_parse_elems(u8 *start, size_t len,
94 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -070095{
96 size_t left = len;
97 u8 *pos = start;
Jiri Bencf0706e82007-05-05 11:45:53 -070098
99 memset(elems, 0, sizeof(*elems));
100
101 while (left >= 2) {
102 u8 id, elen;
103
104 id = *pos++;
105 elen = *pos++;
106 left -= 2;
107
John W. Linville67a4cce2007-10-12 16:40:37 -0400108 if (elen > left)
109 return;
Jiri Bencf0706e82007-05-05 11:45:53 -0700110
111 switch (id) {
112 case WLAN_EID_SSID:
113 elems->ssid = pos;
114 elems->ssid_len = elen;
115 break;
116 case WLAN_EID_SUPP_RATES:
117 elems->supp_rates = pos;
118 elems->supp_rates_len = elen;
119 break;
120 case WLAN_EID_FH_PARAMS:
121 elems->fh_params = pos;
122 elems->fh_params_len = elen;
123 break;
124 case WLAN_EID_DS_PARAMS:
125 elems->ds_params = pos;
126 elems->ds_params_len = elen;
127 break;
128 case WLAN_EID_CF_PARAMS:
129 elems->cf_params = pos;
130 elems->cf_params_len = elen;
131 break;
132 case WLAN_EID_TIM:
133 elems->tim = pos;
134 elems->tim_len = elen;
135 break;
136 case WLAN_EID_IBSS_PARAMS:
137 elems->ibss_params = pos;
138 elems->ibss_params_len = elen;
139 break;
140 case WLAN_EID_CHALLENGE:
141 elems->challenge = pos;
142 elems->challenge_len = elen;
143 break;
144 case WLAN_EID_WPA:
145 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
146 pos[2] == 0xf2) {
147 /* Microsoft OUI (00:50:F2) */
148 if (pos[3] == 1) {
149 /* OUI Type 1 - WPA IE */
150 elems->wpa = pos;
151 elems->wpa_len = elen;
152 } else if (elen >= 5 && pos[3] == 2) {
153 if (pos[4] == 0) {
154 elems->wmm_info = pos;
155 elems->wmm_info_len = elen;
156 } else if (pos[4] == 1) {
157 elems->wmm_param = pos;
158 elems->wmm_param_len = elen;
159 }
160 }
161 }
162 break;
163 case WLAN_EID_RSN:
164 elems->rsn = pos;
165 elems->rsn_len = elen;
166 break;
167 case WLAN_EID_ERP_INFO:
168 elems->erp_info = pos;
169 elems->erp_info_len = elen;
170 break;
171 case WLAN_EID_EXT_SUPP_RATES:
172 elems->ext_supp_rates = pos;
173 elems->ext_supp_rates_len = elen;
174 break;
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200175 case WLAN_EID_HT_CAPABILITY:
176 elems->ht_cap_elem = pos;
177 elems->ht_cap_elem_len = elen;
178 break;
179 case WLAN_EID_HT_EXTRA_INFO:
180 elems->ht_info_elem = pos;
181 elems->ht_info_elem_len = elen;
182 break;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100183 case WLAN_EID_MESH_ID:
184 elems->mesh_id = pos;
185 elems->mesh_id_len = elen;
186 break;
187 case WLAN_EID_MESH_CONFIG:
188 elems->mesh_config = pos;
189 elems->mesh_config_len = elen;
190 break;
191 case WLAN_EID_PEER_LINK:
192 elems->peer_link = pos;
193 elems->peer_link_len = elen;
194 break;
195 case WLAN_EID_PREQ:
196 elems->preq = pos;
197 elems->preq_len = elen;
198 break;
199 case WLAN_EID_PREP:
200 elems->prep = pos;
201 elems->prep_len = elen;
202 break;
203 case WLAN_EID_PERR:
204 elems->perr = pos;
205 elems->perr_len = elen;
206 break;
Assaf Kraussf2df3852008-06-15 18:23:29 +0300207 case WLAN_EID_CHANNEL_SWITCH:
208 elems->ch_switch_elem = pos;
209 elems->ch_switch_elem_len = elen;
210 break;
211 case WLAN_EID_QUIET:
212 if (!elems->quiet_elem) {
213 elems->quiet_elem = pos;
214 elems->quiet_elem_len = elen;
215 }
216 elems->num_of_quiet_elem++;
217 break;
218 case WLAN_EID_COUNTRY:
219 elems->country_elem = pos;
220 elems->country_elem_len = elen;
221 break;
222 case WLAN_EID_PWR_CONSTRAINT:
223 elems->pwr_constr_elem = pos;
224 elems->pwr_constr_elem_len = elen;
225 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700226 default:
Jiri Bencf0706e82007-05-05 11:45:53 -0700227 break;
228 }
229
230 left -= elen;
231 pos += elen;
232 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700233}
234
235
Jiri Bencf0706e82007-05-05 11:45:53 -0700236static int ecw2cw(int ecw)
237{
Johannes Bergac2bf322008-02-14 00:30:35 +0100238 return (1 << ecw) - 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700239}
240
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100241
242static void ieee80211_sta_def_wmm_params(struct net_device *dev,
243 struct ieee80211_sta_bss *bss,
244 int ibss)
245{
246 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
247 struct ieee80211_local *local = sdata->local;
248 int i, have_higher_than_11mbit = 0;
249
250
251 /* cf. IEEE 802.11 9.2.12 */
252 for (i = 0; i < bss->supp_rates_len; i++)
253 if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
254 have_higher_than_11mbit = 1;
255
256 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
257 have_higher_than_11mbit)
258 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
259 else
260 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
261
262
263 if (local->ops->conf_tx) {
264 struct ieee80211_tx_queue_params qparam;
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100265
266 memset(&qparam, 0, sizeof(qparam));
267
268 qparam.aifs = 2;
269
270 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
271 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
272 qparam.cw_min = 31;
273 else
274 qparam.cw_min = 15;
275
276 qparam.cw_max = 1023;
277 qparam.txop = 0;
278
Johannes Berge100bb62008-04-30 18:51:21 +0200279 for (i = 0; i < local_to_hw(local)->queues; i++)
280 local->ops->conf_tx(local_to_hw(local), i, &qparam);
Vladimir Koutnye2839d82008-03-18 21:14:07 +0100281 }
282}
283
Jiri Bencf0706e82007-05-05 11:45:53 -0700284static void ieee80211_sta_wmm_params(struct net_device *dev,
285 struct ieee80211_if_sta *ifsta,
286 u8 *wmm_param, size_t wmm_param_len)
287{
288 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
289 struct ieee80211_tx_queue_params params;
290 size_t left;
291 int count;
292 u8 *pos;
293
Johannes Berg3434fbd2008-05-03 00:59:37 +0200294 if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED))
295 return;
296
297 if (!wmm_param)
298 return;
299
Jiri Bencf0706e82007-05-05 11:45:53 -0700300 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
301 return;
302 count = wmm_param[6] & 0x0f;
303 if (count == ifsta->wmm_last_param_set)
304 return;
305 ifsta->wmm_last_param_set = count;
306
307 pos = wmm_param + 8;
308 left = wmm_param_len - 8;
309
310 memset(&params, 0, sizeof(params));
311
312 if (!local->ops->conf_tx)
313 return;
314
315 local->wmm_acm = 0;
316 for (; left >= 4; left -= 4, pos += 4) {
317 int aci = (pos[0] >> 5) & 0x03;
318 int acm = (pos[0] >> 4) & 0x01;
319 int queue;
320
321 switch (aci) {
322 case 1:
Johannes Berge100bb62008-04-30 18:51:21 +0200323 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200324 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700325 local->wmm_acm |= BIT(0) | BIT(3);
Jiri Bencf0706e82007-05-05 11:45:53 -0700326 break;
327 case 2:
Johannes Berge100bb62008-04-30 18:51:21 +0200328 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200329 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700330 local->wmm_acm |= BIT(4) | BIT(5);
Jiri Bencf0706e82007-05-05 11:45:53 -0700331 break;
332 case 3:
Johannes Berge100bb62008-04-30 18:51:21 +0200333 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200334 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700335 local->wmm_acm |= BIT(6) | BIT(7);
Jiri Bencf0706e82007-05-05 11:45:53 -0700336 break;
337 case 0:
338 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200339 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200340 if (acm)
Jiri Bencf0706e82007-05-05 11:45:53 -0700341 local->wmm_acm |= BIT(1) | BIT(2);
Jiri Bencf0706e82007-05-05 11:45:53 -0700342 break;
343 }
344
345 params.aifs = pos[0] & 0x0f;
346 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
347 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100348 params.txop = pos[2] | (pos[3] << 8);
349#ifdef CONFIG_MAC80211_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700350 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100351 "cWmin=%d cWmax=%d txop=%d\n",
Jiri Bencf0706e82007-05-05 11:45:53 -0700352 dev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100353 params.cw_max, params.txop);
354#endif
Jiri Bencf0706e82007-05-05 11:45:53 -0700355 /* TODO: handle ACM (block TX, fallback to next lowest allowed
356 * AC for now) */
357 if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
358 printk(KERN_DEBUG "%s: failed to set TX queue "
359 "parameters for queue %d\n", dev->name, queue);
360 }
361 }
362}
363
John W. Linville50c4afb2008-04-15 14:09:27 -0400364static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata,
365 bool use_protection,
366 bool use_short_preamble)
Daniel Drake56282212007-07-10 19:32:10 +0200367{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100368 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
Daniel Drake56282212007-07-10 19:32:10 +0200369 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Joe Perches0795af52007-10-03 17:59:30 -0700370 DECLARE_MAC_BUF(mac);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100371 u32 changed = 0;
Daniel Drake56282212007-07-10 19:32:10 +0200372
Johannes Berg471b3ef2007-12-28 14:32:58 +0100373 if (use_protection != bss_conf->use_cts_prot) {
Daniel Drake56282212007-07-10 19:32:10 +0200374 if (net_ratelimit()) {
375 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
Joe Perches0795af52007-10-03 17:59:30 -0700376 "%s)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100377 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200378 use_protection ? "enabled" : "disabled",
Joe Perches0795af52007-10-03 17:59:30 -0700379 print_mac(mac, ifsta->bssid));
Daniel Drake56282212007-07-10 19:32:10 +0200380 }
Johannes Berg471b3ef2007-12-28 14:32:58 +0100381 bss_conf->use_cts_prot = use_protection;
382 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200383 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200384
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200385 if (use_short_preamble != bss_conf->use_short_preamble) {
Daniel Drake7e9ed182007-07-27 15:43:24 +0200386 if (net_ratelimit()) {
387 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Joe Perches0795af52007-10-03 17:59:30 -0700388 " (BSSID=%s)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100389 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200390 use_short_preamble ? "short" : "long",
Joe Perches0795af52007-10-03 17:59:30 -0700391 print_mac(mac, ifsta->bssid));
Daniel Drake7e9ed182007-07-27 15:43:24 +0200392 }
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200393 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100394 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200395 }
Daniel Draked9430a32007-07-27 15:43:24 +0200396
Johannes Berg471b3ef2007-12-28 14:32:58 +0100397 return changed;
Daniel Drake56282212007-07-10 19:32:10 +0200398}
399
John W. Linville50c4afb2008-04-15 14:09:27 -0400400static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
401 u8 erp_value)
402{
403 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
404 bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0;
405
406 return ieee80211_handle_protect_preamb(sdata,
407 use_protection, use_short_preamble);
408}
409
410static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
411 struct ieee80211_sta_bss *bss)
412{
413 u32 changed = 0;
414
415 if (bss->has_erp_value)
416 changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value);
417 else {
418 u16 capab = bss->capability;
419 changed |= ieee80211_handle_protect_preamb(sdata, false,
420 (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
421 }
422
423 return changed;
424}
425
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200426int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
427 struct ieee80211_ht_info *ht_info)
428{
429
430 if (ht_info == NULL)
431 return -EINVAL;
432
433 memset(ht_info, 0, sizeof(*ht_info));
434
435 if (ht_cap_ie) {
436 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
437
438 ht_info->ht_supported = 1;
439 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
440 ht_info->ampdu_factor =
441 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
442 ht_info->ampdu_density =
443 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
444 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
445 } else
446 ht_info->ht_supported = 0;
447
448 return 0;
449}
450
451int ieee80211_ht_addt_info_ie_to_ht_bss_info(
452 struct ieee80211_ht_addt_info *ht_add_info_ie,
453 struct ieee80211_ht_bss_info *bss_info)
454{
455 if (bss_info == NULL)
456 return -EINVAL;
457
458 memset(bss_info, 0, sizeof(*bss_info));
459
460 if (ht_add_info_ie) {
461 u16 op_mode;
462 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
463
464 bss_info->primary_channel = ht_add_info_ie->control_chan;
465 bss_info->bss_cap = ht_add_info_ie->ht_param;
466 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
467 }
468
469 return 0;
470}
Daniel Drake56282212007-07-10 19:32:10 +0200471
Jiri Bencf0706e82007-05-05 11:45:53 -0700472static void ieee80211_sta_send_associnfo(struct net_device *dev,
473 struct ieee80211_if_sta *ifsta)
474{
475 char *buf;
476 size_t len;
477 int i;
478 union iwreq_data wrqu;
479
480 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
481 return;
482
483 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
Michael Wu0ec0b7a2007-07-27 15:43:24 +0200484 ifsta->assocresp_ies_len), GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700485 if (!buf)
486 return;
487
488 len = sprintf(buf, "ASSOCINFO(");
489 if (ifsta->assocreq_ies) {
490 len += sprintf(buf + len, "ReqIEs=");
491 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
492 len += sprintf(buf + len, "%02x",
493 ifsta->assocreq_ies[i]);
494 }
495 }
496 if (ifsta->assocresp_ies) {
497 if (ifsta->assocreq_ies)
498 len += sprintf(buf + len, " ");
499 len += sprintf(buf + len, "RespIEs=");
500 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
501 len += sprintf(buf + len, "%02x",
502 ifsta->assocresp_ies[i]);
503 }
504 }
505 len += sprintf(buf + len, ")");
506
507 if (len > IW_CUSTOM_MAX) {
508 len = sprintf(buf, "ASSOCRESPIE=");
509 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
510 len += sprintf(buf + len, "%02x",
511 ifsta->assocresp_ies[i]);
512 }
513 }
514
515 memset(&wrqu, 0, sizeof(wrqu));
516 wrqu.data.length = len;
517 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
518
519 kfree(buf);
520}
521
522
523static void ieee80211_set_associated(struct net_device *dev,
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400524 struct ieee80211_if_sta *ifsta,
Michael Buesch47f0c502007-09-27 15:10:44 +0200525 bool assoc)
Jiri Bencf0706e82007-05-05 11:45:53 -0700526{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100527 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
528 struct ieee80211_local *local = sdata->local;
Tomas Winkler38668c02008-03-28 16:33:32 -0700529 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
Jiri Bencf0706e82007-05-05 11:45:53 -0700530 union iwreq_data wrqu;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100531 u32 changed = BSS_CHANGED_ASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -0700532
Jiri Bencf0706e82007-05-05 11:45:53 -0700533 if (assoc) {
Daniel Drake56282212007-07-10 19:32:10 +0200534 struct ieee80211_sta_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400535
536 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
537
Johannes Berg51fb61e2007-12-19 01:31:27 +0100538 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700539 return;
Daniel Drake56282212007-07-10 19:32:10 +0200540
John W. Linville65c107a2007-10-05 14:23:27 -0400541 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
Tomas Winkler38668c02008-03-28 16:33:32 -0700542 conf->channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400543 ifsta->ssid, ifsta->ssid_len);
Daniel Drake56282212007-07-10 19:32:10 +0200544 if (bss) {
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700545 /* set timing information */
546 sdata->bss_conf.beacon_int = bss->beacon_int;
547 sdata->bss_conf.timestamp = bss->timestamp;
548
John W. Linville50c4afb2008-04-15 14:09:27 -0400549 changed |= ieee80211_handle_bss_capability(sdata, bss);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700550
Daniel Drake56282212007-07-10 19:32:10 +0200551 ieee80211_rx_bss_put(dev, bss);
552 }
553
Tomas Winkler38668c02008-03-28 16:33:32 -0700554 if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
555 changed |= BSS_CHANGED_HT;
556 sdata->bss_conf.assoc_ht = 1;
557 sdata->bss_conf.ht_conf = &conf->ht_conf;
558 sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf;
559 }
560
Jiri Bencf0706e82007-05-05 11:45:53 -0700561 netif_carrier_on(dev);
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400562 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -0700563 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
564 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
565 ieee80211_sta_send_associnfo(dev, ifsta);
566 } else {
Ron Rindjunsky85249e52008-03-18 15:00:32 -0700567 ieee80211_sta_tear_down_BA_sessions(dev, ifsta->bssid);
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400568 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700569 netif_carrier_off(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200570 ieee80211_reset_erp_info(dev);
Tomas Winkler38668c02008-03-28 16:33:32 -0700571
572 sdata->bss_conf.assoc_ht = 0;
573 sdata->bss_conf.ht_conf = NULL;
574 sdata->bss_conf.ht_bss_conf = NULL;
575
Jiri Bencf0706e82007-05-05 11:45:53 -0700576 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
577 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700578 ifsta->last_probe = jiffies;
Michael Buesch47f0c502007-09-27 15:10:44 +0200579 ieee80211_led_assoc(local, assoc);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100580
Tomas Winklerb2205252008-01-27 16:18:22 +0200581 sdata->bss_conf.assoc = assoc;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100582 ieee80211_bss_info_change_notify(sdata, changed);
Reinette Chatre41a7be42008-04-03 16:08:49 -0700583 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
584 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700585}
586
587static void ieee80211_set_disassoc(struct net_device *dev,
588 struct ieee80211_if_sta *ifsta, int deauth)
589{
590 if (deauth)
591 ifsta->auth_tries = 0;
592 ifsta->assoc_tries = 0;
593 ieee80211_set_associated(dev, ifsta, 0);
594}
595
Luis Carlos Coboee385852008-02-23 15:17:11 +0100596void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
597 int encrypt)
Jiri Bencf0706e82007-05-05 11:45:53 -0700598{
599 struct ieee80211_sub_if_data *sdata;
Johannes Berge039fa42008-05-15 12:55:29 +0200600 struct ieee80211_tx_info *info;
Jiri Bencf0706e82007-05-05 11:45:53 -0700601
602 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
603 skb->dev = sdata->local->mdev;
604 skb_set_mac_header(skb, 0);
605 skb_set_network_header(skb, 0);
606 skb_set_transport_header(skb, 0);
607
Johannes Berge039fa42008-05-15 12:55:29 +0200608 info = IEEE80211_SKB_CB(skb);
609 memset(info, 0, sizeof(struct ieee80211_tx_info));
610 info->control.ifindex = sdata->dev->ifindex;
Jiri Slabye8bf9642007-08-28 17:01:54 -0400611 if (!encrypt)
Johannes Berge039fa42008-05-15 12:55:29 +0200612 info->flags |= IEEE80211_TX_CTL_DO_NOT_ENCRYPT;
Jiri Bencf0706e82007-05-05 11:45:53 -0700613
614 dev_queue_xmit(skb);
615}
616
617
618static void ieee80211_send_auth(struct net_device *dev,
619 struct ieee80211_if_sta *ifsta,
620 int transaction, u8 *extra, size_t extra_len,
621 int encrypt)
622{
623 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
624 struct sk_buff *skb;
625 struct ieee80211_mgmt *mgmt;
626
627 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
628 sizeof(*mgmt) + 6 + extra_len);
629 if (!skb) {
630 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
631 "frame\n", dev->name);
632 return;
633 }
634 skb_reserve(skb, local->hw.extra_tx_headroom);
635
636 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
637 memset(mgmt, 0, 24 + 6);
638 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
639 IEEE80211_STYPE_AUTH);
640 if (encrypt)
641 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
642 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
643 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
644 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
645 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
646 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
647 ifsta->auth_transaction = transaction + 1;
648 mgmt->u.auth.status_code = cpu_to_le16(0);
649 if (extra)
650 memcpy(skb_put(skb, extra_len), extra, extra_len);
651
652 ieee80211_sta_tx(dev, skb, encrypt);
653}
654
655
656static void ieee80211_authenticate(struct net_device *dev,
657 struct ieee80211_if_sta *ifsta)
658{
Joe Perches0795af52007-10-03 17:59:30 -0700659 DECLARE_MAC_BUF(mac);
660
Jiri Bencf0706e82007-05-05 11:45:53 -0700661 ifsta->auth_tries++;
662 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Joe Perches0795af52007-10-03 17:59:30 -0700663 printk(KERN_DEBUG "%s: authentication with AP %s"
Jiri Bencf0706e82007-05-05 11:45:53 -0700664 " timed out\n",
Joe Perches0795af52007-10-03 17:59:30 -0700665 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -0700666 ifsta->state = IEEE80211_DISABLED;
667 return;
668 }
669
670 ifsta->state = IEEE80211_AUTHENTICATE;
Joe Perches0795af52007-10-03 17:59:30 -0700671 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
672 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -0700673
674 ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
675
676 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
677}
678
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200679static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss,
680 struct ieee80211_supported_band *sband,
681 u64 *rates)
682{
683 int i, j, count;
684 *rates = 0;
685 count = 0;
686 for (i = 0; i < bss->supp_rates_len; i++) {
687 int rate = (bss->supp_rates[i] & 0x7F) * 5;
688
689 for (j = 0; j < sband->n_bitrates; j++)
690 if (sband->bitrates[j].bitrate == rate) {
691 *rates |= BIT(j);
692 count++;
693 break;
694 }
695 }
696
697 return count;
698}
Jiri Bencf0706e82007-05-05 11:45:53 -0700699
700static void ieee80211_send_assoc(struct net_device *dev,
701 struct ieee80211_if_sta *ifsta)
702{
703 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e82007-05-05 11:45:53 -0700704 struct sk_buff *skb;
705 struct ieee80211_mgmt *mgmt;
706 u8 *pos, *ies;
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200707 int i, len, count, rates_len, supp_rates_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700708 u16 capab;
709 struct ieee80211_sta_bss *bss;
710 int wmm = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100711 struct ieee80211_supported_band *sband;
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200712 u64 rates = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700713
714 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
715 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
716 ifsta->ssid_len);
717 if (!skb) {
718 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
719 "frame\n", dev->name);
720 return;
721 }
722 skb_reserve(skb, local->hw.extra_tx_headroom);
723
Johannes Berg8318d782008-01-24 19:38:38 +0100724 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
725
Jiri Bencf0706e82007-05-05 11:45:53 -0700726 capab = ifsta->capab;
Johannes Berg8318d782008-01-24 19:38:38 +0100727
728 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
729 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
730 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
731 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
732 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Jiri Bencf0706e82007-05-05 11:45:53 -0700733 }
Johannes Berg8318d782008-01-24 19:38:38 +0100734
735 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
736 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400737 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700738 if (bss) {
739 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
740 capab |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg988c0f72008-04-17 19:21:22 +0200741 if (bss->wmm_ie)
Jiri Bencf0706e82007-05-05 11:45:53 -0700742 wmm = 1;
Helmut Schaa0d580a72008-05-20 09:56:37 +0200743
744 /* get all rates supported by the device and the AP as
745 * some APs don't like getting a superset of their rates
746 * in the association request (e.g. D-Link DAP 1353 in
747 * b-only mode) */
748 rates_len = ieee80211_compatible_rates(bss, sband, &rates);
749
Jiri Bencf0706e82007-05-05 11:45:53 -0700750 ieee80211_rx_bss_put(dev, bss);
Helmut Schaa0d580a72008-05-20 09:56:37 +0200751 } else {
752 rates = ~0;
753 rates_len = sband->n_bitrates;
Jiri Bencf0706e82007-05-05 11:45:53 -0700754 }
755
756 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
757 memset(mgmt, 0, 24);
758 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
759 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
760 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
761
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400762 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700763 skb_put(skb, 10);
764 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
765 IEEE80211_STYPE_REASSOC_REQ);
766 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
767 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
768 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
769 ETH_ALEN);
770 } else {
771 skb_put(skb, 4);
772 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
773 IEEE80211_STYPE_ASSOC_REQ);
774 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
775 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
776 }
777
778 /* SSID */
779 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
780 *pos++ = WLAN_EID_SSID;
781 *pos++ = ifsta->ssid_len;
782 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
783
Helmut Schaa0d580a72008-05-20 09:56:37 +0200784 /* add all rates which were marked to be used above */
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200785 supp_rates_len = rates_len;
786 if (supp_rates_len > 8)
787 supp_rates_len = 8;
Jiri Bencf0706e82007-05-05 11:45:53 -0700788
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200789 len = sband->n_bitrates;
790 pos = skb_put(skb, supp_rates_len + 2);
791 *pos++ = WLAN_EID_SUPP_RATES;
792 *pos++ = supp_rates_len;
793
794 count = 0;
795 for (i = 0; i < sband->n_bitrates; i++) {
796 if (BIT(i) & rates) {
Johannes Berg8318d782008-01-24 19:38:38 +0100797 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e82007-05-05 11:45:53 -0700798 *pos++ = (u8) (rate / 5);
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200799 if (++count == 8)
800 break;
801 }
802 }
803
804 if (count == 8) {
805 pos = skb_put(skb, rates_len - count + 2);
806 *pos++ = WLAN_EID_EXT_SUPP_RATES;
807 *pos++ = rates_len - count;
808
809 for (i++; i < sband->n_bitrates; i++) {
810 if (BIT(i) & rates) {
811 int rate = sband->bitrates[i].bitrate;
812 *pos++ = (u8) (rate / 5);
813 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700814 }
815 }
816
817 if (ifsta->extra_ie) {
818 pos = skb_put(skb, ifsta->extra_ie_len);
819 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
820 }
821
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400822 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700823 pos = skb_put(skb, 9);
824 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
825 *pos++ = 7; /* len */
826 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
827 *pos++ = 0x50;
828 *pos++ = 0xf2;
829 *pos++ = 2; /* WME */
830 *pos++ = 0; /* WME info */
831 *pos++ = 1; /* WME ver */
832 *pos++ = 0;
833 }
Johannes Berg3434fbd2008-05-03 00:59:37 +0200834
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200835 /* wmm support is a must to HT */
Johannes Berg3434fbd2008-05-03 00:59:37 +0200836 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) &&
Emmanuel Grumbach93061022008-05-29 16:35:23 +0800837 sband->ht_info.ht_supported && bss->ht_add_ie) {
838 struct ieee80211_ht_addt_info *ht_add_info =
839 (struct ieee80211_ht_addt_info *)bss->ht_add_ie;
840 u16 cap = sband->ht_info.cap;
841 __le16 tmp;
842 u32 flags = local->hw.conf.channel->flags;
843
844 switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) {
845 case IEEE80211_HT_IE_CHA_SEC_ABOVE:
846 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
847 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
848 cap &= ~IEEE80211_HT_CAP_SGI_40;
849 }
850 break;
851 case IEEE80211_HT_IE_CHA_SEC_BELOW:
852 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
853 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
854 cap &= ~IEEE80211_HT_CAP_SGI_40;
855 }
856 break;
857 }
858
859 tmp = cpu_to_le16(cap);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200860 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
861 *pos++ = WLAN_EID_HT_CAPABILITY;
862 *pos++ = sizeof(struct ieee80211_ht_cap);
863 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
864 memcpy(pos, &tmp, sizeof(u16));
865 pos += sizeof(u16);
Johannes Berg8318d782008-01-24 19:38:38 +0100866 /* TODO: needs a define here for << 2 */
867 *pos++ = sband->ht_info.ampdu_factor |
868 (sband->ht_info.ampdu_density << 2);
869 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200870 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700871
872 kfree(ifsta->assocreq_ies);
873 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
Michael Wu0ec0b7a2007-07-27 15:43:24 +0200874 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700875 if (ifsta->assocreq_ies)
876 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
877
878 ieee80211_sta_tx(dev, skb, 0);
879}
880
881
882static void ieee80211_send_deauth(struct net_device *dev,
883 struct ieee80211_if_sta *ifsta, u16 reason)
884{
885 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
886 struct sk_buff *skb;
887 struct ieee80211_mgmt *mgmt;
888
889 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
890 if (!skb) {
891 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
892 "frame\n", dev->name);
893 return;
894 }
895 skb_reserve(skb, local->hw.extra_tx_headroom);
896
897 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
898 memset(mgmt, 0, 24);
899 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
900 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
901 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
902 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
903 IEEE80211_STYPE_DEAUTH);
904 skb_put(skb, 2);
905 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
906
907 ieee80211_sta_tx(dev, skb, 0);
908}
909
910
911static void ieee80211_send_disassoc(struct net_device *dev,
912 struct ieee80211_if_sta *ifsta, u16 reason)
913{
914 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
915 struct sk_buff *skb;
916 struct ieee80211_mgmt *mgmt;
917
918 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
919 if (!skb) {
920 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
921 "frame\n", dev->name);
922 return;
923 }
924 skb_reserve(skb, local->hw.extra_tx_headroom);
925
926 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
927 memset(mgmt, 0, 24);
928 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
929 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
930 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
931 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
932 IEEE80211_STYPE_DISASSOC);
933 skb_put(skb, 2);
934 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
935
936 ieee80211_sta_tx(dev, skb, 0);
937}
938
939
940static int ieee80211_privacy_mismatch(struct net_device *dev,
941 struct ieee80211_if_sta *ifsta)
942{
John W. Linville65c107a2007-10-05 14:23:27 -0400943 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e82007-05-05 11:45:53 -0700944 struct ieee80211_sta_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000945 int bss_privacy;
946 int wep_privacy;
947 int privacy_invoked;
Jiri Bencf0706e82007-05-05 11:45:53 -0700948
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000949 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
Jiri Bencf0706e82007-05-05 11:45:53 -0700950 return 0;
951
Johannes Berg8318d782008-01-24 19:38:38 +0100952 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
953 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400954 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700955 if (!bss)
956 return 0;
957
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000958 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
959 wep_privacy = !!ieee80211_sta_wep_configured(dev);
960 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e82007-05-05 11:45:53 -0700961
962 ieee80211_rx_bss_put(dev, bss);
963
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000964 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
965 return 0;
966
967 return 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700968}
969
970
971static void ieee80211_associate(struct net_device *dev,
972 struct ieee80211_if_sta *ifsta)
973{
Joe Perches0795af52007-10-03 17:59:30 -0700974 DECLARE_MAC_BUF(mac);
975
Jiri Bencf0706e82007-05-05 11:45:53 -0700976 ifsta->assoc_tries++;
977 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Joe Perches0795af52007-10-03 17:59:30 -0700978 printk(KERN_DEBUG "%s: association with AP %s"
Jiri Bencf0706e82007-05-05 11:45:53 -0700979 " timed out\n",
Joe Perches0795af52007-10-03 17:59:30 -0700980 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -0700981 ifsta->state = IEEE80211_DISABLED;
982 return;
983 }
984
985 ifsta->state = IEEE80211_ASSOCIATE;
Joe Perches0795af52007-10-03 17:59:30 -0700986 printk(KERN_DEBUG "%s: associate with AP %s\n",
987 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -0700988 if (ieee80211_privacy_mismatch(dev, ifsta)) {
989 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
990 "mixed-cell disabled - abort association\n", dev->name);
991 ifsta->state = IEEE80211_DISABLED;
992 return;
993 }
994
995 ieee80211_send_assoc(dev, ifsta);
996
997 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
998}
999
1000
1001static void ieee80211_associated(struct net_device *dev,
1002 struct ieee80211_if_sta *ifsta)
1003{
1004 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1005 struct sta_info *sta;
1006 int disassoc;
Joe Perches0795af52007-10-03 17:59:30 -07001007 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001008
1009 /* TODO: start monitoring current AP signal quality and number of
1010 * missed beacons. Scan other channels every now and then and search
1011 * for better APs. */
1012 /* TODO: remove expired BSSes */
1013
1014 ifsta->state = IEEE80211_ASSOCIATED;
1015
Johannes Bergd0709a62008-02-25 16:27:46 +01001016 rcu_read_lock();
1017
Jiri Bencf0706e82007-05-05 11:45:53 -07001018 sta = sta_info_get(local, ifsta->bssid);
1019 if (!sta) {
Joe Perches0795af52007-10-03 17:59:30 -07001020 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
1021 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001022 disassoc = 1;
1023 } else {
1024 disassoc = 0;
1025 if (time_after(jiffies,
1026 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001027 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001028 printk(KERN_DEBUG "%s: No ProbeResp from "
Joe Perches0795af52007-10-03 17:59:30 -07001029 "current AP %s - assume out of "
Jiri Bencf0706e82007-05-05 11:45:53 -07001030 "range\n",
Joe Perches0795af52007-10-03 17:59:30 -07001031 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001032 disassoc = 1;
Johannes Bergd0709a62008-02-25 16:27:46 +01001033 sta_info_unlink(&sta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001034 } else
Jiri Bencf0706e82007-05-05 11:45:53 -07001035 ieee80211_send_probe_req(dev, ifsta->bssid,
1036 local->scan_ssid,
1037 local->scan_ssid_len);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001038 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001039 } else {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001040 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001041 if (time_after(jiffies, ifsta->last_probe +
1042 IEEE80211_PROBE_INTERVAL)) {
1043 ifsta->last_probe = jiffies;
1044 ieee80211_send_probe_req(dev, ifsta->bssid,
1045 ifsta->ssid,
1046 ifsta->ssid_len);
1047 }
1048 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001049 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001050
1051 rcu_read_unlock();
1052
Johannes Berg3b967662008-04-08 17:56:52 +02001053 if (disassoc && sta)
Johannes Bergd0709a62008-02-25 16:27:46 +01001054 sta_info_destroy(sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001055
Jiri Bencf0706e82007-05-05 11:45:53 -07001056 if (disassoc) {
Michael Wu2d192d92007-11-10 00:15:25 -05001057 ifsta->state = IEEE80211_DISABLED;
1058 ieee80211_set_associated(dev, ifsta, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07001059 } else {
1060 mod_timer(&ifsta->timer, jiffies +
1061 IEEE80211_MONITORING_INTERVAL);
1062 }
1063}
1064
1065
1066static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
1067 u8 *ssid, size_t ssid_len)
1068{
1069 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +01001070 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001071 struct sk_buff *skb;
1072 struct ieee80211_mgmt *mgmt;
1073 u8 *pos, *supp_rates, *esupp_rates = NULL;
1074 int i;
1075
1076 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
1077 if (!skb) {
1078 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
1079 "request\n", dev->name);
1080 return;
1081 }
1082 skb_reserve(skb, local->hw.extra_tx_headroom);
1083
1084 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1085 memset(mgmt, 0, 24);
1086 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1087 IEEE80211_STYPE_PROBE_REQ);
1088 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1089 if (dst) {
1090 memcpy(mgmt->da, dst, ETH_ALEN);
1091 memcpy(mgmt->bssid, dst, ETH_ALEN);
1092 } else {
1093 memset(mgmt->da, 0xff, ETH_ALEN);
1094 memset(mgmt->bssid, 0xff, ETH_ALEN);
1095 }
1096 pos = skb_put(skb, 2 + ssid_len);
1097 *pos++ = WLAN_EID_SSID;
1098 *pos++ = ssid_len;
1099 memcpy(pos, ssid, ssid_len);
1100
1101 supp_rates = skb_put(skb, 2);
1102 supp_rates[0] = WLAN_EID_SUPP_RATES;
1103 supp_rates[1] = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001104 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1105
1106 for (i = 0; i < sband->n_bitrates; i++) {
1107 struct ieee80211_rate *rate = &sband->bitrates[i];
Jiri Bencf0706e82007-05-05 11:45:53 -07001108 if (esupp_rates) {
1109 pos = skb_put(skb, 1);
1110 esupp_rates[1]++;
1111 } else if (supp_rates[1] == 8) {
1112 esupp_rates = skb_put(skb, 3);
1113 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
1114 esupp_rates[1] = 1;
1115 pos = &esupp_rates[2];
1116 } else {
1117 pos = skb_put(skb, 1);
1118 supp_rates[1]++;
1119 }
Johannes Berg8318d782008-01-24 19:38:38 +01001120 *pos = rate->bitrate / 5;
Jiri Bencf0706e82007-05-05 11:45:53 -07001121 }
1122
1123 ieee80211_sta_tx(dev, skb, 0);
1124}
1125
1126
1127static int ieee80211_sta_wep_configured(struct net_device *dev)
1128{
1129 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1130 if (!sdata || !sdata->default_key ||
Johannes Berg8f20fc22007-08-28 17:01:54 -04001131 sdata->default_key->conf.alg != ALG_WEP)
Jiri Bencf0706e82007-05-05 11:45:53 -07001132 return 0;
1133 return 1;
1134}
1135
1136
1137static void ieee80211_auth_completed(struct net_device *dev,
1138 struct ieee80211_if_sta *ifsta)
1139{
1140 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001141 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001142 ieee80211_associate(dev, ifsta);
1143}
1144
1145
1146static void ieee80211_auth_challenge(struct net_device *dev,
1147 struct ieee80211_if_sta *ifsta,
1148 struct ieee80211_mgmt *mgmt,
1149 size_t len)
1150{
1151 u8 *pos;
1152 struct ieee802_11_elems elems;
1153
1154 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
1155 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001156 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Jiri Bencf0706e82007-05-05 11:45:53 -07001157 if (!elems.challenge) {
1158 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
1159 "frame\n", dev->name);
1160 return;
1161 }
1162 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
1163 elems.challenge_len + 2, 1);
1164}
1165
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001166static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
1167 u8 dialog_token, u16 status, u16 policy,
1168 u16 buf_size, u16 timeout)
1169{
1170 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1171 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1172 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1173 struct sk_buff *skb;
1174 struct ieee80211_mgmt *mgmt;
1175 u16 capab;
1176
Ester Kummer3acea5b2008-04-17 16:05:14 -07001177 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
1178
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001179 if (!skb) {
1180 printk(KERN_DEBUG "%s: failed to allocate buffer "
1181 "for addba resp frame\n", dev->name);
1182 return;
1183 }
1184
1185 skb_reserve(skb, local->hw.extra_tx_headroom);
1186 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1187 memset(mgmt, 0, 24);
1188 memcpy(mgmt->da, da, ETH_ALEN);
1189 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001190 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001191 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1192 else
1193 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1194 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1195 IEEE80211_STYPE_ACTION);
1196
1197 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1198 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1199 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1200 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1201
1202 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1203 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1204 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1205
1206 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1207 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1208 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1209
1210 ieee80211_sta_tx(dev, skb, 0);
1211
1212 return;
1213}
1214
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001215void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1216 u16 tid, u8 dialog_token, u16 start_seq_num,
1217 u16 agg_size, u16 timeout)
1218{
1219 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1220 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1221 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1222 struct sk_buff *skb;
1223 struct ieee80211_mgmt *mgmt;
1224 u16 capab;
1225
Ester Kummer3acea5b2008-04-17 16:05:14 -07001226 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001227
1228 if (!skb) {
1229 printk(KERN_ERR "%s: failed to allocate buffer "
1230 "for addba request frame\n", dev->name);
1231 return;
1232 }
1233 skb_reserve(skb, local->hw.extra_tx_headroom);
1234 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1235 memset(mgmt, 0, 24);
1236 memcpy(mgmt->da, da, ETH_ALEN);
1237 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1238 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1239 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1240 else
1241 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1242
1243 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1244 IEEE80211_STYPE_ACTION);
1245
1246 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1247
1248 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1249 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1250
1251 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1252 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1253 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1254 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1255
1256 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1257
1258 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1259 mgmt->u.action.u.addba_req.start_seq_num =
1260 cpu_to_le16(start_seq_num << 4);
1261
1262 ieee80211_sta_tx(dev, skb, 0);
1263}
1264
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001265static void ieee80211_sta_process_addba_request(struct net_device *dev,
1266 struct ieee80211_mgmt *mgmt,
1267 size_t len)
1268{
1269 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001270 struct ieee80211_hw *hw = &local->hw;
1271 struct ieee80211_conf *conf = &hw->conf;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001272 struct sta_info *sta;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001273 struct tid_ampdu_rx *tid_agg_rx;
1274 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001275 u8 dialog_token;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001276 int ret = -EOPNOTSUPP;
1277 DECLARE_MAC_BUF(mac);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001278
Johannes Bergd0709a62008-02-25 16:27:46 +01001279 rcu_read_lock();
1280
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001281 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001282 if (!sta) {
1283 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001284 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001285 }
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001286
1287 /* extract session parameters from addba request frame */
1288 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1289 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001290 start_seq_num =
1291 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001292
1293 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1294 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1295 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1296 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1297
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001298 status = WLAN_STATUS_REQUEST_DECLINED;
1299
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001300 /* sanity check for incoming parameters:
1301 * check if configuration can support the BA policy
1302 * and if buffer size does not exceeds max value */
1303 if (((ba_policy != 1)
1304 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1305 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1306 status = WLAN_STATUS_INVALID_QOS_PARAM;
1307#ifdef CONFIG_MAC80211_HT_DEBUG
1308 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001309 printk(KERN_DEBUG "AddBA Req with bad params from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001310 "%s on tid %u. policy %d, buffer size %d\n",
1311 print_mac(mac, mgmt->sa), tid, ba_policy,
1312 buf_size);
1313#endif /* CONFIG_MAC80211_HT_DEBUG */
1314 goto end_no_lock;
1315 }
1316 /* determine default buffer size */
1317 if (buf_size == 0) {
Johannes Berg8318d782008-01-24 19:38:38 +01001318 struct ieee80211_supported_band *sband;
1319
1320 sband = local->hw.wiphy->bands[conf->channel->band];
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001321 buf_size = IEEE80211_MIN_AMPDU_BUF;
Johannes Berg8318d782008-01-24 19:38:38 +01001322 buf_size = buf_size << sband->ht_info.ampdu_factor;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001323 }
1324
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001325
1326 /* examine state machine */
Johannes Berg07346f812008-05-03 01:02:02 +02001327 spin_lock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001328
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001329 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001330#ifdef CONFIG_MAC80211_HT_DEBUG
1331 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001332 printk(KERN_DEBUG "unexpected AddBA Req from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001333 "%s on tid %u\n",
1334 print_mac(mac, mgmt->sa), tid);
1335#endif /* CONFIG_MAC80211_HT_DEBUG */
1336 goto end;
1337 }
1338
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001339 /* prepare A-MPDU MLME for Rx aggregation */
1340 sta->ampdu_mlme.tid_rx[tid] =
1341 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
1342 if (!sta->ampdu_mlme.tid_rx[tid]) {
1343 if (net_ratelimit())
1344 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
1345 tid);
1346 goto end;
1347 }
1348 /* rx timer */
1349 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
1350 sta_rx_agg_session_timer_expired;
1351 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
1352 (unsigned long)&sta->timer_to_tid[tid];
1353 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1354
1355 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
1356
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001357 /* prepare reordering buffer */
1358 tid_agg_rx->reorder_buf =
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301359 kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC);
Johannes Berg03147df2008-02-26 00:39:28 +01001360 if (!tid_agg_rx->reorder_buf) {
1361 if (net_ratelimit())
1362 printk(KERN_ERR "can not allocate reordering buffer "
1363 "to tid %d\n", tid);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001364 kfree(sta->ampdu_mlme.tid_rx[tid]);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001365 goto end;
1366 }
1367 memset(tid_agg_rx->reorder_buf, 0,
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301368 buf_size * sizeof(struct sk_buff *));
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001369
1370 if (local->ops->ampdu_action)
1371 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001372 sta->addr, tid, &start_seq_num);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001373#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001374 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001375#endif /* CONFIG_MAC80211_HT_DEBUG */
1376
1377 if (ret) {
1378 kfree(tid_agg_rx->reorder_buf);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001379 kfree(tid_agg_rx);
1380 sta->ampdu_mlme.tid_rx[tid] = NULL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001381 goto end;
1382 }
1383
1384 /* change state and send addba resp */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001385 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001386 tid_agg_rx->dialog_token = dialog_token;
1387 tid_agg_rx->ssn = start_seq_num;
1388 tid_agg_rx->head_seq_num = start_seq_num;
1389 tid_agg_rx->buf_size = buf_size;
1390 tid_agg_rx->timeout = timeout;
1391 tid_agg_rx->stored_mpdu_num = 0;
1392 status = WLAN_STATUS_SUCCESS;
1393end:
Johannes Berg07346f812008-05-03 01:02:02 +02001394 spin_unlock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001395
1396end_no_lock:
Johannes Bergd0709a62008-02-25 16:27:46 +01001397 ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
1398 dialog_token, status, 1, buf_size, timeout);
1399 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001400}
Jiri Bencf0706e82007-05-05 11:45:53 -07001401
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001402static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1403 struct ieee80211_mgmt *mgmt,
1404 size_t len)
1405{
1406 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1407 struct ieee80211_hw *hw = &local->hw;
1408 struct sta_info *sta;
1409 u16 capab;
1410 u16 tid;
1411 u8 *state;
1412
Johannes Bergd0709a62008-02-25 16:27:46 +01001413 rcu_read_lock();
1414
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001415 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001416 if (!sta) {
1417 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001418 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001419 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001420
1421 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1422 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1423
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001424 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001425
Johannes Berg07346f812008-05-03 01:02:02 +02001426 spin_lock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001427
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001428 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
Johannes Berg07346f812008-05-03 01:02:02 +02001429 spin_unlock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001430 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1431 "%d\n", *state);
1432 goto addba_resp_exit;
1433 }
1434
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001435 if (mgmt->u.action.u.addba_resp.dialog_token !=
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001436 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
Johannes Berg07346f812008-05-03 01:02:02 +02001437 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001438#ifdef CONFIG_MAC80211_HT_DEBUG
1439 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1440#endif /* CONFIG_MAC80211_HT_DEBUG */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001441 goto addba_resp_exit;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001442 }
1443
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001444 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001445#ifdef CONFIG_MAC80211_HT_DEBUG
1446 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1447#endif /* CONFIG_MAC80211_HT_DEBUG */
1448 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1449 == WLAN_STATUS_SUCCESS) {
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001450 if (*state & HT_ADDBA_RECEIVED_MSK)
1451 printk(KERN_DEBUG "double addBA response\n");
1452
1453 *state |= HT_ADDBA_RECEIVED_MSK;
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001454 sta->ampdu_mlme.addba_req_num[tid] = 0;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001455
1456 if (*state == HT_AGG_STATE_OPERATIONAL) {
1457 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1458 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1459 }
1460
Johannes Berg07346f812008-05-03 01:02:02 +02001461 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001462 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1463 } else {
1464 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1465
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001466 sta->ampdu_mlme.addba_req_num[tid]++;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001467 /* this will allow the state check in stop_BA_session */
1468 *state = HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001469 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001470 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1471 WLAN_BACK_INITIATOR);
1472 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001473
1474addba_resp_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001475 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001476}
1477
1478void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1479 u16 initiator, u16 reason_code)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001480{
1481 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1482 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1483 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1484 struct sk_buff *skb;
1485 struct ieee80211_mgmt *mgmt;
1486 u16 params;
1487
Ester Kummer3acea5b2008-04-17 16:05:14 -07001488 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001489
1490 if (!skb) {
1491 printk(KERN_ERR "%s: failed to allocate buffer "
1492 "for delba frame\n", dev->name);
1493 return;
1494 }
1495
1496 skb_reserve(skb, local->hw.extra_tx_headroom);
1497 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1498 memset(mgmt, 0, 24);
1499 memcpy(mgmt->da, da, ETH_ALEN);
1500 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001501 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001502 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1503 else
1504 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1505 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1506 IEEE80211_STYPE_ACTION);
1507
1508 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1509
1510 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1511 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1512 params = (u16)(initiator << 11); /* bit 11 initiator */
1513 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1514
1515 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1516 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1517
1518 ieee80211_sta_tx(dev, skb, 0);
1519}
1520
1521void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1522 u16 initiator, u16 reason)
1523{
1524 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1525 struct ieee80211_hw *hw = &local->hw;
1526 struct sta_info *sta;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001527 int ret, i;
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001528 DECLARE_MAC_BUF(mac);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001529
Johannes Bergd0709a62008-02-25 16:27:46 +01001530 rcu_read_lock();
1531
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001532 sta = sta_info_get(local, ra);
Johannes Bergd0709a62008-02-25 16:27:46 +01001533 if (!sta) {
1534 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001535 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001536 }
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001537
1538 /* check if TID is in operational state */
Johannes Berg07346f812008-05-03 01:02:02 +02001539 spin_lock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001540 if (sta->ampdu_mlme.tid_state_rx[tid]
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001541 != HT_AGG_STATE_OPERATIONAL) {
Johannes Berg07346f812008-05-03 01:02:02 +02001542 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +01001543 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001544 return;
1545 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001546 sta->ampdu_mlme.tid_state_rx[tid] =
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001547 HT_AGG_STATE_REQ_STOP_BA_MSK |
1548 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
Johannes Berg07346f812008-05-03 01:02:02 +02001549 spin_unlock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001550
1551 /* stop HW Rx aggregation. ampdu_action existence
1552 * already verified in session init so we add the BUG_ON */
1553 BUG_ON(!local->ops->ampdu_action);
1554
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001555#ifdef CONFIG_MAC80211_HT_DEBUG
1556 printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n",
1557 print_mac(mac, ra), tid);
1558#endif /* CONFIG_MAC80211_HT_DEBUG */
1559
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001560 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001561 ra, tid, NULL);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001562 if (ret)
1563 printk(KERN_DEBUG "HW problem - can not stop rx "
1564 "aggergation for tid %d\n", tid);
1565
1566 /* shutdown timer has not expired */
1567 if (initiator != WLAN_BACK_TIMER)
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001568 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001569
1570 /* check if this is a self generated aggregation halt */
1571 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1572 ieee80211_send_delba(dev, ra, tid, 0, reason);
1573
1574 /* free the reordering buffer */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001575 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
1576 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001577 /* release the reordered frames */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001578 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
1579 sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
1580 sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001581 }
1582 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001583 /* free resources */
1584 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
1585 kfree(sta->ampdu_mlme.tid_rx[tid]);
1586 sta->ampdu_mlme.tid_rx[tid] = NULL;
1587 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001588
Johannes Bergd0709a62008-02-25 16:27:46 +01001589 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001590}
1591
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001592
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001593static void ieee80211_sta_process_delba(struct net_device *dev,
1594 struct ieee80211_mgmt *mgmt, size_t len)
1595{
1596 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1597 struct sta_info *sta;
1598 u16 tid, params;
1599 u16 initiator;
1600 DECLARE_MAC_BUF(mac);
1601
Johannes Bergd0709a62008-02-25 16:27:46 +01001602 rcu_read_lock();
1603
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001604 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001605 if (!sta) {
1606 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001607 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001608 }
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001609
1610 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1611 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1612 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1613
1614#ifdef CONFIG_MAC80211_HT_DEBUG
1615 if (net_ratelimit())
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001616 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1617 print_mac(mac, mgmt->sa),
Ron Rindjunsky2e354ed2008-03-18 15:00:30 -07001618 initiator ? "initiator" : "recipient", tid,
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001619 mgmt->u.action.u.delba.reason_code);
1620#endif /* CONFIG_MAC80211_HT_DEBUG */
1621
1622 if (initiator == WLAN_BACK_INITIATOR)
1623 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1624 WLAN_BACK_INITIATOR, 0);
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001625 else { /* WLAN_BACK_RECIPIENT */
Johannes Berg07346f812008-05-03 01:02:02 +02001626 spin_lock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001627 sta->ampdu_mlme.tid_state_tx[tid] =
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001628 HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001629 spin_unlock_bh(&sta->lock);
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001630 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1631 WLAN_BACK_RECIPIENT);
1632 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001633 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001634}
1635
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001636/*
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001637 * After sending add Block Ack request we activated a timer until
1638 * add Block Ack response will arrive from the recipient.
1639 * If this timer expires sta_addba_resp_timer_expired will be executed.
1640 */
1641void sta_addba_resp_timer_expired(unsigned long data)
1642{
1643 /* not an elegant detour, but there is no choice as the timer passes
1644 * only one argument, and both sta_info and TID are needed, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001645 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001646 * array gives the sta through container_of */
Senthil Balasubramanian70d251b2008-05-28 20:08:12 +05301647 u16 tid = *(u8 *)data;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001648 struct sta_info *temp_sta = container_of((void *)data,
1649 struct sta_info, timer_to_tid[tid]);
1650
1651 struct ieee80211_local *local = temp_sta->local;
1652 struct ieee80211_hw *hw = &local->hw;
1653 struct sta_info *sta;
1654 u8 *state;
1655
Johannes Bergd0709a62008-02-25 16:27:46 +01001656 rcu_read_lock();
1657
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001658 sta = sta_info_get(local, temp_sta->addr);
Johannes Bergd0709a62008-02-25 16:27:46 +01001659 if (!sta) {
1660 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001661 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001662 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001663
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001664 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001665 /* check if the TID waits for addBA response */
Johannes Berg07346f812008-05-03 01:02:02 +02001666 spin_lock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001667 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
Johannes Berg07346f812008-05-03 01:02:02 +02001668 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001669 *state = HT_AGG_STATE_IDLE;
1670 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1671 "expecting addBA response there", tid);
1672 goto timer_expired_exit;
1673 }
1674
1675 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1676
1677 /* go through the state check in stop_BA_session */
1678 *state = HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001679 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001680 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1681 WLAN_BACK_INITIATOR);
1682
1683timer_expired_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001684 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001685}
1686
1687/*
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001688 * After accepting the AddBA Request we activated a timer,
1689 * resetting it after each frame that arrives from the originator.
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001690 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1691 */
Adrian Bunk712590d2008-04-21 11:47:51 +03001692static void sta_rx_agg_session_timer_expired(unsigned long data)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001693{
1694 /* not an elegant detour, but there is no choice as the timer passes
Senthil Balasubramanian70d251b2008-05-28 20:08:12 +05301695 * only one argument, and various sta_info are needed here, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001696 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001697 * array gives the sta through container_of */
1698 u8 *ptid = (u8 *)data;
1699 u8 *timer_to_id = ptid - *ptid;
1700 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1701 timer_to_tid[0]);
1702
1703 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
Johannes Bergd0709a62008-02-25 16:27:46 +01001704 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1705 (u16)*ptid, WLAN_BACK_TIMER,
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001706 WLAN_REASON_QSTA_TIMEOUT);
1707}
1708
Ron Rindjunsky85249e52008-03-18 15:00:32 -07001709void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr)
1710{
1711 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1712 int i;
1713
1714 for (i = 0; i < STA_TID_NUM; i++) {
1715 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
1716 WLAN_BACK_INITIATOR);
1717 ieee80211_sta_stop_rx_ba_session(dev, addr, i,
1718 WLAN_BACK_RECIPIENT,
1719 WLAN_REASON_QSTA_LEAVE_QBSS);
1720 }
1721}
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001722
Assaf Kraussb6623482008-06-16 16:09:49 +03001723static void ieee80211_send_refuse_measurement_request(struct net_device *dev,
1724 struct ieee80211_msrment_ie *request_ie,
1725 const u8 *da, const u8 *bssid,
1726 u8 dialog_token)
1727{
1728 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1729 struct sk_buff *skb;
1730 struct ieee80211_mgmt *msr_report;
1731
1732 skb = dev_alloc_skb(sizeof(*msr_report) + local->hw.extra_tx_headroom +
1733 sizeof(struct ieee80211_msrment_ie));
1734
1735 if (!skb) {
1736 printk(KERN_ERR "%s: failed to allocate buffer for "
1737 "measurement report frame\n", dev->name);
1738 return;
1739 }
1740
1741 skb_reserve(skb, local->hw.extra_tx_headroom);
1742 msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24);
1743 memset(msr_report, 0, 24);
1744 memcpy(msr_report->da, da, ETH_ALEN);
1745 memcpy(msr_report->sa, dev->dev_addr, ETH_ALEN);
1746 memcpy(msr_report->bssid, bssid, ETH_ALEN);
1747 msr_report->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1748 IEEE80211_STYPE_ACTION);
1749
1750 skb_put(skb, 1 + sizeof(msr_report->u.action.u.measurement));
1751 msr_report->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT;
1752 msr_report->u.action.u.measurement.action_code =
1753 WLAN_ACTION_SPCT_MSR_RPRT;
1754 msr_report->u.action.u.measurement.dialog_token = dialog_token;
1755
1756 msr_report->u.action.u.measurement.element_id = WLAN_EID_MEASURE_REPORT;
1757 msr_report->u.action.u.measurement.length =
1758 sizeof(struct ieee80211_msrment_ie);
1759
1760 memset(&msr_report->u.action.u.measurement.msr_elem, 0,
1761 sizeof(struct ieee80211_msrment_ie));
1762 msr_report->u.action.u.measurement.msr_elem.token = request_ie->token;
1763 msr_report->u.action.u.measurement.msr_elem.mode |=
1764 IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED;
1765 msr_report->u.action.u.measurement.msr_elem.type = request_ie->type;
1766
1767 ieee80211_sta_tx(dev, skb, 0);
1768}
1769
1770static void ieee80211_sta_process_measurement_req(struct net_device *dev,
1771 struct ieee80211_mgmt *mgmt,
1772 size_t len)
1773{
1774 /*
1775 * Ignoring measurement request is spec violation.
1776 * Mandatory measurements must be reported optional
1777 * measurements might be refused or reported incapable
1778 * For now just refuse
1779 * TODO: Answer basic measurement as unmeasured
1780 */
1781 ieee80211_send_refuse_measurement_request(dev,
1782 &mgmt->u.action.u.measurement.msr_elem,
1783 mgmt->sa, mgmt->bssid,
1784 mgmt->u.action.u.measurement.dialog_token);
1785}
1786
1787
Jiri Bencf0706e82007-05-05 11:45:53 -07001788static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1789 struct ieee80211_if_sta *ifsta,
1790 struct ieee80211_mgmt *mgmt,
1791 size_t len)
1792{
1793 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1794 u16 auth_alg, auth_transaction, status_code;
Joe Perches0795af52007-10-03 17:59:30 -07001795 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001796
1797 if (ifsta->state != IEEE80211_AUTHENTICATE &&
Johannes Berg51fb61e2007-12-19 01:31:27 +01001798 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001799 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001800 "%s, but not in authenticate state - ignored\n",
1801 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e82007-05-05 11:45:53 -07001802 return;
1803 }
1804
1805 if (len < 24 + 6) {
1806 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
Joe Perches0795af52007-10-03 17:59:30 -07001807 "received from %s - ignored\n",
1808 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e82007-05-05 11:45:53 -07001809 return;
1810 }
1811
Johannes Berg51fb61e2007-12-19 01:31:27 +01001812 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Jiri Bencf0706e82007-05-05 11:45:53 -07001813 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1814 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001815 "unknown AP (SA=%s BSSID=%s) - "
1816 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1817 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001818 return;
1819 }
1820
Johannes Berg51fb61e2007-12-19 01:31:27 +01001821 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Jiri Bencf0706e82007-05-05 11:45:53 -07001822 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1823 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001824 "unknown BSSID (SA=%s BSSID=%s) - "
1825 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1826 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001827 return;
1828 }
1829
1830 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1831 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1832 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1833
Joe Perches0795af52007-10-03 17:59:30 -07001834 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
Jiri Bencf0706e82007-05-05 11:45:53 -07001835 "transaction=%d status=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001836 dev->name, print_mac(mac, mgmt->sa), auth_alg,
Jiri Bencf0706e82007-05-05 11:45:53 -07001837 auth_transaction, status_code);
1838
Johannes Berg51fb61e2007-12-19 01:31:27 +01001839 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Johannes Berg135a2112008-06-16 20:55:29 +02001840 /*
1841 * IEEE 802.11 standard does not require authentication in IBSS
Jiri Bencf0706e82007-05-05 11:45:53 -07001842 * networks and most implementations do not seem to use it.
1843 * However, try to reply to authentication attempts if someone
1844 * has actually implemented this.
Johannes Berg135a2112008-06-16 20:55:29 +02001845 */
Jiri Bencf0706e82007-05-05 11:45:53 -07001846 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1847 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1848 "frame (alg=%d transaction=%d)\n",
1849 dev->name, auth_alg, auth_transaction);
1850 return;
1851 }
1852 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1853 }
1854
1855 if (auth_alg != ifsta->auth_alg ||
1856 auth_transaction != ifsta->auth_transaction) {
1857 printk(KERN_DEBUG "%s: unexpected authentication frame "
1858 "(alg=%d transaction=%d)\n",
1859 dev->name, auth_alg, auth_transaction);
1860 return;
1861 }
1862
1863 if (status_code != WLAN_STATUS_SUCCESS) {
1864 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1865 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1866 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1867 u8 algs[3];
1868 const int num_algs = ARRAY_SIZE(algs);
1869 int i, pos;
1870 algs[0] = algs[1] = algs[2] = 0xff;
1871 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1872 algs[0] = WLAN_AUTH_OPEN;
1873 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1874 algs[1] = WLAN_AUTH_SHARED_KEY;
1875 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1876 algs[2] = WLAN_AUTH_LEAP;
1877 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1878 pos = 0;
1879 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1880 pos = 1;
1881 else
1882 pos = 2;
1883 for (i = 0; i < num_algs; i++) {
1884 pos++;
1885 if (pos >= num_algs)
1886 pos = 0;
1887 if (algs[pos] == ifsta->auth_alg ||
1888 algs[pos] == 0xff)
1889 continue;
1890 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1891 !ieee80211_sta_wep_configured(dev))
1892 continue;
1893 ifsta->auth_alg = algs[pos];
1894 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1895 "next try\n",
1896 dev->name, ifsta->auth_alg);
1897 break;
1898 }
1899 }
1900 return;
1901 }
1902
1903 switch (ifsta->auth_alg) {
1904 case WLAN_AUTH_OPEN:
1905 case WLAN_AUTH_LEAP:
1906 ieee80211_auth_completed(dev, ifsta);
1907 break;
1908 case WLAN_AUTH_SHARED_KEY:
1909 if (ifsta->auth_transaction == 4)
1910 ieee80211_auth_completed(dev, ifsta);
1911 else
1912 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1913 break;
1914 }
1915}
1916
1917
1918static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1919 struct ieee80211_if_sta *ifsta,
1920 struct ieee80211_mgmt *mgmt,
1921 size_t len)
1922{
1923 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001924 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001925
1926 if (len < 24 + 2) {
1927 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
Joe Perches0795af52007-10-03 17:59:30 -07001928 "received from %s - ignored\n",
1929 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e82007-05-05 11:45:53 -07001930 return;
1931 }
1932
1933 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1934 printk(KERN_DEBUG "%s: deauthentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001935 "unknown AP (SA=%s BSSID=%s) - "
1936 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1937 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001938 return;
1939 }
1940
1941 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1942
Joe Perches0795af52007-10-03 17:59:30 -07001943 printk(KERN_DEBUG "%s: RX deauthentication from %s"
Jiri Bencf0706e82007-05-05 11:45:53 -07001944 " (reason=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001945 dev->name, print_mac(mac, mgmt->sa), reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001946
Johannes Berg988c0f72008-04-17 19:21:22 +02001947 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
Jiri Bencf0706e82007-05-05 11:45:53 -07001948 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001949
1950 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1951 ifsta->state == IEEE80211_ASSOCIATE ||
1952 ifsta->state == IEEE80211_ASSOCIATED) {
1953 ifsta->state = IEEE80211_AUTHENTICATE;
1954 mod_timer(&ifsta->timer, jiffies +
1955 IEEE80211_RETRY_AUTH_INTERVAL);
1956 }
1957
1958 ieee80211_set_disassoc(dev, ifsta, 1);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001959 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001960}
1961
1962
1963static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1964 struct ieee80211_if_sta *ifsta,
1965 struct ieee80211_mgmt *mgmt,
1966 size_t len)
1967{
1968 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001969 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001970
1971 if (len < 24 + 2) {
1972 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
Joe Perches0795af52007-10-03 17:59:30 -07001973 "received from %s - ignored\n",
1974 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e82007-05-05 11:45:53 -07001975 return;
1976 }
1977
1978 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1979 printk(KERN_DEBUG "%s: disassociation frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001980 "unknown AP (SA=%s BSSID=%s) - "
1981 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1982 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07001983 return;
1984 }
1985
1986 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1987
Joe Perches0795af52007-10-03 17:59:30 -07001988 printk(KERN_DEBUG "%s: RX disassociation from %s"
Jiri Bencf0706e82007-05-05 11:45:53 -07001989 " (reason=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001990 dev->name, print_mac(mac, mgmt->sa), reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001991
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001992 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
Jiri Bencf0706e82007-05-05 11:45:53 -07001993 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1994
1995 if (ifsta->state == IEEE80211_ASSOCIATED) {
1996 ifsta->state = IEEE80211_ASSOCIATE;
1997 mod_timer(&ifsta->timer, jiffies +
1998 IEEE80211_RETRY_AUTH_INTERVAL);
1999 }
2000
2001 ieee80211_set_disassoc(dev, ifsta, 0);
2002}
2003
2004
Johannes Berg471b3ef2007-12-28 14:32:58 +01002005static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002006 struct ieee80211_if_sta *ifsta,
2007 struct ieee80211_mgmt *mgmt,
2008 size_t len,
2009 int reassoc)
2010{
Johannes Berg471b3ef2007-12-28 14:32:58 +01002011 struct ieee80211_local *local = sdata->local;
2012 struct net_device *dev = sdata->dev;
Johannes Berg8318d782008-01-24 19:38:38 +01002013 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07002014 struct sta_info *sta;
Johannes Berg8318d782008-01-24 19:38:38 +01002015 u64 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07002016 u16 capab_info, status_code, aid;
2017 struct ieee802_11_elems elems;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002018 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07002019 u8 *pos;
2020 int i, j;
Joe Perches0795af52007-10-03 17:59:30 -07002021 DECLARE_MAC_BUF(mac);
Johannes Berg8318d782008-01-24 19:38:38 +01002022 bool have_higher_than_11mbit = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002023
2024 /* AssocResp and ReassocResp have identical structure, so process both
2025 * of them in this function. */
2026
2027 if (ifsta->state != IEEE80211_ASSOCIATE) {
2028 printk(KERN_DEBUG "%s: association frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07002029 "%s, but not in associate state - ignored\n",
2030 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e82007-05-05 11:45:53 -07002031 return;
2032 }
2033
2034 if (len < 24 + 6) {
2035 printk(KERN_DEBUG "%s: too short (%zd) association frame "
Joe Perches0795af52007-10-03 17:59:30 -07002036 "received from %s - ignored\n",
2037 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e82007-05-05 11:45:53 -07002038 return;
2039 }
2040
2041 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
2042 printk(KERN_DEBUG "%s: association frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07002043 "unknown AP (SA=%s BSSID=%s) - "
2044 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
2045 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07002046 return;
2047 }
2048
2049 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2050 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2051 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e82007-05-05 11:45:53 -07002052
Joe Perches0795af52007-10-03 17:59:30 -07002053 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07002054 "status=%d aid=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07002055 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
Johannes Bergddd68582007-10-22 14:51:37 +02002056 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07002057
2058 if (status_code != WLAN_STATUS_SUCCESS) {
2059 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
2060 dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02002061 /* if this was a reassociation, ensure we try a "full"
2062 * association next time. This works around some broken APs
2063 * which do not correctly reject reassociation requests. */
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002064 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -07002065 return;
2066 }
2067
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002068 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2069 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
2070 "set\n", dev->name, aid);
2071 aid &= ~(BIT(15) | BIT(14));
2072
Jiri Bencf0706e82007-05-05 11:45:53 -07002073 pos = mgmt->u.assoc_resp.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04002074 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Jiri Bencf0706e82007-05-05 11:45:53 -07002075
2076 if (!elems.supp_rates) {
2077 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
2078 dev->name);
2079 return;
2080 }
2081
2082 printk(KERN_DEBUG "%s: associated\n", dev->name);
2083 ifsta->aid = aid;
2084 ifsta->ap_capab = capab_info;
2085
2086 kfree(ifsta->assocresp_ies);
2087 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
Michael Wu0ec0b7a2007-07-27 15:43:24 +02002088 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07002089 if (ifsta->assocresp_ies)
2090 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
2091
Johannes Bergd0709a62008-02-25 16:27:46 +01002092 rcu_read_lock();
2093
Jiri Bencf0706e82007-05-05 11:45:53 -07002094 /* Add STA entry for the AP */
2095 sta = sta_info_get(local, ifsta->bssid);
2096 if (!sta) {
2097 struct ieee80211_sta_bss *bss;
Johannes Berg73651ee2008-02-25 16:27:47 +01002098 int err;
Johannes Bergd0709a62008-02-25 16:27:46 +01002099
Johannes Berg73651ee2008-02-25 16:27:47 +01002100 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
2101 if (!sta) {
2102 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
2103 " the AP\n", dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01002104 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002105 return;
2106 }
John W. Linville65c107a2007-10-05 14:23:27 -04002107 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01002108 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002109 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002110 if (bss) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002111 sta->last_signal = bss->signal;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002112 sta->last_qual = bss->qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07002113 sta->last_noise = bss->noise;
2114 ieee80211_rx_bss_put(dev, bss);
2115 }
Johannes Berg73651ee2008-02-25 16:27:47 +01002116
2117 err = sta_info_insert(sta);
2118 if (err) {
2119 printk(KERN_DEBUG "%s: failed to insert STA entry for"
2120 " the AP (error %d)\n", dev->name, err);
Johannes Berg73651ee2008-02-25 16:27:47 +01002121 rcu_read_unlock();
2122 return;
2123 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002124 }
2125
Johannes Berg73651ee2008-02-25 16:27:47 +01002126 /*
2127 * FIXME: Do we really need to update the sta_info's information here?
2128 * We already know about the AP (we found it in our list) so it
2129 * should already be filled with the right info, no?
2130 * As is stands, all this is racy because typically we assume
2131 * the information that is filled in here (except flags) doesn't
2132 * change while a STA structure is alive. As such, it should move
2133 * to between the sta_info_alloc() and sta_info_insert() above.
2134 */
2135
Johannes Berg07346f812008-05-03 01:02:02 +02002136 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
2137 WLAN_STA_AUTHORIZED);
Jiri Bencf0706e82007-05-05 11:45:53 -07002138
2139 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002140 basic_rates = 0;
2141 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2142
Jiri Bencf0706e82007-05-05 11:45:53 -07002143 for (i = 0; i < elems.supp_rates_len; i++) {
2144 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01002145
2146 if (rate > 110)
2147 have_higher_than_11mbit = true;
2148
2149 for (j = 0; j < sband->n_bitrates; j++) {
2150 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e82007-05-05 11:45:53 -07002151 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01002152 if (elems.supp_rates[i] & 0x80)
2153 basic_rates |= BIT(j);
2154 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002155 }
Johannes Berg8318d782008-01-24 19:38:38 +01002156
Jiri Bencf0706e82007-05-05 11:45:53 -07002157 for (i = 0; i < elems.ext_supp_rates_len; i++) {
2158 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01002159
2160 if (rate > 110)
2161 have_higher_than_11mbit = true;
2162
2163 for (j = 0; j < sband->n_bitrates; j++) {
2164 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e82007-05-05 11:45:53 -07002165 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01002166 if (elems.ext_supp_rates[i] & 0x80)
2167 basic_rates |= BIT(j);
2168 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002169 }
Johannes Berg8318d782008-01-24 19:38:38 +01002170
2171 sta->supp_rates[local->hw.conf.channel->band] = rates;
2172 sdata->basic_rates = basic_rates;
2173
2174 /* cf. IEEE 802.11 9.2.12 */
2175 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
2176 have_higher_than_11mbit)
2177 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
2178 else
2179 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002180
Johannes Berg3434fbd2008-05-03 00:59:37 +02002181 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
2182 (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002183 struct ieee80211_ht_bss_info bss_info;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002184 ieee80211_ht_cap_ie_to_ht_info(
2185 (struct ieee80211_ht_cap *)
2186 elems.ht_cap_elem, &sta->ht_info);
2187 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2188 (struct ieee80211_ht_addt_info *)
2189 elems.ht_info_elem, &bss_info);
Tomas Winkler38668c02008-03-28 16:33:32 -07002190 ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002191 }
2192
Jiri Bencf0706e82007-05-05 11:45:53 -07002193 rate_control_rate_init(sta, local);
2194
Johannes Berg3434fbd2008-05-03 00:59:37 +02002195 if (elems.wmm_param) {
Johannes Berg07346f812008-05-03 01:02:02 +02002196 set_sta_flags(sta, WLAN_STA_WME);
Johannes Berge5f98f22008-03-05 20:39:31 +01002197 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002198 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2199 elems.wmm_param_len);
Johannes Berge5f98f22008-03-05 20:39:31 +01002200 } else
2201 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002202
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002203 /* set AID and assoc capability,
2204 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002205 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002206 bss_conf->assoc_capability = capab_info;
Johannes Berg8318d782008-01-24 19:38:38 +01002207 ieee80211_set_associated(dev, ifsta, 1);
Jiri Bencf0706e82007-05-05 11:45:53 -07002208
Jiri Bencf0706e82007-05-05 11:45:53 -07002209 ieee80211_associated(dev, ifsta);
2210}
2211
2212
2213/* Caller must hold local->sta_bss_lock */
2214static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
2215 struct ieee80211_sta_bss *bss)
2216{
2217 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002218 u8 hash_idx;
Johannes Berg902acc72008-02-23 15:17:19 +01002219
2220 if (bss_mesh_cfg(bss))
2221 hash_idx = mesh_id_hash(bss_mesh_id(bss),
2222 bss_mesh_id_len(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002223 else
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002224 hash_idx = STA_HASH(bss->bssid);
Johannes Berg902acc72008-02-23 15:17:19 +01002225
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002226 bss->hnext = local->sta_bss_hash[hash_idx];
2227 local->sta_bss_hash[hash_idx] = bss;
Jiri Bencf0706e82007-05-05 11:45:53 -07002228}
2229
2230
2231/* Caller must hold local->sta_bss_lock */
2232static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
2233 struct ieee80211_sta_bss *bss)
2234{
2235 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2236 struct ieee80211_sta_bss *b, *prev = NULL;
2237 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
2238 while (b) {
2239 if (b == bss) {
2240 if (!prev)
2241 local->sta_bss_hash[STA_HASH(bss->bssid)] =
2242 bss->hnext;
2243 else
2244 prev->hnext = bss->hnext;
2245 break;
2246 }
2247 prev = b;
2248 b = b->hnext;
2249 }
2250}
2251
2252
2253static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +01002254ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002255 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002256{
2257 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2258 struct ieee80211_sta_bss *bss;
2259
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002260 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
Jiri Bencf0706e82007-05-05 11:45:53 -07002261 if (!bss)
2262 return NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07002263 atomic_inc(&bss->users);
2264 atomic_inc(&bss->users);
2265 memcpy(bss->bssid, bssid, ETH_ALEN);
Johannes Berg8318d782008-01-24 19:38:38 +01002266 bss->freq = freq;
John W. Linvillecffdd302007-10-05 14:23:27 -04002267 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
2268 memcpy(bss->ssid, ssid, ssid_len);
2269 bss->ssid_len = ssid_len;
2270 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002271
2272 spin_lock_bh(&local->sta_bss_lock);
2273 /* TODO: order by RSSI? */
2274 list_add_tail(&bss->list, &local->sta_bss_list);
2275 __ieee80211_rx_bss_hash_add(dev, bss);
2276 spin_unlock_bh(&local->sta_bss_lock);
2277 return bss;
2278}
2279
Jiri Bencf0706e82007-05-05 11:45:53 -07002280static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +01002281ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002282 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002283{
2284 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2285 struct ieee80211_sta_bss *bss;
2286
2287 spin_lock_bh(&local->sta_bss_lock);
2288 bss = local->sta_bss_hash[STA_HASH(bssid)];
2289 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002290 if (!bss_mesh_cfg(bss) &&
2291 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
Johannes Berg8318d782008-01-24 19:38:38 +01002292 bss->freq == freq &&
John W. Linvillecffdd302007-10-05 14:23:27 -04002293 bss->ssid_len == ssid_len &&
2294 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002295 atomic_inc(&bss->users);
2296 break;
2297 }
2298 bss = bss->hnext;
2299 }
2300 spin_unlock_bh(&local->sta_bss_lock);
2301 return bss;
2302}
2303
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002304#ifdef CONFIG_MAC80211_MESH
2305static struct ieee80211_sta_bss *
2306ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2307 u8 *mesh_cfg, int freq)
2308{
2309 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2310 struct ieee80211_sta_bss *bss;
2311
2312 spin_lock_bh(&local->sta_bss_lock);
2313 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2314 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002315 if (bss_mesh_cfg(bss) &&
2316 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002317 bss->freq == freq &&
2318 mesh_id_len == bss->mesh_id_len &&
2319 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2320 mesh_id_len))) {
2321 atomic_inc(&bss->users);
2322 break;
2323 }
2324 bss = bss->hnext;
2325 }
2326 spin_unlock_bh(&local->sta_bss_lock);
2327 return bss;
2328}
2329
2330static struct ieee80211_sta_bss *
2331ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002332 u8 *mesh_cfg, int mesh_config_len, int freq)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002333{
2334 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2335 struct ieee80211_sta_bss *bss;
2336
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002337 if (mesh_config_len != MESH_CFG_LEN)
2338 return NULL;
2339
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002340 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2341 if (!bss)
2342 return NULL;
2343
John W. Linville24736702008-04-08 14:15:46 -04002344 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002345 if (!bss->mesh_cfg) {
2346 kfree(bss);
2347 return NULL;
2348 }
2349
2350 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2351 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2352 if (!bss->mesh_id) {
2353 kfree(bss->mesh_cfg);
2354 kfree(bss);
2355 return NULL;
2356 }
2357 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2358 }
2359
2360 atomic_inc(&bss->users);
2361 atomic_inc(&bss->users);
John W. Linville24736702008-04-08 14:15:46 -04002362 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002363 bss->mesh_id_len = mesh_id_len;
2364 bss->freq = freq;
2365 spin_lock_bh(&local->sta_bss_lock);
2366 /* TODO: order by RSSI? */
2367 list_add_tail(&bss->list, &local->sta_bss_list);
2368 __ieee80211_rx_bss_hash_add(dev, bss);
2369 spin_unlock_bh(&local->sta_bss_lock);
2370 return bss;
2371}
2372#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07002373
2374static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2375{
2376 kfree(bss->wpa_ie);
2377 kfree(bss->rsn_ie);
2378 kfree(bss->wmm_ie);
Ron Rindjunskyc7153502007-11-26 16:14:31 +02002379 kfree(bss->ht_ie);
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002380 kfree(bss->ht_add_ie);
Johannes Berg902acc72008-02-23 15:17:19 +01002381 kfree(bss_mesh_id(bss));
2382 kfree(bss_mesh_cfg(bss));
Jiri Bencf0706e82007-05-05 11:45:53 -07002383 kfree(bss);
2384}
2385
2386
2387static void ieee80211_rx_bss_put(struct net_device *dev,
2388 struct ieee80211_sta_bss *bss)
2389{
2390 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e82007-05-05 11:45:53 -07002391
Pavel Emelyanov1ebebea2008-04-23 11:47:15 +04002392 local_bh_disable();
2393 if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
2394 local_bh_enable();
2395 return;
2396 }
2397
Jiri Bencf0706e82007-05-05 11:45:53 -07002398 __ieee80211_rx_bss_hash_del(dev, bss);
2399 list_del(&bss->list);
2400 spin_unlock_bh(&local->sta_bss_lock);
2401 ieee80211_rx_bss_free(bss);
2402}
2403
2404
2405void ieee80211_rx_bss_list_init(struct net_device *dev)
2406{
2407 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2408 spin_lock_init(&local->sta_bss_lock);
2409 INIT_LIST_HEAD(&local->sta_bss_list);
2410}
2411
2412
2413void ieee80211_rx_bss_list_deinit(struct net_device *dev)
2414{
2415 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2416 struct ieee80211_sta_bss *bss, *tmp;
2417
2418 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
2419 ieee80211_rx_bss_put(dev, bss);
2420}
2421
2422
Bruno Randolfa6072682008-02-18 11:21:15 +09002423static int ieee80211_sta_join_ibss(struct net_device *dev,
2424 struct ieee80211_if_sta *ifsta,
2425 struct ieee80211_sta_bss *bss)
2426{
2427 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2428 int res, rates, i, j;
2429 struct sk_buff *skb;
2430 struct ieee80211_mgmt *mgmt;
Johannes Berge039fa42008-05-15 12:55:29 +02002431 struct ieee80211_tx_info *control;
Bruno Randolfa6072682008-02-18 11:21:15 +09002432 struct rate_selection ratesel;
2433 u8 *pos;
2434 struct ieee80211_sub_if_data *sdata;
2435 struct ieee80211_supported_band *sband;
Dan Williams507b06d2008-06-03 23:39:55 -04002436 union iwreq_data wrqu;
Bruno Randolfa6072682008-02-18 11:21:15 +09002437
2438 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2439
Johannes Berg9dd6aed2008-03-31 19:22:59 +02002440 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2441
Bruno Randolfa6072682008-02-18 11:21:15 +09002442 /* Remove possible STA entries from other IBSS networks. */
Johannes Bergdc6676b2008-03-31 19:23:03 +02002443 sta_info_flush_delayed(sdata);
Bruno Randolfa6072682008-02-18 11:21:15 +09002444
2445 if (local->ops->reset_tsf) {
2446 /* Reset own TSF to allow time synchronization work. */
2447 local->ops->reset_tsf(local_to_hw(local));
2448 }
2449 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2450 res = ieee80211_if_config(dev);
2451 if (res)
2452 return res;
2453
2454 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2455
Bruno Randolfa6072682008-02-18 11:21:15 +09002456 sdata->drop_unencrypted = bss->capability &
2457 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2458
Assaf Kraussbe038b32008-06-05 19:55:21 +03002459 res = ieee80211_set_freq(dev, bss->freq);
Bruno Randolfa6072682008-02-18 11:21:15 +09002460
Assaf Kraussbe038b32008-06-05 19:55:21 +03002461 if (res)
2462 return res;
Bruno Randolfa6072682008-02-18 11:21:15 +09002463
2464 /* Set beacon template */
2465 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2466 do {
2467 if (!skb)
2468 break;
2469
2470 skb_reserve(skb, local->hw.extra_tx_headroom);
2471
2472 mgmt = (struct ieee80211_mgmt *)
2473 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2474 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2475 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2476 IEEE80211_STYPE_BEACON);
2477 memset(mgmt->da, 0xff, ETH_ALEN);
2478 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2479 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2480 mgmt->u.beacon.beacon_int =
2481 cpu_to_le16(local->hw.conf.beacon_int);
2482 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2483
2484 pos = skb_put(skb, 2 + ifsta->ssid_len);
2485 *pos++ = WLAN_EID_SSID;
2486 *pos++ = ifsta->ssid_len;
2487 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2488
2489 rates = bss->supp_rates_len;
2490 if (rates > 8)
2491 rates = 8;
2492 pos = skb_put(skb, 2 + rates);
2493 *pos++ = WLAN_EID_SUPP_RATES;
2494 *pos++ = rates;
2495 memcpy(pos, bss->supp_rates, rates);
2496
2497 if (bss->band == IEEE80211_BAND_2GHZ) {
2498 pos = skb_put(skb, 2 + 1);
2499 *pos++ = WLAN_EID_DS_PARAMS;
2500 *pos++ = 1;
2501 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2502 }
2503
2504 pos = skb_put(skb, 2 + 2);
2505 *pos++ = WLAN_EID_IBSS_PARAMS;
2506 *pos++ = 2;
2507 /* FIX: set ATIM window based on scan results */
2508 *pos++ = 0;
2509 *pos++ = 0;
2510
2511 if (bss->supp_rates_len > 8) {
2512 rates = bss->supp_rates_len - 8;
2513 pos = skb_put(skb, 2 + rates);
2514 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2515 *pos++ = rates;
2516 memcpy(pos, &bss->supp_rates[8], rates);
2517 }
2518
Johannes Berge039fa42008-05-15 12:55:29 +02002519 control = IEEE80211_SKB_CB(skb);
2520
Bruno Randolfa6072682008-02-18 11:21:15 +09002521 rate_control_get_rate(dev, sband, skb, &ratesel);
Johannes Berg2e92e6f2008-05-15 12:55:27 +02002522 if (ratesel.rate_idx < 0) {
Bruno Randolfa6072682008-02-18 11:21:15 +09002523 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2524 "for IBSS beacon\n", dev->name);
2525 break;
2526 }
Johannes Berge039fa42008-05-15 12:55:29 +02002527 control->control.vif = &sdata->vif;
2528 control->tx_rate_idx = ratesel.rate_idx;
Bruno Randolfa6072682008-02-18 11:21:15 +09002529 if (sdata->bss_conf.use_short_preamble &&
Johannes Berg2e92e6f2008-05-15 12:55:27 +02002530 sband->bitrates[ratesel.rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE)
Johannes Berge039fa42008-05-15 12:55:29 +02002531 control->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE;
2532 control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2533 control->flags |= IEEE80211_TX_CTL_NO_ACK;
2534 control->control.retry_limit = 1;
Bruno Randolfa6072682008-02-18 11:21:15 +09002535
2536 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2537 if (ifsta->probe_resp) {
2538 mgmt = (struct ieee80211_mgmt *)
2539 ifsta->probe_resp->data;
2540 mgmt->frame_control =
2541 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2542 IEEE80211_STYPE_PROBE_RESP);
2543 } else {
2544 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2545 "template for IBSS\n", dev->name);
2546 }
2547
2548 if (local->ops->beacon_update &&
Johannes Berge039fa42008-05-15 12:55:29 +02002549 local->ops->beacon_update(local_to_hw(local), skb) == 0) {
Bruno Randolfa6072682008-02-18 11:21:15 +09002550 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2551 "template\n", dev->name);
2552 skb = NULL;
2553 }
2554
2555 rates = 0;
2556 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2557 for (i = 0; i < bss->supp_rates_len; i++) {
2558 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2559 for (j = 0; j < sband->n_bitrates; j++)
2560 if (sband->bitrates[j].bitrate == bitrate)
2561 rates |= BIT(j);
2562 }
2563 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
Vladimir Koutnye2839d82008-03-18 21:14:07 +01002564
2565 ieee80211_sta_def_wmm_params(dev, bss, 1);
Bruno Randolfa6072682008-02-18 11:21:15 +09002566 } while (0);
2567
2568 if (skb) {
2569 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2570 "template\n", dev->name);
2571 dev_kfree_skb(skb);
2572 }
2573
2574 ifsta->state = IEEE80211_IBSS_JOINED;
2575 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2576
Dan Williams507b06d2008-06-03 23:39:55 -04002577 memset(&wrqu, 0, sizeof(wrqu));
2578 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
2579 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Bruno Randolfa6072682008-02-18 11:21:15 +09002580
2581 return res;
2582}
2583
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002584u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2585 struct ieee802_11_elems *elems,
2586 enum ieee80211_band band)
2587{
2588 struct ieee80211_supported_band *sband;
2589 struct ieee80211_rate *bitrates;
2590 size_t num_rates;
2591 u64 supp_rates;
2592 int i, j;
2593 sband = local->hw.wiphy->bands[band];
2594
2595 if (!sband) {
2596 WARN_ON(1);
2597 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2598 }
2599
2600 bitrates = sband->bitrates;
2601 num_rates = sband->n_bitrates;
2602 supp_rates = 0;
2603 for (i = 0; i < elems->supp_rates_len +
2604 elems->ext_supp_rates_len; i++) {
2605 u8 rate = 0;
2606 int own_rate;
2607 if (i < elems->supp_rates_len)
2608 rate = elems->supp_rates[i];
2609 else if (elems->ext_supp_rates)
2610 rate = elems->ext_supp_rates
2611 [i - elems->supp_rates_len];
2612 own_rate = 5 * (rate & 0x7f);
2613 for (j = 0; j < num_rates; j++)
2614 if (bitrates[j].bitrate == own_rate)
2615 supp_rates |= BIT(j);
2616 }
2617 return supp_rates;
2618}
2619
Bruno Randolfa6072682008-02-18 11:21:15 +09002620
Jiri Bencf0706e82007-05-05 11:45:53 -07002621static void ieee80211_rx_bss_info(struct net_device *dev,
2622 struct ieee80211_mgmt *mgmt,
2623 size_t len,
2624 struct ieee80211_rx_status *rx_status,
2625 int beacon)
2626{
2627 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2628 struct ieee802_11_elems elems;
2629 size_t baselen;
Johannes Berg8318d782008-01-24 19:38:38 +01002630 int freq, clen;
Jiri Bencf0706e82007-05-05 11:45:53 -07002631 struct ieee80211_sta_bss *bss;
2632 struct sta_info *sta;
2633 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002634 u64 beacon_timestamp, rx_timestamp;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002635 struct ieee80211_channel *channel;
Joe Perches0795af52007-10-03 17:59:30 -07002636 DECLARE_MAC_BUF(mac);
2637 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e82007-05-05 11:45:53 -07002638
2639 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
2640 return; /* ignore ProbeResp to foreign address */
2641
2642#if 0
Joe Perches0795af52007-10-03 17:59:30 -07002643 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
Jiri Bencf0706e82007-05-05 11:45:53 -07002644 dev->name, beacon ? "Beacon" : "Probe Response",
Joe Perches0795af52007-10-03 17:59:30 -07002645 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
Jiri Bencf0706e82007-05-05 11:45:53 -07002646#endif
2647
2648 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2649 if (baselen > len)
2650 return;
2651
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002652 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
John W. Linville67a4cce2007-10-12 16:40:37 -04002653 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
Jiri Bencf0706e82007-05-05 11:45:53 -07002654
Johannes Berg902acc72008-02-23 15:17:19 +01002655 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
2656 elems.mesh_config && mesh_matches_local(&elems, dev)) {
2657 u64 rates = ieee80211_sta_get_rates(local, &elems,
2658 rx_status->band);
2659
2660 mesh_neighbour_update(mgmt->sa, rates, dev,
2661 mesh_peer_accepts_plinks(&elems, dev));
2662 }
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002663
Johannes Bergd0709a62008-02-25 16:27:46 +01002664 rcu_read_lock();
2665
Johannes Berg51fb61e2007-12-19 01:31:27 +01002666 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
Jiri Bencf0706e82007-05-05 11:45:53 -07002667 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2668 (sta = sta_info_get(local, mgmt->sa))) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002669 u64 prev_rates;
2670 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
2671 rx_status->band);
Jiri Bencf0706e82007-05-05 11:45:53 -07002672
Johannes Berg8318d782008-01-24 19:38:38 +01002673 prev_rates = sta->supp_rates[rx_status->band];
2674 sta->supp_rates[rx_status->band] &= supp_rates;
2675 if (sta->supp_rates[rx_status->band] == 0) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002676 /* No matching rates - this should not really happen.
2677 * Make sure that at least one rate is marked
2678 * supported to avoid issues with TX rate ctrl. */
Johannes Berg8318d782008-01-24 19:38:38 +01002679 sta->supp_rates[rx_status->band] =
2680 sdata->u.sta.supp_rates_bits[rx_status->band];
Jiri Bencf0706e82007-05-05 11:45:53 -07002681 }
Johannes Berg8318d782008-01-24 19:38:38 +01002682 if (sta->supp_rates[rx_status->band] != prev_rates) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002683 printk(KERN_DEBUG "%s: updated supp_rates set for "
Johannes Berg8318d782008-01-24 19:38:38 +01002684 "%s based on beacon info (0x%llx & 0x%llx -> "
2685 "0x%llx)\n",
2686 dev->name, print_mac(mac, sta->addr),
2687 (unsigned long long) prev_rates,
2688 (unsigned long long) supp_rates,
2689 (unsigned long long) sta->supp_rates[rx_status->band]);
Jiri Bencf0706e82007-05-05 11:45:53 -07002690 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002691 }
2692
Johannes Bergd0709a62008-02-25 16:27:46 +01002693 rcu_read_unlock();
2694
Jiri Bencf0706e82007-05-05 11:45:53 -07002695 if (elems.ds_params && elems.ds_params_len == 1)
Johannes Berg8318d782008-01-24 19:38:38 +01002696 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
Jiri Bencf0706e82007-05-05 11:45:53 -07002697 else
Johannes Berg8318d782008-01-24 19:38:38 +01002698 freq = rx_status->freq;
Jiri Bencf0706e82007-05-05 11:45:53 -07002699
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002700 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2701
2702 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2703 return;
2704
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002705#ifdef CONFIG_MAC80211_MESH
2706 if (elems.mesh_config)
2707 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
2708 elems.mesh_id_len, elems.mesh_config, freq);
2709 else
2710#endif
2711 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002712 elems.ssid, elems.ssid_len);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002713 if (!bss) {
2714#ifdef CONFIG_MAC80211_MESH
2715 if (elems.mesh_config)
2716 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002717 elems.mesh_id_len, elems.mesh_config,
2718 elems.mesh_config_len, freq);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002719 else
2720#endif
2721 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2722 elems.ssid, elems.ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002723 if (!bss)
2724 return;
2725 } else {
2726#if 0
2727 /* TODO: order by RSSI? */
2728 spin_lock_bh(&local->sta_bss_lock);
2729 list_move_tail(&bss->list, &local->sta_bss_list);
2730 spin_unlock_bh(&local->sta_bss_lock);
2731#endif
2732 }
2733
Daniel Drake56282212007-07-10 19:32:10 +02002734 /* save the ERP value so that it is available at association time */
2735 if (elems.erp_info && elems.erp_info_len >= 1) {
2736 bss->erp_value = elems.erp_info[0];
2737 bss->has_erp_value = 1;
2738 }
2739
Johannes Berg30b89b02008-04-16 17:43:20 +02002740 if (elems.ht_cap_elem &&
2741 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2742 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2743 kfree(bss->ht_ie);
2744 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2745 if (bss->ht_ie) {
2746 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2747 elems.ht_cap_elem_len + 2);
2748 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2749 } else
2750 bss->ht_ie_len = 0;
2751 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2752 kfree(bss->ht_ie);
2753 bss->ht_ie = NULL;
2754 bss->ht_ie_len = 0;
2755 }
2756
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002757 if (elems.ht_info_elem &&
2758 (!bss->ht_add_ie ||
2759 bss->ht_add_ie_len != elems.ht_info_elem_len ||
2760 memcmp(bss->ht_add_ie, elems.ht_info_elem,
2761 elems.ht_info_elem_len))) {
2762 kfree(bss->ht_add_ie);
2763 bss->ht_add_ie =
2764 kmalloc(elems.ht_info_elem_len + 2, GFP_ATOMIC);
2765 if (bss->ht_add_ie) {
2766 memcpy(bss->ht_add_ie, elems.ht_info_elem - 2,
2767 elems.ht_info_elem_len + 2);
2768 bss->ht_add_ie_len = elems.ht_info_elem_len + 2;
2769 } else
2770 bss->ht_add_ie_len = 0;
2771 } else if (!elems.ht_info_elem && bss->ht_add_ie) {
2772 kfree(bss->ht_add_ie);
2773 bss->ht_add_ie = NULL;
2774 bss->ht_add_ie_len = 0;
2775 }
2776
Jiri Bencf0706e82007-05-05 11:45:53 -07002777 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2778 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07002779
2780 bss->supp_rates_len = 0;
2781 if (elems.supp_rates) {
2782 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2783 if (clen > elems.supp_rates_len)
2784 clen = elems.supp_rates_len;
2785 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
2786 clen);
2787 bss->supp_rates_len += clen;
2788 }
2789 if (elems.ext_supp_rates) {
2790 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2791 if (clen > elems.ext_supp_rates_len)
2792 clen = elems.ext_supp_rates_len;
2793 memcpy(&bss->supp_rates[bss->supp_rates_len],
2794 elems.ext_supp_rates, clen);
2795 bss->supp_rates_len += clen;
2796 }
2797
Johannes Berg30b89b02008-04-16 17:43:20 +02002798 bss->band = rx_status->band;
2799
2800 bss->timestamp = beacon_timestamp;
2801 bss->last_update = jiffies;
Johannes Berg30b89b02008-04-16 17:43:20 +02002802 bss->signal = rx_status->signal;
2803 bss->noise = rx_status->noise;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002804 bss->qual = rx_status->qual;
Johannes Berg30b89b02008-04-16 17:43:20 +02002805 if (!beacon && !bss->probe_resp)
2806 bss->probe_resp = true;
2807
2808 /*
2809 * In STA mode, the remaining parameters should not be overridden
2810 * by beacons because they're not necessarily accurate there.
2811 */
2812 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2813 bss->probe_resp && beacon) {
2814 ieee80211_rx_bss_put(dev, bss);
2815 return;
2816 }
2817
Jiri Bencf0706e82007-05-05 11:45:53 -07002818 if (elems.wpa &&
2819 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
2820 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
2821 kfree(bss->wpa_ie);
2822 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
2823 if (bss->wpa_ie) {
2824 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
2825 bss->wpa_ie_len = elems.wpa_len + 2;
2826 } else
2827 bss->wpa_ie_len = 0;
2828 } else if (!elems.wpa && bss->wpa_ie) {
2829 kfree(bss->wpa_ie);
2830 bss->wpa_ie = NULL;
2831 bss->wpa_ie_len = 0;
2832 }
2833
2834 if (elems.rsn &&
2835 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2836 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2837 kfree(bss->rsn_ie);
2838 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2839 if (bss->rsn_ie) {
2840 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2841 bss->rsn_ie_len = elems.rsn_len + 2;
2842 } else
2843 bss->rsn_ie_len = 0;
2844 } else if (!elems.rsn && bss->rsn_ie) {
2845 kfree(bss->rsn_ie);
2846 bss->rsn_ie = NULL;
2847 bss->rsn_ie_len = 0;
2848 }
2849
Johannes Berg30b89b02008-04-16 17:43:20 +02002850 /*
2851 * Cf.
2852 * http://www.wipo.int/pctdb/en/wo.jsp?wo=2007047181&IA=WO2007047181&DISPLAY=DESC
2853 *
2854 * quoting:
2855 *
2856 * In particular, "Wi-Fi CERTIFIED for WMM - Support for Multimedia
2857 * Applications with Quality of Service in Wi-Fi Networks," Wi- Fi
2858 * Alliance (September 1, 2004) is incorporated by reference herein.
2859 * The inclusion of the WMM Parameters in probe responses and
2860 * association responses is mandatory for WMM enabled networks. The
2861 * inclusion of the WMM Parameters in beacons, however, is optional.
2862 */
2863
Jiri Bencf0706e82007-05-05 11:45:53 -07002864 if (elems.wmm_param &&
2865 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2866 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2867 kfree(bss->wmm_ie);
2868 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2869 if (bss->wmm_ie) {
2870 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2871 elems.wmm_param_len + 2);
2872 bss->wmm_ie_len = elems.wmm_param_len + 2;
2873 } else
2874 bss->wmm_ie_len = 0;
Abhijeet Kolekara46f0252008-04-16 14:02:04 -07002875 } else if (elems.wmm_info &&
2876 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_info_len ||
2877 memcmp(bss->wmm_ie, elems.wmm_info, elems.wmm_info_len))) {
2878 /* As for certain AP's Fifth bit is not set in WMM IE in
2879 * beacon frames.So while parsing the beacon frame the
2880 * wmm_info structure is used instead of wmm_param.
2881 * wmm_info structure was never used to set bss->wmm_ie.
2882 * This code fixes this problem by copying the WME
2883 * information from wmm_info to bss->wmm_ie and enabling
2884 * n-band association.
2885 */
2886 kfree(bss->wmm_ie);
2887 bss->wmm_ie = kmalloc(elems.wmm_info_len + 2, GFP_ATOMIC);
2888 if (bss->wmm_ie) {
2889 memcpy(bss->wmm_ie, elems.wmm_info - 2,
2890 elems.wmm_info_len + 2);
2891 bss->wmm_ie_len = elems.wmm_info_len + 2;
2892 } else
2893 bss->wmm_ie_len = 0;
2894 } else if (!elems.wmm_param && !elems.wmm_info && bss->wmm_ie) {
Jiri Bencf0706e82007-05-05 11:45:53 -07002895 kfree(bss->wmm_ie);
2896 bss->wmm_ie = NULL;
2897 bss->wmm_ie_len = 0;
2898 }
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002899
2900 /* check if we need to merge IBSS */
2901 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2902 !local->sta_sw_scanning && !local->sta_hw_scanning &&
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002903 bss->capability & WLAN_CAPABILITY_IBSS &&
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002904 bss->freq == local->oper_channel->center_freq &&
2905 elems.ssid_len == sdata->u.sta.ssid_len &&
2906 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2907 if (rx_status->flag & RX_FLAG_TSFT) {
2908 /* in order for correct IBSS merging we need mactime
2909 *
2910 * since mactime is defined as the time the first data
2911 * symbol of the frame hits the PHY, and the timestamp
2912 * of the beacon is defined as "the time that the data
2913 * symbol containing the first bit of the timestamp is
2914 * transmitted to the PHY plus the transmitting STA’s
2915 * delays through its local PHY from the MAC-PHY
2916 * interface to its interface with the WM"
2917 * (802.11 11.1.2) - equals the time this bit arrives at
2918 * the receiver - we have to take into account the
2919 * offset between the two.
2920 * e.g: at 1 MBit that means mactime is 192 usec earlier
2921 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2922 */
2923 int rate = local->hw.wiphy->bands[rx_status->band]->
2924 bitrates[rx_status->rate_idx].bitrate;
2925 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2926 } else if (local && local->ops && local->ops->get_tsf)
2927 /* second best option: get current TSF */
2928 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2929 else
2930 /* can't merge without knowing the TSF */
2931 rx_timestamp = -1LLU;
2932#ifdef CONFIG_MAC80211_IBSS_DEBUG
2933 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2934 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2935 print_mac(mac, mgmt->sa),
2936 print_mac(mac2, mgmt->bssid),
2937 (unsigned long long)rx_timestamp,
2938 (unsigned long long)beacon_timestamp,
2939 (unsigned long long)(rx_timestamp - beacon_timestamp),
2940 jiffies);
2941#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2942 if (beacon_timestamp > rx_timestamp) {
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002943#ifndef CONFIG_MAC80211_IBSS_DEBUG
Pavel Roskind97cf012008-02-21 11:33:58 -05002944 if (net_ratelimit())
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002945#endif
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002946 printk(KERN_DEBUG "%s: beacon TSF higher than "
2947 "local TSF - IBSS merge with BSSID %s\n",
2948 dev->name, print_mac(mac, mgmt->bssid));
2949 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2950 ieee80211_ibss_add_sta(dev, NULL,
Vladimir Koutny87291c02008-06-13 16:50:44 +02002951 mgmt->bssid, mgmt->sa,
2952 BIT(rx_status->rate_idx));
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002953 }
2954 }
2955
Jiri Bencf0706e82007-05-05 11:45:53 -07002956 ieee80211_rx_bss_put(dev, bss);
2957}
2958
2959
2960static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2961 struct ieee80211_mgmt *mgmt,
2962 size_t len,
2963 struct ieee80211_rx_status *rx_status)
2964{
2965 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2966}
2967
2968
2969static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2970 struct ieee80211_mgmt *mgmt,
2971 size_t len,
2972 struct ieee80211_rx_status *rx_status)
2973{
Jiri Bencf0706e82007-05-05 11:45:53 -07002974 struct ieee80211_sub_if_data *sdata;
2975 struct ieee80211_if_sta *ifsta;
Jiri Bencf0706e82007-05-05 11:45:53 -07002976 size_t baselen;
2977 struct ieee802_11_elems elems;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002978 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2979 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002980 u32 changed = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07002981
2982 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
2983
2984 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01002985 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07002986 return;
2987 ifsta = &sdata->u.sta;
2988
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002989 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
Jiri Bencf0706e82007-05-05 11:45:53 -07002990 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2991 return;
2992
2993 /* Process beacon from the current BSS */
2994 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2995 if (baselen > len)
2996 return;
2997
John W. Linville67a4cce2007-10-12 16:40:37 -04002998 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
Jiri Bencf0706e82007-05-05 11:45:53 -07002999
Johannes Berg3434fbd2008-05-03 00:59:37 +02003000 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
3001 elems.wmm_param_len);
Reinette Chatred18ef292008-04-09 16:56:15 -07003002
3003 /* Do not send changes to driver if we are scanning. This removes
3004 * requirement that driver's bss_info_changed function needs to be
3005 * atomic. */
3006 if (local->sta_sw_scanning || local->sta_hw_scanning)
3007 return;
3008
Daniel Drake56282212007-07-10 19:32:10 +02003009 if (elems.erp_info && elems.erp_info_len >= 1)
Johannes Berg471b3ef2007-12-28 14:32:58 +01003010 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
John W. Linville50c4afb2008-04-15 14:09:27 -04003011 else {
3012 u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info);
3013 changed |= ieee80211_handle_protect_preamb(sdata, false,
3014 (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
3015 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003016
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003017 if (elems.ht_cap_elem && elems.ht_info_elem &&
Tomas Winkler38668c02008-03-28 16:33:32 -07003018 elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003019 struct ieee80211_ht_bss_info bss_info;
3020
3021 ieee80211_ht_addt_info_ie_to_ht_bss_info(
3022 (struct ieee80211_ht_addt_info *)
3023 elems.ht_info_elem, &bss_info);
Tomas Winkler38668c02008-03-28 16:33:32 -07003024 changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf,
3025 &bss_info);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003026 }
3027
Johannes Berg471b3ef2007-12-28 14:32:58 +01003028 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003029}
3030
3031
3032static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
3033 struct ieee80211_if_sta *ifsta,
3034 struct ieee80211_mgmt *mgmt,
3035 size_t len,
3036 struct ieee80211_rx_status *rx_status)
3037{
3038 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3039 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3040 int tx_last_beacon;
3041 struct sk_buff *skb;
3042 struct ieee80211_mgmt *resp;
3043 u8 *pos, *end;
Joe Perches0795af52007-10-03 17:59:30 -07003044 DECLARE_MAC_BUF(mac);
3045#ifdef CONFIG_MAC80211_IBSS_DEBUG
3046 DECLARE_MAC_BUF(mac2);
3047 DECLARE_MAC_BUF(mac3);
3048#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07003049
Johannes Berg51fb61e2007-12-19 01:31:27 +01003050 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
Jiri Bencf0706e82007-05-05 11:45:53 -07003051 ifsta->state != IEEE80211_IBSS_JOINED ||
3052 len < 24 + 2 || !ifsta->probe_resp)
3053 return;
3054
3055 if (local->ops->tx_last_beacon)
3056 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
3057 else
3058 tx_last_beacon = 1;
3059
3060#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003061 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
3062 "%s (tx_last_beacon=%d)\n",
3063 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
3064 print_mac(mac3, mgmt->bssid), tx_last_beacon);
Jiri Bencf0706e82007-05-05 11:45:53 -07003065#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3066
3067 if (!tx_last_beacon)
3068 return;
3069
3070 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
3071 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
3072 return;
3073
3074 end = ((u8 *) mgmt) + len;
3075 pos = mgmt->u.probe_req.variable;
3076 if (pos[0] != WLAN_EID_SSID ||
3077 pos + 2 + pos[1] > end) {
3078 if (net_ratelimit()) {
3079 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
Joe Perches0795af52007-10-03 17:59:30 -07003080 "from %s\n",
3081 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e82007-05-05 11:45:53 -07003082 }
3083 return;
3084 }
3085 if (pos[1] != 0 &&
3086 (pos[1] != ifsta->ssid_len ||
3087 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
3088 /* Ignore ProbeReq for foreign SSID */
3089 return;
3090 }
3091
3092 /* Reply with ProbeResp */
Michael Wu0ec0b7a2007-07-27 15:43:24 +02003093 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07003094 if (!skb)
3095 return;
3096
3097 resp = (struct ieee80211_mgmt *) skb->data;
3098 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3099#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003100 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
3101 dev->name, print_mac(mac, resp->da));
Jiri Bencf0706e82007-05-05 11:45:53 -07003102#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3103 ieee80211_sta_tx(dev, skb, 0);
3104}
3105
Johannes Berg4e20cb22007-12-19 01:31:24 +01003106static void ieee80211_rx_mgmt_action(struct net_device *dev,
3107 struct ieee80211_if_sta *ifsta,
3108 struct ieee80211_mgmt *mgmt,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003109 size_t len,
3110 struct ieee80211_rx_status *rx_status)
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003111{
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003112 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Assaf Kraussb6623482008-06-16 16:09:49 +03003113 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003114
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003115 if (len < IEEE80211_MIN_ACTION_SIZE)
3116 return;
3117
3118 switch (mgmt->u.action.category) {
Assaf Kraussb6623482008-06-16 16:09:49 +03003119 case WLAN_CATEGORY_SPECTRUM_MGMT:
3120 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
3121 break;
3122 switch (mgmt->u.action.u.chan_switch.action_code) {
3123 case WLAN_ACTION_SPCT_MSR_REQ:
3124 if (len < (IEEE80211_MIN_ACTION_SIZE +
3125 sizeof(mgmt->u.action.u.measurement)))
3126 break;
3127 ieee80211_sta_process_measurement_req(dev, mgmt, len);
3128 break;
3129 }
3130 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003131 case WLAN_CATEGORY_BACK:
3132 switch (mgmt->u.action.u.addba_req.action_code) {
3133 case WLAN_ACTION_ADDBA_REQ:
3134 if (len < (IEEE80211_MIN_ACTION_SIZE +
3135 sizeof(mgmt->u.action.u.addba_req)))
3136 break;
3137 ieee80211_sta_process_addba_request(dev, mgmt, len);
3138 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02003139 case WLAN_ACTION_ADDBA_RESP:
3140 if (len < (IEEE80211_MIN_ACTION_SIZE +
3141 sizeof(mgmt->u.action.u.addba_resp)))
3142 break;
3143 ieee80211_sta_process_addba_resp(dev, mgmt, len);
3144 break;
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02003145 case WLAN_ACTION_DELBA:
3146 if (len < (IEEE80211_MIN_ACTION_SIZE +
3147 sizeof(mgmt->u.action.u.delba)))
3148 break;
3149 ieee80211_sta_process_delba(dev, mgmt, len);
3150 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003151 default:
3152 if (net_ratelimit())
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02003153 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003154 dev->name);
3155 break;
3156 }
3157 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003158 case PLINK_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01003159 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003160 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
3161 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003162 case MESH_PATH_SEL_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01003163 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003164 mesh_rx_path_sel_frame(dev, mgmt, len);
3165 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003166 default:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003167 if (net_ratelimit())
3168 printk(KERN_DEBUG "%s: Rx unknown action frame - "
3169 "category=%d\n", dev->name, mgmt->u.action.category);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003170 break;
3171 }
3172}
Jiri Bencf0706e82007-05-05 11:45:53 -07003173
3174void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
3175 struct ieee80211_rx_status *rx_status)
3176{
3177 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3178 struct ieee80211_sub_if_data *sdata;
3179 struct ieee80211_if_sta *ifsta;
3180 struct ieee80211_mgmt *mgmt;
3181 u16 fc;
3182
3183 if (skb->len < 24)
3184 goto fail;
3185
3186 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3187 ifsta = &sdata->u.sta;
3188
3189 mgmt = (struct ieee80211_mgmt *) skb->data;
3190 fc = le16_to_cpu(mgmt->frame_control);
3191
3192 switch (fc & IEEE80211_FCTL_STYPE) {
3193 case IEEE80211_STYPE_PROBE_REQ:
3194 case IEEE80211_STYPE_PROBE_RESP:
3195 case IEEE80211_STYPE_BEACON:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003196 case IEEE80211_STYPE_ACTION:
Jiri Bencf0706e82007-05-05 11:45:53 -07003197 memcpy(skb->cb, rx_status, sizeof(*rx_status));
3198 case IEEE80211_STYPE_AUTH:
3199 case IEEE80211_STYPE_ASSOC_RESP:
3200 case IEEE80211_STYPE_REASSOC_RESP:
3201 case IEEE80211_STYPE_DEAUTH:
3202 case IEEE80211_STYPE_DISASSOC:
3203 skb_queue_tail(&ifsta->skb_queue, skb);
3204 queue_work(local->hw.workqueue, &ifsta->work);
3205 return;
3206 default:
3207 printk(KERN_DEBUG "%s: received unknown management frame - "
3208 "stype=%d\n", dev->name,
3209 (fc & IEEE80211_FCTL_STYPE) >> 4);
3210 break;
3211 }
3212
3213 fail:
3214 kfree_skb(skb);
3215}
3216
3217
3218static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
3219 struct sk_buff *skb)
3220{
3221 struct ieee80211_rx_status *rx_status;
3222 struct ieee80211_sub_if_data *sdata;
3223 struct ieee80211_if_sta *ifsta;
3224 struct ieee80211_mgmt *mgmt;
3225 u16 fc;
3226
3227 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3228 ifsta = &sdata->u.sta;
3229
3230 rx_status = (struct ieee80211_rx_status *) skb->cb;
3231 mgmt = (struct ieee80211_mgmt *) skb->data;
3232 fc = le16_to_cpu(mgmt->frame_control);
3233
3234 switch (fc & IEEE80211_FCTL_STYPE) {
3235 case IEEE80211_STYPE_PROBE_REQ:
3236 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
3237 rx_status);
3238 break;
3239 case IEEE80211_STYPE_PROBE_RESP:
3240 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
3241 break;
3242 case IEEE80211_STYPE_BEACON:
3243 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
3244 break;
3245 case IEEE80211_STYPE_AUTH:
3246 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
3247 break;
3248 case IEEE80211_STYPE_ASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003249 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003250 break;
3251 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003252 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
Jiri Bencf0706e82007-05-05 11:45:53 -07003253 break;
3254 case IEEE80211_STYPE_DEAUTH:
3255 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
3256 break;
3257 case IEEE80211_STYPE_DISASSOC:
3258 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
3259 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003260 case IEEE80211_STYPE_ACTION:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003261 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003262 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07003263 }
3264
3265 kfree_skb(skb);
3266}
3267
3268
Johannes Berg9ae54c82008-01-31 19:48:20 +01003269ieee80211_rx_result
Zhu Yiece8edd2007-11-22 10:53:21 +08003270ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
3271 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003272{
3273 struct ieee80211_mgmt *mgmt;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003274 __le16 fc;
Jiri Bencf0706e82007-05-05 11:45:53 -07003275
Zhu Yiece8edd2007-11-22 10:53:21 +08003276 if (skb->len < 2)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003277 return RX_DROP_UNUSABLE;
Jiri Bencf0706e82007-05-05 11:45:53 -07003278
3279 mgmt = (struct ieee80211_mgmt *) skb->data;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003280 fc = mgmt->frame_control;
Jiri Bencf0706e82007-05-05 11:45:53 -07003281
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003282 if (ieee80211_is_ctl(fc))
Johannes Berg9ae54c82008-01-31 19:48:20 +01003283 return RX_CONTINUE;
Zhu Yiece8edd2007-11-22 10:53:21 +08003284
3285 if (skb->len < 24)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003286 return RX_DROP_MONITOR;
Zhu Yiece8edd2007-11-22 10:53:21 +08003287
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003288 if (ieee80211_is_probe_resp(fc)) {
3289 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
3290 dev_kfree_skb(skb);
3291 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07003292 }
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003293
3294 if (ieee80211_is_beacon(fc)) {
3295 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
3296 dev_kfree_skb(skb);
3297 return RX_QUEUED;
3298 }
3299
Johannes Berg9ae54c82008-01-31 19:48:20 +01003300 return RX_CONTINUE;
Jiri Bencf0706e82007-05-05 11:45:53 -07003301}
3302
3303
3304static int ieee80211_sta_active_ibss(struct net_device *dev)
3305{
3306 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3307 int active = 0;
3308 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +01003309 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07003310
Johannes Bergd0709a62008-02-25 16:27:46 +01003311 rcu_read_lock();
3312
3313 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3314 if (sta->sdata == sdata &&
Jiri Bencf0706e82007-05-05 11:45:53 -07003315 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
3316 jiffies)) {
3317 active++;
3318 break;
3319 }
3320 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003321
3322 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07003323
3324 return active;
3325}
3326
3327
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003328static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
Jiri Bencf0706e82007-05-05 11:45:53 -07003329{
3330 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3331 struct sta_info *sta, *tmp;
Michael Wube8755e2007-07-27 15:43:23 +02003332 LIST_HEAD(tmp_list);
Joe Perches0795af52007-10-03 17:59:30 -07003333 DECLARE_MAC_BUF(mac);
Johannes Bergd0709a62008-02-25 16:27:46 +01003334 unsigned long flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07003335
Johannes Bergd0709a62008-02-25 16:27:46 +01003336 spin_lock_irqsave(&local->sta_lock, flags);
Jiri Bencf0706e82007-05-05 11:45:53 -07003337 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003338 if (time_after(jiffies, sta->last_rx + exp_time)) {
Joe Perches0795af52007-10-03 17:59:30 -07003339 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
3340 dev->name, print_mac(mac, sta->addr));
Luis Carlos Cobocb585bc2008-03-31 15:21:23 -07003341 __sta_info_unlink(&sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01003342 if (sta)
3343 list_add(&sta->list, &tmp_list);
Jiri Bencf0706e82007-05-05 11:45:53 -07003344 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003345 spin_unlock_irqrestore(&local->sta_lock, flags);
Michael Wube8755e2007-07-27 15:43:23 +02003346
Johannes Bergd0709a62008-02-25 16:27:46 +01003347 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
3348 sta_info_destroy(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003349}
3350
3351
3352static void ieee80211_sta_merge_ibss(struct net_device *dev,
3353 struct ieee80211_if_sta *ifsta)
3354{
3355 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
3356
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003357 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
Jiri Bencf0706e82007-05-05 11:45:53 -07003358 if (ieee80211_sta_active_ibss(dev))
3359 return;
3360
3361 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
3362 "IBSS networks with same SSID (merge)\n", dev->name);
3363 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
3364}
3365
3366
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003367#ifdef CONFIG_MAC80211_MESH
3368static void ieee80211_mesh_housekeeping(struct net_device *dev,
3369 struct ieee80211_if_sta *ifsta)
3370{
3371 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3372 bool free_plinks;
3373
3374 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3375 mesh_path_expire(dev);
3376
3377 free_plinks = mesh_plink_availables(sdata);
3378 if (free_plinks != sdata->u.sta.accepting_plinks)
3379 ieee80211_if_config_beacon(dev);
3380
3381 mod_timer(&ifsta->timer, jiffies +
3382 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3383}
3384
3385
3386void ieee80211_start_mesh(struct net_device *dev)
3387{
3388 struct ieee80211_if_sta *ifsta;
3389 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3390 ifsta = &sdata->u.sta;
3391 ifsta->state = IEEE80211_MESH_UP;
3392 ieee80211_sta_timer((unsigned long)sdata);
3393}
3394#endif
3395
3396
Jiri Bencf0706e82007-05-05 11:45:53 -07003397void ieee80211_sta_timer(unsigned long data)
3398{
3399 struct ieee80211_sub_if_data *sdata =
3400 (struct ieee80211_sub_if_data *) data;
3401 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3402 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
3403
3404 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3405 queue_work(local->hw.workqueue, &ifsta->work);
3406}
3407
Jiri Bencf0706e82007-05-05 11:45:53 -07003408void ieee80211_sta_work(struct work_struct *work)
3409{
3410 struct ieee80211_sub_if_data *sdata =
3411 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
3412 struct net_device *dev = sdata->dev;
3413 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3414 struct ieee80211_if_sta *ifsta;
3415 struct sk_buff *skb;
3416
3417 if (!netif_running(dev))
3418 return;
3419
Zhu Yiece8edd2007-11-22 10:53:21 +08003420 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -07003421 return;
3422
Johannes Berg51fb61e2007-12-19 01:31:27 +01003423 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003424 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3425 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003426 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
Johannes Berg51fb61e2007-12-19 01:31:27 +01003427 "(type=%d)\n", dev->name, sdata->vif.type);
Jiri Bencf0706e82007-05-05 11:45:53 -07003428 return;
3429 }
3430 ifsta = &sdata->u.sta;
3431
3432 while ((skb = skb_dequeue(&ifsta->skb_queue)))
3433 ieee80211_sta_rx_queued_mgmt(dev, skb);
3434
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003435#ifdef CONFIG_MAC80211_MESH
Johannes Berg902acc72008-02-23 15:17:19 +01003436 if (ifsta->preq_queue_len &&
3437 time_after(jiffies,
3438 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003439 mesh_path_start_discovery(dev);
3440#endif
3441
Jiri Bencf0706e82007-05-05 11:45:53 -07003442 if (ifsta->state != IEEE80211_AUTHENTICATE &&
3443 ifsta->state != IEEE80211_ASSOCIATE &&
3444 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
Helmut Schaaa0af5f12007-11-09 16:25:08 +01003445 if (ifsta->scan_ssid_len)
3446 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
3447 else
3448 ieee80211_sta_start_scan(dev, NULL, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003449 return;
3450 }
3451
3452 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
3453 if (ieee80211_sta_config_auth(dev, ifsta))
3454 return;
3455 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3456 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3457 return;
3458
3459 switch (ifsta->state) {
3460 case IEEE80211_DISABLED:
3461 break;
3462 case IEEE80211_AUTHENTICATE:
3463 ieee80211_authenticate(dev, ifsta);
3464 break;
3465 case IEEE80211_ASSOCIATE:
3466 ieee80211_associate(dev, ifsta);
3467 break;
3468 case IEEE80211_ASSOCIATED:
3469 ieee80211_associated(dev, ifsta);
3470 break;
3471 case IEEE80211_IBSS_SEARCH:
3472 ieee80211_sta_find_ibss(dev, ifsta);
3473 break;
3474 case IEEE80211_IBSS_JOINED:
3475 ieee80211_sta_merge_ibss(dev, ifsta);
3476 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003477#ifdef CONFIG_MAC80211_MESH
3478 case IEEE80211_MESH_UP:
3479 ieee80211_mesh_housekeeping(dev, ifsta);
3480 break;
3481#endif
Jiri Bencf0706e82007-05-05 11:45:53 -07003482 default:
3483 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
3484 ifsta->state);
3485 break;
3486 }
3487
3488 if (ieee80211_privacy_mismatch(dev, ifsta)) {
3489 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
3490 "mixed-cell disabled - disassociate\n", dev->name);
3491
3492 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
3493 ieee80211_set_disassoc(dev, ifsta, 0);
3494 }
3495}
3496
3497
3498static void ieee80211_sta_reset_auth(struct net_device *dev,
3499 struct ieee80211_if_sta *ifsta)
3500{
3501 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3502
3503 if (local->ops->reset_tsf) {
3504 /* Reset own TSF to allow time synchronization work. */
3505 local->ops->reset_tsf(local_to_hw(local));
3506 }
3507
3508 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3509
3510
3511 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3512 ifsta->auth_alg = WLAN_AUTH_OPEN;
3513 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3514 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3515 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3516 ifsta->auth_alg = WLAN_AUTH_LEAP;
3517 else
3518 ifsta->auth_alg = WLAN_AUTH_OPEN;
3519 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
3520 ifsta->auth_alg);
3521 ifsta->auth_transaction = -1;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003522 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
3523 ifsta->auth_tries = ifsta->assoc_tries = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07003524 netif_carrier_off(dev);
3525}
3526
3527
3528void ieee80211_sta_req_auth(struct net_device *dev,
3529 struct ieee80211_if_sta *ifsta)
3530{
3531 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3532 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3533
Johannes Berg51fb61e2007-12-19 01:31:27 +01003534 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07003535 return;
3536
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003537 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3538 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3539 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3540 IEEE80211_STA_AUTO_SSID_SEL))) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003541 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3542 queue_work(local->hw.workqueue, &ifsta->work);
3543 }
3544}
3545
3546static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3547 const char *ssid, int ssid_len)
3548{
3549 int tmp, hidden_ssid;
3550
Michael Wu48225702007-10-19 17:14:36 -04003551 if (ssid_len == ifsta->ssid_len &&
3552 !memcmp(ifsta->ssid, ssid, ssid_len))
Jiri Bencf0706e82007-05-05 11:45:53 -07003553 return 1;
3554
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003555 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Jiri Bencf0706e82007-05-05 11:45:53 -07003556 return 0;
3557
3558 hidden_ssid = 1;
3559 tmp = ssid_len;
3560 while (tmp--) {
3561 if (ssid[tmp] != '\0') {
3562 hidden_ssid = 0;
3563 break;
3564 }
3565 }
3566
3567 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3568 return 1;
3569
3570 if (ssid_len == 1 && ssid[0] == ' ')
3571 return 1;
3572
3573 return 0;
3574}
3575
3576static int ieee80211_sta_config_auth(struct net_device *dev,
3577 struct ieee80211_if_sta *ifsta)
3578{
3579 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3580 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3581 struct ieee80211_sta_bss *bss, *selected = NULL;
3582 int top_rssi = 0, freq;
3583
Jiri Bencf0706e82007-05-05 11:45:53 -07003584 spin_lock_bh(&local->sta_bss_lock);
Johannes Berg8318d782008-01-24 19:38:38 +01003585 freq = local->oper_channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -07003586 list_for_each_entry(bss, &local->sta_bss_list, list) {
3587 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3588 continue;
3589
Abhijeet Kolekar34a961f2008-05-09 09:35:41 -07003590 if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3591 IEEE80211_STA_AUTO_BSSID_SEL |
3592 IEEE80211_STA_AUTO_CHANNEL_SEL)) &&
3593 (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3594 !!sdata->default_key))
Jiri Bencf0706e82007-05-05 11:45:53 -07003595 continue;
3596
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003597 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3598 bss->freq != freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07003599 continue;
3600
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003601 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
Jiri Bencf0706e82007-05-05 11:45:53 -07003602 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3603 continue;
3604
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003605 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
Jiri Bencf0706e82007-05-05 11:45:53 -07003606 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3607 continue;
3608
Bruno Randolf566bfe52008-05-08 19:15:40 +02003609 if (!selected || top_rssi < bss->signal) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003610 selected = bss;
Bruno Randolf566bfe52008-05-08 19:15:40 +02003611 top_rssi = bss->signal;
Jiri Bencf0706e82007-05-05 11:45:53 -07003612 }
3613 }
3614 if (selected)
3615 atomic_inc(&selected->users);
3616 spin_unlock_bh(&local->sta_bss_lock);
3617
3618 if (selected) {
Assaf Kraussbe038b32008-06-05 19:55:21 +03003619 ieee80211_set_freq(dev, selected->freq);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003620 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
Jiri Bencf0706e82007-05-05 11:45:53 -07003621 ieee80211_sta_set_ssid(dev, selected->ssid,
3622 selected->ssid_len);
3623 ieee80211_sta_set_bssid(dev, selected->bssid);
Vladimir Koutnye2839d82008-03-18 21:14:07 +01003624 ieee80211_sta_def_wmm_params(dev, selected, 0);
Jiri Bencf0706e82007-05-05 11:45:53 -07003625 ieee80211_rx_bss_put(dev, selected);
3626 ifsta->state = IEEE80211_AUTHENTICATE;
Jiri Bencf0706e82007-05-05 11:45:53 -07003627 ieee80211_sta_reset_auth(dev, ifsta);
3628 return 0;
3629 } else {
3630 if (ifsta->state != IEEE80211_AUTHENTICATE) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003631 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
John W. Linvilleb9bf1e62007-08-07 16:33:15 -04003632 ieee80211_sta_start_scan(dev, NULL, 0);
3633 else
3634 ieee80211_sta_start_scan(dev, ifsta->ssid,
3635 ifsta->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07003636 ifsta->state = IEEE80211_AUTHENTICATE;
3637 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3638 } else
3639 ifsta->state = IEEE80211_DISABLED;
3640 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003641 return -1;
3642}
3643
Jiri Bencf0706e82007-05-05 11:45:53 -07003644
3645static int ieee80211_sta_create_ibss(struct net_device *dev,
3646 struct ieee80211_if_sta *ifsta)
3647{
3648 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3649 struct ieee80211_sta_bss *bss;
John W. Linvillecffdd302007-10-05 14:23:27 -04003650 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +01003651 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003652 u8 bssid[ETH_ALEN], *pos;
3653 int i;
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003654 int ret;
Joe Perches0795af52007-10-03 17:59:30 -07003655 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -07003656
3657#if 0
3658 /* Easier testing, use fixed BSSID. */
3659 memset(bssid, 0xfe, ETH_ALEN);
3660#else
3661 /* Generate random, not broadcast, locally administered BSSID. Mix in
3662 * own MAC address to make sure that devices that do not have proper
3663 * random number generator get different BSSID. */
3664 get_random_bytes(bssid, ETH_ALEN);
3665 for (i = 0; i < ETH_ALEN; i++)
3666 bssid[i] ^= dev->dev_addr[i];
3667 bssid[0] &= ~0x01;
3668 bssid[0] |= 0x02;
3669#endif
3670
Joe Perches0795af52007-10-03 17:59:30 -07003671 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3672 dev->name, print_mac(mac, bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07003673
Johannes Berg8318d782008-01-24 19:38:38 +01003674 bss = ieee80211_rx_bss_add(dev, bssid,
3675 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04003676 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07003677 if (!bss)
3678 return -ENOMEM;
3679
Johannes Berg8318d782008-01-24 19:38:38 +01003680 bss->band = local->hw.conf.channel->band;
3681 sband = local->hw.wiphy->bands[bss->band];
Jiri Bencf0706e82007-05-05 11:45:53 -07003682
3683 if (local->hw.conf.beacon_int == 0)
Tomas Winklerdc0ae302008-06-12 22:38:37 +03003684 local->hw.conf.beacon_int = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -07003685 bss->beacon_int = local->hw.conf.beacon_int;
Jiri Bencf0706e82007-05-05 11:45:53 -07003686 bss->last_update = jiffies;
3687 bss->capability = WLAN_CAPABILITY_IBSS;
Johannes Berg988c0f72008-04-17 19:21:22 +02003688
3689 if (sdata->default_key)
Jiri Bencf0706e82007-05-05 11:45:53 -07003690 bss->capability |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg988c0f72008-04-17 19:21:22 +02003691 else
Jiri Bencf0706e82007-05-05 11:45:53 -07003692 sdata->drop_unencrypted = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02003693
Johannes Berg8318d782008-01-24 19:38:38 +01003694 bss->supp_rates_len = sband->n_bitrates;
Jiri Bencf0706e82007-05-05 11:45:53 -07003695 pos = bss->supp_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01003696 for (i = 0; i < sband->n_bitrates; i++) {
3697 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e82007-05-05 11:45:53 -07003698 *pos++ = (u8) (rate / 5);
3699 }
3700
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003701 ret = ieee80211_sta_join_ibss(dev, ifsta, bss);
3702 ieee80211_rx_bss_put(dev, bss);
3703 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003704}
3705
3706
3707static int ieee80211_sta_find_ibss(struct net_device *dev,
3708 struct ieee80211_if_sta *ifsta)
3709{
3710 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3711 struct ieee80211_sta_bss *bss;
3712 int found = 0;
3713 u8 bssid[ETH_ALEN];
3714 int active_ibss;
Joe Perches0795af52007-10-03 17:59:30 -07003715 DECLARE_MAC_BUF(mac);
3716 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e82007-05-05 11:45:53 -07003717
3718 if (ifsta->ssid_len == 0)
3719 return -EINVAL;
3720
3721 active_ibss = ieee80211_sta_active_ibss(dev);
3722#ifdef CONFIG_MAC80211_IBSS_DEBUG
3723 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
3724 dev->name, active_ibss);
3725#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3726 spin_lock_bh(&local->sta_bss_lock);
3727 list_for_each_entry(bss, &local->sta_bss_list, list) {
3728 if (ifsta->ssid_len != bss->ssid_len ||
3729 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3730 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3731 continue;
3732#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003733 printk(KERN_DEBUG " bssid=%s found\n",
3734 print_mac(mac, bss->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07003735#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3736 memcpy(bssid, bss->bssid, ETH_ALEN);
3737 found = 1;
3738 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3739 break;
3740 }
3741 spin_unlock_bh(&local->sta_bss_lock);
3742
3743#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003744 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3745 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
Jiri Bencf0706e82007-05-05 11:45:53 -07003746#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3747 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
Johannes Berg8318d782008-01-24 19:38:38 +01003748 (bss = ieee80211_rx_bss_get(dev, bssid,
3749 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04003750 ifsta->ssid, ifsta->ssid_len))) {
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003751 int ret;
Joe Perches0795af52007-10-03 17:59:30 -07003752 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
Jiri Bencf0706e82007-05-05 11:45:53 -07003753 " based on configured SSID\n",
Joe Perches0795af52007-10-03 17:59:30 -07003754 dev->name, print_mac(mac, bssid));
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003755 ret = ieee80211_sta_join_ibss(dev, ifsta, bss);
3756 ieee80211_rx_bss_put(dev, bss);
3757 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003758 }
3759#ifdef CONFIG_MAC80211_IBSS_DEBUG
3760 printk(KERN_DEBUG " did not try to join ibss\n");
3761#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3762
3763 /* Selected IBSS not found in current scan results - try to scan */
3764 if (ifsta->state == IEEE80211_IBSS_JOINED &&
3765 !ieee80211_sta_active_ibss(dev)) {
3766 mod_timer(&ifsta->timer, jiffies +
3767 IEEE80211_IBSS_MERGE_INTERVAL);
3768 } else if (time_after(jiffies, local->last_scan_completed +
3769 IEEE80211_SCAN_INTERVAL)) {
3770 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
3771 "join\n", dev->name);
3772 return ieee80211_sta_req_scan(dev, ifsta->ssid,
3773 ifsta->ssid_len);
3774 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
3775 int interval = IEEE80211_SCAN_INTERVAL;
3776
3777 if (time_after(jiffies, ifsta->ibss_join_req +
3778 IEEE80211_IBSS_JOIN_TIMEOUT)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003779 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
Johannes Berg8318d782008-01-24 19:38:38 +01003780 (!(local->oper_channel->flags &
3781 IEEE80211_CHAN_NO_IBSS)))
Jiri Bencf0706e82007-05-05 11:45:53 -07003782 return ieee80211_sta_create_ibss(dev, ifsta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003783 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
Johannes Berg8318d782008-01-24 19:38:38 +01003784 printk(KERN_DEBUG "%s: IBSS not allowed on"
3785 " %d MHz\n", dev->name,
3786 local->hw.conf.channel->center_freq);
Jiri Bencf0706e82007-05-05 11:45:53 -07003787 }
3788
3789 /* No IBSS found - decrease scan interval and continue
3790 * scanning. */
3791 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3792 }
3793
3794 ifsta->state = IEEE80211_IBSS_SEARCH;
3795 mod_timer(&ifsta->timer, jiffies + interval);
3796 return 0;
3797 }
3798
3799 return 0;
3800}
3801
3802
3803int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3804{
Johannes Berg8318d782008-01-24 19:38:38 +01003805 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07003806 struct ieee80211_if_sta *ifsta;
Jiri Bencf0706e82007-05-05 11:45:53 -07003807
3808 if (len > IEEE80211_MAX_SSID_LEN)
3809 return -EINVAL;
3810
Jiri Bencf0706e82007-05-05 11:45:53 -07003811 ifsta = &sdata->u.sta;
3812
3813 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003814 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -07003815 memcpy(ifsta->ssid, ssid, len);
3816 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3817 ifsta->ssid_len = len;
3818
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003819 if (len)
3820 ifsta->flags |= IEEE80211_STA_SSID_SET;
3821 else
3822 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
Johannes Berg51fb61e2007-12-19 01:31:27 +01003823 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003824 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003825 ifsta->ibss_join_req = jiffies;
3826 ifsta->state = IEEE80211_IBSS_SEARCH;
3827 return ieee80211_sta_find_ibss(dev, ifsta);
3828 }
3829 return 0;
3830}
3831
3832
3833int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3834{
3835 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3836 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3837 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3838 *len = ifsta->ssid_len;
3839 return 0;
3840}
3841
3842
3843int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3844{
3845 struct ieee80211_sub_if_data *sdata;
3846 struct ieee80211_if_sta *ifsta;
3847 int res;
3848
3849 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3850 ifsta = &sdata->u.sta;
3851
3852 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3853 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3854 res = ieee80211_if_config(dev);
3855 if (res) {
3856 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3857 "the low-level driver\n", dev->name);
3858 return res;
3859 }
3860 }
3861
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003862 if (is_valid_ether_addr(bssid))
3863 ifsta->flags |= IEEE80211_STA_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -07003864 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003865 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3866
Jiri Bencf0706e82007-05-05 11:45:53 -07003867 return 0;
3868}
3869
3870
3871static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3872 struct ieee80211_sub_if_data *sdata,
3873 int powersave)
3874{
3875 struct sk_buff *skb;
3876 struct ieee80211_hdr *nullfunc;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003877 __le16 fc;
Jiri Bencf0706e82007-05-05 11:45:53 -07003878
3879 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3880 if (!skb) {
3881 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3882 "frame\n", sdata->dev->name);
3883 return;
3884 }
3885 skb_reserve(skb, local->hw.extra_tx_headroom);
3886
3887 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3888 memset(nullfunc, 0, 24);
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003889 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3890 IEEE80211_FCTL_TODS);
Jiri Bencf0706e82007-05-05 11:45:53 -07003891 if (powersave)
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003892 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
3893 nullfunc->frame_control = fc;
Jiri Bencf0706e82007-05-05 11:45:53 -07003894 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3895 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3896 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3897
3898 ieee80211_sta_tx(sdata->dev, skb, 0);
3899}
3900
3901
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003902static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3903{
3904 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3905 ieee80211_vif_is_mesh(&sdata->vif))
3906 ieee80211_sta_timer((unsigned long)sdata);
3907}
3908
Jiri Bencf0706e82007-05-05 11:45:53 -07003909void ieee80211_scan_completed(struct ieee80211_hw *hw)
3910{
3911 struct ieee80211_local *local = hw_to_local(hw);
3912 struct net_device *dev = local->scan_dev;
3913 struct ieee80211_sub_if_data *sdata;
3914 union iwreq_data wrqu;
3915
3916 local->last_scan_completed = jiffies;
Zhu Yiece8edd2007-11-22 10:53:21 +08003917 memset(&wrqu, 0, sizeof(wrqu));
3918 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -07003919
Zhu Yiece8edd2007-11-22 10:53:21 +08003920 if (local->sta_hw_scanning) {
3921 local->sta_hw_scanning = 0;
Mohamed Abbas675ef582008-03-20 08:14:29 -07003922 if (ieee80211_hw_config(local))
3923 printk(KERN_DEBUG "%s: failed to restore operational "
3924 "channel after scan\n", dev->name);
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003925 /* Restart STA timer for HW scan case */
3926 rcu_read_lock();
3927 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3928 ieee80211_restart_sta_timer(sdata);
3929 rcu_read_unlock();
3930
Zhu Yiece8edd2007-11-22 10:53:21 +08003931 goto done;
3932 }
3933
3934 local->sta_sw_scanning = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07003935 if (ieee80211_hw_config(local))
Bruno Randolf4b50e382007-11-16 17:04:01 +09003936 printk(KERN_DEBUG "%s: failed to restore operational "
Jiri Bencf0706e82007-05-05 11:45:53 -07003937 "channel after scan\n", dev->name);
3938
Johannes Berg4150c572007-09-17 01:29:23 -04003939
3940 netif_tx_lock_bh(local->mdev);
3941 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3942 local->ops->configure_filter(local_to_hw(local),
3943 FIF_BCN_PRBRESP_PROMISC,
3944 &local->filter_flags,
3945 local->mdev->mc_count,
3946 local->mdev->mc_list);
3947
3948 netif_tx_unlock_bh(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -07003949
Johannes Berg79010422007-09-18 17:29:21 -04003950 rcu_read_lock();
3951 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Mattias Nissler14042cbe2007-06-08 15:31:13 +02003952
3953 /* No need to wake the master device. */
3954 if (sdata->dev == local->mdev)
3955 continue;
3956
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003957 /* Tell AP we're back */
3958 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3959 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3960 ieee80211_send_nullfunc(local, sdata, 0);
Mattias Nissler14042cbe2007-06-08 15:31:13 +02003961
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003962 ieee80211_restart_sta_timer(sdata);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003963
Jiri Bencf0706e82007-05-05 11:45:53 -07003964 netif_wake_queue(sdata->dev);
3965 }
Johannes Berg79010422007-09-18 17:29:21 -04003966 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07003967
Zhu Yiece8edd2007-11-22 10:53:21 +08003968done:
Jiri Bencf0706e82007-05-05 11:45:53 -07003969 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01003970 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07003971 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003972 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
Jiri Bencf0706e82007-05-05 11:45:53 -07003973 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3974 !ieee80211_sta_active_ibss(dev)))
3975 ieee80211_sta_find_ibss(dev, ifsta);
3976 }
3977}
3978EXPORT_SYMBOL(ieee80211_scan_completed);
3979
3980void ieee80211_sta_scan_work(struct work_struct *work)
3981{
3982 struct ieee80211_local *local =
3983 container_of(work, struct ieee80211_local, scan_work.work);
3984 struct net_device *dev = local->scan_dev;
3985 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +01003986 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003987 struct ieee80211_channel *chan;
3988 int skip;
3989 unsigned long next_delay = 0;
3990
Zhu Yiece8edd2007-11-22 10:53:21 +08003991 if (!local->sta_sw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -07003992 return;
3993
3994 switch (local->scan_state) {
3995 case SCAN_SET_CHANNEL:
Johannes Berg69d464d2008-01-28 17:08:56 +01003996 /*
3997 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3998 * after we successfully scanned the last channel of the last
3999 * band (and the last band is supported by the hw)
4000 */
Johannes Berg8318d782008-01-24 19:38:38 +01004001 if (local->scan_band < IEEE80211_NUM_BANDS)
4002 sband = local->hw.wiphy->bands[local->scan_band];
4003 else
4004 sband = NULL;
4005
Johannes Berg69d464d2008-01-28 17:08:56 +01004006 /*
4007 * If we are at an unsupported band and have more bands
4008 * left to scan, advance to the next supported one.
4009 */
4010 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
Johannes Berg8318d782008-01-24 19:38:38 +01004011 local->scan_band++;
4012 sband = local->hw.wiphy->bands[local->scan_band];
4013 local->scan_channel_idx = 0;
4014 }
4015
Johannes Berg69d464d2008-01-28 17:08:56 +01004016 /* if no more bands/channels left, complete scan */
4017 if (!sband || local->scan_channel_idx >= sband->n_channels) {
Jiri Bencf0706e82007-05-05 11:45:53 -07004018 ieee80211_scan_completed(local_to_hw(local));
4019 return;
4020 }
Johannes Berg8318d782008-01-24 19:38:38 +01004021 skip = 0;
4022 chan = &sband->channels[local->scan_channel_idx];
4023
4024 if (chan->flags & IEEE80211_CHAN_DISABLED ||
Johannes Berg51fb61e2007-12-19 01:31:27 +01004025 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Johannes Berg8318d782008-01-24 19:38:38 +01004026 chan->flags & IEEE80211_CHAN_NO_IBSS))
Jiri Bencf0706e82007-05-05 11:45:53 -07004027 skip = 1;
4028
4029 if (!skip) {
Jiri Bencf0706e82007-05-05 11:45:53 -07004030 local->scan_channel = chan;
4031 if (ieee80211_hw_config(local)) {
Johannes Berg8318d782008-01-24 19:38:38 +01004032 printk(KERN_DEBUG "%s: failed to set freq to "
4033 "%d MHz for scan\n", dev->name,
4034 chan->center_freq);
Jiri Bencf0706e82007-05-05 11:45:53 -07004035 skip = 1;
4036 }
4037 }
4038
Johannes Berg69d464d2008-01-28 17:08:56 +01004039 /* advance state machine to next channel/band */
Jiri Bencf0706e82007-05-05 11:45:53 -07004040 local->scan_channel_idx++;
Johannes Berg8318d782008-01-24 19:38:38 +01004041 if (local->scan_channel_idx >= sband->n_channels) {
Johannes Berg69d464d2008-01-28 17:08:56 +01004042 /*
4043 * scan_band may end up == IEEE80211_NUM_BANDS, but
4044 * we'll catch that case above and complete the scan
4045 * if that is the case.
4046 */
Johannes Berg8318d782008-01-24 19:38:38 +01004047 local->scan_band++;
4048 local->scan_channel_idx = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07004049 }
4050
4051 if (skip)
4052 break;
4053
4054 next_delay = IEEE80211_PROBE_DELAY +
4055 usecs_to_jiffies(local->hw.channel_change_time);
4056 local->scan_state = SCAN_SEND_PROBE;
4057 break;
4058 case SCAN_SEND_PROBE:
Johannes Berg8318d782008-01-24 19:38:38 +01004059 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
Jiri Bencf0706e82007-05-05 11:45:53 -07004060 local->scan_state = SCAN_SET_CHANNEL;
Johannes Berg8318d782008-01-24 19:38:38 +01004061
4062 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
4063 break;
4064 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
4065 local->scan_ssid_len);
4066 next_delay = IEEE80211_CHANNEL_TIME;
Jiri Bencf0706e82007-05-05 11:45:53 -07004067 break;
4068 }
4069
Zhu Yiece8edd2007-11-22 10:53:21 +08004070 if (local->sta_sw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -07004071 queue_delayed_work(local->hw.workqueue, &local->scan_work,
4072 next_delay);
4073}
4074
4075
4076static int ieee80211_sta_start_scan(struct net_device *dev,
4077 u8 *ssid, size_t ssid_len)
4078{
4079 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4080 struct ieee80211_sub_if_data *sdata;
4081
4082 if (ssid_len > IEEE80211_MAX_SSID_LEN)
4083 return -EINVAL;
4084
4085 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
4086 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
4087 * BSSID: MACAddress
4088 * SSID
4089 * ScanType: ACTIVE, PASSIVE
4090 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
4091 * a Probe frame during active scanning
4092 * ChannelList
4093 * MinChannelTime (>= ProbeDelay), in TU
4094 * MaxChannelTime: (>= MinChannelTime), in TU
4095 */
4096
4097 /* MLME-SCAN.confirm
4098 * BSSDescriptionSet
4099 * ResultCode: SUCCESS, INVALID_PARAMETERS
4100 */
4101
Zhu Yiece8edd2007-11-22 10:53:21 +08004102 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jiri Bencf0706e82007-05-05 11:45:53 -07004103 if (local->scan_dev == dev)
4104 return 0;
4105 return -EBUSY;
4106 }
4107
4108 if (local->ops->hw_scan) {
4109 int rc = local->ops->hw_scan(local_to_hw(local),
Zhu Yiece8edd2007-11-22 10:53:21 +08004110 ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07004111 if (!rc) {
Zhu Yiece8edd2007-11-22 10:53:21 +08004112 local->sta_hw_scanning = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07004113 local->scan_dev = dev;
4114 }
4115 return rc;
4116 }
4117
Zhu Yiece8edd2007-11-22 10:53:21 +08004118 local->sta_sw_scanning = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07004119
Johannes Berg79010422007-09-18 17:29:21 -04004120 rcu_read_lock();
4121 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Mattias Nissler14042cbe2007-06-08 15:31:13 +02004122
4123 /* Don't stop the master interface, otherwise we can't transmit
4124 * probes! */
4125 if (sdata->dev == local->mdev)
4126 continue;
4127
Jiri Bencf0706e82007-05-05 11:45:53 -07004128 netif_stop_queue(sdata->dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01004129 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04004130 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e82007-05-05 11:45:53 -07004131 ieee80211_send_nullfunc(local, sdata, 1);
4132 }
Johannes Berg79010422007-09-18 17:29:21 -04004133 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07004134
4135 if (ssid) {
4136 local->scan_ssid_len = ssid_len;
4137 memcpy(local->scan_ssid, ssid, ssid_len);
4138 } else
4139 local->scan_ssid_len = 0;
4140 local->scan_state = SCAN_SET_CHANNEL;
Jiri Bencf0706e82007-05-05 11:45:53 -07004141 local->scan_channel_idx = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01004142 local->scan_band = IEEE80211_BAND_2GHZ;
Jiri Bencf0706e82007-05-05 11:45:53 -07004143 local->scan_dev = dev;
4144
Johannes Berg4150c572007-09-17 01:29:23 -04004145 netif_tx_lock_bh(local->mdev);
4146 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
4147 local->ops->configure_filter(local_to_hw(local),
4148 FIF_BCN_PRBRESP_PROMISC,
4149 &local->filter_flags,
4150 local->mdev->mc_count,
4151 local->mdev->mc_list);
4152 netif_tx_unlock_bh(local->mdev);
Jiri Bencf0706e82007-05-05 11:45:53 -07004153
4154 /* TODO: start scan as soon as all nullfunc frames are ACKed */
4155 queue_delayed_work(local->hw.workqueue, &local->scan_work,
4156 IEEE80211_CHANNEL_TIME);
4157
4158 return 0;
4159}
4160
4161
4162int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
4163{
4164 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4165 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4166 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4167
Johannes Berg51fb61e2007-12-19 01:31:27 +01004168 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07004169 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
4170
Zhu Yiece8edd2007-11-22 10:53:21 +08004171 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jiri Bencf0706e82007-05-05 11:45:53 -07004172 if (local->scan_dev == dev)
4173 return 0;
4174 return -EBUSY;
4175 }
4176
Helmut Schaaa0af5f12007-11-09 16:25:08 +01004177 ifsta->scan_ssid_len = ssid_len;
4178 if (ssid_len)
4179 memcpy(ifsta->scan_ssid, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07004180 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
4181 queue_work(local->hw.workqueue, &ifsta->work);
4182 return 0;
4183}
4184
4185static char *
4186ieee80211_sta_scan_result(struct net_device *dev,
David S. Millerccc58052008-06-16 18:50:49 -07004187 struct iw_request_info *info,
Jiri Bencf0706e82007-05-05 11:45:53 -07004188 struct ieee80211_sta_bss *bss,
4189 char *current_ev, char *end_buf)
4190{
4191 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4192 struct iw_event iwe;
4193
4194 if (time_after(jiffies,
4195 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
4196 return current_ev;
4197
Jiri Bencf0706e82007-05-05 11:45:53 -07004198 memset(&iwe, 0, sizeof(iwe));
4199 iwe.cmd = SIOCGIWAP;
4200 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4201 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07004202 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e82007-05-05 11:45:53 -07004203 IW_EV_ADDR_LEN);
4204
4205 memset(&iwe, 0, sizeof(iwe));
4206 iwe.cmd = SIOCGIWESSID;
Johannes Berg902acc72008-02-23 15:17:19 +01004207 if (bss_mesh_cfg(bss)) {
4208 iwe.u.data.length = bss_mesh_id_len(bss);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004209 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004210 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4211 &iwe, bss_mesh_id(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004212 } else {
4213 iwe.u.data.length = bss->ssid_len;
4214 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004215 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4216 &iwe, bss->ssid);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004217 }
Jiri Bencf0706e82007-05-05 11:45:53 -07004218
Luis Carlos Cobo1d1b5352008-02-29 12:15:28 -08004219 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
4220 || bss_mesh_cfg(bss)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07004221 memset(&iwe, 0, sizeof(iwe));
4222 iwe.cmd = SIOCGIWMODE;
Johannes Berg902acc72008-02-23 15:17:19 +01004223 if (bss_mesh_cfg(bss))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004224 iwe.u.mode = IW_MODE_MESH;
4225 else if (bss->capability & WLAN_CAPABILITY_ESS)
Jiri Bencf0706e82007-05-05 11:45:53 -07004226 iwe.u.mode = IW_MODE_MASTER;
4227 else
4228 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07004229 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4230 &iwe, IW_EV_UINT_LEN);
Jiri Bencf0706e82007-05-05 11:45:53 -07004231 }
4232
4233 memset(&iwe, 0, sizeof(iwe));
4234 iwe.cmd = SIOCGIWFREQ;
Johannes Berg8318d782008-01-24 19:38:38 +01004235 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
4236 iwe.u.freq.e = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004237 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e82007-05-05 11:45:53 -07004238 IW_EV_FREQ_LEN);
4239
4240 memset(&iwe, 0, sizeof(iwe));
Tomas Winkler9381be02008-05-23 01:36:36 +03004241 iwe.cmd = SIOCGIWFREQ;
4242 iwe.u.freq.m = bss->freq;
4243 iwe.u.freq.e = 6;
David S. Millerccc58052008-06-16 18:50:49 -07004244 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Tomas Winkler9381be02008-05-23 01:36:36 +03004245 IW_EV_FREQ_LEN);
4246 memset(&iwe, 0, sizeof(iwe));
Jiri Bencf0706e82007-05-05 11:45:53 -07004247 iwe.cmd = IWEVQUAL;
Bruno Randolf566bfe52008-05-08 19:15:40 +02004248 iwe.u.qual.qual = bss->qual;
4249 iwe.u.qual.level = bss->signal;
Jiri Bencf0706e82007-05-05 11:45:53 -07004250 iwe.u.qual.noise = bss->noise;
4251 iwe.u.qual.updated = local->wstats_flags;
David S. Millerccc58052008-06-16 18:50:49 -07004252 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e82007-05-05 11:45:53 -07004253 IW_EV_QUAL_LEN);
4254
4255 memset(&iwe, 0, sizeof(iwe));
4256 iwe.cmd = SIOCGIWENCODE;
4257 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
4258 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4259 else
4260 iwe.u.data.flags = IW_ENCODE_DISABLED;
4261 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004262 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4263 &iwe, "");
Jiri Bencf0706e82007-05-05 11:45:53 -07004264
4265 if (bss && bss->wpa_ie) {
4266 memset(&iwe, 0, sizeof(iwe));
4267 iwe.cmd = IWEVGENIE;
4268 iwe.u.data.length = bss->wpa_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004269 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4270 &iwe, bss->wpa_ie);
Jiri Bencf0706e82007-05-05 11:45:53 -07004271 }
4272
4273 if (bss && bss->rsn_ie) {
4274 memset(&iwe, 0, sizeof(iwe));
4275 iwe.cmd = IWEVGENIE;
4276 iwe.u.data.length = bss->rsn_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004277 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4278 &iwe, bss->rsn_ie);
Jiri Bencf0706e82007-05-05 11:45:53 -07004279 }
4280
Emmanuel Grumbache6231572008-05-27 20:00:11 +03004281 if (bss && bss->ht_ie) {
4282 memset(&iwe, 0, sizeof(iwe));
4283 iwe.cmd = IWEVGENIE;
4284 iwe.u.data.length = bss->ht_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004285 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4286 &iwe, bss->ht_ie);
Emmanuel Grumbache6231572008-05-27 20:00:11 +03004287 }
4288
Jiri Bencf0706e82007-05-05 11:45:53 -07004289 if (bss && bss->supp_rates_len > 0) {
4290 /* display all supported rates in readable format */
David S. Millerccc58052008-06-16 18:50:49 -07004291 char *p = current_ev + iwe_stream_lcp_len(info);
Jiri Bencf0706e82007-05-05 11:45:53 -07004292 int i;
4293
4294 memset(&iwe, 0, sizeof(iwe));
4295 iwe.cmd = SIOCGIWRATE;
4296 /* Those two flags are ignored... */
4297 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4298
4299 for (i = 0; i < bss->supp_rates_len; i++) {
4300 iwe.u.bitrate.value = ((bss->supp_rates[i] &
4301 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07004302 p = iwe_stream_add_value(info, current_ev, p,
Jiri Bencf0706e82007-05-05 11:45:53 -07004303 end_buf, &iwe, IW_EV_PARAM_LEN);
4304 }
4305 current_ev = p;
4306 }
4307
4308 if (bss) {
4309 char *buf;
4310 buf = kmalloc(30, GFP_ATOMIC);
4311 if (buf) {
4312 memset(&iwe, 0, sizeof(iwe));
4313 iwe.cmd = IWEVCUSTOM;
4314 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
4315 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004316 current_ev = iwe_stream_add_point(info, current_ev,
4317 end_buf,
Jiri Bencf0706e82007-05-05 11:45:53 -07004318 &iwe, buf);
4319 kfree(buf);
4320 }
4321 }
4322
Johannes Berg902acc72008-02-23 15:17:19 +01004323 if (bss_mesh_cfg(bss)) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004324 char *buf;
John W. Linville24736702008-04-08 14:15:46 -04004325 u8 *cfg = bss_mesh_cfg(bss);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004326 buf = kmalloc(50, GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004327 if (buf) {
4328 memset(&iwe, 0, sizeof(iwe));
4329 iwe.cmd = IWEVCUSTOM;
John W. Linville24736702008-04-08 14:15:46 -04004330 sprintf(buf, "Mesh network (version %d)", cfg[0]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004331 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004332 current_ev = iwe_stream_add_point(info, current_ev,
4333 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004334 &iwe, buf);
4335 sprintf(buf, "Path Selection Protocol ID: "
John W. Linville24736702008-04-08 14:15:46 -04004336 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
4337 cfg[4]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004338 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004339 current_ev = iwe_stream_add_point(info, current_ev,
4340 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004341 &iwe, buf);
4342 sprintf(buf, "Path Selection Metric ID: "
John W. Linville24736702008-04-08 14:15:46 -04004343 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
4344 cfg[8]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004345 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004346 current_ev = iwe_stream_add_point(info, current_ev,
4347 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004348 &iwe, buf);
4349 sprintf(buf, "Congestion Control Mode ID: "
John W. Linville24736702008-04-08 14:15:46 -04004350 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
4351 cfg[11], cfg[12]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004352 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004353 current_ev = iwe_stream_add_point(info, current_ev,
4354 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004355 &iwe, buf);
4356 sprintf(buf, "Channel Precedence: "
John W. Linville24736702008-04-08 14:15:46 -04004357 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
4358 cfg[15], cfg[16]);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004359 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004360 current_ev = iwe_stream_add_point(info, current_ev,
4361 end_buf,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004362 &iwe, buf);
4363 kfree(buf);
4364 }
4365 }
4366
Jiri Bencf0706e82007-05-05 11:45:53 -07004367 return current_ev;
4368}
4369
4370
David S. Millerccc58052008-06-16 18:50:49 -07004371int ieee80211_sta_scan_results(struct net_device *dev,
4372 struct iw_request_info *info,
4373 char *buf, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07004374{
4375 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4376 char *current_ev = buf;
4377 char *end_buf = buf + len;
4378 struct ieee80211_sta_bss *bss;
4379
4380 spin_lock_bh(&local->sta_bss_lock);
4381 list_for_each_entry(bss, &local->sta_bss_list, list) {
4382 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
4383 spin_unlock_bh(&local->sta_bss_lock);
4384 return -E2BIG;
4385 }
David S. Millerccc58052008-06-16 18:50:49 -07004386 current_ev = ieee80211_sta_scan_result(dev, info, bss,
4387 current_ev, end_buf);
Jiri Bencf0706e82007-05-05 11:45:53 -07004388 }
4389 spin_unlock_bh(&local->sta_bss_lock);
4390 return current_ev - buf;
4391}
4392
4393
4394int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
4395{
4396 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4397 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Johannes Berg988c0f72008-04-17 19:21:22 +02004398
Jiri Bencf0706e82007-05-05 11:45:53 -07004399 kfree(ifsta->extra_ie);
4400 if (len == 0) {
4401 ifsta->extra_ie = NULL;
4402 ifsta->extra_ie_len = 0;
4403 return 0;
4404 }
4405 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
4406 if (!ifsta->extra_ie) {
4407 ifsta->extra_ie_len = 0;
4408 return -ENOMEM;
4409 }
4410 memcpy(ifsta->extra_ie, ie, len);
4411 ifsta->extra_ie_len = len;
4412 return 0;
4413}
4414
4415
Johannes Berg988c0f72008-04-17 19:21:22 +02004416struct sta_info *ieee80211_ibss_add_sta(struct net_device *dev,
4417 struct sk_buff *skb, u8 *bssid,
Vladimir Koutny87291c02008-06-13 16:50:44 +02004418 u8 *addr, u64 supp_rates)
Jiri Bencf0706e82007-05-05 11:45:53 -07004419{
4420 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4421 struct sta_info *sta;
John W. Linville91fa5582007-05-15 16:14:40 -04004422 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Joe Perches0795af52007-10-03 17:59:30 -07004423 DECLARE_MAC_BUF(mac);
Vladimir Koutny87291c02008-06-13 16:50:44 +02004424 int band = local->hw.conf.channel->band;
Jiri Bencf0706e82007-05-05 11:45:53 -07004425
4426 /* TODO: Could consider removing the least recently used entry and
4427 * allow new one to be added. */
4428 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
4429 if (net_ratelimit()) {
4430 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
Joe Perches0795af52007-10-03 17:59:30 -07004431 "entry %s\n", dev->name, print_mac(mac, addr));
Jiri Bencf0706e82007-05-05 11:45:53 -07004432 }
4433 return NULL;
4434 }
4435
Vladimir Koutny87291c02008-06-13 16:50:44 +02004436 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid))
4437 return NULL;
4438
Joe Perches0795af52007-10-03 17:59:30 -07004439 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04004440 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07004441
Johannes Berg73651ee2008-02-25 16:27:47 +01004442 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
4443 if (!sta)
Jiri Bencf0706e82007-05-05 11:45:53 -07004444 return NULL;
4445
Johannes Berg07346f812008-05-03 01:02:02 +02004446 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
Johannes Berg238814f2008-01-28 17:19:37 +01004447
Vladimir Koutny87291c02008-06-13 16:50:44 +02004448 if (supp_rates)
4449 sta->supp_rates[band] = supp_rates;
4450 else
4451 sta->supp_rates[band] = sdata->u.sta.supp_rates_bits[band];
Jiri Bencf0706e82007-05-05 11:45:53 -07004452
4453 rate_control_rate_init(sta, local);
4454
Johannes Berg93e5deb2008-04-01 15:21:00 +02004455 if (sta_info_insert(sta))
Johannes Berg73651ee2008-02-25 16:27:47 +01004456 return NULL;
Johannes Berg73651ee2008-02-25 16:27:47 +01004457
Johannes Bergd0709a62008-02-25 16:27:46 +01004458 return sta;
Jiri Bencf0706e82007-05-05 11:45:53 -07004459}
4460
4461
4462int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
4463{
4464 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4465 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4466
4467 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
4468 dev->name, reason);
4469
Johannes Berg51fb61e2007-12-19 01:31:27 +01004470 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4471 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07004472 return -EINVAL;
4473
4474 ieee80211_send_deauth(dev, ifsta, reason);
4475 ieee80211_set_disassoc(dev, ifsta, 1);
4476 return 0;
4477}
4478
4479
4480int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
4481{
4482 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4483 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4484
4485 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
4486 dev->name, reason);
4487
Johannes Berg51fb61e2007-12-19 01:31:27 +01004488 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07004489 return -EINVAL;
4490
Jiri Slabyd6f2da52007-08-28 17:01:54 -04004491 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e82007-05-05 11:45:53 -07004492 return -1;
4493
4494 ieee80211_send_disassoc(dev, ifsta, reason);
4495 ieee80211_set_disassoc(dev, ifsta, 0);
4496 return 0;
4497}
Mohamed Abbas84363e62008-04-04 16:59:58 -07004498
4499void ieee80211_notify_mac(struct ieee80211_hw *hw,
4500 enum ieee80211_notification_types notif_type)
4501{
4502 struct ieee80211_local *local = hw_to_local(hw);
4503 struct ieee80211_sub_if_data *sdata;
4504
4505 switch (notif_type) {
4506 case IEEE80211_NOTIFY_RE_ASSOC:
4507 rcu_read_lock();
4508 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4509
4510 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
4511 ieee80211_sta_req_auth(sdata->dev,
4512 &sdata->u.sta);
4513 }
4514
4515 }
4516 rcu_read_unlock();
4517 break;
4518 }
4519}
4520EXPORT_SYMBOL(ieee80211_notify_mac);