blob: cffef44cec052a2e3fe15d03a368fb9102dd96c1 [file] [log] [blame]
Jiri Bencf0706e822007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14/* TODO:
Jiri Bencf0706e822007-05-05 11:45:53 -070015 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
17 * SSID)
18 */
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070019#include <linux/delay.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070020#include <linux/if_ether.h>
21#include <linux/skbuff.h>
22#include <linux/netdevice.h>
23#include <linux/if_arp.h>
24#include <linux/wireless.h>
25#include <linux/random.h>
26#include <linux/etherdevice.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010027#include <linux/rtnetlink.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070028#include <net/iw_handler.h>
29#include <asm/types.h>
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070056
57#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
58
59
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070095{
96 size_t left = len;
97 u8 *pos = start;
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -0700226 default:
Jiri Bencf0706e822007-05-05 11:45:53 -0700227 break;
228 }
229
230 left -= elen;
231 pos += elen;
232 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700233}
234
235
Jiri Bencf0706e822007-05-05 11:45:53 -0700236static int ecw2cw(int ecw)
237{
Johannes Bergac2bf322008-02-14 00:30:35 +0100238 return (1 << ecw) - 1;
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -0700325 local->wmm_acm |= BIT(0) | BIT(3);
Jiri Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -0700330 local->wmm_acm |= BIT(4) | BIT(5);
Jiri Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -0700335 local->wmm_acm |= BIT(6) | BIT(7);
Jiri Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -0700341 local->wmm_acm |= BIT(1) | BIT(2);
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -0700530 union iwreq_data wrqu;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100531 u32 changed = BSS_CHANGED_ASSOC;
Jiri Bencf0706e822007-05-05 11:45:53 -0700532
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -0700576 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
577 }
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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
Tomas Winkler06ff47b2008-06-18 17:53:44 +0300750 if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
751 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
752 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
753
Jiri Bencf0706e822007-05-05 11:45:53 -0700754 ieee80211_rx_bss_put(dev, bss);
Helmut Schaa0d580a72008-05-20 09:56:37 +0200755 } else {
756 rates = ~0;
757 rates_len = sband->n_bitrates;
Jiri Bencf0706e822007-05-05 11:45:53 -0700758 }
759
760 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
761 memset(mgmt, 0, 24);
762 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
763 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
764 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
765
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400766 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700767 skb_put(skb, 10);
768 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
769 IEEE80211_STYPE_REASSOC_REQ);
770 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
771 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
772 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
773 ETH_ALEN);
774 } else {
775 skb_put(skb, 4);
776 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
777 IEEE80211_STYPE_ASSOC_REQ);
778 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
779 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
780 }
781
782 /* SSID */
783 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
784 *pos++ = WLAN_EID_SSID;
785 *pos++ = ifsta->ssid_len;
786 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
787
Helmut Schaa0d580a72008-05-20 09:56:37 +0200788 /* add all rates which were marked to be used above */
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200789 supp_rates_len = rates_len;
790 if (supp_rates_len > 8)
791 supp_rates_len = 8;
Jiri Bencf0706e822007-05-05 11:45:53 -0700792
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200793 len = sband->n_bitrates;
794 pos = skb_put(skb, supp_rates_len + 2);
795 *pos++ = WLAN_EID_SUPP_RATES;
796 *pos++ = supp_rates_len;
797
798 count = 0;
799 for (i = 0; i < sband->n_bitrates; i++) {
800 if (BIT(i) & rates) {
Johannes Berg8318d782008-01-24 19:38:38 +0100801 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e822007-05-05 11:45:53 -0700802 *pos++ = (u8) (rate / 5);
Helmut Schaa36d16ae2008-05-08 13:34:07 +0200803 if (++count == 8)
804 break;
805 }
806 }
807
808 if (count == 8) {
809 pos = skb_put(skb, rates_len - count + 2);
810 *pos++ = WLAN_EID_EXT_SUPP_RATES;
811 *pos++ = rates_len - count;
812
813 for (i++; i < sband->n_bitrates; i++) {
814 if (BIT(i) & rates) {
815 int rate = sband->bitrates[i].bitrate;
816 *pos++ = (u8) (rate / 5);
817 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700818 }
819 }
820
Tomas Winkler06ff47b2008-06-18 17:53:44 +0300821 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
822 /* 1. power capabilities */
823 pos = skb_put(skb, 4);
824 *pos++ = WLAN_EID_PWR_CAPABILITY;
825 *pos++ = 2;
826 *pos++ = 0; /* min tx power */
827 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
828
829 /* 2. supported channels */
830 /* TODO: get this in reg domain format */
831 pos = skb_put(skb, 2 * sband->n_channels + 2);
832 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
833 *pos++ = 2 * sband->n_channels;
834 for (i = 0; i < sband->n_channels; i++) {
835 *pos++ = ieee80211_frequency_to_channel(
836 sband->channels[i].center_freq);
837 *pos++ = 1; /* one channel in the subband*/
838 }
839 }
840
Jiri Bencf0706e822007-05-05 11:45:53 -0700841 if (ifsta->extra_ie) {
842 pos = skb_put(skb, ifsta->extra_ie_len);
843 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
844 }
845
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400846 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700847 pos = skb_put(skb, 9);
848 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
849 *pos++ = 7; /* len */
850 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
851 *pos++ = 0x50;
852 *pos++ = 0xf2;
853 *pos++ = 2; /* WME */
854 *pos++ = 0; /* WME info */
855 *pos++ = 1; /* WME ver */
856 *pos++ = 0;
857 }
Johannes Berg3434fbd2008-05-03 00:59:37 +0200858
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200859 /* wmm support is a must to HT */
Johannes Berg3434fbd2008-05-03 00:59:37 +0200860 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) &&
Emmanuel Grumbach93061022008-05-29 16:35:23 +0800861 sband->ht_info.ht_supported && bss->ht_add_ie) {
862 struct ieee80211_ht_addt_info *ht_add_info =
863 (struct ieee80211_ht_addt_info *)bss->ht_add_ie;
864 u16 cap = sband->ht_info.cap;
865 __le16 tmp;
866 u32 flags = local->hw.conf.channel->flags;
867
868 switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) {
869 case IEEE80211_HT_IE_CHA_SEC_ABOVE:
870 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
871 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
872 cap &= ~IEEE80211_HT_CAP_SGI_40;
873 }
874 break;
875 case IEEE80211_HT_IE_CHA_SEC_BELOW:
876 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
877 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
878 cap &= ~IEEE80211_HT_CAP_SGI_40;
879 }
880 break;
881 }
882
883 tmp = cpu_to_le16(cap);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200884 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
885 *pos++ = WLAN_EID_HT_CAPABILITY;
886 *pos++ = sizeof(struct ieee80211_ht_cap);
887 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
888 memcpy(pos, &tmp, sizeof(u16));
889 pos += sizeof(u16);
Johannes Berg8318d782008-01-24 19:38:38 +0100890 /* TODO: needs a define here for << 2 */
891 *pos++ = sband->ht_info.ampdu_factor |
892 (sband->ht_info.ampdu_density << 2);
893 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
Ron Rindjunskyc7153502007-11-26 16:14:31 +0200894 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700895
896 kfree(ifsta->assocreq_ies);
897 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
Michael Wu0ec0b7a2007-07-27 15:43:24 +0200898 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -0700899 if (ifsta->assocreq_ies)
900 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
901
902 ieee80211_sta_tx(dev, skb, 0);
903}
904
905
906static void ieee80211_send_deauth(struct net_device *dev,
907 struct ieee80211_if_sta *ifsta, u16 reason)
908{
909 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
910 struct sk_buff *skb;
911 struct ieee80211_mgmt *mgmt;
912
913 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
914 if (!skb) {
915 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
916 "frame\n", dev->name);
917 return;
918 }
919 skb_reserve(skb, local->hw.extra_tx_headroom);
920
921 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
922 memset(mgmt, 0, 24);
923 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
924 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
925 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
926 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
927 IEEE80211_STYPE_DEAUTH);
928 skb_put(skb, 2);
929 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
930
931 ieee80211_sta_tx(dev, skb, 0);
932}
933
934
935static void ieee80211_send_disassoc(struct net_device *dev,
936 struct ieee80211_if_sta *ifsta, u16 reason)
937{
938 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
939 struct sk_buff *skb;
940 struct ieee80211_mgmt *mgmt;
941
942 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
943 if (!skb) {
944 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
945 "frame\n", dev->name);
946 return;
947 }
948 skb_reserve(skb, local->hw.extra_tx_headroom);
949
950 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
951 memset(mgmt, 0, 24);
952 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
953 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
954 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
955 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
956 IEEE80211_STYPE_DISASSOC);
957 skb_put(skb, 2);
958 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
959
960 ieee80211_sta_tx(dev, skb, 0);
961}
962
963
964static int ieee80211_privacy_mismatch(struct net_device *dev,
965 struct ieee80211_if_sta *ifsta)
966{
John W. Linville65c107a2007-10-05 14:23:27 -0400967 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e822007-05-05 11:45:53 -0700968 struct ieee80211_sta_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000969 int bss_privacy;
970 int wep_privacy;
971 int privacy_invoked;
Jiri Bencf0706e822007-05-05 11:45:53 -0700972
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000973 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
Jiri Bencf0706e822007-05-05 11:45:53 -0700974 return 0;
975
Johannes Berg8318d782008-01-24 19:38:38 +0100976 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
977 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -0400978 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700979 if (!bss)
980 return 0;
981
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000982 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
983 wep_privacy = !!ieee80211_sta_wep_configured(dev);
984 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e822007-05-05 11:45:53 -0700985
986 ieee80211_rx_bss_put(dev, bss);
987
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000988 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
989 return 0;
990
991 return 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700992}
993
994
995static void ieee80211_associate(struct net_device *dev,
996 struct ieee80211_if_sta *ifsta)
997{
Joe Perches0795af52007-10-03 17:59:30 -0700998 DECLARE_MAC_BUF(mac);
999
Jiri Bencf0706e822007-05-05 11:45:53 -07001000 ifsta->assoc_tries++;
1001 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Joe Perches0795af52007-10-03 17:59:30 -07001002 printk(KERN_DEBUG "%s: association with AP %s"
Jiri Bencf0706e822007-05-05 11:45:53 -07001003 " timed out\n",
Joe Perches0795af52007-10-03 17:59:30 -07001004 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001005 ifsta->state = IEEE80211_DISABLED;
1006 return;
1007 }
1008
1009 ifsta->state = IEEE80211_ASSOCIATE;
Joe Perches0795af52007-10-03 17:59:30 -07001010 printk(KERN_DEBUG "%s: associate with AP %s\n",
1011 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001012 if (ieee80211_privacy_mismatch(dev, ifsta)) {
1013 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
1014 "mixed-cell disabled - abort association\n", dev->name);
1015 ifsta->state = IEEE80211_DISABLED;
1016 return;
1017 }
1018
1019 ieee80211_send_assoc(dev, ifsta);
1020
1021 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
1022}
1023
1024
1025static void ieee80211_associated(struct net_device *dev,
1026 struct ieee80211_if_sta *ifsta)
1027{
1028 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1029 struct sta_info *sta;
1030 int disassoc;
Joe Perches0795af52007-10-03 17:59:30 -07001031 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07001032
1033 /* TODO: start monitoring current AP signal quality and number of
1034 * missed beacons. Scan other channels every now and then and search
1035 * for better APs. */
1036 /* TODO: remove expired BSSes */
1037
1038 ifsta->state = IEEE80211_ASSOCIATED;
1039
Johannes Bergd0709a62008-02-25 16:27:46 +01001040 rcu_read_lock();
1041
Jiri Bencf0706e822007-05-05 11:45:53 -07001042 sta = sta_info_get(local, ifsta->bssid);
1043 if (!sta) {
Joe Perches0795af52007-10-03 17:59:30 -07001044 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
1045 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001046 disassoc = 1;
1047 } else {
1048 disassoc = 0;
1049 if (time_after(jiffies,
1050 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001051 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
Jiri Bencf0706e822007-05-05 11:45:53 -07001052 printk(KERN_DEBUG "%s: No ProbeResp from "
Joe Perches0795af52007-10-03 17:59:30 -07001053 "current AP %s - assume out of "
Jiri Bencf0706e822007-05-05 11:45:53 -07001054 "range\n",
Joe Perches0795af52007-10-03 17:59:30 -07001055 dev->name, print_mac(mac, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001056 disassoc = 1;
Johannes Bergd0709a62008-02-25 16:27:46 +01001057 sta_info_unlink(&sta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001058 } else
Jiri Bencf0706e822007-05-05 11:45:53 -07001059 ieee80211_send_probe_req(dev, ifsta->bssid,
1060 local->scan_ssid,
1061 local->scan_ssid_len);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001062 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e822007-05-05 11:45:53 -07001063 } else {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001064 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e822007-05-05 11:45:53 -07001065 if (time_after(jiffies, ifsta->last_probe +
1066 IEEE80211_PROBE_INTERVAL)) {
1067 ifsta->last_probe = jiffies;
1068 ieee80211_send_probe_req(dev, ifsta->bssid,
1069 ifsta->ssid,
1070 ifsta->ssid_len);
1071 }
1072 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001073 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001074
1075 rcu_read_unlock();
1076
Johannes Berg3b967662008-04-08 17:56:52 +02001077 if (disassoc && sta)
Johannes Bergd0709a62008-02-25 16:27:46 +01001078 sta_info_destroy(sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001079
Jiri Bencf0706e822007-05-05 11:45:53 -07001080 if (disassoc) {
Michael Wu2d192d92007-11-10 00:15:25 -05001081 ifsta->state = IEEE80211_DISABLED;
1082 ieee80211_set_associated(dev, ifsta, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -07001083 } else {
1084 mod_timer(&ifsta->timer, jiffies +
1085 IEEE80211_MONITORING_INTERVAL);
1086 }
1087}
1088
1089
1090static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
1091 u8 *ssid, size_t ssid_len)
1092{
1093 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +01001094 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07001095 struct sk_buff *skb;
1096 struct ieee80211_mgmt *mgmt;
1097 u8 *pos, *supp_rates, *esupp_rates = NULL;
1098 int i;
1099
1100 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
1101 if (!skb) {
1102 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
1103 "request\n", dev->name);
1104 return;
1105 }
1106 skb_reserve(skb, local->hw.extra_tx_headroom);
1107
1108 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1109 memset(mgmt, 0, 24);
1110 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1111 IEEE80211_STYPE_PROBE_REQ);
1112 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1113 if (dst) {
1114 memcpy(mgmt->da, dst, ETH_ALEN);
1115 memcpy(mgmt->bssid, dst, ETH_ALEN);
1116 } else {
1117 memset(mgmt->da, 0xff, ETH_ALEN);
1118 memset(mgmt->bssid, 0xff, ETH_ALEN);
1119 }
1120 pos = skb_put(skb, 2 + ssid_len);
1121 *pos++ = WLAN_EID_SSID;
1122 *pos++ = ssid_len;
1123 memcpy(pos, ssid, ssid_len);
1124
1125 supp_rates = skb_put(skb, 2);
1126 supp_rates[0] = WLAN_EID_SUPP_RATES;
1127 supp_rates[1] = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001128 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1129
1130 for (i = 0; i < sband->n_bitrates; i++) {
1131 struct ieee80211_rate *rate = &sband->bitrates[i];
Jiri Bencf0706e822007-05-05 11:45:53 -07001132 if (esupp_rates) {
1133 pos = skb_put(skb, 1);
1134 esupp_rates[1]++;
1135 } else if (supp_rates[1] == 8) {
1136 esupp_rates = skb_put(skb, 3);
1137 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
1138 esupp_rates[1] = 1;
1139 pos = &esupp_rates[2];
1140 } else {
1141 pos = skb_put(skb, 1);
1142 supp_rates[1]++;
1143 }
Johannes Berg8318d782008-01-24 19:38:38 +01001144 *pos = rate->bitrate / 5;
Jiri Bencf0706e822007-05-05 11:45:53 -07001145 }
1146
1147 ieee80211_sta_tx(dev, skb, 0);
1148}
1149
1150
1151static int ieee80211_sta_wep_configured(struct net_device *dev)
1152{
1153 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1154 if (!sdata || !sdata->default_key ||
Johannes Berg8f20fc22007-08-28 17:01:54 -04001155 sdata->default_key->conf.alg != ALG_WEP)
Jiri Bencf0706e822007-05-05 11:45:53 -07001156 return 0;
1157 return 1;
1158}
1159
1160
1161static void ieee80211_auth_completed(struct net_device *dev,
1162 struct ieee80211_if_sta *ifsta)
1163{
1164 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001165 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
Jiri Bencf0706e822007-05-05 11:45:53 -07001166 ieee80211_associate(dev, ifsta);
1167}
1168
1169
1170static void ieee80211_auth_challenge(struct net_device *dev,
1171 struct ieee80211_if_sta *ifsta,
1172 struct ieee80211_mgmt *mgmt,
1173 size_t len)
1174{
1175 u8 *pos;
1176 struct ieee802_11_elems elems;
1177
1178 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
1179 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001180 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07001181 if (!elems.challenge) {
1182 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
1183 "frame\n", dev->name);
1184 return;
1185 }
1186 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
1187 elems.challenge_len + 2, 1);
1188}
1189
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001190static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
1191 u8 dialog_token, u16 status, u16 policy,
1192 u16 buf_size, u16 timeout)
1193{
1194 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1195 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1196 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1197 struct sk_buff *skb;
1198 struct ieee80211_mgmt *mgmt;
1199 u16 capab;
1200
Ester Kummer3acea5b2008-04-17 16:05:14 -07001201 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
1202
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001203 if (!skb) {
1204 printk(KERN_DEBUG "%s: failed to allocate buffer "
1205 "for addba resp frame\n", dev->name);
1206 return;
1207 }
1208
1209 skb_reserve(skb, local->hw.extra_tx_headroom);
1210 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1211 memset(mgmt, 0, 24);
1212 memcpy(mgmt->da, da, ETH_ALEN);
1213 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001214 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001215 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1216 else
1217 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1218 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1219 IEEE80211_STYPE_ACTION);
1220
1221 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1222 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1223 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1224 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1225
1226 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1227 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1228 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1229
1230 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1231 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1232 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1233
1234 ieee80211_sta_tx(dev, skb, 0);
1235
1236 return;
1237}
1238
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001239void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1240 u16 tid, u8 dialog_token, u16 start_seq_num,
1241 u16 agg_size, u16 timeout)
1242{
1243 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1244 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1245 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1246 struct sk_buff *skb;
1247 struct ieee80211_mgmt *mgmt;
1248 u16 capab;
1249
Ester Kummer3acea5b2008-04-17 16:05:14 -07001250 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001251
1252 if (!skb) {
1253 printk(KERN_ERR "%s: failed to allocate buffer "
1254 "for addba request frame\n", dev->name);
1255 return;
1256 }
1257 skb_reserve(skb, local->hw.extra_tx_headroom);
1258 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1259 memset(mgmt, 0, 24);
1260 memcpy(mgmt->da, da, ETH_ALEN);
1261 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1262 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1263 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1264 else
1265 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1266
1267 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1268 IEEE80211_STYPE_ACTION);
1269
1270 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1271
1272 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1273 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1274
1275 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1276 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1277 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1278 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1279
1280 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1281
1282 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1283 mgmt->u.action.u.addba_req.start_seq_num =
1284 cpu_to_le16(start_seq_num << 4);
1285
1286 ieee80211_sta_tx(dev, skb, 0);
1287}
1288
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001289static void ieee80211_sta_process_addba_request(struct net_device *dev,
1290 struct ieee80211_mgmt *mgmt,
1291 size_t len)
1292{
1293 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001294 struct ieee80211_hw *hw = &local->hw;
1295 struct ieee80211_conf *conf = &hw->conf;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001296 struct sta_info *sta;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001297 struct tid_ampdu_rx *tid_agg_rx;
1298 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001299 u8 dialog_token;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001300 int ret = -EOPNOTSUPP;
1301 DECLARE_MAC_BUF(mac);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001302
Johannes Bergd0709a62008-02-25 16:27:46 +01001303 rcu_read_lock();
1304
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001305 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001306 if (!sta) {
1307 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001308 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001309 }
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001310
1311 /* extract session parameters from addba request frame */
1312 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1313 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001314 start_seq_num =
1315 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001316
1317 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1318 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1319 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1320 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1321
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001322 status = WLAN_STATUS_REQUEST_DECLINED;
1323
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001324 /* sanity check for incoming parameters:
1325 * check if configuration can support the BA policy
1326 * and if buffer size does not exceeds max value */
1327 if (((ba_policy != 1)
1328 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1329 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1330 status = WLAN_STATUS_INVALID_QOS_PARAM;
1331#ifdef CONFIG_MAC80211_HT_DEBUG
1332 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001333 printk(KERN_DEBUG "AddBA Req with bad params from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001334 "%s on tid %u. policy %d, buffer size %d\n",
1335 print_mac(mac, mgmt->sa), tid, ba_policy,
1336 buf_size);
1337#endif /* CONFIG_MAC80211_HT_DEBUG */
1338 goto end_no_lock;
1339 }
1340 /* determine default buffer size */
1341 if (buf_size == 0) {
Johannes Berg8318d782008-01-24 19:38:38 +01001342 struct ieee80211_supported_band *sband;
1343
1344 sband = local->hw.wiphy->bands[conf->channel->band];
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001345 buf_size = IEEE80211_MIN_AMPDU_BUF;
Johannes Berg8318d782008-01-24 19:38:38 +01001346 buf_size = buf_size << sband->ht_info.ampdu_factor;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001347 }
1348
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001349
1350 /* examine state machine */
Johannes Berg07346f812008-05-03 01:02:02 +02001351 spin_lock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001352
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001353 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001354#ifdef CONFIG_MAC80211_HT_DEBUG
1355 if (net_ratelimit())
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001356 printk(KERN_DEBUG "unexpected AddBA Req from "
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001357 "%s on tid %u\n",
1358 print_mac(mac, mgmt->sa), tid);
1359#endif /* CONFIG_MAC80211_HT_DEBUG */
1360 goto end;
1361 }
1362
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001363 /* prepare A-MPDU MLME for Rx aggregation */
1364 sta->ampdu_mlme.tid_rx[tid] =
1365 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
1366 if (!sta->ampdu_mlme.tid_rx[tid]) {
1367 if (net_ratelimit())
1368 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
1369 tid);
1370 goto end;
1371 }
1372 /* rx timer */
1373 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
1374 sta_rx_agg_session_timer_expired;
1375 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
1376 (unsigned long)&sta->timer_to_tid[tid];
1377 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1378
1379 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
1380
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001381 /* prepare reordering buffer */
1382 tid_agg_rx->reorder_buf =
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301383 kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC);
Johannes Berg03147df2008-02-26 00:39:28 +01001384 if (!tid_agg_rx->reorder_buf) {
1385 if (net_ratelimit())
1386 printk(KERN_ERR "can not allocate reordering buffer "
1387 "to tid %d\n", tid);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001388 kfree(sta->ampdu_mlme.tid_rx[tid]);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001389 goto end;
1390 }
1391 memset(tid_agg_rx->reorder_buf, 0,
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +05301392 buf_size * sizeof(struct sk_buff *));
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001393
1394 if (local->ops->ampdu_action)
1395 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001396 sta->addr, tid, &start_seq_num);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001397#ifdef CONFIG_MAC80211_HT_DEBUG
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001398 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001399#endif /* CONFIG_MAC80211_HT_DEBUG */
1400
1401 if (ret) {
1402 kfree(tid_agg_rx->reorder_buf);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001403 kfree(tid_agg_rx);
1404 sta->ampdu_mlme.tid_rx[tid] = NULL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001405 goto end;
1406 }
1407
1408 /* change state and send addba resp */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001409 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001410 tid_agg_rx->dialog_token = dialog_token;
1411 tid_agg_rx->ssn = start_seq_num;
1412 tid_agg_rx->head_seq_num = start_seq_num;
1413 tid_agg_rx->buf_size = buf_size;
1414 tid_agg_rx->timeout = timeout;
1415 tid_agg_rx->stored_mpdu_num = 0;
1416 status = WLAN_STATUS_SUCCESS;
1417end:
Johannes Berg07346f812008-05-03 01:02:02 +02001418 spin_unlock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001419
1420end_no_lock:
Johannes Bergd0709a62008-02-25 16:27:46 +01001421 ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
1422 dialog_token, status, 1, buf_size, timeout);
1423 rcu_read_unlock();
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02001424}
Jiri Bencf0706e822007-05-05 11:45:53 -07001425
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001426static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1427 struct ieee80211_mgmt *mgmt,
1428 size_t len)
1429{
1430 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1431 struct ieee80211_hw *hw = &local->hw;
1432 struct sta_info *sta;
1433 u16 capab;
1434 u16 tid;
1435 u8 *state;
1436
Johannes Bergd0709a62008-02-25 16:27:46 +01001437 rcu_read_lock();
1438
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001439 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001440 if (!sta) {
1441 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001442 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001443 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001444
1445 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1446 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1447
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001448 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001449
Johannes Berg07346f812008-05-03 01:02:02 +02001450 spin_lock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001451
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001452 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
Johannes Berg07346f812008-05-03 01:02:02 +02001453 spin_unlock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001454 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1455 "%d\n", *state);
1456 goto addba_resp_exit;
1457 }
1458
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001459 if (mgmt->u.action.u.addba_resp.dialog_token !=
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001460 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
Johannes Berg07346f812008-05-03 01:02:02 +02001461 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001462#ifdef CONFIG_MAC80211_HT_DEBUG
1463 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1464#endif /* CONFIG_MAC80211_HT_DEBUG */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001465 goto addba_resp_exit;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001466 }
1467
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001468 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001469#ifdef CONFIG_MAC80211_HT_DEBUG
1470 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1471#endif /* CONFIG_MAC80211_HT_DEBUG */
1472 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1473 == WLAN_STATUS_SUCCESS) {
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001474 if (*state & HT_ADDBA_RECEIVED_MSK)
1475 printk(KERN_DEBUG "double addBA response\n");
1476
1477 *state |= HT_ADDBA_RECEIVED_MSK;
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001478 sta->ampdu_mlme.addba_req_num[tid] = 0;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001479
1480 if (*state == HT_AGG_STATE_OPERATIONAL) {
1481 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1482 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1483 }
1484
Johannes Berg07346f812008-05-03 01:02:02 +02001485 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001486 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1487 } else {
1488 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1489
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001490 sta->ampdu_mlme.addba_req_num[tid]++;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001491 /* this will allow the state check in stop_BA_session */
1492 *state = HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001493 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001494 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1495 WLAN_BACK_INITIATOR);
1496 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001497
1498addba_resp_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001499 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001500}
1501
1502void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1503 u16 initiator, u16 reason_code)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001504{
1505 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1506 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1507 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1508 struct sk_buff *skb;
1509 struct ieee80211_mgmt *mgmt;
1510 u16 params;
1511
Ester Kummer3acea5b2008-04-17 16:05:14 -07001512 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001513
1514 if (!skb) {
1515 printk(KERN_ERR "%s: failed to allocate buffer "
1516 "for delba frame\n", dev->name);
1517 return;
1518 }
1519
1520 skb_reserve(skb, local->hw.extra_tx_headroom);
1521 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1522 memset(mgmt, 0, 24);
1523 memcpy(mgmt->da, da, ETH_ALEN);
1524 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
Johannes Berg51fb61e2007-12-19 01:31:27 +01001525 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001526 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1527 else
1528 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1529 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1530 IEEE80211_STYPE_ACTION);
1531
1532 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1533
1534 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1535 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1536 params = (u16)(initiator << 11); /* bit 11 initiator */
1537 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1538
1539 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1540 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1541
1542 ieee80211_sta_tx(dev, skb, 0);
1543}
1544
1545void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1546 u16 initiator, u16 reason)
1547{
1548 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1549 struct ieee80211_hw *hw = &local->hw;
1550 struct sta_info *sta;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001551 int ret, i;
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001552 DECLARE_MAC_BUF(mac);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001553
Johannes Bergd0709a62008-02-25 16:27:46 +01001554 rcu_read_lock();
1555
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001556 sta = sta_info_get(local, ra);
Johannes Bergd0709a62008-02-25 16:27:46 +01001557 if (!sta) {
1558 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001559 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001560 }
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001561
1562 /* check if TID is in operational state */
Johannes Berg07346f812008-05-03 01:02:02 +02001563 spin_lock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001564 if (sta->ampdu_mlme.tid_state_rx[tid]
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001565 != HT_AGG_STATE_OPERATIONAL) {
Johannes Berg07346f812008-05-03 01:02:02 +02001566 spin_unlock_bh(&sta->lock);
Johannes Bergd0709a62008-02-25 16:27:46 +01001567 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001568 return;
1569 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001570 sta->ampdu_mlme.tid_state_rx[tid] =
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001571 HT_AGG_STATE_REQ_STOP_BA_MSK |
1572 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
Johannes Berg07346f812008-05-03 01:02:02 +02001573 spin_unlock_bh(&sta->lock);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001574
1575 /* stop HW Rx aggregation. ampdu_action existence
1576 * already verified in session init so we add the BUG_ON */
1577 BUG_ON(!local->ops->ampdu_action);
1578
Ron Rindjunsky513a1022008-04-07 10:16:56 -07001579#ifdef CONFIG_MAC80211_HT_DEBUG
1580 printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n",
1581 print_mac(mac, ra), tid);
1582#endif /* CONFIG_MAC80211_HT_DEBUG */
1583
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001584 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +02001585 ra, tid, NULL);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001586 if (ret)
1587 printk(KERN_DEBUG "HW problem - can not stop rx "
1588 "aggergation for tid %d\n", tid);
1589
1590 /* shutdown timer has not expired */
1591 if (initiator != WLAN_BACK_TIMER)
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001592 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001593
1594 /* check if this is a self generated aggregation halt */
1595 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1596 ieee80211_send_delba(dev, ra, tid, 0, reason);
1597
1598 /* free the reordering buffer */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001599 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
1600 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001601 /* release the reordered frames */
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001602 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
1603 sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
1604 sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
Ron Rindjunskyb5807812007-12-25 17:00:35 +02001605 }
1606 }
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001607 /* free resources */
1608 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
1609 kfree(sta->ampdu_mlme.tid_rx[tid]);
1610 sta->ampdu_mlme.tid_rx[tid] = NULL;
1611 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001612
Johannes Bergd0709a62008-02-25 16:27:46 +01001613 rcu_read_unlock();
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001614}
1615
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001616
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001617static void ieee80211_sta_process_delba(struct net_device *dev,
1618 struct ieee80211_mgmt *mgmt, size_t len)
1619{
1620 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1621 struct sta_info *sta;
1622 u16 tid, params;
1623 u16 initiator;
1624 DECLARE_MAC_BUF(mac);
1625
Johannes Bergd0709a62008-02-25 16:27:46 +01001626 rcu_read_lock();
1627
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001628 sta = sta_info_get(local, mgmt->sa);
Johannes Bergd0709a62008-02-25 16:27:46 +01001629 if (!sta) {
1630 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001631 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001632 }
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001633
1634 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1635 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1636 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1637
1638#ifdef CONFIG_MAC80211_HT_DEBUG
1639 if (net_ratelimit())
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001640 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1641 print_mac(mac, mgmt->sa),
Ron Rindjunsky2e354ed2008-03-18 15:00:30 -07001642 initiator ? "initiator" : "recipient", tid,
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001643 mgmt->u.action.u.delba.reason_code);
1644#endif /* CONFIG_MAC80211_HT_DEBUG */
1645
1646 if (initiator == WLAN_BACK_INITIATOR)
1647 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1648 WLAN_BACK_INITIATOR, 0);
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001649 else { /* WLAN_BACK_RECIPIENT */
Johannes Berg07346f812008-05-03 01:02:02 +02001650 spin_lock_bh(&sta->lock);
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001651 sta->ampdu_mlme.tid_state_tx[tid] =
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001652 HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001653 spin_unlock_bh(&sta->lock);
Ron Rindjunskyd92684e2008-01-28 14:07:22 +02001654 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1655 WLAN_BACK_RECIPIENT);
1656 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001657 rcu_read_unlock();
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02001658}
1659
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001660/*
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001661 * After sending add Block Ack request we activated a timer until
1662 * add Block Ack response will arrive from the recipient.
1663 * If this timer expires sta_addba_resp_timer_expired will be executed.
1664 */
1665void sta_addba_resp_timer_expired(unsigned long data)
1666{
1667 /* not an elegant detour, but there is no choice as the timer passes
1668 * only one argument, and both sta_info and TID are needed, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001669 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001670 * array gives the sta through container_of */
Senthil Balasubramanian70d251b2008-05-28 20:08:12 +05301671 u16 tid = *(u8 *)data;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001672 struct sta_info *temp_sta = container_of((void *)data,
1673 struct sta_info, timer_to_tid[tid]);
1674
1675 struct ieee80211_local *local = temp_sta->local;
1676 struct ieee80211_hw *hw = &local->hw;
1677 struct sta_info *sta;
1678 u8 *state;
1679
Johannes Bergd0709a62008-02-25 16:27:46 +01001680 rcu_read_lock();
1681
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001682 sta = sta_info_get(local, temp_sta->addr);
Johannes Bergd0709a62008-02-25 16:27:46 +01001683 if (!sta) {
1684 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001685 return;
Johannes Bergd0709a62008-02-25 16:27:46 +01001686 }
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001687
Ron Rindjunskycee24a32008-03-26 20:36:03 +02001688 state = &sta->ampdu_mlme.tid_state_tx[tid];
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001689 /* check if the TID waits for addBA response */
Johannes Berg07346f812008-05-03 01:02:02 +02001690 spin_lock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001691 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
Johannes Berg07346f812008-05-03 01:02:02 +02001692 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001693 *state = HT_AGG_STATE_IDLE;
1694 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1695 "expecting addBA response there", tid);
1696 goto timer_expired_exit;
1697 }
1698
1699 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1700
1701 /* go through the state check in stop_BA_session */
1702 *state = HT_AGG_STATE_OPERATIONAL;
Johannes Berg07346f812008-05-03 01:02:02 +02001703 spin_unlock_bh(&sta->lock);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001704 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1705 WLAN_BACK_INITIATOR);
1706
1707timer_expired_exit:
Johannes Bergd0709a62008-02-25 16:27:46 +01001708 rcu_read_unlock();
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001709}
1710
1711/*
Ron Rindjunsky7b9d44c2008-03-18 15:00:31 -07001712 * After accepting the AddBA Request we activated a timer,
1713 * resetting it after each frame that arrives from the originator.
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001714 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1715 */
Adrian Bunk712590d2008-04-21 11:47:51 +03001716static void sta_rx_agg_session_timer_expired(unsigned long data)
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001717{
1718 /* not an elegant detour, but there is no choice as the timer passes
Senthil Balasubramanian70d251b2008-05-28 20:08:12 +05301719 * only one argument, and various sta_info are needed here, so init
Johannes Berg73651ee2008-02-25 16:27:47 +01001720 * flow in sta_info_create gives the TID as data, while the timer_to_id
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001721 * array gives the sta through container_of */
1722 u8 *ptid = (u8 *)data;
1723 u8 *timer_to_id = ptid - *ptid;
1724 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1725 timer_to_tid[0]);
1726
1727 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
Johannes Bergd0709a62008-02-25 16:27:46 +01001728 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1729 (u16)*ptid, WLAN_BACK_TIMER,
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001730 WLAN_REASON_QSTA_TIMEOUT);
1731}
1732
Ron Rindjunsky85249e52008-03-18 15:00:32 -07001733void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr)
1734{
1735 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1736 int i;
1737
1738 for (i = 0; i < STA_TID_NUM; i++) {
1739 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
1740 WLAN_BACK_INITIATOR);
1741 ieee80211_sta_stop_rx_ba_session(dev, addr, i,
1742 WLAN_BACK_RECIPIENT,
1743 WLAN_REASON_QSTA_LEAVE_QBSS);
1744 }
1745}
Ron Rindjunsky07db2182007-12-25 17:00:33 +02001746
Assaf Kraussb6623482008-06-16 16:09:49 +03001747static void ieee80211_send_refuse_measurement_request(struct net_device *dev,
1748 struct ieee80211_msrment_ie *request_ie,
1749 const u8 *da, const u8 *bssid,
1750 u8 dialog_token)
1751{
1752 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1753 struct sk_buff *skb;
1754 struct ieee80211_mgmt *msr_report;
1755
1756 skb = dev_alloc_skb(sizeof(*msr_report) + local->hw.extra_tx_headroom +
1757 sizeof(struct ieee80211_msrment_ie));
1758
1759 if (!skb) {
1760 printk(KERN_ERR "%s: failed to allocate buffer for "
1761 "measurement report frame\n", dev->name);
1762 return;
1763 }
1764
1765 skb_reserve(skb, local->hw.extra_tx_headroom);
1766 msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24);
1767 memset(msr_report, 0, 24);
1768 memcpy(msr_report->da, da, ETH_ALEN);
1769 memcpy(msr_report->sa, dev->dev_addr, ETH_ALEN);
1770 memcpy(msr_report->bssid, bssid, ETH_ALEN);
1771 msr_report->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1772 IEEE80211_STYPE_ACTION);
1773
1774 skb_put(skb, 1 + sizeof(msr_report->u.action.u.measurement));
1775 msr_report->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT;
1776 msr_report->u.action.u.measurement.action_code =
1777 WLAN_ACTION_SPCT_MSR_RPRT;
1778 msr_report->u.action.u.measurement.dialog_token = dialog_token;
1779
1780 msr_report->u.action.u.measurement.element_id = WLAN_EID_MEASURE_REPORT;
1781 msr_report->u.action.u.measurement.length =
1782 sizeof(struct ieee80211_msrment_ie);
1783
1784 memset(&msr_report->u.action.u.measurement.msr_elem, 0,
1785 sizeof(struct ieee80211_msrment_ie));
1786 msr_report->u.action.u.measurement.msr_elem.token = request_ie->token;
1787 msr_report->u.action.u.measurement.msr_elem.mode |=
1788 IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED;
1789 msr_report->u.action.u.measurement.msr_elem.type = request_ie->type;
1790
1791 ieee80211_sta_tx(dev, skb, 0);
1792}
1793
1794static void ieee80211_sta_process_measurement_req(struct net_device *dev,
1795 struct ieee80211_mgmt *mgmt,
1796 size_t len)
1797{
1798 /*
1799 * Ignoring measurement request is spec violation.
1800 * Mandatory measurements must be reported optional
1801 * measurements might be refused or reported incapable
1802 * For now just refuse
1803 * TODO: Answer basic measurement as unmeasured
1804 */
1805 ieee80211_send_refuse_measurement_request(dev,
1806 &mgmt->u.action.u.measurement.msr_elem,
1807 mgmt->sa, mgmt->bssid,
1808 mgmt->u.action.u.measurement.dialog_token);
1809}
1810
1811
Jiri Bencf0706e822007-05-05 11:45:53 -07001812static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1813 struct ieee80211_if_sta *ifsta,
1814 struct ieee80211_mgmt *mgmt,
1815 size_t len)
1816{
1817 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1818 u16 auth_alg, auth_transaction, status_code;
Joe Perches0795af52007-10-03 17:59:30 -07001819 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07001820
1821 if (ifsta->state != IEEE80211_AUTHENTICATE &&
Johannes Berg51fb61e2007-12-19 01:31:27 +01001822 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -07001823 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001824 "%s, but not in authenticate state - ignored\n",
1825 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001826 return;
1827 }
1828
1829 if (len < 24 + 6) {
1830 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
Joe Perches0795af52007-10-03 17:59:30 -07001831 "received from %s - ignored\n",
1832 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001833 return;
1834 }
1835
Johannes Berg51fb61e2007-12-19 01:31:27 +01001836 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Jiri Bencf0706e822007-05-05 11:45:53 -07001837 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1838 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001839 "unknown AP (SA=%s BSSID=%s) - "
1840 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1841 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001842 return;
1843 }
1844
Johannes Berg51fb61e2007-12-19 01:31:27 +01001845 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Jiri Bencf0706e822007-05-05 11:45:53 -07001846 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1847 printk(KERN_DEBUG "%s: authentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001848 "unknown BSSID (SA=%s BSSID=%s) - "
1849 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1850 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001851 return;
1852 }
1853
1854 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1855 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1856 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1857
Joe Perches0795af52007-10-03 17:59:30 -07001858 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
Jiri Bencf0706e822007-05-05 11:45:53 -07001859 "transaction=%d status=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001860 dev->name, print_mac(mac, mgmt->sa), auth_alg,
Jiri Bencf0706e822007-05-05 11:45:53 -07001861 auth_transaction, status_code);
1862
Johannes Berg51fb61e2007-12-19 01:31:27 +01001863 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Johannes Berg135a2112008-06-16 20:55:29 +02001864 /*
1865 * IEEE 802.11 standard does not require authentication in IBSS
Jiri Bencf0706e822007-05-05 11:45:53 -07001866 * networks and most implementations do not seem to use it.
1867 * However, try to reply to authentication attempts if someone
1868 * has actually implemented this.
Johannes Berg135a2112008-06-16 20:55:29 +02001869 */
Jiri Bencf0706e822007-05-05 11:45:53 -07001870 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1871 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1872 "frame (alg=%d transaction=%d)\n",
1873 dev->name, auth_alg, auth_transaction);
1874 return;
1875 }
1876 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1877 }
1878
1879 if (auth_alg != ifsta->auth_alg ||
1880 auth_transaction != ifsta->auth_transaction) {
1881 printk(KERN_DEBUG "%s: unexpected authentication frame "
1882 "(alg=%d transaction=%d)\n",
1883 dev->name, auth_alg, auth_transaction);
1884 return;
1885 }
1886
1887 if (status_code != WLAN_STATUS_SUCCESS) {
1888 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1889 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1890 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1891 u8 algs[3];
1892 const int num_algs = ARRAY_SIZE(algs);
1893 int i, pos;
1894 algs[0] = algs[1] = algs[2] = 0xff;
1895 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1896 algs[0] = WLAN_AUTH_OPEN;
1897 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1898 algs[1] = WLAN_AUTH_SHARED_KEY;
1899 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1900 algs[2] = WLAN_AUTH_LEAP;
1901 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1902 pos = 0;
1903 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1904 pos = 1;
1905 else
1906 pos = 2;
1907 for (i = 0; i < num_algs; i++) {
1908 pos++;
1909 if (pos >= num_algs)
1910 pos = 0;
1911 if (algs[pos] == ifsta->auth_alg ||
1912 algs[pos] == 0xff)
1913 continue;
1914 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1915 !ieee80211_sta_wep_configured(dev))
1916 continue;
1917 ifsta->auth_alg = algs[pos];
1918 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1919 "next try\n",
1920 dev->name, ifsta->auth_alg);
1921 break;
1922 }
1923 }
1924 return;
1925 }
1926
1927 switch (ifsta->auth_alg) {
1928 case WLAN_AUTH_OPEN:
1929 case WLAN_AUTH_LEAP:
1930 ieee80211_auth_completed(dev, ifsta);
1931 break;
1932 case WLAN_AUTH_SHARED_KEY:
1933 if (ifsta->auth_transaction == 4)
1934 ieee80211_auth_completed(dev, ifsta);
1935 else
1936 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1937 break;
1938 }
1939}
1940
1941
1942static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1943 struct ieee80211_if_sta *ifsta,
1944 struct ieee80211_mgmt *mgmt,
1945 size_t len)
1946{
1947 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001948 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07001949
1950 if (len < 24 + 2) {
1951 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
Joe Perches0795af52007-10-03 17:59:30 -07001952 "received from %s - ignored\n",
1953 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001954 return;
1955 }
1956
1957 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1958 printk(KERN_DEBUG "%s: deauthentication frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07001959 "unknown AP (SA=%s BSSID=%s) - "
1960 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1961 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07001962 return;
1963 }
1964
1965 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1966
Joe Perches0795af52007-10-03 17:59:30 -07001967 printk(KERN_DEBUG "%s: RX deauthentication from %s"
Jiri Bencf0706e822007-05-05 11:45:53 -07001968 " (reason=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07001969 dev->name, print_mac(mac, mgmt->sa), reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07001970
Johannes Berg988c0f72008-04-17 19:21:22 +02001971 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
Jiri Bencf0706e822007-05-05 11:45:53 -07001972 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
Jiri Bencf0706e822007-05-05 11:45:53 -07001973
1974 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1975 ifsta->state == IEEE80211_ASSOCIATE ||
1976 ifsta->state == IEEE80211_ASSOCIATED) {
1977 ifsta->state = IEEE80211_AUTHENTICATE;
1978 mod_timer(&ifsta->timer, jiffies +
1979 IEEE80211_RETRY_AUTH_INTERVAL);
1980 }
1981
1982 ieee80211_set_disassoc(dev, ifsta, 1);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001983 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jiri Bencf0706e822007-05-05 11:45:53 -07001984}
1985
1986
1987static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1988 struct ieee80211_if_sta *ifsta,
1989 struct ieee80211_mgmt *mgmt,
1990 size_t len)
1991{
1992 u16 reason_code;
Joe Perches0795af52007-10-03 17:59:30 -07001993 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07001994
1995 if (len < 24 + 2) {
1996 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
Joe Perches0795af52007-10-03 17:59:30 -07001997 "received from %s - ignored\n",
1998 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07001999 return;
2000 }
2001
2002 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
2003 printk(KERN_DEBUG "%s: disassociation frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07002004 "unknown AP (SA=%s BSSID=%s) - "
2005 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
2006 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07002007 return;
2008 }
2009
2010 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2011
Joe Perches0795af52007-10-03 17:59:30 -07002012 printk(KERN_DEBUG "%s: RX disassociation from %s"
Jiri Bencf0706e822007-05-05 11:45:53 -07002013 " (reason=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07002014 dev->name, print_mac(mac, mgmt->sa), reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07002015
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002016 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
Jiri Bencf0706e822007-05-05 11:45:53 -07002017 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
2018
2019 if (ifsta->state == IEEE80211_ASSOCIATED) {
2020 ifsta->state = IEEE80211_ASSOCIATE;
2021 mod_timer(&ifsta->timer, jiffies +
2022 IEEE80211_RETRY_AUTH_INTERVAL);
2023 }
2024
2025 ieee80211_set_disassoc(dev, ifsta, 0);
2026}
2027
2028
Johannes Berg471b3ef2007-12-28 14:32:58 +01002029static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -07002030 struct ieee80211_if_sta *ifsta,
2031 struct ieee80211_mgmt *mgmt,
2032 size_t len,
2033 int reassoc)
2034{
Johannes Berg471b3ef2007-12-28 14:32:58 +01002035 struct ieee80211_local *local = sdata->local;
2036 struct net_device *dev = sdata->dev;
Johannes Berg8318d782008-01-24 19:38:38 +01002037 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07002038 struct sta_info *sta;
Johannes Berg8318d782008-01-24 19:38:38 +01002039 u64 rates, basic_rates;
Jiri Bencf0706e822007-05-05 11:45:53 -07002040 u16 capab_info, status_code, aid;
2041 struct ieee802_11_elems elems;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002042 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
Jiri Bencf0706e822007-05-05 11:45:53 -07002043 u8 *pos;
2044 int i, j;
Joe Perches0795af52007-10-03 17:59:30 -07002045 DECLARE_MAC_BUF(mac);
Johannes Berg8318d782008-01-24 19:38:38 +01002046 bool have_higher_than_11mbit = false;
Jiri Bencf0706e822007-05-05 11:45:53 -07002047
2048 /* AssocResp and ReassocResp have identical structure, so process both
2049 * of them in this function. */
2050
2051 if (ifsta->state != IEEE80211_ASSOCIATE) {
2052 printk(KERN_DEBUG "%s: association frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07002053 "%s, but not in associate state - ignored\n",
2054 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07002055 return;
2056 }
2057
2058 if (len < 24 + 6) {
2059 printk(KERN_DEBUG "%s: too short (%zd) association frame "
Joe Perches0795af52007-10-03 17:59:30 -07002060 "received from %s - ignored\n",
2061 dev->name, len, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07002062 return;
2063 }
2064
2065 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
2066 printk(KERN_DEBUG "%s: association frame received from "
Joe Perches0795af52007-10-03 17:59:30 -07002067 "unknown AP (SA=%s BSSID=%s) - "
2068 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
2069 print_mac(mac, mgmt->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07002070 return;
2071 }
2072
2073 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2074 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2075 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e822007-05-05 11:45:53 -07002076
Joe Perches0795af52007-10-03 17:59:30 -07002077 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
Jiri Bencf0706e822007-05-05 11:45:53 -07002078 "status=%d aid=%d)\n",
Joe Perches0795af52007-10-03 17:59:30 -07002079 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
Johannes Bergddd68582007-10-22 14:51:37 +02002080 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e822007-05-05 11:45:53 -07002081
2082 if (status_code != WLAN_STATUS_SUCCESS) {
2083 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
2084 dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02002085 /* if this was a reassociation, ensure we try a "full"
2086 * association next time. This works around some broken APs
2087 * which do not correctly reject reassociation requests. */
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002088 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e822007-05-05 11:45:53 -07002089 return;
2090 }
2091
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002092 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2093 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
2094 "set\n", dev->name, aid);
2095 aid &= ~(BIT(15) | BIT(14));
2096
Jiri Bencf0706e822007-05-05 11:45:53 -07002097 pos = mgmt->u.assoc_resp.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04002098 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07002099
2100 if (!elems.supp_rates) {
2101 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
2102 dev->name);
2103 return;
2104 }
2105
2106 printk(KERN_DEBUG "%s: associated\n", dev->name);
2107 ifsta->aid = aid;
2108 ifsta->ap_capab = capab_info;
2109
2110 kfree(ifsta->assocresp_ies);
2111 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
Michael Wu0ec0b7a2007-07-27 15:43:24 +02002112 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -07002113 if (ifsta->assocresp_ies)
2114 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
2115
Johannes Bergd0709a62008-02-25 16:27:46 +01002116 rcu_read_lock();
2117
Jiri Bencf0706e822007-05-05 11:45:53 -07002118 /* Add STA entry for the AP */
2119 sta = sta_info_get(local, ifsta->bssid);
2120 if (!sta) {
2121 struct ieee80211_sta_bss *bss;
Johannes Berg73651ee2008-02-25 16:27:47 +01002122 int err;
Johannes Bergd0709a62008-02-25 16:27:46 +01002123
Johannes Berg73651ee2008-02-25 16:27:47 +01002124 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
2125 if (!sta) {
2126 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
2127 " the AP\n", dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01002128 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07002129 return;
2130 }
John W. Linville65c107a2007-10-05 14:23:27 -04002131 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01002132 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002133 ifsta->ssid, ifsta->ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07002134 if (bss) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002135 sta->last_signal = bss->signal;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002136 sta->last_qual = bss->qual;
Jiri Bencf0706e822007-05-05 11:45:53 -07002137 sta->last_noise = bss->noise;
2138 ieee80211_rx_bss_put(dev, bss);
2139 }
Johannes Berg73651ee2008-02-25 16:27:47 +01002140
2141 err = sta_info_insert(sta);
2142 if (err) {
2143 printk(KERN_DEBUG "%s: failed to insert STA entry for"
2144 " the AP (error %d)\n", dev->name, err);
Johannes Berg73651ee2008-02-25 16:27:47 +01002145 rcu_read_unlock();
2146 return;
2147 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002148 }
2149
Johannes Berg73651ee2008-02-25 16:27:47 +01002150 /*
2151 * FIXME: Do we really need to update the sta_info's information here?
2152 * We already know about the AP (we found it in our list) so it
2153 * should already be filled with the right info, no?
2154 * As is stands, all this is racy because typically we assume
2155 * the information that is filled in here (except flags) doesn't
2156 * change while a STA structure is alive. As such, it should move
2157 * to between the sta_info_alloc() and sta_info_insert() above.
2158 */
2159
Johannes Berg07346f812008-05-03 01:02:02 +02002160 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
2161 WLAN_STA_AUTHORIZED);
Jiri Bencf0706e822007-05-05 11:45:53 -07002162
2163 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002164 basic_rates = 0;
2165 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2166
Jiri Bencf0706e822007-05-05 11:45:53 -07002167 for (i = 0; i < elems.supp_rates_len; i++) {
2168 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01002169
2170 if (rate > 110)
2171 have_higher_than_11mbit = true;
2172
2173 for (j = 0; j < sband->n_bitrates; j++) {
2174 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e822007-05-05 11:45:53 -07002175 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01002176 if (elems.supp_rates[i] & 0x80)
2177 basic_rates |= BIT(j);
2178 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002179 }
Johannes Berg8318d782008-01-24 19:38:38 +01002180
Jiri Bencf0706e822007-05-05 11:45:53 -07002181 for (i = 0; i < elems.ext_supp_rates_len; i++) {
2182 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01002183
2184 if (rate > 110)
2185 have_higher_than_11mbit = true;
2186
2187 for (j = 0; j < sband->n_bitrates; j++) {
2188 if (sband->bitrates[j].bitrate == rate)
Jiri Bencf0706e822007-05-05 11:45:53 -07002189 rates |= BIT(j);
Johannes Berg8318d782008-01-24 19:38:38 +01002190 if (elems.ext_supp_rates[i] & 0x80)
2191 basic_rates |= BIT(j);
2192 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002193 }
Johannes Berg8318d782008-01-24 19:38:38 +01002194
2195 sta->supp_rates[local->hw.conf.channel->band] = rates;
2196 sdata->basic_rates = basic_rates;
2197
2198 /* cf. IEEE 802.11 9.2.12 */
2199 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
2200 have_higher_than_11mbit)
2201 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
2202 else
2203 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e822007-05-05 11:45:53 -07002204
Johannes Berg3434fbd2008-05-03 00:59:37 +02002205 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
2206 (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002207 struct ieee80211_ht_bss_info bss_info;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002208 ieee80211_ht_cap_ie_to_ht_info(
2209 (struct ieee80211_ht_cap *)
2210 elems.ht_cap_elem, &sta->ht_info);
2211 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2212 (struct ieee80211_ht_addt_info *)
2213 elems.ht_info_elem, &bss_info);
Tomas Winkler38668c02008-03-28 16:33:32 -07002214 ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002215 }
2216
Jiri Bencf0706e822007-05-05 11:45:53 -07002217 rate_control_rate_init(sta, local);
2218
Johannes Berg3434fbd2008-05-03 00:59:37 +02002219 if (elems.wmm_param) {
Johannes Berg07346f812008-05-03 01:02:02 +02002220 set_sta_flags(sta, WLAN_STA_WME);
Johannes Berge5f98f22008-03-05 20:39:31 +01002221 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07002222 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2223 elems.wmm_param_len);
Johannes Berge5f98f22008-03-05 20:39:31 +01002224 } else
2225 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07002226
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002227 /* set AID and assoc capability,
2228 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002229 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002230 bss_conf->assoc_capability = capab_info;
Johannes Berg8318d782008-01-24 19:38:38 +01002231 ieee80211_set_associated(dev, ifsta, 1);
Jiri Bencf0706e822007-05-05 11:45:53 -07002232
Jiri Bencf0706e822007-05-05 11:45:53 -07002233 ieee80211_associated(dev, ifsta);
2234}
2235
2236
2237/* Caller must hold local->sta_bss_lock */
2238static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
2239 struct ieee80211_sta_bss *bss)
2240{
2241 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002242 u8 hash_idx;
Johannes Berg902acc72008-02-23 15:17:19 +01002243
2244 if (bss_mesh_cfg(bss))
2245 hash_idx = mesh_id_hash(bss_mesh_id(bss),
2246 bss_mesh_id_len(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002247 else
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002248 hash_idx = STA_HASH(bss->bssid);
Johannes Berg902acc72008-02-23 15:17:19 +01002249
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002250 bss->hnext = local->sta_bss_hash[hash_idx];
2251 local->sta_bss_hash[hash_idx] = bss;
Jiri Bencf0706e822007-05-05 11:45:53 -07002252}
2253
2254
2255/* Caller must hold local->sta_bss_lock */
2256static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
2257 struct ieee80211_sta_bss *bss)
2258{
2259 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2260 struct ieee80211_sta_bss *b, *prev = NULL;
2261 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
2262 while (b) {
2263 if (b == bss) {
2264 if (!prev)
2265 local->sta_bss_hash[STA_HASH(bss->bssid)] =
2266 bss->hnext;
2267 else
2268 prev->hnext = bss->hnext;
2269 break;
2270 }
2271 prev = b;
2272 b = b->hnext;
2273 }
2274}
2275
2276
2277static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +01002278ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002279 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e822007-05-05 11:45:53 -07002280{
2281 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2282 struct ieee80211_sta_bss *bss;
2283
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002284 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
Jiri Bencf0706e822007-05-05 11:45:53 -07002285 if (!bss)
2286 return NULL;
Jiri Bencf0706e822007-05-05 11:45:53 -07002287 atomic_inc(&bss->users);
2288 atomic_inc(&bss->users);
2289 memcpy(bss->bssid, bssid, ETH_ALEN);
Johannes Berg8318d782008-01-24 19:38:38 +01002290 bss->freq = freq;
John W. Linvillecffdd302007-10-05 14:23:27 -04002291 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
2292 memcpy(bss->ssid, ssid, ssid_len);
2293 bss->ssid_len = ssid_len;
2294 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002295
2296 spin_lock_bh(&local->sta_bss_lock);
2297 /* TODO: order by RSSI? */
2298 list_add_tail(&bss->list, &local->sta_bss_list);
2299 __ieee80211_rx_bss_hash_add(dev, bss);
2300 spin_unlock_bh(&local->sta_bss_lock);
2301 return bss;
2302}
2303
Jiri Bencf0706e822007-05-05 11:45:53 -07002304static struct ieee80211_sta_bss *
Johannes Berg8318d782008-01-24 19:38:38 +01002305ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002306 u8 *ssid, u8 ssid_len)
Jiri Bencf0706e822007-05-05 11:45:53 -07002307{
2308 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2309 struct ieee80211_sta_bss *bss;
2310
2311 spin_lock_bh(&local->sta_bss_lock);
2312 bss = local->sta_bss_hash[STA_HASH(bssid)];
2313 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002314 if (!bss_mesh_cfg(bss) &&
2315 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
Johannes Berg8318d782008-01-24 19:38:38 +01002316 bss->freq == freq &&
John W. Linvillecffdd302007-10-05 14:23:27 -04002317 bss->ssid_len == ssid_len &&
2318 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002319 atomic_inc(&bss->users);
2320 break;
2321 }
2322 bss = bss->hnext;
2323 }
2324 spin_unlock_bh(&local->sta_bss_lock);
2325 return bss;
2326}
2327
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002328#ifdef CONFIG_MAC80211_MESH
2329static struct ieee80211_sta_bss *
2330ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2331 u8 *mesh_cfg, int freq)
2332{
2333 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2334 struct ieee80211_sta_bss *bss;
2335
2336 spin_lock_bh(&local->sta_bss_lock);
2337 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2338 while (bss) {
Johannes Berg902acc72008-02-23 15:17:19 +01002339 if (bss_mesh_cfg(bss) &&
2340 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002341 bss->freq == freq &&
2342 mesh_id_len == bss->mesh_id_len &&
2343 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2344 mesh_id_len))) {
2345 atomic_inc(&bss->users);
2346 break;
2347 }
2348 bss = bss->hnext;
2349 }
2350 spin_unlock_bh(&local->sta_bss_lock);
2351 return bss;
2352}
2353
2354static struct ieee80211_sta_bss *
2355ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002356 u8 *mesh_cfg, int mesh_config_len, int freq)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002357{
2358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2359 struct ieee80211_sta_bss *bss;
2360
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002361 if (mesh_config_len != MESH_CFG_LEN)
2362 return NULL;
2363
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002364 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2365 if (!bss)
2366 return NULL;
2367
John W. Linville24736702008-04-08 14:15:46 -04002368 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002369 if (!bss->mesh_cfg) {
2370 kfree(bss);
2371 return NULL;
2372 }
2373
2374 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2375 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2376 if (!bss->mesh_id) {
2377 kfree(bss->mesh_cfg);
2378 kfree(bss);
2379 return NULL;
2380 }
2381 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2382 }
2383
2384 atomic_inc(&bss->users);
2385 atomic_inc(&bss->users);
John W. Linville24736702008-04-08 14:15:46 -04002386 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002387 bss->mesh_id_len = mesh_id_len;
2388 bss->freq = freq;
2389 spin_lock_bh(&local->sta_bss_lock);
2390 /* TODO: order by RSSI? */
2391 list_add_tail(&bss->list, &local->sta_bss_list);
2392 __ieee80211_rx_bss_hash_add(dev, bss);
2393 spin_unlock_bh(&local->sta_bss_lock);
2394 return bss;
2395}
2396#endif
Jiri Bencf0706e822007-05-05 11:45:53 -07002397
2398static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2399{
2400 kfree(bss->wpa_ie);
2401 kfree(bss->rsn_ie);
2402 kfree(bss->wmm_ie);
Ron Rindjunskyc7153502007-11-26 16:14:31 +02002403 kfree(bss->ht_ie);
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002404 kfree(bss->ht_add_ie);
Johannes Berg902acc72008-02-23 15:17:19 +01002405 kfree(bss_mesh_id(bss));
2406 kfree(bss_mesh_cfg(bss));
Jiri Bencf0706e822007-05-05 11:45:53 -07002407 kfree(bss);
2408}
2409
2410
2411static void ieee80211_rx_bss_put(struct net_device *dev,
2412 struct ieee80211_sta_bss *bss)
2413{
2414 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e822007-05-05 11:45:53 -07002415
Pavel Emelyanov1ebebea2008-04-23 11:47:15 +04002416 local_bh_disable();
2417 if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
2418 local_bh_enable();
2419 return;
2420 }
2421
Jiri Bencf0706e822007-05-05 11:45:53 -07002422 __ieee80211_rx_bss_hash_del(dev, bss);
2423 list_del(&bss->list);
2424 spin_unlock_bh(&local->sta_bss_lock);
2425 ieee80211_rx_bss_free(bss);
2426}
2427
2428
2429void ieee80211_rx_bss_list_init(struct net_device *dev)
2430{
2431 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2432 spin_lock_init(&local->sta_bss_lock);
2433 INIT_LIST_HEAD(&local->sta_bss_list);
2434}
2435
2436
2437void ieee80211_rx_bss_list_deinit(struct net_device *dev)
2438{
2439 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2440 struct ieee80211_sta_bss *bss, *tmp;
2441
2442 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
2443 ieee80211_rx_bss_put(dev, bss);
2444}
2445
2446
Bruno Randolfa6072682008-02-18 11:21:15 +09002447static int ieee80211_sta_join_ibss(struct net_device *dev,
2448 struct ieee80211_if_sta *ifsta,
2449 struct ieee80211_sta_bss *bss)
2450{
2451 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2452 int res, rates, i, j;
2453 struct sk_buff *skb;
2454 struct ieee80211_mgmt *mgmt;
Johannes Berge039fa42008-05-15 12:55:29 +02002455 struct ieee80211_tx_info *control;
Bruno Randolfa6072682008-02-18 11:21:15 +09002456 struct rate_selection ratesel;
2457 u8 *pos;
2458 struct ieee80211_sub_if_data *sdata;
2459 struct ieee80211_supported_band *sband;
Dan Williams507b06d2008-06-03 23:39:55 -04002460 union iwreq_data wrqu;
Bruno Randolfa6072682008-02-18 11:21:15 +09002461
2462 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2463
Johannes Berg9dd6aed2008-03-31 19:22:59 +02002464 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2465
Bruno Randolfa6072682008-02-18 11:21:15 +09002466 /* Remove possible STA entries from other IBSS networks. */
Johannes Bergdc6676b2008-03-31 19:23:03 +02002467 sta_info_flush_delayed(sdata);
Bruno Randolfa6072682008-02-18 11:21:15 +09002468
2469 if (local->ops->reset_tsf) {
2470 /* Reset own TSF to allow time synchronization work. */
2471 local->ops->reset_tsf(local_to_hw(local));
2472 }
2473 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2474 res = ieee80211_if_config(dev);
2475 if (res)
2476 return res;
2477
2478 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2479
Bruno Randolfa6072682008-02-18 11:21:15 +09002480 sdata->drop_unencrypted = bss->capability &
2481 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2482
Assaf Kraussbe038b32008-06-05 19:55:21 +03002483 res = ieee80211_set_freq(dev, bss->freq);
Bruno Randolfa6072682008-02-18 11:21:15 +09002484
Assaf Kraussbe038b32008-06-05 19:55:21 +03002485 if (res)
2486 return res;
Bruno Randolfa6072682008-02-18 11:21:15 +09002487
2488 /* Set beacon template */
2489 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2490 do {
2491 if (!skb)
2492 break;
2493
2494 skb_reserve(skb, local->hw.extra_tx_headroom);
2495
2496 mgmt = (struct ieee80211_mgmt *)
2497 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2498 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2499 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2500 IEEE80211_STYPE_BEACON);
2501 memset(mgmt->da, 0xff, ETH_ALEN);
2502 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2503 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2504 mgmt->u.beacon.beacon_int =
2505 cpu_to_le16(local->hw.conf.beacon_int);
2506 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2507
2508 pos = skb_put(skb, 2 + ifsta->ssid_len);
2509 *pos++ = WLAN_EID_SSID;
2510 *pos++ = ifsta->ssid_len;
2511 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2512
2513 rates = bss->supp_rates_len;
2514 if (rates > 8)
2515 rates = 8;
2516 pos = skb_put(skb, 2 + rates);
2517 *pos++ = WLAN_EID_SUPP_RATES;
2518 *pos++ = rates;
2519 memcpy(pos, bss->supp_rates, rates);
2520
2521 if (bss->band == IEEE80211_BAND_2GHZ) {
2522 pos = skb_put(skb, 2 + 1);
2523 *pos++ = WLAN_EID_DS_PARAMS;
2524 *pos++ = 1;
2525 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2526 }
2527
2528 pos = skb_put(skb, 2 + 2);
2529 *pos++ = WLAN_EID_IBSS_PARAMS;
2530 *pos++ = 2;
2531 /* FIX: set ATIM window based on scan results */
2532 *pos++ = 0;
2533 *pos++ = 0;
2534
2535 if (bss->supp_rates_len > 8) {
2536 rates = bss->supp_rates_len - 8;
2537 pos = skb_put(skb, 2 + rates);
2538 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2539 *pos++ = rates;
2540 memcpy(pos, &bss->supp_rates[8], rates);
2541 }
2542
Johannes Berge039fa42008-05-15 12:55:29 +02002543 control = IEEE80211_SKB_CB(skb);
2544
Bruno Randolfa6072682008-02-18 11:21:15 +09002545 rate_control_get_rate(dev, sband, skb, &ratesel);
Johannes Berg2e92e6f2008-05-15 12:55:27 +02002546 if (ratesel.rate_idx < 0) {
Bruno Randolfa6072682008-02-18 11:21:15 +09002547 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2548 "for IBSS beacon\n", dev->name);
2549 break;
2550 }
Johannes Berge039fa42008-05-15 12:55:29 +02002551 control->control.vif = &sdata->vif;
2552 control->tx_rate_idx = ratesel.rate_idx;
Bruno Randolfa6072682008-02-18 11:21:15 +09002553 if (sdata->bss_conf.use_short_preamble &&
Johannes Berg2e92e6f2008-05-15 12:55:27 +02002554 sband->bitrates[ratesel.rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE)
Johannes Berge039fa42008-05-15 12:55:29 +02002555 control->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE;
2556 control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2557 control->flags |= IEEE80211_TX_CTL_NO_ACK;
2558 control->control.retry_limit = 1;
Bruno Randolfa6072682008-02-18 11:21:15 +09002559
2560 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2561 if (ifsta->probe_resp) {
2562 mgmt = (struct ieee80211_mgmt *)
2563 ifsta->probe_resp->data;
2564 mgmt->frame_control =
2565 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2566 IEEE80211_STYPE_PROBE_RESP);
2567 } else {
2568 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2569 "template for IBSS\n", dev->name);
2570 }
2571
2572 if (local->ops->beacon_update &&
Johannes Berge039fa42008-05-15 12:55:29 +02002573 local->ops->beacon_update(local_to_hw(local), skb) == 0) {
Bruno Randolfa6072682008-02-18 11:21:15 +09002574 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2575 "template\n", dev->name);
2576 skb = NULL;
2577 }
2578
2579 rates = 0;
2580 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2581 for (i = 0; i < bss->supp_rates_len; i++) {
2582 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2583 for (j = 0; j < sband->n_bitrates; j++)
2584 if (sband->bitrates[j].bitrate == bitrate)
2585 rates |= BIT(j);
2586 }
2587 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
Vladimir Koutnye2839d82008-03-18 21:14:07 +01002588
2589 ieee80211_sta_def_wmm_params(dev, bss, 1);
Bruno Randolfa6072682008-02-18 11:21:15 +09002590 } while (0);
2591
2592 if (skb) {
2593 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2594 "template\n", dev->name);
2595 dev_kfree_skb(skb);
2596 }
2597
2598 ifsta->state = IEEE80211_IBSS_JOINED;
2599 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2600
Dan Williams507b06d2008-06-03 23:39:55 -04002601 memset(&wrqu, 0, sizeof(wrqu));
2602 memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
2603 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Bruno Randolfa6072682008-02-18 11:21:15 +09002604
2605 return res;
2606}
2607
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002608u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2609 struct ieee802_11_elems *elems,
2610 enum ieee80211_band band)
2611{
2612 struct ieee80211_supported_band *sband;
2613 struct ieee80211_rate *bitrates;
2614 size_t num_rates;
2615 u64 supp_rates;
2616 int i, j;
2617 sband = local->hw.wiphy->bands[band];
2618
2619 if (!sband) {
2620 WARN_ON(1);
2621 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2622 }
2623
2624 bitrates = sband->bitrates;
2625 num_rates = sband->n_bitrates;
2626 supp_rates = 0;
2627 for (i = 0; i < elems->supp_rates_len +
2628 elems->ext_supp_rates_len; i++) {
2629 u8 rate = 0;
2630 int own_rate;
2631 if (i < elems->supp_rates_len)
2632 rate = elems->supp_rates[i];
2633 else if (elems->ext_supp_rates)
2634 rate = elems->ext_supp_rates
2635 [i - elems->supp_rates_len];
2636 own_rate = 5 * (rate & 0x7f);
2637 for (j = 0; j < num_rates; j++)
2638 if (bitrates[j].bitrate == own_rate)
2639 supp_rates |= BIT(j);
2640 }
2641 return supp_rates;
2642}
2643
Bruno Randolfa6072682008-02-18 11:21:15 +09002644
Jiri Bencf0706e822007-05-05 11:45:53 -07002645static void ieee80211_rx_bss_info(struct net_device *dev,
2646 struct ieee80211_mgmt *mgmt,
2647 size_t len,
2648 struct ieee80211_rx_status *rx_status,
2649 int beacon)
2650{
2651 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2652 struct ieee802_11_elems elems;
2653 size_t baselen;
Johannes Berg8318d782008-01-24 19:38:38 +01002654 int freq, clen;
Jiri Bencf0706e822007-05-05 11:45:53 -07002655 struct ieee80211_sta_bss *bss;
2656 struct sta_info *sta;
2657 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002658 u64 beacon_timestamp, rx_timestamp;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002659 struct ieee80211_channel *channel;
Joe Perches0795af52007-10-03 17:59:30 -07002660 DECLARE_MAC_BUF(mac);
2661 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e822007-05-05 11:45:53 -07002662
2663 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
2664 return; /* ignore ProbeResp to foreign address */
2665
2666#if 0
Joe Perches0795af52007-10-03 17:59:30 -07002667 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
Jiri Bencf0706e822007-05-05 11:45:53 -07002668 dev->name, beacon ? "Beacon" : "Probe Response",
Joe Perches0795af52007-10-03 17:59:30 -07002669 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
Jiri Bencf0706e822007-05-05 11:45:53 -07002670#endif
2671
2672 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2673 if (baselen > len)
2674 return;
2675
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002676 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
John W. Linville67a4cce2007-10-12 16:40:37 -04002677 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07002678
Johannes Berg902acc72008-02-23 15:17:19 +01002679 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
2680 elems.mesh_config && mesh_matches_local(&elems, dev)) {
2681 u64 rates = ieee80211_sta_get_rates(local, &elems,
2682 rx_status->band);
2683
2684 mesh_neighbour_update(mgmt->sa, rates, dev,
2685 mesh_peer_accepts_plinks(&elems, dev));
2686 }
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002687
Johannes Bergd0709a62008-02-25 16:27:46 +01002688 rcu_read_lock();
2689
Johannes Berg51fb61e2007-12-19 01:31:27 +01002690 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
Jiri Bencf0706e822007-05-05 11:45:53 -07002691 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2692 (sta = sta_info_get(local, mgmt->sa))) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002693 u64 prev_rates;
2694 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
2695 rx_status->band);
Jiri Bencf0706e822007-05-05 11:45:53 -07002696
Johannes Berg8318d782008-01-24 19:38:38 +01002697 prev_rates = sta->supp_rates[rx_status->band];
2698 sta->supp_rates[rx_status->band] &= supp_rates;
2699 if (sta->supp_rates[rx_status->band] == 0) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002700 /* No matching rates - this should not really happen.
2701 * Make sure that at least one rate is marked
2702 * supported to avoid issues with TX rate ctrl. */
Johannes Berg8318d782008-01-24 19:38:38 +01002703 sta->supp_rates[rx_status->band] =
2704 sdata->u.sta.supp_rates_bits[rx_status->band];
Jiri Bencf0706e822007-05-05 11:45:53 -07002705 }
Johannes Berg8318d782008-01-24 19:38:38 +01002706 if (sta->supp_rates[rx_status->band] != prev_rates) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002707 printk(KERN_DEBUG "%s: updated supp_rates set for "
Johannes Berg8318d782008-01-24 19:38:38 +01002708 "%s based on beacon info (0x%llx & 0x%llx -> "
2709 "0x%llx)\n",
2710 dev->name, print_mac(mac, sta->addr),
2711 (unsigned long long) prev_rates,
2712 (unsigned long long) supp_rates,
2713 (unsigned long long) sta->supp_rates[rx_status->band]);
Jiri Bencf0706e822007-05-05 11:45:53 -07002714 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002715 }
2716
Johannes Bergd0709a62008-02-25 16:27:46 +01002717 rcu_read_unlock();
2718
Jiri Bencf0706e822007-05-05 11:45:53 -07002719 if (elems.ds_params && elems.ds_params_len == 1)
Johannes Berg8318d782008-01-24 19:38:38 +01002720 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
Jiri Bencf0706e822007-05-05 11:45:53 -07002721 else
Johannes Berg8318d782008-01-24 19:38:38 +01002722 freq = rx_status->freq;
Jiri Bencf0706e822007-05-05 11:45:53 -07002723
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002724 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2725
2726 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2727 return;
2728
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002729#ifdef CONFIG_MAC80211_MESH
2730 if (elems.mesh_config)
2731 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
2732 elems.mesh_id_len, elems.mesh_config, freq);
2733 else
2734#endif
2735 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04002736 elems.ssid, elems.ssid_len);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002737 if (!bss) {
2738#ifdef CONFIG_MAC80211_MESH
2739 if (elems.mesh_config)
2740 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
Luis Carlos Cobo05e5e882008-03-31 16:00:13 -07002741 elems.mesh_id_len, elems.mesh_config,
2742 elems.mesh_config_len, freq);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01002743 else
2744#endif
2745 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2746 elems.ssid, elems.ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07002747 if (!bss)
2748 return;
2749 } else {
2750#if 0
2751 /* TODO: order by RSSI? */
2752 spin_lock_bh(&local->sta_bss_lock);
2753 list_move_tail(&bss->list, &local->sta_bss_list);
2754 spin_unlock_bh(&local->sta_bss_lock);
2755#endif
2756 }
2757
Daniel Drake56282212007-07-10 19:32:10 +02002758 /* save the ERP value so that it is available at association time */
2759 if (elems.erp_info && elems.erp_info_len >= 1) {
2760 bss->erp_value = elems.erp_info[0];
2761 bss->has_erp_value = 1;
2762 }
2763
Johannes Berg30b89b02008-04-16 17:43:20 +02002764 if (elems.ht_cap_elem &&
2765 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2766 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2767 kfree(bss->ht_ie);
2768 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2769 if (bss->ht_ie) {
2770 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2771 elems.ht_cap_elem_len + 2);
2772 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2773 } else
2774 bss->ht_ie_len = 0;
2775 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2776 kfree(bss->ht_ie);
2777 bss->ht_ie = NULL;
2778 bss->ht_ie_len = 0;
2779 }
2780
Emmanuel Grumbach93061022008-05-29 16:35:23 +08002781 if (elems.ht_info_elem &&
2782 (!bss->ht_add_ie ||
2783 bss->ht_add_ie_len != elems.ht_info_elem_len ||
2784 memcmp(bss->ht_add_ie, elems.ht_info_elem,
2785 elems.ht_info_elem_len))) {
2786 kfree(bss->ht_add_ie);
2787 bss->ht_add_ie =
2788 kmalloc(elems.ht_info_elem_len + 2, GFP_ATOMIC);
2789 if (bss->ht_add_ie) {
2790 memcpy(bss->ht_add_ie, elems.ht_info_elem - 2,
2791 elems.ht_info_elem_len + 2);
2792 bss->ht_add_ie_len = elems.ht_info_elem_len + 2;
2793 } else
2794 bss->ht_add_ie_len = 0;
2795 } else if (!elems.ht_info_elem && bss->ht_add_ie) {
2796 kfree(bss->ht_add_ie);
2797 bss->ht_add_ie = NULL;
2798 bss->ht_add_ie_len = 0;
2799 }
2800
Jiri Bencf0706e822007-05-05 11:45:53 -07002801 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2802 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
Jiri Bencf0706e822007-05-05 11:45:53 -07002803
2804 bss->supp_rates_len = 0;
2805 if (elems.supp_rates) {
2806 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2807 if (clen > elems.supp_rates_len)
2808 clen = elems.supp_rates_len;
2809 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
2810 clen);
2811 bss->supp_rates_len += clen;
2812 }
2813 if (elems.ext_supp_rates) {
2814 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2815 if (clen > elems.ext_supp_rates_len)
2816 clen = elems.ext_supp_rates_len;
2817 memcpy(&bss->supp_rates[bss->supp_rates_len],
2818 elems.ext_supp_rates, clen);
2819 bss->supp_rates_len += clen;
2820 }
2821
Johannes Berg30b89b02008-04-16 17:43:20 +02002822 bss->band = rx_status->band;
2823
2824 bss->timestamp = beacon_timestamp;
2825 bss->last_update = jiffies;
Johannes Berg30b89b02008-04-16 17:43:20 +02002826 bss->signal = rx_status->signal;
2827 bss->noise = rx_status->noise;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002828 bss->qual = rx_status->qual;
Johannes Berg30b89b02008-04-16 17:43:20 +02002829 if (!beacon && !bss->probe_resp)
2830 bss->probe_resp = true;
2831
2832 /*
2833 * In STA mode, the remaining parameters should not be overridden
2834 * by beacons because they're not necessarily accurate there.
2835 */
2836 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2837 bss->probe_resp && beacon) {
2838 ieee80211_rx_bss_put(dev, bss);
2839 return;
2840 }
2841
Jiri Bencf0706e822007-05-05 11:45:53 -07002842 if (elems.wpa &&
2843 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
2844 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
2845 kfree(bss->wpa_ie);
2846 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
2847 if (bss->wpa_ie) {
2848 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
2849 bss->wpa_ie_len = elems.wpa_len + 2;
2850 } else
2851 bss->wpa_ie_len = 0;
2852 } else if (!elems.wpa && bss->wpa_ie) {
2853 kfree(bss->wpa_ie);
2854 bss->wpa_ie = NULL;
2855 bss->wpa_ie_len = 0;
2856 }
2857
2858 if (elems.rsn &&
2859 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2860 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2861 kfree(bss->rsn_ie);
2862 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2863 if (bss->rsn_ie) {
2864 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2865 bss->rsn_ie_len = elems.rsn_len + 2;
2866 } else
2867 bss->rsn_ie_len = 0;
2868 } else if (!elems.rsn && bss->rsn_ie) {
2869 kfree(bss->rsn_ie);
2870 bss->rsn_ie = NULL;
2871 bss->rsn_ie_len = 0;
2872 }
2873
Johannes Berg30b89b02008-04-16 17:43:20 +02002874 /*
2875 * Cf.
2876 * http://www.wipo.int/pctdb/en/wo.jsp?wo=2007047181&IA=WO2007047181&DISPLAY=DESC
2877 *
2878 * quoting:
2879 *
2880 * In particular, "Wi-Fi CERTIFIED for WMM - Support for Multimedia
2881 * Applications with Quality of Service in Wi-Fi Networks," Wi- Fi
2882 * Alliance (September 1, 2004) is incorporated by reference herein.
2883 * The inclusion of the WMM Parameters in probe responses and
2884 * association responses is mandatory for WMM enabled networks. The
2885 * inclusion of the WMM Parameters in beacons, however, is optional.
2886 */
2887
Jiri Bencf0706e822007-05-05 11:45:53 -07002888 if (elems.wmm_param &&
2889 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2890 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2891 kfree(bss->wmm_ie);
2892 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2893 if (bss->wmm_ie) {
2894 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2895 elems.wmm_param_len + 2);
2896 bss->wmm_ie_len = elems.wmm_param_len + 2;
2897 } else
2898 bss->wmm_ie_len = 0;
Abhijeet Kolekara46f0252008-04-16 14:02:04 -07002899 } else if (elems.wmm_info &&
2900 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_info_len ||
2901 memcmp(bss->wmm_ie, elems.wmm_info, elems.wmm_info_len))) {
2902 /* As for certain AP's Fifth bit is not set in WMM IE in
2903 * beacon frames.So while parsing the beacon frame the
2904 * wmm_info structure is used instead of wmm_param.
2905 * wmm_info structure was never used to set bss->wmm_ie.
2906 * This code fixes this problem by copying the WME
2907 * information from wmm_info to bss->wmm_ie and enabling
2908 * n-band association.
2909 */
2910 kfree(bss->wmm_ie);
2911 bss->wmm_ie = kmalloc(elems.wmm_info_len + 2, GFP_ATOMIC);
2912 if (bss->wmm_ie) {
2913 memcpy(bss->wmm_ie, elems.wmm_info - 2,
2914 elems.wmm_info_len + 2);
2915 bss->wmm_ie_len = elems.wmm_info_len + 2;
2916 } else
2917 bss->wmm_ie_len = 0;
2918 } else if (!elems.wmm_param && !elems.wmm_info && bss->wmm_ie) {
Jiri Bencf0706e822007-05-05 11:45:53 -07002919 kfree(bss->wmm_ie);
2920 bss->wmm_ie = NULL;
2921 bss->wmm_ie_len = 0;
2922 }
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002923
2924 /* check if we need to merge IBSS */
2925 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2926 !local->sta_sw_scanning && !local->sta_hw_scanning &&
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002927 bss->capability & WLAN_CAPABILITY_IBSS &&
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002928 bss->freq == local->oper_channel->center_freq &&
2929 elems.ssid_len == sdata->u.sta.ssid_len &&
2930 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2931 if (rx_status->flag & RX_FLAG_TSFT) {
2932 /* in order for correct IBSS merging we need mactime
2933 *
2934 * since mactime is defined as the time the first data
2935 * symbol of the frame hits the PHY, and the timestamp
2936 * of the beacon is defined as "the time that the data
2937 * symbol containing the first bit of the timestamp is
2938 * transmitted to the PHY plus the transmitting STA’s
2939 * delays through its local PHY from the MAC-PHY
2940 * interface to its interface with the WM"
2941 * (802.11 11.1.2) - equals the time this bit arrives at
2942 * the receiver - we have to take into account the
2943 * offset between the two.
2944 * e.g: at 1 MBit that means mactime is 192 usec earlier
2945 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2946 */
2947 int rate = local->hw.wiphy->bands[rx_status->band]->
2948 bitrates[rx_status->rate_idx].bitrate;
2949 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2950 } else if (local && local->ops && local->ops->get_tsf)
2951 /* second best option: get current TSF */
2952 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2953 else
2954 /* can't merge without knowing the TSF */
2955 rx_timestamp = -1LLU;
2956#ifdef CONFIG_MAC80211_IBSS_DEBUG
2957 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2958 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2959 print_mac(mac, mgmt->sa),
2960 print_mac(mac2, mgmt->bssid),
2961 (unsigned long long)rx_timestamp,
2962 (unsigned long long)beacon_timestamp,
2963 (unsigned long long)(rx_timestamp - beacon_timestamp),
2964 jiffies);
2965#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2966 if (beacon_timestamp > rx_timestamp) {
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002967#ifndef CONFIG_MAC80211_IBSS_DEBUG
Pavel Roskind97cf012008-02-21 11:33:58 -05002968 if (net_ratelimit())
Johannes Bergfba4a1e2008-02-21 11:08:33 +01002969#endif
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002970 printk(KERN_DEBUG "%s: beacon TSF higher than "
2971 "local TSF - IBSS merge with BSSID %s\n",
2972 dev->name, print_mac(mac, mgmt->bssid));
2973 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2974 ieee80211_ibss_add_sta(dev, NULL,
Vladimir Koutny87291c02008-06-13 16:50:44 +02002975 mgmt->bssid, mgmt->sa,
2976 BIT(rx_status->rate_idx));
Bruno Randolf9d9bf772008-02-18 11:21:36 +09002977 }
2978 }
2979
Jiri Bencf0706e822007-05-05 11:45:53 -07002980 ieee80211_rx_bss_put(dev, bss);
2981}
2982
2983
2984static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2985 struct ieee80211_mgmt *mgmt,
2986 size_t len,
2987 struct ieee80211_rx_status *rx_status)
2988{
2989 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2990}
2991
2992
2993static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2994 struct ieee80211_mgmt *mgmt,
2995 size_t len,
2996 struct ieee80211_rx_status *rx_status)
2997{
Jiri Bencf0706e822007-05-05 11:45:53 -07002998 struct ieee80211_sub_if_data *sdata;
2999 struct ieee80211_if_sta *ifsta;
Jiri Bencf0706e822007-05-05 11:45:53 -07003000 size_t baselen;
3001 struct ieee802_11_elems elems;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003002 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3003 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003004 u32 changed = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07003005
3006 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
3007
3008 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01003009 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07003010 return;
3011 ifsta = &sdata->u.sta;
3012
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003013 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
Jiri Bencf0706e822007-05-05 11:45:53 -07003014 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
3015 return;
3016
3017 /* Process beacon from the current BSS */
3018 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3019 if (baselen > len)
3020 return;
3021
John W. Linville67a4cce2007-10-12 16:40:37 -04003022 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
Jiri Bencf0706e822007-05-05 11:45:53 -07003023
Johannes Berg3434fbd2008-05-03 00:59:37 +02003024 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
3025 elems.wmm_param_len);
Reinette Chatred18ef292008-04-09 16:56:15 -07003026
3027 /* Do not send changes to driver if we are scanning. This removes
3028 * requirement that driver's bss_info_changed function needs to be
3029 * atomic. */
3030 if (local->sta_sw_scanning || local->sta_hw_scanning)
3031 return;
3032
Daniel Drake56282212007-07-10 19:32:10 +02003033 if (elems.erp_info && elems.erp_info_len >= 1)
Johannes Berg471b3ef2007-12-28 14:32:58 +01003034 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
John W. Linville50c4afb2008-04-15 14:09:27 -04003035 else {
3036 u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info);
3037 changed |= ieee80211_handle_protect_preamb(sdata, false,
3038 (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
3039 }
Jiri Bencf0706e822007-05-05 11:45:53 -07003040
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003041 if (elems.ht_cap_elem && elems.ht_info_elem &&
Tomas Winkler38668c02008-03-28 16:33:32 -07003042 elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003043 struct ieee80211_ht_bss_info bss_info;
3044
3045 ieee80211_ht_addt_info_ie_to_ht_bss_info(
3046 (struct ieee80211_ht_addt_info *)
3047 elems.ht_info_elem, &bss_info);
Tomas Winkler38668c02008-03-28 16:33:32 -07003048 changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf,
3049 &bss_info);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003050 }
3051
Johannes Berg471b3ef2007-12-28 14:32:58 +01003052 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e822007-05-05 11:45:53 -07003053}
3054
3055
3056static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
3057 struct ieee80211_if_sta *ifsta,
3058 struct ieee80211_mgmt *mgmt,
3059 size_t len,
3060 struct ieee80211_rx_status *rx_status)
3061{
3062 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3063 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3064 int tx_last_beacon;
3065 struct sk_buff *skb;
3066 struct ieee80211_mgmt *resp;
3067 u8 *pos, *end;
Joe Perches0795af52007-10-03 17:59:30 -07003068 DECLARE_MAC_BUF(mac);
3069#ifdef CONFIG_MAC80211_IBSS_DEBUG
3070 DECLARE_MAC_BUF(mac2);
3071 DECLARE_MAC_BUF(mac3);
3072#endif
Jiri Bencf0706e822007-05-05 11:45:53 -07003073
Johannes Berg51fb61e2007-12-19 01:31:27 +01003074 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
Jiri Bencf0706e822007-05-05 11:45:53 -07003075 ifsta->state != IEEE80211_IBSS_JOINED ||
3076 len < 24 + 2 || !ifsta->probe_resp)
3077 return;
3078
3079 if (local->ops->tx_last_beacon)
3080 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
3081 else
3082 tx_last_beacon = 1;
3083
3084#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003085 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
3086 "%s (tx_last_beacon=%d)\n",
3087 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
3088 print_mac(mac3, mgmt->bssid), tx_last_beacon);
Jiri Bencf0706e822007-05-05 11:45:53 -07003089#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3090
3091 if (!tx_last_beacon)
3092 return;
3093
3094 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
3095 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
3096 return;
3097
3098 end = ((u8 *) mgmt) + len;
3099 pos = mgmt->u.probe_req.variable;
3100 if (pos[0] != WLAN_EID_SSID ||
3101 pos + 2 + pos[1] > end) {
3102 if (net_ratelimit()) {
3103 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
Joe Perches0795af52007-10-03 17:59:30 -07003104 "from %s\n",
3105 dev->name, print_mac(mac, mgmt->sa));
Jiri Bencf0706e822007-05-05 11:45:53 -07003106 }
3107 return;
3108 }
3109 if (pos[1] != 0 &&
3110 (pos[1] != ifsta->ssid_len ||
3111 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
3112 /* Ignore ProbeReq for foreign SSID */
3113 return;
3114 }
3115
3116 /* Reply with ProbeResp */
Michael Wu0ec0b7a2007-07-27 15:43:24 +02003117 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -07003118 if (!skb)
3119 return;
3120
3121 resp = (struct ieee80211_mgmt *) skb->data;
3122 memcpy(resp->da, mgmt->sa, ETH_ALEN);
3123#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003124 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
3125 dev->name, print_mac(mac, resp->da));
Jiri Bencf0706e822007-05-05 11:45:53 -07003126#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3127 ieee80211_sta_tx(dev, skb, 0);
3128}
3129
Johannes Berg4e20cb22007-12-19 01:31:24 +01003130static void ieee80211_rx_mgmt_action(struct net_device *dev,
3131 struct ieee80211_if_sta *ifsta,
3132 struct ieee80211_mgmt *mgmt,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003133 size_t len,
3134 struct ieee80211_rx_status *rx_status)
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003135{
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003136 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Assaf Kraussb6623482008-06-16 16:09:49 +03003137 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003138
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003139 if (len < IEEE80211_MIN_ACTION_SIZE)
3140 return;
3141
3142 switch (mgmt->u.action.category) {
Assaf Kraussb6623482008-06-16 16:09:49 +03003143 case WLAN_CATEGORY_SPECTRUM_MGMT:
3144 if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
3145 break;
3146 switch (mgmt->u.action.u.chan_switch.action_code) {
3147 case WLAN_ACTION_SPCT_MSR_REQ:
3148 if (len < (IEEE80211_MIN_ACTION_SIZE +
3149 sizeof(mgmt->u.action.u.measurement)))
3150 break;
3151 ieee80211_sta_process_measurement_req(dev, mgmt, len);
3152 break;
3153 }
3154 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003155 case WLAN_CATEGORY_BACK:
3156 switch (mgmt->u.action.u.addba_req.action_code) {
3157 case WLAN_ACTION_ADDBA_REQ:
3158 if (len < (IEEE80211_MIN_ACTION_SIZE +
3159 sizeof(mgmt->u.action.u.addba_req)))
3160 break;
3161 ieee80211_sta_process_addba_request(dev, mgmt, len);
3162 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02003163 case WLAN_ACTION_ADDBA_RESP:
3164 if (len < (IEEE80211_MIN_ACTION_SIZE +
3165 sizeof(mgmt->u.action.u.addba_resp)))
3166 break;
3167 ieee80211_sta_process_addba_resp(dev, mgmt, len);
3168 break;
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02003169 case WLAN_ACTION_DELBA:
3170 if (len < (IEEE80211_MIN_ACTION_SIZE +
3171 sizeof(mgmt->u.action.u.delba)))
3172 break;
3173 ieee80211_sta_process_delba(dev, mgmt, len);
3174 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003175 default:
3176 if (net_ratelimit())
Ron Rindjunsky688b88a2007-12-25 17:00:37 +02003177 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003178 dev->name);
3179 break;
3180 }
3181 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003182 case PLINK_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01003183 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003184 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
3185 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003186 case MESH_PATH_SEL_CATEGORY:
Johannes Berg902acc72008-02-23 15:17:19 +01003187 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003188 mesh_rx_path_sel_frame(dev, mgmt, len);
3189 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003190 default:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003191 if (net_ratelimit())
3192 printk(KERN_DEBUG "%s: Rx unknown action frame - "
3193 "category=%d\n", dev->name, mgmt->u.action.category);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003194 break;
3195 }
3196}
Jiri Bencf0706e822007-05-05 11:45:53 -07003197
3198void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
3199 struct ieee80211_rx_status *rx_status)
3200{
3201 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3202 struct ieee80211_sub_if_data *sdata;
3203 struct ieee80211_if_sta *ifsta;
3204 struct ieee80211_mgmt *mgmt;
3205 u16 fc;
3206
3207 if (skb->len < 24)
3208 goto fail;
3209
3210 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3211 ifsta = &sdata->u.sta;
3212
3213 mgmt = (struct ieee80211_mgmt *) skb->data;
3214 fc = le16_to_cpu(mgmt->frame_control);
3215
3216 switch (fc & IEEE80211_FCTL_STYPE) {
3217 case IEEE80211_STYPE_PROBE_REQ:
3218 case IEEE80211_STYPE_PROBE_RESP:
3219 case IEEE80211_STYPE_BEACON:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003220 case IEEE80211_STYPE_ACTION:
Jiri Bencf0706e822007-05-05 11:45:53 -07003221 memcpy(skb->cb, rx_status, sizeof(*rx_status));
3222 case IEEE80211_STYPE_AUTH:
3223 case IEEE80211_STYPE_ASSOC_RESP:
3224 case IEEE80211_STYPE_REASSOC_RESP:
3225 case IEEE80211_STYPE_DEAUTH:
3226 case IEEE80211_STYPE_DISASSOC:
3227 skb_queue_tail(&ifsta->skb_queue, skb);
3228 queue_work(local->hw.workqueue, &ifsta->work);
3229 return;
3230 default:
3231 printk(KERN_DEBUG "%s: received unknown management frame - "
3232 "stype=%d\n", dev->name,
3233 (fc & IEEE80211_FCTL_STYPE) >> 4);
3234 break;
3235 }
3236
3237 fail:
3238 kfree_skb(skb);
3239}
3240
3241
3242static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
3243 struct sk_buff *skb)
3244{
3245 struct ieee80211_rx_status *rx_status;
3246 struct ieee80211_sub_if_data *sdata;
3247 struct ieee80211_if_sta *ifsta;
3248 struct ieee80211_mgmt *mgmt;
3249 u16 fc;
3250
3251 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3252 ifsta = &sdata->u.sta;
3253
3254 rx_status = (struct ieee80211_rx_status *) skb->cb;
3255 mgmt = (struct ieee80211_mgmt *) skb->data;
3256 fc = le16_to_cpu(mgmt->frame_control);
3257
3258 switch (fc & IEEE80211_FCTL_STYPE) {
3259 case IEEE80211_STYPE_PROBE_REQ:
3260 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
3261 rx_status);
3262 break;
3263 case IEEE80211_STYPE_PROBE_RESP:
3264 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
3265 break;
3266 case IEEE80211_STYPE_BEACON:
3267 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
3268 break;
3269 case IEEE80211_STYPE_AUTH:
3270 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
3271 break;
3272 case IEEE80211_STYPE_ASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003273 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -07003274 break;
3275 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg471b3ef2007-12-28 14:32:58 +01003276 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
Jiri Bencf0706e822007-05-05 11:45:53 -07003277 break;
3278 case IEEE80211_STYPE_DEAUTH:
3279 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
3280 break;
3281 case IEEE80211_STYPE_DISASSOC:
3282 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
3283 break;
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003284 case IEEE80211_STYPE_ACTION:
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003285 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
Ron Rindjunsky9f985b02007-11-26 16:14:32 +02003286 break;
Jiri Bencf0706e822007-05-05 11:45:53 -07003287 }
3288
3289 kfree_skb(skb);
3290}
3291
3292
Johannes Berg9ae54c82008-01-31 19:48:20 +01003293ieee80211_rx_result
Zhu Yiece8edd2007-11-22 10:53:21 +08003294ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
3295 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e822007-05-05 11:45:53 -07003296{
3297 struct ieee80211_mgmt *mgmt;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003298 __le16 fc;
Jiri Bencf0706e822007-05-05 11:45:53 -07003299
Zhu Yiece8edd2007-11-22 10:53:21 +08003300 if (skb->len < 2)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003301 return RX_DROP_UNUSABLE;
Jiri Bencf0706e822007-05-05 11:45:53 -07003302
3303 mgmt = (struct ieee80211_mgmt *) skb->data;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003304 fc = mgmt->frame_control;
Jiri Bencf0706e822007-05-05 11:45:53 -07003305
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003306 if (ieee80211_is_ctl(fc))
Johannes Berg9ae54c82008-01-31 19:48:20 +01003307 return RX_CONTINUE;
Zhu Yiece8edd2007-11-22 10:53:21 +08003308
3309 if (skb->len < 24)
Johannes Berge4c26ad2008-01-31 19:48:21 +01003310 return RX_DROP_MONITOR;
Zhu Yiece8edd2007-11-22 10:53:21 +08003311
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003312 if (ieee80211_is_probe_resp(fc)) {
3313 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
3314 dev_kfree_skb(skb);
3315 return RX_QUEUED;
Jiri Bencf0706e822007-05-05 11:45:53 -07003316 }
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003317
3318 if (ieee80211_is_beacon(fc)) {
3319 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
3320 dev_kfree_skb(skb);
3321 return RX_QUEUED;
3322 }
3323
Johannes Berg9ae54c82008-01-31 19:48:20 +01003324 return RX_CONTINUE;
Jiri Bencf0706e822007-05-05 11:45:53 -07003325}
3326
3327
3328static int ieee80211_sta_active_ibss(struct net_device *dev)
3329{
3330 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3331 int active = 0;
3332 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +01003333 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -07003334
Johannes Bergd0709a62008-02-25 16:27:46 +01003335 rcu_read_lock();
3336
3337 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3338 if (sta->sdata == sdata &&
Jiri Bencf0706e822007-05-05 11:45:53 -07003339 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
3340 jiffies)) {
3341 active++;
3342 break;
3343 }
3344 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003345
3346 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07003347
3348 return active;
3349}
3350
3351
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003352static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
Jiri Bencf0706e822007-05-05 11:45:53 -07003353{
3354 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3355 struct sta_info *sta, *tmp;
Michael Wube8755e2007-07-27 15:43:23 +02003356 LIST_HEAD(tmp_list);
Joe Perches0795af52007-10-03 17:59:30 -07003357 DECLARE_MAC_BUF(mac);
Johannes Bergd0709a62008-02-25 16:27:46 +01003358 unsigned long flags;
Jiri Bencf0706e822007-05-05 11:45:53 -07003359
Johannes Bergd0709a62008-02-25 16:27:46 +01003360 spin_lock_irqsave(&local->sta_lock, flags);
Jiri Bencf0706e822007-05-05 11:45:53 -07003361 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003362 if (time_after(jiffies, sta->last_rx + exp_time)) {
Joe Perches0795af52007-10-03 17:59:30 -07003363 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
3364 dev->name, print_mac(mac, sta->addr));
Luis Carlos Cobocb585bc2008-03-31 15:21:23 -07003365 __sta_info_unlink(&sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01003366 if (sta)
3367 list_add(&sta->list, &tmp_list);
Jiri Bencf0706e822007-05-05 11:45:53 -07003368 }
Johannes Bergd0709a62008-02-25 16:27:46 +01003369 spin_unlock_irqrestore(&local->sta_lock, flags);
Michael Wube8755e2007-07-27 15:43:23 +02003370
Johannes Bergd0709a62008-02-25 16:27:46 +01003371 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
3372 sta_info_destroy(sta);
Jiri Bencf0706e822007-05-05 11:45:53 -07003373}
3374
3375
3376static void ieee80211_sta_merge_ibss(struct net_device *dev,
3377 struct ieee80211_if_sta *ifsta)
3378{
3379 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
3380
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003381 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
Jiri Bencf0706e822007-05-05 11:45:53 -07003382 if (ieee80211_sta_active_ibss(dev))
3383 return;
3384
3385 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
3386 "IBSS networks with same SSID (merge)\n", dev->name);
3387 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
3388}
3389
3390
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003391#ifdef CONFIG_MAC80211_MESH
3392static void ieee80211_mesh_housekeeping(struct net_device *dev,
3393 struct ieee80211_if_sta *ifsta)
3394{
3395 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3396 bool free_plinks;
3397
3398 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3399 mesh_path_expire(dev);
3400
3401 free_plinks = mesh_plink_availables(sdata);
3402 if (free_plinks != sdata->u.sta.accepting_plinks)
3403 ieee80211_if_config_beacon(dev);
3404
3405 mod_timer(&ifsta->timer, jiffies +
3406 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3407}
3408
3409
3410void ieee80211_start_mesh(struct net_device *dev)
3411{
3412 struct ieee80211_if_sta *ifsta;
3413 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3414 ifsta = &sdata->u.sta;
3415 ifsta->state = IEEE80211_MESH_UP;
3416 ieee80211_sta_timer((unsigned long)sdata);
3417}
3418#endif
3419
3420
Jiri Bencf0706e822007-05-05 11:45:53 -07003421void ieee80211_sta_timer(unsigned long data)
3422{
3423 struct ieee80211_sub_if_data *sdata =
3424 (struct ieee80211_sub_if_data *) data;
3425 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3426 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
3427
3428 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3429 queue_work(local->hw.workqueue, &ifsta->work);
3430}
3431
Jiri Bencf0706e822007-05-05 11:45:53 -07003432void ieee80211_sta_work(struct work_struct *work)
3433{
3434 struct ieee80211_sub_if_data *sdata =
3435 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
3436 struct net_device *dev = sdata->dev;
3437 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3438 struct ieee80211_if_sta *ifsta;
3439 struct sk_buff *skb;
3440
3441 if (!netif_running(dev))
3442 return;
3443
Zhu Yiece8edd2007-11-22 10:53:21 +08003444 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -07003445 return;
3446
Johannes Berg51fb61e2007-12-19 01:31:27 +01003447 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003448 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3449 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003450 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
Johannes Berg51fb61e2007-12-19 01:31:27 +01003451 "(type=%d)\n", dev->name, sdata->vif.type);
Jiri Bencf0706e822007-05-05 11:45:53 -07003452 return;
3453 }
3454 ifsta = &sdata->u.sta;
3455
3456 while ((skb = skb_dequeue(&ifsta->skb_queue)))
3457 ieee80211_sta_rx_queued_mgmt(dev, skb);
3458
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003459#ifdef CONFIG_MAC80211_MESH
Johannes Berg902acc72008-02-23 15:17:19 +01003460 if (ifsta->preq_queue_len &&
3461 time_after(jiffies,
3462 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003463 mesh_path_start_discovery(dev);
3464#endif
3465
Jiri Bencf0706e822007-05-05 11:45:53 -07003466 if (ifsta->state != IEEE80211_AUTHENTICATE &&
3467 ifsta->state != IEEE80211_ASSOCIATE &&
3468 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
Helmut Schaaa0af5f12007-11-09 16:25:08 +01003469 if (ifsta->scan_ssid_len)
3470 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
3471 else
3472 ieee80211_sta_start_scan(dev, NULL, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -07003473 return;
3474 }
3475
3476 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
3477 if (ieee80211_sta_config_auth(dev, ifsta))
3478 return;
3479 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3480 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3481 return;
3482
3483 switch (ifsta->state) {
3484 case IEEE80211_DISABLED:
3485 break;
3486 case IEEE80211_AUTHENTICATE:
3487 ieee80211_authenticate(dev, ifsta);
3488 break;
3489 case IEEE80211_ASSOCIATE:
3490 ieee80211_associate(dev, ifsta);
3491 break;
3492 case IEEE80211_ASSOCIATED:
3493 ieee80211_associated(dev, ifsta);
3494 break;
3495 case IEEE80211_IBSS_SEARCH:
3496 ieee80211_sta_find_ibss(dev, ifsta);
3497 break;
3498 case IEEE80211_IBSS_JOINED:
3499 ieee80211_sta_merge_ibss(dev, ifsta);
3500 break;
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003501#ifdef CONFIG_MAC80211_MESH
3502 case IEEE80211_MESH_UP:
3503 ieee80211_mesh_housekeeping(dev, ifsta);
3504 break;
3505#endif
Jiri Bencf0706e822007-05-05 11:45:53 -07003506 default:
3507 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
3508 ifsta->state);
3509 break;
3510 }
3511
3512 if (ieee80211_privacy_mismatch(dev, ifsta)) {
3513 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
3514 "mixed-cell disabled - disassociate\n", dev->name);
3515
3516 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
3517 ieee80211_set_disassoc(dev, ifsta, 0);
3518 }
3519}
3520
3521
3522static void ieee80211_sta_reset_auth(struct net_device *dev,
3523 struct ieee80211_if_sta *ifsta)
3524{
3525 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3526
3527 if (local->ops->reset_tsf) {
3528 /* Reset own TSF to allow time synchronization work. */
3529 local->ops->reset_tsf(local_to_hw(local));
3530 }
3531
3532 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3533
3534
3535 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3536 ifsta->auth_alg = WLAN_AUTH_OPEN;
3537 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3538 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3539 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3540 ifsta->auth_alg = WLAN_AUTH_LEAP;
3541 else
3542 ifsta->auth_alg = WLAN_AUTH_OPEN;
3543 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
3544 ifsta->auth_alg);
3545 ifsta->auth_transaction = -1;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003546 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
3547 ifsta->auth_tries = ifsta->assoc_tries = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07003548 netif_carrier_off(dev);
3549}
3550
3551
3552void ieee80211_sta_req_auth(struct net_device *dev,
3553 struct ieee80211_if_sta *ifsta)
3554{
3555 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3556 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3557
Johannes Berg51fb61e2007-12-19 01:31:27 +01003558 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07003559 return;
3560
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003561 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3562 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3563 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3564 IEEE80211_STA_AUTO_SSID_SEL))) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003565 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3566 queue_work(local->hw.workqueue, &ifsta->work);
3567 }
3568}
3569
3570static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3571 const char *ssid, int ssid_len)
3572{
3573 int tmp, hidden_ssid;
3574
Michael Wu48225702007-10-19 17:14:36 -04003575 if (ssid_len == ifsta->ssid_len &&
3576 !memcmp(ifsta->ssid, ssid, ssid_len))
Jiri Bencf0706e822007-05-05 11:45:53 -07003577 return 1;
3578
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003579 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Jiri Bencf0706e822007-05-05 11:45:53 -07003580 return 0;
3581
3582 hidden_ssid = 1;
3583 tmp = ssid_len;
3584 while (tmp--) {
3585 if (ssid[tmp] != '\0') {
3586 hidden_ssid = 0;
3587 break;
3588 }
3589 }
3590
3591 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3592 return 1;
3593
3594 if (ssid_len == 1 && ssid[0] == ' ')
3595 return 1;
3596
3597 return 0;
3598}
3599
3600static int ieee80211_sta_config_auth(struct net_device *dev,
3601 struct ieee80211_if_sta *ifsta)
3602{
3603 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3604 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3605 struct ieee80211_sta_bss *bss, *selected = NULL;
3606 int top_rssi = 0, freq;
3607
Jiri Bencf0706e822007-05-05 11:45:53 -07003608 spin_lock_bh(&local->sta_bss_lock);
Johannes Berg8318d782008-01-24 19:38:38 +01003609 freq = local->oper_channel->center_freq;
Jiri Bencf0706e822007-05-05 11:45:53 -07003610 list_for_each_entry(bss, &local->sta_bss_list, list) {
3611 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3612 continue;
3613
Abhijeet Kolekar34a961f2008-05-09 09:35:41 -07003614 if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3615 IEEE80211_STA_AUTO_BSSID_SEL |
3616 IEEE80211_STA_AUTO_CHANNEL_SEL)) &&
3617 (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3618 !!sdata->default_key))
Jiri Bencf0706e822007-05-05 11:45:53 -07003619 continue;
3620
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003621 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3622 bss->freq != freq)
Jiri Bencf0706e822007-05-05 11:45:53 -07003623 continue;
3624
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003625 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
Jiri Bencf0706e822007-05-05 11:45:53 -07003626 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3627 continue;
3628
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003629 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
Jiri Bencf0706e822007-05-05 11:45:53 -07003630 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3631 continue;
3632
Bruno Randolf566bfe52008-05-08 19:15:40 +02003633 if (!selected || top_rssi < bss->signal) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003634 selected = bss;
Bruno Randolf566bfe52008-05-08 19:15:40 +02003635 top_rssi = bss->signal;
Jiri Bencf0706e822007-05-05 11:45:53 -07003636 }
3637 }
3638 if (selected)
3639 atomic_inc(&selected->users);
3640 spin_unlock_bh(&local->sta_bss_lock);
3641
3642 if (selected) {
Assaf Kraussbe038b32008-06-05 19:55:21 +03003643 ieee80211_set_freq(dev, selected->freq);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003644 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
Jiri Bencf0706e822007-05-05 11:45:53 -07003645 ieee80211_sta_set_ssid(dev, selected->ssid,
3646 selected->ssid_len);
3647 ieee80211_sta_set_bssid(dev, selected->bssid);
Vladimir Koutnye2839d82008-03-18 21:14:07 +01003648 ieee80211_sta_def_wmm_params(dev, selected, 0);
Jiri Bencf0706e822007-05-05 11:45:53 -07003649 ieee80211_rx_bss_put(dev, selected);
3650 ifsta->state = IEEE80211_AUTHENTICATE;
Jiri Bencf0706e822007-05-05 11:45:53 -07003651 ieee80211_sta_reset_auth(dev, ifsta);
3652 return 0;
3653 } else {
3654 if (ifsta->state != IEEE80211_AUTHENTICATE) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003655 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
John W. Linvilleb9bf1e62007-08-07 16:33:15 -04003656 ieee80211_sta_start_scan(dev, NULL, 0);
3657 else
3658 ieee80211_sta_start_scan(dev, ifsta->ssid,
3659 ifsta->ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07003660 ifsta->state = IEEE80211_AUTHENTICATE;
3661 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3662 } else
3663 ifsta->state = IEEE80211_DISABLED;
3664 }
Jiri Bencf0706e822007-05-05 11:45:53 -07003665 return -1;
3666}
3667
Jiri Bencf0706e822007-05-05 11:45:53 -07003668
3669static int ieee80211_sta_create_ibss(struct net_device *dev,
3670 struct ieee80211_if_sta *ifsta)
3671{
3672 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3673 struct ieee80211_sta_bss *bss;
John W. Linvillecffdd302007-10-05 14:23:27 -04003674 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +01003675 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07003676 u8 bssid[ETH_ALEN], *pos;
3677 int i;
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003678 int ret;
Joe Perches0795af52007-10-03 17:59:30 -07003679 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e822007-05-05 11:45:53 -07003680
3681#if 0
3682 /* Easier testing, use fixed BSSID. */
3683 memset(bssid, 0xfe, ETH_ALEN);
3684#else
3685 /* Generate random, not broadcast, locally administered BSSID. Mix in
3686 * own MAC address to make sure that devices that do not have proper
3687 * random number generator get different BSSID. */
3688 get_random_bytes(bssid, ETH_ALEN);
3689 for (i = 0; i < ETH_ALEN; i++)
3690 bssid[i] ^= dev->dev_addr[i];
3691 bssid[0] &= ~0x01;
3692 bssid[0] |= 0x02;
3693#endif
3694
Joe Perches0795af52007-10-03 17:59:30 -07003695 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3696 dev->name, print_mac(mac, bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07003697
Johannes Berg8318d782008-01-24 19:38:38 +01003698 bss = ieee80211_rx_bss_add(dev, bssid,
3699 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04003700 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07003701 if (!bss)
3702 return -ENOMEM;
3703
Johannes Berg8318d782008-01-24 19:38:38 +01003704 bss->band = local->hw.conf.channel->band;
3705 sband = local->hw.wiphy->bands[bss->band];
Jiri Bencf0706e822007-05-05 11:45:53 -07003706
3707 if (local->hw.conf.beacon_int == 0)
Tomas Winklerdc0ae302008-06-12 22:38:37 +03003708 local->hw.conf.beacon_int = 100;
Jiri Bencf0706e822007-05-05 11:45:53 -07003709 bss->beacon_int = local->hw.conf.beacon_int;
Jiri Bencf0706e822007-05-05 11:45:53 -07003710 bss->last_update = jiffies;
3711 bss->capability = WLAN_CAPABILITY_IBSS;
Johannes Berg988c0f72008-04-17 19:21:22 +02003712
3713 if (sdata->default_key)
Jiri Bencf0706e822007-05-05 11:45:53 -07003714 bss->capability |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg988c0f72008-04-17 19:21:22 +02003715 else
Jiri Bencf0706e822007-05-05 11:45:53 -07003716 sdata->drop_unencrypted = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02003717
Johannes Berg8318d782008-01-24 19:38:38 +01003718 bss->supp_rates_len = sband->n_bitrates;
Jiri Bencf0706e822007-05-05 11:45:53 -07003719 pos = bss->supp_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01003720 for (i = 0; i < sband->n_bitrates; i++) {
3721 int rate = sband->bitrates[i].bitrate;
Jiri Bencf0706e822007-05-05 11:45:53 -07003722 *pos++ = (u8) (rate / 5);
3723 }
3724
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003725 ret = ieee80211_sta_join_ibss(dev, ifsta, bss);
3726 ieee80211_rx_bss_put(dev, bss);
3727 return ret;
Jiri Bencf0706e822007-05-05 11:45:53 -07003728}
3729
3730
3731static int ieee80211_sta_find_ibss(struct net_device *dev,
3732 struct ieee80211_if_sta *ifsta)
3733{
3734 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3735 struct ieee80211_sta_bss *bss;
3736 int found = 0;
3737 u8 bssid[ETH_ALEN];
3738 int active_ibss;
Joe Perches0795af52007-10-03 17:59:30 -07003739 DECLARE_MAC_BUF(mac);
3740 DECLARE_MAC_BUF(mac2);
Jiri Bencf0706e822007-05-05 11:45:53 -07003741
3742 if (ifsta->ssid_len == 0)
3743 return -EINVAL;
3744
3745 active_ibss = ieee80211_sta_active_ibss(dev);
3746#ifdef CONFIG_MAC80211_IBSS_DEBUG
3747 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
3748 dev->name, active_ibss);
3749#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3750 spin_lock_bh(&local->sta_bss_lock);
3751 list_for_each_entry(bss, &local->sta_bss_list, list) {
3752 if (ifsta->ssid_len != bss->ssid_len ||
3753 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3754 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3755 continue;
3756#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003757 printk(KERN_DEBUG " bssid=%s found\n",
3758 print_mac(mac, bss->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07003759#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3760 memcpy(bssid, bss->bssid, ETH_ALEN);
3761 found = 1;
3762 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3763 break;
3764 }
3765 spin_unlock_bh(&local->sta_bss_lock);
3766
3767#ifdef CONFIG_MAC80211_IBSS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -07003768 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3769 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
Jiri Bencf0706e822007-05-05 11:45:53 -07003770#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3771 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
Johannes Berg8318d782008-01-24 19:38:38 +01003772 (bss = ieee80211_rx_bss_get(dev, bssid,
3773 local->hw.conf.channel->center_freq,
John W. Linvillecffdd302007-10-05 14:23:27 -04003774 ifsta->ssid, ifsta->ssid_len))) {
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003775 int ret;
Joe Perches0795af52007-10-03 17:59:30 -07003776 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
Jiri Bencf0706e822007-05-05 11:45:53 -07003777 " based on configured SSID\n",
Joe Perches0795af52007-10-03 17:59:30 -07003778 dev->name, print_mac(mac, bssid));
Tomas Winkler167ad6f2008-05-21 18:17:05 +03003779 ret = ieee80211_sta_join_ibss(dev, ifsta, bss);
3780 ieee80211_rx_bss_put(dev, bss);
3781 return ret;
Jiri Bencf0706e822007-05-05 11:45:53 -07003782 }
3783#ifdef CONFIG_MAC80211_IBSS_DEBUG
3784 printk(KERN_DEBUG " did not try to join ibss\n");
3785#endif /* CONFIG_MAC80211_IBSS_DEBUG */
3786
3787 /* Selected IBSS not found in current scan results - try to scan */
3788 if (ifsta->state == IEEE80211_IBSS_JOINED &&
3789 !ieee80211_sta_active_ibss(dev)) {
3790 mod_timer(&ifsta->timer, jiffies +
3791 IEEE80211_IBSS_MERGE_INTERVAL);
3792 } else if (time_after(jiffies, local->last_scan_completed +
3793 IEEE80211_SCAN_INTERVAL)) {
3794 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
3795 "join\n", dev->name);
3796 return ieee80211_sta_req_scan(dev, ifsta->ssid,
3797 ifsta->ssid_len);
3798 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
3799 int interval = IEEE80211_SCAN_INTERVAL;
3800
3801 if (time_after(jiffies, ifsta->ibss_join_req +
3802 IEEE80211_IBSS_JOIN_TIMEOUT)) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003803 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
Johannes Berg8318d782008-01-24 19:38:38 +01003804 (!(local->oper_channel->flags &
3805 IEEE80211_CHAN_NO_IBSS)))
Jiri Bencf0706e822007-05-05 11:45:53 -07003806 return ieee80211_sta_create_ibss(dev, ifsta);
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003807 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
Johannes Berg8318d782008-01-24 19:38:38 +01003808 printk(KERN_DEBUG "%s: IBSS not allowed on"
3809 " %d MHz\n", dev->name,
3810 local->hw.conf.channel->center_freq);
Jiri Bencf0706e822007-05-05 11:45:53 -07003811 }
3812
3813 /* No IBSS found - decrease scan interval and continue
3814 * scanning. */
3815 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3816 }
3817
3818 ifsta->state = IEEE80211_IBSS_SEARCH;
3819 mod_timer(&ifsta->timer, jiffies + interval);
3820 return 0;
3821 }
3822
3823 return 0;
3824}
3825
3826
3827int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3828{
Johannes Berg8318d782008-01-24 19:38:38 +01003829 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -07003830 struct ieee80211_if_sta *ifsta;
Jiri Bencf0706e822007-05-05 11:45:53 -07003831
3832 if (len > IEEE80211_MAX_SSID_LEN)
3833 return -EINVAL;
3834
Jiri Bencf0706e822007-05-05 11:45:53 -07003835 ifsta = &sdata->u.sta;
3836
3837 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003838 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e822007-05-05 11:45:53 -07003839 memcpy(ifsta->ssid, ssid, len);
3840 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3841 ifsta->ssid_len = len;
3842
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003843 if (len)
3844 ifsta->flags |= IEEE80211_STA_SSID_SET;
3845 else
3846 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
Johannes Berg51fb61e2007-12-19 01:31:27 +01003847 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003848 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003849 ifsta->ibss_join_req = jiffies;
3850 ifsta->state = IEEE80211_IBSS_SEARCH;
3851 return ieee80211_sta_find_ibss(dev, ifsta);
3852 }
3853 return 0;
3854}
3855
3856
3857int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3858{
3859 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3860 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3861 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3862 *len = ifsta->ssid_len;
3863 return 0;
3864}
3865
3866
3867int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3868{
3869 struct ieee80211_sub_if_data *sdata;
3870 struct ieee80211_if_sta *ifsta;
3871 int res;
3872
3873 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3874 ifsta = &sdata->u.sta;
3875
3876 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3877 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3878 res = ieee80211_if_config(dev);
3879 if (res) {
3880 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3881 "the low-level driver\n", dev->name);
3882 return res;
3883 }
3884 }
3885
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003886 if (is_valid_ether_addr(bssid))
3887 ifsta->flags |= IEEE80211_STA_BSSID_SET;
Jiri Bencf0706e822007-05-05 11:45:53 -07003888 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003889 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3890
Jiri Bencf0706e822007-05-05 11:45:53 -07003891 return 0;
3892}
3893
3894
3895static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3896 struct ieee80211_sub_if_data *sdata,
3897 int powersave)
3898{
3899 struct sk_buff *skb;
3900 struct ieee80211_hdr *nullfunc;
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003901 __le16 fc;
Jiri Bencf0706e822007-05-05 11:45:53 -07003902
3903 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3904 if (!skb) {
3905 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3906 "frame\n", sdata->dev->name);
3907 return;
3908 }
3909 skb_reserve(skb, local->hw.extra_tx_headroom);
3910
3911 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3912 memset(nullfunc, 0, 24);
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003913 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3914 IEEE80211_FCTL_TODS);
Jiri Bencf0706e822007-05-05 11:45:53 -07003915 if (powersave)
Harvey Harrison4e3996f2008-06-22 16:45:32 -07003916 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
3917 nullfunc->frame_control = fc;
Jiri Bencf0706e822007-05-05 11:45:53 -07003918 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3919 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3920 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3921
3922 ieee80211_sta_tx(sdata->dev, skb, 0);
3923}
3924
3925
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003926static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3927{
3928 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3929 ieee80211_vif_is_mesh(&sdata->vif))
3930 ieee80211_sta_timer((unsigned long)sdata);
3931}
3932
Jiri Bencf0706e822007-05-05 11:45:53 -07003933void ieee80211_scan_completed(struct ieee80211_hw *hw)
3934{
3935 struct ieee80211_local *local = hw_to_local(hw);
3936 struct net_device *dev = local->scan_dev;
3937 struct ieee80211_sub_if_data *sdata;
3938 union iwreq_data wrqu;
3939
3940 local->last_scan_completed = jiffies;
Zhu Yiece8edd2007-11-22 10:53:21 +08003941 memset(&wrqu, 0, sizeof(wrqu));
3942 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
Jiri Bencf0706e822007-05-05 11:45:53 -07003943
Zhu Yiece8edd2007-11-22 10:53:21 +08003944 if (local->sta_hw_scanning) {
3945 local->sta_hw_scanning = 0;
Mohamed Abbas675ef582008-03-20 08:14:29 -07003946 if (ieee80211_hw_config(local))
3947 printk(KERN_DEBUG "%s: failed to restore operational "
3948 "channel after scan\n", dev->name);
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003949 /* Restart STA timer for HW scan case */
3950 rcu_read_lock();
3951 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3952 ieee80211_restart_sta_timer(sdata);
3953 rcu_read_unlock();
3954
Zhu Yiece8edd2007-11-22 10:53:21 +08003955 goto done;
3956 }
3957
3958 local->sta_sw_scanning = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07003959 if (ieee80211_hw_config(local))
Bruno Randolf4b50e382007-11-16 17:04:01 +09003960 printk(KERN_DEBUG "%s: failed to restore operational "
Jiri Bencf0706e822007-05-05 11:45:53 -07003961 "channel after scan\n", dev->name);
3962
Johannes Berg4150c572007-09-17 01:29:23 -04003963
3964 netif_tx_lock_bh(local->mdev);
3965 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3966 local->ops->configure_filter(local_to_hw(local),
3967 FIF_BCN_PRBRESP_PROMISC,
3968 &local->filter_flags,
3969 local->mdev->mc_count,
3970 local->mdev->mc_list);
3971
3972 netif_tx_unlock_bh(local->mdev);
Jiri Bencf0706e822007-05-05 11:45:53 -07003973
Johannes Berg79010422007-09-18 17:29:21 -04003974 rcu_read_lock();
3975 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Mattias Nissler14042cb2007-06-08 15:31:13 +02003976
3977 /* No need to wake the master device. */
3978 if (sdata->dev == local->mdev)
3979 continue;
3980
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003981 /* Tell AP we're back */
3982 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3983 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3984 ieee80211_send_nullfunc(local, sdata, 0);
Mattias Nissler14042cb2007-06-08 15:31:13 +02003985
Johannes Berg69d3b6f2008-03-05 10:58:40 +01003986 ieee80211_restart_sta_timer(sdata);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01003987
Jiri Bencf0706e822007-05-05 11:45:53 -07003988 netif_wake_queue(sdata->dev);
3989 }
Johannes Berg79010422007-09-18 17:29:21 -04003990 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07003991
Zhu Yiece8edd2007-11-22 10:53:21 +08003992done:
Jiri Bencf0706e822007-05-05 11:45:53 -07003993 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01003994 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -07003995 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04003996 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
Jiri Bencf0706e822007-05-05 11:45:53 -07003997 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3998 !ieee80211_sta_active_ibss(dev)))
3999 ieee80211_sta_find_ibss(dev, ifsta);
4000 }
4001}
4002EXPORT_SYMBOL(ieee80211_scan_completed);
4003
4004void ieee80211_sta_scan_work(struct work_struct *work)
4005{
4006 struct ieee80211_local *local =
4007 container_of(work, struct ieee80211_local, scan_work.work);
4008 struct net_device *dev = local->scan_dev;
4009 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +01004010 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07004011 struct ieee80211_channel *chan;
4012 int skip;
4013 unsigned long next_delay = 0;
4014
Zhu Yiece8edd2007-11-22 10:53:21 +08004015 if (!local->sta_sw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -07004016 return;
4017
4018 switch (local->scan_state) {
4019 case SCAN_SET_CHANNEL:
Johannes Berg69d464d2008-01-28 17:08:56 +01004020 /*
4021 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
4022 * after we successfully scanned the last channel of the last
4023 * band (and the last band is supported by the hw)
4024 */
Johannes Berg8318d782008-01-24 19:38:38 +01004025 if (local->scan_band < IEEE80211_NUM_BANDS)
4026 sband = local->hw.wiphy->bands[local->scan_band];
4027 else
4028 sband = NULL;
4029
Johannes Berg69d464d2008-01-28 17:08:56 +01004030 /*
4031 * If we are at an unsupported band and have more bands
4032 * left to scan, advance to the next supported one.
4033 */
4034 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
Johannes Berg8318d782008-01-24 19:38:38 +01004035 local->scan_band++;
4036 sband = local->hw.wiphy->bands[local->scan_band];
4037 local->scan_channel_idx = 0;
4038 }
4039
Johannes Berg69d464d2008-01-28 17:08:56 +01004040 /* if no more bands/channels left, complete scan */
4041 if (!sband || local->scan_channel_idx >= sband->n_channels) {
Jiri Bencf0706e822007-05-05 11:45:53 -07004042 ieee80211_scan_completed(local_to_hw(local));
4043 return;
4044 }
Johannes Berg8318d782008-01-24 19:38:38 +01004045 skip = 0;
4046 chan = &sband->channels[local->scan_channel_idx];
4047
4048 if (chan->flags & IEEE80211_CHAN_DISABLED ||
Johannes Berg51fb61e2007-12-19 01:31:27 +01004049 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
Johannes Berg8318d782008-01-24 19:38:38 +01004050 chan->flags & IEEE80211_CHAN_NO_IBSS))
Jiri Bencf0706e822007-05-05 11:45:53 -07004051 skip = 1;
4052
4053 if (!skip) {
Jiri Bencf0706e822007-05-05 11:45:53 -07004054 local->scan_channel = chan;
4055 if (ieee80211_hw_config(local)) {
Johannes Berg8318d782008-01-24 19:38:38 +01004056 printk(KERN_DEBUG "%s: failed to set freq to "
4057 "%d MHz for scan\n", dev->name,
4058 chan->center_freq);
Jiri Bencf0706e822007-05-05 11:45:53 -07004059 skip = 1;
4060 }
4061 }
4062
Johannes Berg69d464d2008-01-28 17:08:56 +01004063 /* advance state machine to next channel/band */
Jiri Bencf0706e822007-05-05 11:45:53 -07004064 local->scan_channel_idx++;
Johannes Berg8318d782008-01-24 19:38:38 +01004065 if (local->scan_channel_idx >= sband->n_channels) {
Johannes Berg69d464d2008-01-28 17:08:56 +01004066 /*
4067 * scan_band may end up == IEEE80211_NUM_BANDS, but
4068 * we'll catch that case above and complete the scan
4069 * if that is the case.
4070 */
Johannes Berg8318d782008-01-24 19:38:38 +01004071 local->scan_band++;
4072 local->scan_channel_idx = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07004073 }
4074
4075 if (skip)
4076 break;
4077
4078 next_delay = IEEE80211_PROBE_DELAY +
4079 usecs_to_jiffies(local->hw.channel_change_time);
4080 local->scan_state = SCAN_SEND_PROBE;
4081 break;
4082 case SCAN_SEND_PROBE:
Johannes Berg8318d782008-01-24 19:38:38 +01004083 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
Jiri Bencf0706e822007-05-05 11:45:53 -07004084 local->scan_state = SCAN_SET_CHANNEL;
Johannes Berg8318d782008-01-24 19:38:38 +01004085
4086 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
4087 break;
4088 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
4089 local->scan_ssid_len);
4090 next_delay = IEEE80211_CHANNEL_TIME;
Jiri Bencf0706e822007-05-05 11:45:53 -07004091 break;
4092 }
4093
Zhu Yiece8edd2007-11-22 10:53:21 +08004094 if (local->sta_sw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -07004095 queue_delayed_work(local->hw.workqueue, &local->scan_work,
4096 next_delay);
4097}
4098
4099
4100static int ieee80211_sta_start_scan(struct net_device *dev,
4101 u8 *ssid, size_t ssid_len)
4102{
4103 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4104 struct ieee80211_sub_if_data *sdata;
4105
4106 if (ssid_len > IEEE80211_MAX_SSID_LEN)
4107 return -EINVAL;
4108
4109 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
4110 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
4111 * BSSID: MACAddress
4112 * SSID
4113 * ScanType: ACTIVE, PASSIVE
4114 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
4115 * a Probe frame during active scanning
4116 * ChannelList
4117 * MinChannelTime (>= ProbeDelay), in TU
4118 * MaxChannelTime: (>= MinChannelTime), in TU
4119 */
4120
4121 /* MLME-SCAN.confirm
4122 * BSSDescriptionSet
4123 * ResultCode: SUCCESS, INVALID_PARAMETERS
4124 */
4125
Zhu Yiece8edd2007-11-22 10:53:21 +08004126 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jiri Bencf0706e822007-05-05 11:45:53 -07004127 if (local->scan_dev == dev)
4128 return 0;
4129 return -EBUSY;
4130 }
4131
4132 if (local->ops->hw_scan) {
4133 int rc = local->ops->hw_scan(local_to_hw(local),
Zhu Yiece8edd2007-11-22 10:53:21 +08004134 ssid, ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07004135 if (!rc) {
Zhu Yiece8edd2007-11-22 10:53:21 +08004136 local->sta_hw_scanning = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07004137 local->scan_dev = dev;
4138 }
4139 return rc;
4140 }
4141
Zhu Yiece8edd2007-11-22 10:53:21 +08004142 local->sta_sw_scanning = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07004143
Johannes Berg79010422007-09-18 17:29:21 -04004144 rcu_read_lock();
4145 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Mattias Nissler14042cb2007-06-08 15:31:13 +02004146
4147 /* Don't stop the master interface, otherwise we can't transmit
4148 * probes! */
4149 if (sdata->dev == local->mdev)
4150 continue;
4151
Jiri Bencf0706e822007-05-05 11:45:53 -07004152 netif_stop_queue(sdata->dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +01004153 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Jiri Slabyd6f2da52007-08-28 17:01:54 -04004154 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e822007-05-05 11:45:53 -07004155 ieee80211_send_nullfunc(local, sdata, 1);
4156 }
Johannes Berg79010422007-09-18 17:29:21 -04004157 rcu_read_unlock();
Jiri Bencf0706e822007-05-05 11:45:53 -07004158
4159 if (ssid) {
4160 local->scan_ssid_len = ssid_len;
4161 memcpy(local->scan_ssid, ssid, ssid_len);
4162 } else
4163 local->scan_ssid_len = 0;
4164 local->scan_state = SCAN_SET_CHANNEL;
Jiri Bencf0706e822007-05-05 11:45:53 -07004165 local->scan_channel_idx = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01004166 local->scan_band = IEEE80211_BAND_2GHZ;
Jiri Bencf0706e822007-05-05 11:45:53 -07004167 local->scan_dev = dev;
4168
Johannes Berg4150c572007-09-17 01:29:23 -04004169 netif_tx_lock_bh(local->mdev);
4170 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
4171 local->ops->configure_filter(local_to_hw(local),
4172 FIF_BCN_PRBRESP_PROMISC,
4173 &local->filter_flags,
4174 local->mdev->mc_count,
4175 local->mdev->mc_list);
4176 netif_tx_unlock_bh(local->mdev);
Jiri Bencf0706e822007-05-05 11:45:53 -07004177
4178 /* TODO: start scan as soon as all nullfunc frames are ACKed */
4179 queue_delayed_work(local->hw.workqueue, &local->scan_work,
4180 IEEE80211_CHANNEL_TIME);
4181
4182 return 0;
4183}
4184
4185
4186int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
4187{
4188 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4189 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4190 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4191
Johannes Berg51fb61e2007-12-19 01:31:27 +01004192 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07004193 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
4194
Zhu Yiece8edd2007-11-22 10:53:21 +08004195 if (local->sta_sw_scanning || local->sta_hw_scanning) {
Jiri Bencf0706e822007-05-05 11:45:53 -07004196 if (local->scan_dev == dev)
4197 return 0;
4198 return -EBUSY;
4199 }
4200
Helmut Schaaa0af5f12007-11-09 16:25:08 +01004201 ifsta->scan_ssid_len = ssid_len;
4202 if (ssid_len)
4203 memcpy(ifsta->scan_ssid, ssid, ssid_len);
Jiri Bencf0706e822007-05-05 11:45:53 -07004204 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
4205 queue_work(local->hw.workqueue, &ifsta->work);
4206 return 0;
4207}
4208
4209static char *
4210ieee80211_sta_scan_result(struct net_device *dev,
David S. Millerccc58052008-06-16 18:50:49 -07004211 struct iw_request_info *info,
Jiri Bencf0706e822007-05-05 11:45:53 -07004212 struct ieee80211_sta_bss *bss,
4213 char *current_ev, char *end_buf)
4214{
4215 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4216 struct iw_event iwe;
4217
4218 if (time_after(jiffies,
4219 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
4220 return current_ev;
4221
Jiri Bencf0706e822007-05-05 11:45:53 -07004222 memset(&iwe, 0, sizeof(iwe));
4223 iwe.cmd = SIOCGIWAP;
4224 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4225 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07004226 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e822007-05-05 11:45:53 -07004227 IW_EV_ADDR_LEN);
4228
4229 memset(&iwe, 0, sizeof(iwe));
4230 iwe.cmd = SIOCGIWESSID;
Johannes Berg902acc72008-02-23 15:17:19 +01004231 if (bss_mesh_cfg(bss)) {
4232 iwe.u.data.length = bss_mesh_id_len(bss);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004233 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004234 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4235 &iwe, bss_mesh_id(bss));
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004236 } else {
4237 iwe.u.data.length = bss->ssid_len;
4238 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004239 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4240 &iwe, bss->ssid);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004241 }
Jiri Bencf0706e822007-05-05 11:45:53 -07004242
Luis Carlos Cobo1d1b5352008-02-29 12:15:28 -08004243 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
4244 || bss_mesh_cfg(bss)) {
Jiri Bencf0706e822007-05-05 11:45:53 -07004245 memset(&iwe, 0, sizeof(iwe));
4246 iwe.cmd = SIOCGIWMODE;
Johannes Berg902acc72008-02-23 15:17:19 +01004247 if (bss_mesh_cfg(bss))
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004248 iwe.u.mode = IW_MODE_MESH;
4249 else if (bss->capability & WLAN_CAPABILITY_ESS)
Jiri Bencf0706e822007-05-05 11:45:53 -07004250 iwe.u.mode = IW_MODE_MASTER;
4251 else
4252 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07004253 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4254 &iwe, IW_EV_UINT_LEN);
Jiri Bencf0706e822007-05-05 11:45:53 -07004255 }
4256
4257 memset(&iwe, 0, sizeof(iwe));
4258 iwe.cmd = SIOCGIWFREQ;
Johannes Berg8318d782008-01-24 19:38:38 +01004259 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
4260 iwe.u.freq.e = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004261 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e822007-05-05 11:45:53 -07004262 IW_EV_FREQ_LEN);
4263
4264 memset(&iwe, 0, sizeof(iwe));
Tomas Winkler9381be02008-05-23 01:36:36 +03004265 iwe.cmd = SIOCGIWFREQ;
4266 iwe.u.freq.m = bss->freq;
4267 iwe.u.freq.e = 6;
David S. Millerccc58052008-06-16 18:50:49 -07004268 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Tomas Winkler9381be02008-05-23 01:36:36 +03004269 IW_EV_FREQ_LEN);
4270 memset(&iwe, 0, sizeof(iwe));
Jiri Bencf0706e822007-05-05 11:45:53 -07004271 iwe.cmd = IWEVQUAL;
Bruno Randolf566bfe52008-05-08 19:15:40 +02004272 iwe.u.qual.qual = bss->qual;
4273 iwe.u.qual.level = bss->signal;
Jiri Bencf0706e822007-05-05 11:45:53 -07004274 iwe.u.qual.noise = bss->noise;
4275 iwe.u.qual.updated = local->wstats_flags;
David S. Millerccc58052008-06-16 18:50:49 -07004276 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
Jiri Bencf0706e822007-05-05 11:45:53 -07004277 IW_EV_QUAL_LEN);
4278
4279 memset(&iwe, 0, sizeof(iwe));
4280 iwe.cmd = SIOCGIWENCODE;
4281 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
4282 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4283 else
4284 iwe.u.data.flags = IW_ENCODE_DISABLED;
4285 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004286 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4287 &iwe, "");
Jiri Bencf0706e822007-05-05 11:45:53 -07004288
4289 if (bss && bss->wpa_ie) {
4290 memset(&iwe, 0, sizeof(iwe));
4291 iwe.cmd = IWEVGENIE;
4292 iwe.u.data.length = bss->wpa_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004293 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4294 &iwe, bss->wpa_ie);
Jiri Bencf0706e822007-05-05 11:45:53 -07004295 }
4296
4297 if (bss && bss->rsn_ie) {
4298 memset(&iwe, 0, sizeof(iwe));
4299 iwe.cmd = IWEVGENIE;
4300 iwe.u.data.length = bss->rsn_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004301 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4302 &iwe, bss->rsn_ie);
Jiri Bencf0706e822007-05-05 11:45:53 -07004303 }
4304
Emmanuel Grumbache6231572008-05-27 20:00:11 +03004305 if (bss && bss->ht_ie) {
4306 memset(&iwe, 0, sizeof(iwe));
4307 iwe.cmd = IWEVGENIE;
4308 iwe.u.data.length = bss->ht_ie_len;
David S. Millerccc58052008-06-16 18:50:49 -07004309 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4310 &iwe, bss->ht_ie);
Emmanuel Grumbache6231572008-05-27 20:00:11 +03004311 }
4312
Jiri Bencf0706e822007-05-05 11:45:53 -07004313 if (bss && bss->supp_rates_len > 0) {
4314 /* display all supported rates in readable format */
David S. Millerccc58052008-06-16 18:50:49 -07004315 char *p = current_ev + iwe_stream_lcp_len(info);
Jiri Bencf0706e822007-05-05 11:45:53 -07004316 int i;
4317
4318 memset(&iwe, 0, sizeof(iwe));
4319 iwe.cmd = SIOCGIWRATE;
4320 /* Those two flags are ignored... */
4321 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4322
4323 for (i = 0; i < bss->supp_rates_len; i++) {
4324 iwe.u.bitrate.value = ((bss->supp_rates[i] &
4325 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07004326 p = iwe_stream_add_value(info, current_ev, p,
Jiri Bencf0706e822007-05-05 11:45:53 -07004327 end_buf, &iwe, IW_EV_PARAM_LEN);
4328 }
4329 current_ev = p;
4330 }
4331
4332 if (bss) {
4333 char *buf;
4334 buf = kmalloc(30, GFP_ATOMIC);
4335 if (buf) {
4336 memset(&iwe, 0, sizeof(iwe));
4337 iwe.cmd = IWEVCUSTOM;
4338 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
4339 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004340 current_ev = iwe_stream_add_point(info, current_ev,
4341 end_buf,
Jiri Bencf0706e822007-05-05 11:45:53 -07004342 &iwe, buf);
Emmanuel Grumbachbf998f62008-06-24 13:38:00 +03004343 memset(&iwe, 0, sizeof(iwe));
4344 iwe.cmd = IWEVCUSTOM;
4345 sprintf(buf, " Last beacon: %dms ago",
4346 jiffies_to_msecs(jiffies - bss->last_update));
4347 iwe.u.data.length = strlen(buf);
4348 current_ev = iwe_stream_add_point(info, current_ev,
4349 end_buf, &iwe, buf);
Jiri Bencf0706e822007-05-05 11:45:53 -07004350 kfree(buf);
4351 }
4352 }
4353
Johannes Berg902acc72008-02-23 15:17:19 +01004354 if (bss_mesh_cfg(bss)) {
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004355 char *buf;
John W. Linville24736702008-04-08 14:15:46 -04004356 u8 *cfg = bss_mesh_cfg(bss);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004357 buf = kmalloc(50, GFP_ATOMIC);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004358 if (buf) {
4359 memset(&iwe, 0, sizeof(iwe));
4360 iwe.cmd = IWEVCUSTOM;
John W. Linville24736702008-04-08 14:15:46 -04004361 sprintf(buf, "Mesh network (version %d)", cfg[0]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004362 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004363 current_ev = iwe_stream_add_point(info, current_ev,
4364 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004365 &iwe, buf);
4366 sprintf(buf, "Path Selection Protocol ID: "
John W. Linville24736702008-04-08 14:15:46 -04004367 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
4368 cfg[4]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004369 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004370 current_ev = iwe_stream_add_point(info, current_ev,
4371 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004372 &iwe, buf);
4373 sprintf(buf, "Path Selection Metric ID: "
John W. Linville24736702008-04-08 14:15:46 -04004374 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
4375 cfg[8]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004376 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004377 current_ev = iwe_stream_add_point(info, current_ev,
4378 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004379 &iwe, buf);
4380 sprintf(buf, "Congestion Control Mode ID: "
John W. Linville24736702008-04-08 14:15:46 -04004381 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
4382 cfg[11], cfg[12]);
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004383 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004384 current_ev = iwe_stream_add_point(info, current_ev,
4385 end_buf,
Luis Carlos Cobo4f5d4c42008-02-29 12:32:46 -08004386 &iwe, buf);
4387 sprintf(buf, "Channel Precedence: "
John W. Linville24736702008-04-08 14:15:46 -04004388 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
4389 cfg[15], cfg[16]);
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004390 iwe.u.data.length = strlen(buf);
David S. Millerccc58052008-06-16 18:50:49 -07004391 current_ev = iwe_stream_add_point(info, current_ev,
4392 end_buf,
Luis Carlos Cobof709fc62008-02-23 15:17:12 +01004393 &iwe, buf);
4394 kfree(buf);
4395 }
4396 }
4397
Jiri Bencf0706e822007-05-05 11:45:53 -07004398 return current_ev;
4399}
4400
4401
David S. Millerccc58052008-06-16 18:50:49 -07004402int ieee80211_sta_scan_results(struct net_device *dev,
4403 struct iw_request_info *info,
4404 char *buf, size_t len)
Jiri Bencf0706e822007-05-05 11:45:53 -07004405{
4406 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4407 char *current_ev = buf;
4408 char *end_buf = buf + len;
4409 struct ieee80211_sta_bss *bss;
4410
4411 spin_lock_bh(&local->sta_bss_lock);
4412 list_for_each_entry(bss, &local->sta_bss_list, list) {
4413 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
4414 spin_unlock_bh(&local->sta_bss_lock);
4415 return -E2BIG;
4416 }
David S. Millerccc58052008-06-16 18:50:49 -07004417 current_ev = ieee80211_sta_scan_result(dev, info, bss,
4418 current_ev, end_buf);
Jiri Bencf0706e822007-05-05 11:45:53 -07004419 }
4420 spin_unlock_bh(&local->sta_bss_lock);
4421 return current_ev - buf;
4422}
4423
4424
4425int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
4426{
4427 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4428 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
Johannes Berg988c0f72008-04-17 19:21:22 +02004429
Jiri Bencf0706e822007-05-05 11:45:53 -07004430 kfree(ifsta->extra_ie);
4431 if (len == 0) {
4432 ifsta->extra_ie = NULL;
4433 ifsta->extra_ie_len = 0;
4434 return 0;
4435 }
4436 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
4437 if (!ifsta->extra_ie) {
4438 ifsta->extra_ie_len = 0;
4439 return -ENOMEM;
4440 }
4441 memcpy(ifsta->extra_ie, ie, len);
4442 ifsta->extra_ie_len = len;
4443 return 0;
4444}
4445
4446
Johannes Berg988c0f72008-04-17 19:21:22 +02004447struct sta_info *ieee80211_ibss_add_sta(struct net_device *dev,
4448 struct sk_buff *skb, u8 *bssid,
Vladimir Koutny87291c02008-06-13 16:50:44 +02004449 u8 *addr, u64 supp_rates)
Jiri Bencf0706e822007-05-05 11:45:53 -07004450{
4451 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4452 struct sta_info *sta;
John W. Linville91fa5582007-05-15 16:14:40 -04004453 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Joe Perches0795af52007-10-03 17:59:30 -07004454 DECLARE_MAC_BUF(mac);
Vladimir Koutny87291c02008-06-13 16:50:44 +02004455 int band = local->hw.conf.channel->band;
Jiri Bencf0706e822007-05-05 11:45:53 -07004456
4457 /* TODO: Could consider removing the least recently used entry and
4458 * allow new one to be added. */
4459 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
4460 if (net_ratelimit()) {
4461 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
Joe Perches0795af52007-10-03 17:59:30 -07004462 "entry %s\n", dev->name, print_mac(mac, addr));
Jiri Bencf0706e822007-05-05 11:45:53 -07004463 }
4464 return NULL;
4465 }
4466
Vladimir Koutny87291c02008-06-13 16:50:44 +02004467 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid))
4468 return NULL;
4469
Joe Perches0795af52007-10-03 17:59:30 -07004470 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04004471 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
Jiri Bencf0706e822007-05-05 11:45:53 -07004472
Johannes Berg73651ee2008-02-25 16:27:47 +01004473 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
4474 if (!sta)
Jiri Bencf0706e822007-05-05 11:45:53 -07004475 return NULL;
4476
Johannes Berg07346f812008-05-03 01:02:02 +02004477 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
Johannes Berg238814f2008-01-28 17:19:37 +01004478
Vladimir Koutny87291c02008-06-13 16:50:44 +02004479 if (supp_rates)
4480 sta->supp_rates[band] = supp_rates;
4481 else
4482 sta->supp_rates[band] = sdata->u.sta.supp_rates_bits[band];
Jiri Bencf0706e822007-05-05 11:45:53 -07004483
4484 rate_control_rate_init(sta, local);
4485
Johannes Berg93e5deb2008-04-01 15:21:00 +02004486 if (sta_info_insert(sta))
Johannes Berg73651ee2008-02-25 16:27:47 +01004487 return NULL;
Johannes Berg73651ee2008-02-25 16:27:47 +01004488
Johannes Bergd0709a62008-02-25 16:27:46 +01004489 return sta;
Jiri Bencf0706e822007-05-05 11:45:53 -07004490}
4491
4492
4493int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
4494{
4495 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4496 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4497
4498 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
4499 dev->name, reason);
4500
Johannes Berg51fb61e2007-12-19 01:31:27 +01004501 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4502 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e822007-05-05 11:45:53 -07004503 return -EINVAL;
4504
4505 ieee80211_send_deauth(dev, ifsta, reason);
4506 ieee80211_set_disassoc(dev, ifsta, 1);
4507 return 0;
4508}
4509
4510
4511int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
4512{
4513 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4514 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4515
4516 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
4517 dev->name, reason);
4518
Johannes Berg51fb61e2007-12-19 01:31:27 +01004519 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07004520 return -EINVAL;
4521
Jiri Slabyd6f2da52007-08-28 17:01:54 -04004522 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
Jiri Bencf0706e822007-05-05 11:45:53 -07004523 return -1;
4524
4525 ieee80211_send_disassoc(dev, ifsta, reason);
4526 ieee80211_set_disassoc(dev, ifsta, 0);
4527 return 0;
4528}
Mohamed Abbas84363e62008-04-04 16:59:58 -07004529
4530void ieee80211_notify_mac(struct ieee80211_hw *hw,
4531 enum ieee80211_notification_types notif_type)
4532{
4533 struct ieee80211_local *local = hw_to_local(hw);
4534 struct ieee80211_sub_if_data *sdata;
4535
4536 switch (notif_type) {
4537 case IEEE80211_NOTIFY_RE_ASSOC:
4538 rcu_read_lock();
4539 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4540
4541 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
4542 ieee80211_sta_req_auth(sdata->dev,
4543 &sdata->u.sta);
4544 }
4545
4546 }
4547 rcu_read_unlock();
4548 break;
4549 }
4550}
4551EXPORT_SYMBOL(ieee80211_notify_mac);