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
);
34 * This must be before sending the other events!
35 * Otherwise, wpa_supplicant gets completely confused with
38 cfg80211_sme_scan_done(dev
);
41 nl80211_send_scan_aborted(wiphy_to_dev(request
->wiphy
), dev
);
43 nl80211_send_scan_done(wiphy_to_dev(request
->wiphy
), dev
);
45 wiphy_to_dev(request
->wiphy
)->scan_req
= NULL
;
47 #ifdef CONFIG_WIRELESS_EXT
49 memset(&wrqu
, 0, sizeof(wrqu
));
51 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
60 EXPORT_SYMBOL(cfg80211_scan_done
);
62 static void bss_release(struct kref
*ref
)
64 struct cfg80211_internal_bss
*bss
;
66 bss
= container_of(ref
, struct cfg80211_internal_bss
, ref
);
67 if (bss
->pub
.free_priv
)
68 bss
->pub
.free_priv(&bss
->pub
);
70 if (bss
->ies_allocated
)
71 kfree(bss
->pub
.information_elements
);
73 BUG_ON(atomic_read(&bss
->hold
));
78 /* must hold dev->bss_lock! */
79 void cfg80211_bss_age(struct cfg80211_registered_device
*dev
,
80 unsigned long age_secs
)
82 struct cfg80211_internal_bss
*bss
;
83 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
85 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
86 bss
->ts
-= age_jiffies
;
90 /* must hold dev->bss_lock! */
91 void cfg80211_bss_expire(struct cfg80211_registered_device
*dev
)
93 struct cfg80211_internal_bss
*bss
, *tmp
;
96 list_for_each_entry_safe(bss
, tmp
, &dev
->bss_list
, list
) {
97 if (atomic_read(&bss
->hold
))
99 if (!time_after(jiffies
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
))
101 list_del(&bss
->list
);
102 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
103 kref_put(&bss
->ref
, bss_release
);
108 dev
->bss_generation
++;
111 static u8
*find_ie(u8 num
, u8
*ies
, size_t len
)
113 while (len
> 2 && ies
[0] != num
) {
119 if (len
< 2 + ies
[1])
124 static int cmp_ies(u8 num
, u8
*ies1
, size_t len1
, u8
*ies2
, size_t len2
)
126 const u8
*ie1
= find_ie(num
, ies1
, len1
);
127 const u8
*ie2
= find_ie(num
, ies2
, len2
);
135 r
= memcmp(ie1
+ 2, ie2
+ 2, min(ie1
[1], ie2
[1]));
136 if (r
== 0 && ie1
[1] != ie2
[1])
137 return ie2
[1] - ie1
[1];
141 static bool is_bss(struct cfg80211_bss
*a
,
143 const u8
*ssid
, size_t ssid_len
)
147 if (bssid
&& compare_ether_addr(a
->bssid
, bssid
))
153 ssidie
= find_ie(WLAN_EID_SSID
,
154 a
->information_elements
,
155 a
->len_information_elements
);
158 if (ssidie
[1] != ssid_len
)
160 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
163 static bool is_mesh(struct cfg80211_bss
*a
,
164 const u8
*meshid
, size_t meshidlen
,
169 if (!is_zero_ether_addr(a
->bssid
))
172 ie
= find_ie(WLAN_EID_MESH_ID
,
173 a
->information_elements
,
174 a
->len_information_elements
);
177 if (ie
[1] != meshidlen
)
179 if (memcmp(ie
+ 2, meshid
, meshidlen
))
182 ie
= find_ie(WLAN_EID_MESH_CONFIG
,
183 a
->information_elements
,
184 a
->len_information_elements
);
185 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
189 * Ignore mesh capability (last two bytes of the IE) when
190 * comparing since that may differ between stations taking
191 * part in the same mesh.
193 return memcmp(ie
+ 2, meshcfg
, IEEE80211_MESH_CONFIG_LEN
- 2) == 0;
196 static int cmp_bss(struct cfg80211_bss
*a
,
197 struct cfg80211_bss
*b
)
201 if (a
->channel
!= b
->channel
)
202 return b
->channel
->center_freq
- a
->channel
->center_freq
;
204 r
= memcmp(a
->bssid
, b
->bssid
, ETH_ALEN
);
208 if (is_zero_ether_addr(a
->bssid
)) {
209 r
= cmp_ies(WLAN_EID_MESH_ID
,
210 a
->information_elements
,
211 a
->len_information_elements
,
212 b
->information_elements
,
213 b
->len_information_elements
);
216 return cmp_ies(WLAN_EID_MESH_CONFIG
,
217 a
->information_elements
,
218 a
->len_information_elements
,
219 b
->information_elements
,
220 b
->len_information_elements
);
223 return cmp_ies(WLAN_EID_SSID
,
224 a
->information_elements
,
225 a
->len_information_elements
,
226 b
->information_elements
,
227 b
->len_information_elements
);
230 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
231 struct ieee80211_channel
*channel
,
233 const u8
*ssid
, size_t ssid_len
,
234 u16 capa_mask
, u16 capa_val
)
236 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
237 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
239 spin_lock_bh(&dev
->bss_lock
);
241 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
242 if ((bss
->pub
.capability
& capa_mask
) != capa_val
)
244 if (channel
&& bss
->pub
.channel
!= channel
)
246 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
253 spin_unlock_bh(&dev
->bss_lock
);
258 EXPORT_SYMBOL(cfg80211_get_bss
);
260 struct cfg80211_bss
*cfg80211_get_mesh(struct wiphy
*wiphy
,
261 struct ieee80211_channel
*channel
,
262 const u8
*meshid
, size_t meshidlen
,
265 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
266 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
268 spin_lock_bh(&dev
->bss_lock
);
270 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
271 if (channel
&& bss
->pub
.channel
!= channel
)
273 if (is_mesh(&bss
->pub
, meshid
, meshidlen
, meshcfg
)) {
280 spin_unlock_bh(&dev
->bss_lock
);
285 EXPORT_SYMBOL(cfg80211_get_mesh
);
288 static void rb_insert_bss(struct cfg80211_registered_device
*dev
,
289 struct cfg80211_internal_bss
*bss
)
291 struct rb_node
**p
= &dev
->bss_tree
.rb_node
;
292 struct rb_node
*parent
= NULL
;
293 struct cfg80211_internal_bss
*tbss
;
298 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
300 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
);
303 /* will sort of leak this BSS */
313 rb_link_node(&bss
->rbn
, parent
, p
);
314 rb_insert_color(&bss
->rbn
, &dev
->bss_tree
);
317 static struct cfg80211_internal_bss
*
318 rb_find_bss(struct cfg80211_registered_device
*dev
,
319 struct cfg80211_internal_bss
*res
)
321 struct rb_node
*n
= dev
->bss_tree
.rb_node
;
322 struct cfg80211_internal_bss
*bss
;
326 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
327 r
= cmp_bss(&res
->pub
, &bss
->pub
);
340 static struct cfg80211_internal_bss
*
341 cfg80211_bss_update(struct cfg80211_registered_device
*dev
,
342 struct cfg80211_internal_bss
*res
,
345 struct cfg80211_internal_bss
*found
= NULL
;
346 const u8
*meshid
, *meshcfg
;
349 * The reference to "res" is donated to this function.
352 if (WARN_ON(!res
->pub
.channel
)) {
353 kref_put(&res
->ref
, bss_release
);
359 if (is_zero_ether_addr(res
->pub
.bssid
)) {
360 /* must be mesh, verify */
361 meshid
= find_ie(WLAN_EID_MESH_ID
, res
->pub
.information_elements
,
362 res
->pub
.len_information_elements
);
363 meshcfg
= find_ie(WLAN_EID_MESH_CONFIG
,
364 res
->pub
.information_elements
,
365 res
->pub
.len_information_elements
);
366 if (!meshid
|| !meshcfg
||
367 meshcfg
[1] != IEEE80211_MESH_CONFIG_LEN
) {
369 kref_put(&res
->ref
, bss_release
);
374 spin_lock_bh(&dev
->bss_lock
);
376 found
= rb_find_bss(dev
, res
);
379 found
->pub
.beacon_interval
= res
->pub
.beacon_interval
;
380 found
->pub
.tsf
= res
->pub
.tsf
;
381 found
->pub
.signal
= res
->pub
.signal
;
382 found
->pub
.capability
= res
->pub
.capability
;
387 size_t used
= dev
->wiphy
.bss_priv_size
+ sizeof(*res
);
388 size_t ielen
= res
->pub
.len_information_elements
;
390 if (!found
->ies_allocated
&& ksize(found
) >= used
+ ielen
) {
391 memcpy(found
->pub
.information_elements
,
392 res
->pub
.information_elements
, ielen
);
393 found
->pub
.len_information_elements
= ielen
;
395 u8
*ies
= found
->pub
.information_elements
;
397 if (found
->ies_allocated
)
398 ies
= krealloc(ies
, ielen
, GFP_ATOMIC
);
400 ies
= kmalloc(ielen
, GFP_ATOMIC
);
403 memcpy(ies
, res
->pub
.information_elements
, ielen
);
404 found
->ies_allocated
= true;
405 found
->pub
.information_elements
= ies
;
406 found
->pub
.len_information_elements
= ielen
;
411 kref_put(&res
->ref
, bss_release
);
413 /* this "consumes" the reference */
414 list_add_tail(&res
->list
, &dev
->bss_list
);
415 rb_insert_bss(dev
, res
);
419 dev
->bss_generation
++;
420 spin_unlock_bh(&dev
->bss_lock
);
422 kref_get(&found
->ref
);
427 cfg80211_inform_bss(struct wiphy
*wiphy
,
428 struct ieee80211_channel
*channel
,
430 u64 timestamp
, u16 capability
, u16 beacon_interval
,
431 const u8
*ie
, size_t ielen
,
432 s32 signal
, gfp_t gfp
)
434 struct cfg80211_internal_bss
*res
;
440 privsz
= wiphy
->bss_priv_size
;
442 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
443 (signal
< 0 || signal
> 100)))
446 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
450 memcpy(res
->pub
.bssid
, bssid
, ETH_ALEN
);
451 res
->pub
.channel
= channel
;
452 res
->pub
.signal
= signal
;
453 res
->pub
.tsf
= timestamp
;
454 res
->pub
.beacon_interval
= beacon_interval
;
455 res
->pub
.capability
= capability
;
456 /* point to after the private area */
457 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
458 memcpy(res
->pub
.information_elements
, ie
, ielen
);
459 res
->pub
.len_information_elements
= ielen
;
461 kref_init(&res
->ref
);
463 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, 0);
467 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
468 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
470 /* cfg80211_bss_update gives us a referenced result */
473 EXPORT_SYMBOL(cfg80211_inform_bss
);
475 struct cfg80211_bss
*
476 cfg80211_inform_bss_frame(struct wiphy
*wiphy
,
477 struct ieee80211_channel
*channel
,
478 struct ieee80211_mgmt
*mgmt
, size_t len
,
479 s32 signal
, gfp_t gfp
)
481 struct cfg80211_internal_bss
*res
;
482 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
483 u
.probe_resp
.variable
);
485 size_t privsz
= wiphy
->bss_priv_size
;
487 if (WARN_ON(wiphy
->signal_type
== NL80211_BSS_SIGNAL_UNSPEC
&&
488 (signal
< 0 || signal
> 100)))
491 if (WARN_ON(!mgmt
|| !wiphy
||
492 len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
495 res
= kzalloc(sizeof(*res
) + privsz
+ ielen
, gfp
);
499 memcpy(res
->pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
500 res
->pub
.channel
= channel
;
501 res
->pub
.signal
= signal
;
502 res
->pub
.tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
503 res
->pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
504 res
->pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
505 /* point to after the private area */
506 res
->pub
.information_elements
= (u8
*)res
+ sizeof(*res
) + privsz
;
507 memcpy(res
->pub
.information_elements
, mgmt
->u
.probe_resp
.variable
, ielen
);
508 res
->pub
.len_information_elements
= ielen
;
510 kref_init(&res
->ref
);
512 overwrite
= ieee80211_is_probe_resp(mgmt
->frame_control
);
514 res
= cfg80211_bss_update(wiphy_to_dev(wiphy
), res
, overwrite
);
518 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
519 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
521 /* cfg80211_bss_update gives us a referenced result */
524 EXPORT_SYMBOL(cfg80211_inform_bss_frame
);
526 void cfg80211_put_bss(struct cfg80211_bss
*pub
)
528 struct cfg80211_internal_bss
*bss
;
533 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
534 kref_put(&bss
->ref
, bss_release
);
536 EXPORT_SYMBOL(cfg80211_put_bss
);
538 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
540 struct cfg80211_registered_device
*dev
= wiphy_to_dev(wiphy
);
541 struct cfg80211_internal_bss
*bss
;
546 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
548 spin_lock_bh(&dev
->bss_lock
);
550 list_del(&bss
->list
);
551 rb_erase(&bss
->rbn
, &dev
->bss_tree
);
553 spin_unlock_bh(&dev
->bss_lock
);
555 kref_put(&bss
->ref
, bss_release
);
557 EXPORT_SYMBOL(cfg80211_unlink_bss
);
559 #ifdef CONFIG_WIRELESS_EXT
560 int cfg80211_wext_siwscan(struct net_device
*dev
,
561 struct iw_request_info
*info
,
562 union iwreq_data
*wrqu
, char *extra
)
564 struct cfg80211_registered_device
*rdev
;
566 struct iw_scan_req
*wreq
= NULL
;
567 struct cfg80211_scan_request
*creq
;
568 int i
, err
, n_channels
= 0;
569 enum ieee80211_band band
;
571 if (!netif_running(dev
))
574 rdev
= cfg80211_get_dev_from_ifindex(dev
->ifindex
);
577 return PTR_ERR(rdev
);
579 if (rdev
->scan_req
) {
584 wiphy
= &rdev
->wiphy
;
586 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
587 if (wiphy
->bands
[band
])
588 n_channels
+= wiphy
->bands
[band
]->n_channels
;
590 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
591 n_channels
* sizeof(void *),
599 creq
->ifidx
= dev
->ifindex
;
600 creq
->ssids
= (void *)(creq
+ 1);
601 creq
->channels
= (void *)(creq
->ssids
+ 1);
602 creq
->n_channels
= n_channels
;
607 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
609 if (!wiphy
->bands
[band
])
611 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
612 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
617 /* translate scan request */
618 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
)) {
619 wreq
= (struct iw_scan_req
*)extra
;
621 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
622 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
)
624 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
625 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
627 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
631 rdev
->scan_req
= creq
;
632 err
= rdev
->ops
->scan(wiphy
, dev
, creq
);
634 rdev
->scan_req
= NULL
;
637 nl80211_send_scan_start(rdev
, dev
);
639 cfg80211_put_dev(rdev
);
642 EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan
);
644 static void ieee80211_scan_add_ies(struct iw_request_info
*info
,
645 struct cfg80211_bss
*bss
,
646 char **current_ev
, char *end_buf
)
648 u8
*pos
, *end
, *next
;
651 if (!bss
->information_elements
||
652 !bss
->len_information_elements
)
656 * If needed, fragment the IEs buffer (at IE boundaries) into short
657 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
659 pos
= bss
->information_elements
;
660 end
= pos
+ bss
->len_information_elements
;
662 while (end
- pos
> IW_GENERIC_IE_MAX
) {
663 next
= pos
+ 2 + pos
[1];
664 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
665 next
= next
+ 2 + next
[1];
667 memset(&iwe
, 0, sizeof(iwe
));
669 iwe
.u
.data
.length
= next
- pos
;
670 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
677 memset(&iwe
, 0, sizeof(iwe
));
679 iwe
.u
.data
.length
= end
- pos
;
680 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
685 static inline unsigned int elapsed_jiffies_msecs(unsigned long start
)
687 unsigned long end
= jiffies
;
690 return jiffies_to_msecs(end
- start
);
692 return jiffies_to_msecs(end
+ (MAX_JIFFY_OFFSET
- start
) + 1);
696 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
697 struct cfg80211_internal_bss
*bss
, char *current_ev
,
702 u8
*ie
= bss
->pub
.information_elements
;
703 int rem
= bss
->pub
.len_information_elements
, i
, sig
;
706 memset(&iwe
, 0, sizeof(iwe
));
708 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
709 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
710 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
713 memset(&iwe
, 0, sizeof(iwe
));
714 iwe
.cmd
= SIOCGIWFREQ
;
715 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
717 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
720 memset(&iwe
, 0, sizeof(iwe
));
721 iwe
.cmd
= SIOCGIWFREQ
;
722 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
724 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
727 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
728 memset(&iwe
, 0, sizeof(iwe
));
730 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
731 IW_QUAL_NOISE_INVALID
|
732 IW_QUAL_QUAL_UPDATED
;
733 switch (wiphy
->signal_type
) {
734 case CFG80211_SIGNAL_TYPE_MBM
:
735 sig
= bss
->pub
.signal
/ 100;
736 iwe
.u
.qual
.level
= sig
;
737 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
738 if (sig
< -110) /* rather bad */
740 else if (sig
> -40) /* perfect */
742 /* will give a range of 0 .. 70 */
743 iwe
.u
.qual
.qual
= sig
+ 110;
745 case CFG80211_SIGNAL_TYPE_UNSPEC
:
746 iwe
.u
.qual
.level
= bss
->pub
.signal
;
747 /* will give range 0 .. 100 */
748 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
754 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
755 &iwe
, IW_EV_QUAL_LEN
);
758 memset(&iwe
, 0, sizeof(iwe
));
759 iwe
.cmd
= SIOCGIWENCODE
;
760 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
761 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
763 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
764 iwe
.u
.data
.length
= 0;
765 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
775 memset(&iwe
, 0, sizeof(iwe
));
776 iwe
.cmd
= SIOCGIWESSID
;
777 iwe
.u
.data
.length
= ie
[1];
778 iwe
.u
.data
.flags
= 1;
779 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
782 case WLAN_EID_MESH_ID
:
783 memset(&iwe
, 0, sizeof(iwe
));
784 iwe
.cmd
= SIOCGIWESSID
;
785 iwe
.u
.data
.length
= ie
[1];
786 iwe
.u
.data
.flags
= 1;
787 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
790 case WLAN_EID_MESH_CONFIG
:
792 if (ie
[1] != IEEE80211_MESH_CONFIG_LEN
)
794 buf
= kmalloc(50, GFP_ATOMIC
);
798 memset(&iwe
, 0, sizeof(iwe
));
799 iwe
.cmd
= IWEVCUSTOM
;
800 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
801 iwe
.u
.data
.length
= strlen(buf
);
802 current_ev
= iwe_stream_add_point(info
, current_ev
,
805 sprintf(buf
, "Path Selection Protocol ID: "
806 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
808 iwe
.u
.data
.length
= strlen(buf
);
809 current_ev
= iwe_stream_add_point(info
, current_ev
,
812 sprintf(buf
, "Path Selection Metric ID: "
813 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
815 iwe
.u
.data
.length
= strlen(buf
);
816 current_ev
= iwe_stream_add_point(info
, current_ev
,
819 sprintf(buf
, "Congestion Control Mode ID: "
820 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
822 iwe
.u
.data
.length
= strlen(buf
);
823 current_ev
= iwe_stream_add_point(info
, current_ev
,
826 sprintf(buf
, "Channel Precedence: "
827 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
829 iwe
.u
.data
.length
= strlen(buf
);
830 current_ev
= iwe_stream_add_point(info
, current_ev
,
835 case WLAN_EID_SUPP_RATES
:
836 case WLAN_EID_EXT_SUPP_RATES
:
837 /* display all supported rates in readable format */
838 p
= current_ev
+ iwe_stream_lcp_len(info
);
840 memset(&iwe
, 0, sizeof(iwe
));
841 iwe
.cmd
= SIOCGIWRATE
;
842 /* Those two flags are ignored... */
843 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
845 for (i
= 0; i
< ie
[1]; i
++) {
846 iwe
.u
.bitrate
.value
=
847 ((ie
[i
+ 2] & 0x7f) * 500000);
848 p
= iwe_stream_add_value(info
, current_ev
, p
,
849 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
858 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
860 memset(&iwe
, 0, sizeof(iwe
));
861 iwe
.cmd
= SIOCGIWMODE
;
863 iwe
.u
.mode
= IW_MODE_MESH
;
864 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
865 iwe
.u
.mode
= IW_MODE_MASTER
;
867 iwe
.u
.mode
= IW_MODE_ADHOC
;
868 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
869 &iwe
, IW_EV_UINT_LEN
);
872 buf
= kmalloc(30, GFP_ATOMIC
);
874 memset(&iwe
, 0, sizeof(iwe
));
875 iwe
.cmd
= IWEVCUSTOM
;
876 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->pub
.tsf
));
877 iwe
.u
.data
.length
= strlen(buf
);
878 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
880 memset(&iwe
, 0, sizeof(iwe
));
881 iwe
.cmd
= IWEVCUSTOM
;
882 sprintf(buf
, " Last beacon: %ums ago",
883 elapsed_jiffies_msecs(bss
->ts
));
884 iwe
.u
.data
.length
= strlen(buf
);
885 current_ev
= iwe_stream_add_point(info
, current_ev
,
890 ieee80211_scan_add_ies(info
, &bss
->pub
, ¤t_ev
, end_buf
);
896 static int ieee80211_scan_results(struct cfg80211_registered_device
*dev
,
897 struct iw_request_info
*info
,
898 char *buf
, size_t len
)
900 char *current_ev
= buf
;
901 char *end_buf
= buf
+ len
;
902 struct cfg80211_internal_bss
*bss
;
904 spin_lock_bh(&dev
->bss_lock
);
905 cfg80211_bss_expire(dev
);
907 list_for_each_entry(bss
, &dev
->bss_list
, list
) {
908 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
909 spin_unlock_bh(&dev
->bss_lock
);
912 current_ev
= ieee80211_bss(&dev
->wiphy
, info
, bss
,
913 current_ev
, end_buf
);
915 spin_unlock_bh(&dev
->bss_lock
);
916 return current_ev
- buf
;
920 int cfg80211_wext_giwscan(struct net_device
*dev
,
921 struct iw_request_info
*info
,
922 struct iw_point
*data
, char *extra
)
924 struct cfg80211_registered_device
*rdev
;
927 if (!netif_running(dev
))
930 rdev
= cfg80211_get_dev_from_ifindex(dev
->ifindex
);
933 return PTR_ERR(rdev
);
935 if (rdev
->scan_req
) {
940 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
948 cfg80211_put_dev(rdev
);
951 EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan
);