aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless
diff options
context:
space:
mode:
Diffstat (limited to 'net/wireless')
-rw-r--r--net/wireless/Makefile2
-rw-r--r--net/wireless/core.c8
-rw-r--r--net/wireless/core.h20
-rw-r--r--net/wireless/nl80211.c323
-rw-r--r--net/wireless/nl80211.h8
-rw-r--r--net/wireless/scan.c836
6 files changed, 1196 insertions, 1 deletions
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index 938a334c8dbc..dad43c24f695 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -5,7 +5,7 @@ obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o
5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o 5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o 6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
7 7
8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o 8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o
9cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o 9cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o
10cfg80211-$(CONFIG_NL80211) += nl80211.o 10cfg80211-$(CONFIG_NL80211) += nl80211.o
11 11
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 125226476089..0668b2bfc1da 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -240,6 +240,8 @@ struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
240 mutex_init(&drv->mtx); 240 mutex_init(&drv->mtx);
241 mutex_init(&drv->devlist_mtx); 241 mutex_init(&drv->devlist_mtx);
242 INIT_LIST_HEAD(&drv->netdev_list); 242 INIT_LIST_HEAD(&drv->netdev_list);
243 spin_lock_init(&drv->bss_lock);
244 INIT_LIST_HEAD(&drv->bss_list);
243 245
244 device_initialize(&drv->wiphy.dev); 246 device_initialize(&drv->wiphy.dev);
245 drv->wiphy.dev.class = &ieee80211_class; 247 drv->wiphy.dev.class = &ieee80211_class;
@@ -259,6 +261,9 @@ int wiphy_register(struct wiphy *wiphy)
259 int i; 261 int i;
260 u16 ifmodes = wiphy->interface_modes; 262 u16 ifmodes = wiphy->interface_modes;
261 263
264 if (WARN_ON(wiphy->max_scan_ssids < 1))
265 return -EINVAL;
266
262 /* sanity check ifmodes */ 267 /* sanity check ifmodes */
263 WARN_ON(!ifmodes); 268 WARN_ON(!ifmodes);
264 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1; 269 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1;
@@ -367,8 +372,11 @@ EXPORT_SYMBOL(wiphy_unregister);
367 372
368void cfg80211_dev_free(struct cfg80211_registered_device *drv) 373void cfg80211_dev_free(struct cfg80211_registered_device *drv)
369{ 374{
375 struct cfg80211_internal_bss *scan, *tmp;
370 mutex_destroy(&drv->mtx); 376 mutex_destroy(&drv->mtx);
371 mutex_destroy(&drv->devlist_mtx); 377 mutex_destroy(&drv->devlist_mtx);
378 list_for_each_entry_safe(scan, tmp, &drv->bss_list, list)
379 cfg80211_put_bss(&scan->pub);
372 kfree(drv); 380 kfree(drv);
373} 381}
374 382
diff --git a/net/wireless/core.h b/net/wireless/core.h
index f7fb9f413028..e29ad4cd464f 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -8,6 +8,8 @@
8#include <linux/mutex.h> 8#include <linux/mutex.h>
9#include <linux/list.h> 9#include <linux/list.h>
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/kref.h>
12#include <linux/rbtree.h>
11#include <net/genetlink.h> 13#include <net/genetlink.h>
12#include <net/wireless.h> 14#include <net/wireless.h>
13#include <net/cfg80211.h> 15#include <net/cfg80211.h>
@@ -41,6 +43,13 @@ struct cfg80211_registered_device {
41 struct mutex devlist_mtx; 43 struct mutex devlist_mtx;
42 struct list_head netdev_list; 44 struct list_head netdev_list;
43 45
46 /* BSSes/scanning */
47 spinlock_t bss_lock;
48 struct list_head bss_list;
49 struct rb_root bss_tree;
50 u32 bss_generation;
51 struct cfg80211_scan_request *scan_req; /* protected by RTNL */
52
44 /* must be last because of the way we do wiphy_priv(), 53 /* must be last because of the way we do wiphy_priv(),
45 * and it should at least be aligned to NETDEV_ALIGN */ 54 * and it should at least be aligned to NETDEV_ALIGN */
46 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN))); 55 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
@@ -56,6 +65,15 @@ struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
56extern struct mutex cfg80211_drv_mutex; 65extern struct mutex cfg80211_drv_mutex;
57extern struct list_head cfg80211_drv_list; 66extern struct list_head cfg80211_drv_list;
58 67
68struct cfg80211_internal_bss {
69 struct list_head list;
70 struct rb_node rbn;
71 unsigned long ts;
72 struct kref ref;
73 /* must be last because of priv member */
74 struct cfg80211_bss pub;
75};
76
59/* 77/*
60 * This function returns a pointer to the driver 78 * This function returns a pointer to the driver
61 * that the genl_info item that is passed refers to. 79 * that the genl_info item that is passed refers to.
@@ -94,4 +112,6 @@ extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv,
94void ieee80211_set_bitrate_flags(struct wiphy *wiphy); 112void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
95void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby); 113void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby);
96 114
115void cfg80211_bss_expire(struct cfg80211_registered_device *dev);
116
97#endif /* __NET_WIRELESS_CORE_H */ 117#endif /* __NET_WIRELESS_CORE_H */
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index d452396006ee..298a4de59948 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -14,6 +14,7 @@
14#include <linux/nl80211.h> 14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h> 15#include <linux/rtnetlink.h>
16#include <linux/netlink.h> 16#include <linux/netlink.h>
17#include <linux/etherdevice.h>
17#include <net/genetlink.h> 18#include <net/genetlink.h>
18#include <net/cfg80211.h> 19#include <net/cfg80211.h>
19#include "core.h" 20#include "core.h"
@@ -109,6 +110,8 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
109 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, 110 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
110 [NL80211_ATTR_IE] = { .type = NLA_BINARY, 111 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
111 .len = IEEE80211_MAX_DATA_LEN }, 112 .len = IEEE80211_MAX_DATA_LEN },
113 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
114 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
112}; 115};
113 116
114/* message building helper */ 117/* message building helper */
@@ -141,6 +144,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
141 144
142 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->idx); 145 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->idx);
143 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); 146 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
147 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
148 dev->wiphy.max_scan_ssids);
144 149
145 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); 150 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
146 if (!nl_modes) 151 if (!nl_modes)
@@ -2270,6 +2275,246 @@ static int nl80211_set_mgmt_extra_ie(struct sk_buff *skb,
2270 return err; 2275 return err;
2271} 2276}
2272 2277
2278static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2279{
2280 struct cfg80211_registered_device *drv;
2281 struct net_device *dev;
2282 struct cfg80211_scan_request *request;
2283 struct cfg80211_ssid *ssid;
2284 struct ieee80211_channel *channel;
2285 struct nlattr *attr;
2286 struct wiphy *wiphy;
2287 int err, tmp, n_ssids = 0, n_channels = 0, i;
2288 enum ieee80211_band band;
2289
2290 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2291 if (err)
2292 return err;
2293
2294 wiphy = &drv->wiphy;
2295
2296 if (!drv->ops->scan) {
2297 err = -EOPNOTSUPP;
2298 goto out;
2299 }
2300
2301 rtnl_lock();
2302
2303 if (drv->scan_req) {
2304 err = -EBUSY;
2305 goto out_unlock;
2306 }
2307
2308 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2309 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2310 n_channels++;
2311 if (!n_channels) {
2312 err = -EINVAL;
2313 goto out_unlock;
2314 }
2315 } else {
2316 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2317 if (wiphy->bands[band])
2318 n_channels += wiphy->bands[band]->n_channels;
2319 }
2320
2321 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2322 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2323 n_ssids++;
2324
2325 if (n_ssids > wiphy->max_scan_ssids) {
2326 err = -EINVAL;
2327 goto out_unlock;
2328 }
2329
2330 request = kzalloc(sizeof(*request)
2331 + sizeof(*ssid) * n_ssids
2332 + sizeof(channel) * n_channels, GFP_KERNEL);
2333 if (!request) {
2334 err = -ENOMEM;
2335 goto out_unlock;
2336 }
2337
2338 request->channels = (void *)((char *)request + sizeof(*request));
2339 request->n_channels = n_channels;
2340 if (n_ssids)
2341 request->ssids = (void *)(request->channels + n_channels);
2342 request->n_ssids = n_ssids;
2343
2344 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2345 /* user specified, bail out if channel not found */
2346 request->n_channels = n_channels;
2347 i = 0;
2348 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2349 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2350 if (!request->channels[i]) {
2351 err = -EINVAL;
2352 goto out_free;
2353 }
2354 i++;
2355 }
2356 } else {
2357 /* all channels */
2358 i = 0;
2359 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2360 int j;
2361 if (!wiphy->bands[band])
2362 continue;
2363 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2364 request->channels[i] = &wiphy->bands[band]->channels[j];
2365 i++;
2366 }
2367 }
2368 }
2369
2370 i = 0;
2371 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2372 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2373 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2374 err = -EINVAL;
2375 goto out_free;
2376 }
2377 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2378 request->ssids[i].ssid_len = nla_len(attr);
2379 i++;
2380 }
2381 }
2382
2383 request->ifidx = dev->ifindex;
2384 request->wiphy = &drv->wiphy;
2385
2386 drv->scan_req = request;
2387 err = drv->ops->scan(&drv->wiphy, dev, request);
2388
2389 out_free:
2390 if (err) {
2391 drv->scan_req = NULL;
2392 kfree(request);
2393 }
2394 out_unlock:
2395 rtnl_unlock();
2396 out:
2397 cfg80211_put_dev(drv);
2398 dev_put(dev);
2399 return err;
2400}
2401
2402static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2403 struct cfg80211_registered_device *rdev,
2404 struct net_device *dev,
2405 struct cfg80211_bss *res)
2406{
2407 void *hdr;
2408 struct nlattr *bss;
2409
2410 hdr = nl80211hdr_put(msg, pid, seq, flags,
2411 NL80211_CMD_NEW_SCAN_RESULTS);
2412 if (!hdr)
2413 return -1;
2414
2415 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2416 rdev->bss_generation);
2417 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2418
2419 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2420 if (!bss)
2421 goto nla_put_failure;
2422 if (!is_zero_ether_addr(res->bssid))
2423 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2424 if (res->information_elements && res->len_information_elements)
2425 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2426 res->len_information_elements,
2427 res->information_elements);
2428 if (res->tsf)
2429 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2430 if (res->beacon_interval)
2431 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2432 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2433 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2434
2435 switch (res->signal_type) {
2436 case CFG80211_SIGNAL_TYPE_MBM:
2437 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2438 break;
2439 case CFG80211_SIGNAL_TYPE_UNSPEC:
2440 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2441 break;
2442 default:
2443 break;
2444 }
2445
2446 nla_nest_end(msg, bss);
2447
2448 return genlmsg_end(msg, hdr);
2449
2450 nla_put_failure:
2451 genlmsg_cancel(msg, hdr);
2452 return -EMSGSIZE;
2453}
2454
2455static int nl80211_dump_scan(struct sk_buff *skb,
2456 struct netlink_callback *cb)
2457{
2458 struct cfg80211_registered_device *dev;
2459 struct net_device *netdev;
2460 struct cfg80211_internal_bss *scan;
2461 int ifidx = cb->args[0];
2462 int start = cb->args[1], idx = 0;
2463 int err;
2464
2465 if (!ifidx) {
2466 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2467 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2468 nl80211_policy);
2469 if (err)
2470 return err;
2471
2472 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2473 return -EINVAL;
2474
2475 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2476 if (!ifidx)
2477 return -EINVAL;
2478 cb->args[0] = ifidx;
2479 }
2480
2481 netdev = dev_get_by_index(&init_net, ifidx);
2482 if (!netdev)
2483 return -ENODEV;
2484
2485 dev = cfg80211_get_dev_from_ifindex(ifidx);
2486 if (IS_ERR(dev)) {
2487 err = PTR_ERR(dev);
2488 goto out_put_netdev;
2489 }
2490
2491 spin_lock_bh(&dev->bss_lock);
2492 cfg80211_bss_expire(dev);
2493
2494 list_for_each_entry(scan, &dev->bss_list, list) {
2495 if (++idx <= start)
2496 continue;
2497 if (nl80211_send_bss(skb,
2498 NETLINK_CB(cb->skb).pid,
2499 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2500 dev, netdev, &scan->pub) < 0) {
2501 idx--;
2502 goto out;
2503 }
2504 }
2505
2506 out:
2507 spin_unlock_bh(&dev->bss_lock);
2508
2509 cb->args[1] = idx;
2510 err = skb->len;
2511 cfg80211_put_dev(dev);
2512 out_put_netdev:
2513 dev_put(netdev);
2514
2515 return err;
2516}
2517
2273static struct genl_ops nl80211_ops[] = { 2518static struct genl_ops nl80211_ops[] = {
2274 { 2519 {
2275 .cmd = NL80211_CMD_GET_WIPHY, 2520 .cmd = NL80211_CMD_GET_WIPHY,
@@ -2443,12 +2688,26 @@ static struct genl_ops nl80211_ops[] = {
2443 .policy = nl80211_policy, 2688 .policy = nl80211_policy,
2444 .flags = GENL_ADMIN_PERM, 2689 .flags = GENL_ADMIN_PERM,
2445 }, 2690 },
2691 {
2692 .cmd = NL80211_CMD_TRIGGER_SCAN,
2693 .doit = nl80211_trigger_scan,
2694 .policy = nl80211_policy,
2695 .flags = GENL_ADMIN_PERM,
2696 },
2697 {
2698 .cmd = NL80211_CMD_GET_SCAN,
2699 .policy = nl80211_policy,
2700 .dumpit = nl80211_dump_scan,
2701 },
2446}; 2702};
2447 2703
2448/* multicast groups */ 2704/* multicast groups */
2449static struct genl_multicast_group nl80211_config_mcgrp = { 2705static struct genl_multicast_group nl80211_config_mcgrp = {
2450 .name = "config", 2706 .name = "config",
2451}; 2707};
2708static struct genl_multicast_group nl80211_scan_mcgrp = {
2709 .name = "scan",
2710};
2452 2711
2453/* notification functions */ 2712/* notification functions */
2454 2713
@@ -2468,6 +2727,66 @@ void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
2468 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); 2727 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
2469} 2728}
2470 2729
2730static int nl80211_send_scan_donemsg(struct sk_buff *msg,
2731 struct cfg80211_registered_device *rdev,
2732 struct net_device *netdev,
2733 u32 pid, u32 seq, int flags,
2734 u32 cmd)
2735{
2736 void *hdr;
2737
2738 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
2739 if (!hdr)
2740 return -1;
2741
2742 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->idx);
2743 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
2744
2745 /* XXX: we should probably bounce back the request? */
2746
2747 return genlmsg_end(msg, hdr);
2748
2749 nla_put_failure:
2750 genlmsg_cancel(msg, hdr);
2751 return -EMSGSIZE;
2752}
2753
2754void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
2755 struct net_device *netdev)
2756{
2757 struct sk_buff *msg;
2758
2759 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2760 if (!msg)
2761 return;
2762
2763 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
2764 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
2765 nlmsg_free(msg);
2766 return;
2767 }
2768
2769 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
2770}
2771
2772void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
2773 struct net_device *netdev)
2774{
2775 struct sk_buff *msg;
2776
2777 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2778 if (!msg)
2779 return;
2780
2781 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
2782 NL80211_CMD_SCAN_ABORTED) < 0) {
2783 nlmsg_free(msg);
2784 return;
2785 }
2786
2787 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
2788}
2789
2471/* initialisation/exit functions */ 2790/* initialisation/exit functions */
2472 2791
2473int nl80211_init(void) 2792int nl80211_init(void)
@@ -2488,6 +2807,10 @@ int nl80211_init(void)
2488 if (err) 2807 if (err)
2489 goto err_out; 2808 goto err_out;
2490 2809
2810 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
2811 if (err)
2812 goto err_out;
2813
2491 return 0; 2814 return 0;
2492 err_out: 2815 err_out:
2493 genl_unregister_family(&nl80211_fam); 2816 genl_unregister_family(&nl80211_fam);
diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h
index f3ea5c029aee..b565a5f84e97 100644
--- a/net/wireless/nl80211.h
+++ b/net/wireless/nl80211.h
@@ -7,6 +7,10 @@
7extern int nl80211_init(void); 7extern int nl80211_init(void);
8extern void nl80211_exit(void); 8extern void nl80211_exit(void);
9extern void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev); 9extern void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
10extern void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
11 struct net_device *netdev);
12extern void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
13 struct net_device *netdev);
10#else 14#else
11static inline int nl80211_init(void) 15static inline int nl80211_init(void)
12{ 16{
@@ -19,6 +23,10 @@ static inline void nl80211_notify_dev_rename(
19 struct cfg80211_registered_device *rdev) 23 struct cfg80211_registered_device *rdev)
20{ 24{
21} 25}
26static inline void
27nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
28 struct net_device *netdev)
29{}
22#endif /* CONFIG_NL80211 */ 30#endif /* CONFIG_NL80211 */
23 31
24#endif /* __NET_WIRELESS_NL80211_H */ 32#endif /* __NET_WIRELESS_NL80211_H */
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
new file mode 100644
index 000000000000..b1893c863b97
--- /dev/null
+++ b/net/wireless/scan.c
@@ -0,0 +1,836 @@
1/*
2 * cfg80211 scan result handling
3 *
4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
5 */
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>
12#include <net/arp.h>
13#include <net/cfg80211.h>
14#include <net/iw_handler.h>
15#include "core.h"
16#include "nl80211.h"
17
18#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
19
20void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
21{
22 struct net_device *dev;
23#ifdef CONFIG_WIRELESS_EXT
24 union iwreq_data wrqu;
25#endif
26
27 dev = dev_get_by_index(&init_net, request->ifidx);
28 if (!dev)
29 goto out;
30
31 WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req);
32 wiphy_to_dev(request->wiphy)->scan_req = NULL;
33
34 if (aborted)
35 nl80211_send_scan_aborted(wiphy_to_dev(request->wiphy), dev);
36 else
37 nl80211_send_scan_done(wiphy_to_dev(request->wiphy), dev);
38
39#ifdef CONFIG_WIRELESS_EXT
40 if (!aborted) {
41 memset(&wrqu, 0, sizeof(wrqu));
42
43 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
44 }
45#endif
46
47 dev_put(dev);
48
49 out:
50 kfree(request);
51}
52EXPORT_SYMBOL(cfg80211_scan_done);
53
54static void bss_release(struct kref *ref)
55{
56 struct cfg80211_internal_bss *bss;
57
58 bss = container_of(ref, struct cfg80211_internal_bss, ref);
59 if (bss->pub.free_priv)
60 bss->pub.free_priv(&bss->pub);
61 kfree(bss);
62}
63
64/* must hold dev->bss_lock! */
65void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
66{
67 struct cfg80211_internal_bss *bss, *tmp;
68 bool expired = false;
69
70 list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) {
71 if (!time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE))
72 continue;
73 list_del(&bss->list);
74 rb_erase(&bss->rbn, &dev->bss_tree);
75 kref_put(&bss->ref, bss_release);
76 expired = true;
77 }
78
79 if (expired)
80 dev->bss_generation++;
81}
82
83static u8 *find_ie(u8 num, u8 *ies, size_t len)
84{
85 while (len > 2 && ies[0] != num) {
86 len -= ies[1] + 2;
87 ies += ies[1] + 2;
88 }
89 if (len < 2)
90 return NULL;
91 if (len < 2 + ies[1])
92 return NULL;
93 return ies;
94}
95
96static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2)
97{
98 const u8 *ie1 = find_ie(num, ies1, len1);
99 const u8 *ie2 = find_ie(num, ies2, len2);
100 int r;
101
102 if (!ie1 && !ie2)
103 return 0;
104 if (!ie1)
105 return -1;
106
107 r = memcmp(ie1 + 2, ie2 + 2, min(ie1[1], ie2[1]));
108 if (r == 0 && ie1[1] != ie2[1])
109 return ie2[1] - ie1[1];
110 return r;
111}
112
113static bool is_bss(struct cfg80211_bss *a,
114 const u8 *bssid,
115 const u8 *ssid, size_t ssid_len)
116{
117 const u8 *ssidie;
118
119 if (bssid && compare_ether_addr(a->bssid, bssid))
120 return false;
121
122 if (!ssid)
123 return true;
124
125 ssidie = find_ie(WLAN_EID_SSID,
126 a->information_elements,
127 a->len_information_elements);
128 if (!ssidie)
129 return false;
130 if (ssidie[1] != ssid_len)
131 return false;
132 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
133}
134
135static bool is_mesh(struct cfg80211_bss *a,
136 const u8 *meshid, size_t meshidlen,
137 const u8 *meshcfg)
138{
139 const u8 *ie;
140
141 if (!is_zero_ether_addr(a->bssid))
142 return false;
143
144 ie = find_ie(WLAN_EID_MESH_ID,
145 a->information_elements,
146 a->len_information_elements);
147 if (!ie)
148 return false;
149 if (ie[1] != meshidlen)
150 return false;
151 if (memcmp(ie + 2, meshid, meshidlen))
152 return false;
153
154 ie = find_ie(WLAN_EID_MESH_CONFIG,
155 a->information_elements,
156 a->len_information_elements);
157 if (ie[1] != IEEE80211_MESH_CONFIG_LEN)
158 return false;
159
160 /*
161 * Ignore mesh capability (last two bytes of the IE) when
162 * comparing since that may differ between stations taking
163 * part in the same mesh.
164 */
165 return memcmp(ie + 2, meshcfg, IEEE80211_MESH_CONFIG_LEN - 2) == 0;
166}
167
168static int cmp_bss(struct cfg80211_bss *a,
169 struct cfg80211_bss *b)
170{
171 int r;
172
173 if (a->channel != b->channel)
174 return b->channel->center_freq - a->channel->center_freq;
175
176 r = memcmp(a->bssid, b->bssid, ETH_ALEN);
177 if (r)
178 return r;
179
180 if (is_zero_ether_addr(a->bssid)) {
181 r = cmp_ies(WLAN_EID_MESH_ID,
182 a->information_elements,
183 a->len_information_elements,
184 b->information_elements,
185 b->len_information_elements);
186 if (r)
187 return r;
188 return cmp_ies(WLAN_EID_MESH_CONFIG,
189 a->information_elements,
190 a->len_information_elements,
191 b->information_elements,
192 b->len_information_elements);
193 }
194
195 return cmp_ies(WLAN_EID_SSID,
196 a->information_elements,
197 a->len_information_elements,
198 b->information_elements,
199 b->len_information_elements);
200}
201
202struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
203 struct ieee80211_channel *channel,
204 const u8 *bssid,
205 const u8 *ssid, size_t ssid_len,
206 u16 capa_mask, u16 capa_val)
207{
208 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
209 struct cfg80211_internal_bss *bss, *res = NULL;
210
211 spin_lock_bh(&dev->bss_lock);
212
213 list_for_each_entry(bss, &dev->bss_list, list) {
214 if ((bss->pub.capability & capa_mask) != capa_val)
215 continue;
216 if (channel && bss->pub.channel != channel)
217 continue;
218 if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
219 res = bss;
220 kref_get(&res->ref);
221 break;
222 }
223 }
224
225 spin_unlock_bh(&dev->bss_lock);
226 if (!res)
227 return NULL;
228 return &res->pub;
229}
230EXPORT_SYMBOL(cfg80211_get_bss);
231
232struct cfg80211_bss *cfg80211_get_mesh(struct wiphy *wiphy,
233 struct ieee80211_channel *channel,
234 const u8 *meshid, size_t meshidlen,
235 const u8 *meshcfg)
236{
237 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
238 struct cfg80211_internal_bss *bss, *res = NULL;
239
240 spin_lock_bh(&dev->bss_lock);
241
242 list_for_each_entry(bss, &dev->bss_list, list) {
243 if (channel && bss->pub.channel != channel)
244 continue;
245 if (is_mesh(&bss->pub, meshid, meshidlen, meshcfg)) {
246 res = bss;
247 kref_get(&res->ref);
248 break;
249 }
250 }
251
252 spin_unlock_bh(&dev->bss_lock);
253 if (!res)
254 return NULL;
255 return &res->pub;
256}
257EXPORT_SYMBOL(cfg80211_get_mesh);
258
259
260static void rb_insert_bss(struct cfg80211_registered_device *dev,
261 struct cfg80211_internal_bss *bss)
262{
263 struct rb_node **p = &dev->bss_tree.rb_node;
264 struct rb_node *parent = NULL;
265 struct cfg80211_internal_bss *tbss;
266 int cmp;
267
268 while (*p) {
269 parent = *p;
270 tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
271
272 cmp = cmp_bss(&bss->pub, &tbss->pub);
273
274 if (WARN_ON(!cmp)) {
275 /* will sort of leak this BSS */
276 return;
277 }
278
279 if (cmp < 0)
280 p = &(*p)->rb_left;
281 else
282 p = &(*p)->rb_right;
283 }
284
285 rb_link_node(&bss->rbn, parent, p);
286 rb_insert_color(&bss->rbn, &dev->bss_tree);
287}
288
289static struct cfg80211_internal_bss *
290rb_find_bss(struct cfg80211_registered_device *dev,
291 struct cfg80211_internal_bss *res)
292{
293 struct rb_node *n = dev->bss_tree.rb_node;
294 struct cfg80211_internal_bss *bss;
295 int r;
296
297 while (n) {
298 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
299 r = cmp_bss(&res->pub, &bss->pub);
300
301 if (r == 0)
302 return bss;
303 else if (r < 0)
304 n = n->rb_left;
305 else
306 n = n->rb_right;
307 }
308
309 return NULL;
310}
311
312static struct cfg80211_internal_bss *
313cfg80211_bss_update(struct cfg80211_registered_device *dev,
314 struct cfg80211_internal_bss *res,
315 bool overwrite)
316{
317 struct cfg80211_internal_bss *found = NULL;
318 const u8 *meshid, *meshcfg;
319
320 /*
321 * The reference to "res" is donated to this function.
322 */
323
324 if (WARN_ON(!res->pub.channel)) {
325 kref_put(&res->ref, bss_release);
326 return NULL;
327 }
328
329 res->ts = jiffies;
330
331 if (is_zero_ether_addr(res->pub.bssid)) {
332 /* must be mesh, verify */
333 meshid = find_ie(WLAN_EID_MESH_ID, res->pub.information_elements,
334 res->pub.len_information_elements);
335 meshcfg = find_ie(WLAN_EID_MESH_CONFIG,
336 res->pub.information_elements,
337 res->pub.len_information_elements);
338 if (!meshid || !meshcfg ||
339 meshcfg[1] != IEEE80211_MESH_CONFIG_LEN) {
340 /* bogus mesh */
341 kref_put(&res->ref, bss_release);
342 return NULL;
343 }
344 }
345
346 spin_lock_bh(&dev->bss_lock);
347
348 found = rb_find_bss(dev, res);
349
350 if (found && overwrite) {
351 list_replace(&found->list, &res->list);
352 rb_replace_node(&found->rbn, &res->rbn,
353 &dev->bss_tree);
354 kref_put(&found->ref, bss_release);
355 found = res;
356 } else if (found) {
357 kref_get(&found->ref);
358 found->pub.beacon_interval = res->pub.beacon_interval;
359 found->pub.tsf = res->pub.tsf;
360 found->pub.signal = res->pub.signal;
361 found->pub.signal_type = res->pub.signal_type;
362 found->pub.capability = res->pub.capability;
363 found->ts = res->ts;
364 kref_put(&res->ref, bss_release);
365 } else {
366 /* this "consumes" the reference */
367 list_add_tail(&res->list, &dev->bss_list);
368 rb_insert_bss(dev, res);
369 found = res;
370 }
371
372 dev->bss_generation++;
373 spin_unlock_bh(&dev->bss_lock);
374
375 kref_get(&found->ref);
376 return found;
377}
378
379struct cfg80211_bss *
380cfg80211_inform_bss_frame(struct wiphy *wiphy,
381 struct ieee80211_channel *channel,
382 struct ieee80211_mgmt *mgmt, size_t len,
383 s32 signal, enum cfg80211_signal_type sigtype,
384 gfp_t gfp)
385{
386 struct cfg80211_internal_bss *res;
387 size_t ielen = len - offsetof(struct ieee80211_mgmt,
388 u.probe_resp.variable);
389 bool overwrite;
390 size_t privsz = wiphy->bss_priv_size;
391
392 if (WARN_ON(sigtype == NL80211_BSS_SIGNAL_UNSPEC &&
393 (signal < 0 || signal > 100)))
394 return NULL;
395
396 if (WARN_ON(!mgmt || !wiphy ||
397 len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
398 return NULL;
399
400 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
401 if (!res)
402 return NULL;
403
404 memcpy(res->pub.bssid, mgmt->bssid, ETH_ALEN);
405 res->pub.channel = channel;
406 res->pub.signal_type = sigtype;
407 res->pub.signal = signal;
408 res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
409 res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
410 res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
411 /* point to after the private area */
412 res->pub.information_elements = (u8 *)res + sizeof(*res) + privsz;
413 memcpy(res->pub.information_elements, mgmt->u.probe_resp.variable, ielen);
414 res->pub.len_information_elements = ielen;
415
416 kref_init(&res->ref);
417
418 overwrite = ieee80211_is_probe_resp(mgmt->frame_control);
419
420 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res, overwrite);
421 if (!res)
422 return NULL;
423
424 /* cfg80211_bss_update gives us a referenced result */
425 return &res->pub;
426}
427EXPORT_SYMBOL(cfg80211_inform_bss_frame);
428
429void cfg80211_put_bss(struct cfg80211_bss *pub)
430{
431 struct cfg80211_internal_bss *bss;
432
433 if (!pub)
434 return;
435
436 bss = container_of(pub, struct cfg80211_internal_bss, pub);
437 kref_put(&bss->ref, bss_release);
438}
439EXPORT_SYMBOL(cfg80211_put_bss);
440
441void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
442{
443 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
444 struct cfg80211_internal_bss *bss;
445
446 if (WARN_ON(!pub))
447 return;
448
449 bss = container_of(pub, struct cfg80211_internal_bss, pub);
450
451 spin_lock_bh(&dev->bss_lock);
452
453 list_del(&bss->list);
454 rb_erase(&bss->rbn, &dev->bss_tree);
455
456 spin_unlock_bh(&dev->bss_lock);
457
458 kref_put(&bss->ref, bss_release);
459}
460EXPORT_SYMBOL(cfg80211_unlink_bss);
461
462#ifdef CONFIG_WIRELESS_EXT
463int cfg80211_wext_siwscan(struct net_device *dev,
464 struct iw_request_info *info,
465 union iwreq_data *wrqu, char *extra)
466{
467 struct cfg80211_registered_device *rdev;
468 struct wiphy *wiphy;
469 struct iw_scan_req *wreq = NULL;
470 struct cfg80211_scan_request *creq;
471 int i, err, n_channels = 0;
472 enum ieee80211_band band;
473
474 if (!netif_running(dev))
475 return -ENETDOWN;
476
477 rdev = cfg80211_get_dev_from_ifindex(dev->ifindex);
478
479 if (IS_ERR(rdev))
480 return PTR_ERR(rdev);
481
482 if (rdev->scan_req) {
483 err = -EBUSY;
484 goto out;
485 }
486
487 wiphy = &rdev->wiphy;
488
489 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
490 if (wiphy->bands[band])
491 n_channels += wiphy->bands[band]->n_channels;
492
493 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
494 n_channels * sizeof(void *),
495 GFP_ATOMIC);
496 if (!creq) {
497 err = -ENOMEM;
498 goto out;
499 }
500
501 creq->wiphy = wiphy;
502 creq->ifidx = dev->ifindex;
503 creq->ssids = (void *)(creq + 1);
504 creq->channels = (void *)(creq->ssids + 1);
505 creq->n_channels = n_channels;
506 creq->n_ssids = 1;
507
508 /* all channels */
509 i = 0;
510 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
511 int j;
512 if (!wiphy->bands[band])
513 continue;
514 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
515 creq->channels[i] = &wiphy->bands[band]->channels[j];
516 i++;
517 }
518 }
519
520 /* translate scan request */
521 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
522 wreq = (struct iw_scan_req *)extra;
523
524 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
525 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN)
526 return -EINVAL;
527 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
528 creq->ssids[0].ssid_len = wreq->essid_len;
529 }
530 if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
531 creq->n_ssids = 0;
532 }
533
534 rdev->scan_req = creq;
535 err = rdev->ops->scan(wiphy, dev, creq);
536 if (err) {
537 rdev->scan_req = NULL;
538 kfree(creq);
539 }
540 out:
541 cfg80211_put_dev(rdev);
542 return err;
543}
544EXPORT_SYMBOL(cfg80211_wext_siwscan);
545
546static void ieee80211_scan_add_ies(struct iw_request_info *info,
547 struct cfg80211_bss *bss,
548 char **current_ev, char *end_buf)
549{
550 u8 *pos, *end, *next;
551 struct iw_event iwe;
552
553 if (!bss->information_elements ||
554 !bss->len_information_elements)
555 return;
556
557 /*
558 * If needed, fragment the IEs buffer (at IE boundaries) into short
559 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
560 */
561 pos = bss->information_elements;
562 end = pos + bss->len_information_elements;
563
564 while (end - pos > IW_GENERIC_IE_MAX) {
565 next = pos + 2 + pos[1];
566 while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
567 next = next + 2 + next[1];
568
569 memset(&iwe, 0, sizeof(iwe));
570 iwe.cmd = IWEVGENIE;
571 iwe.u.data.length = next - pos;
572 *current_ev = iwe_stream_add_point(info, *current_ev,
573 end_buf, &iwe, pos);
574
575 pos = next;
576 }
577
578 if (end > pos) {
579 memset(&iwe, 0, sizeof(iwe));
580 iwe.cmd = IWEVGENIE;
581 iwe.u.data.length = end - pos;
582 *current_ev = iwe_stream_add_point(info, *current_ev,
583 end_buf, &iwe, pos);
584 }
585}
586
587
588static char *
589ieee80211_bss(struct iw_request_info *info,
590 struct cfg80211_internal_bss *bss,
591 char *current_ev, char *end_buf)
592{
593 struct iw_event iwe;
594 u8 *buf, *cfg, *p;
595 u8 *ie = bss->pub.information_elements;
596 int rem = bss->pub.len_information_elements, i;
597 bool ismesh = false;
598
599 memset(&iwe, 0, sizeof(iwe));
600 iwe.cmd = SIOCGIWAP;
601 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
602 memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
603 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
604 IW_EV_ADDR_LEN);
605
606 memset(&iwe, 0, sizeof(iwe));
607 iwe.cmd = SIOCGIWFREQ;
608 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
609 iwe.u.freq.e = 0;
610 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
611 IW_EV_FREQ_LEN);
612
613 memset(&iwe, 0, sizeof(iwe));
614 iwe.cmd = SIOCGIWFREQ;
615 iwe.u.freq.m = bss->pub.channel->center_freq;
616 iwe.u.freq.e = 6;
617 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
618 IW_EV_FREQ_LEN);
619
620 if (bss->pub.signal_type != CFG80211_SIGNAL_TYPE_NONE) {
621 memset(&iwe, 0, sizeof(iwe));
622 iwe.cmd = IWEVQUAL;
623 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
624 IW_QUAL_NOISE_INVALID |
625 IW_QUAL_QUAL_INVALID;
626 switch (bss->pub.signal_type) {
627 case CFG80211_SIGNAL_TYPE_MBM:
628 iwe.u.qual.level = bss->pub.signal / 100;
629 iwe.u.qual.updated |= IW_QUAL_DBM;
630 break;
631 case CFG80211_SIGNAL_TYPE_UNSPEC:
632 iwe.u.qual.level = bss->pub.signal;
633 break;
634 default:
635 /* not reached */
636 break;
637 }
638 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
639 &iwe, IW_EV_QUAL_LEN);
640 }
641
642 memset(&iwe, 0, sizeof(iwe));
643 iwe.cmd = SIOCGIWENCODE;
644 if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
645 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
646 else
647 iwe.u.data.flags = IW_ENCODE_DISABLED;
648 iwe.u.data.length = 0;
649 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
650 &iwe, "");
651
652 while (rem >= 2) {
653 /* invalid data */
654 if (ie[1] > rem - 2)
655 break;
656
657 switch (ie[0]) {
658 case WLAN_EID_SSID:
659 memset(&iwe, 0, sizeof(iwe));
660 iwe.cmd = SIOCGIWESSID;
661 iwe.u.data.length = ie[1];
662 iwe.u.data.flags = 1;
663 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
664 &iwe, ie + 2);
665 break;
666 case WLAN_EID_MESH_ID:
667 memset(&iwe, 0, sizeof(iwe));
668 iwe.cmd = SIOCGIWESSID;
669 iwe.u.data.length = ie[1];
670 iwe.u.data.flags = 1;
671 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
672 &iwe, ie + 2);
673 break;
674 case WLAN_EID_MESH_CONFIG:
675 ismesh = true;
676 if (ie[1] != IEEE80211_MESH_CONFIG_LEN)
677 break;
678 buf = kmalloc(50, GFP_ATOMIC);
679 if (!buf)
680 break;
681 cfg = ie + 2;
682 memset(&iwe, 0, sizeof(iwe));
683 iwe.cmd = IWEVCUSTOM;
684 sprintf(buf, "Mesh network (version %d)", cfg[0]);
685 iwe.u.data.length = strlen(buf);
686 current_ev = iwe_stream_add_point(info, current_ev,
687 end_buf,
688 &iwe, buf);
689 sprintf(buf, "Path Selection Protocol ID: "
690 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
691 cfg[4]);
692 iwe.u.data.length = strlen(buf);
693 current_ev = iwe_stream_add_point(info, current_ev,
694 end_buf,
695 &iwe, buf);
696 sprintf(buf, "Path Selection Metric ID: "
697 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
698 cfg[8]);
699 iwe.u.data.length = strlen(buf);
700 current_ev = iwe_stream_add_point(info, current_ev,
701 end_buf,
702 &iwe, buf);
703 sprintf(buf, "Congestion Control Mode ID: "
704 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
705 cfg[11], cfg[12]);
706 iwe.u.data.length = strlen(buf);
707 current_ev = iwe_stream_add_point(info, current_ev,
708 end_buf,
709 &iwe, buf);
710 sprintf(buf, "Channel Precedence: "
711 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
712 cfg[15], cfg[16]);
713 iwe.u.data.length = strlen(buf);
714 current_ev = iwe_stream_add_point(info, current_ev,
715 end_buf,
716 &iwe, buf);
717 kfree(buf);
718 break;
719 case WLAN_EID_SUPP_RATES:
720 case WLAN_EID_EXT_SUPP_RATES:
721 /* display all supported rates in readable format */
722 p = current_ev + iwe_stream_lcp_len(info);
723
724 memset(&iwe, 0, sizeof(iwe));
725 iwe.cmd = SIOCGIWRATE;
726 /* Those two flags are ignored... */
727 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
728
729 for (i = 0; i < ie[1]; i++) {
730 iwe.u.bitrate.value =
731 ((ie[i + 2] & 0x7f) * 500000);
732 p = iwe_stream_add_value(info, current_ev, p,
733 end_buf, &iwe, IW_EV_PARAM_LEN);
734 }
735 current_ev = p;
736 break;
737 }
738 rem -= ie[1] + 2;
739 ie += ie[1] + 2;
740 }
741
742 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
743 || ismesh) {
744 memset(&iwe, 0, sizeof(iwe));
745 iwe.cmd = SIOCGIWMODE;
746 if (ismesh)
747 iwe.u.mode = IW_MODE_MESH;
748 else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
749 iwe.u.mode = IW_MODE_MASTER;
750 else
751 iwe.u.mode = IW_MODE_ADHOC;
752 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
753 &iwe, IW_EV_UINT_LEN);
754 }
755
756 buf = kmalloc(30, GFP_ATOMIC);
757 if (buf) {
758 memset(&iwe, 0, sizeof(iwe));
759 iwe.cmd = IWEVCUSTOM;
760 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->pub.tsf));
761 iwe.u.data.length = strlen(buf);
762 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
763 &iwe, buf);
764 memset(&iwe, 0, sizeof(iwe));
765 iwe.cmd = IWEVCUSTOM;
766 sprintf(buf, " Last beacon: %dms ago",
767 jiffies_to_msecs(jiffies - bss->ts));
768 iwe.u.data.length = strlen(buf);
769 current_ev = iwe_stream_add_point(info, current_ev,
770 end_buf, &iwe, buf);
771 kfree(buf);
772 }
773
774 ieee80211_scan_add_ies(info, &bss->pub, &current_ev, end_buf);
775
776 return current_ev;
777}
778
779
780static int ieee80211_scan_results(struct cfg80211_registered_device *dev,
781 struct iw_request_info *info,
782 char *buf, size_t len)
783{
784 char *current_ev = buf;
785 char *end_buf = buf + len;
786 struct cfg80211_internal_bss *bss;
787
788 spin_lock_bh(&dev->bss_lock);
789 cfg80211_bss_expire(dev);
790
791 list_for_each_entry(bss, &dev->bss_list, list) {
792 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
793 spin_unlock_bh(&dev->bss_lock);
794 return -E2BIG;
795 }
796 current_ev = ieee80211_bss(info, bss,
797 current_ev, end_buf);
798 }
799 spin_unlock_bh(&dev->bss_lock);
800 return current_ev - buf;
801}
802
803
804int cfg80211_wext_giwscan(struct net_device *dev,
805 struct iw_request_info *info,
806 struct iw_point *data, char *extra)
807{
808 struct cfg80211_registered_device *rdev;
809 int res;
810
811 if (!netif_running(dev))
812 return -ENETDOWN;
813
814 rdev = cfg80211_get_dev_from_ifindex(dev->ifindex);
815
816 if (IS_ERR(rdev))
817 return PTR_ERR(rdev);
818
819 if (rdev->scan_req) {
820 res = -EAGAIN;
821 goto out;
822 }
823
824 res = ieee80211_scan_results(rdev, info, extra, data->length);
825 data->length = 0;
826 if (res >= 0) {
827 data->length = res;
828 res = 0;
829 }
830
831 out:
832 cfg80211_put_dev(rdev);
833 return res;
834}
835EXPORT_SYMBOL(cfg80211_wext_giwscan);
836#endif