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 work_struct
*wk
)
23 struct cfg80211_registered_device
*rdev
;
24 struct cfg80211_scan_request
*request
;
25 struct net_device
*dev
;
26 #ifdef CONFIG_WIRELESS_EXT
27 union iwreq_data wrqu
;
30 rdev
= container_of(wk
, struct cfg80211_registered_device
,
33 mutex_lock(&rdev
->mtx
);
34 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(wiphy_to_dev(request
->wiphy
), dev
);
48 nl80211_send_scan_done(wiphy_to_dev(request
->wiphy
), 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 cfg80211_unlock_rdev(rdev
);
61 wiphy_to_dev(request
->wiphy
)->scan_req
= NULL
;
65 void cfg80211_scan_done(struct cfg80211_scan_request
*request
, bool aborted
)
67 WARN_ON(request
!= wiphy_to_dev(request
->wiphy
)->scan_req
);
69 request
->aborted
= aborted
;
70 schedule_work(&wiphy_to_dev(request
->wiphy
)->scan_done_wk
);
72 EXPORT_SYMBOL(cfg80211_scan_done
);
74 static void bss_release(struct kref
*ref
)
76 struct cfg80211_internal_bss
*bss
;
78 bss
= container_of(ref
, struct cfg80211_internal_bss
, ref
);
79 if (bss
->pub
.free_priv
)
80 bss
->pub
.free_priv(&bss
->pub
);
82 if (bss
->ies_allocated
)
83 kfree(bss
->pub
.information_elements
);
85 BUG_ON(atomic_read(&bss
->hold
));
90 /* must hold dev->bss_lock! */
91 void cfg80211_bss_age(struct cfg80211_registered_device
*dev
,
92 unsigned long age_secs
)
94 struct cfg80211_internal_bss
*bss
;
95 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
97 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
98 bss
->ts
-= age_jiffies
;
102 /* must hold dev->bss_lock! */
103 void cfg80211_bss_expire(struct cfg80211_registered_device
*dev
)
105 struct cfg80211_internal_bss
*bss
, *tmp
;
106 bool expired
= false;
108 list_for_each_entry_safe(bss
, tmp
, &dev
->bss_list
, list
) {
109 if (atomic_read(&bss
->hold
))
111 if (!time_after(jiffies
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
))
113 list_del(&bss
->list
);
114 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
115 kref_put(&bss
->ref
, bss_release
);
120 dev
->bss_generation
++;
123 static u8
*find_ie(u8 num
, u8
*ies
, size_t len
)
125 while (len
> 2 && ies
[0] != num
) {
131 if (len
< 2 + ies
[1])
136 static int cmp_ies(u8 num
, u8
*ies1
, size_t len1
, u8
*ies2
, size_t len2
)
138 const u8
*ie1
= find_ie(num
, ies1
, len1
);
139 const u8
*ie2
= find_ie(num
, ies2
, len2
);
147 r
= memcmp(ie1
+ 2, ie2
+ 2, min(ie1
[1], ie2
[1]));
148 if (r
== 0 && ie1
[1] != ie2
[1])
149 return ie2
[1] - ie1
[1];
153 static bool is_bss(struct cfg80211_bss
*a
,
155 const u8
*ssid
, size_t ssid_len
)
159 if (bssid
&& compare_ether_addr(a
->bssid
, bssid
))
165 ssidie
= find_ie(WLAN_EID_SSID
,
166 a
->information_elements
,
167 a
->len_information_elements
);
170 if (ssidie
[1] != ssid_len
)
172 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
175 static bool is_mesh(struct cfg80211_bss
*a
,
176 const u8
*meshid
, size_t meshidlen
,
181 if (!is_zero_ether_addr(a
->bssid
))
184 ie
= find_ie(WLAN_EID_MESH_ID
,
185 a
->information_elements
,
186 a
->len_information_elements
);
189 if (ie
[1] != meshidlen
)
191 if (memcmp(ie
+ 2, meshid
, meshidlen
))
194 ie
= find_ie(WLAN_EID_MESH_CONFIG
,
195 a
->information_elements
,
196 a
->len_information_elements
);
199 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
203 * Ignore mesh capability (last two bytes of the IE) when
204 * comparing since that may differ between stations taking
205 * part in the same mesh.
207 return memcmp(ie
+ 2, meshcfg
, IEEE80211_MESH_CONFIG_LEN
- 2) == 0;
210 static int cmp_bss(struct cfg80211_bss
*a
,
211 struct cfg80211_bss
*b
)
215 if (a
->channel
!= b
->channel
)
216 return b
->channel
->center_freq
- a
->channel
->center_freq
;
218 r
= memcmp(a
->bssid
, b
->bssid
, ETH_ALEN
);
222 if (is_zero_ether_addr(a
->bssid
)) {
223 r
= cmp_ies(WLAN_EID_MESH_ID
,
224 a
->information_elements
,
225 a
->len_information_elements
,
226 b
->information_elements
,
227 b
->len_information_elements
);
230 return cmp_ies(WLAN_EID_MESH_CONFIG
,
231 a
->information_elements
,
232 a
->len_information_elements
,
233 b
->information_elements
,
234 b
->len_information_elements
);
237 return cmp_ies(WLAN_EID_SSID
,
238 a
->information_elements
,
239 a
->len_information_elements
,
240 b
->information_elements
,
241 b
->len_information_elements
);
244 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
245 struct ieee80211_channel
*channel
,
247 const u8
*ssid
, size_t ssid_len
,
248 u16 capa_mask
, u16 capa_val
)
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 ((bss
->pub
.capability
& capa_mask
) != capa_val
)
258 if (channel
&& bss
->pub
.channel
!= channel
)
260 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
267 spin_unlock_bh(&dev
->bss_lock
);
272 EXPORT_SYMBOL(cfg80211_get_bss
);
274 struct cfg80211_bss
*cfg80211_get_mesh(struct wiphy
*wiphy
,
275 struct ieee80211_channel
*channel
,
276 const u8
*meshid
, size_t meshidlen
,
279 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
280 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
282 spin_lock_bh(&dev
->bss_lock
);
284 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
285 if (channel
&& bss
->pub
.channel
!= channel
)
287 if (is_mesh(&bss
->pub
, meshid
, meshidlen
, meshcfg
)) {
294 spin_unlock_bh(&dev
->bss_lock
);
299 EXPORT_SYMBOL(cfg80211_get_mesh
);
302 static void rb_insert_bss(struct cfg80211_registered_device
*dev
,
303 struct cfg80211_internal_bss
*bss
)
305 struct rb_node
**p
= &dev
->bss_tree
.rb_node
;
306 struct rb_node
*parent
= NULL
;
307 struct cfg80211_internal_bss
*tbss
;
312 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
314 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
);
317 /* will sort of leak this BSS */
327 rb_link_node(&bss
->rbn
, parent
, p
);
328 rb_insert_color(&bss
->rbn
, &dev
->bss_tree
);
331 static struct cfg80211_internal_bss
*
332 rb_find_bss(struct cfg80211_registered_device
*dev
,
333 struct cfg80211_internal_bss
*res
)
335 struct rb_node
*n
= dev
->bss_tree
.rb_node
;
336 struct cfg80211_internal_bss
*bss
;
340 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
341 r
= cmp_bss(&res
->pub
, &bss
->pub
);
354 static struct cfg80211_internal_bss
*
355 cfg80211_bss_update(struct cfg80211_registered_device
*dev
,
356 struct cfg80211_internal_bss
*res
,
359 struct cfg80211_internal_bss
*found
= NULL
;
360 const u8
*meshid
, *meshcfg
;
363 * The reference to "res" is donated to this function.
366 if (WARN_ON(!res
->pub
.channel
)) {
367 kref_put(&res
->ref
, bss_release
);
373 if (is_zero_ether_addr(res
->pub
.bssid
)) {
374 /* must be mesh, verify */
375 meshid
= find_ie(WLAN_EID_MESH_ID
, res
->pub
.information_elements
,
376 res
->pub
.len_information_elements
);
377 meshcfg
= find_ie(WLAN_EID_MESH_CONFIG
,
378 res
->pub
.information_elements
,
379 res
->pub
.len_information_elements
);
380 if (!meshid
|| !meshcfg
||
381 meshcfg
[1] != IEEE80211_MESH_CONFIG_LEN
) {
383 kref_put(&res
->ref
, bss_release
);
388 spin_lock_bh(&dev
->bss_lock
);
390 found
= rb_find_bss(dev
, res
);
393 found
->pub
.beacon_interval
= res
->pub
.beacon_interval
;
394 found
->pub
.tsf
= res
->pub
.tsf
;
395 found
->pub
.signal
= res
->pub
.signal
;
396 found
->pub
.capability
= res
->pub
.capability
;
401 size_t used
= dev
->wiphy
.bss_priv_size
+ sizeof(*res
);
402 size_t ielen
= res
->pub
.len_information_elements
;
404 if (!found
->ies_allocated
&& ksize(found
) >= used
+ ielen
) {
405 memcpy(found
->pub
.information_elements
,
406 res
->pub
.information_elements
, ielen
);
407 found
->pub
.len_information_elements
= ielen
;
409 u8
*ies
= found
->pub
.information_elements
;
411 if (found
->ies_allocated
)
412 ies
= krealloc(ies
, ielen
, GFP_ATOMIC
);
414 ies
= kmalloc(ielen
, GFP_ATOMIC
);
417 memcpy(ies
, res
->pub
.information_elements
, ielen
);
418 found
->ies_allocated
= true;
419 found
->pub
.information_elements
= ies
;
420 found
->pub
.len_information_elements
= ielen
;
425 kref_put(&res
->ref
, bss_release
);
427 /* this "consumes" the reference */
428 list_add_tail(&res
->list
, &dev
->bss_list
);
429 rb_insert_bss(dev
, res
);
433 dev
->bss_generation
++;
434 spin_unlock_bh(&dev
->bss_lock
);
436 kref_get(&found
->ref
);
441 cfg80211_inform_bss(struct wiphy
*wiphy
,
442 struct ieee80211_channel
*channel
,
444 u64 timestamp
, u16 capability
, u16 beacon_interval
,
445 const u8
*ie
, size_t ielen
,
446 s32 signal
, gfp_t gfp
)
448 struct cfg80211_internal_bss
*res
;
454 privsz
= wiphy
->bss_priv_size
;
456 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
457 (signal
< 0 || signal
> 100)))
460 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
464 memcpy(res
->pub
.bssid
, bssid
, ETH_ALEN
);
465 res
->pub
.channel
= channel
;
466 res
->pub
.signal
= signal
;
467 res
->pub
.tsf
= timestamp
;
468 res
->pub
.beacon_interval
= beacon_interval
;
469 res
->pub
.capability
= capability
;
470 /* point to after the private area */
471 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
472 memcpy(res
->pub
.information_elements
, ie
, ielen
);
473 res
->pub
.len_information_elements
= ielen
;
475 kref_init(&res
->ref
);
477 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, 0);
481 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
482 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
484 /* cfg80211_bss_update gives us a referenced result */
487 EXPORT_SYMBOL(cfg80211_inform_bss
);
489 struct cfg80211_bss
*
490 cfg80211_inform_bss_frame(struct wiphy
*wiphy
,
491 struct ieee80211_channel
*channel
,
492 struct ieee80211_mgmt
*mgmt
, size_t len
,
493 s32 signal
, gfp_t gfp
)
495 struct cfg80211_internal_bss
*res
;
496 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
497 u
.probe_resp
.variable
);
499 size_t privsz
= wiphy
->bss_priv_size
;
501 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
502 (signal
< 0 || signal
> 100)))
505 if (WARN_ON(!mgmt
|| !wiphy
||
506 len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
509 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
513 memcpy(res
->pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
514 res
->pub
.channel
= channel
;
515 res
->pub
.signal
= signal
;
516 res
->pub
.tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
517 res
->pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
518 res
->pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
519 /* point to after the private area */
520 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
521 memcpy(res
->pub
.information_elements
, mgmt
->u
.probe_resp
.variable
, ielen
);
522 res
->pub
.len_information_elements
= ielen
;
524 kref_init(&res
->ref
);
526 overwrite
= ieee80211_is_probe_resp(mgmt
->frame_control
);
528 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, overwrite
);
532 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
533 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
535 /* cfg80211_bss_update gives us a referenced result */
538 EXPORT_SYMBOL(cfg80211_inform_bss_frame
);
540 void cfg80211_put_bss(struct cfg80211_bss
*pub
)
542 struct cfg80211_internal_bss
*bss
;
547 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
548 kref_put(&bss
->ref
, bss_release
);
550 EXPORT_SYMBOL(cfg80211_put_bss
);
552 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
554 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
555 struct cfg80211_internal_bss
*bss
;
560 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
562 spin_lock_bh(&dev
->bss_lock
);
564 list_del(&bss
->list
);
565 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
567 spin_unlock_bh(&dev
->bss_lock
);
569 kref_put(&bss
->ref
, bss_release
);
571 EXPORT_SYMBOL(cfg80211_unlink_bss
);
573 #ifdef CONFIG_WIRELESS_EXT
574 int cfg80211_wext_siwscan(struct net_device
*dev
,
575 struct iw_request_info
*info
,
576 union iwreq_data
*wrqu
, char *extra
)
578 struct cfg80211_registered_device
*rdev
;
580 struct iw_scan_req
*wreq
= NULL
;
581 struct cfg80211_scan_request
*creq
;
582 int i
, err
, n_channels
= 0;
583 enum ieee80211_band band
;
585 if (!netif_running(dev
))
588 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
591 return PTR_ERR(rdev
);
593 if (rdev
->scan_req
) {
598 wiphy
= &rdev
->wiphy
;
600 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
601 if (wiphy
->bands
[band
])
602 n_channels
+= wiphy
->bands
[band
]->n_channels
;
604 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
605 n_channels
* sizeof(void *),
614 creq
->ssids
= (void *)(creq
+ 1);
615 creq
->channels
= (void *)(creq
->ssids
+ 1);
616 creq
->n_channels
= n_channels
;
621 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
623 if (!wiphy
->bands
[band
])
625 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
626 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
631 /* translate scan request */
632 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
)) {
633 wreq
= (struct iw_scan_req
*)extra
;
635 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
636 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
)
638 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
639 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
641 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
645 rdev
->scan_req
= creq
;
646 err
= rdev
->ops
->scan(wiphy
, dev
, creq
);
648 rdev
->scan_req
= NULL
;
651 nl80211_send_scan_start(rdev
, dev
);
655 cfg80211_unlock_rdev(rdev
);
658 EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan
);
660 static void ieee80211_scan_add_ies(struct iw_request_info
*info
,
661 struct cfg80211_bss
*bss
,
662 char **current_ev
, char *end_buf
)
664 u8
*pos
, *end
, *next
;
667 if (!bss
->information_elements
||
668 !bss
->len_information_elements
)
672 * If needed, fragment the IEs buffer (at IE boundaries) into short
673 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
675 pos
= bss
->information_elements
;
676 end
= pos
+ bss
->len_information_elements
;
678 while (end
- pos
> IW_GENERIC_IE_MAX
) {
679 next
= pos
+ 2 + pos
[1];
680 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
681 next
= next
+ 2 + next
[1];
683 memset(&iwe
, 0, sizeof(iwe
));
685 iwe
.u
.data
.length
= next
- pos
;
686 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
693 memset(&iwe
, 0, sizeof(iwe
));
695 iwe
.u
.data
.length
= end
- pos
;
696 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
701 static inline unsigned int elapsed_jiffies_msecs(unsigned long start
)
703 unsigned long end
= jiffies
;
706 return jiffies_to_msecs(end
- start
);
708 return jiffies_to_msecs(end
+ (MAX_JIFFY_OFFSET
- start
) + 1);
712 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
713 struct cfg80211_internal_bss
*bss
, char *current_ev
,
718 u8
*ie
= bss
->pub
.information_elements
;
719 int rem
= bss
->pub
.len_information_elements
, i
, sig
;
722 memset(&iwe
, 0, sizeof(iwe
));
724 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
725 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
726 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
729 memset(&iwe
, 0, sizeof(iwe
));
730 iwe
.cmd
= SIOCGIWFREQ
;
731 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
733 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
736 memset(&iwe
, 0, sizeof(iwe
));
737 iwe
.cmd
= SIOCGIWFREQ
;
738 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
740 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
743 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
744 memset(&iwe
, 0, sizeof(iwe
));
746 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
747 IW_QUAL_NOISE_INVALID
|
748 IW_QUAL_QUAL_UPDATED
;
749 switch (wiphy
->signal_type
) {
750 case CFG80211_SIGNAL_TYPE_MBM
:
751 sig
= bss
->pub
.signal
/ 100;
752 iwe
.u
.qual
.level
= sig
;
753 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
754 if (sig
< -110) /* rather bad */
756 else if (sig
> -40) /* perfect */
758 /* will give a range of 0 .. 70 */
759 iwe
.u
.qual
.qual
= sig
+ 110;
761 case CFG80211_SIGNAL_TYPE_UNSPEC
:
762 iwe
.u
.qual
.level
= bss
->pub
.signal
;
763 /* will give range 0 .. 100 */
764 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
770 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
771 &iwe
, IW_EV_QUAL_LEN
);
774 memset(&iwe
, 0, sizeof(iwe
));
775 iwe
.cmd
= SIOCGIWENCODE
;
776 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
777 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
779 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
780 iwe
.u
.data
.length
= 0;
781 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
791 memset(&iwe
, 0, sizeof(iwe
));
792 iwe
.cmd
= SIOCGIWESSID
;
793 iwe
.u
.data
.length
= ie
[1];
794 iwe
.u
.data
.flags
= 1;
795 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
798 case WLAN_EID_MESH_ID
:
799 memset(&iwe
, 0, sizeof(iwe
));
800 iwe
.cmd
= SIOCGIWESSID
;
801 iwe
.u
.data
.length
= ie
[1];
802 iwe
.u
.data
.flags
= 1;
803 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
806 case WLAN_EID_MESH_CONFIG
:
808 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
810 buf
= kmalloc(50, GFP_ATOMIC
);
814 memset(&iwe
, 0, sizeof(iwe
));
815 iwe
.cmd
= IWEVCUSTOM
;
816 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
817 iwe
.u
.data
.length
= strlen(buf
);
818 current_ev
= iwe_stream_add_point(info
, current_ev
,
821 sprintf(buf
, "Path Selection Protocol ID: "
822 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
824 iwe
.u
.data
.length
= strlen(buf
);
825 current_ev
= iwe_stream_add_point(info
, current_ev
,
828 sprintf(buf
, "Path Selection Metric ID: "
829 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
831 iwe
.u
.data
.length
= strlen(buf
);
832 current_ev
= iwe_stream_add_point(info
, current_ev
,
835 sprintf(buf
, "Congestion Control Mode ID: "
836 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
838 iwe
.u
.data
.length
= strlen(buf
);
839 current_ev
= iwe_stream_add_point(info
, current_ev
,
842 sprintf(buf
, "Channel Precedence: "
843 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
845 iwe
.u
.data
.length
= strlen(buf
);
846 current_ev
= iwe_stream_add_point(info
, current_ev
,
851 case WLAN_EID_SUPP_RATES
:
852 case WLAN_EID_EXT_SUPP_RATES
:
853 /* display all supported rates in readable format */
854 p
= current_ev
+ iwe_stream_lcp_len(info
);
856 memset(&iwe
, 0, sizeof(iwe
));
857 iwe
.cmd
= SIOCGIWRATE
;
858 /* Those two flags are ignored... */
859 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
861 for (i
= 0; i
< ie
[1]; i
++) {
862 iwe
.u
.bitrate
.value
=
863 ((ie
[i
+ 2] & 0x7f) * 500000);
864 p
= iwe_stream_add_value(info
, current_ev
, p
,
865 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
874 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
876 memset(&iwe
, 0, sizeof(iwe
));
877 iwe
.cmd
= SIOCGIWMODE
;
879 iwe
.u
.mode
= IW_MODE_MESH
;
880 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
881 iwe
.u
.mode
= IW_MODE_MASTER
;
883 iwe
.u
.mode
= IW_MODE_ADHOC
;
884 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
885 &iwe
, IW_EV_UINT_LEN
);
888 buf
= kmalloc(30, GFP_ATOMIC
);
890 memset(&iwe
, 0, sizeof(iwe
));
891 iwe
.cmd
= IWEVCUSTOM
;
892 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->pub
.tsf
));
893 iwe
.u
.data
.length
= strlen(buf
);
894 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
896 memset(&iwe
, 0, sizeof(iwe
));
897 iwe
.cmd
= IWEVCUSTOM
;
898 sprintf(buf
, " Last beacon: %ums ago",
899 elapsed_jiffies_msecs(bss
->ts
));
900 iwe
.u
.data
.length
= strlen(buf
);
901 current_ev
= iwe_stream_add_point(info
, current_ev
,
906 ieee80211_scan_add_ies(info
, &bss
->pub
, ¤t_ev
, end_buf
);
912 static int ieee80211_scan_results(struct cfg80211_registered_device
*dev
,
913 struct iw_request_info
*info
,
914 char *buf
, size_t len
)
916 char *current_ev
= buf
;
917 char *end_buf
= buf
+ len
;
918 struct cfg80211_internal_bss
*bss
;
920 spin_lock_bh(&dev
->bss_lock
);
921 cfg80211_bss_expire(dev
);
923 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
924 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
925 spin_unlock_bh(&dev
->bss_lock
);
928 current_ev
= ieee80211_bss(&dev
->wiphy
, info
, bss
,
929 current_ev
, end_buf
);
931 spin_unlock_bh(&dev
->bss_lock
);
932 return current_ev
- buf
;
936 int cfg80211_wext_giwscan(struct net_device
*dev
,
937 struct iw_request_info
*info
,
938 struct iw_point
*data
, char *extra
)
940 struct cfg80211_registered_device
*rdev
;
943 if (!netif_running(dev
))
946 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
949 return PTR_ERR(rdev
);
951 if (rdev
->scan_req
) {
956 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
964 cfg80211_unlock_rdev(rdev
);
967 EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan
);