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>
18 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
20 void cfg80211_scan_done(struct cfg80211_scan_request
*request
, bool aborted
)
22 struct net_device
*dev
;
23 #ifdef CONFIG_WIRELESS_EXT
24 union iwreq_data wrqu
;
27 dev
= dev_get_by_index(&init_net
, request
->ifidx
);
31 WARN_ON(request
!= wiphy_to_dev(request
->wiphy
)->scan_req
);
32 wiphy_to_dev(request
->wiphy
)->scan_req
= NULL
;
35 nl80211_send_scan_aborted(wiphy_to_dev(request
->wiphy
), dev
);
37 nl80211_send_scan_done(wiphy_to_dev(request
->wiphy
), dev
);
39 #ifdef CONFIG_WIRELESS_EXT
41 memset(&wrqu
, 0, sizeof(wrqu
));
43 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
52 EXPORT_SYMBOL(cfg80211_scan_done
);
54 static void bss_release(struct kref
*ref
)
56 struct cfg80211_internal_bss
*bss
;
58 bss
= container_of(ref
, struct cfg80211_internal_bss
, ref
);
59 if (bss
->pub
.free_priv
)
60 bss
->pub
.free_priv(&bss
->pub
);
64 /* must hold dev->bss_lock! */
65 void cfg80211_bss_age(struct cfg80211_registered_device
*dev
,
66 unsigned long age_secs
)
68 struct cfg80211_internal_bss
*bss
;
69 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
71 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
72 bss
->ts
-= age_jiffies
;
76 /* must hold dev->bss_lock! */
77 void cfg80211_bss_expire(struct cfg80211_registered_device
*dev
)
79 struct cfg80211_internal_bss
*bss
, *tmp
;
82 list_for_each_entry_safe(bss
, tmp
, &dev
->bss_list
, list
) {
84 !time_after(jiffies
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
))
87 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
88 kref_put(&bss
->ref
, bss_release
);
93 dev
->bss_generation
++;
96 static u8
*find_ie(u8 num
, u8
*ies
, size_t len
)
98 while (len
> 2 && ies
[0] != num
) {
104 if (len
< 2 + ies
[1])
109 static int cmp_ies(u8 num
, u8
*ies1
, size_t len1
, u8
*ies2
, size_t len2
)
111 const u8
*ie1
= find_ie(num
, ies1
, len1
);
112 const u8
*ie2
= find_ie(num
, ies2
, len2
);
120 r
= memcmp(ie1
+ 2, ie2
+ 2, min(ie1
[1], ie2
[1]));
121 if (r
== 0 && ie1
[1] != ie2
[1])
122 return ie2
[1] - ie1
[1];
126 static bool is_bss(struct cfg80211_bss
*a
,
128 const u8
*ssid
, size_t ssid_len
)
132 if (bssid
&& compare_ether_addr(a
->bssid
, bssid
))
138 ssidie
= find_ie(WLAN_EID_SSID
,
139 a
->information_elements
,
140 a
->len_information_elements
);
143 if (ssidie
[1] != ssid_len
)
145 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
148 static bool is_mesh(struct cfg80211_bss
*a
,
149 const u8
*meshid
, size_t meshidlen
,
154 if (!is_zero_ether_addr(a
->bssid
))
157 ie
= find_ie(WLAN_EID_MESH_ID
,
158 a
->information_elements
,
159 a
->len_information_elements
);
162 if (ie
[1] != meshidlen
)
164 if (memcmp(ie
+ 2, meshid
, meshidlen
))
167 ie
= find_ie(WLAN_EID_MESH_CONFIG
,
168 a
->information_elements
,
169 a
->len_information_elements
);
170 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
174 * Ignore mesh capability (last two bytes of the IE) when
175 * comparing since that may differ between stations taking
176 * part in the same mesh.
178 return memcmp(ie
+ 2, meshcfg
, IEEE80211_MESH_CONFIG_LEN
- 2) == 0;
181 static int cmp_bss(struct cfg80211_bss
*a
,
182 struct cfg80211_bss
*b
)
186 if (a
->channel
!= b
->channel
)
187 return b
->channel
->center_freq
- a
->channel
->center_freq
;
189 r
= memcmp(a
->bssid
, b
->bssid
, ETH_ALEN
);
193 if (is_zero_ether_addr(a
->bssid
)) {
194 r
= cmp_ies(WLAN_EID_MESH_ID
,
195 a
->information_elements
,
196 a
->len_information_elements
,
197 b
->information_elements
,
198 b
->len_information_elements
);
201 return cmp_ies(WLAN_EID_MESH_CONFIG
,
202 a
->information_elements
,
203 a
->len_information_elements
,
204 b
->information_elements
,
205 b
->len_information_elements
);
208 return cmp_ies(WLAN_EID_SSID
,
209 a
->information_elements
,
210 a
->len_information_elements
,
211 b
->information_elements
,
212 b
->len_information_elements
);
215 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
216 struct ieee80211_channel
*channel
,
218 const u8
*ssid
, size_t ssid_len
,
219 u16 capa_mask
, u16 capa_val
)
221 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
222 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
224 spin_lock_bh(&dev
->bss_lock
);
226 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
227 if ((bss
->pub
.capability
& capa_mask
) != capa_val
)
229 if (channel
&& bss
->pub
.channel
!= channel
)
231 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
238 spin_unlock_bh(&dev
->bss_lock
);
243 EXPORT_SYMBOL(cfg80211_get_bss
);
245 struct cfg80211_bss
*cfg80211_get_mesh(struct wiphy
*wiphy
,
246 struct ieee80211_channel
*channel
,
247 const u8
*meshid
, size_t meshidlen
,
250 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
251 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
253 spin_lock_bh(&dev
->bss_lock
);
255 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
256 if (channel
&& bss
->pub
.channel
!= channel
)
258 if (is_mesh(&bss
->pub
, meshid
, meshidlen
, meshcfg
)) {
265 spin_unlock_bh(&dev
->bss_lock
);
270 EXPORT_SYMBOL(cfg80211_get_mesh
);
273 static void rb_insert_bss(struct cfg80211_registered_device
*dev
,
274 struct cfg80211_internal_bss
*bss
)
276 struct rb_node
**p
= &dev
->bss_tree
.rb_node
;
277 struct rb_node
*parent
= NULL
;
278 struct cfg80211_internal_bss
*tbss
;
283 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
285 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
);
288 /* will sort of leak this BSS */
298 rb_link_node(&bss
->rbn
, parent
, p
);
299 rb_insert_color(&bss
->rbn
, &dev
->bss_tree
);
302 static struct cfg80211_internal_bss
*
303 rb_find_bss(struct cfg80211_registered_device
*dev
,
304 struct cfg80211_internal_bss
*res
)
306 struct rb_node
*n
= dev
->bss_tree
.rb_node
;
307 struct cfg80211_internal_bss
*bss
;
311 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
312 r
= cmp_bss(&res
->pub
, &bss
->pub
);
325 static struct cfg80211_internal_bss
*
326 cfg80211_bss_update(struct cfg80211_registered_device
*dev
,
327 struct cfg80211_internal_bss
*res
,
330 struct cfg80211_internal_bss
*found
= NULL
;
331 const u8
*meshid
, *meshcfg
;
334 * The reference to "res" is donated to this function.
337 if (WARN_ON(!res
->pub
.channel
)) {
338 kref_put(&res
->ref
, bss_release
);
344 if (is_zero_ether_addr(res
->pub
.bssid
)) {
345 /* must be mesh, verify */
346 meshid
= find_ie(WLAN_EID_MESH_ID
, res
->pub
.information_elements
,
347 res
->pub
.len_information_elements
);
348 meshcfg
= find_ie(WLAN_EID_MESH_CONFIG
,
349 res
->pub
.information_elements
,
350 res
->pub
.len_information_elements
);
351 if (!meshid
|| !meshcfg
||
352 meshcfg
[1] != IEEE80211_MESH_CONFIG_LEN
) {
354 kref_put(&res
->ref
, bss_release
);
359 spin_lock_bh(&dev
->bss_lock
);
361 found
= rb_find_bss(dev
, res
);
363 if (found
&& overwrite
) {
364 list_replace(&found
->list
, &res
->list
);
365 rb_replace_node(&found
->rbn
, &res
->rbn
,
367 kref_put(&found
->ref
, bss_release
);
370 kref_get(&found
->ref
);
371 found
->pub
.beacon_interval
= res
->pub
.beacon_interval
;
372 found
->pub
.tsf
= res
->pub
.tsf
;
373 found
->pub
.signal
= res
->pub
.signal
;
374 found
->pub
.capability
= res
->pub
.capability
;
376 kref_put(&res
->ref
, bss_release
);
378 /* this "consumes" the reference */
379 list_add_tail(&res
->list
, &dev
->bss_list
);
380 rb_insert_bss(dev
, res
);
384 dev
->bss_generation
++;
385 spin_unlock_bh(&dev
->bss_lock
);
387 kref_get(&found
->ref
);
391 struct cfg80211_bss
*
392 cfg80211_inform_bss_frame(struct wiphy
*wiphy
,
393 struct ieee80211_channel
*channel
,
394 struct ieee80211_mgmt
*mgmt
, size_t len
,
395 s32 signal
, gfp_t gfp
)
397 struct cfg80211_internal_bss
*res
;
398 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
399 u
.probe_resp
.variable
);
401 size_t privsz
= wiphy
->bss_priv_size
;
403 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
404 (signal
< 0 || signal
> 100)))
407 if (WARN_ON(!mgmt
|| !wiphy
||
408 len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
411 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
415 memcpy(res
->pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
416 res
->pub
.channel
= channel
;
417 res
->pub
.signal
= signal
;
418 res
->pub
.tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
419 res
->pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
420 res
->pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
421 /* point to after the private area */
422 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
423 memcpy(res
->pub
.information_elements
, mgmt
->u
.probe_resp
.variable
, ielen
);
424 res
->pub
.len_information_elements
= ielen
;
426 kref_init(&res
->ref
);
428 overwrite
= ieee80211_is_probe_resp(mgmt
->frame_control
);
430 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, overwrite
);
434 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
435 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
437 /* cfg80211_bss_update gives us a referenced result */
440 EXPORT_SYMBOL(cfg80211_inform_bss_frame
);
442 void cfg80211_put_bss(struct cfg80211_bss
*pub
)
444 struct cfg80211_internal_bss
*bss
;
449 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
450 kref_put(&bss
->ref
, bss_release
);
452 EXPORT_SYMBOL(cfg80211_put_bss
);
454 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
456 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
457 struct cfg80211_internal_bss
*bss
;
462 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
464 spin_lock_bh(&dev
->bss_lock
);
466 list_del(&bss
->list
);
467 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
469 spin_unlock_bh(&dev
->bss_lock
);
471 kref_put(&bss
->ref
, bss_release
);
473 EXPORT_SYMBOL(cfg80211_unlink_bss
);
475 void cfg80211_hold_bss(struct cfg80211_bss
*pub
)
477 struct cfg80211_internal_bss
*bss
;
482 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
485 EXPORT_SYMBOL(cfg80211_hold_bss
);
487 void cfg80211_unhold_bss(struct cfg80211_bss
*pub
)
489 struct cfg80211_internal_bss
*bss
;
494 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
497 EXPORT_SYMBOL(cfg80211_unhold_bss
);
499 #ifdef CONFIG_WIRELESS_EXT
500 int cfg80211_wext_siwscan(struct net_device
*dev
,
501 struct iw_request_info
*info
,
502 union iwreq_data
*wrqu
, char *extra
)
504 struct cfg80211_registered_device
*rdev
;
506 struct iw_scan_req
*wreq
= NULL
;
507 struct cfg80211_scan_request
*creq
;
508 int i
, err
, n_channels
= 0;
509 enum ieee80211_band band
;
511 if (!netif_running(dev
))
514 rdev
= cfg80211_get_dev_from_ifindex(dev
->ifindex
);
517 return PTR_ERR(rdev
);
519 if (rdev
->scan_req
) {
524 wiphy
= &rdev
->wiphy
;
526 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
527 if (wiphy
->bands
[band
])
528 n_channels
+= wiphy
->bands
[band
]->n_channels
;
530 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
531 n_channels
* sizeof(void *),
539 creq
->ifidx
= dev
->ifindex
;
540 creq
->ssids
= (void *)(creq
+ 1);
541 creq
->channels
= (void *)(creq
->ssids
+ 1);
542 creq
->n_channels
= n_channels
;
547 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
549 if (!wiphy
->bands
[band
])
551 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
552 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
557 /* translate scan request */
558 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
)) {
559 wreq
= (struct iw_scan_req
*)extra
;
561 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
562 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
)
564 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
565 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
567 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
571 rdev
->scan_req
= creq
;
572 err
= rdev
->ops
->scan(wiphy
, dev
, creq
);
574 rdev
->scan_req
= NULL
;
578 cfg80211_put_dev(rdev
);
581 EXPORT_SYMBOL(cfg80211_wext_siwscan
);
583 static void ieee80211_scan_add_ies(struct iw_request_info
*info
,
584 struct cfg80211_bss
*bss
,
585 char **current_ev
, char *end_buf
)
587 u8
*pos
, *end
, *next
;
590 if (!bss
->information_elements
||
591 !bss
->len_information_elements
)
595 * If needed, fragment the IEs buffer (at IE boundaries) into short
596 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
598 pos
= bss
->information_elements
;
599 end
= pos
+ bss
->len_information_elements
;
601 while (end
- pos
> IW_GENERIC_IE_MAX
) {
602 next
= pos
+ 2 + pos
[1];
603 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
604 next
= next
+ 2 + next
[1];
606 memset(&iwe
, 0, sizeof(iwe
));
608 iwe
.u
.data
.length
= next
- pos
;
609 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
616 memset(&iwe
, 0, sizeof(iwe
));
618 iwe
.u
.data
.length
= end
- pos
;
619 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
624 static inline unsigned int elapsed_jiffies_msecs(unsigned long start
)
626 unsigned long end
= jiffies
;
629 return jiffies_to_msecs(end
- start
);
631 return jiffies_to_msecs(end
+ (MAX_JIFFY_OFFSET
- start
) + 1);
635 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
636 struct cfg80211_internal_bss
*bss
, char *current_ev
,
641 u8
*ie
= bss
->pub
.information_elements
;
642 int rem
= bss
->pub
.len_information_elements
, i
, sig
;
645 memset(&iwe
, 0, sizeof(iwe
));
647 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
648 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
649 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
652 memset(&iwe
, 0, sizeof(iwe
));
653 iwe
.cmd
= SIOCGIWFREQ
;
654 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
656 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
659 memset(&iwe
, 0, sizeof(iwe
));
660 iwe
.cmd
= SIOCGIWFREQ
;
661 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
663 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
666 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
667 memset(&iwe
, 0, sizeof(iwe
));
669 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
670 IW_QUAL_NOISE_INVALID
|
671 IW_QUAL_QUAL_UPDATED
;
672 switch (wiphy
->signal_type
) {
673 case CFG80211_SIGNAL_TYPE_MBM
:
674 sig
= bss
->pub
.signal
/ 100;
675 iwe
.u
.qual
.level
= sig
;
676 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
677 if (sig
< -110) /* rather bad */
679 else if (sig
> -40) /* perfect */
681 /* will give a range of 0 .. 70 */
682 iwe
.u
.qual
.qual
= sig
+ 110;
684 case CFG80211_SIGNAL_TYPE_UNSPEC
:
685 iwe
.u
.qual
.level
= bss
->pub
.signal
;
686 /* will give range 0 .. 100 */
687 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
693 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
694 &iwe
, IW_EV_QUAL_LEN
);
697 memset(&iwe
, 0, sizeof(iwe
));
698 iwe
.cmd
= SIOCGIWENCODE
;
699 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
700 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
702 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
703 iwe
.u
.data
.length
= 0;
704 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
714 memset(&iwe
, 0, sizeof(iwe
));
715 iwe
.cmd
= SIOCGIWESSID
;
716 iwe
.u
.data
.length
= ie
[1];
717 iwe
.u
.data
.flags
= 1;
718 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
721 case WLAN_EID_MESH_ID
:
722 memset(&iwe
, 0, sizeof(iwe
));
723 iwe
.cmd
= SIOCGIWESSID
;
724 iwe
.u
.data
.length
= ie
[1];
725 iwe
.u
.data
.flags
= 1;
726 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
729 case WLAN_EID_MESH_CONFIG
:
731 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
733 buf
= kmalloc(50, GFP_ATOMIC
);
737 memset(&iwe
, 0, sizeof(iwe
));
738 iwe
.cmd
= IWEVCUSTOM
;
739 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
740 iwe
.u
.data
.length
= strlen(buf
);
741 current_ev
= iwe_stream_add_point(info
, current_ev
,
744 sprintf(buf
, "Path Selection Protocol ID: "
745 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
747 iwe
.u
.data
.length
= strlen(buf
);
748 current_ev
= iwe_stream_add_point(info
, current_ev
,
751 sprintf(buf
, "Path Selection Metric ID: "
752 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
754 iwe
.u
.data
.length
= strlen(buf
);
755 current_ev
= iwe_stream_add_point(info
, current_ev
,
758 sprintf(buf
, "Congestion Control Mode ID: "
759 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
761 iwe
.u
.data
.length
= strlen(buf
);
762 current_ev
= iwe_stream_add_point(info
, current_ev
,
765 sprintf(buf
, "Channel Precedence: "
766 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
768 iwe
.u
.data
.length
= strlen(buf
);
769 current_ev
= iwe_stream_add_point(info
, current_ev
,
774 case WLAN_EID_SUPP_RATES
:
775 case WLAN_EID_EXT_SUPP_RATES
:
776 /* display all supported rates in readable format */
777 p
= current_ev
+ iwe_stream_lcp_len(info
);
779 memset(&iwe
, 0, sizeof(iwe
));
780 iwe
.cmd
= SIOCGIWRATE
;
781 /* Those two flags are ignored... */
782 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
784 for (i
= 0; i
< ie
[1]; i
++) {
785 iwe
.u
.bitrate
.value
=
786 ((ie
[i
+ 2] & 0x7f) * 500000);
787 p
= iwe_stream_add_value(info
, current_ev
, p
,
788 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
797 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
799 memset(&iwe
, 0, sizeof(iwe
));
800 iwe
.cmd
= SIOCGIWMODE
;
802 iwe
.u
.mode
= IW_MODE_MESH
;
803 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
804 iwe
.u
.mode
= IW_MODE_MASTER
;
806 iwe
.u
.mode
= IW_MODE_ADHOC
;
807 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
808 &iwe
, IW_EV_UINT_LEN
);
811 buf
= kmalloc(30, GFP_ATOMIC
);
813 memset(&iwe
, 0, sizeof(iwe
));
814 iwe
.cmd
= IWEVCUSTOM
;
815 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->pub
.tsf
));
816 iwe
.u
.data
.length
= strlen(buf
);
817 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
819 memset(&iwe
, 0, sizeof(iwe
));
820 iwe
.cmd
= IWEVCUSTOM
;
821 sprintf(buf
, " Last beacon: %ums ago",
822 elapsed_jiffies_msecs(bss
->ts
));
823 iwe
.u
.data
.length
= strlen(buf
);
824 current_ev
= iwe_stream_add_point(info
, current_ev
,
829 ieee80211_scan_add_ies(info
, &bss
->pub
, ¤t_ev
, end_buf
);
835 static int ieee80211_scan_results(struct cfg80211_registered_device
*dev
,
836 struct iw_request_info
*info
,
837 char *buf
, size_t len
)
839 char *current_ev
= buf
;
840 char *end_buf
= buf
+ len
;
841 struct cfg80211_internal_bss
*bss
;
843 spin_lock_bh(&dev
->bss_lock
);
844 cfg80211_bss_expire(dev
);
846 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
847 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
848 spin_unlock_bh(&dev
->bss_lock
);
851 current_ev
= ieee80211_bss(&dev
->wiphy
, info
, bss
,
852 current_ev
, end_buf
);
854 spin_unlock_bh(&dev
->bss_lock
);
855 return current_ev
- buf
;
859 int cfg80211_wext_giwscan(struct net_device
*dev
,
860 struct iw_request_info
*info
,
861 struct iw_point
*data
, char *extra
)
863 struct cfg80211_registered_device
*rdev
;
866 if (!netif_running(dev
))
869 rdev
= cfg80211_get_dev_from_ifindex(dev
->ifindex
);
872 return PTR_ERR(rdev
);
874 if (rdev
->scan_req
) {
879 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
887 cfg80211_put_dev(rdev
);
890 EXPORT_SYMBOL(cfg80211_wext_giwscan
);