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);
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) {
96 !time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE))
99 rb_erase(&bss->rbn, &dev->bss_tree);
100 kref_put(&bss->ref, bss_release);
105 dev->bss_generation++;
108 static u8 *find_ie(u8 num, u8 *ies, size_t len)
110 while (len > 2 && ies[0] != num) {
116 if (len < 2 + ies[1])
121 static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2)
123 const u8 *ie1 = find_ie(num, ies1, len1);
124 const u8 *ie2 = find_ie(num, ies2, len2);
132 r = memcmp(ie1 + 2, ie2 + 2, min(ie1[1], ie2[1]));
133 if (r == 0 && ie1[1] != ie2[1])
134 return ie2[1] - ie1[1];
138 static bool is_bss(struct cfg80211_bss *a,
140 const u8 *ssid, size_t ssid_len)
144 if (bssid && compare_ether_addr(a->bssid, bssid))
150 ssidie = find_ie(WLAN_EID_SSID,
151 a->information_elements,
152 a->len_information_elements);
155 if (ssidie[1] != ssid_len)
157 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
160 static bool is_mesh(struct cfg80211_bss *a,
161 const u8 *meshid, size_t meshidlen,
166 if (!is_zero_ether_addr(a->bssid))
169 ie = find_ie(WLAN_EID_MESH_ID,
170 a->information_elements,
171 a->len_information_elements);
174 if (ie[1] != meshidlen)
176 if (memcmp(ie + 2, meshid, meshidlen))
179 ie = find_ie(WLAN_EID_MESH_CONFIG,
180 a->information_elements,
181 a->len_information_elements);
182 if (ie[1] != IEEE80211_MESH_CONFIG_LEN)
186 * Ignore mesh capability (last two bytes of the IE) when
187 * comparing since that may differ between stations taking
188 * part in the same mesh.
190 return memcmp(ie + 2, meshcfg, IEEE80211_MESH_CONFIG_LEN - 2) == 0;
193 static int cmp_bss(struct cfg80211_bss *a,
194 struct cfg80211_bss *b)
198 if (a->channel != b->channel)
199 return b->channel->center_freq - a->channel->center_freq;
201 r = memcmp(a->bssid, b->bssid, ETH_ALEN);
205 if (is_zero_ether_addr(a->bssid)) {
206 r = cmp_ies(WLAN_EID_MESH_ID,
207 a->information_elements,
208 a->len_information_elements,
209 b->information_elements,
210 b->len_information_elements);
213 return cmp_ies(WLAN_EID_MESH_CONFIG,
214 a->information_elements,
215 a->len_information_elements,
216 b->information_elements,
217 b->len_information_elements);
220 return cmp_ies(WLAN_EID_SSID,
221 a->information_elements,
222 a->len_information_elements,
223 b->information_elements,
224 b->len_information_elements);
227 struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
228 struct ieee80211_channel *channel,
230 const u8 *ssid, size_t ssid_len,
231 u16 capa_mask, u16 capa_val)
233 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
234 struct cfg80211_internal_bss *bss, *res = NULL;
236 spin_lock_bh(&dev->bss_lock);
238 list_for_each_entry(bss, &dev->bss_list, list) {
239 if ((bss->pub.capability & capa_mask) != capa_val)
241 if (channel && bss->pub.channel != channel)
243 if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
250 spin_unlock_bh(&dev->bss_lock);
255 EXPORT_SYMBOL(cfg80211_get_bss);
257 struct cfg80211_bss *cfg80211_get_mesh(struct wiphy *wiphy,
258 struct ieee80211_channel *channel,
259 const u8 *meshid, size_t meshidlen,
262 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
263 struct cfg80211_internal_bss *bss, *res = NULL;
265 spin_lock_bh(&dev->bss_lock);
267 list_for_each_entry(bss, &dev->bss_list, list) {
268 if (channel && bss->pub.channel != channel)
270 if (is_mesh(&bss->pub, meshid, meshidlen, meshcfg)) {
277 spin_unlock_bh(&dev->bss_lock);
282 EXPORT_SYMBOL(cfg80211_get_mesh);
285 static void rb_insert_bss(struct cfg80211_registered_device *dev,
286 struct cfg80211_internal_bss *bss)
288 struct rb_node **p = &dev->bss_tree.rb_node;
289 struct rb_node *parent = NULL;
290 struct cfg80211_internal_bss *tbss;
295 tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
297 cmp = cmp_bss(&bss->pub, &tbss->pub);
300 /* will sort of leak this BSS */
310 rb_link_node(&bss->rbn, parent, p);
311 rb_insert_color(&bss->rbn, &dev->bss_tree);
314 static struct cfg80211_internal_bss *
315 rb_find_bss(struct cfg80211_registered_device *dev,
316 struct cfg80211_internal_bss *res)
318 struct rb_node *n = dev->bss_tree.rb_node;
319 struct cfg80211_internal_bss *bss;
323 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
324 r = cmp_bss(&res->pub, &bss->pub);
337 static struct cfg80211_internal_bss *
338 cfg80211_bss_update(struct cfg80211_registered_device *dev,
339 struct cfg80211_internal_bss *res,
342 struct cfg80211_internal_bss *found = NULL;
343 const u8 *meshid, *meshcfg;
346 * The reference to "res" is donated to this function.
349 if (WARN_ON(!res->pub.channel)) {
350 kref_put(&res->ref, bss_release);
356 if (is_zero_ether_addr(res->pub.bssid)) {
357 /* must be mesh, verify */
358 meshid = find_ie(WLAN_EID_MESH_ID, res->pub.information_elements,
359 res->pub.len_information_elements);
360 meshcfg = find_ie(WLAN_EID_MESH_CONFIG,
361 res->pub.information_elements,
362 res->pub.len_information_elements);
363 if (!meshid || !meshcfg ||
364 meshcfg[1] != IEEE80211_MESH_CONFIG_LEN) {
366 kref_put(&res->ref, bss_release);
371 spin_lock_bh(&dev->bss_lock);
373 found = rb_find_bss(dev, res);
376 found->pub.beacon_interval = res->pub.beacon_interval;
377 found->pub.tsf = res->pub.tsf;
378 found->pub.signal = res->pub.signal;
379 found->pub.capability = res->pub.capability;
384 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
385 size_t ielen = res->pub.len_information_elements;
387 if (!found->ies_allocated && ksize(found) >= used + ielen) {
388 memcpy(found->pub.information_elements,
389 res->pub.information_elements, ielen);
390 found->pub.len_information_elements = ielen;
392 u8 *ies = found->pub.information_elements;
394 if (found->ies_allocated)
395 ies = krealloc(ies, ielen, GFP_ATOMIC);
397 ies = kmalloc(ielen, GFP_ATOMIC);
400 memcpy(ies, res->pub.information_elements, ielen);
401 found->ies_allocated = true;
402 found->pub.information_elements = ies;
403 found->pub.len_information_elements = ielen;
408 kref_put(&res->ref, bss_release);
410 /* this "consumes" the reference */
411 list_add_tail(&res->list, &dev->bss_list);
412 rb_insert_bss(dev, res);
416 dev->bss_generation++;
417 spin_unlock_bh(&dev->bss_lock);
419 kref_get(&found->ref);
424 cfg80211_inform_bss(struct wiphy *wiphy,
425 struct ieee80211_channel *channel,
427 u64 timestamp, u16 capability, u16 beacon_interval,
428 const u8 *ie, size_t ielen,
429 s32 signal, gfp_t gfp)
431 struct cfg80211_internal_bss *res;
437 privsz = wiphy->bss_priv_size;
439 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
440 (signal < 0 || signal > 100)))
443 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
447 memcpy(res->pub.bssid, bssid, ETH_ALEN);
448 res->pub.channel = channel;
449 res->pub.signal = signal;
450 res->pub.tsf = timestamp;
451 res->pub.beacon_interval = beacon_interval;
452 res->pub.capability = capability;
453 /* point to after the private area */
454 res->pub.information_elements = (u8 *)res + sizeof(*res) + privsz;
455 memcpy(res->pub.information_elements, ie, ielen);
456 res->pub.len_information_elements = ielen;
458 kref_init(&res->ref);
460 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res, 0);
464 if (res->pub.capability & WLAN_CAPABILITY_ESS)
465 regulatory_hint_found_beacon(wiphy, channel, gfp);
467 /* cfg80211_bss_update gives us a referenced result */
470 EXPORT_SYMBOL(cfg80211_inform_bss);
472 struct cfg80211_bss *
473 cfg80211_inform_bss_frame(struct wiphy *wiphy,
474 struct ieee80211_channel *channel,
475 struct ieee80211_mgmt *mgmt, size_t len,
476 s32 signal, gfp_t gfp)
478 struct cfg80211_internal_bss *res;
479 size_t ielen = len - offsetof(struct ieee80211_mgmt,
480 u.probe_resp.variable);
482 size_t privsz = wiphy->bss_priv_size;
484 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
485 (signal < 0 || signal > 100)))
488 if (WARN_ON(!mgmt || !wiphy ||
489 len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
492 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
496 memcpy(res->pub.bssid, mgmt->bssid, ETH_ALEN);
497 res->pub.channel = channel;
498 res->pub.signal = signal;
499 res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
500 res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
501 res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
502 /* point to after the private area */
503 res->pub.information_elements = (u8 *)res + sizeof(*res) + privsz;
504 memcpy(res->pub.information_elements, mgmt->u.probe_resp.variable, ielen);
505 res->pub.len_information_elements = ielen;
507 kref_init(&res->ref);
509 overwrite = ieee80211_is_probe_resp(mgmt->frame_control);
511 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res, overwrite);
515 if (res->pub.capability & WLAN_CAPABILITY_ESS)
516 regulatory_hint_found_beacon(wiphy, channel, gfp);
518 /* cfg80211_bss_update gives us a referenced result */
521 EXPORT_SYMBOL(cfg80211_inform_bss_frame);
523 void cfg80211_put_bss(struct cfg80211_bss *pub)
525 struct cfg80211_internal_bss *bss;
530 bss = container_of(pub, struct cfg80211_internal_bss, pub);
531 kref_put(&bss->ref, bss_release);
533 EXPORT_SYMBOL(cfg80211_put_bss);
535 void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
537 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
538 struct cfg80211_internal_bss *bss;
543 bss = container_of(pub, struct cfg80211_internal_bss, pub);
545 spin_lock_bh(&dev->bss_lock);
547 list_del(&bss->list);
548 rb_erase(&bss->rbn, &dev->bss_tree);
550 spin_unlock_bh(&dev->bss_lock);
552 kref_put(&bss->ref, bss_release);
554 EXPORT_SYMBOL(cfg80211_unlink_bss);
556 void cfg80211_hold_bss(struct cfg80211_bss *pub)
558 struct cfg80211_internal_bss *bss;
563 bss = container_of(pub, struct cfg80211_internal_bss, pub);
566 EXPORT_SYMBOL(cfg80211_hold_bss);
568 void cfg80211_unhold_bss(struct cfg80211_bss *pub)
570 struct cfg80211_internal_bss *bss;
575 bss = container_of(pub, struct cfg80211_internal_bss, pub);
578 EXPORT_SYMBOL(cfg80211_unhold_bss);
580 #ifdef CONFIG_WIRELESS_EXT
581 int cfg80211_wext_siwscan(struct net_device *dev,
582 struct iw_request_info *info,
583 union iwreq_data *wrqu, char *extra)
585 struct cfg80211_registered_device *rdev;
587 struct iw_scan_req *wreq = NULL;
588 struct cfg80211_scan_request *creq;
589 int i, err, n_channels = 0;
590 enum ieee80211_band band;
592 if (!netif_running(dev))
595 rdev = cfg80211_get_dev_from_ifindex(dev->ifindex);
598 return PTR_ERR(rdev);
600 if (rdev->scan_req) {
605 wiphy = &rdev->wiphy;
607 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
608 if (wiphy->bands[band])
609 n_channels += wiphy->bands[band]->n_channels;
611 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
612 n_channels * sizeof(void *),
620 creq->ifidx = dev->ifindex;
621 creq->ssids = (void *)(creq + 1);
622 creq->channels = (void *)(creq->ssids + 1);
623 creq->n_channels = n_channels;
628 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
630 if (!wiphy->bands[band])
632 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
633 creq->channels[i] = &wiphy->bands[band]->channels[j];
638 /* translate scan request */
639 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
640 wreq = (struct iw_scan_req *)extra;
642 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
643 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN)
645 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
646 creq->ssids[0].ssid_len = wreq->essid_len;
648 if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
652 rdev->scan_req = creq;
653 err = rdev->ops->scan(wiphy, dev, creq);
655 rdev->scan_req = NULL;
658 nl80211_send_scan_start(rdev, dev);
660 cfg80211_put_dev(rdev);
663 EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan);
665 static void ieee80211_scan_add_ies(struct iw_request_info *info,
666 struct cfg80211_bss *bss,
667 char **current_ev, char *end_buf)
669 u8 *pos, *end, *next;
672 if (!bss->information_elements ||
673 !bss->len_information_elements)
677 * If needed, fragment the IEs buffer (at IE boundaries) into short
678 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
680 pos = bss->information_elements;
681 end = pos + bss->len_information_elements;
683 while (end - pos > IW_GENERIC_IE_MAX) {
684 next = pos + 2 + pos[1];
685 while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
686 next = next + 2 + next[1];
688 memset(&iwe, 0, sizeof(iwe));
690 iwe.u.data.length = next - pos;
691 *current_ev = iwe_stream_add_point(info, *current_ev,
698 memset(&iwe, 0, sizeof(iwe));
700 iwe.u.data.length = end - pos;
701 *current_ev = iwe_stream_add_point(info, *current_ev,
706 static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
708 unsigned long end = jiffies;
711 return jiffies_to_msecs(end - start);
713 return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
717 ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
718 struct cfg80211_internal_bss *bss, char *current_ev,
723 u8 *ie = bss->pub.information_elements;
724 int rem = bss->pub.len_information_elements, i, sig;
727 memset(&iwe, 0, sizeof(iwe));
729 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
730 memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
731 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
734 memset(&iwe, 0, sizeof(iwe));
735 iwe.cmd = SIOCGIWFREQ;
736 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
738 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
741 memset(&iwe, 0, sizeof(iwe));
742 iwe.cmd = SIOCGIWFREQ;
743 iwe.u.freq.m = bss->pub.channel->center_freq;
745 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
748 if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) {
749 memset(&iwe, 0, sizeof(iwe));
751 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
752 IW_QUAL_NOISE_INVALID |
753 IW_QUAL_QUAL_UPDATED;
754 switch (wiphy->signal_type) {
755 case CFG80211_SIGNAL_TYPE_MBM:
756 sig = bss->pub.signal / 100;
757 iwe.u.qual.level = sig;
758 iwe.u.qual.updated |= IW_QUAL_DBM;
759 if (sig < -110) /* rather bad */
761 else if (sig > -40) /* perfect */
763 /* will give a range of 0 .. 70 */
764 iwe.u.qual.qual = sig + 110;
766 case CFG80211_SIGNAL_TYPE_UNSPEC:
767 iwe.u.qual.level = bss->pub.signal;
768 /* will give range 0 .. 100 */
769 iwe.u.qual.qual = bss->pub.signal;
775 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
776 &iwe, IW_EV_QUAL_LEN);
779 memset(&iwe, 0, sizeof(iwe));
780 iwe.cmd = SIOCGIWENCODE;
781 if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
782 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
784 iwe.u.data.flags = IW_ENCODE_DISABLED;
785 iwe.u.data.length = 0;
786 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
796 memset(&iwe, 0, sizeof(iwe));
797 iwe.cmd = SIOCGIWESSID;
798 iwe.u.data.length = ie[1];
799 iwe.u.data.flags = 1;
800 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
803 case WLAN_EID_MESH_ID:
804 memset(&iwe, 0, sizeof(iwe));
805 iwe.cmd = SIOCGIWESSID;
806 iwe.u.data.length = ie[1];
807 iwe.u.data.flags = 1;
808 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
811 case WLAN_EID_MESH_CONFIG:
813 if (ie[1] != IEEE80211_MESH_CONFIG_LEN)
815 buf = kmalloc(50, GFP_ATOMIC);
819 memset(&iwe, 0, sizeof(iwe));
820 iwe.cmd = IWEVCUSTOM;
821 sprintf(buf, "Mesh network (version %d)", cfg[0]);
822 iwe.u.data.length = strlen(buf);
823 current_ev = iwe_stream_add_point(info, current_ev,
826 sprintf(buf, "Path Selection Protocol ID: "
827 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
829 iwe.u.data.length = strlen(buf);
830 current_ev = iwe_stream_add_point(info, current_ev,
833 sprintf(buf, "Path Selection Metric ID: "
834 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
836 iwe.u.data.length = strlen(buf);
837 current_ev = iwe_stream_add_point(info, current_ev,
840 sprintf(buf, "Congestion Control Mode ID: "
841 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
843 iwe.u.data.length = strlen(buf);
844 current_ev = iwe_stream_add_point(info, current_ev,
847 sprintf(buf, "Channel Precedence: "
848 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
850 iwe.u.data.length = strlen(buf);
851 current_ev = iwe_stream_add_point(info, current_ev,
856 case WLAN_EID_SUPP_RATES:
857 case WLAN_EID_EXT_SUPP_RATES:
858 /* display all supported rates in readable format */
859 p = current_ev + iwe_stream_lcp_len(info);
861 memset(&iwe, 0, sizeof(iwe));
862 iwe.cmd = SIOCGIWRATE;
863 /* Those two flags are ignored... */
864 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
866 for (i = 0; i < ie[1]; i++) {
867 iwe.u.bitrate.value =
868 ((ie[i + 2] & 0x7f) * 500000);
869 p = iwe_stream_add_value(info, current_ev, p,
870 end_buf, &iwe, IW_EV_PARAM_LEN);
879 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
881 memset(&iwe, 0, sizeof(iwe));
882 iwe.cmd = SIOCGIWMODE;
884 iwe.u.mode = IW_MODE_MESH;
885 else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
886 iwe.u.mode = IW_MODE_MASTER;
888 iwe.u.mode = IW_MODE_ADHOC;
889 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
890 &iwe, IW_EV_UINT_LEN);
893 buf = kmalloc(30, GFP_ATOMIC);
895 memset(&iwe, 0, sizeof(iwe));
896 iwe.cmd = IWEVCUSTOM;
897 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->pub.tsf));
898 iwe.u.data.length = strlen(buf);
899 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
901 memset(&iwe, 0, sizeof(iwe));
902 iwe.cmd = IWEVCUSTOM;
903 sprintf(buf, " Last beacon: %ums ago",
904 elapsed_jiffies_msecs(bss->ts));
905 iwe.u.data.length = strlen(buf);
906 current_ev = iwe_stream_add_point(info, current_ev,
911 ieee80211_scan_add_ies(info, &bss->pub, ¤t_ev, end_buf);
917 static int ieee80211_scan_results(struct cfg80211_registered_device *dev,
918 struct iw_request_info *info,
919 char *buf, size_t len)
921 char *current_ev = buf;
922 char *end_buf = buf + len;
923 struct cfg80211_internal_bss *bss;
925 spin_lock_bh(&dev->bss_lock);
926 cfg80211_bss_expire(dev);
928 list_for_each_entry(bss, &dev->bss_list, list) {
929 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
930 spin_unlock_bh(&dev->bss_lock);
933 current_ev = ieee80211_bss(&dev->wiphy, info, bss,
934 current_ev, end_buf);
936 spin_unlock_bh(&dev->bss_lock);
937 return current_ev - buf;
941 int cfg80211_wext_giwscan(struct net_device *dev,
942 struct iw_request_info *info,
943 struct iw_point *data, char *extra)
945 struct cfg80211_registered_device *rdev;
948 if (!netif_running(dev))
951 rdev = cfg80211_get_dev_from_ifindex(dev->ifindex);
954 return PTR_ERR(rdev);
956 if (rdev->scan_req) {
961 res = ieee80211_scan_results(rdev, info, extra, data->length);
969 cfg80211_put_dev(rdev);
972 EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan);