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 static u8 *find_ie(u8 num, u8 *ies, int len)
148 while (len > 2 && ies[0] != num) {
154 if (len < 2 + ies[1])
159 static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2)
161 const u8 *ie1 = find_ie(num, ies1, len1);
162 const u8 *ie2 = find_ie(num, ies2, len2);
170 r = memcmp(ie1 + 2, ie2 + 2, min(ie1[1], ie2[1]));
171 if (r == 0 && ie1[1] != ie2[1])
172 return ie2[1] - ie1[1];
176 static bool is_bss(struct cfg80211_bss *a,
178 const u8 *ssid, size_t ssid_len)
182 if (bssid && compare_ether_addr(a->bssid, bssid))
188 ssidie = find_ie(WLAN_EID_SSID,
189 a->information_elements,
190 a->len_information_elements);
193 if (ssidie[1] != ssid_len)
195 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
198 static bool is_mesh(struct cfg80211_bss *a,
199 const u8 *meshid, size_t meshidlen,
204 if (!is_zero_ether_addr(a->bssid))
207 ie = find_ie(WLAN_EID_MESH_ID,
208 a->information_elements,
209 a->len_information_elements);
212 if (ie[1] != meshidlen)
214 if (memcmp(ie + 2, meshid, meshidlen))
217 ie = find_ie(WLAN_EID_MESH_CONFIG,
218 a->information_elements,
219 a->len_information_elements);
222 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
226 * Ignore mesh capability (last two bytes of the IE) when
227 * comparing since that may differ between stations taking
228 * part in the same mesh.
230 return memcmp(ie + 2, meshcfg,
231 sizeof(struct ieee80211_meshconf_ie) - 2) == 0;
234 static int cmp_bss(struct cfg80211_bss *a,
235 struct cfg80211_bss *b)
239 if (a->channel != b->channel)
240 return b->channel->center_freq - a->channel->center_freq;
242 r = memcmp(a->bssid, b->bssid, ETH_ALEN);
246 if (is_zero_ether_addr(a->bssid)) {
247 r = cmp_ies(WLAN_EID_MESH_ID,
248 a->information_elements,
249 a->len_information_elements,
250 b->information_elements,
251 b->len_information_elements);
254 return cmp_ies(WLAN_EID_MESH_CONFIG,
255 a->information_elements,
256 a->len_information_elements,
257 b->information_elements,
258 b->len_information_elements);
261 return cmp_ies(WLAN_EID_SSID,
262 a->information_elements,
263 a->len_information_elements,
264 b->information_elements,
265 b->len_information_elements);
268 struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
269 struct ieee80211_channel *channel,
271 const u8 *ssid, size_t ssid_len,
272 u16 capa_mask, u16 capa_val)
274 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
275 struct cfg80211_internal_bss *bss, *res = NULL;
277 spin_lock_bh(&dev->bss_lock);
279 list_for_each_entry(bss, &dev->bss_list, list) {
280 if ((bss->pub.capability & capa_mask) != capa_val)
282 if (channel && bss->pub.channel != channel)
284 if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
291 spin_unlock_bh(&dev->bss_lock);
296 EXPORT_SYMBOL(cfg80211_get_bss);
298 struct cfg80211_bss *cfg80211_get_mesh(struct wiphy *wiphy,
299 struct ieee80211_channel *channel,
300 const u8 *meshid, size_t meshidlen,
303 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
304 struct cfg80211_internal_bss *bss, *res = NULL;
306 spin_lock_bh(&dev->bss_lock);
308 list_for_each_entry(bss, &dev->bss_list, list) {
309 if (channel && bss->pub.channel != channel)
311 if (is_mesh(&bss->pub, meshid, meshidlen, meshcfg)) {
318 spin_unlock_bh(&dev->bss_lock);
323 EXPORT_SYMBOL(cfg80211_get_mesh);
326 static void rb_insert_bss(struct cfg80211_registered_device *dev,
327 struct cfg80211_internal_bss *bss)
329 struct rb_node **p = &dev->bss_tree.rb_node;
330 struct rb_node *parent = NULL;
331 struct cfg80211_internal_bss *tbss;
336 tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
338 cmp = cmp_bss(&bss->pub, &tbss->pub);
341 /* will sort of leak this BSS */
351 rb_link_node(&bss->rbn, parent, p);
352 rb_insert_color(&bss->rbn, &dev->bss_tree);
355 static struct cfg80211_internal_bss *
356 rb_find_bss(struct cfg80211_registered_device *dev,
357 struct cfg80211_internal_bss *res)
359 struct rb_node *n = dev->bss_tree.rb_node;
360 struct cfg80211_internal_bss *bss;
364 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
365 r = cmp_bss(&res->pub, &bss->pub);
378 static struct cfg80211_internal_bss *
379 cfg80211_bss_update(struct cfg80211_registered_device *dev,
380 struct cfg80211_internal_bss *res)
382 struct cfg80211_internal_bss *found = NULL;
383 const u8 *meshid, *meshcfg;
386 * The reference to "res" is donated to this function.
389 if (WARN_ON(!res->pub.channel)) {
390 kref_put(&res->ref, bss_release);
396 if (is_zero_ether_addr(res->pub.bssid)) {
397 /* must be mesh, verify */
398 meshid = find_ie(WLAN_EID_MESH_ID, res->pub.information_elements,
399 res->pub.len_information_elements);
400 meshcfg = find_ie(WLAN_EID_MESH_CONFIG,
401 res->pub.information_elements,
402 res->pub.len_information_elements);
403 if (!meshid || !meshcfg ||
404 meshcfg[1] != sizeof(struct ieee80211_meshconf_ie)) {
406 kref_put(&res->ref, bss_release);
411 spin_lock_bh(&dev->bss_lock);
413 found = rb_find_bss(dev, res);
416 found->pub.beacon_interval = res->pub.beacon_interval;
417 found->pub.tsf = res->pub.tsf;
418 found->pub.signal = res->pub.signal;
419 found->pub.capability = res->pub.capability;
423 if (res->pub.proberesp_ies) {
424 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
425 size_t ielen = res->pub.len_proberesp_ies;
427 if (found->pub.proberesp_ies &&
428 !found->proberesp_ies_allocated &&
429 ksize(found) >= used + ielen) {
430 memcpy(found->pub.proberesp_ies,
431 res->pub.proberesp_ies, ielen);
432 found->pub.len_proberesp_ies = ielen;
434 u8 *ies = found->pub.proberesp_ies;
436 if (found->proberesp_ies_allocated)
437 ies = krealloc(ies, ielen, GFP_ATOMIC);
439 ies = kmalloc(ielen, GFP_ATOMIC);
442 memcpy(ies, res->pub.proberesp_ies,
444 found->proberesp_ies_allocated = true;
445 found->pub.proberesp_ies = ies;
446 found->pub.len_proberesp_ies = ielen;
450 /* Override possible earlier Beacon frame IEs */
451 found->pub.information_elements =
452 found->pub.proberesp_ies;
453 found->pub.len_information_elements =
454 found->pub.len_proberesp_ies;
456 if (res->pub.beacon_ies) {
457 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
458 size_t ielen = res->pub.len_beacon_ies;
460 if (found->pub.beacon_ies &&
461 !found->beacon_ies_allocated &&
462 ksize(found) >= used + ielen) {
463 memcpy(found->pub.beacon_ies,
464 res->pub.beacon_ies, ielen);
465 found->pub.len_beacon_ies = ielen;
467 u8 *ies = found->pub.beacon_ies;
469 if (found->beacon_ies_allocated)
470 ies = krealloc(ies, ielen, GFP_ATOMIC);
472 ies = kmalloc(ielen, GFP_ATOMIC);
475 memcpy(ies, res->pub.beacon_ies,
477 found->beacon_ies_allocated = true;
478 found->pub.beacon_ies = ies;
479 found->pub.len_beacon_ies = ielen;
484 kref_put(&res->ref, bss_release);
486 /* this "consumes" the reference */
487 list_add_tail(&res->list, &dev->bss_list);
488 rb_insert_bss(dev, res);
492 dev->bss_generation++;
493 spin_unlock_bh(&dev->bss_lock);
495 kref_get(&found->ref);
500 cfg80211_inform_bss(struct wiphy *wiphy,
501 struct ieee80211_channel *channel,
503 u64 timestamp, u16 capability, u16 beacon_interval,
504 const u8 *ie, size_t ielen,
505 s32 signal, gfp_t gfp)
507 struct cfg80211_internal_bss *res;
513 privsz = wiphy->bss_priv_size;
515 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
516 (signal < 0 || signal > 100)))
519 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
523 memcpy(res->pub.bssid, bssid, ETH_ALEN);
524 res->pub.channel = channel;
525 res->pub.signal = signal;
526 res->pub.tsf = timestamp;
527 res->pub.beacon_interval = beacon_interval;
528 res->pub.capability = capability;
530 * Since we do not know here whether the IEs are from a Beacon or Probe
531 * Response frame, we need to pick one of the options and only use it
532 * with the driver that does not provide the full Beacon/Probe Response
533 * frame. Use Beacon frame pointer to avoid indicating that this should
534 * override the information_elements pointer should we have received an
535 * earlier indication of Probe Response data.
537 * The initial buffer for the IEs is allocated with the BSS entry and
538 * is located after the private area.
540 res->pub.beacon_ies = (u8 *)res + sizeof(*res) + privsz;
541 memcpy(res->pub.beacon_ies, ie, ielen);
542 res->pub.len_beacon_ies = ielen;
543 res->pub.information_elements = res->pub.beacon_ies;
544 res->pub.len_information_elements = res->pub.len_beacon_ies;
546 kref_init(&res->ref);
548 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
552 if (res->pub.capability & WLAN_CAPABILITY_ESS)
553 regulatory_hint_found_beacon(wiphy, channel, gfp);
555 /* cfg80211_bss_update gives us a referenced result */
558 EXPORT_SYMBOL(cfg80211_inform_bss);
560 struct cfg80211_bss *
561 cfg80211_inform_bss_frame(struct wiphy *wiphy,
562 struct ieee80211_channel *channel,
563 struct ieee80211_mgmt *mgmt, size_t len,
564 s32 signal, gfp_t gfp)
566 struct cfg80211_internal_bss *res;
567 size_t ielen = len - offsetof(struct ieee80211_mgmt,
568 u.probe_resp.variable);
569 size_t privsz = wiphy->bss_priv_size;
571 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
572 (signal < 0 || signal > 100)))
575 if (WARN_ON(!mgmt || !wiphy ||
576 len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
579 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
583 memcpy(res->pub.bssid, mgmt->bssid, ETH_ALEN);
584 res->pub.channel = channel;
585 res->pub.signal = signal;
586 res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
587 res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
588 res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
590 * The initial buffer for the IEs is allocated with the BSS entry and
591 * is located after the private area.
593 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
594 res->pub.proberesp_ies = (u8 *) res + sizeof(*res) + privsz;
595 memcpy(res->pub.proberesp_ies, mgmt->u.probe_resp.variable,
597 res->pub.len_proberesp_ies = ielen;
598 res->pub.information_elements = res->pub.proberesp_ies;
599 res->pub.len_information_elements = res->pub.len_proberesp_ies;
601 res->pub.beacon_ies = (u8 *) res + sizeof(*res) + privsz;
602 memcpy(res->pub.beacon_ies, mgmt->u.beacon.variable, ielen);
603 res->pub.len_beacon_ies = ielen;
604 res->pub.information_elements = res->pub.beacon_ies;
605 res->pub.len_information_elements = res->pub.len_beacon_ies;
608 kref_init(&res->ref);
610 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
614 if (res->pub.capability & WLAN_CAPABILITY_ESS)
615 regulatory_hint_found_beacon(wiphy, channel, gfp);
617 /* cfg80211_bss_update gives us a referenced result */
620 EXPORT_SYMBOL(cfg80211_inform_bss_frame);
622 void cfg80211_put_bss(struct cfg80211_bss *pub)
624 struct cfg80211_internal_bss *bss;
629 bss = container_of(pub, struct cfg80211_internal_bss, pub);
630 kref_put(&bss->ref, bss_release);
632 EXPORT_SYMBOL(cfg80211_put_bss);
634 void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
636 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
637 struct cfg80211_internal_bss *bss;
642 bss = container_of(pub, struct cfg80211_internal_bss, pub);
644 spin_lock_bh(&dev->bss_lock);
646 list_del(&bss->list);
647 dev->bss_generation++;
648 rb_erase(&bss->rbn, &dev->bss_tree);
650 spin_unlock_bh(&dev->bss_lock);
652 kref_put(&bss->ref, bss_release);
654 EXPORT_SYMBOL(cfg80211_unlink_bss);
656 #ifdef CONFIG_CFG80211_WEXT
657 int cfg80211_wext_siwscan(struct net_device *dev,
658 struct iw_request_info *info,
659 union iwreq_data *wrqu, char *extra)
661 struct cfg80211_registered_device *rdev;
663 struct iw_scan_req *wreq = NULL;
664 struct cfg80211_scan_request *creq = NULL;
665 int i, err, n_channels = 0;
666 enum ieee80211_band band;
668 if (!netif_running(dev))
671 if (wrqu->data.length == sizeof(struct iw_scan_req))
672 wreq = (struct iw_scan_req *)extra;
674 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
677 return PTR_ERR(rdev);
679 if (rdev->scan_req) {
684 wiphy = &rdev->wiphy;
686 /* Determine number of channels, needed to allocate creq */
687 if (wreq && wreq->num_channels)
688 n_channels = wreq->num_channels;
690 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
691 if (wiphy->bands[band])
692 n_channels += wiphy->bands[band]->n_channels;
695 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
696 n_channels * sizeof(void *),
705 /* SSIDs come after channels */
706 creq->ssids = (void *)&creq->channels[n_channels];
707 creq->n_channels = n_channels;
710 /* translate "Scan on frequencies" request */
712 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
715 if (!wiphy->bands[band])
718 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
719 /* ignore disabled channels */
720 if (wiphy->bands[band]->channels[j].flags &
721 IEEE80211_CHAN_DISABLED)
724 /* If we have a wireless request structure and the
725 * wireless request specifies frequencies, then search
726 * for the matching hardware channel.
728 if (wreq && wreq->num_channels) {
730 int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
731 for (k = 0; k < wreq->num_channels; k++) {
732 int wext_freq = cfg80211_wext_freq(wiphy, &wreq->channel_list[k]);
733 if (wext_freq == wiphy_freq)
734 goto wext_freq_found;
736 goto wext_freq_not_found;
740 creq->channels[i] = &wiphy->bands[band]->channels[j];
742 wext_freq_not_found: ;
745 /* No channels found? */
751 /* Set real number of channels specified in creq->channels[] */
752 creq->n_channels = i;
754 /* translate "Scan for SSID" request */
756 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
757 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
761 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
762 creq->ssids[0].ssid_len = wreq->essid_len;
764 if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
768 rdev->scan_req = creq;
769 err = rdev->ops->scan(wiphy, dev, creq);
771 rdev->scan_req = NULL;
772 /* creq will be freed below */
774 nl80211_send_scan_start(rdev, dev);
775 /* creq now owned by driver */
781 cfg80211_unlock_rdev(rdev);
784 EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan);
786 static void ieee80211_scan_add_ies(struct iw_request_info *info,
787 struct cfg80211_bss *bss,
788 char **current_ev, char *end_buf)
790 u8 *pos, *end, *next;
793 if (!bss->information_elements ||
794 !bss->len_information_elements)
798 * If needed, fragment the IEs buffer (at IE boundaries) into short
799 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
801 pos = bss->information_elements;
802 end = pos + bss->len_information_elements;
804 while (end - pos > IW_GENERIC_IE_MAX) {
805 next = pos + 2 + pos[1];
806 while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
807 next = next + 2 + next[1];
809 memset(&iwe, 0, sizeof(iwe));
811 iwe.u.data.length = next - pos;
812 *current_ev = iwe_stream_add_point(info, *current_ev,
819 memset(&iwe, 0, sizeof(iwe));
821 iwe.u.data.length = end - pos;
822 *current_ev = iwe_stream_add_point(info, *current_ev,
827 static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
829 unsigned long end = jiffies;
832 return jiffies_to_msecs(end - start);
834 return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
838 ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
839 struct cfg80211_internal_bss *bss, char *current_ev,
844 u8 *ie = bss->pub.information_elements;
845 int rem = bss->pub.len_information_elements, i, sig;
848 memset(&iwe, 0, sizeof(iwe));
850 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
851 memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
852 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
855 memset(&iwe, 0, sizeof(iwe));
856 iwe.cmd = SIOCGIWFREQ;
857 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
859 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
862 memset(&iwe, 0, sizeof(iwe));
863 iwe.cmd = SIOCGIWFREQ;
864 iwe.u.freq.m = bss->pub.channel->center_freq;
866 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
869 if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) {
870 memset(&iwe, 0, sizeof(iwe));
872 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
873 IW_QUAL_NOISE_INVALID |
874 IW_QUAL_QUAL_UPDATED;
875 switch (wiphy->signal_type) {
876 case CFG80211_SIGNAL_TYPE_MBM:
877 sig = bss->pub.signal / 100;
878 iwe.u.qual.level = sig;
879 iwe.u.qual.updated |= IW_QUAL_DBM;
880 if (sig < -110) /* rather bad */
882 else if (sig > -40) /* perfect */
884 /* will give a range of 0 .. 70 */
885 iwe.u.qual.qual = sig + 110;
887 case CFG80211_SIGNAL_TYPE_UNSPEC:
888 iwe.u.qual.level = bss->pub.signal;
889 /* will give range 0 .. 100 */
890 iwe.u.qual.qual = bss->pub.signal;
896 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
897 &iwe, IW_EV_QUAL_LEN);
900 memset(&iwe, 0, sizeof(iwe));
901 iwe.cmd = SIOCGIWENCODE;
902 if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
903 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
905 iwe.u.data.flags = IW_ENCODE_DISABLED;
906 iwe.u.data.length = 0;
907 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
917 memset(&iwe, 0, sizeof(iwe));
918 iwe.cmd = SIOCGIWESSID;
919 iwe.u.data.length = ie[1];
920 iwe.u.data.flags = 1;
921 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
924 case WLAN_EID_MESH_ID:
925 memset(&iwe, 0, sizeof(iwe));
926 iwe.cmd = SIOCGIWESSID;
927 iwe.u.data.length = ie[1];
928 iwe.u.data.flags = 1;
929 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
932 case WLAN_EID_MESH_CONFIG:
934 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
936 buf = kmalloc(50, GFP_ATOMIC);
940 memset(&iwe, 0, sizeof(iwe));
941 iwe.cmd = IWEVCUSTOM;
942 sprintf(buf, "Mesh Network Path Selection Protocol ID: "
944 iwe.u.data.length = strlen(buf);
945 current_ev = iwe_stream_add_point(info, current_ev,
948 sprintf(buf, "Path Selection Metric ID: 0x%02X",
950 iwe.u.data.length = strlen(buf);
951 current_ev = iwe_stream_add_point(info, current_ev,
954 sprintf(buf, "Congestion Control Mode ID: 0x%02X",
956 iwe.u.data.length = strlen(buf);
957 current_ev = iwe_stream_add_point(info, current_ev,
960 sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
961 iwe.u.data.length = strlen(buf);
962 current_ev = iwe_stream_add_point(info, current_ev,
965 sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
966 iwe.u.data.length = strlen(buf);
967 current_ev = iwe_stream_add_point(info, current_ev,
970 sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
971 iwe.u.data.length = strlen(buf);
972 current_ev = iwe_stream_add_point(info, current_ev,
975 sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
976 iwe.u.data.length = strlen(buf);
977 current_ev = iwe_stream_add_point(info, current_ev,
982 case WLAN_EID_SUPP_RATES:
983 case WLAN_EID_EXT_SUPP_RATES:
984 /* display all supported rates in readable format */
985 p = current_ev + iwe_stream_lcp_len(info);
987 memset(&iwe, 0, sizeof(iwe));
988 iwe.cmd = SIOCGIWRATE;
989 /* Those two flags are ignored... */
990 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
992 for (i = 0; i < ie[1]; i++) {
993 iwe.u.bitrate.value =
994 ((ie[i + 2] & 0x7f) * 500000);
995 p = iwe_stream_add_value(info, current_ev, p,
996 end_buf, &iwe, IW_EV_PARAM_LEN);
1005 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) ||
1007 memset(&iwe, 0, sizeof(iwe));
1008 iwe.cmd = SIOCGIWMODE;
1010 iwe.u.mode = IW_MODE_MESH;
1011 else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
1012 iwe.u.mode = IW_MODE_MASTER;
1014 iwe.u.mode = IW_MODE_ADHOC;
1015 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1016 &iwe, IW_EV_UINT_LEN);
1019 buf = kmalloc(30, GFP_ATOMIC);
1021 memset(&iwe, 0, sizeof(iwe));
1022 iwe.cmd = IWEVCUSTOM;
1023 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->pub.tsf));
1024 iwe.u.data.length = strlen(buf);
1025 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1027 memset(&iwe, 0, sizeof(iwe));
1028 iwe.cmd = IWEVCUSTOM;
1029 sprintf(buf, " Last beacon: %ums ago",
1030 elapsed_jiffies_msecs(bss->ts));
1031 iwe.u.data.length = strlen(buf);
1032 current_ev = iwe_stream_add_point(info, current_ev,
1033 end_buf, &iwe, buf);
1037 ieee80211_scan_add_ies(info, &bss->pub, ¤t_ev, end_buf);
1043 static int ieee80211_scan_results(struct cfg80211_registered_device *dev,
1044 struct iw_request_info *info,
1045 char *buf, size_t len)
1047 char *current_ev = buf;
1048 char *end_buf = buf + len;
1049 struct cfg80211_internal_bss *bss;
1051 spin_lock_bh(&dev->bss_lock);
1052 cfg80211_bss_expire(dev);
1054 list_for_each_entry(bss, &dev->bss_list, list) {
1055 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
1056 spin_unlock_bh(&dev->bss_lock);
1059 current_ev = ieee80211_bss(&dev->wiphy, info, bss,
1060 current_ev, end_buf);
1062 spin_unlock_bh(&dev->bss_lock);
1063 return current_ev - buf;
1067 int cfg80211_wext_giwscan(struct net_device *dev,
1068 struct iw_request_info *info,
1069 struct iw_point *data, char *extra)
1071 struct cfg80211_registered_device *rdev;
1074 if (!netif_running(dev))
1077 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
1080 return PTR_ERR(rdev);
1082 if (rdev->scan_req) {
1087 res = ieee80211_scan_results(rdev, info, extra, data->length);
1095 cfg80211_unlock_rdev(rdev);
1098 EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan);