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_CFG80211_WEXT
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_CFG80211_WEXT
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 queue_work(cfg80211_wq, &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->beacon_ies_allocated)
104 kfree(bss->pub.beacon_ies);
105 if (bss->proberesp_ies_allocated)
106 kfree(bss->pub.proberesp_ies);
108 BUG_ON(atomic_read(&bss->hold));
113 /* must hold dev->bss_lock! */
114 void cfg80211_bss_age(struct cfg80211_registered_device *dev,
115 unsigned long age_secs)
117 struct cfg80211_internal_bss *bss;
118 unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
120 list_for_each_entry(bss, &dev->bss_list, list) {
121 bss->ts -= age_jiffies;
125 /* must hold dev->bss_lock! */
126 void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
128 struct cfg80211_internal_bss *bss, *tmp;
129 bool expired = false;
131 list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) {
132 if (atomic_read(&bss->hold))
134 if (!time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE))
136 list_del(&bss->list);
137 rb_erase(&bss->rbn, &dev->bss_tree);
138 kref_put(&bss->ref, bss_release);
143 dev->bss_generation++;
146 const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len)
148 while (len > 2 && ies[0] != eid) {
154 if (len < 2 + ies[1])
158 EXPORT_SYMBOL(cfg80211_find_ie);
160 static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2)
162 const u8 *ie1 = cfg80211_find_ie(num, ies1, len1);
163 const u8 *ie2 = cfg80211_find_ie(num, ies2, len2);
171 r = memcmp(ie1 + 2, ie2 + 2, min(ie1[1], ie2[1]));
172 if (r == 0 && ie1[1] != ie2[1])
173 return ie2[1] - ie1[1];
177 static bool is_bss(struct cfg80211_bss *a,
179 const u8 *ssid, size_t ssid_len)
183 if (bssid && compare_ether_addr(a->bssid, bssid))
189 ssidie = cfg80211_find_ie(WLAN_EID_SSID,
190 a->information_elements,
191 a->len_information_elements);
194 if (ssidie[1] != ssid_len)
196 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
199 static bool is_mesh(struct cfg80211_bss *a,
200 const u8 *meshid, size_t meshidlen,
205 if (!is_zero_ether_addr(a->bssid))
208 ie = cfg80211_find_ie(WLAN_EID_MESH_ID,
209 a->information_elements,
210 a->len_information_elements);
213 if (ie[1] != meshidlen)
215 if (memcmp(ie + 2, meshid, meshidlen))
218 ie = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
219 a->information_elements,
220 a->len_information_elements);
223 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
227 * Ignore mesh capability (last two bytes of the IE) when
228 * comparing since that may differ between stations taking
229 * part in the same mesh.
231 return memcmp(ie + 2, meshcfg,
232 sizeof(struct ieee80211_meshconf_ie) - 2) == 0;
235 static int cmp_bss(struct cfg80211_bss *a,
236 struct cfg80211_bss *b)
240 if (a->channel != b->channel)
241 return b->channel->center_freq - a->channel->center_freq;
243 r = memcmp(a->bssid, b->bssid, ETH_ALEN);
247 if (is_zero_ether_addr(a->bssid)) {
248 r = cmp_ies(WLAN_EID_MESH_ID,
249 a->information_elements,
250 a->len_information_elements,
251 b->information_elements,
252 b->len_information_elements);
255 return cmp_ies(WLAN_EID_MESH_CONFIG,
256 a->information_elements,
257 a->len_information_elements,
258 b->information_elements,
259 b->len_information_elements);
262 return cmp_ies(WLAN_EID_SSID,
263 a->information_elements,
264 a->len_information_elements,
265 b->information_elements,
266 b->len_information_elements);
269 struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
270 struct ieee80211_channel *channel,
272 const u8 *ssid, size_t ssid_len,
273 u16 capa_mask, u16 capa_val)
275 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
276 struct cfg80211_internal_bss *bss, *res = NULL;
278 spin_lock_bh(&dev->bss_lock);
280 list_for_each_entry(bss, &dev->bss_list, list) {
281 if ((bss->pub.capability & capa_mask) != capa_val)
283 if (channel && bss->pub.channel != channel)
285 if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
292 spin_unlock_bh(&dev->bss_lock);
297 EXPORT_SYMBOL(cfg80211_get_bss);
299 struct cfg80211_bss *cfg80211_get_mesh(struct wiphy *wiphy,
300 struct ieee80211_channel *channel,
301 const u8 *meshid, size_t meshidlen,
304 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
305 struct cfg80211_internal_bss *bss, *res = NULL;
307 spin_lock_bh(&dev->bss_lock);
309 list_for_each_entry(bss, &dev->bss_list, list) {
310 if (channel && bss->pub.channel != channel)
312 if (is_mesh(&bss->pub, meshid, meshidlen, meshcfg)) {
319 spin_unlock_bh(&dev->bss_lock);
324 EXPORT_SYMBOL(cfg80211_get_mesh);
327 static void rb_insert_bss(struct cfg80211_registered_device *dev,
328 struct cfg80211_internal_bss *bss)
330 struct rb_node **p = &dev->bss_tree.rb_node;
331 struct rb_node *parent = NULL;
332 struct cfg80211_internal_bss *tbss;
337 tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
339 cmp = cmp_bss(&bss->pub, &tbss->pub);
342 /* will sort of leak this BSS */
352 rb_link_node(&bss->rbn, parent, p);
353 rb_insert_color(&bss->rbn, &dev->bss_tree);
356 static struct cfg80211_internal_bss *
357 rb_find_bss(struct cfg80211_registered_device *dev,
358 struct cfg80211_internal_bss *res)
360 struct rb_node *n = dev->bss_tree.rb_node;
361 struct cfg80211_internal_bss *bss;
365 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
366 r = cmp_bss(&res->pub, &bss->pub);
379 static struct cfg80211_internal_bss *
380 cfg80211_bss_update(struct cfg80211_registered_device *dev,
381 struct cfg80211_internal_bss *res)
383 struct cfg80211_internal_bss *found = NULL;
384 const u8 *meshid, *meshcfg;
387 * The reference to "res" is donated to this function.
390 if (WARN_ON(!res->pub.channel)) {
391 kref_put(&res->ref, bss_release);
397 if (is_zero_ether_addr(res->pub.bssid)) {
398 /* must be mesh, verify */
399 meshid = cfg80211_find_ie(WLAN_EID_MESH_ID,
400 res->pub.information_elements,
401 res->pub.len_information_elements);
402 meshcfg = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
403 res->pub.information_elements,
404 res->pub.len_information_elements);
405 if (!meshid || !meshcfg ||
406 meshcfg[1] != sizeof(struct ieee80211_meshconf_ie)) {
408 kref_put(&res->ref, bss_release);
413 spin_lock_bh(&dev->bss_lock);
415 found = rb_find_bss(dev, res);
418 found->pub.beacon_interval = res->pub.beacon_interval;
419 found->pub.tsf = res->pub.tsf;
420 found->pub.signal = res->pub.signal;
421 found->pub.capability = res->pub.capability;
425 if (res->pub.proberesp_ies) {
426 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
427 size_t ielen = res->pub.len_proberesp_ies;
429 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
431 used = 0; /* just to shut up the compiler */
433 if (found->pub.proberesp_ies &&
434 !found->proberesp_ies_allocated &&
435 ksize(found) >= used + ielen) {
437 memcpy(found->pub.proberesp_ies,
438 res->pub.proberesp_ies, ielen);
439 found->pub.len_proberesp_ies = ielen;
441 u8 *ies = found->pub.proberesp_ies;
443 if (found->proberesp_ies_allocated)
444 ies = krealloc(ies, ielen, GFP_ATOMIC);
446 ies = kmalloc(ielen, GFP_ATOMIC);
449 memcpy(ies, res->pub.proberesp_ies,
451 found->proberesp_ies_allocated = true;
452 found->pub.proberesp_ies = ies;
453 found->pub.len_proberesp_ies = ielen;
457 /* Override possible earlier Beacon frame IEs */
458 found->pub.information_elements =
459 found->pub.proberesp_ies;
460 found->pub.len_information_elements =
461 found->pub.len_proberesp_ies;
463 if (res->pub.beacon_ies) {
464 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
465 size_t ielen = res->pub.len_beacon_ies;
467 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
469 used = 0; /* just to shut up the compiler */
471 if (found->pub.beacon_ies &&
472 !found->beacon_ies_allocated &&
473 ksize(found) >= used + ielen) {
475 memcpy(found->pub.beacon_ies,
476 res->pub.beacon_ies, ielen);
477 found->pub.len_beacon_ies = ielen;
479 u8 *ies = found->pub.beacon_ies;
481 if (found->beacon_ies_allocated)
482 ies = krealloc(ies, ielen, GFP_ATOMIC);
484 ies = kmalloc(ielen, GFP_ATOMIC);
487 memcpy(ies, res->pub.beacon_ies,
489 found->beacon_ies_allocated = true;
490 found->pub.beacon_ies = ies;
491 found->pub.len_beacon_ies = ielen;
496 kref_put(&res->ref, bss_release);
498 /* this "consumes" the reference */
499 list_add_tail(&res->list, &dev->bss_list);
500 rb_insert_bss(dev, res);
504 dev->bss_generation++;
505 spin_unlock_bh(&dev->bss_lock);
507 kref_get(&found->ref);
512 cfg80211_inform_bss(struct wiphy *wiphy,
513 struct ieee80211_channel *channel,
515 u64 timestamp, u16 capability, u16 beacon_interval,
516 const u8 *ie, size_t ielen,
517 s32 signal, gfp_t gfp)
519 struct cfg80211_internal_bss *res;
525 privsz = wiphy->bss_priv_size;
527 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
528 (signal < 0 || signal > 100)))
531 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
535 memcpy(res->pub.bssid, bssid, ETH_ALEN);
536 res->pub.channel = channel;
537 res->pub.signal = signal;
538 res->pub.tsf = timestamp;
539 res->pub.beacon_interval = beacon_interval;
540 res->pub.capability = capability;
542 * Since we do not know here whether the IEs are from a Beacon or Probe
543 * Response frame, we need to pick one of the options and only use it
544 * with the driver that does not provide the full Beacon/Probe Response
545 * frame. Use Beacon frame pointer to avoid indicating that this should
546 * override the information_elements pointer should we have received an
547 * earlier indication of Probe Response data.
549 * The initial buffer for the IEs is allocated with the BSS entry and
550 * is located after the private area.
552 res->pub.beacon_ies = (u8 *)res + sizeof(*res) + privsz;
553 memcpy(res->pub.beacon_ies, ie, ielen);
554 res->pub.len_beacon_ies = ielen;
555 res->pub.information_elements = res->pub.beacon_ies;
556 res->pub.len_information_elements = res->pub.len_beacon_ies;
558 kref_init(&res->ref);
560 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
564 if (res->pub.capability & WLAN_CAPABILITY_ESS)
565 regulatory_hint_found_beacon(wiphy, channel, gfp);
567 /* cfg80211_bss_update gives us a referenced result */
570 EXPORT_SYMBOL(cfg80211_inform_bss);
572 struct cfg80211_bss *
573 cfg80211_inform_bss_frame(struct wiphy *wiphy,
574 struct ieee80211_channel *channel,
575 struct ieee80211_mgmt *mgmt, size_t len,
576 s32 signal, gfp_t gfp)
578 struct cfg80211_internal_bss *res;
579 size_t ielen = len - offsetof(struct ieee80211_mgmt,
580 u.probe_resp.variable);
581 size_t privsz = wiphy->bss_priv_size;
583 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
584 (signal < 0 || signal > 100)))
587 if (WARN_ON(!mgmt || !wiphy ||
588 len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
591 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
595 memcpy(res->pub.bssid, mgmt->bssid, ETH_ALEN);
596 res->pub.channel = channel;
597 res->pub.signal = signal;
598 res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
599 res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
600 res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
602 * The initial buffer for the IEs is allocated with the BSS entry and
603 * is located after the private area.
605 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
606 res->pub.proberesp_ies = (u8 *) res + sizeof(*res) + privsz;
607 memcpy(res->pub.proberesp_ies, mgmt->u.probe_resp.variable,
609 res->pub.len_proberesp_ies = ielen;
610 res->pub.information_elements = res->pub.proberesp_ies;
611 res->pub.len_information_elements = res->pub.len_proberesp_ies;
613 res->pub.beacon_ies = (u8 *) res + sizeof(*res) + privsz;
614 memcpy(res->pub.beacon_ies, mgmt->u.beacon.variable, ielen);
615 res->pub.len_beacon_ies = ielen;
616 res->pub.information_elements = res->pub.beacon_ies;
617 res->pub.len_information_elements = res->pub.len_beacon_ies;
620 kref_init(&res->ref);
622 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
626 if (res->pub.capability & WLAN_CAPABILITY_ESS)
627 regulatory_hint_found_beacon(wiphy, channel, gfp);
629 /* cfg80211_bss_update gives us a referenced result */
632 EXPORT_SYMBOL(cfg80211_inform_bss_frame);
634 void cfg80211_put_bss(struct cfg80211_bss *pub)
636 struct cfg80211_internal_bss *bss;
641 bss = container_of(pub, struct cfg80211_internal_bss, pub);
642 kref_put(&bss->ref, bss_release);
644 EXPORT_SYMBOL(cfg80211_put_bss);
646 void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
648 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
649 struct cfg80211_internal_bss *bss;
654 bss = container_of(pub, struct cfg80211_internal_bss, pub);
656 spin_lock_bh(&dev->bss_lock);
658 list_del(&bss->list);
659 dev->bss_generation++;
660 rb_erase(&bss->rbn, &dev->bss_tree);
662 spin_unlock_bh(&dev->bss_lock);
664 kref_put(&bss->ref, bss_release);
666 EXPORT_SYMBOL(cfg80211_unlink_bss);
668 #ifdef CONFIG_CFG80211_WEXT
669 int cfg80211_wext_siwscan(struct net_device *dev,
670 struct iw_request_info *info,
671 union iwreq_data *wrqu, char *extra)
673 struct cfg80211_registered_device *rdev;
675 struct iw_scan_req *wreq = NULL;
676 struct cfg80211_scan_request *creq = NULL;
677 int i, err, n_channels = 0;
678 enum ieee80211_band band;
680 if (!netif_running(dev))
683 if (wrqu->data.length == sizeof(struct iw_scan_req))
684 wreq = (struct iw_scan_req *)extra;
686 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
689 return PTR_ERR(rdev);
691 if (rdev->scan_req) {
696 wiphy = &rdev->wiphy;
698 /* Determine number of channels, needed to allocate creq */
699 if (wreq && wreq->num_channels)
700 n_channels = wreq->num_channels;
702 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
703 if (wiphy->bands[band])
704 n_channels += wiphy->bands[band]->n_channels;
707 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
708 n_channels * sizeof(void *),
717 /* SSIDs come after channels */
718 creq->ssids = (void *)&creq->channels[n_channels];
719 creq->n_channels = n_channels;
722 /* translate "Scan on frequencies" request */
724 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
727 if (!wiphy->bands[band])
730 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
731 /* ignore disabled channels */
732 if (wiphy->bands[band]->channels[j].flags &
733 IEEE80211_CHAN_DISABLED)
736 /* If we have a wireless request structure and the
737 * wireless request specifies frequencies, then search
738 * for the matching hardware channel.
740 if (wreq && wreq->num_channels) {
742 int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
743 for (k = 0; k < wreq->num_channels; k++) {
744 int wext_freq = cfg80211_wext_freq(wiphy, &wreq->channel_list[k]);
745 if (wext_freq == wiphy_freq)
746 goto wext_freq_found;
748 goto wext_freq_not_found;
752 creq->channels[i] = &wiphy->bands[band]->channels[j];
754 wext_freq_not_found: ;
757 /* No channels found? */
763 /* Set real number of channels specified in creq->channels[] */
764 creq->n_channels = i;
766 /* translate "Scan for SSID" request */
768 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
769 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
773 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
774 creq->ssids[0].ssid_len = wreq->essid_len;
776 if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
780 rdev->scan_req = creq;
781 err = rdev->ops->scan(wiphy, dev, creq);
783 rdev->scan_req = NULL;
784 /* creq will be freed below */
786 nl80211_send_scan_start(rdev, dev);
787 /* creq now owned by driver */
793 cfg80211_unlock_rdev(rdev);
796 EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan);
798 static void ieee80211_scan_add_ies(struct iw_request_info *info,
799 struct cfg80211_bss *bss,
800 char **current_ev, char *end_buf)
802 u8 *pos, *end, *next;
805 if (!bss->information_elements ||
806 !bss->len_information_elements)
810 * If needed, fragment the IEs buffer (at IE boundaries) into short
811 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
813 pos = bss->information_elements;
814 end = pos + bss->len_information_elements;
816 while (end - pos > IW_GENERIC_IE_MAX) {
817 next = pos + 2 + pos[1];
818 while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
819 next = next + 2 + next[1];
821 memset(&iwe, 0, sizeof(iwe));
823 iwe.u.data.length = next - pos;
824 *current_ev = iwe_stream_add_point(info, *current_ev,
831 memset(&iwe, 0, sizeof(iwe));
833 iwe.u.data.length = end - pos;
834 *current_ev = iwe_stream_add_point(info, *current_ev,
839 static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
841 unsigned long end = jiffies;
844 return jiffies_to_msecs(end - start);
846 return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
850 ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
851 struct cfg80211_internal_bss *bss, char *current_ev,
856 u8 *ie = bss->pub.information_elements;
857 int rem = bss->pub.len_information_elements, i, sig;
860 memset(&iwe, 0, sizeof(iwe));
862 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
863 memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
864 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
867 memset(&iwe, 0, sizeof(iwe));
868 iwe.cmd = SIOCGIWFREQ;
869 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
871 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
874 memset(&iwe, 0, sizeof(iwe));
875 iwe.cmd = SIOCGIWFREQ;
876 iwe.u.freq.m = bss->pub.channel->center_freq;
878 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
881 if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) {
882 memset(&iwe, 0, sizeof(iwe));
884 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
885 IW_QUAL_NOISE_INVALID |
886 IW_QUAL_QUAL_UPDATED;
887 switch (wiphy->signal_type) {
888 case CFG80211_SIGNAL_TYPE_MBM:
889 sig = bss->pub.signal / 100;
890 iwe.u.qual.level = sig;
891 iwe.u.qual.updated |= IW_QUAL_DBM;
892 if (sig < -110) /* rather bad */
894 else if (sig > -40) /* perfect */
896 /* will give a range of 0 .. 70 */
897 iwe.u.qual.qual = sig + 110;
899 case CFG80211_SIGNAL_TYPE_UNSPEC:
900 iwe.u.qual.level = bss->pub.signal;
901 /* will give range 0 .. 100 */
902 iwe.u.qual.qual = bss->pub.signal;
908 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
909 &iwe, IW_EV_QUAL_LEN);
912 memset(&iwe, 0, sizeof(iwe));
913 iwe.cmd = SIOCGIWENCODE;
914 if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
915 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
917 iwe.u.data.flags = IW_ENCODE_DISABLED;
918 iwe.u.data.length = 0;
919 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
929 memset(&iwe, 0, sizeof(iwe));
930 iwe.cmd = SIOCGIWESSID;
931 iwe.u.data.length = ie[1];
932 iwe.u.data.flags = 1;
933 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
936 case WLAN_EID_MESH_ID:
937 memset(&iwe, 0, sizeof(iwe));
938 iwe.cmd = SIOCGIWESSID;
939 iwe.u.data.length = ie[1];
940 iwe.u.data.flags = 1;
941 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
944 case WLAN_EID_MESH_CONFIG:
946 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
948 buf = kmalloc(50, GFP_ATOMIC);
952 memset(&iwe, 0, sizeof(iwe));
953 iwe.cmd = IWEVCUSTOM;
954 sprintf(buf, "Mesh Network Path Selection Protocol ID: "
956 iwe.u.data.length = strlen(buf);
957 current_ev = iwe_stream_add_point(info, current_ev,
960 sprintf(buf, "Path Selection Metric ID: 0x%02X",
962 iwe.u.data.length = strlen(buf);
963 current_ev = iwe_stream_add_point(info, current_ev,
966 sprintf(buf, "Congestion Control Mode ID: 0x%02X",
968 iwe.u.data.length = strlen(buf);
969 current_ev = iwe_stream_add_point(info, current_ev,
972 sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
973 iwe.u.data.length = strlen(buf);
974 current_ev = iwe_stream_add_point(info, current_ev,
977 sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
978 iwe.u.data.length = strlen(buf);
979 current_ev = iwe_stream_add_point(info, current_ev,
982 sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
983 iwe.u.data.length = strlen(buf);
984 current_ev = iwe_stream_add_point(info, current_ev,
987 sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
988 iwe.u.data.length = strlen(buf);
989 current_ev = iwe_stream_add_point(info, current_ev,
994 case WLAN_EID_SUPP_RATES:
995 case WLAN_EID_EXT_SUPP_RATES:
996 /* display all supported rates in readable format */
997 p = current_ev + iwe_stream_lcp_len(info);
999 memset(&iwe, 0, sizeof(iwe));
1000 iwe.cmd = SIOCGIWRATE;
1001 /* Those two flags are ignored... */
1002 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1004 for (i = 0; i < ie[1]; i++) {
1005 iwe.u.bitrate.value =
1006 ((ie[i + 2] & 0x7f) * 500000);
1007 p = iwe_stream_add_value(info, current_ev, p,
1008 end_buf, &iwe, IW_EV_PARAM_LEN);
1017 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) ||
1019 memset(&iwe, 0, sizeof(iwe));
1020 iwe.cmd = SIOCGIWMODE;
1022 iwe.u.mode = IW_MODE_MESH;
1023 else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
1024 iwe.u.mode = IW_MODE_MASTER;
1026 iwe.u.mode = IW_MODE_ADHOC;
1027 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1028 &iwe, IW_EV_UINT_LEN);
1031 buf = kmalloc(30, GFP_ATOMIC);
1033 memset(&iwe, 0, sizeof(iwe));
1034 iwe.cmd = IWEVCUSTOM;
1035 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->pub.tsf));
1036 iwe.u.data.length = strlen(buf);
1037 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1039 memset(&iwe, 0, sizeof(iwe));
1040 iwe.cmd = IWEVCUSTOM;
1041 sprintf(buf, " Last beacon: %ums ago",
1042 elapsed_jiffies_msecs(bss->ts));
1043 iwe.u.data.length = strlen(buf);
1044 current_ev = iwe_stream_add_point(info, current_ev,
1045 end_buf, &iwe, buf);
1049 ieee80211_scan_add_ies(info, &bss->pub, ¤t_ev, end_buf);
1055 static int ieee80211_scan_results(struct cfg80211_registered_device *dev,
1056 struct iw_request_info *info,
1057 char *buf, size_t len)
1059 char *current_ev = buf;
1060 char *end_buf = buf + len;
1061 struct cfg80211_internal_bss *bss;
1063 spin_lock_bh(&dev->bss_lock);
1064 cfg80211_bss_expire(dev);
1066 list_for_each_entry(bss, &dev->bss_list, list) {
1067 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
1068 spin_unlock_bh(&dev->bss_lock);
1071 current_ev = ieee80211_bss(&dev->wiphy, info, bss,
1072 current_ev, end_buf);
1074 spin_unlock_bh(&dev->bss_lock);
1075 return current_ev - buf;
1079 int cfg80211_wext_giwscan(struct net_device *dev,
1080 struct iw_request_info *info,
1081 struct iw_point *data, char *extra)
1083 struct cfg80211_registered_device *rdev;
1086 if (!netif_running(dev))
1089 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
1092 return PTR_ERR(rdev);
1094 if (rdev->scan_req) {
1099 res = ieee80211_scan_results(rdev, info, extra, data->length);
1107 cfg80211_unlock_rdev(rdev);
1110 EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan);