2 * cfg80211 scan result handling
4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/netdevice.h>
9 #include <linux/wireless.h>
10 #include <linux/nl80211.h>
11 #include <linux/etherdevice.h>
13 #include <net/cfg80211.h>
14 #include <net/iw_handler.h>
17 #include "wext-compat.h"
19 #define IEEE80211_SCAN_RESULT_EXPIRE (15 * HZ)
21 void ___cfg80211_scan_done(struct cfg80211_registered_device
*rdev
, bool leak
)
23 struct cfg80211_scan_request
*request
;
24 struct net_device
*dev
;
25 #ifdef CONFIG_WIRELESS_EXT
26 union iwreq_data wrqu
;
29 ASSERT_RDEV_LOCK(rdev
);
31 request
= rdev
->scan_req
;
39 * This must be before sending the other events!
40 * Otherwise, wpa_supplicant gets completely confused with
43 cfg80211_sme_scan_done(dev
);
46 nl80211_send_scan_aborted(rdev
, dev
);
48 nl80211_send_scan_done(rdev
, dev
);
50 #ifdef CONFIG_WIRELESS_EXT
51 if (!request
->aborted
) {
52 memset(&wrqu
, 0, sizeof(wrqu
));
54 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
60 rdev
->scan_req
= NULL
;
63 * OK. If this is invoked with "leak" then we can't
64 * free this ... but we've cleaned it up anyway. The
65 * driver failed to call the scan_done callback, so
66 * all bets are off, it might still be trying to use
67 * the scan request or not ... if it accesses the dev
68 * in there (it shouldn't anyway) then it may crash.
74 void __cfg80211_scan_done(struct work_struct
*wk
)
76 struct cfg80211_registered_device
*rdev
;
78 rdev
= container_of(wk
, struct cfg80211_registered_device
,
81 cfg80211_lock_rdev(rdev
);
82 ___cfg80211_scan_done(rdev
, false);
83 cfg80211_unlock_rdev(rdev
);
86 void cfg80211_scan_done(struct cfg80211_scan_request
*request
, bool aborted
)
88 WARN_ON(request
!= wiphy_to_dev(request
->wiphy
)->scan_req
);
90 request
->aborted
= aborted
;
91 schedule_work(&wiphy_to_dev(request
->wiphy
)->scan_done_wk
);
93 EXPORT_SYMBOL(cfg80211_scan_done
);
95 static void bss_release(struct kref
*ref
)
97 struct cfg80211_internal_bss
*bss
;
99 bss
= container_of(ref
, struct cfg80211_internal_bss
, ref
);
100 if (bss
->pub
.free_priv
)
101 bss
->pub
.free_priv(&bss
->pub
);
103 if (bss
->ies_allocated
)
104 kfree(bss
->pub
.information_elements
);
106 BUG_ON(atomic_read(&bss
->hold
));
111 /* must hold dev->bss_lock! */
112 void cfg80211_bss_age(struct cfg80211_registered_device
*dev
,
113 unsigned long age_secs
)
115 struct cfg80211_internal_bss
*bss
;
116 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
118 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
119 bss
->ts
-= age_jiffies
;
123 /* must hold dev->bss_lock! */
124 void cfg80211_bss_expire(struct cfg80211_registered_device
*dev
)
126 struct cfg80211_internal_bss
*bss
, *tmp
;
127 bool expired
= false;
129 list_for_each_entry_safe(bss
, tmp
, &dev
->bss_list
, list
) {
130 if (atomic_read(&bss
->hold
))
132 if (!time_after(jiffies
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
))
134 list_del(&bss
->list
);
135 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
136 kref_put(&bss
->ref
, bss_release
);
141 dev
->bss_generation
++;
144 static u8
*find_ie(u8 num
, u8
*ies
, int len
)
146 while (len
> 2 && ies
[0] != num
) {
152 if (len
< 2 + ies
[1])
157 static int cmp_ies(u8 num
, u8
*ies1
, size_t len1
, u8
*ies2
, size_t len2
)
159 const u8
*ie1
= find_ie(num
, ies1
, len1
);
160 const u8
*ie2
= find_ie(num
, ies2
, len2
);
168 r
= memcmp(ie1
+ 2, ie2
+ 2, min(ie1
[1], ie2
[1]));
169 if (r
== 0 && ie1
[1] != ie2
[1])
170 return ie2
[1] - ie1
[1];
174 static bool is_bss(struct cfg80211_bss
*a
,
176 const u8
*ssid
, size_t ssid_len
)
180 if (bssid
&& compare_ether_addr(a
->bssid
, bssid
))
186 ssidie
= find_ie(WLAN_EID_SSID
,
187 a
->information_elements
,
188 a
->len_information_elements
);
191 if (ssidie
[1] != ssid_len
)
193 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
196 static bool is_mesh(struct cfg80211_bss
*a
,
197 const u8
*meshid
, size_t meshidlen
,
202 if (!is_zero_ether_addr(a
->bssid
))
205 ie
= find_ie(WLAN_EID_MESH_ID
,
206 a
->information_elements
,
207 a
->len_information_elements
);
210 if (ie
[1] != meshidlen
)
212 if (memcmp(ie
+ 2, meshid
, meshidlen
))
215 ie
= find_ie(WLAN_EID_MESH_CONFIG
,
216 a
->information_elements
,
217 a
->len_information_elements
);
220 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
224 * Ignore mesh capability (last two bytes of the IE) when
225 * comparing since that may differ between stations taking
226 * part in the same mesh.
228 return memcmp(ie
+ 2, meshcfg
, IEEE80211_MESH_CONFIG_LEN
- 2) == 0;
231 static int cmp_bss(struct cfg80211_bss
*a
,
232 struct cfg80211_bss
*b
)
236 if (a
->channel
!= b
->channel
)
237 return b
->channel
->center_freq
- a
->channel
->center_freq
;
239 r
= memcmp(a
->bssid
, b
->bssid
, ETH_ALEN
);
243 if (is_zero_ether_addr(a
->bssid
)) {
244 r
= cmp_ies(WLAN_EID_MESH_ID
,
245 a
->information_elements
,
246 a
->len_information_elements
,
247 b
->information_elements
,
248 b
->len_information_elements
);
251 return cmp_ies(WLAN_EID_MESH_CONFIG
,
252 a
->information_elements
,
253 a
->len_information_elements
,
254 b
->information_elements
,
255 b
->len_information_elements
);
258 return cmp_ies(WLAN_EID_SSID
,
259 a
->information_elements
,
260 a
->len_information_elements
,
261 b
->information_elements
,
262 b
->len_information_elements
);
265 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
266 struct ieee80211_channel
*channel
,
268 const u8
*ssid
, size_t ssid_len
,
269 u16 capa_mask
, u16 capa_val
)
271 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
272 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
274 spin_lock_bh(&dev
->bss_lock
);
276 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
277 if ((bss
->pub
.capability
& capa_mask
) != capa_val
)
279 if (channel
&& bss
->pub
.channel
!= channel
)
281 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
288 spin_unlock_bh(&dev
->bss_lock
);
293 EXPORT_SYMBOL(cfg80211_get_bss
);
295 struct cfg80211_bss
*cfg80211_get_mesh(struct wiphy
*wiphy
,
296 struct ieee80211_channel
*channel
,
297 const u8
*meshid
, size_t meshidlen
,
300 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
301 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
303 spin_lock_bh(&dev
->bss_lock
);
305 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
306 if (channel
&& bss
->pub
.channel
!= channel
)
308 if (is_mesh(&bss
->pub
, meshid
, meshidlen
, meshcfg
)) {
315 spin_unlock_bh(&dev
->bss_lock
);
320 EXPORT_SYMBOL(cfg80211_get_mesh
);
323 static void rb_insert_bss(struct cfg80211_registered_device
*dev
,
324 struct cfg80211_internal_bss
*bss
)
326 struct rb_node
**p
= &dev
->bss_tree
.rb_node
;
327 struct rb_node
*parent
= NULL
;
328 struct cfg80211_internal_bss
*tbss
;
333 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
335 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
);
338 /* will sort of leak this BSS */
348 rb_link_node(&bss
->rbn
, parent
, p
);
349 rb_insert_color(&bss
->rbn
, &dev
->bss_tree
);
352 static struct cfg80211_internal_bss
*
353 rb_find_bss(struct cfg80211_registered_device
*dev
,
354 struct cfg80211_internal_bss
*res
)
356 struct rb_node
*n
= dev
->bss_tree
.rb_node
;
357 struct cfg80211_internal_bss
*bss
;
361 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
362 r
= cmp_bss(&res
->pub
, &bss
->pub
);
375 static struct cfg80211_internal_bss
*
376 cfg80211_bss_update(struct cfg80211_registered_device
*dev
,
377 struct cfg80211_internal_bss
*res
,
380 struct cfg80211_internal_bss
*found
= NULL
;
381 const u8
*meshid
, *meshcfg
;
384 * The reference to "res" is donated to this function.
387 if (WARN_ON(!res
->pub
.channel
)) {
388 kref_put(&res
->ref
, bss_release
);
394 if (is_zero_ether_addr(res
->pub
.bssid
)) {
395 /* must be mesh, verify */
396 meshid
= find_ie(WLAN_EID_MESH_ID
, res
->pub
.information_elements
,
397 res
->pub
.len_information_elements
);
398 meshcfg
= find_ie(WLAN_EID_MESH_CONFIG
,
399 res
->pub
.information_elements
,
400 res
->pub
.len_information_elements
);
401 if (!meshid
|| !meshcfg
||
402 meshcfg
[1] != IEEE80211_MESH_CONFIG_LEN
) {
404 kref_put(&res
->ref
, bss_release
);
409 spin_lock_bh(&dev
->bss_lock
);
411 found
= rb_find_bss(dev
, res
);
414 found
->pub
.beacon_interval
= res
->pub
.beacon_interval
;
415 found
->pub
.tsf
= res
->pub
.tsf
;
416 found
->pub
.signal
= res
->pub
.signal
;
417 found
->pub
.capability
= res
->pub
.capability
;
422 size_t used
= dev
->wiphy
.bss_priv_size
+ sizeof(*res
);
423 size_t ielen
= res
->pub
.len_information_elements
;
425 if (!found
->ies_allocated
&& ksize(found
) >= used
+ ielen
) {
426 memcpy(found
->pub
.information_elements
,
427 res
->pub
.information_elements
, ielen
);
428 found
->pub
.len_information_elements
= ielen
;
430 u8
*ies
= found
->pub
.information_elements
;
432 if (found
->ies_allocated
)
433 ies
= krealloc(ies
, ielen
, GFP_ATOMIC
);
435 ies
= kmalloc(ielen
, GFP_ATOMIC
);
438 memcpy(ies
, res
->pub
.information_elements
, ielen
);
439 found
->ies_allocated
= true;
440 found
->pub
.information_elements
= ies
;
441 found
->pub
.len_information_elements
= ielen
;
446 kref_put(&res
->ref
, bss_release
);
448 /* this "consumes" the reference */
449 list_add_tail(&res
->list
, &dev
->bss_list
);
450 rb_insert_bss(dev
, res
);
454 dev
->bss_generation
++;
455 spin_unlock_bh(&dev
->bss_lock
);
457 kref_get(&found
->ref
);
462 cfg80211_inform_bss(struct wiphy
*wiphy
,
463 struct ieee80211_channel
*channel
,
465 u64 timestamp
, u16 capability
, u16 beacon_interval
,
466 const u8
*ie
, size_t ielen
,
467 s32 signal
, gfp_t gfp
)
469 struct cfg80211_internal_bss
*res
;
475 privsz
= wiphy
->bss_priv_size
;
477 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
478 (signal
< 0 || signal
> 100)))
481 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
485 memcpy(res
->pub
.bssid
, bssid
, ETH_ALEN
);
486 res
->pub
.channel
= channel
;
487 res
->pub
.signal
= signal
;
488 res
->pub
.tsf
= timestamp
;
489 res
->pub
.beacon_interval
= beacon_interval
;
490 res
->pub
.capability
= capability
;
491 /* point to after the private area */
492 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
493 memcpy(res
->pub
.information_elements
, ie
, ielen
);
494 res
->pub
.len_information_elements
= ielen
;
496 kref_init(&res
->ref
);
498 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, 0);
502 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
503 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
505 /* cfg80211_bss_update gives us a referenced result */
508 EXPORT_SYMBOL(cfg80211_inform_bss
);
510 struct cfg80211_bss
*
511 cfg80211_inform_bss_frame(struct wiphy
*wiphy
,
512 struct ieee80211_channel
*channel
,
513 struct ieee80211_mgmt
*mgmt
, size_t len
,
514 s32 signal
, gfp_t gfp
)
516 struct cfg80211_internal_bss
*res
;
517 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
518 u
.probe_resp
.variable
);
520 size_t privsz
= wiphy
->bss_priv_size
;
522 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
523 (signal
< 0 || signal
> 100)))
526 if (WARN_ON(!mgmt
|| !wiphy
||
527 len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
530 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
534 memcpy(res
->pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
535 res
->pub
.channel
= channel
;
536 res
->pub
.signal
= signal
;
537 res
->pub
.tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
538 res
->pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
539 res
->pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
540 /* point to after the private area */
541 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
542 memcpy(res
->pub
.information_elements
, mgmt
->u
.probe_resp
.variable
, ielen
);
543 res
->pub
.len_information_elements
= ielen
;
545 kref_init(&res
->ref
);
547 overwrite
= ieee80211_is_probe_resp(mgmt
->frame_control
);
549 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, overwrite
);
553 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
554 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
556 /* cfg80211_bss_update gives us a referenced result */
559 EXPORT_SYMBOL(cfg80211_inform_bss_frame
);
561 void cfg80211_put_bss(struct cfg80211_bss
*pub
)
563 struct cfg80211_internal_bss
*bss
;
568 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
569 kref_put(&bss
->ref
, bss_release
);
571 EXPORT_SYMBOL(cfg80211_put_bss
);
573 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
575 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
576 struct cfg80211_internal_bss
*bss
;
581 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
583 spin_lock_bh(&dev
->bss_lock
);
585 list_del(&bss
->list
);
586 dev
->bss_generation
++;
587 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
589 spin_unlock_bh(&dev
->bss_lock
);
591 kref_put(&bss
->ref
, bss_release
);
593 EXPORT_SYMBOL(cfg80211_unlink_bss
);
595 #ifdef CONFIG_WIRELESS_EXT
596 int cfg80211_wext_siwscan(struct net_device
*dev
,
597 struct iw_request_info
*info
,
598 union iwreq_data
*wrqu
, char *extra
)
600 struct cfg80211_registered_device
*rdev
;
602 struct iw_scan_req
*wreq
= NULL
;
603 struct cfg80211_scan_request
*creq
;
604 int i
, err
, n_channels
= 0;
605 enum ieee80211_band band
;
607 if (!netif_running(dev
))
610 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
))
611 wreq
= (struct iw_scan_req
*)extra
;
613 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
616 return PTR_ERR(rdev
);
618 if (rdev
->scan_req
) {
623 wiphy
= &rdev
->wiphy
;
625 /* Determine number of channels, needed to allocate creq */
626 if (wreq
&& wreq
->num_channels
)
627 n_channels
= wreq
->num_channels
;
629 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
630 if (wiphy
->bands
[band
])
631 n_channels
+= wiphy
->bands
[band
]->n_channels
;
634 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
635 n_channels
* sizeof(void *),
644 /* SSIDs come after channels */
645 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
646 creq
->n_channels
= n_channels
;
649 /* translate "Scan on frequencies" request */
651 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
653 if (!wiphy
->bands
[band
])
655 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
657 /* If we have a wireless request structure and the
658 * wireless request specifies frequencies, then search
659 * for the matching hardware channel.
661 if (wreq
&& wreq
->num_channels
) {
663 int wiphy_freq
= wiphy
->bands
[band
]->channels
[j
].center_freq
;
664 for (k
= 0; k
< wreq
->num_channels
; k
++) {
665 int wext_freq
= wreq
->channel_list
[k
].m
/ 100000;
666 if (wext_freq
== wiphy_freq
)
667 goto wext_freq_found
;
669 goto wext_freq_not_found
;
673 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
675 wext_freq_not_found
: ;
679 /* Set real number of channels specified in creq->channels[] */
680 creq
->n_channels
= i
;
682 /* translate "Scan for SSID" request */
684 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
685 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
)
687 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
688 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
690 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
694 rdev
->scan_req
= creq
;
695 err
= rdev
->ops
->scan(wiphy
, dev
, creq
);
697 rdev
->scan_req
= NULL
;
700 nl80211_send_scan_start(rdev
, dev
);
704 cfg80211_unlock_rdev(rdev
);
707 EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan
);
709 static void ieee80211_scan_add_ies(struct iw_request_info
*info
,
710 struct cfg80211_bss
*bss
,
711 char **current_ev
, char *end_buf
)
713 u8
*pos
, *end
, *next
;
716 if (!bss
->information_elements
||
717 !bss
->len_information_elements
)
721 * If needed, fragment the IEs buffer (at IE boundaries) into short
722 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
724 pos
= bss
->information_elements
;
725 end
= pos
+ bss
->len_information_elements
;
727 while (end
- pos
> IW_GENERIC_IE_MAX
) {
728 next
= pos
+ 2 + pos
[1];
729 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
730 next
= next
+ 2 + next
[1];
732 memset(&iwe
, 0, sizeof(iwe
));
734 iwe
.u
.data
.length
= next
- pos
;
735 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
742 memset(&iwe
, 0, sizeof(iwe
));
744 iwe
.u
.data
.length
= end
- pos
;
745 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
750 static inline unsigned int elapsed_jiffies_msecs(unsigned long start
)
752 unsigned long end
= jiffies
;
755 return jiffies_to_msecs(end
- start
);
757 return jiffies_to_msecs(end
+ (MAX_JIFFY_OFFSET
- start
) + 1);
761 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
762 struct cfg80211_internal_bss
*bss
, char *current_ev
,
767 u8
*ie
= bss
->pub
.information_elements
;
768 int rem
= bss
->pub
.len_information_elements
, i
, sig
;
771 memset(&iwe
, 0, sizeof(iwe
));
773 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
774 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
775 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
778 memset(&iwe
, 0, sizeof(iwe
));
779 iwe
.cmd
= SIOCGIWFREQ
;
780 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
782 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
785 memset(&iwe
, 0, sizeof(iwe
));
786 iwe
.cmd
= SIOCGIWFREQ
;
787 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
789 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
792 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
793 memset(&iwe
, 0, sizeof(iwe
));
795 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
796 IW_QUAL_NOISE_INVALID
|
797 IW_QUAL_QUAL_UPDATED
;
798 switch (wiphy
->signal_type
) {
799 case CFG80211_SIGNAL_TYPE_MBM
:
800 sig
= bss
->pub
.signal
/ 100;
801 iwe
.u
.qual
.level
= sig
;
802 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
803 if (sig
< -110) /* rather bad */
805 else if (sig
> -40) /* perfect */
807 /* will give a range of 0 .. 70 */
808 iwe
.u
.qual
.qual
= sig
+ 110;
810 case CFG80211_SIGNAL_TYPE_UNSPEC
:
811 iwe
.u
.qual
.level
= bss
->pub
.signal
;
812 /* will give range 0 .. 100 */
813 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
819 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
820 &iwe
, IW_EV_QUAL_LEN
);
823 memset(&iwe
, 0, sizeof(iwe
));
824 iwe
.cmd
= SIOCGIWENCODE
;
825 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
826 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
828 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
829 iwe
.u
.data
.length
= 0;
830 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
840 memset(&iwe
, 0, sizeof(iwe
));
841 iwe
.cmd
= SIOCGIWESSID
;
842 iwe
.u
.data
.length
= ie
[1];
843 iwe
.u
.data
.flags
= 1;
844 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
847 case WLAN_EID_MESH_ID
:
848 memset(&iwe
, 0, sizeof(iwe
));
849 iwe
.cmd
= SIOCGIWESSID
;
850 iwe
.u
.data
.length
= ie
[1];
851 iwe
.u
.data
.flags
= 1;
852 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
855 case WLAN_EID_MESH_CONFIG
:
857 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
859 buf
= kmalloc(50, GFP_ATOMIC
);
863 memset(&iwe
, 0, sizeof(iwe
));
864 iwe
.cmd
= IWEVCUSTOM
;
865 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
866 iwe
.u
.data
.length
= strlen(buf
);
867 current_ev
= iwe_stream_add_point(info
, current_ev
,
870 sprintf(buf
, "Path Selection Protocol ID: "
871 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
873 iwe
.u
.data
.length
= strlen(buf
);
874 current_ev
= iwe_stream_add_point(info
, current_ev
,
877 sprintf(buf
, "Path Selection Metric ID: "
878 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
880 iwe
.u
.data
.length
= strlen(buf
);
881 current_ev
= iwe_stream_add_point(info
, current_ev
,
884 sprintf(buf
, "Congestion Control Mode ID: "
885 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
887 iwe
.u
.data
.length
= strlen(buf
);
888 current_ev
= iwe_stream_add_point(info
, current_ev
,
891 sprintf(buf
, "Channel Precedence: "
892 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
894 iwe
.u
.data
.length
= strlen(buf
);
895 current_ev
= iwe_stream_add_point(info
, current_ev
,
900 case WLAN_EID_SUPP_RATES
:
901 case WLAN_EID_EXT_SUPP_RATES
:
902 /* display all supported rates in readable format */
903 p
= current_ev
+ iwe_stream_lcp_len(info
);
905 memset(&iwe
, 0, sizeof(iwe
));
906 iwe
.cmd
= SIOCGIWRATE
;
907 /* Those two flags are ignored... */
908 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
910 for (i
= 0; i
< ie
[1]; i
++) {
911 iwe
.u
.bitrate
.value
=
912 ((ie
[i
+ 2] & 0x7f) * 500000);
913 p
= iwe_stream_add_value(info
, current_ev
, p
,
914 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
923 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
925 memset(&iwe
, 0, sizeof(iwe
));
926 iwe
.cmd
= SIOCGIWMODE
;
928 iwe
.u
.mode
= IW_MODE_MESH
;
929 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
930 iwe
.u
.mode
= IW_MODE_MASTER
;
932 iwe
.u
.mode
= IW_MODE_ADHOC
;
933 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
934 &iwe
, IW_EV_UINT_LEN
);
937 buf
= kmalloc(30, GFP_ATOMIC
);
939 memset(&iwe
, 0, sizeof(iwe
));
940 iwe
.cmd
= IWEVCUSTOM
;
941 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->pub
.tsf
));
942 iwe
.u
.data
.length
= strlen(buf
);
943 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
945 memset(&iwe
, 0, sizeof(iwe
));
946 iwe
.cmd
= IWEVCUSTOM
;
947 sprintf(buf
, " Last beacon: %ums ago",
948 elapsed_jiffies_msecs(bss
->ts
));
949 iwe
.u
.data
.length
= strlen(buf
);
950 current_ev
= iwe_stream_add_point(info
, current_ev
,
955 ieee80211_scan_add_ies(info
, &bss
->pub
, ¤t_ev
, end_buf
);
961 static int ieee80211_scan_results(struct cfg80211_registered_device
*dev
,
962 struct iw_request_info
*info
,
963 char *buf
, size_t len
)
965 char *current_ev
= buf
;
966 char *end_buf
= buf
+ len
;
967 struct cfg80211_internal_bss
*bss
;
969 spin_lock_bh(&dev
->bss_lock
);
970 cfg80211_bss_expire(dev
);
972 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
973 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
974 spin_unlock_bh(&dev
->bss_lock
);
977 current_ev
= ieee80211_bss(&dev
->wiphy
, info
, bss
,
978 current_ev
, end_buf
);
980 spin_unlock_bh(&dev
->bss_lock
);
981 return current_ev
- buf
;
985 int cfg80211_wext_giwscan(struct net_device
*dev
,
986 struct iw_request_info
*info
,
987 struct iw_point
*data
, char *extra
)
989 struct cfg80211_registered_device
*rdev
;
992 if (!netif_running(dev
))
995 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
998 return PTR_ERR(rdev
);
1000 if (rdev
->scan_req
) {
1005 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
1013 cfg80211_unlock_rdev(rdev
);
1016 EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan
);