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
);
32 * This must be before sending the other events!
33 * Otherwise, wpa_supplicant gets completely confused with
36 cfg80211_sme_scan_done(dev
);
39 nl80211_send_scan_aborted(wiphy_to_dev(request
->wiphy
), dev
);
41 nl80211_send_scan_done(wiphy_to_dev(request
->wiphy
), dev
);
43 wiphy_to_dev(request
->wiphy
)->scan_req
= NULL
;
45 #ifdef CONFIG_WIRELESS_EXT
47 memset(&wrqu
, 0, sizeof(wrqu
));
49 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
58 EXPORT_SYMBOL(cfg80211_scan_done
);
60 static void bss_release(struct kref
*ref
)
62 struct cfg80211_internal_bss
*bss
;
64 bss
= container_of(ref
, struct cfg80211_internal_bss
, ref
);
65 if (bss
->pub
.free_priv
)
66 bss
->pub
.free_priv(&bss
->pub
);
68 if (bss
->ies_allocated
)
69 kfree(bss
->pub
.information_elements
);
71 BUG_ON(atomic_read(&bss
->hold
));
76 /* must hold dev->bss_lock! */
77 void cfg80211_bss_age(struct cfg80211_registered_device
*dev
,
78 unsigned long age_secs
)
80 struct cfg80211_internal_bss
*bss
;
81 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
83 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
84 bss
->ts
-= age_jiffies
;
88 /* must hold dev->bss_lock! */
89 void cfg80211_bss_expire(struct cfg80211_registered_device
*dev
)
91 struct cfg80211_internal_bss
*bss
, *tmp
;
94 list_for_each_entry_safe(bss
, tmp
, &dev
->bss_list
, list
) {
95 if (atomic_read(&bss
->hold
))
97 if (!time_after(jiffies
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
))
100 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
101 kref_put(&bss
->ref
, bss_release
);
106 dev
->bss_generation
++;
109 static u8
*find_ie(u8 num
, u8
*ies
, size_t len
)
111 while (len
> 2 && ies
[0] != num
) {
117 if (len
< 2 + ies
[1])
122 static int cmp_ies(u8 num
, u8
*ies1
, size_t len1
, u8
*ies2
, size_t len2
)
124 const u8
*ie1
= find_ie(num
, ies1
, len1
);
125 const u8
*ie2
= find_ie(num
, ies2
, len2
);
133 r
= memcmp(ie1
+ 2, ie2
+ 2, min(ie1
[1], ie2
[1]));
134 if (r
== 0 && ie1
[1] != ie2
[1])
135 return ie2
[1] - ie1
[1];
139 static bool is_bss(struct cfg80211_bss
*a
,
141 const u8
*ssid
, size_t ssid_len
)
145 if (bssid
&& compare_ether_addr(a
->bssid
, bssid
))
151 ssidie
= find_ie(WLAN_EID_SSID
,
152 a
->information_elements
,
153 a
->len_information_elements
);
156 if (ssidie
[1] != ssid_len
)
158 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
161 static bool is_mesh(struct cfg80211_bss
*a
,
162 const u8
*meshid
, size_t meshidlen
,
167 if (!is_zero_ether_addr(a
->bssid
))
170 ie
= find_ie(WLAN_EID_MESH_ID
,
171 a
->information_elements
,
172 a
->len_information_elements
);
175 if (ie
[1] != meshidlen
)
177 if (memcmp(ie
+ 2, meshid
, meshidlen
))
180 ie
= find_ie(WLAN_EID_MESH_CONFIG
,
181 a
->information_elements
,
182 a
->len_information_elements
);
183 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
187 * Ignore mesh capability (last two bytes of the IE) when
188 * comparing since that may differ between stations taking
189 * part in the same mesh.
191 return memcmp(ie
+ 2, meshcfg
, IEEE80211_MESH_CONFIG_LEN
- 2) == 0;
194 static int cmp_bss(struct cfg80211_bss
*a
,
195 struct cfg80211_bss
*b
)
199 if (a
->channel
!= b
->channel
)
200 return b
->channel
->center_freq
- a
->channel
->center_freq
;
202 r
= memcmp(a
->bssid
, b
->bssid
, ETH_ALEN
);
206 if (is_zero_ether_addr(a
->bssid
)) {
207 r
= cmp_ies(WLAN_EID_MESH_ID
,
208 a
->information_elements
,
209 a
->len_information_elements
,
210 b
->information_elements
,
211 b
->len_information_elements
);
214 return cmp_ies(WLAN_EID_MESH_CONFIG
,
215 a
->information_elements
,
216 a
->len_information_elements
,
217 b
->information_elements
,
218 b
->len_information_elements
);
221 return cmp_ies(WLAN_EID_SSID
,
222 a
->information_elements
,
223 a
->len_information_elements
,
224 b
->information_elements
,
225 b
->len_information_elements
);
228 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
229 struct ieee80211_channel
*channel
,
231 const u8
*ssid
, size_t ssid_len
,
232 u16 capa_mask
, u16 capa_val
)
234 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
235 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
237 spin_lock_bh(&dev
->bss_lock
);
239 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
240 if ((bss
->pub
.capability
& capa_mask
) != capa_val
)
242 if (channel
&& bss
->pub
.channel
!= channel
)
244 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
251 spin_unlock_bh(&dev
->bss_lock
);
256 EXPORT_SYMBOL(cfg80211_get_bss
);
258 struct cfg80211_bss
*cfg80211_get_mesh(struct wiphy
*wiphy
,
259 struct ieee80211_channel
*channel
,
260 const u8
*meshid
, size_t meshidlen
,
263 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
264 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
266 spin_lock_bh(&dev
->bss_lock
);
268 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
269 if (channel
&& bss
->pub
.channel
!= channel
)
271 if (is_mesh(&bss
->pub
, meshid
, meshidlen
, meshcfg
)) {
278 spin_unlock_bh(&dev
->bss_lock
);
283 EXPORT_SYMBOL(cfg80211_get_mesh
);
286 static void rb_insert_bss(struct cfg80211_registered_device
*dev
,
287 struct cfg80211_internal_bss
*bss
)
289 struct rb_node
**p
= &dev
->bss_tree
.rb_node
;
290 struct rb_node
*parent
= NULL
;
291 struct cfg80211_internal_bss
*tbss
;
296 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
298 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
);
301 /* will sort of leak this BSS */
311 rb_link_node(&bss
->rbn
, parent
, p
);
312 rb_insert_color(&bss
->rbn
, &dev
->bss_tree
);
315 static struct cfg80211_internal_bss
*
316 rb_find_bss(struct cfg80211_registered_device
*dev
,
317 struct cfg80211_internal_bss
*res
)
319 struct rb_node
*n
= dev
->bss_tree
.rb_node
;
320 struct cfg80211_internal_bss
*bss
;
324 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
325 r
= cmp_bss(&res
->pub
, &bss
->pub
);
338 static struct cfg80211_internal_bss
*
339 cfg80211_bss_update(struct cfg80211_registered_device
*dev
,
340 struct cfg80211_internal_bss
*res
,
343 struct cfg80211_internal_bss
*found
= NULL
;
344 const u8
*meshid
, *meshcfg
;
347 * The reference to "res" is donated to this function.
350 if (WARN_ON(!res
->pub
.channel
)) {
351 kref_put(&res
->ref
, bss_release
);
357 if (is_zero_ether_addr(res
->pub
.bssid
)) {
358 /* must be mesh, verify */
359 meshid
= find_ie(WLAN_EID_MESH_ID
, res
->pub
.information_elements
,
360 res
->pub
.len_information_elements
);
361 meshcfg
= find_ie(WLAN_EID_MESH_CONFIG
,
362 res
->pub
.information_elements
,
363 res
->pub
.len_information_elements
);
364 if (!meshid
|| !meshcfg
||
365 meshcfg
[1] != IEEE80211_MESH_CONFIG_LEN
) {
367 kref_put(&res
->ref
, bss_release
);
372 spin_lock_bh(&dev
->bss_lock
);
374 found
= rb_find_bss(dev
, res
);
377 found
->pub
.beacon_interval
= res
->pub
.beacon_interval
;
378 found
->pub
.tsf
= res
->pub
.tsf
;
379 found
->pub
.signal
= res
->pub
.signal
;
380 found
->pub
.capability
= res
->pub
.capability
;
385 size_t used
= dev
->wiphy
.bss_priv_size
+ sizeof(*res
);
386 size_t ielen
= res
->pub
.len_information_elements
;
388 if (!found
->ies_allocated
&& ksize(found
) >= used
+ ielen
) {
389 memcpy(found
->pub
.information_elements
,
390 res
->pub
.information_elements
, ielen
);
391 found
->pub
.len_information_elements
= ielen
;
393 u8
*ies
= found
->pub
.information_elements
;
395 if (found
->ies_allocated
)
396 ies
= krealloc(ies
, ielen
, GFP_ATOMIC
);
398 ies
= kmalloc(ielen
, GFP_ATOMIC
);
401 memcpy(ies
, res
->pub
.information_elements
, ielen
);
402 found
->ies_allocated
= true;
403 found
->pub
.information_elements
= ies
;
404 found
->pub
.len_information_elements
= ielen
;
409 kref_put(&res
->ref
, bss_release
);
411 /* this "consumes" the reference */
412 list_add_tail(&res
->list
, &dev
->bss_list
);
413 rb_insert_bss(dev
, res
);
417 dev
->bss_generation
++;
418 spin_unlock_bh(&dev
->bss_lock
);
420 kref_get(&found
->ref
);
425 cfg80211_inform_bss(struct wiphy
*wiphy
,
426 struct ieee80211_channel
*channel
,
428 u64 timestamp
, u16 capability
, u16 beacon_interval
,
429 const u8
*ie
, size_t ielen
,
430 s32 signal
, gfp_t gfp
)
432 struct cfg80211_internal_bss
*res
;
438 privsz
= wiphy
->bss_priv_size
;
440 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
441 (signal
< 0 || signal
> 100)))
444 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
448 memcpy(res
->pub
.bssid
, bssid
, ETH_ALEN
);
449 res
->pub
.channel
= channel
;
450 res
->pub
.signal
= signal
;
451 res
->pub
.tsf
= timestamp
;
452 res
->pub
.beacon_interval
= beacon_interval
;
453 res
->pub
.capability
= capability
;
454 /* point to after the private area */
455 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
456 memcpy(res
->pub
.information_elements
, ie
, ielen
);
457 res
->pub
.len_information_elements
= ielen
;
459 kref_init(&res
->ref
);
461 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, 0);
465 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
466 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
468 /* cfg80211_bss_update gives us a referenced result */
471 EXPORT_SYMBOL(cfg80211_inform_bss
);
473 struct cfg80211_bss
*
474 cfg80211_inform_bss_frame(struct wiphy
*wiphy
,
475 struct ieee80211_channel
*channel
,
476 struct ieee80211_mgmt
*mgmt
, size_t len
,
477 s32 signal
, gfp_t gfp
)
479 struct cfg80211_internal_bss
*res
;
480 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
481 u
.probe_resp
.variable
);
483 size_t privsz
= wiphy
->bss_priv_size
;
485 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
486 (signal
< 0 || signal
> 100)))
489 if (WARN_ON(!mgmt
|| !wiphy
||
490 len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
493 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
497 memcpy(res
->pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
498 res
->pub
.channel
= channel
;
499 res
->pub
.signal
= signal
;
500 res
->pub
.tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
501 res
->pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
502 res
->pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
503 /* point to after the private area */
504 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
505 memcpy(res
->pub
.information_elements
, mgmt
->u
.probe_resp
.variable
, ielen
);
506 res
->pub
.len_information_elements
= ielen
;
508 kref_init(&res
->ref
);
510 overwrite
= ieee80211_is_probe_resp(mgmt
->frame_control
);
512 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, overwrite
);
516 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
517 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
519 /* cfg80211_bss_update gives us a referenced result */
522 EXPORT_SYMBOL(cfg80211_inform_bss_frame
);
524 void cfg80211_put_bss(struct cfg80211_bss
*pub
)
526 struct cfg80211_internal_bss
*bss
;
531 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
532 kref_put(&bss
->ref
, bss_release
);
534 EXPORT_SYMBOL(cfg80211_put_bss
);
536 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
538 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
539 struct cfg80211_internal_bss
*bss
;
544 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
546 spin_lock_bh(&dev
->bss_lock
);
548 list_del(&bss
->list
);
549 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
551 spin_unlock_bh(&dev
->bss_lock
);
553 kref_put(&bss
->ref
, bss_release
);
555 EXPORT_SYMBOL(cfg80211_unlink_bss
);
557 #ifdef CONFIG_WIRELESS_EXT
558 int cfg80211_wext_siwscan(struct net_device
*dev
,
559 struct iw_request_info
*info
,
560 union iwreq_data
*wrqu
, char *extra
)
562 struct cfg80211_registered_device
*rdev
;
564 struct iw_scan_req
*wreq
= NULL
;
565 struct cfg80211_scan_request
*creq
;
566 int i
, err
, n_channels
= 0;
567 enum ieee80211_band band
;
569 if (!netif_running(dev
))
572 rdev
= cfg80211_get_dev_from_ifindex(dev
->ifindex
);
575 return PTR_ERR(rdev
);
577 if (rdev
->scan_req
) {
582 wiphy
= &rdev
->wiphy
;
584 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
585 if (wiphy
->bands
[band
])
586 n_channels
+= wiphy
->bands
[band
]->n_channels
;
588 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
589 n_channels
* sizeof(void *),
597 creq
->ifidx
= dev
->ifindex
;
598 creq
->ssids
= (void *)(creq
+ 1);
599 creq
->channels
= (void *)(creq
->ssids
+ 1);
600 creq
->n_channels
= n_channels
;
605 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
607 if (!wiphy
->bands
[band
])
609 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
610 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
615 /* translate scan request */
616 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
)) {
617 wreq
= (struct iw_scan_req
*)extra
;
619 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
620 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
)
622 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
623 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
625 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
629 rdev
->scan_req
= creq
;
630 err
= rdev
->ops
->scan(wiphy
, dev
, creq
);
632 rdev
->scan_req
= NULL
;
635 nl80211_send_scan_start(rdev
, dev
);
637 cfg80211_unlock_rdev(rdev
);
640 EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan
);
642 static void ieee80211_scan_add_ies(struct iw_request_info
*info
,
643 struct cfg80211_bss
*bss
,
644 char **current_ev
, char *end_buf
)
646 u8
*pos
, *end
, *next
;
649 if (!bss
->information_elements
||
650 !bss
->len_information_elements
)
654 * If needed, fragment the IEs buffer (at IE boundaries) into short
655 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
657 pos
= bss
->information_elements
;
658 end
= pos
+ bss
->len_information_elements
;
660 while (end
- pos
> IW_GENERIC_IE_MAX
) {
661 next
= pos
+ 2 + pos
[1];
662 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
663 next
= next
+ 2 + next
[1];
665 memset(&iwe
, 0, sizeof(iwe
));
667 iwe
.u
.data
.length
= next
- pos
;
668 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
675 memset(&iwe
, 0, sizeof(iwe
));
677 iwe
.u
.data
.length
= end
- pos
;
678 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
683 static inline unsigned int elapsed_jiffies_msecs(unsigned long start
)
685 unsigned long end
= jiffies
;
688 return jiffies_to_msecs(end
- start
);
690 return jiffies_to_msecs(end
+ (MAX_JIFFY_OFFSET
- start
) + 1);
694 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
695 struct cfg80211_internal_bss
*bss
, char *current_ev
,
700 u8
*ie
= bss
->pub
.information_elements
;
701 int rem
= bss
->pub
.len_information_elements
, i
, sig
;
704 memset(&iwe
, 0, sizeof(iwe
));
706 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
707 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
708 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
711 memset(&iwe
, 0, sizeof(iwe
));
712 iwe
.cmd
= SIOCGIWFREQ
;
713 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
715 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
718 memset(&iwe
, 0, sizeof(iwe
));
719 iwe
.cmd
= SIOCGIWFREQ
;
720 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
722 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
725 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
726 memset(&iwe
, 0, sizeof(iwe
));
728 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
729 IW_QUAL_NOISE_INVALID
|
730 IW_QUAL_QUAL_UPDATED
;
731 switch (wiphy
->signal_type
) {
732 case CFG80211_SIGNAL_TYPE_MBM
:
733 sig
= bss
->pub
.signal
/ 100;
734 iwe
.u
.qual
.level
= sig
;
735 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
736 if (sig
< -110) /* rather bad */
738 else if (sig
> -40) /* perfect */
740 /* will give a range of 0 .. 70 */
741 iwe
.u
.qual
.qual
= sig
+ 110;
743 case CFG80211_SIGNAL_TYPE_UNSPEC
:
744 iwe
.u
.qual
.level
= bss
->pub
.signal
;
745 /* will give range 0 .. 100 */
746 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
752 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
753 &iwe
, IW_EV_QUAL_LEN
);
756 memset(&iwe
, 0, sizeof(iwe
));
757 iwe
.cmd
= SIOCGIWENCODE
;
758 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
759 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
761 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
762 iwe
.u
.data
.length
= 0;
763 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
773 memset(&iwe
, 0, sizeof(iwe
));
774 iwe
.cmd
= SIOCGIWESSID
;
775 iwe
.u
.data
.length
= ie
[1];
776 iwe
.u
.data
.flags
= 1;
777 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
780 case WLAN_EID_MESH_ID
:
781 memset(&iwe
, 0, sizeof(iwe
));
782 iwe
.cmd
= SIOCGIWESSID
;
783 iwe
.u
.data
.length
= ie
[1];
784 iwe
.u
.data
.flags
= 1;
785 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
788 case WLAN_EID_MESH_CONFIG
:
790 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
792 buf
= kmalloc(50, GFP_ATOMIC
);
796 memset(&iwe
, 0, sizeof(iwe
));
797 iwe
.cmd
= IWEVCUSTOM
;
798 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
799 iwe
.u
.data
.length
= strlen(buf
);
800 current_ev
= iwe_stream_add_point(info
, current_ev
,
803 sprintf(buf
, "Path Selection Protocol ID: "
804 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
806 iwe
.u
.data
.length
= strlen(buf
);
807 current_ev
= iwe_stream_add_point(info
, current_ev
,
810 sprintf(buf
, "Path Selection Metric ID: "
811 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
813 iwe
.u
.data
.length
= strlen(buf
);
814 current_ev
= iwe_stream_add_point(info
, current_ev
,
817 sprintf(buf
, "Congestion Control Mode ID: "
818 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
820 iwe
.u
.data
.length
= strlen(buf
);
821 current_ev
= iwe_stream_add_point(info
, current_ev
,
824 sprintf(buf
, "Channel Precedence: "
825 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
827 iwe
.u
.data
.length
= strlen(buf
);
828 current_ev
= iwe_stream_add_point(info
, current_ev
,
833 case WLAN_EID_SUPP_RATES
:
834 case WLAN_EID_EXT_SUPP_RATES
:
835 /* display all supported rates in readable format */
836 p
= current_ev
+ iwe_stream_lcp_len(info
);
838 memset(&iwe
, 0, sizeof(iwe
));
839 iwe
.cmd
= SIOCGIWRATE
;
840 /* Those two flags are ignored... */
841 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
843 for (i
= 0; i
< ie
[1]; i
++) {
844 iwe
.u
.bitrate
.value
=
845 ((ie
[i
+ 2] & 0x7f) * 500000);
846 p
= iwe_stream_add_value(info
, current_ev
, p
,
847 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
856 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
858 memset(&iwe
, 0, sizeof(iwe
));
859 iwe
.cmd
= SIOCGIWMODE
;
861 iwe
.u
.mode
= IW_MODE_MESH
;
862 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
863 iwe
.u
.mode
= IW_MODE_MASTER
;
865 iwe
.u
.mode
= IW_MODE_ADHOC
;
866 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
867 &iwe
, IW_EV_UINT_LEN
);
870 buf
= kmalloc(30, GFP_ATOMIC
);
872 memset(&iwe
, 0, sizeof(iwe
));
873 iwe
.cmd
= IWEVCUSTOM
;
874 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->pub
.tsf
));
875 iwe
.u
.data
.length
= strlen(buf
);
876 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
878 memset(&iwe
, 0, sizeof(iwe
));
879 iwe
.cmd
= IWEVCUSTOM
;
880 sprintf(buf
, " Last beacon: %ums ago",
881 elapsed_jiffies_msecs(bss
->ts
));
882 iwe
.u
.data
.length
= strlen(buf
);
883 current_ev
= iwe_stream_add_point(info
, current_ev
,
888 ieee80211_scan_add_ies(info
, &bss
->pub
, ¤t_ev
, end_buf
);
894 static int ieee80211_scan_results(struct cfg80211_registered_device
*dev
,
895 struct iw_request_info
*info
,
896 char *buf
, size_t len
)
898 char *current_ev
= buf
;
899 char *end_buf
= buf
+ len
;
900 struct cfg80211_internal_bss
*bss
;
902 spin_lock_bh(&dev
->bss_lock
);
903 cfg80211_bss_expire(dev
);
905 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
906 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
907 spin_unlock_bh(&dev
->bss_lock
);
910 current_ev
= ieee80211_bss(&dev
->wiphy
, info
, bss
,
911 current_ev
, end_buf
);
913 spin_unlock_bh(&dev
->bss_lock
);
914 return current_ev
- buf
;
918 int cfg80211_wext_giwscan(struct net_device
*dev
,
919 struct iw_request_info
*info
,
920 struct iw_point
*data
, char *extra
)
922 struct cfg80211_registered_device
*rdev
;
925 if (!netif_running(dev
))
928 rdev
= cfg80211_get_dev_from_ifindex(dev
->ifindex
);
931 return PTR_ERR(rdev
);
933 if (rdev
->scan_req
) {
938 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
946 cfg80211_unlock_rdev(rdev
);
949 EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan
);