2 * Scanning implementation
4 * 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>
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.
16 * order BSS list by RSSI(?) ("quality of AP")
17 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
21 #include <linux/wireless.h>
22 #include <linux/if_arp.h>
23 #include <net/mac80211.h>
24 #include <net/iw_handler.h>
26 #include "ieee80211_i.h"
29 #define IEEE80211_PROBE_DELAY (HZ / 33)
30 #define IEEE80211_CHANNEL_TIME (HZ / 33)
31 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
33 void ieee80211_rx_bss_list_init(struct ieee80211_local
*local
)
35 spin_lock_init(&local
->bss_lock
);
36 INIT_LIST_HEAD(&local
->bss_list
);
39 void ieee80211_rx_bss_list_deinit(struct ieee80211_local
*local
)
41 struct ieee80211_bss
*bss
, *tmp
;
43 list_for_each_entry_safe(bss
, tmp
, &local
->bss_list
, list
)
44 ieee80211_rx_bss_put(local
, bss
);
47 struct ieee80211_bss
*
48 ieee80211_rx_bss_get(struct ieee80211_local
*local
, u8
*bssid
, int freq
,
49 u8
*ssid
, u8 ssid_len
)
51 struct ieee80211_bss
*bss
;
53 spin_lock_bh(&local
->bss_lock
);
54 bss
= local
->bss_hash
[STA_HASH(bssid
)];
56 if (!bss_mesh_cfg(bss
) &&
57 !memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
59 bss
->ssid_len
== ssid_len
&&
60 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
61 atomic_inc(&bss
->users
);
66 spin_unlock_bh(&local
->bss_lock
);
70 /* Caller must hold local->bss_lock */
71 static void __ieee80211_rx_bss_hash_add(struct ieee80211_local
*local
,
72 struct ieee80211_bss
*bss
)
76 if (bss_mesh_cfg(bss
))
77 hash_idx
= mesh_id_hash(bss_mesh_id(bss
),
78 bss_mesh_id_len(bss
));
80 hash_idx
= STA_HASH(bss
->bssid
);
82 bss
->hnext
= local
->bss_hash
[hash_idx
];
83 local
->bss_hash
[hash_idx
] = bss
;
86 /* Caller must hold local->bss_lock */
87 static void __ieee80211_rx_bss_hash_del(struct ieee80211_local
*local
,
88 struct ieee80211_bss
*bss
)
90 struct ieee80211_bss
*b
, *prev
= NULL
;
91 b
= local
->bss_hash
[STA_HASH(bss
->bssid
)];
95 local
->bss_hash
[STA_HASH(bss
->bssid
)] =
98 prev
->hnext
= bss
->hnext
;
106 struct ieee80211_bss
*
107 ieee80211_rx_bss_add(struct ieee80211_local
*local
, u8
*bssid
, int freq
,
108 u8
*ssid
, u8 ssid_len
)
110 struct ieee80211_bss
*bss
;
112 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
115 atomic_set(&bss
->users
, 2);
116 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
118 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
119 memcpy(bss
->ssid
, ssid
, ssid_len
);
120 bss
->ssid_len
= ssid_len
;
123 spin_lock_bh(&local
->bss_lock
);
124 /* TODO: order by RSSI? */
125 list_add_tail(&bss
->list
, &local
->bss_list
);
126 __ieee80211_rx_bss_hash_add(local
, bss
);
127 spin_unlock_bh(&local
->bss_lock
);
131 #ifdef CONFIG_MAC80211_MESH
132 static struct ieee80211_bss
*
133 ieee80211_rx_mesh_bss_get(struct ieee80211_local
*local
, u8
*mesh_id
, int mesh_id_len
,
134 u8
*mesh_cfg
, int freq
)
136 struct ieee80211_bss
*bss
;
138 spin_lock_bh(&local
->bss_lock
);
139 bss
= local
->bss_hash
[mesh_id_hash(mesh_id
, mesh_id_len
)];
141 if (bss_mesh_cfg(bss
) &&
142 !memcmp(bss_mesh_cfg(bss
), mesh_cfg
, MESH_CFG_CMP_LEN
) &&
144 mesh_id_len
== bss
->mesh_id_len
&&
145 (mesh_id_len
== 0 || !memcmp(bss
->mesh_id
, mesh_id
,
147 atomic_inc(&bss
->users
);
152 spin_unlock_bh(&local
->bss_lock
);
156 static struct ieee80211_bss
*
157 ieee80211_rx_mesh_bss_add(struct ieee80211_local
*local
, u8
*mesh_id
, int mesh_id_len
,
158 u8
*mesh_cfg
, int mesh_config_len
, int freq
)
160 struct ieee80211_bss
*bss
;
162 if (mesh_config_len
!= IEEE80211_MESH_CONFIG_LEN
)
165 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
169 bss
->mesh_cfg
= kmalloc(MESH_CFG_CMP_LEN
, GFP_ATOMIC
);
170 if (!bss
->mesh_cfg
) {
175 if (mesh_id_len
&& mesh_id_len
<= IEEE80211_MAX_MESH_ID_LEN
) {
176 bss
->mesh_id
= kmalloc(mesh_id_len
, GFP_ATOMIC
);
178 kfree(bss
->mesh_cfg
);
182 memcpy(bss
->mesh_id
, mesh_id
, mesh_id_len
);
185 atomic_set(&bss
->users
, 2);
186 memcpy(bss
->mesh_cfg
, mesh_cfg
, MESH_CFG_CMP_LEN
);
187 bss
->mesh_id_len
= mesh_id_len
;
189 spin_lock_bh(&local
->bss_lock
);
190 /* TODO: order by RSSI? */
191 list_add_tail(&bss
->list
, &local
->bss_list
);
192 __ieee80211_rx_bss_hash_add(local
, bss
);
193 spin_unlock_bh(&local
->bss_lock
);
198 static void ieee80211_rx_bss_free(struct ieee80211_bss
*bss
)
201 kfree(bss_mesh_id(bss
));
202 kfree(bss_mesh_cfg(bss
));
206 void ieee80211_rx_bss_put(struct ieee80211_local
*local
,
207 struct ieee80211_bss
*bss
)
210 if (!atomic_dec_and_lock(&bss
->users
, &local
->bss_lock
)) {
215 __ieee80211_rx_bss_hash_del(local
, bss
);
216 list_del(&bss
->list
);
217 spin_unlock_bh(&local
->bss_lock
);
218 ieee80211_rx_bss_free(bss
);
221 struct ieee80211_bss
*
222 ieee80211_bss_info_update(struct ieee80211_local
*local
,
223 struct ieee80211_rx_status
*rx_status
,
224 struct ieee80211_mgmt
*mgmt
,
226 struct ieee802_11_elems
*elems
,
227 int freq
, bool beacon
)
229 struct ieee80211_bss
*bss
;
232 #ifdef CONFIG_MAC80211_MESH
233 if (elems
->mesh_config
)
234 bss
= ieee80211_rx_mesh_bss_get(local
, elems
->mesh_id
,
235 elems
->mesh_id_len
, elems
->mesh_config
, freq
);
238 bss
= ieee80211_rx_bss_get(local
, mgmt
->bssid
, freq
,
239 elems
->ssid
, elems
->ssid_len
);
241 #ifdef CONFIG_MAC80211_MESH
242 if (elems
->mesh_config
)
243 bss
= ieee80211_rx_mesh_bss_add(local
, elems
->mesh_id
,
244 elems
->mesh_id_len
, elems
->mesh_config
,
245 elems
->mesh_config_len
, freq
);
248 bss
= ieee80211_rx_bss_add(local
, mgmt
->bssid
, freq
,
249 elems
->ssid
, elems
->ssid_len
);
254 /* TODO: order by RSSI? */
255 spin_lock_bh(&local
->bss_lock
);
256 list_move_tail(&bss
->list
, &local
->bss_list
);
257 spin_unlock_bh(&local
->bss_lock
);
261 /* save the ERP value so that it is available at association time */
262 if (elems
->erp_info
&& elems
->erp_info_len
>= 1) {
263 bss
->erp_value
= elems
->erp_info
[0];
264 bss
->has_erp_value
= 1;
267 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
268 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
271 struct ieee80211_tim_ie
*tim_ie
=
272 (struct ieee80211_tim_ie
*)elems
->tim
;
273 bss
->dtim_period
= tim_ie
->dtim_period
;
276 /* set default value for buggy APs */
277 if (!elems
->tim
|| bss
->dtim_period
== 0)
278 bss
->dtim_period
= 1;
280 bss
->supp_rates_len
= 0;
281 if (elems
->supp_rates
) {
282 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
283 if (clen
> elems
->supp_rates_len
)
284 clen
= elems
->supp_rates_len
;
285 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
->supp_rates
,
287 bss
->supp_rates_len
+= clen
;
289 if (elems
->ext_supp_rates
) {
290 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
291 if (clen
> elems
->ext_supp_rates_len
)
292 clen
= elems
->ext_supp_rates_len
;
293 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
294 elems
->ext_supp_rates
, clen
);
295 bss
->supp_rates_len
+= clen
;
298 bss
->band
= rx_status
->band
;
300 bss
->timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
301 bss
->last_update
= jiffies
;
302 bss
->signal
= rx_status
->signal
;
303 bss
->noise
= rx_status
->noise
;
304 bss
->qual
= rx_status
->qual
;
305 bss
->wmm_used
= elems
->wmm_param
|| elems
->wmm_info
;
308 bss
->last_probe_resp
= jiffies
;
311 * For probe responses, or if we don't have any information yet,
312 * use the IEs from the beacon.
314 if (!bss
->ies
|| !beacon
) {
315 if (bss
->ies
== NULL
|| bss
->ies_len
< elems
->total_len
) {
317 bss
->ies
= kmalloc(elems
->total_len
, GFP_ATOMIC
);
320 memcpy(bss
->ies
, elems
->ie_start
, elems
->total_len
);
321 bss
->ies_len
= elems
->total_len
;
330 ieee80211_scan_rx(struct ieee80211_sub_if_data
*sdata
, struct sk_buff
*skb
,
331 struct ieee80211_rx_status
*rx_status
)
333 struct ieee80211_mgmt
*mgmt
;
334 struct ieee80211_bss
*bss
;
336 struct ieee80211_channel
*channel
;
340 bool presp
, beacon
= false;
341 struct ieee802_11_elems elems
;
344 return RX_DROP_UNUSABLE
;
346 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
347 fc
= mgmt
->frame_control
;
349 if (ieee80211_is_ctl(fc
))
353 return RX_DROP_MONITOR
;
355 presp
= ieee80211_is_probe_resp(fc
);
357 /* ignore ProbeResp to foreign address */
358 if (memcmp(mgmt
->da
, sdata
->dev
->dev_addr
, ETH_ALEN
))
359 return RX_DROP_MONITOR
;
362 elements
= mgmt
->u
.probe_resp
.variable
;
363 baselen
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
365 beacon
= ieee80211_is_beacon(fc
);
366 baselen
= offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
367 elements
= mgmt
->u
.beacon
.variable
;
370 if (!presp
&& !beacon
)
373 if (baselen
> skb
->len
)
374 return RX_DROP_MONITOR
;
376 ieee802_11_parse_elems(elements
, skb
->len
- baselen
, &elems
);
378 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
379 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0]);
381 freq
= rx_status
->freq
;
383 channel
= ieee80211_get_channel(sdata
->local
->hw
.wiphy
, freq
);
385 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
386 return RX_DROP_MONITOR
;
388 bss
= ieee80211_bss_info_update(sdata
->local
, rx_status
,
389 mgmt
, skb
->len
, &elems
,
392 ieee80211_rx_bss_put(sdata
->local
, bss
);
398 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
399 struct ieee80211_sub_if_data
*sdata
,
403 struct ieee80211_hdr
*nullfunc
;
406 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
408 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
409 "frame\n", sdata
->dev
->name
);
412 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
414 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
415 memset(nullfunc
, 0, 24);
416 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
417 IEEE80211_FCTL_TODS
);
419 fc
|= cpu_to_le16(IEEE80211_FCTL_PM
);
420 nullfunc
->frame_control
= fc
;
421 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
422 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
423 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
425 ieee80211_tx_skb(sdata
, skb
, 0);
428 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
430 struct ieee80211_local
*local
= hw_to_local(hw
);
431 struct ieee80211_sub_if_data
*sdata
;
432 union iwreq_data wrqu
;
434 if (WARN_ON(!local
->hw_scanning
&& !local
->sw_scanning
))
437 local
->last_scan_completed
= jiffies
;
438 memset(&wrqu
, 0, sizeof(wrqu
));
441 * local->scan_sdata could have been NULLed by the interface
442 * down code in case we were scanning on an interface that is
445 sdata
= local
->scan_sdata
;
447 wireless_send_event(sdata
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
449 if (local
->hw_scanning
) {
450 local
->hw_scanning
= false;
452 * Somebody might have requested channel change during scan
453 * that we won't have acted upon, try now. ieee80211_hw_config
454 * will set the flag based on actual changes.
456 ieee80211_hw_config(local
, 0);
460 local
->sw_scanning
= false;
461 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
463 netif_tx_lock_bh(local
->mdev
);
464 netif_addr_lock(local
->mdev
);
465 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
466 local
->ops
->configure_filter(local_to_hw(local
),
467 FIF_BCN_PRBRESP_PROMISC
,
468 &local
->filter_flags
,
469 local
->mdev
->mc_count
,
470 local
->mdev
->mc_list
);
472 netif_addr_unlock(local
->mdev
);
473 netif_tx_unlock_bh(local
->mdev
);
476 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
477 /* Tell AP we're back */
478 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
479 if (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
) {
480 ieee80211_send_nullfunc(local
, sdata
, 0);
481 netif_tx_wake_all_queues(sdata
->dev
);
484 netif_tx_wake_all_queues(sdata
->dev
);
489 ieee80211_mlme_notify_scan_completed(local
);
490 ieee80211_mesh_notify_scan_completed(local
);
492 EXPORT_SYMBOL(ieee80211_scan_completed
);
495 void ieee80211_scan_work(struct work_struct
*work
)
497 struct ieee80211_local
*local
=
498 container_of(work
, struct ieee80211_local
, scan_work
.work
);
499 struct ieee80211_sub_if_data
*sdata
= local
->scan_sdata
;
500 struct ieee80211_supported_band
*sband
;
501 struct ieee80211_channel
*chan
;
503 unsigned long next_delay
= 0;
506 * Avoid re-scheduling when the sdata is going away.
508 if (!netif_running(sdata
->dev
))
511 switch (local
->scan_state
) {
512 case SCAN_SET_CHANNEL
:
514 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
515 * after we successfully scanned the last channel of the last
516 * band (and the last band is supported by the hw)
518 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
519 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
524 * If we are at an unsupported band and have more bands
525 * left to scan, advance to the next supported one.
527 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
529 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
530 local
->scan_channel_idx
= 0;
533 /* if no more bands/channels left, complete scan */
534 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
535 ieee80211_scan_completed(local_to_hw(local
));
539 chan
= &sband
->channels
[local
->scan_channel_idx
];
541 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
542 (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
&&
543 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
547 local
->scan_channel
= chan
;
548 if (ieee80211_hw_config(local
,
549 IEEE80211_CONF_CHANGE_CHANNEL
))
553 /* advance state machine to next channel/band */
554 local
->scan_channel_idx
++;
555 if (local
->scan_channel_idx
>= sband
->n_channels
) {
557 * scan_band may end up == IEEE80211_NUM_BANDS, but
558 * we'll catch that case above and complete the scan
559 * if that is the case.
562 local
->scan_channel_idx
= 0;
568 next_delay
= IEEE80211_PROBE_DELAY
+
569 usecs_to_jiffies(local
->hw
.channel_change_time
);
570 local
->scan_state
= SCAN_SEND_PROBE
;
572 case SCAN_SEND_PROBE
:
573 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
574 local
->scan_state
= SCAN_SET_CHANNEL
;
576 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
578 ieee80211_send_probe_req(sdata
, NULL
, local
->scan_ssid
,
579 local
->scan_ssid_len
);
580 next_delay
= IEEE80211_CHANNEL_TIME
;
584 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
589 int ieee80211_start_scan(struct ieee80211_sub_if_data
*scan_sdata
,
590 u8
*ssid
, size_t ssid_len
)
592 struct ieee80211_local
*local
= scan_sdata
->local
;
593 struct ieee80211_sub_if_data
*sdata
;
595 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
598 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
599 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
602 * ScanType: ACTIVE, PASSIVE
603 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
604 * a Probe frame during active scanning
606 * MinChannelTime (>= ProbeDelay), in TU
607 * MaxChannelTime: (>= MinChannelTime), in TU
612 * ResultCode: SUCCESS, INVALID_PARAMETERS
615 if (local
->sw_scanning
|| local
->hw_scanning
) {
616 if (local
->scan_sdata
== scan_sdata
)
621 if (local
->ops
->hw_scan
) {
624 local
->hw_scanning
= true;
625 rc
= local
->ops
->hw_scan(local_to_hw(local
), ssid
, ssid_len
);
627 local
->hw_scanning
= false;
630 local
->scan_sdata
= scan_sdata
;
634 local
->sw_scanning
= true;
637 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
638 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
639 if (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
) {
640 netif_tx_stop_all_queues(sdata
->dev
);
641 ieee80211_send_nullfunc(local
, sdata
, 1);
644 netif_tx_stop_all_queues(sdata
->dev
);
649 local
->scan_ssid_len
= ssid_len
;
650 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
652 local
->scan_ssid_len
= 0;
653 local
->scan_state
= SCAN_SET_CHANNEL
;
654 local
->scan_channel_idx
= 0;
655 local
->scan_band
= IEEE80211_BAND_2GHZ
;
656 local
->scan_sdata
= scan_sdata
;
658 netif_addr_lock_bh(local
->mdev
);
659 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
660 local
->ops
->configure_filter(local_to_hw(local
),
661 FIF_BCN_PRBRESP_PROMISC
,
662 &local
->filter_flags
,
663 local
->mdev
->mc_count
,
664 local
->mdev
->mc_list
);
665 netif_addr_unlock_bh(local
->mdev
);
667 /* TODO: start scan as soon as all nullfunc frames are ACKed */
668 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
669 IEEE80211_CHANNEL_TIME
);
675 int ieee80211_request_scan(struct ieee80211_sub_if_data
*sdata
,
676 u8
*ssid
, size_t ssid_len
)
678 struct ieee80211_local
*local
= sdata
->local
;
679 struct ieee80211_if_sta
*ifsta
;
681 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
682 return ieee80211_start_scan(sdata
, ssid
, ssid_len
);
685 * STA has a state machine that might need to defer scanning
686 * while it's trying to associate/authenticate, therefore we
687 * queue it up to the state machine in that case.
690 if (local
->sw_scanning
|| local
->hw_scanning
) {
691 if (local
->scan_sdata
== sdata
)
696 ifsta
= &sdata
->u
.sta
;
698 ifsta
->scan_ssid_len
= ssid_len
;
700 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
701 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
702 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
708 static void ieee80211_scan_add_ies(struct iw_request_info
*info
,
709 struct ieee80211_bss
*bss
,
710 char **current_ev
, char *end_buf
)
712 u8
*pos
, *end
, *next
;
715 if (bss
== NULL
|| bss
->ies
== NULL
)
719 * If needed, fragment the IEs buffer (at IE boundaries) into short
720 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
723 end
= pos
+ bss
->ies_len
;
725 while (end
- pos
> IW_GENERIC_IE_MAX
) {
726 next
= pos
+ 2 + pos
[1];
727 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
728 next
= next
+ 2 + next
[1];
730 memset(&iwe
, 0, sizeof(iwe
));
732 iwe
.u
.data
.length
= next
- pos
;
733 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
740 memset(&iwe
, 0, sizeof(iwe
));
742 iwe
.u
.data
.length
= end
- pos
;
743 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
750 ieee80211_scan_result(struct ieee80211_local
*local
,
751 struct iw_request_info
*info
,
752 struct ieee80211_bss
*bss
,
753 char *current_ev
, char *end_buf
)
758 if (time_after(jiffies
,
759 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
762 memset(&iwe
, 0, sizeof(iwe
));
764 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
765 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
766 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
769 memset(&iwe
, 0, sizeof(iwe
));
770 iwe
.cmd
= SIOCGIWESSID
;
771 if (bss_mesh_cfg(bss
)) {
772 iwe
.u
.data
.length
= bss_mesh_id_len(bss
);
773 iwe
.u
.data
.flags
= 1;
774 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
775 &iwe
, bss_mesh_id(bss
));
777 iwe
.u
.data
.length
= bss
->ssid_len
;
778 iwe
.u
.data
.flags
= 1;
779 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
783 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
784 || bss_mesh_cfg(bss
)) {
785 memset(&iwe
, 0, sizeof(iwe
));
786 iwe
.cmd
= SIOCGIWMODE
;
787 if (bss_mesh_cfg(bss
))
788 iwe
.u
.mode
= IW_MODE_MESH
;
789 else if (bss
->capability
& WLAN_CAPABILITY_ESS
)
790 iwe
.u
.mode
= IW_MODE_MASTER
;
792 iwe
.u
.mode
= IW_MODE_ADHOC
;
793 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
794 &iwe
, IW_EV_UINT_LEN
);
797 memset(&iwe
, 0, sizeof(iwe
));
798 iwe
.cmd
= SIOCGIWFREQ
;
799 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
801 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
804 memset(&iwe
, 0, sizeof(iwe
));
805 iwe
.cmd
= SIOCGIWFREQ
;
806 iwe
.u
.freq
.m
= bss
->freq
;
808 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
810 memset(&iwe
, 0, sizeof(iwe
));
812 iwe
.u
.qual
.qual
= bss
->qual
;
813 iwe
.u
.qual
.level
= bss
->signal
;
814 iwe
.u
.qual
.noise
= bss
->noise
;
815 iwe
.u
.qual
.updated
= local
->wstats_flags
;
816 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
819 memset(&iwe
, 0, sizeof(iwe
));
820 iwe
.cmd
= SIOCGIWENCODE
;
821 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
822 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
824 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
825 iwe
.u
.data
.length
= 0;
826 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
829 ieee80211_scan_add_ies(info
, bss
, ¤t_ev
, end_buf
);
831 if (bss
->supp_rates_len
> 0) {
832 /* display all supported rates in readable format */
833 char *p
= current_ev
+ iwe_stream_lcp_len(info
);
836 memset(&iwe
, 0, sizeof(iwe
));
837 iwe
.cmd
= SIOCGIWRATE
;
838 /* Those two flags are ignored... */
839 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
841 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
842 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
844 p
= iwe_stream_add_value(info
, current_ev
, p
,
845 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
850 buf
= kmalloc(30, GFP_ATOMIC
);
852 memset(&iwe
, 0, sizeof(iwe
));
853 iwe
.cmd
= IWEVCUSTOM
;
854 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
855 iwe
.u
.data
.length
= strlen(buf
);
856 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
858 memset(&iwe
, 0, sizeof(iwe
));
859 iwe
.cmd
= IWEVCUSTOM
;
860 sprintf(buf
, " Last beacon: %dms ago",
861 jiffies_to_msecs(jiffies
- bss
->last_update
));
862 iwe
.u
.data
.length
= strlen(buf
);
863 current_ev
= iwe_stream_add_point(info
, current_ev
,
868 if (bss_mesh_cfg(bss
)) {
869 u8
*cfg
= bss_mesh_cfg(bss
);
870 buf
= kmalloc(50, GFP_ATOMIC
);
872 memset(&iwe
, 0, sizeof(iwe
));
873 iwe
.cmd
= IWEVCUSTOM
;
874 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
875 iwe
.u
.data
.length
= strlen(buf
);
876 current_ev
= iwe_stream_add_point(info
, current_ev
,
879 sprintf(buf
, "Path Selection Protocol ID: "
880 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
882 iwe
.u
.data
.length
= strlen(buf
);
883 current_ev
= iwe_stream_add_point(info
, current_ev
,
886 sprintf(buf
, "Path Selection Metric ID: "
887 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
889 iwe
.u
.data
.length
= strlen(buf
);
890 current_ev
= iwe_stream_add_point(info
, current_ev
,
893 sprintf(buf
, "Congestion Control Mode ID: "
894 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
896 iwe
.u
.data
.length
= strlen(buf
);
897 current_ev
= iwe_stream_add_point(info
, current_ev
,
900 sprintf(buf
, "Channel Precedence: "
901 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
903 iwe
.u
.data
.length
= strlen(buf
);
904 current_ev
= iwe_stream_add_point(info
, current_ev
,
915 int ieee80211_scan_results(struct ieee80211_local
*local
,
916 struct iw_request_info
*info
,
917 char *buf
, size_t len
)
919 char *current_ev
= buf
;
920 char *end_buf
= buf
+ len
;
921 struct ieee80211_bss
*bss
;
923 spin_lock_bh(&local
->bss_lock
);
924 list_for_each_entry(bss
, &local
->bss_list
, list
) {
925 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
926 spin_unlock_bh(&local
->bss_lock
);
929 current_ev
= ieee80211_scan_result(local
, info
, bss
,
930 current_ev
, end_buf
);
932 spin_unlock_bh(&local
->bss_lock
);
933 return current_ev
- buf
;