blob: f883ab9f1e6e436de1f4a311963410a341a931cd [file] [log] [blame]
Johannes Berg0a51b272008-09-08 17:44:25 +02001/*
Johannes Berg5484e232008-09-08 17:44:27 +02002 * Scanning implementation
3 *
Johannes Berg0a51b272008-09-08 17:44:25 +02004 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
Johannes Berg00d3f142009-02-10 21:26:00 +010015/* TODO: figure out how to avoid that the "current BSS" expires */
Johannes Berg5484e232008-09-08 17:44:27 +020016
Johannes Berg0a51b272008-09-08 17:44:25 +020017#include <linux/wireless.h>
18#include <linux/if_arp.h>
Johannes Berg078e1e62009-01-22 18:07:31 +010019#include <linux/rtnetlink.h>
Johannes Berg0a51b272008-09-08 17:44:25 +020020#include <net/mac80211.h>
21#include <net/iw_handler.h>
22
23#include "ieee80211_i.h"
Johannes Berg5484e232008-09-08 17:44:27 +020024#include "mesh.h"
Johannes Berg0a51b272008-09-08 17:44:25 +020025
26#define IEEE80211_PROBE_DELAY (HZ / 33)
27#define IEEE80211_CHANNEL_TIME (HZ / 33)
28#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
29
Johannes Bergc2b13452008-09-11 00:01:55 +020030struct ieee80211_bss *
Johannes Berg5484e232008-09-08 17:44:27 +020031ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
32 u8 *ssid, u8 ssid_len)
33{
Johannes Berg00d3f142009-02-10 21:26:00 +010034 return (void *)cfg80211_get_bss(local->hw.wiphy,
35 ieee80211_get_channel(local->hw.wiphy,
36 freq),
37 bssid, ssid, ssid_len,
38 0, 0);
Johannes Berg5484e232008-09-08 17:44:27 +020039}
40
Johannes Berg00d3f142009-02-10 21:26:00 +010041static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss)
Johannes Berg5484e232008-09-08 17:44:27 +020042{
Johannes Berg00d3f142009-02-10 21:26:00 +010043 struct ieee80211_bss *bss = (void *)cbss;
Johannes Berg5484e232008-09-08 17:44:27 +020044
Johannes Berg5484e232008-09-08 17:44:27 +020045 kfree(bss_mesh_id(bss));
46 kfree(bss_mesh_cfg(bss));
Johannes Berg5484e232008-09-08 17:44:27 +020047}
48
49void ieee80211_rx_bss_put(struct ieee80211_local *local,
Johannes Bergc2b13452008-09-11 00:01:55 +020050 struct ieee80211_bss *bss)
Johannes Berg5484e232008-09-08 17:44:27 +020051{
Johannes Berg00d3f142009-02-10 21:26:00 +010052 cfg80211_put_bss((struct cfg80211_bss *)bss);
Johannes Berg5484e232008-09-08 17:44:27 +020053}
54
Johannes Bergc2b13452008-09-11 00:01:55 +020055struct ieee80211_bss *
Johannes Berg5484e232008-09-08 17:44:27 +020056ieee80211_bss_info_update(struct ieee80211_local *local,
57 struct ieee80211_rx_status *rx_status,
58 struct ieee80211_mgmt *mgmt,
59 size_t len,
60 struct ieee802_11_elems *elems,
Johannes Berg2a519312009-02-10 21:25:55 +010061 struct ieee80211_channel *channel,
62 bool beacon)
Johannes Berg5484e232008-09-08 17:44:27 +020063{
Johannes Bergc2b13452008-09-11 00:01:55 +020064 struct ieee80211_bss *bss;
Johannes Berg00d3f142009-02-10 21:26:00 +010065 int clen;
Johannes Berg2a519312009-02-10 21:25:55 +010066 enum cfg80211_signal_type sigtype = CFG80211_SIGNAL_TYPE_NONE;
67 s32 signal = 0;
68
69 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
70 sigtype = CFG80211_SIGNAL_TYPE_MBM;
71 signal = rx_status->signal * 100;
72 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
73 sigtype = CFG80211_SIGNAL_TYPE_UNSPEC;
74 signal = (rx_status->signal * 100) / local->hw.max_signal;
75 }
76
Johannes Berg00d3f142009-02-10 21:26:00 +010077 bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel,
78 mgmt, len, signal, sigtype,
79 GFP_ATOMIC);
Johannes Berg5484e232008-09-08 17:44:27 +020080
Johannes Berg00d3f142009-02-10 21:26:00 +010081 if (!bss)
82 return NULL;
83
84 bss->cbss.free_priv = ieee80211_rx_bss_free;
Johannes Berg5484e232008-09-08 17:44:27 +020085
86 /* save the ERP value so that it is available at association time */
87 if (elems->erp_info && elems->erp_info_len >= 1) {
88 bss->erp_value = elems->erp_info[0];
89 bss->has_erp_value = 1;
90 }
91
Johannes Berg5484e232008-09-08 17:44:27 +020092 if (elems->tim) {
93 struct ieee80211_tim_ie *tim_ie =
94 (struct ieee80211_tim_ie *)elems->tim;
95 bss->dtim_period = tim_ie->dtim_period;
96 }
97
98 /* set default value for buggy APs */
99 if (!elems->tim || bss->dtim_period == 0)
100 bss->dtim_period = 1;
101
102 bss->supp_rates_len = 0;
103 if (elems->supp_rates) {
104 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
105 if (clen > elems->supp_rates_len)
106 clen = elems->supp_rates_len;
107 memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates,
108 clen);
109 bss->supp_rates_len += clen;
110 }
111 if (elems->ext_supp_rates) {
112 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
113 if (clen > elems->ext_supp_rates_len)
114 clen = elems->ext_supp_rates_len;
115 memcpy(&bss->supp_rates[bss->supp_rates_len],
116 elems->ext_supp_rates, clen);
117 bss->supp_rates_len += clen;
118 }
119
Johannes Berg5484e232008-09-08 17:44:27 +0200120 bss->wmm_used = elems->wmm_param || elems->wmm_info;
121
122 if (!beacon)
123 bss->last_probe_resp = jiffies;
124
Johannes Berg5484e232008-09-08 17:44:27 +0200125 return bss;
126}
Johannes Berg0a51b272008-09-08 17:44:25 +0200127
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530128void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid,
129 int freq, u8 *ssid, u8 ssid_len)
130{
131 struct ieee80211_bss *bss;
132 struct ieee80211_local *local = sdata->local;
133
134 bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len);
135 if (bss) {
Johannes Berg00d3f142009-02-10 21:26:00 +0100136 cfg80211_unlink_bss(local->hw.wiphy, (void *)bss);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530137 ieee80211_rx_bss_put(local, bss);
138 }
139}
140
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200141ieee80211_rx_result
Johannes Bergc2b13452008-09-11 00:01:55 +0200142ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
143 struct ieee80211_rx_status *rx_status)
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200144{
145 struct ieee80211_mgmt *mgmt;
Johannes Bergc2b13452008-09-11 00:01:55 +0200146 struct ieee80211_bss *bss;
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200147 u8 *elements;
148 struct ieee80211_channel *channel;
149 size_t baselen;
150 int freq;
151 __le16 fc;
152 bool presp, beacon = false;
153 struct ieee802_11_elems elems;
154
155 if (skb->len < 2)
156 return RX_DROP_UNUSABLE;
157
158 mgmt = (struct ieee80211_mgmt *) skb->data;
159 fc = mgmt->frame_control;
160
161 if (ieee80211_is_ctl(fc))
162 return RX_CONTINUE;
163
164 if (skb->len < 24)
165 return RX_DROP_MONITOR;
166
167 presp = ieee80211_is_probe_resp(fc);
168 if (presp) {
169 /* ignore ProbeResp to foreign address */
170 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
171 return RX_DROP_MONITOR;
172
173 presp = true;
174 elements = mgmt->u.probe_resp.variable;
175 baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
176 } else {
177 beacon = ieee80211_is_beacon(fc);
178 baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
179 elements = mgmt->u.beacon.variable;
180 }
181
182 if (!presp && !beacon)
183 return RX_CONTINUE;
184
185 if (baselen > skb->len)
186 return RX_DROP_MONITOR;
187
188 ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
189
190 if (elems.ds_params && elems.ds_params_len == 1)
191 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
192 else
193 freq = rx_status->freq;
194
195 channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
196
197 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
198 return RX_DROP_MONITOR;
199
200 bss = ieee80211_bss_info_update(sdata->local, rx_status,
201 mgmt, skb->len, &elems,
Johannes Berg2a519312009-02-10 21:25:55 +0100202 channel, beacon);
Jouni Malinend048e502008-10-11 03:29:55 +0300203 if (bss)
204 ieee80211_rx_bss_put(sdata->local, bss);
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200205
206 dev_kfree_skb(skb);
207 return RX_QUEUED;
208}
209
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800210void ieee80211_send_nullfunc(struct ieee80211_local *local,
Johannes Berg0a51b272008-09-08 17:44:25 +0200211 struct ieee80211_sub_if_data *sdata,
212 int powersave)
213{
214 struct sk_buff *skb;
215 struct ieee80211_hdr *nullfunc;
216 __le16 fc;
217
218 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
219 if (!skb) {
220 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
221 "frame\n", sdata->dev->name);
222 return;
223 }
224 skb_reserve(skb, local->hw.extra_tx_headroom);
225
226 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
227 memset(nullfunc, 0, 24);
228 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
229 IEEE80211_FCTL_TODS);
230 if (powersave)
231 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
232 nullfunc->frame_control = fc;
233 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
234 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
235 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
236
Johannes Berge50db652008-09-09 15:07:09 +0200237 ieee80211_tx_skb(sdata, skb, 0);
Johannes Berg0a51b272008-09-08 17:44:25 +0200238}
239
Johannes Berg2a519312009-02-10 21:25:55 +0100240void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
Johannes Berg0a51b272008-09-08 17:44:25 +0200241{
242 struct ieee80211_local *local = hw_to_local(hw);
243 struct ieee80211_sub_if_data *sdata;
Johannes Berg0a51b272008-09-08 17:44:25 +0200244
Johannes Bergc2b13452008-09-11 00:01:55 +0200245 if (WARN_ON(!local->hw_scanning && !local->sw_scanning))
Johannes Berg5bc75722008-09-11 00:01:51 +0200246 return;
247
Johannes Berg2a519312009-02-10 21:25:55 +0100248 if (WARN_ON(!local->scan_req))
249 return;
Johannes Berg5bc75722008-09-11 00:01:51 +0200250
Johannes Berg2a519312009-02-10 21:25:55 +0100251 if (local->scan_req != &local->int_scan_req)
252 cfg80211_scan_done(local->scan_req, aborted);
253 local->scan_req = NULL;
254
255 local->last_scan_completed = jiffies;
Johannes Berg0a51b272008-09-08 17:44:25 +0200256
Johannes Bergc2b13452008-09-11 00:01:55 +0200257 if (local->hw_scanning) {
258 local->hw_scanning = false;
Johannes Berge8975582008-10-09 12:18:51 +0200259 /*
260 * Somebody might have requested channel change during scan
261 * that we won't have acted upon, try now. ieee80211_hw_config
262 * will set the flag based on actual changes.
263 */
264 ieee80211_hw_config(local, 0);
Johannes Berg0a51b272008-09-08 17:44:25 +0200265 goto done;
266 }
267
Johannes Bergc2b13452008-09-11 00:01:55 +0200268 local->sw_scanning = false;
Johannes Berge8975582008-10-09 12:18:51 +0200269 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
Johannes Berg0a51b272008-09-08 17:44:25 +0200270
271 netif_tx_lock_bh(local->mdev);
272 netif_addr_lock(local->mdev);
273 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
274 local->ops->configure_filter(local_to_hw(local),
275 FIF_BCN_PRBRESP_PROMISC,
276 &local->filter_flags,
277 local->mdev->mc_count,
278 local->mdev->mc_list);
279
280 netif_addr_unlock(local->mdev);
281 netif_tx_unlock_bh(local->mdev);
282
Johannes Berg078e1e62009-01-22 18:07:31 +0100283 mutex_lock(&local->iflist_mtx);
284 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Bergfb9ddbf2009-01-26 19:11:57 +0100285 if (!netif_running(sdata->dev))
286 continue;
287
Johannes Berg0a51b272008-09-08 17:44:25 +0200288 /* Tell AP we're back */
Johannes Berg05c914f2008-09-11 00:01:58 +0200289 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg0a51b272008-09-08 17:44:25 +0200290 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
291 ieee80211_send_nullfunc(local, sdata, 0);
292 netif_tx_wake_all_queues(sdata->dev);
293 }
294 } else
295 netif_tx_wake_all_queues(sdata->dev);
Johannes Berg078e1e62009-01-22 18:07:31 +0100296
Johannes Berg14b80722009-02-10 21:25:42 +0100297 /* re-enable beaconing */
298 if (sdata->vif.type == NL80211_IFTYPE_AP ||
299 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
300 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
301 ieee80211_if_config(sdata,
302 IEEE80211_IFCC_BEACON_ENABLED);
Johannes Berg0a51b272008-09-08 17:44:25 +0200303 }
Johannes Berg078e1e62009-01-22 18:07:31 +0100304 mutex_unlock(&local->iflist_mtx);
Johannes Berg0a51b272008-09-08 17:44:25 +0200305
306 done:
307 ieee80211_mlme_notify_scan_completed(local);
Johannes Berg472dbc42008-09-11 00:01:49 +0200308 ieee80211_mesh_notify_scan_completed(local);
Johannes Berg0a51b272008-09-08 17:44:25 +0200309}
310EXPORT_SYMBOL(ieee80211_scan_completed);
311
Johannes Bergc2b13452008-09-11 00:01:55 +0200312void ieee80211_scan_work(struct work_struct *work)
Johannes Berg0a51b272008-09-08 17:44:25 +0200313{
314 struct ieee80211_local *local =
315 container_of(work, struct ieee80211_local, scan_work.work);
316 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berg0a51b272008-09-08 17:44:25 +0200317 struct ieee80211_channel *chan;
Johannes Berg2a519312009-02-10 21:25:55 +0100318 int skip, i;
Johannes Berg0a51b272008-09-08 17:44:25 +0200319 unsigned long next_delay = 0;
320
Johannes Berg5bc75722008-09-11 00:01:51 +0200321 /*
322 * Avoid re-scheduling when the sdata is going away.
323 */
324 if (!netif_running(sdata->dev))
Johannes Berg0a51b272008-09-08 17:44:25 +0200325 return;
326
327 switch (local->scan_state) {
328 case SCAN_SET_CHANNEL:
Johannes Berg0a51b272008-09-08 17:44:25 +0200329 /* if no more bands/channels left, complete scan */
Johannes Berg2a519312009-02-10 21:25:55 +0100330 if (local->scan_channel_idx >= local->scan_req->n_channels) {
331 ieee80211_scan_completed(local_to_hw(local), false);
Johannes Berg0a51b272008-09-08 17:44:25 +0200332 return;
333 }
334 skip = 0;
Johannes Berg2a519312009-02-10 21:25:55 +0100335 chan = local->scan_req->channels[local->scan_channel_idx];
Johannes Berg0a51b272008-09-08 17:44:25 +0200336
337 if (chan->flags & IEEE80211_CHAN_DISABLED ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200338 (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
Johannes Berg0a51b272008-09-08 17:44:25 +0200339 chan->flags & IEEE80211_CHAN_NO_IBSS))
340 skip = 1;
341
342 if (!skip) {
343 local->scan_channel = chan;
Johannes Berge8975582008-10-09 12:18:51 +0200344 if (ieee80211_hw_config(local,
345 IEEE80211_CONF_CHANGE_CHANNEL))
Johannes Berg0a51b272008-09-08 17:44:25 +0200346 skip = 1;
Johannes Berg0a51b272008-09-08 17:44:25 +0200347 }
348
349 /* advance state machine to next channel/band */
350 local->scan_channel_idx++;
Johannes Berg0a51b272008-09-08 17:44:25 +0200351
352 if (skip)
353 break;
354
355 next_delay = IEEE80211_PROBE_DELAY +
356 usecs_to_jiffies(local->hw.channel_change_time);
357 local->scan_state = SCAN_SEND_PROBE;
358 break;
359 case SCAN_SEND_PROBE:
360 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
361 local->scan_state = SCAN_SET_CHANNEL;
362
Johannes Berg2a519312009-02-10 21:25:55 +0100363 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
364 !local->scan_req->n_ssids)
Johannes Berg0a51b272008-09-08 17:44:25 +0200365 break;
Johannes Berg2a519312009-02-10 21:25:55 +0100366 for (i = 0; i < local->scan_req->n_ssids; i++)
367 ieee80211_send_probe_req(
368 sdata, NULL,
369 local->scan_req->ssids[i].ssid,
370 local->scan_req->ssids[i].ssid_len);
Johannes Berg0a51b272008-09-08 17:44:25 +0200371 next_delay = IEEE80211_CHANNEL_TIME;
372 break;
373 }
374
Johannes Berg5bc75722008-09-11 00:01:51 +0200375 queue_delayed_work(local->hw.workqueue, &local->scan_work,
376 next_delay);
Johannes Berg0a51b272008-09-08 17:44:25 +0200377}
378
379
Johannes Bergc2b13452008-09-11 00:01:55 +0200380int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
Johannes Berg2a519312009-02-10 21:25:55 +0100381 struct cfg80211_scan_request *req)
Johannes Berg0a51b272008-09-08 17:44:25 +0200382{
383 struct ieee80211_local *local = scan_sdata->local;
384 struct ieee80211_sub_if_data *sdata;
385
Johannes Berg2a519312009-02-10 21:25:55 +0100386 if (!req)
Johannes Berg0a51b272008-09-08 17:44:25 +0200387 return -EINVAL;
388
Johannes Berg2a519312009-02-10 21:25:55 +0100389 if (local->scan_req && local->scan_req != req)
390 return -EBUSY;
391
392 local->scan_req = req;
393
Johannes Berg0a51b272008-09-08 17:44:25 +0200394 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
395 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
396 * BSSID: MACAddress
397 * SSID
398 * ScanType: ACTIVE, PASSIVE
399 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
400 * a Probe frame during active scanning
401 * ChannelList
402 * MinChannelTime (>= ProbeDelay), in TU
403 * MaxChannelTime: (>= MinChannelTime), in TU
404 */
405
406 /* MLME-SCAN.confirm
407 * BSSDescriptionSet
408 * ResultCode: SUCCESS, INVALID_PARAMETERS
409 */
410
Johannes Bergc2b13452008-09-11 00:01:55 +0200411 if (local->sw_scanning || local->hw_scanning) {
Johannes Berg0a51b272008-09-08 17:44:25 +0200412 if (local->scan_sdata == scan_sdata)
413 return 0;
414 return -EBUSY;
415 }
416
417 if (local->ops->hw_scan) {
Johannes Berg5bc75722008-09-11 00:01:51 +0200418 int rc;
419
Johannes Bergc2b13452008-09-11 00:01:55 +0200420 local->hw_scanning = true;
Johannes Berg2a519312009-02-10 21:25:55 +0100421 rc = local->ops->hw_scan(local_to_hw(local), req);
Johannes Berg5bc75722008-09-11 00:01:51 +0200422 if (rc) {
Johannes Bergc2b13452008-09-11 00:01:55 +0200423 local->hw_scanning = false;
Johannes Berg5bc75722008-09-11 00:01:51 +0200424 return rc;
Johannes Berg0a51b272008-09-08 17:44:25 +0200425 }
Johannes Berg5bc75722008-09-11 00:01:51 +0200426 local->scan_sdata = scan_sdata;
427 return 0;
Johannes Berg0a51b272008-09-08 17:44:25 +0200428 }
429
Johannes Bergc2b13452008-09-11 00:01:55 +0200430 local->sw_scanning = true;
Johannes Berg0a51b272008-09-08 17:44:25 +0200431
Johannes Berg078e1e62009-01-22 18:07:31 +0100432 mutex_lock(&local->iflist_mtx);
433 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Bergfb9ddbf2009-01-26 19:11:57 +0100434 if (!netif_running(sdata->dev))
435 continue;
436
Johannes Berg14b80722009-02-10 21:25:42 +0100437 /* disable beaconing */
438 if (sdata->vif.type == NL80211_IFTYPE_AP ||
439 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
440 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
441 ieee80211_if_config(sdata,
442 IEEE80211_IFCC_BEACON_ENABLED);
Johannes Berg078e1e62009-01-22 18:07:31 +0100443
Johannes Berg05c914f2008-09-11 00:01:58 +0200444 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg0a51b272008-09-08 17:44:25 +0200445 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
446 netif_tx_stop_all_queues(sdata->dev);
447 ieee80211_send_nullfunc(local, sdata, 1);
448 }
449 } else
450 netif_tx_stop_all_queues(sdata->dev);
451 }
Johannes Berg078e1e62009-01-22 18:07:31 +0100452 mutex_unlock(&local->iflist_mtx);
Johannes Berg0a51b272008-09-08 17:44:25 +0200453
Johannes Berg0a51b272008-09-08 17:44:25 +0200454 local->scan_state = SCAN_SET_CHANNEL;
455 local->scan_channel_idx = 0;
Johannes Berg0a51b272008-09-08 17:44:25 +0200456 local->scan_sdata = scan_sdata;
Johannes Berg2a519312009-02-10 21:25:55 +0100457 local->scan_req = req;
Johannes Berg0a51b272008-09-08 17:44:25 +0200458
459 netif_addr_lock_bh(local->mdev);
460 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
461 local->ops->configure_filter(local_to_hw(local),
462 FIF_BCN_PRBRESP_PROMISC,
463 &local->filter_flags,
464 local->mdev->mc_count,
465 local->mdev->mc_list);
466 netif_addr_unlock_bh(local->mdev);
467
468 /* TODO: start scan as soon as all nullfunc frames are ACKed */
469 queue_delayed_work(local->hw.workqueue, &local->scan_work,
470 IEEE80211_CHANNEL_TIME);
471
472 return 0;
473}
474
475
Johannes Bergc2b13452008-09-11 00:01:55 +0200476int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
Johannes Berg2a519312009-02-10 21:25:55 +0100477 struct cfg80211_scan_request *req)
Johannes Berg0a51b272008-09-08 17:44:25 +0200478{
Johannes Berg0a51b272008-09-08 17:44:25 +0200479 struct ieee80211_local *local = sdata->local;
Johannes Berg9116dd02008-09-08 17:47:23 +0200480 struct ieee80211_if_sta *ifsta;
Johannes Berg0a51b272008-09-08 17:44:25 +0200481
Johannes Berg2a519312009-02-10 21:25:55 +0100482 if (!req)
483 return -EINVAL;
484
485 if (local->scan_req && local->scan_req != req)
486 return -EBUSY;
487
488 local->scan_req = req;
489
Johannes Berg05c914f2008-09-11 00:01:58 +0200490 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg2a519312009-02-10 21:25:55 +0100491 return ieee80211_start_scan(sdata, req);
Johannes Berg0a51b272008-09-08 17:44:25 +0200492
Johannes Berg9116dd02008-09-08 17:47:23 +0200493 /*
494 * STA has a state machine that might need to defer scanning
495 * while it's trying to associate/authenticate, therefore we
496 * queue it up to the state machine in that case.
497 */
498
Johannes Bergc2b13452008-09-11 00:01:55 +0200499 if (local->sw_scanning || local->hw_scanning) {
Johannes Berg0a51b272008-09-08 17:44:25 +0200500 if (local->scan_sdata == sdata)
501 return 0;
502 return -EBUSY;
503 }
504
Johannes Berg9116dd02008-09-08 17:47:23 +0200505 ifsta = &sdata->u.sta;
Johannes Berg0a51b272008-09-08 17:44:25 +0200506 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
507 queue_work(local->hw.workqueue, &ifsta->work);
Johannes Berg9116dd02008-09-08 17:47:23 +0200508
Johannes Berg0a51b272008-09-08 17:44:25 +0200509 return 0;
510}