Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * cfg80211 scan result handling |
| 3 | * |
| 4 | * Copyright 2008 Johannes Berg <johannes@sipsolutions.net> |
| 5 | */ |
| 6 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 7 | #include <linux/slab.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8 | #include <linux/module.h> |
| 9 | #include <linux/netdevice.h> |
| 10 | #include <linux/wireless.h> |
| 11 | #include <linux/nl80211.h> |
| 12 | #include <linux/etherdevice.h> |
| 13 | #include <net/arp.h> |
| 14 | #include <net/cfg80211.h> |
Johannes Berg | 262eb9b2 | 2011-07-13 10:39:09 +0200 | [diff] [blame] | 15 | #include <net/cfg80211-wext.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16 | #include <net/iw_handler.h> |
| 17 | #include "core.h" |
| 18 | #include "nl80211.h" |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 19 | #include "wext-compat.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 20 | #include "rdev-ops.h" |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 21 | |
Rajkumar Manoharan | f9616e0 | 2012-04-13 16:38:40 +0530 | [diff] [blame] | 22 | #define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 23 | |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 24 | static void bss_release(struct kref *ref) |
| 25 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 26 | struct cfg80211_bss_ies *ies; |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 27 | struct cfg80211_internal_bss *bss; |
| 28 | |
| 29 | bss = container_of(ref, struct cfg80211_internal_bss, ref); |
Johannes Berg | b629ea3 | 2012-11-28 22:14:56 +0100 | [diff] [blame] | 30 | |
| 31 | if (WARN_ON(atomic_read(&bss->hold))) |
| 32 | return; |
| 33 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 34 | ies = (void *)rcu_access_pointer(bss->pub.beacon_ies); |
| 35 | if (ies) |
| 36 | kfree_rcu(ies, rcu_head); |
| 37 | ies = (void *)rcu_access_pointer(bss->pub.proberesp_ies); |
| 38 | if (ies) |
| 39 | kfree_rcu(ies, rcu_head); |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 40 | |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 41 | kfree(bss); |
| 42 | } |
| 43 | |
| 44 | /* must hold dev->bss_lock! */ |
| 45 | static void __cfg80211_unlink_bss(struct cfg80211_registered_device *dev, |
| 46 | struct cfg80211_internal_bss *bss) |
| 47 | { |
| 48 | list_del_init(&bss->list); |
| 49 | rb_erase(&bss->rbn, &dev->bss_tree); |
| 50 | kref_put(&bss->ref, bss_release); |
| 51 | } |
| 52 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 53 | /* must hold dev->bss_lock! */ |
| 54 | static void __cfg80211_bss_expire(struct cfg80211_registered_device *dev, |
| 55 | unsigned long expire_time) |
| 56 | { |
| 57 | struct cfg80211_internal_bss *bss, *tmp; |
| 58 | bool expired = false; |
| 59 | |
| 60 | list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) { |
| 61 | if (atomic_read(&bss->hold)) |
| 62 | continue; |
| 63 | if (!time_after(expire_time, bss->ts)) |
| 64 | continue; |
| 65 | |
| 66 | __cfg80211_unlink_bss(dev, bss); |
| 67 | expired = true; |
| 68 | } |
| 69 | |
| 70 | if (expired) |
| 71 | dev->bss_generation++; |
| 72 | } |
| 73 | |
Johannes Berg | 01a0ac4 | 2009-08-20 21:36:16 +0200 | [diff] [blame] | 74 | void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 75 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 76 | struct cfg80211_scan_request *request; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 77 | struct wireless_dev *wdev; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 78 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 79 | union iwreq_data wrqu; |
| 80 | #endif |
| 81 | |
Johannes Berg | 01a0ac4 | 2009-08-20 21:36:16 +0200 | [diff] [blame] | 82 | ASSERT_RDEV_LOCK(rdev); |
| 83 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 84 | request = rdev->scan_req; |
| 85 | |
Johannes Berg | 01a0ac4 | 2009-08-20 21:36:16 +0200 | [diff] [blame] | 86 | if (!request) |
| 87 | return; |
| 88 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 89 | wdev = request->wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 90 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 91 | /* |
| 92 | * This must be before sending the other events! |
| 93 | * Otherwise, wpa_supplicant gets completely confused with |
| 94 | * wext events. |
| 95 | */ |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 96 | if (wdev->netdev) |
| 97 | cfg80211_sme_scan_done(wdev->netdev); |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 98 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 99 | if (request->aborted) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 100 | nl80211_send_scan_aborted(rdev, wdev); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 101 | } else { |
| 102 | if (request->flags & NL80211_SCAN_FLAG_FLUSH) { |
| 103 | /* flush entries from previous scans */ |
| 104 | spin_lock_bh(&rdev->bss_lock); |
| 105 | __cfg80211_bss_expire(rdev, request->scan_start); |
| 106 | spin_unlock_bh(&rdev->bss_lock); |
| 107 | } |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 108 | nl80211_send_scan_done(rdev, wdev); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 109 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 110 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 111 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 112 | if (wdev->netdev && !request->aborted) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 113 | memset(&wrqu, 0, sizeof(wrqu)); |
| 114 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 115 | wireless_send_event(wdev->netdev, SIOCGIWSCAN, &wrqu, NULL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 116 | } |
| 117 | #endif |
| 118 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 119 | if (wdev->netdev) |
| 120 | dev_put(wdev->netdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 121 | |
Johannes Berg | 36e6fea | 2009-08-12 22:21:21 +0200 | [diff] [blame] | 122 | rdev->scan_req = NULL; |
Johannes Berg | 01a0ac4 | 2009-08-20 21:36:16 +0200 | [diff] [blame] | 123 | |
| 124 | /* |
| 125 | * OK. If this is invoked with "leak" then we can't |
| 126 | * free this ... but we've cleaned it up anyway. The |
| 127 | * driver failed to call the scan_done callback, so |
| 128 | * all bets are off, it might still be trying to use |
| 129 | * the scan request or not ... if it accesses the dev |
| 130 | * in there (it shouldn't anyway) then it may crash. |
| 131 | */ |
| 132 | if (!leak) |
| 133 | kfree(request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 134 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 135 | |
Johannes Berg | 36e6fea | 2009-08-12 22:21:21 +0200 | [diff] [blame] | 136 | void __cfg80211_scan_done(struct work_struct *wk) |
| 137 | { |
| 138 | struct cfg80211_registered_device *rdev; |
| 139 | |
| 140 | rdev = container_of(wk, struct cfg80211_registered_device, |
| 141 | scan_done_wk); |
| 142 | |
| 143 | cfg80211_lock_rdev(rdev); |
Johannes Berg | 01a0ac4 | 2009-08-20 21:36:16 +0200 | [diff] [blame] | 144 | ___cfg80211_scan_done(rdev, false); |
Johannes Berg | 36e6fea | 2009-08-12 22:21:21 +0200 | [diff] [blame] | 145 | cfg80211_unlock_rdev(rdev); |
| 146 | } |
| 147 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 148 | void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted) |
| 149 | { |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 150 | trace_cfg80211_scan_done(request, aborted); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 151 | WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); |
| 152 | |
| 153 | request->aborted = aborted; |
Alban Browaeys | e60d744 | 2009-11-25 15:13:00 +0100 | [diff] [blame] | 154 | queue_work(cfg80211_wq, &wiphy_to_dev(request->wiphy)->scan_done_wk); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 155 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 156 | EXPORT_SYMBOL(cfg80211_scan_done); |
| 157 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 158 | void __cfg80211_sched_scan_results(struct work_struct *wk) |
| 159 | { |
| 160 | struct cfg80211_registered_device *rdev; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 161 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 162 | |
| 163 | rdev = container_of(wk, struct cfg80211_registered_device, |
| 164 | sched_scan_results_wk); |
| 165 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 166 | request = rdev->sched_scan_req; |
| 167 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 168 | mutex_lock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 169 | |
| 170 | /* we don't have sched_scan_req anymore if the scan is stopping */ |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 171 | if (request) { |
| 172 | if (request->flags & NL80211_SCAN_FLAG_FLUSH) { |
| 173 | /* flush entries from previous scans */ |
| 174 | spin_lock_bh(&rdev->bss_lock); |
| 175 | __cfg80211_bss_expire(rdev, request->scan_start); |
| 176 | spin_unlock_bh(&rdev->bss_lock); |
| 177 | request->scan_start = |
| 178 | jiffies + msecs_to_jiffies(request->interval); |
| 179 | } |
| 180 | nl80211_send_sched_scan_results(rdev, request->dev); |
| 181 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 182 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 183 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void cfg80211_sched_scan_results(struct wiphy *wiphy) |
| 187 | { |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 188 | trace_cfg80211_sched_scan_results(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 189 | /* ignore if we're not scanning */ |
| 190 | if (wiphy_to_dev(wiphy)->sched_scan_req) |
| 191 | queue_work(cfg80211_wq, |
| 192 | &wiphy_to_dev(wiphy)->sched_scan_results_wk); |
| 193 | } |
| 194 | EXPORT_SYMBOL(cfg80211_sched_scan_results); |
| 195 | |
Luciano Coelho | 85a9994 | 2011-05-12 16:28:29 +0300 | [diff] [blame] | 196 | void cfg80211_sched_scan_stopped(struct wiphy *wiphy) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 197 | { |
Luciano Coelho | 85a9994 | 2011-05-12 16:28:29 +0300 | [diff] [blame] | 198 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 199 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 200 | trace_cfg80211_sched_scan_stopped(wiphy); |
| 201 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 202 | mutex_lock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 203 | __cfg80211_stop_sched_scan(rdev, true); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 204 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 205 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 206 | EXPORT_SYMBOL(cfg80211_sched_scan_stopped); |
| 207 | |
| 208 | int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev, |
| 209 | bool driver_initiated) |
| 210 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 211 | struct net_device *dev; |
| 212 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 213 | lockdep_assert_held(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 214 | |
| 215 | if (!rdev->sched_scan_req) |
Luciano Coelho | 1a84ff7 | 2011-07-08 11:16:16 +0300 | [diff] [blame] | 216 | return -ENOENT; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 217 | |
| 218 | dev = rdev->sched_scan_req->dev; |
| 219 | |
Luciano Coelho | 85a9994 | 2011-05-12 16:28:29 +0300 | [diff] [blame] | 220 | if (!driver_initiated) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 221 | int err = rdev_sched_scan_stop(rdev, dev); |
Luciano Coelho | 85a9994 | 2011-05-12 16:28:29 +0300 | [diff] [blame] | 222 | if (err) |
| 223 | return err; |
| 224 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 225 | |
| 226 | nl80211_send_sched_scan(rdev, dev, NL80211_CMD_SCHED_SCAN_STOPPED); |
| 227 | |
| 228 | kfree(rdev->sched_scan_req); |
| 229 | rdev->sched_scan_req = NULL; |
| 230 | |
Jesper Juhl | 3b4670f | 2011-06-29 22:49:33 +0200 | [diff] [blame] | 231 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 232 | } |
| 233 | |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 234 | void cfg80211_bss_age(struct cfg80211_registered_device *dev, |
| 235 | unsigned long age_secs) |
| 236 | { |
| 237 | struct cfg80211_internal_bss *bss; |
| 238 | unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC); |
| 239 | |
Johannes Berg | 2ca813a | 2013-02-01 01:04:14 +0100 | [diff] [blame^] | 240 | spin_lock_bh(&dev->bss_lock); |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame] | 241 | list_for_each_entry(bss, &dev->bss_list, list) |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 242 | bss->ts -= age_jiffies; |
Johannes Berg | 2ca813a | 2013-02-01 01:04:14 +0100 | [diff] [blame^] | 243 | spin_unlock_bh(&dev->bss_lock); |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 244 | } |
| 245 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 246 | void cfg80211_bss_expire(struct cfg80211_registered_device *dev) |
| 247 | { |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 248 | __cfg80211_bss_expire(dev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 251 | const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 252 | { |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 253 | while (len > 2 && ies[0] != eid) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 254 | len -= ies[1] + 2; |
| 255 | ies += ies[1] + 2; |
| 256 | } |
| 257 | if (len < 2) |
| 258 | return NULL; |
| 259 | if (len < 2 + ies[1]) |
| 260 | return NULL; |
| 261 | return ies; |
| 262 | } |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 263 | EXPORT_SYMBOL(cfg80211_find_ie); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 264 | |
Eliad Peller | 0c28ec5 | 2011-09-15 11:53:01 +0300 | [diff] [blame] | 265 | const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 oui_type, |
| 266 | const u8 *ies, int len) |
| 267 | { |
| 268 | struct ieee80211_vendor_ie *ie; |
| 269 | const u8 *pos = ies, *end = ies + len; |
| 270 | int ie_oui; |
| 271 | |
| 272 | while (pos < end) { |
| 273 | pos = cfg80211_find_ie(WLAN_EID_VENDOR_SPECIFIC, pos, |
| 274 | end - pos); |
| 275 | if (!pos) |
| 276 | return NULL; |
| 277 | |
| 278 | if (end - pos < sizeof(*ie)) |
| 279 | return NULL; |
| 280 | |
| 281 | ie = (struct ieee80211_vendor_ie *)pos; |
| 282 | ie_oui = ie->oui[0] << 16 | ie->oui[1] << 8 | ie->oui[2]; |
| 283 | if (ie_oui == oui && ie->oui_type == oui_type) |
| 284 | return pos; |
| 285 | |
| 286 | pos += 2 + ie->len; |
| 287 | } |
| 288 | return NULL; |
| 289 | } |
| 290 | EXPORT_SYMBOL(cfg80211_find_vendor_ie); |
| 291 | |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame] | 292 | static bool is_bss(struct cfg80211_bss *a, const u8 *bssid, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 293 | const u8 *ssid, size_t ssid_len) |
| 294 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 295 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 296 | const u8 *ssidie; |
| 297 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 298 | if (bssid && !ether_addr_equal(a->bssid, bssid)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 299 | return false; |
| 300 | |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 301 | if (!ssid) |
| 302 | return true; |
| 303 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 304 | ies = rcu_access_pointer(a->ies); |
| 305 | if (!ies) |
| 306 | return false; |
| 307 | ssidie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 308 | if (!ssidie) |
| 309 | return false; |
| 310 | if (ssidie[1] != ssid_len) |
| 311 | return false; |
| 312 | return memcmp(ssidie + 2, ssid, ssid_len) == 0; |
| 313 | } |
| 314 | |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 315 | /** |
| 316 | * enum bss_compare_mode - BSS compare mode |
| 317 | * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find) |
| 318 | * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode |
| 319 | * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode |
| 320 | */ |
| 321 | enum bss_compare_mode { |
| 322 | BSS_CMP_REGULAR, |
| 323 | BSS_CMP_HIDE_ZLEN, |
| 324 | BSS_CMP_HIDE_NUL, |
| 325 | }; |
| 326 | |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 327 | static int cmp_bss(struct cfg80211_bss *a, |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 328 | struct cfg80211_bss *b, |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 329 | enum bss_compare_mode mode) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 330 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 331 | const struct cfg80211_bss_ies *a_ies, *b_ies; |
Johannes Berg | 3af6341 | 2013-01-30 00:40:20 +0100 | [diff] [blame] | 332 | const u8 *ie1 = NULL; |
| 333 | const u8 *ie2 = NULL; |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 334 | int i, r; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 335 | |
Johannes Berg | 3af6341 | 2013-01-30 00:40:20 +0100 | [diff] [blame] | 336 | if (a->channel != b->channel) |
| 337 | return b->channel->center_freq - a->channel->center_freq; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 338 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 339 | a_ies = rcu_access_pointer(a->ies); |
| 340 | if (!a_ies) |
| 341 | return -1; |
| 342 | b_ies = rcu_access_pointer(b->ies); |
| 343 | if (!b_ies) |
| 344 | return 1; |
| 345 | |
Johannes Berg | 3af6341 | 2013-01-30 00:40:20 +0100 | [diff] [blame] | 346 | if (WLAN_CAPABILITY_IS_STA_BSS(a->capability)) |
| 347 | ie1 = cfg80211_find_ie(WLAN_EID_MESH_ID, |
| 348 | a_ies->data, a_ies->len); |
| 349 | if (WLAN_CAPABILITY_IS_STA_BSS(b->capability)) |
| 350 | ie2 = cfg80211_find_ie(WLAN_EID_MESH_ID, |
| 351 | b_ies->data, b_ies->len); |
| 352 | if (ie1 && ie2) { |
| 353 | int mesh_id_cmp; |
| 354 | |
| 355 | if (ie1[1] == ie2[1]) |
| 356 | mesh_id_cmp = memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
| 357 | else |
| 358 | mesh_id_cmp = ie2[1] - ie1[1]; |
| 359 | |
| 360 | ie1 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, |
| 361 | a_ies->data, a_ies->len); |
| 362 | ie2 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, |
| 363 | b_ies->data, b_ies->len); |
| 364 | if (ie1 && ie2) { |
| 365 | if (mesh_id_cmp) |
| 366 | return mesh_id_cmp; |
| 367 | if (ie1[1] != ie2[1]) |
| 368 | return ie2[1] - ie1[1]; |
| 369 | return memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * we can't use compare_ether_addr here since we need a < > operator. |
| 375 | * The binary return value of compare_ether_addr isn't enough |
| 376 | */ |
| 377 | r = memcmp(a->bssid, b->bssid, sizeof(a->bssid)); |
| 378 | if (r) |
| 379 | return r; |
| 380 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 381 | ie1 = cfg80211_find_ie(WLAN_EID_SSID, a_ies->data, a_ies->len); |
| 382 | ie2 = cfg80211_find_ie(WLAN_EID_SSID, b_ies->data, b_ies->len); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 383 | |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 384 | if (!ie1 && !ie2) |
| 385 | return 0; |
| 386 | |
Johannes Berg | f94f8b1 | 2012-11-28 22:42:34 +0100 | [diff] [blame] | 387 | /* |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 388 | * Note that with "hide_ssid", the function returns a match if |
| 389 | * the already-present BSS ("b") is a hidden SSID beacon for |
| 390 | * the new BSS ("a"). |
Johannes Berg | f94f8b1 | 2012-11-28 22:42:34 +0100 | [diff] [blame] | 391 | */ |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 392 | |
| 393 | /* sort missing IE before (left of) present IE */ |
| 394 | if (!ie1) |
| 395 | return -1; |
| 396 | if (!ie2) |
| 397 | return 1; |
| 398 | |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 399 | switch (mode) { |
| 400 | case BSS_CMP_HIDE_ZLEN: |
| 401 | /* |
| 402 | * In ZLEN mode we assume the BSS entry we're |
| 403 | * looking for has a zero-length SSID. So if |
| 404 | * the one we're looking at right now has that, |
| 405 | * return 0. Otherwise, return the difference |
| 406 | * in length, but since we're looking for the |
| 407 | * 0-length it's really equivalent to returning |
| 408 | * the length of the one we're looking at. |
| 409 | * |
| 410 | * No content comparison is needed as we assume |
| 411 | * the content length is zero. |
| 412 | */ |
| 413 | return ie2[1]; |
| 414 | case BSS_CMP_REGULAR: |
| 415 | default: |
| 416 | /* sort by length first, then by contents */ |
| 417 | if (ie1[1] != ie2[1]) |
| 418 | return ie2[1] - ie1[1]; |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 419 | return memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 420 | case BSS_CMP_HIDE_NUL: |
| 421 | if (ie1[1] != ie2[1]) |
| 422 | return ie2[1] - ie1[1]; |
| 423 | /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */ |
| 424 | for (i = 0; i < ie2[1]; i++) |
| 425 | if (ie2[i + 2]) |
| 426 | return -1; |
| 427 | return 0; |
| 428 | } |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 431 | struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy, |
| 432 | struct ieee80211_channel *channel, |
| 433 | const u8 *bssid, |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 434 | const u8 *ssid, size_t ssid_len, |
| 435 | u16 capa_mask, u16 capa_val) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 436 | { |
| 437 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); |
| 438 | struct cfg80211_internal_bss *bss, *res = NULL; |
Johannes Berg | ccb6c13 | 2010-07-13 10:55:38 +0200 | [diff] [blame] | 439 | unsigned long now = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 440 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 441 | trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, capa_mask, |
| 442 | capa_val); |
| 443 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 444 | spin_lock_bh(&dev->bss_lock); |
| 445 | |
| 446 | list_for_each_entry(bss, &dev->bss_list, list) { |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 447 | if ((bss->pub.capability & capa_mask) != capa_val) |
| 448 | continue; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 449 | if (channel && bss->pub.channel != channel) |
| 450 | continue; |
Johannes Berg | ccb6c13 | 2010-07-13 10:55:38 +0200 | [diff] [blame] | 451 | /* Don't get expired BSS structs */ |
| 452 | if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) && |
| 453 | !atomic_read(&bss->hold)) |
| 454 | continue; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 455 | if (is_bss(&bss->pub, bssid, ssid, ssid_len)) { |
| 456 | res = bss; |
| 457 | kref_get(&res->ref); |
| 458 | break; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | spin_unlock_bh(&dev->bss_lock); |
| 463 | if (!res) |
| 464 | return NULL; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 465 | trace_cfg80211_return_bss(&res->pub); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 466 | return &res->pub; |
| 467 | } |
| 468 | EXPORT_SYMBOL(cfg80211_get_bss); |
| 469 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 470 | static void rb_insert_bss(struct cfg80211_registered_device *dev, |
| 471 | struct cfg80211_internal_bss *bss) |
| 472 | { |
| 473 | struct rb_node **p = &dev->bss_tree.rb_node; |
| 474 | struct rb_node *parent = NULL; |
| 475 | struct cfg80211_internal_bss *tbss; |
| 476 | int cmp; |
| 477 | |
| 478 | while (*p) { |
| 479 | parent = *p; |
| 480 | tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn); |
| 481 | |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 482 | cmp = cmp_bss(&bss->pub, &tbss->pub, BSS_CMP_REGULAR); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 483 | |
| 484 | if (WARN_ON(!cmp)) { |
| 485 | /* will sort of leak this BSS */ |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | if (cmp < 0) |
| 490 | p = &(*p)->rb_left; |
| 491 | else |
| 492 | p = &(*p)->rb_right; |
| 493 | } |
| 494 | |
| 495 | rb_link_node(&bss->rbn, parent, p); |
| 496 | rb_insert_color(&bss->rbn, &dev->bss_tree); |
| 497 | } |
| 498 | |
| 499 | static struct cfg80211_internal_bss * |
| 500 | rb_find_bss(struct cfg80211_registered_device *dev, |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 501 | struct cfg80211_internal_bss *res, |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 502 | enum bss_compare_mode mode) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 503 | { |
| 504 | struct rb_node *n = dev->bss_tree.rb_node; |
| 505 | struct cfg80211_internal_bss *bss; |
| 506 | int r; |
| 507 | |
| 508 | while (n) { |
| 509 | bss = rb_entry(n, struct cfg80211_internal_bss, rbn); |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 510 | r = cmp_bss(&res->pub, &bss->pub, mode); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 511 | |
| 512 | if (r == 0) |
| 513 | return bss; |
| 514 | else if (r < 0) |
| 515 | n = n->rb_left; |
| 516 | else |
| 517 | n = n->rb_right; |
| 518 | } |
| 519 | |
| 520 | return NULL; |
| 521 | } |
| 522 | |
| 523 | static void |
| 524 | copy_hidden_ies(struct cfg80211_internal_bss *res, |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame] | 525 | struct cfg80211_internal_bss *hidden) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 526 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 527 | const struct cfg80211_bss_ies *ies; |
| 528 | |
| 529 | if (rcu_access_pointer(res->pub.beacon_ies)) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 530 | return; |
| 531 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 532 | ies = rcu_access_pointer(hidden->pub.beacon_ies); |
| 533 | if (WARN_ON(!ies)) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 534 | return; |
| 535 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 536 | ies = kmemdup(ies, sizeof(*ies) + ies->len, GFP_ATOMIC); |
| 537 | if (unlikely(!ies)) |
| 538 | return; |
| 539 | rcu_assign_pointer(res->pub.beacon_ies, ies); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static struct cfg80211_internal_bss * |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 543 | cfg80211_bss_update(struct cfg80211_registered_device *dev, |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 544 | struct cfg80211_internal_bss *tmp) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 545 | { |
| 546 | struct cfg80211_internal_bss *found = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 547 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 548 | if (WARN_ON(!tmp->pub.channel)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 549 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 550 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 551 | tmp->ts = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 552 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 553 | spin_lock_bh(&dev->bss_lock); |
| 554 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 555 | if (WARN_ON(!rcu_access_pointer(tmp->pub.ies))) { |
| 556 | spin_unlock_bh(&dev->bss_lock); |
| 557 | return NULL; |
| 558 | } |
| 559 | |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 560 | found = rb_find_bss(dev, tmp, BSS_CMP_REGULAR); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 561 | |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 562 | if (found) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 563 | found->pub.beacon_interval = tmp->pub.beacon_interval; |
| 564 | found->pub.tsf = tmp->pub.tsf; |
| 565 | found->pub.signal = tmp->pub.signal; |
| 566 | found->pub.capability = tmp->pub.capability; |
| 567 | found->ts = tmp->ts; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 568 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 569 | /* Update IEs */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 570 | if (rcu_access_pointer(tmp->pub.proberesp_ies)) { |
| 571 | const struct cfg80211_bss_ies *old; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 572 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 573 | old = rcu_access_pointer(found->pub.proberesp_ies); |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 574 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 575 | rcu_assign_pointer(found->pub.proberesp_ies, |
| 576 | tmp->pub.proberesp_ies); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 577 | /* Override possible earlier Beacon frame IEs */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 578 | rcu_assign_pointer(found->pub.ies, |
| 579 | tmp->pub.proberesp_ies); |
| 580 | if (old) |
| 581 | kfree_rcu((struct cfg80211_bss_ies *)old, |
| 582 | rcu_head); |
| 583 | } else if (rcu_access_pointer(tmp->pub.beacon_ies)) { |
| 584 | const struct cfg80211_bss_ies *old, *ies; |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame] | 585 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 586 | old = rcu_access_pointer(found->pub.beacon_ies); |
| 587 | ies = rcu_access_pointer(found->pub.ies); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 588 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 589 | rcu_assign_pointer(found->pub.beacon_ies, |
| 590 | tmp->pub.beacon_ies); |
Sven Neumann | 01123e2 | 2010-12-09 15:05:24 +0100 | [diff] [blame] | 591 | |
| 592 | /* Override IEs if they were from a beacon before */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 593 | if (old == ies) |
| 594 | rcu_assign_pointer(found->pub.ies, |
| 595 | tmp->pub.beacon_ies); |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 596 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 597 | if (old) |
| 598 | kfree_rcu((struct cfg80211_bss_ies *)old, |
| 599 | rcu_head); |
| 600 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 601 | } else { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 602 | struct cfg80211_internal_bss *new; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 603 | struct cfg80211_internal_bss *hidden; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 604 | struct cfg80211_bss_ies *ies; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 605 | |
| 606 | /* First check if the beacon is a probe response from |
| 607 | * a hidden bss. If so, copy beacon ies (with nullified |
| 608 | * ssid) into the probe response bss entry (with real ssid). |
| 609 | * It is required basically for PSM implementation |
| 610 | * (probe responses do not contain tim ie) */ |
| 611 | |
| 612 | /* TODO: The code is not trying to update existing probe |
| 613 | * response bss entries when beacon ies are |
| 614 | * getting changed. */ |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 615 | hidden = rb_find_bss(dev, tmp, BSS_CMP_HIDE_ZLEN); |
| 616 | if (hidden) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 617 | copy_hidden_ies(tmp, hidden); |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 618 | } else { |
| 619 | hidden = rb_find_bss(dev, tmp, BSS_CMP_HIDE_NUL); |
| 620 | if (hidden) |
| 621 | copy_hidden_ies(tmp, hidden); |
| 622 | } |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 623 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 624 | /* |
| 625 | * create a copy -- the "res" variable that is passed in |
| 626 | * is allocated on the stack since it's not needed in the |
| 627 | * more common case of an update |
| 628 | */ |
| 629 | new = kzalloc(sizeof(*new) + dev->wiphy.bss_priv_size, |
| 630 | GFP_ATOMIC); |
| 631 | if (!new) { |
| 632 | ies = (void *)rcu_dereference(tmp->pub.beacon_ies); |
| 633 | if (ies) |
| 634 | kfree_rcu(ies, rcu_head); |
| 635 | ies = (void *)rcu_dereference(tmp->pub.proberesp_ies); |
| 636 | if (ies) |
| 637 | kfree_rcu(ies, rcu_head); |
| 638 | spin_unlock_bh(&dev->bss_lock); |
| 639 | return NULL; |
| 640 | } |
| 641 | memcpy(new, tmp, sizeof(*new)); |
| 642 | kref_init(&new->ref); |
| 643 | list_add_tail(&new->list, &dev->bss_list); |
| 644 | rb_insert_bss(dev, new); |
| 645 | found = new; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | dev->bss_generation++; |
| 649 | spin_unlock_bh(&dev->bss_lock); |
| 650 | |
| 651 | kref_get(&found->ref); |
| 652 | return found; |
| 653 | } |
| 654 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 655 | static struct ieee80211_channel * |
| 656 | cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen, |
| 657 | struct ieee80211_channel *channel) |
| 658 | { |
| 659 | const u8 *tmp; |
| 660 | u32 freq; |
| 661 | int channel_number = -1; |
| 662 | |
| 663 | tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen); |
| 664 | if (tmp && tmp[1] == 1) { |
| 665 | channel_number = tmp[2]; |
| 666 | } else { |
| 667 | tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen); |
| 668 | if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) { |
| 669 | struct ieee80211_ht_operation *htop = (void *)(tmp + 2); |
| 670 | |
| 671 | channel_number = htop->primary_chan; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | if (channel_number < 0) |
| 676 | return channel; |
| 677 | |
| 678 | freq = ieee80211_channel_to_frequency(channel_number, channel->band); |
| 679 | channel = ieee80211_get_channel(wiphy, freq); |
| 680 | if (!channel) |
| 681 | return NULL; |
| 682 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 683 | return NULL; |
| 684 | return channel; |
| 685 | } |
| 686 | |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 687 | struct cfg80211_bss* |
| 688 | cfg80211_inform_bss(struct wiphy *wiphy, |
| 689 | struct ieee80211_channel *channel, |
Johannes Berg | 7b8bcff | 2012-03-13 13:57:04 +0100 | [diff] [blame] | 690 | const u8 *bssid, u64 tsf, u16 capability, |
| 691 | u16 beacon_interval, const u8 *ie, size_t ielen, |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 692 | s32 signal, gfp_t gfp) |
| 693 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 694 | struct cfg80211_bss_ies *ies; |
| 695 | struct cfg80211_internal_bss tmp = {}, *res; |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 696 | |
| 697 | if (WARN_ON(!wiphy)) |
| 698 | return NULL; |
| 699 | |
Sujith | 22fe88d | 2010-05-13 10:34:08 +0530 | [diff] [blame] | 700 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 701 | (signal < 0 || signal > 100))) |
| 702 | return NULL; |
| 703 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 704 | channel = cfg80211_get_bss_channel(wiphy, ie, ielen, channel); |
| 705 | if (!channel) |
| 706 | return NULL; |
| 707 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 708 | memcpy(tmp.pub.bssid, bssid, ETH_ALEN); |
| 709 | tmp.pub.channel = channel; |
| 710 | tmp.pub.signal = signal; |
| 711 | tmp.pub.tsf = tsf; |
| 712 | tmp.pub.beacon_interval = beacon_interval; |
| 713 | tmp.pub.capability = capability; |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 714 | /* |
| 715 | * Since we do not know here whether the IEs are from a Beacon or Probe |
| 716 | * Response frame, we need to pick one of the options and only use it |
| 717 | * with the driver that does not provide the full Beacon/Probe Response |
| 718 | * frame. Use Beacon frame pointer to avoid indicating that this should |
Johannes Berg | 50521aa | 2013-01-30 21:33:19 +0100 | [diff] [blame] | 719 | * override the IEs pointer should we have received an earlier |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 720 | * indication of Probe Response data. |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 721 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 722 | ies = kmalloc(sizeof(*ies) + ielen, gfp); |
| 723 | if (!ies) |
| 724 | return NULL; |
| 725 | ies->len = ielen; |
| 726 | memcpy(ies->data, ie, ielen); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 727 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 728 | rcu_assign_pointer(tmp.pub.beacon_ies, ies); |
| 729 | rcu_assign_pointer(tmp.pub.ies, ies); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 730 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 731 | res = cfg80211_bss_update(wiphy_to_dev(wiphy), &tmp); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 732 | if (!res) |
| 733 | return NULL; |
| 734 | |
| 735 | if (res->pub.capability & WLAN_CAPABILITY_ESS) |
| 736 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 737 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 738 | trace_cfg80211_return_bss(&res->pub); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 739 | /* cfg80211_bss_update gives us a referenced result */ |
| 740 | return &res->pub; |
| 741 | } |
| 742 | EXPORT_SYMBOL(cfg80211_inform_bss); |
| 743 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 744 | struct cfg80211_bss * |
| 745 | cfg80211_inform_bss_frame(struct wiphy *wiphy, |
| 746 | struct ieee80211_channel *channel, |
| 747 | struct ieee80211_mgmt *mgmt, size_t len, |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 748 | s32 signal, gfp_t gfp) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 749 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 750 | struct cfg80211_internal_bss tmp = {}, *res; |
| 751 | struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 752 | size_t ielen = len - offsetof(struct ieee80211_mgmt, |
| 753 | u.probe_resp.variable); |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 754 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 755 | BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) != |
| 756 | offsetof(struct ieee80211_mgmt, u.beacon.variable)); |
| 757 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 758 | trace_cfg80211_inform_bss_frame(wiphy, channel, mgmt, len, signal); |
| 759 | |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 760 | if (WARN_ON(!mgmt)) |
| 761 | return NULL; |
| 762 | |
| 763 | if (WARN_ON(!wiphy)) |
| 764 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 765 | |
Sujith | 22fe88d | 2010-05-13 10:34:08 +0530 | [diff] [blame] | 766 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
Hila Gonen | 768be59 | 2012-08-26 11:00:28 +0300 | [diff] [blame] | 767 | (signal < 0 || signal > 100))) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 768 | return NULL; |
| 769 | |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 770 | if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable))) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 771 | return NULL; |
| 772 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 773 | channel = cfg80211_get_bss_channel(wiphy, mgmt->u.beacon.variable, |
| 774 | ielen, channel); |
| 775 | if (!channel) |
| 776 | return NULL; |
| 777 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 778 | ies = kmalloc(sizeof(*ies) + ielen, gfp); |
| 779 | if (!ies) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 780 | return NULL; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 781 | ies->len = ielen; |
| 782 | memcpy(ies->data, mgmt->u.probe_resp.variable, ielen); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 783 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 784 | if (ieee80211_is_probe_resp(mgmt->frame_control)) |
| 785 | rcu_assign_pointer(tmp.pub.proberesp_ies, ies); |
| 786 | else |
| 787 | rcu_assign_pointer(tmp.pub.beacon_ies, ies); |
| 788 | rcu_assign_pointer(tmp.pub.ies, ies); |
| 789 | |
| 790 | memcpy(tmp.pub.bssid, mgmt->bssid, ETH_ALEN); |
| 791 | tmp.pub.channel = channel; |
| 792 | tmp.pub.signal = signal; |
| 793 | tmp.pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp); |
| 794 | tmp.pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int); |
| 795 | tmp.pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 796 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 797 | res = cfg80211_bss_update(wiphy_to_dev(wiphy), &tmp); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 798 | if (!res) |
| 799 | return NULL; |
| 800 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 801 | if (res->pub.capability & WLAN_CAPABILITY_ESS) |
| 802 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 803 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 804 | trace_cfg80211_return_bss(&res->pub); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 805 | /* cfg80211_bss_update gives us a referenced result */ |
| 806 | return &res->pub; |
| 807 | } |
| 808 | EXPORT_SYMBOL(cfg80211_inform_bss_frame); |
| 809 | |
Johannes Berg | 4c0c0b7 | 2012-01-20 13:55:26 +0100 | [diff] [blame] | 810 | void cfg80211_ref_bss(struct cfg80211_bss *pub) |
| 811 | { |
| 812 | struct cfg80211_internal_bss *bss; |
| 813 | |
| 814 | if (!pub) |
| 815 | return; |
| 816 | |
| 817 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
| 818 | kref_get(&bss->ref); |
| 819 | } |
| 820 | EXPORT_SYMBOL(cfg80211_ref_bss); |
| 821 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 822 | void cfg80211_put_bss(struct cfg80211_bss *pub) |
| 823 | { |
| 824 | struct cfg80211_internal_bss *bss; |
| 825 | |
| 826 | if (!pub) |
| 827 | return; |
| 828 | |
| 829 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
| 830 | kref_put(&bss->ref, bss_release); |
| 831 | } |
| 832 | EXPORT_SYMBOL(cfg80211_put_bss); |
| 833 | |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 834 | void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
| 835 | { |
| 836 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); |
| 837 | struct cfg80211_internal_bss *bss; |
| 838 | |
| 839 | if (WARN_ON(!pub)) |
| 840 | return; |
| 841 | |
| 842 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
| 843 | |
| 844 | spin_lock_bh(&dev->bss_lock); |
Johannes Berg | 3207390 | 2010-10-06 21:18:04 +0200 | [diff] [blame] | 845 | if (!list_empty(&bss->list)) { |
Juuso Oikarinen | 2b78ac9 | 2011-03-28 14:32:32 +0300 | [diff] [blame] | 846 | __cfg80211_unlink_bss(dev, bss); |
Johannes Berg | 3207390 | 2010-10-06 21:18:04 +0200 | [diff] [blame] | 847 | dev->bss_generation++; |
Johannes Berg | 3207390 | 2010-10-06 21:18:04 +0200 | [diff] [blame] | 848 | } |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 849 | spin_unlock_bh(&dev->bss_lock); |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 850 | } |
| 851 | EXPORT_SYMBOL(cfg80211_unlink_bss); |
| 852 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 853 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 854 | int cfg80211_wext_siwscan(struct net_device *dev, |
| 855 | struct iw_request_info *info, |
| 856 | union iwreq_data *wrqu, char *extra) |
| 857 | { |
| 858 | struct cfg80211_registered_device *rdev; |
| 859 | struct wiphy *wiphy; |
| 860 | struct iw_scan_req *wreq = NULL; |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 861 | struct cfg80211_scan_request *creq = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 862 | int i, err, n_channels = 0; |
| 863 | enum ieee80211_band band; |
| 864 | |
| 865 | if (!netif_running(dev)) |
| 866 | return -ENETDOWN; |
| 867 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 868 | if (wrqu->data.length == sizeof(struct iw_scan_req)) |
| 869 | wreq = (struct iw_scan_req *)extra; |
| 870 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 871 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 872 | |
| 873 | if (IS_ERR(rdev)) |
| 874 | return PTR_ERR(rdev); |
| 875 | |
| 876 | if (rdev->scan_req) { |
| 877 | err = -EBUSY; |
| 878 | goto out; |
| 879 | } |
| 880 | |
| 881 | wiphy = &rdev->wiphy; |
| 882 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 883 | /* Determine number of channels, needed to allocate creq */ |
| 884 | if (wreq && wreq->num_channels) |
| 885 | n_channels = wreq->num_channels; |
| 886 | else { |
| 887 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 888 | if (wiphy->bands[band]) |
| 889 | n_channels += wiphy->bands[band]->n_channels; |
| 890 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 891 | |
| 892 | creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) + |
| 893 | n_channels * sizeof(void *), |
| 894 | GFP_ATOMIC); |
| 895 | if (!creq) { |
| 896 | err = -ENOMEM; |
| 897 | goto out; |
| 898 | } |
| 899 | |
| 900 | creq->wiphy = wiphy; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 901 | creq->wdev = dev->ieee80211_ptr; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 902 | /* SSIDs come after channels */ |
| 903 | creq->ssids = (void *)&creq->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 904 | creq->n_channels = n_channels; |
| 905 | creq->n_ssids = 1; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 906 | creq->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 907 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 908 | /* translate "Scan on frequencies" request */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 909 | i = 0; |
| 910 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 911 | int j; |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 912 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 913 | if (!wiphy->bands[band]) |
| 914 | continue; |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 915 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 916 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 917 | /* ignore disabled channels */ |
| 918 | if (wiphy->bands[band]->channels[j].flags & |
| 919 | IEEE80211_CHAN_DISABLED) |
| 920 | continue; |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 921 | |
| 922 | /* If we have a wireless request structure and the |
| 923 | * wireless request specifies frequencies, then search |
| 924 | * for the matching hardware channel. |
| 925 | */ |
| 926 | if (wreq && wreq->num_channels) { |
| 927 | int k; |
| 928 | int wiphy_freq = wiphy->bands[band]->channels[j].center_freq; |
| 929 | for (k = 0; k < wreq->num_channels; k++) { |
Holger Schurig | a4e7b73 | 2009-09-11 10:13:53 +0200 | [diff] [blame] | 930 | int wext_freq = cfg80211_wext_freq(wiphy, &wreq->channel_list[k]); |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 931 | if (wext_freq == wiphy_freq) |
| 932 | goto wext_freq_found; |
| 933 | } |
| 934 | goto wext_freq_not_found; |
| 935 | } |
| 936 | |
| 937 | wext_freq_found: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 938 | creq->channels[i] = &wiphy->bands[band]->channels[j]; |
| 939 | i++; |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 940 | wext_freq_not_found: ; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 941 | } |
| 942 | } |
Holger Schurig | 8862dc5 | 2009-09-11 10:13:55 +0200 | [diff] [blame] | 943 | /* No channels found? */ |
| 944 | if (!i) { |
| 945 | err = -EINVAL; |
| 946 | goto out; |
| 947 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 948 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 949 | /* Set real number of channels specified in creq->channels[] */ |
| 950 | creq->n_channels = i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 951 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 952 | /* translate "Scan for SSID" request */ |
| 953 | if (wreq) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 954 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 955 | if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) { |
| 956 | err = -EINVAL; |
| 957 | goto out; |
| 958 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 959 | memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len); |
| 960 | creq->ssids[0].ssid_len = wreq->essid_len; |
| 961 | } |
| 962 | if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE) |
| 963 | creq->n_ssids = 0; |
| 964 | } |
| 965 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 966 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 967 | if (wiphy->bands[i]) |
| 968 | creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 969 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 970 | rdev->scan_req = creq; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 971 | err = rdev_scan(rdev, creq); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 972 | if (err) { |
| 973 | rdev->scan_req = NULL; |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 974 | /* creq will be freed below */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 975 | } else { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 976 | nl80211_send_scan_start(rdev, dev->ieee80211_ptr); |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 977 | /* creq now owned by driver */ |
| 978 | creq = NULL; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 979 | dev_hold(dev); |
| 980 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 981 | out: |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 982 | kfree(creq); |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 983 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 984 | return err; |
| 985 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 986 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 987 | |
| 988 | static void ieee80211_scan_add_ies(struct iw_request_info *info, |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 989 | const struct cfg80211_bss_ies *ies, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 990 | char **current_ev, char *end_buf) |
| 991 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 992 | const u8 *pos, *end, *next; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 993 | struct iw_event iwe; |
| 994 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 995 | if (!ies) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 996 | return; |
| 997 | |
| 998 | /* |
| 999 | * If needed, fragment the IEs buffer (at IE boundaries) into short |
| 1000 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. |
| 1001 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1002 | pos = ies->data; |
| 1003 | end = pos + ies->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1004 | |
| 1005 | while (end - pos > IW_GENERIC_IE_MAX) { |
| 1006 | next = pos + 2 + pos[1]; |
| 1007 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) |
| 1008 | next = next + 2 + next[1]; |
| 1009 | |
| 1010 | memset(&iwe, 0, sizeof(iwe)); |
| 1011 | iwe.cmd = IWEVGENIE; |
| 1012 | iwe.u.data.length = next - pos; |
| 1013 | *current_ev = iwe_stream_add_point(info, *current_ev, |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1014 | end_buf, &iwe, |
| 1015 | (void *)pos); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1016 | |
| 1017 | pos = next; |
| 1018 | } |
| 1019 | |
| 1020 | if (end > pos) { |
| 1021 | memset(&iwe, 0, sizeof(iwe)); |
| 1022 | iwe.cmd = IWEVGENIE; |
| 1023 | iwe.u.data.length = end - pos; |
| 1024 | *current_ev = iwe_stream_add_point(info, *current_ev, |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1025 | end_buf, &iwe, |
| 1026 | (void *)pos); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 1030 | static inline unsigned int elapsed_jiffies_msecs(unsigned long start) |
| 1031 | { |
| 1032 | unsigned long end = jiffies; |
| 1033 | |
| 1034 | if (end >= start) |
| 1035 | return jiffies_to_msecs(end - start); |
| 1036 | |
| 1037 | return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1); |
| 1038 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1039 | |
| 1040 | static char * |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1041 | ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info, |
| 1042 | struct cfg80211_internal_bss *bss, char *current_ev, |
| 1043 | char *end_buf) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1044 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1045 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1046 | struct iw_event iwe; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1047 | const u8 *ie; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1048 | u8 *buf, *cfg, *p; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1049 | int rem, i, sig; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1050 | bool ismesh = false; |
| 1051 | |
| 1052 | memset(&iwe, 0, sizeof(iwe)); |
| 1053 | iwe.cmd = SIOCGIWAP; |
| 1054 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 1055 | memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN); |
| 1056 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
| 1057 | IW_EV_ADDR_LEN); |
| 1058 | |
| 1059 | memset(&iwe, 0, sizeof(iwe)); |
| 1060 | iwe.cmd = SIOCGIWFREQ; |
| 1061 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq); |
| 1062 | iwe.u.freq.e = 0; |
| 1063 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
| 1064 | IW_EV_FREQ_LEN); |
| 1065 | |
| 1066 | memset(&iwe, 0, sizeof(iwe)); |
| 1067 | iwe.cmd = SIOCGIWFREQ; |
| 1068 | iwe.u.freq.m = bss->pub.channel->center_freq; |
| 1069 | iwe.u.freq.e = 6; |
| 1070 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
| 1071 | IW_EV_FREQ_LEN); |
| 1072 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1073 | if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1074 | memset(&iwe, 0, sizeof(iwe)); |
| 1075 | iwe.cmd = IWEVQUAL; |
| 1076 | iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED | |
| 1077 | IW_QUAL_NOISE_INVALID | |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1078 | IW_QUAL_QUAL_UPDATED; |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1079 | switch (wiphy->signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1080 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1081 | sig = bss->pub.signal / 100; |
| 1082 | iwe.u.qual.level = sig; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1083 | iwe.u.qual.updated |= IW_QUAL_DBM; |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1084 | if (sig < -110) /* rather bad */ |
| 1085 | sig = -110; |
| 1086 | else if (sig > -40) /* perfect */ |
| 1087 | sig = -40; |
| 1088 | /* will give a range of 0 .. 70 */ |
| 1089 | iwe.u.qual.qual = sig + 110; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1090 | break; |
| 1091 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 1092 | iwe.u.qual.level = bss->pub.signal; |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1093 | /* will give range 0 .. 100 */ |
| 1094 | iwe.u.qual.qual = bss->pub.signal; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1095 | break; |
| 1096 | default: |
| 1097 | /* not reached */ |
| 1098 | break; |
| 1099 | } |
| 1100 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
| 1101 | &iwe, IW_EV_QUAL_LEN); |
| 1102 | } |
| 1103 | |
| 1104 | memset(&iwe, 0, sizeof(iwe)); |
| 1105 | iwe.cmd = SIOCGIWENCODE; |
| 1106 | if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY) |
| 1107 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 1108 | else |
| 1109 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 1110 | iwe.u.data.length = 0; |
| 1111 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 1112 | &iwe, ""); |
| 1113 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1114 | rcu_read_lock(); |
| 1115 | ies = rcu_dereference(bss->pub.ies); |
| 1116 | if (ies) { |
| 1117 | rem = ies->len; |
| 1118 | ie = ies->data; |
| 1119 | } else { |
| 1120 | rem = 0; |
| 1121 | ie = NULL; |
| 1122 | } |
| 1123 | |
| 1124 | while (ies && rem >= 2) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1125 | /* invalid data */ |
| 1126 | if (ie[1] > rem - 2) |
| 1127 | break; |
| 1128 | |
| 1129 | switch (ie[0]) { |
| 1130 | case WLAN_EID_SSID: |
| 1131 | memset(&iwe, 0, sizeof(iwe)); |
| 1132 | iwe.cmd = SIOCGIWESSID; |
| 1133 | iwe.u.data.length = ie[1]; |
| 1134 | iwe.u.data.flags = 1; |
| 1135 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1136 | &iwe, (u8 *)ie + 2); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1137 | break; |
| 1138 | case WLAN_EID_MESH_ID: |
| 1139 | memset(&iwe, 0, sizeof(iwe)); |
| 1140 | iwe.cmd = SIOCGIWESSID; |
| 1141 | iwe.u.data.length = ie[1]; |
| 1142 | iwe.u.data.flags = 1; |
| 1143 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1144 | &iwe, (u8 *)ie + 2); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1145 | break; |
| 1146 | case WLAN_EID_MESH_CONFIG: |
| 1147 | ismesh = true; |
Rui Paulo | 136cfa2 | 2009-11-18 18:40:00 +0000 | [diff] [blame] | 1148 | if (ie[1] != sizeof(struct ieee80211_meshconf_ie)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1149 | break; |
| 1150 | buf = kmalloc(50, GFP_ATOMIC); |
| 1151 | if (!buf) |
| 1152 | break; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1153 | cfg = (u8 *)ie + 2; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1154 | memset(&iwe, 0, sizeof(iwe)); |
| 1155 | iwe.cmd = IWEVCUSTOM; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1156 | sprintf(buf, "Mesh Network Path Selection Protocol ID: " |
| 1157 | "0x%02X", cfg[0]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1158 | iwe.u.data.length = strlen(buf); |
| 1159 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1160 | end_buf, |
| 1161 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1162 | sprintf(buf, "Path Selection Metric ID: 0x%02X", |
| 1163 | cfg[1]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1164 | iwe.u.data.length = strlen(buf); |
| 1165 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1166 | end_buf, |
| 1167 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1168 | sprintf(buf, "Congestion Control Mode ID: 0x%02X", |
| 1169 | cfg[2]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1170 | iwe.u.data.length = strlen(buf); |
| 1171 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1172 | end_buf, |
| 1173 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1174 | sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1175 | iwe.u.data.length = strlen(buf); |
| 1176 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1177 | end_buf, |
| 1178 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1179 | sprintf(buf, "Authentication ID: 0x%02X", cfg[4]); |
| 1180 | iwe.u.data.length = strlen(buf); |
| 1181 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1182 | end_buf, |
| 1183 | &iwe, buf); |
| 1184 | sprintf(buf, "Formation Info: 0x%02X", cfg[5]); |
| 1185 | iwe.u.data.length = strlen(buf); |
| 1186 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1187 | end_buf, |
| 1188 | &iwe, buf); |
| 1189 | sprintf(buf, "Capabilities: 0x%02X", cfg[6]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1190 | iwe.u.data.length = strlen(buf); |
| 1191 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1192 | end_buf, |
| 1193 | &iwe, buf); |
| 1194 | kfree(buf); |
| 1195 | break; |
| 1196 | case WLAN_EID_SUPP_RATES: |
| 1197 | case WLAN_EID_EXT_SUPP_RATES: |
| 1198 | /* display all supported rates in readable format */ |
| 1199 | p = current_ev + iwe_stream_lcp_len(info); |
| 1200 | |
| 1201 | memset(&iwe, 0, sizeof(iwe)); |
| 1202 | iwe.cmd = SIOCGIWRATE; |
| 1203 | /* Those two flags are ignored... */ |
| 1204 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; |
| 1205 | |
| 1206 | for (i = 0; i < ie[1]; i++) { |
| 1207 | iwe.u.bitrate.value = |
| 1208 | ((ie[i + 2] & 0x7f) * 500000); |
| 1209 | p = iwe_stream_add_value(info, current_ev, p, |
| 1210 | end_buf, &iwe, IW_EV_PARAM_LEN); |
| 1211 | } |
| 1212 | current_ev = p; |
| 1213 | break; |
| 1214 | } |
| 1215 | rem -= ie[1] + 2; |
| 1216 | ie += ie[1] + 2; |
| 1217 | } |
| 1218 | |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 1219 | if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) || |
| 1220 | ismesh) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1221 | memset(&iwe, 0, sizeof(iwe)); |
| 1222 | iwe.cmd = SIOCGIWMODE; |
| 1223 | if (ismesh) |
| 1224 | iwe.u.mode = IW_MODE_MESH; |
| 1225 | else if (bss->pub.capability & WLAN_CAPABILITY_ESS) |
| 1226 | iwe.u.mode = IW_MODE_MASTER; |
| 1227 | else |
| 1228 | iwe.u.mode = IW_MODE_ADHOC; |
| 1229 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
| 1230 | &iwe, IW_EV_UINT_LEN); |
| 1231 | } |
| 1232 | |
| 1233 | buf = kmalloc(30, GFP_ATOMIC); |
| 1234 | if (buf) { |
| 1235 | memset(&iwe, 0, sizeof(iwe)); |
| 1236 | iwe.cmd = IWEVCUSTOM; |
| 1237 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->pub.tsf)); |
| 1238 | iwe.u.data.length = strlen(buf); |
| 1239 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 1240 | &iwe, buf); |
| 1241 | memset(&iwe, 0, sizeof(iwe)); |
| 1242 | iwe.cmd = IWEVCUSTOM; |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 1243 | sprintf(buf, " Last beacon: %ums ago", |
| 1244 | elapsed_jiffies_msecs(bss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1245 | iwe.u.data.length = strlen(buf); |
| 1246 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1247 | end_buf, &iwe, buf); |
| 1248 | kfree(buf); |
| 1249 | } |
| 1250 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1251 | ieee80211_scan_add_ies(info, ies, ¤t_ev, end_buf); |
| 1252 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1253 | |
| 1254 | return current_ev; |
| 1255 | } |
| 1256 | |
| 1257 | |
| 1258 | static int ieee80211_scan_results(struct cfg80211_registered_device *dev, |
| 1259 | struct iw_request_info *info, |
| 1260 | char *buf, size_t len) |
| 1261 | { |
| 1262 | char *current_ev = buf; |
| 1263 | char *end_buf = buf + len; |
| 1264 | struct cfg80211_internal_bss *bss; |
| 1265 | |
| 1266 | spin_lock_bh(&dev->bss_lock); |
| 1267 | cfg80211_bss_expire(dev); |
| 1268 | |
| 1269 | list_for_each_entry(bss, &dev->bss_list, list) { |
| 1270 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { |
| 1271 | spin_unlock_bh(&dev->bss_lock); |
| 1272 | return -E2BIG; |
| 1273 | } |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1274 | current_ev = ieee80211_bss(&dev->wiphy, info, bss, |
| 1275 | current_ev, end_buf); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1276 | } |
| 1277 | spin_unlock_bh(&dev->bss_lock); |
| 1278 | return current_ev - buf; |
| 1279 | } |
| 1280 | |
| 1281 | |
| 1282 | int cfg80211_wext_giwscan(struct net_device *dev, |
| 1283 | struct iw_request_info *info, |
| 1284 | struct iw_point *data, char *extra) |
| 1285 | { |
| 1286 | struct cfg80211_registered_device *rdev; |
| 1287 | int res; |
| 1288 | |
| 1289 | if (!netif_running(dev)) |
| 1290 | return -ENETDOWN; |
| 1291 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1292 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1293 | |
| 1294 | if (IS_ERR(rdev)) |
| 1295 | return PTR_ERR(rdev); |
| 1296 | |
| 1297 | if (rdev->scan_req) { |
| 1298 | res = -EAGAIN; |
| 1299 | goto out; |
| 1300 | } |
| 1301 | |
| 1302 | res = ieee80211_scan_results(rdev, info, extra, data->length); |
| 1303 | data->length = 0; |
| 1304 | if (res >= 0) { |
| 1305 | data->length = res; |
| 1306 | res = 0; |
| 1307 | } |
| 1308 | |
| 1309 | out: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 1310 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1311 | return res; |
| 1312 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 1313 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1314 | #endif |