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 | { |
| 26 | struct cfg80211_internal_bss *bss; |
| 27 | |
| 28 | bss = container_of(ref, struct cfg80211_internal_bss, ref); |
Johannes Berg | b629ea3 | 2012-11-28 22:14:56 +0100 | [diff] [blame] | 29 | |
| 30 | if (WARN_ON(atomic_read(&bss->hold))) |
| 31 | return; |
| 32 | |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 33 | if (bss->pub.free_priv) |
| 34 | bss->pub.free_priv(&bss->pub); |
| 35 | |
| 36 | if (bss->beacon_ies_allocated) |
| 37 | kfree(bss->pub.beacon_ies); |
| 38 | if (bss->proberesp_ies_allocated) |
| 39 | kfree(bss->pub.proberesp_ies); |
| 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 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 234 | /* must hold dev->bss_lock! */ |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 235 | void cfg80211_bss_age(struct cfg80211_registered_device *dev, |
| 236 | unsigned long age_secs) |
| 237 | { |
| 238 | struct cfg80211_internal_bss *bss; |
| 239 | unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC); |
| 240 | |
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; |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 243 | } |
| 244 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 245 | void cfg80211_bss_expire(struct cfg80211_registered_device *dev) |
| 246 | { |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 247 | __cfg80211_bss_expire(dev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 250 | const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 251 | { |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 252 | while (len > 2 && ies[0] != eid) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 253 | len -= ies[1] + 2; |
| 254 | ies += ies[1] + 2; |
| 255 | } |
| 256 | if (len < 2) |
| 257 | return NULL; |
| 258 | if (len < 2 + ies[1]) |
| 259 | return NULL; |
| 260 | return ies; |
| 261 | } |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 262 | EXPORT_SYMBOL(cfg80211_find_ie); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 263 | |
Eliad Peller | 0c28ec5 | 2011-09-15 11:53:01 +0300 | [diff] [blame] | 264 | const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 oui_type, |
| 265 | const u8 *ies, int len) |
| 266 | { |
| 267 | struct ieee80211_vendor_ie *ie; |
| 268 | const u8 *pos = ies, *end = ies + len; |
| 269 | int ie_oui; |
| 270 | |
| 271 | while (pos < end) { |
| 272 | pos = cfg80211_find_ie(WLAN_EID_VENDOR_SPECIFIC, pos, |
| 273 | end - pos); |
| 274 | if (!pos) |
| 275 | return NULL; |
| 276 | |
| 277 | if (end - pos < sizeof(*ie)) |
| 278 | return NULL; |
| 279 | |
| 280 | ie = (struct ieee80211_vendor_ie *)pos; |
| 281 | ie_oui = ie->oui[0] << 16 | ie->oui[1] << 8 | ie->oui[2]; |
| 282 | if (ie_oui == oui && ie->oui_type == oui_type) |
| 283 | return pos; |
| 284 | |
| 285 | pos += 2 + ie->len; |
| 286 | } |
| 287 | return NULL; |
| 288 | } |
| 289 | EXPORT_SYMBOL(cfg80211_find_vendor_ie); |
| 290 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 291 | static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2) |
| 292 | { |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 293 | const u8 *ie1 = cfg80211_find_ie(num, ies1, len1); |
| 294 | const u8 *ie2 = cfg80211_find_ie(num, ies2, len2); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 295 | |
Johannes Berg | 3b6ef63 | 2011-11-04 11:01:46 +0100 | [diff] [blame] | 296 | /* equal if both missing */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 297 | if (!ie1 && !ie2) |
| 298 | return 0; |
Johannes Berg | 3b6ef63 | 2011-11-04 11:01:46 +0100 | [diff] [blame] | 299 | /* sort missing IE before (left of) present IE */ |
| 300 | if (!ie1) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 301 | return -1; |
Johannes Berg | 3b6ef63 | 2011-11-04 11:01:46 +0100 | [diff] [blame] | 302 | if (!ie2) |
| 303 | return 1; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 304 | |
Johannes Berg | 3b6ef63 | 2011-11-04 11:01:46 +0100 | [diff] [blame] | 305 | /* sort by length first, then by contents */ |
| 306 | if (ie1[1] != ie2[1]) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 307 | return ie2[1] - ie1[1]; |
Johannes Berg | 3b6ef63 | 2011-11-04 11:01:46 +0100 | [diff] [blame] | 308 | return memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 311 | static bool is_bss(struct cfg80211_bss *a, const u8 *bssid, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 312 | const u8 *ssid, size_t ssid_len) |
| 313 | { |
| 314 | const u8 *ssidie; |
| 315 | |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 316 | if (bssid && !ether_addr_equal(a->bssid, bssid)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 317 | return false; |
| 318 | |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 319 | if (!ssid) |
| 320 | return true; |
| 321 | |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 322 | ssidie = cfg80211_find_ie(WLAN_EID_SSID, |
| 323 | a->information_elements, |
| 324 | a->len_information_elements); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 325 | if (!ssidie) |
| 326 | return false; |
| 327 | if (ssidie[1] != ssid_len) |
| 328 | return false; |
| 329 | return memcmp(ssidie + 2, ssid, ssid_len) == 0; |
| 330 | } |
| 331 | |
Eliad Peller | 333ba73 | 2011-05-29 15:53:20 +0300 | [diff] [blame] | 332 | static bool is_mesh_bss(struct cfg80211_bss *a) |
| 333 | { |
| 334 | const u8 *ie; |
| 335 | |
| 336 | if (!WLAN_CAPABILITY_IS_STA_BSS(a->capability)) |
| 337 | return false; |
| 338 | |
| 339 | ie = cfg80211_find_ie(WLAN_EID_MESH_ID, |
| 340 | a->information_elements, |
| 341 | a->len_information_elements); |
| 342 | if (!ie) |
| 343 | return false; |
| 344 | |
| 345 | ie = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, |
| 346 | a->information_elements, |
| 347 | a->len_information_elements); |
| 348 | if (!ie) |
| 349 | return false; |
| 350 | |
| 351 | return true; |
| 352 | } |
| 353 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 354 | static bool is_mesh(struct cfg80211_bss *a, |
| 355 | const u8 *meshid, size_t meshidlen, |
| 356 | const u8 *meshcfg) |
| 357 | { |
| 358 | const u8 *ie; |
| 359 | |
Eliad Peller | 333ba73 | 2011-05-29 15:53:20 +0300 | [diff] [blame] | 360 | if (!WLAN_CAPABILITY_IS_STA_BSS(a->capability)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 361 | return false; |
| 362 | |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 363 | ie = cfg80211_find_ie(WLAN_EID_MESH_ID, |
| 364 | a->information_elements, |
| 365 | a->len_information_elements); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 366 | if (!ie) |
| 367 | return false; |
| 368 | if (ie[1] != meshidlen) |
| 369 | return false; |
| 370 | if (memcmp(ie + 2, meshid, meshidlen)) |
| 371 | return false; |
| 372 | |
Johannes Berg | c21dbf9 | 2010-01-26 14:15:46 +0100 | [diff] [blame] | 373 | ie = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, |
| 374 | a->information_elements, |
| 375 | a->len_information_elements); |
Johannes Berg | cd3468b | 2009-07-29 22:07:44 +0200 | [diff] [blame] | 376 | if (!ie) |
| 377 | return false; |
Rui Paulo | 136cfa2 | 2009-11-18 18:40:00 +0000 | [diff] [blame] | 378 | if (ie[1] != sizeof(struct ieee80211_meshconf_ie)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 379 | return false; |
| 380 | |
| 381 | /* |
| 382 | * Ignore mesh capability (last two bytes of the IE) when |
| 383 | * comparing since that may differ between stations taking |
| 384 | * part in the same mesh. |
| 385 | */ |
Rui Paulo | 136cfa2 | 2009-11-18 18:40:00 +0000 | [diff] [blame] | 386 | return memcmp(ie + 2, meshcfg, |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 387 | sizeof(struct ieee80211_meshconf_ie) - 2) == 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 388 | } |
| 389 | |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 390 | static int cmp_bss_core(struct cfg80211_bss *a, struct cfg80211_bss *b) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 391 | { |
| 392 | int r; |
| 393 | |
| 394 | if (a->channel != b->channel) |
| 395 | return b->channel->center_freq - a->channel->center_freq; |
| 396 | |
Eliad Peller | 333ba73 | 2011-05-29 15:53:20 +0300 | [diff] [blame] | 397 | if (is_mesh_bss(a) && is_mesh_bss(b)) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 398 | r = cmp_ies(WLAN_EID_MESH_ID, |
| 399 | a->information_elements, |
| 400 | a->len_information_elements, |
| 401 | b->information_elements, |
| 402 | b->len_information_elements); |
| 403 | if (r) |
| 404 | return r; |
| 405 | return cmp_ies(WLAN_EID_MESH_CONFIG, |
| 406 | a->information_elements, |
| 407 | a->len_information_elements, |
| 408 | b->information_elements, |
| 409 | b->len_information_elements); |
| 410 | } |
| 411 | |
Emmanuel Grumbach | ef9456a | 2012-04-30 10:23:36 +0300 | [diff] [blame] | 412 | /* |
| 413 | * we can't use compare_ether_addr here since we need a < > operator. |
| 414 | * The binary return value of compare_ether_addr isn't enough |
| 415 | */ |
| 416 | return memcmp(a->bssid, b->bssid, sizeof(a->bssid)); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static int cmp_bss(struct cfg80211_bss *a, |
| 420 | struct cfg80211_bss *b) |
| 421 | { |
| 422 | int r; |
| 423 | |
| 424 | r = cmp_bss_core(a, b); |
Javier Cardona | 0a35d36 | 2011-05-04 10:24:56 -0700 | [diff] [blame] | 425 | if (r) |
| 426 | return r; |
| 427 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 428 | return cmp_ies(WLAN_EID_SSID, |
| 429 | a->information_elements, |
| 430 | a->len_information_elements, |
| 431 | b->information_elements, |
| 432 | b->len_information_elements); |
| 433 | } |
| 434 | |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 435 | static int cmp_hidden_bss(struct cfg80211_bss *a, struct cfg80211_bss *b) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 436 | { |
| 437 | const u8 *ie1; |
| 438 | const u8 *ie2; |
| 439 | int i; |
| 440 | int r; |
| 441 | |
| 442 | r = cmp_bss_core(a, b); |
| 443 | if (r) |
| 444 | return r; |
| 445 | |
| 446 | ie1 = cfg80211_find_ie(WLAN_EID_SSID, |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 447 | a->information_elements, |
| 448 | a->len_information_elements); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 449 | ie2 = cfg80211_find_ie(WLAN_EID_SSID, |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 450 | b->information_elements, |
| 451 | b->len_information_elements); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 452 | |
| 453 | /* Key comparator must use same algorithm in any rb-tree |
| 454 | * search function (order is important), otherwise ordering |
| 455 | * of items in the tree is broken and search gives incorrect |
| 456 | * results. This code uses same order as cmp_ies() does. */ |
| 457 | |
| 458 | /* sort missing IE before (left of) present IE */ |
| 459 | if (!ie1) |
| 460 | return -1; |
| 461 | if (!ie2) |
| 462 | return 1; |
| 463 | |
| 464 | /* zero-size SSID is used as an indication of the hidden bss */ |
| 465 | if (!ie2[1]) |
| 466 | return 0; |
| 467 | |
| 468 | /* sort by length first, then by contents */ |
| 469 | if (ie1[1] != ie2[1]) |
| 470 | return ie2[1] - ie1[1]; |
| 471 | |
| 472 | /* zeroed SSID ie is another indication of a hidden bss */ |
| 473 | for (i = 0; i < ie2[1]; i++) |
| 474 | if (ie2[i + 2]) |
| 475 | return -1; |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 480 | struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy, |
| 481 | struct ieee80211_channel *channel, |
| 482 | const u8 *bssid, |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 483 | const u8 *ssid, size_t ssid_len, |
| 484 | u16 capa_mask, u16 capa_val) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 485 | { |
| 486 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); |
| 487 | struct cfg80211_internal_bss *bss, *res = NULL; |
Johannes Berg | ccb6c13 | 2010-07-13 10:55:38 +0200 | [diff] [blame] | 488 | unsigned long now = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 489 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 490 | trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, capa_mask, |
| 491 | capa_val); |
| 492 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 493 | spin_lock_bh(&dev->bss_lock); |
| 494 | |
| 495 | list_for_each_entry(bss, &dev->bss_list, list) { |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 496 | if ((bss->pub.capability & capa_mask) != capa_val) |
| 497 | continue; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 498 | if (channel && bss->pub.channel != channel) |
| 499 | continue; |
Johannes Berg | ccb6c13 | 2010-07-13 10:55:38 +0200 | [diff] [blame] | 500 | /* Don't get expired BSS structs */ |
| 501 | if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) && |
| 502 | !atomic_read(&bss->hold)) |
| 503 | continue; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 504 | if (is_bss(&bss->pub, bssid, ssid, ssid_len)) { |
| 505 | res = bss; |
| 506 | kref_get(&res->ref); |
| 507 | break; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | spin_unlock_bh(&dev->bss_lock); |
| 512 | if (!res) |
| 513 | return NULL; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 514 | trace_cfg80211_return_bss(&res->pub); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 515 | return &res->pub; |
| 516 | } |
| 517 | EXPORT_SYMBOL(cfg80211_get_bss); |
| 518 | |
| 519 | struct cfg80211_bss *cfg80211_get_mesh(struct wiphy *wiphy, |
| 520 | struct ieee80211_channel *channel, |
| 521 | const u8 *meshid, size_t meshidlen, |
| 522 | const u8 *meshcfg) |
| 523 | { |
| 524 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); |
| 525 | struct cfg80211_internal_bss *bss, *res = NULL; |
| 526 | |
| 527 | spin_lock_bh(&dev->bss_lock); |
| 528 | |
| 529 | list_for_each_entry(bss, &dev->bss_list, list) { |
| 530 | if (channel && bss->pub.channel != channel) |
| 531 | continue; |
| 532 | if (is_mesh(&bss->pub, meshid, meshidlen, meshcfg)) { |
| 533 | res = bss; |
| 534 | kref_get(&res->ref); |
| 535 | break; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | spin_unlock_bh(&dev->bss_lock); |
| 540 | if (!res) |
| 541 | return NULL; |
| 542 | return &res->pub; |
| 543 | } |
| 544 | EXPORT_SYMBOL(cfg80211_get_mesh); |
| 545 | |
| 546 | |
| 547 | static void rb_insert_bss(struct cfg80211_registered_device *dev, |
| 548 | struct cfg80211_internal_bss *bss) |
| 549 | { |
| 550 | struct rb_node **p = &dev->bss_tree.rb_node; |
| 551 | struct rb_node *parent = NULL; |
| 552 | struct cfg80211_internal_bss *tbss; |
| 553 | int cmp; |
| 554 | |
| 555 | while (*p) { |
| 556 | parent = *p; |
| 557 | tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn); |
| 558 | |
| 559 | cmp = cmp_bss(&bss->pub, &tbss->pub); |
| 560 | |
| 561 | if (WARN_ON(!cmp)) { |
| 562 | /* will sort of leak this BSS */ |
| 563 | return; |
| 564 | } |
| 565 | |
| 566 | if (cmp < 0) |
| 567 | p = &(*p)->rb_left; |
| 568 | else |
| 569 | p = &(*p)->rb_right; |
| 570 | } |
| 571 | |
| 572 | rb_link_node(&bss->rbn, parent, p); |
| 573 | rb_insert_color(&bss->rbn, &dev->bss_tree); |
| 574 | } |
| 575 | |
| 576 | static struct cfg80211_internal_bss * |
| 577 | rb_find_bss(struct cfg80211_registered_device *dev, |
| 578 | struct cfg80211_internal_bss *res) |
| 579 | { |
| 580 | struct rb_node *n = dev->bss_tree.rb_node; |
| 581 | struct cfg80211_internal_bss *bss; |
| 582 | int r; |
| 583 | |
| 584 | while (n) { |
| 585 | bss = rb_entry(n, struct cfg80211_internal_bss, rbn); |
| 586 | r = cmp_bss(&res->pub, &bss->pub); |
| 587 | |
| 588 | if (r == 0) |
| 589 | return bss; |
| 590 | else if (r < 0) |
| 591 | n = n->rb_left; |
| 592 | else |
| 593 | n = n->rb_right; |
| 594 | } |
| 595 | |
| 596 | return NULL; |
| 597 | } |
| 598 | |
| 599 | static struct cfg80211_internal_bss * |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 600 | rb_find_hidden_bss(struct cfg80211_registered_device *dev, |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 601 | struct cfg80211_internal_bss *res) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 602 | { |
| 603 | struct rb_node *n = dev->bss_tree.rb_node; |
| 604 | struct cfg80211_internal_bss *bss; |
| 605 | int r; |
| 606 | |
| 607 | while (n) { |
| 608 | bss = rb_entry(n, struct cfg80211_internal_bss, rbn); |
| 609 | r = cmp_hidden_bss(&res->pub, &bss->pub); |
| 610 | |
| 611 | if (r == 0) |
| 612 | return bss; |
| 613 | else if (r < 0) |
| 614 | n = n->rb_left; |
| 615 | else |
| 616 | n = n->rb_right; |
| 617 | } |
| 618 | |
| 619 | return NULL; |
| 620 | } |
| 621 | |
| 622 | static void |
| 623 | copy_hidden_ies(struct cfg80211_internal_bss *res, |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 624 | struct cfg80211_internal_bss *hidden) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 625 | { |
| 626 | if (unlikely(res->pub.beacon_ies)) |
| 627 | return; |
| 628 | if (WARN_ON(!hidden->pub.beacon_ies)) |
| 629 | return; |
| 630 | |
| 631 | res->pub.beacon_ies = kmalloc(hidden->pub.len_beacon_ies, GFP_ATOMIC); |
| 632 | if (unlikely(!res->pub.beacon_ies)) |
| 633 | return; |
| 634 | |
| 635 | res->beacon_ies_allocated = true; |
| 636 | res->pub.len_beacon_ies = hidden->pub.len_beacon_ies; |
| 637 | memcpy(res->pub.beacon_ies, hidden->pub.beacon_ies, |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 638 | res->pub.len_beacon_ies); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | static struct cfg80211_internal_bss * |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 642 | cfg80211_bss_update(struct cfg80211_registered_device *dev, |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 643 | struct cfg80211_internal_bss *res) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 644 | { |
| 645 | struct cfg80211_internal_bss *found = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 646 | |
| 647 | /* |
| 648 | * The reference to "res" is donated to this function. |
| 649 | */ |
| 650 | |
| 651 | if (WARN_ON(!res->pub.channel)) { |
| 652 | kref_put(&res->ref, bss_release); |
| 653 | return NULL; |
| 654 | } |
| 655 | |
| 656 | res->ts = jiffies; |
| 657 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 658 | spin_lock_bh(&dev->bss_lock); |
| 659 | |
| 660 | found = rb_find_bss(dev, res); |
| 661 | |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 662 | if (found) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 663 | found->pub.beacon_interval = res->pub.beacon_interval; |
| 664 | found->pub.tsf = res->pub.tsf; |
| 665 | found->pub.signal = res->pub.signal; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 666 | found->pub.capability = res->pub.capability; |
| 667 | found->ts = res->ts; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 668 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 669 | /* Update IEs */ |
| 670 | if (res->pub.proberesp_ies) { |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 671 | size_t used = dev->wiphy.bss_priv_size + sizeof(*res); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 672 | size_t ielen = res->pub.len_proberesp_ies; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 673 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 674 | if (found->pub.proberesp_ies && |
| 675 | !found->proberesp_ies_allocated && |
| 676 | ksize(found) >= used + ielen) { |
| 677 | memcpy(found->pub.proberesp_ies, |
| 678 | res->pub.proberesp_ies, ielen); |
| 679 | found->pub.len_proberesp_ies = ielen; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 680 | } else { |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 681 | u8 *ies = found->pub.proberesp_ies; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 682 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 683 | if (found->proberesp_ies_allocated) |
Michael Buesch | 273de92 | 2009-04-25 22:28:55 +0200 | [diff] [blame] | 684 | ies = krealloc(ies, ielen, GFP_ATOMIC); |
| 685 | else |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 686 | ies = kmalloc(ielen, GFP_ATOMIC); |
| 687 | |
| 688 | if (ies) { |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 689 | memcpy(ies, res->pub.proberesp_ies, |
| 690 | ielen); |
| 691 | found->proberesp_ies_allocated = true; |
| 692 | found->pub.proberesp_ies = ies; |
| 693 | found->pub.len_proberesp_ies = ielen; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | /* Override possible earlier Beacon frame IEs */ |
| 698 | found->pub.information_elements = |
| 699 | found->pub.proberesp_ies; |
| 700 | found->pub.len_information_elements = |
| 701 | found->pub.len_proberesp_ies; |
| 702 | } |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame^] | 703 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 704 | if (res->pub.beacon_ies) { |
| 705 | size_t used = dev->wiphy.bss_priv_size + sizeof(*res); |
| 706 | size_t ielen = res->pub.len_beacon_ies; |
Sven Neumann | 01123e2 | 2010-12-09 15:05:24 +0100 | [diff] [blame] | 707 | bool information_elements_is_beacon_ies = |
| 708 | (found->pub.information_elements == |
| 709 | found->pub.beacon_ies); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 710 | |
| 711 | if (found->pub.beacon_ies && |
| 712 | !found->beacon_ies_allocated && |
| 713 | ksize(found) >= used + ielen) { |
| 714 | memcpy(found->pub.beacon_ies, |
| 715 | res->pub.beacon_ies, ielen); |
| 716 | found->pub.len_beacon_ies = ielen; |
| 717 | } else { |
| 718 | u8 *ies = found->pub.beacon_ies; |
| 719 | |
| 720 | if (found->beacon_ies_allocated) |
| 721 | ies = krealloc(ies, ielen, GFP_ATOMIC); |
| 722 | else |
| 723 | ies = kmalloc(ielen, GFP_ATOMIC); |
| 724 | |
| 725 | if (ies) { |
| 726 | memcpy(ies, res->pub.beacon_ies, |
| 727 | ielen); |
| 728 | found->beacon_ies_allocated = true; |
| 729 | found->pub.beacon_ies = ies; |
| 730 | found->pub.len_beacon_ies = ielen; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 731 | } |
| 732 | } |
Sven Neumann | 01123e2 | 2010-12-09 15:05:24 +0100 | [diff] [blame] | 733 | |
| 734 | /* Override IEs if they were from a beacon before */ |
| 735 | if (information_elements_is_beacon_ies) { |
| 736 | found->pub.information_elements = |
| 737 | found->pub.beacon_ies; |
| 738 | found->pub.len_information_elements = |
| 739 | found->pub.len_beacon_ies; |
| 740 | } |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 741 | } |
| 742 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 743 | kref_put(&res->ref, bss_release); |
| 744 | } else { |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 745 | struct cfg80211_internal_bss *hidden; |
| 746 | |
| 747 | /* First check if the beacon is a probe response from |
| 748 | * a hidden bss. If so, copy beacon ies (with nullified |
| 749 | * ssid) into the probe response bss entry (with real ssid). |
| 750 | * It is required basically for PSM implementation |
| 751 | * (probe responses do not contain tim ie) */ |
| 752 | |
| 753 | /* TODO: The code is not trying to update existing probe |
| 754 | * response bss entries when beacon ies are |
| 755 | * getting changed. */ |
| 756 | hidden = rb_find_hidden_bss(dev, res); |
| 757 | if (hidden) |
| 758 | copy_hidden_ies(res, hidden); |
| 759 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 760 | /* this "consumes" the reference */ |
| 761 | list_add_tail(&res->list, &dev->bss_list); |
| 762 | rb_insert_bss(dev, res); |
| 763 | found = res; |
| 764 | } |
| 765 | |
| 766 | dev->bss_generation++; |
| 767 | spin_unlock_bh(&dev->bss_lock); |
| 768 | |
| 769 | kref_get(&found->ref); |
| 770 | return found; |
| 771 | } |
| 772 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 773 | static struct ieee80211_channel * |
| 774 | cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen, |
| 775 | struct ieee80211_channel *channel) |
| 776 | { |
| 777 | const u8 *tmp; |
| 778 | u32 freq; |
| 779 | int channel_number = -1; |
| 780 | |
| 781 | tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen); |
| 782 | if (tmp && tmp[1] == 1) { |
| 783 | channel_number = tmp[2]; |
| 784 | } else { |
| 785 | tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen); |
| 786 | if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) { |
| 787 | struct ieee80211_ht_operation *htop = (void *)(tmp + 2); |
| 788 | |
| 789 | channel_number = htop->primary_chan; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | if (channel_number < 0) |
| 794 | return channel; |
| 795 | |
| 796 | freq = ieee80211_channel_to_frequency(channel_number, channel->band); |
| 797 | channel = ieee80211_get_channel(wiphy, freq); |
| 798 | if (!channel) |
| 799 | return NULL; |
| 800 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 801 | return NULL; |
| 802 | return channel; |
| 803 | } |
| 804 | |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 805 | struct cfg80211_bss* |
| 806 | cfg80211_inform_bss(struct wiphy *wiphy, |
| 807 | struct ieee80211_channel *channel, |
Johannes Berg | 7b8bcff | 2012-03-13 13:57:04 +0100 | [diff] [blame] | 808 | const u8 *bssid, u64 tsf, u16 capability, |
| 809 | u16 beacon_interval, const u8 *ie, size_t ielen, |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 810 | s32 signal, gfp_t gfp) |
| 811 | { |
| 812 | struct cfg80211_internal_bss *res; |
| 813 | size_t privsz; |
| 814 | |
| 815 | if (WARN_ON(!wiphy)) |
| 816 | return NULL; |
| 817 | |
| 818 | privsz = wiphy->bss_priv_size; |
| 819 | |
Sujith | 22fe88d | 2010-05-13 10:34:08 +0530 | [diff] [blame] | 820 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 821 | (signal < 0 || signal > 100))) |
| 822 | return NULL; |
| 823 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 824 | channel = cfg80211_get_bss_channel(wiphy, ie, ielen, channel); |
| 825 | if (!channel) |
| 826 | return NULL; |
| 827 | |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 828 | res = kzalloc(sizeof(*res) + privsz + ielen, gfp); |
| 829 | if (!res) |
| 830 | return NULL; |
| 831 | |
| 832 | memcpy(res->pub.bssid, bssid, ETH_ALEN); |
| 833 | res->pub.channel = channel; |
| 834 | res->pub.signal = signal; |
Johannes Berg | 7b8bcff | 2012-03-13 13:57:04 +0100 | [diff] [blame] | 835 | res->pub.tsf = tsf; |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 836 | res->pub.beacon_interval = beacon_interval; |
| 837 | res->pub.capability = capability; |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 838 | /* |
| 839 | * Since we do not know here whether the IEs are from a Beacon or Probe |
| 840 | * Response frame, we need to pick one of the options and only use it |
| 841 | * with the driver that does not provide the full Beacon/Probe Response |
| 842 | * frame. Use Beacon frame pointer to avoid indicating that this should |
| 843 | * override the information_elements pointer should we have received an |
| 844 | * earlier indication of Probe Response data. |
| 845 | * |
| 846 | * The initial buffer for the IEs is allocated with the BSS entry and |
| 847 | * is located after the private area. |
| 848 | */ |
| 849 | res->pub.beacon_ies = (u8 *)res + sizeof(*res) + privsz; |
| 850 | memcpy(res->pub.beacon_ies, ie, ielen); |
| 851 | res->pub.len_beacon_ies = ielen; |
| 852 | res->pub.information_elements = res->pub.beacon_ies; |
| 853 | res->pub.len_information_elements = res->pub.len_beacon_ies; |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 854 | |
| 855 | kref_init(&res->ref); |
| 856 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 857 | res = cfg80211_bss_update(wiphy_to_dev(wiphy), res); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 858 | if (!res) |
| 859 | return NULL; |
| 860 | |
| 861 | if (res->pub.capability & WLAN_CAPABILITY_ESS) |
| 862 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 863 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 864 | trace_cfg80211_return_bss(&res->pub); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 865 | /* cfg80211_bss_update gives us a referenced result */ |
| 866 | return &res->pub; |
| 867 | } |
| 868 | EXPORT_SYMBOL(cfg80211_inform_bss); |
| 869 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 870 | struct cfg80211_bss * |
| 871 | cfg80211_inform_bss_frame(struct wiphy *wiphy, |
| 872 | struct ieee80211_channel *channel, |
| 873 | struct ieee80211_mgmt *mgmt, size_t len, |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 874 | s32 signal, gfp_t gfp) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 875 | { |
| 876 | struct cfg80211_internal_bss *res; |
| 877 | size_t ielen = len - offsetof(struct ieee80211_mgmt, |
| 878 | u.probe_resp.variable); |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 879 | size_t privsz; |
| 880 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 881 | BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) != |
| 882 | offsetof(struct ieee80211_mgmt, u.beacon.variable)); |
| 883 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 884 | trace_cfg80211_inform_bss_frame(wiphy, channel, mgmt, len, signal); |
| 885 | |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 886 | if (WARN_ON(!mgmt)) |
| 887 | return NULL; |
| 888 | |
| 889 | if (WARN_ON(!wiphy)) |
| 890 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 891 | |
Sujith | 22fe88d | 2010-05-13 10:34:08 +0530 | [diff] [blame] | 892 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
Hila Gonen | 768be59 | 2012-08-26 11:00:28 +0300 | [diff] [blame] | 893 | (signal < 0 || signal > 100))) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 894 | return NULL; |
| 895 | |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 896 | if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable))) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 897 | return NULL; |
| 898 | |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 899 | privsz = wiphy->bss_priv_size; |
| 900 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 901 | channel = cfg80211_get_bss_channel(wiphy, mgmt->u.beacon.variable, |
| 902 | ielen, channel); |
| 903 | if (!channel) |
| 904 | return NULL; |
| 905 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 906 | res = kzalloc(sizeof(*res) + privsz + ielen, gfp); |
| 907 | if (!res) |
| 908 | return NULL; |
| 909 | |
| 910 | memcpy(res->pub.bssid, mgmt->bssid, ETH_ALEN); |
| 911 | res->pub.channel = channel; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 912 | res->pub.signal = signal; |
| 913 | res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp); |
| 914 | res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int); |
| 915 | res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 916 | /* |
| 917 | * The initial buffer for the IEs is allocated with the BSS entry and |
| 918 | * is located after the private area. |
| 919 | */ |
| 920 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
| 921 | res->pub.proberesp_ies = (u8 *) res + sizeof(*res) + privsz; |
| 922 | memcpy(res->pub.proberesp_ies, mgmt->u.probe_resp.variable, |
| 923 | ielen); |
| 924 | res->pub.len_proberesp_ies = ielen; |
| 925 | res->pub.information_elements = res->pub.proberesp_ies; |
| 926 | res->pub.len_information_elements = res->pub.len_proberesp_ies; |
| 927 | } else { |
| 928 | res->pub.beacon_ies = (u8 *) res + sizeof(*res) + privsz; |
| 929 | memcpy(res->pub.beacon_ies, mgmt->u.beacon.variable, ielen); |
| 930 | res->pub.len_beacon_ies = ielen; |
| 931 | res->pub.information_elements = res->pub.beacon_ies; |
| 932 | res->pub.len_information_elements = res->pub.len_beacon_ies; |
| 933 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 934 | |
| 935 | kref_init(&res->ref); |
| 936 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 937 | res = cfg80211_bss_update(wiphy_to_dev(wiphy), res); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 938 | if (!res) |
| 939 | return NULL; |
| 940 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 941 | if (res->pub.capability & WLAN_CAPABILITY_ESS) |
| 942 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 943 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 944 | trace_cfg80211_return_bss(&res->pub); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 945 | /* cfg80211_bss_update gives us a referenced result */ |
| 946 | return &res->pub; |
| 947 | } |
| 948 | EXPORT_SYMBOL(cfg80211_inform_bss_frame); |
| 949 | |
Johannes Berg | 4c0c0b7 | 2012-01-20 13:55:26 +0100 | [diff] [blame] | 950 | void cfg80211_ref_bss(struct cfg80211_bss *pub) |
| 951 | { |
| 952 | struct cfg80211_internal_bss *bss; |
| 953 | |
| 954 | if (!pub) |
| 955 | return; |
| 956 | |
| 957 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
| 958 | kref_get(&bss->ref); |
| 959 | } |
| 960 | EXPORT_SYMBOL(cfg80211_ref_bss); |
| 961 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 962 | void cfg80211_put_bss(struct cfg80211_bss *pub) |
| 963 | { |
| 964 | struct cfg80211_internal_bss *bss; |
| 965 | |
| 966 | if (!pub) |
| 967 | return; |
| 968 | |
| 969 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
| 970 | kref_put(&bss->ref, bss_release); |
| 971 | } |
| 972 | EXPORT_SYMBOL(cfg80211_put_bss); |
| 973 | |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 974 | void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
| 975 | { |
| 976 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); |
| 977 | struct cfg80211_internal_bss *bss; |
| 978 | |
| 979 | if (WARN_ON(!pub)) |
| 980 | return; |
| 981 | |
| 982 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
| 983 | |
| 984 | spin_lock_bh(&dev->bss_lock); |
Johannes Berg | 3207390 | 2010-10-06 21:18:04 +0200 | [diff] [blame] | 985 | if (!list_empty(&bss->list)) { |
Juuso Oikarinen | 2b78ac9 | 2011-03-28 14:32:32 +0300 | [diff] [blame] | 986 | __cfg80211_unlink_bss(dev, bss); |
Johannes Berg | 3207390 | 2010-10-06 21:18:04 +0200 | [diff] [blame] | 987 | dev->bss_generation++; |
Johannes Berg | 3207390 | 2010-10-06 21:18:04 +0200 | [diff] [blame] | 988 | } |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 989 | spin_unlock_bh(&dev->bss_lock); |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 990 | } |
| 991 | EXPORT_SYMBOL(cfg80211_unlink_bss); |
| 992 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 993 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 994 | int cfg80211_wext_siwscan(struct net_device *dev, |
| 995 | struct iw_request_info *info, |
| 996 | union iwreq_data *wrqu, char *extra) |
| 997 | { |
| 998 | struct cfg80211_registered_device *rdev; |
| 999 | struct wiphy *wiphy; |
| 1000 | struct iw_scan_req *wreq = NULL; |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1001 | struct cfg80211_scan_request *creq = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1002 | int i, err, n_channels = 0; |
| 1003 | enum ieee80211_band band; |
| 1004 | |
| 1005 | if (!netif_running(dev)) |
| 1006 | return -ENETDOWN; |
| 1007 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1008 | if (wrqu->data.length == sizeof(struct iw_scan_req)) |
| 1009 | wreq = (struct iw_scan_req *)extra; |
| 1010 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1011 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1012 | |
| 1013 | if (IS_ERR(rdev)) |
| 1014 | return PTR_ERR(rdev); |
| 1015 | |
| 1016 | if (rdev->scan_req) { |
| 1017 | err = -EBUSY; |
| 1018 | goto out; |
| 1019 | } |
| 1020 | |
| 1021 | wiphy = &rdev->wiphy; |
| 1022 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1023 | /* Determine number of channels, needed to allocate creq */ |
| 1024 | if (wreq && wreq->num_channels) |
| 1025 | n_channels = wreq->num_channels; |
| 1026 | else { |
| 1027 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 1028 | if (wiphy->bands[band]) |
| 1029 | n_channels += wiphy->bands[band]->n_channels; |
| 1030 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1031 | |
| 1032 | creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) + |
| 1033 | n_channels * sizeof(void *), |
| 1034 | GFP_ATOMIC); |
| 1035 | if (!creq) { |
| 1036 | err = -ENOMEM; |
| 1037 | goto out; |
| 1038 | } |
| 1039 | |
| 1040 | creq->wiphy = wiphy; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 1041 | creq->wdev = dev->ieee80211_ptr; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 1042 | /* SSIDs come after channels */ |
| 1043 | creq->ssids = (void *)&creq->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1044 | creq->n_channels = n_channels; |
| 1045 | creq->n_ssids = 1; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 1046 | creq->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1047 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1048 | /* translate "Scan on frequencies" request */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1049 | i = 0; |
| 1050 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1051 | int j; |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 1052 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1053 | if (!wiphy->bands[band]) |
| 1054 | continue; |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 1055 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1056 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 1057 | /* ignore disabled channels */ |
| 1058 | if (wiphy->bands[band]->channels[j].flags & |
| 1059 | IEEE80211_CHAN_DISABLED) |
| 1060 | continue; |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1061 | |
| 1062 | /* If we have a wireless request structure and the |
| 1063 | * wireless request specifies frequencies, then search |
| 1064 | * for the matching hardware channel. |
| 1065 | */ |
| 1066 | if (wreq && wreq->num_channels) { |
| 1067 | int k; |
| 1068 | int wiphy_freq = wiphy->bands[band]->channels[j].center_freq; |
| 1069 | for (k = 0; k < wreq->num_channels; k++) { |
Holger Schurig | a4e7b73 | 2009-09-11 10:13:53 +0200 | [diff] [blame] | 1070 | int wext_freq = cfg80211_wext_freq(wiphy, &wreq->channel_list[k]); |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1071 | if (wext_freq == wiphy_freq) |
| 1072 | goto wext_freq_found; |
| 1073 | } |
| 1074 | goto wext_freq_not_found; |
| 1075 | } |
| 1076 | |
| 1077 | wext_freq_found: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1078 | creq->channels[i] = &wiphy->bands[band]->channels[j]; |
| 1079 | i++; |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1080 | wext_freq_not_found: ; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1081 | } |
| 1082 | } |
Holger Schurig | 8862dc5 | 2009-09-11 10:13:55 +0200 | [diff] [blame] | 1083 | /* No channels found? */ |
| 1084 | if (!i) { |
| 1085 | err = -EINVAL; |
| 1086 | goto out; |
| 1087 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1088 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1089 | /* Set real number of channels specified in creq->channels[] */ |
| 1090 | creq->n_channels = i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1091 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1092 | /* translate "Scan for SSID" request */ |
| 1093 | if (wreq) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1094 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1095 | if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) { |
| 1096 | err = -EINVAL; |
| 1097 | goto out; |
| 1098 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1099 | memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len); |
| 1100 | creq->ssids[0].ssid_len = wreq->essid_len; |
| 1101 | } |
| 1102 | if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE) |
| 1103 | creq->n_ssids = 0; |
| 1104 | } |
| 1105 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 1106 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 1107 | if (wiphy->bands[i]) |
| 1108 | creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 1109 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1110 | rdev->scan_req = creq; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1111 | err = rdev_scan(rdev, creq); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1112 | if (err) { |
| 1113 | rdev->scan_req = NULL; |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1114 | /* creq will be freed below */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1115 | } else { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 1116 | nl80211_send_scan_start(rdev, dev->ieee80211_ptr); |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1117 | /* creq now owned by driver */ |
| 1118 | creq = NULL; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1119 | dev_hold(dev); |
| 1120 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1121 | out: |
Johannes Berg | 65486c8b | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1122 | kfree(creq); |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 1123 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1124 | return err; |
| 1125 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 1126 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1127 | |
| 1128 | static void ieee80211_scan_add_ies(struct iw_request_info *info, |
| 1129 | struct cfg80211_bss *bss, |
| 1130 | char **current_ev, char *end_buf) |
| 1131 | { |
| 1132 | u8 *pos, *end, *next; |
| 1133 | struct iw_event iwe; |
| 1134 | |
| 1135 | if (!bss->information_elements || |
| 1136 | !bss->len_information_elements) |
| 1137 | return; |
| 1138 | |
| 1139 | /* |
| 1140 | * If needed, fragment the IEs buffer (at IE boundaries) into short |
| 1141 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. |
| 1142 | */ |
| 1143 | pos = bss->information_elements; |
| 1144 | end = pos + bss->len_information_elements; |
| 1145 | |
| 1146 | while (end - pos > IW_GENERIC_IE_MAX) { |
| 1147 | next = pos + 2 + pos[1]; |
| 1148 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) |
| 1149 | next = next + 2 + next[1]; |
| 1150 | |
| 1151 | memset(&iwe, 0, sizeof(iwe)); |
| 1152 | iwe.cmd = IWEVGENIE; |
| 1153 | iwe.u.data.length = next - pos; |
| 1154 | *current_ev = iwe_stream_add_point(info, *current_ev, |
| 1155 | end_buf, &iwe, pos); |
| 1156 | |
| 1157 | pos = next; |
| 1158 | } |
| 1159 | |
| 1160 | if (end > pos) { |
| 1161 | memset(&iwe, 0, sizeof(iwe)); |
| 1162 | iwe.cmd = IWEVGENIE; |
| 1163 | iwe.u.data.length = end - pos; |
| 1164 | *current_ev = iwe_stream_add_point(info, *current_ev, |
| 1165 | end_buf, &iwe, pos); |
| 1166 | } |
| 1167 | } |
| 1168 | |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 1169 | static inline unsigned int elapsed_jiffies_msecs(unsigned long start) |
| 1170 | { |
| 1171 | unsigned long end = jiffies; |
| 1172 | |
| 1173 | if (end >= start) |
| 1174 | return jiffies_to_msecs(end - start); |
| 1175 | |
| 1176 | return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1); |
| 1177 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1178 | |
| 1179 | static char * |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1180 | ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info, |
| 1181 | struct cfg80211_internal_bss *bss, char *current_ev, |
| 1182 | char *end_buf) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1183 | { |
| 1184 | struct iw_event iwe; |
| 1185 | u8 *buf, *cfg, *p; |
| 1186 | u8 *ie = bss->pub.information_elements; |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1187 | int rem = bss->pub.len_information_elements, i, sig; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1188 | bool ismesh = false; |
| 1189 | |
| 1190 | memset(&iwe, 0, sizeof(iwe)); |
| 1191 | iwe.cmd = SIOCGIWAP; |
| 1192 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 1193 | memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN); |
| 1194 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
| 1195 | IW_EV_ADDR_LEN); |
| 1196 | |
| 1197 | memset(&iwe, 0, sizeof(iwe)); |
| 1198 | iwe.cmd = SIOCGIWFREQ; |
| 1199 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq); |
| 1200 | iwe.u.freq.e = 0; |
| 1201 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
| 1202 | IW_EV_FREQ_LEN); |
| 1203 | |
| 1204 | memset(&iwe, 0, sizeof(iwe)); |
| 1205 | iwe.cmd = SIOCGIWFREQ; |
| 1206 | iwe.u.freq.m = bss->pub.channel->center_freq; |
| 1207 | iwe.u.freq.e = 6; |
| 1208 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
| 1209 | IW_EV_FREQ_LEN); |
| 1210 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1211 | if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1212 | memset(&iwe, 0, sizeof(iwe)); |
| 1213 | iwe.cmd = IWEVQUAL; |
| 1214 | iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED | |
| 1215 | IW_QUAL_NOISE_INVALID | |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1216 | IW_QUAL_QUAL_UPDATED; |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1217 | switch (wiphy->signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1218 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1219 | sig = bss->pub.signal / 100; |
| 1220 | iwe.u.qual.level = sig; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1221 | iwe.u.qual.updated |= IW_QUAL_DBM; |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1222 | if (sig < -110) /* rather bad */ |
| 1223 | sig = -110; |
| 1224 | else if (sig > -40) /* perfect */ |
| 1225 | sig = -40; |
| 1226 | /* will give a range of 0 .. 70 */ |
| 1227 | iwe.u.qual.qual = sig + 110; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1228 | break; |
| 1229 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 1230 | iwe.u.qual.level = bss->pub.signal; |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 1231 | /* will give range 0 .. 100 */ |
| 1232 | iwe.u.qual.qual = bss->pub.signal; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1233 | break; |
| 1234 | default: |
| 1235 | /* not reached */ |
| 1236 | break; |
| 1237 | } |
| 1238 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
| 1239 | &iwe, IW_EV_QUAL_LEN); |
| 1240 | } |
| 1241 | |
| 1242 | memset(&iwe, 0, sizeof(iwe)); |
| 1243 | iwe.cmd = SIOCGIWENCODE; |
| 1244 | if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY) |
| 1245 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 1246 | else |
| 1247 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 1248 | iwe.u.data.length = 0; |
| 1249 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 1250 | &iwe, ""); |
| 1251 | |
| 1252 | while (rem >= 2) { |
| 1253 | /* invalid data */ |
| 1254 | if (ie[1] > rem - 2) |
| 1255 | break; |
| 1256 | |
| 1257 | switch (ie[0]) { |
| 1258 | case WLAN_EID_SSID: |
| 1259 | memset(&iwe, 0, sizeof(iwe)); |
| 1260 | iwe.cmd = SIOCGIWESSID; |
| 1261 | iwe.u.data.length = ie[1]; |
| 1262 | iwe.u.data.flags = 1; |
| 1263 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 1264 | &iwe, ie + 2); |
| 1265 | break; |
| 1266 | case WLAN_EID_MESH_ID: |
| 1267 | memset(&iwe, 0, sizeof(iwe)); |
| 1268 | iwe.cmd = SIOCGIWESSID; |
| 1269 | iwe.u.data.length = ie[1]; |
| 1270 | iwe.u.data.flags = 1; |
| 1271 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 1272 | &iwe, ie + 2); |
| 1273 | break; |
| 1274 | case WLAN_EID_MESH_CONFIG: |
| 1275 | ismesh = true; |
Rui Paulo | 136cfa2 | 2009-11-18 18:40:00 +0000 | [diff] [blame] | 1276 | if (ie[1] != sizeof(struct ieee80211_meshconf_ie)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1277 | break; |
| 1278 | buf = kmalloc(50, GFP_ATOMIC); |
| 1279 | if (!buf) |
| 1280 | break; |
| 1281 | cfg = ie + 2; |
| 1282 | memset(&iwe, 0, sizeof(iwe)); |
| 1283 | iwe.cmd = IWEVCUSTOM; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1284 | sprintf(buf, "Mesh Network Path Selection Protocol ID: " |
| 1285 | "0x%02X", cfg[0]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1286 | iwe.u.data.length = strlen(buf); |
| 1287 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1288 | end_buf, |
| 1289 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1290 | sprintf(buf, "Path Selection Metric ID: 0x%02X", |
| 1291 | cfg[1]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1292 | iwe.u.data.length = strlen(buf); |
| 1293 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1294 | end_buf, |
| 1295 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1296 | sprintf(buf, "Congestion Control Mode ID: 0x%02X", |
| 1297 | cfg[2]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1298 | iwe.u.data.length = strlen(buf); |
| 1299 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1300 | end_buf, |
| 1301 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1302 | sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1303 | iwe.u.data.length = strlen(buf); |
| 1304 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1305 | end_buf, |
| 1306 | &iwe, buf); |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 1307 | sprintf(buf, "Authentication ID: 0x%02X", cfg[4]); |
| 1308 | iwe.u.data.length = strlen(buf); |
| 1309 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1310 | end_buf, |
| 1311 | &iwe, buf); |
| 1312 | sprintf(buf, "Formation Info: 0x%02X", cfg[5]); |
| 1313 | iwe.u.data.length = strlen(buf); |
| 1314 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1315 | end_buf, |
| 1316 | &iwe, buf); |
| 1317 | sprintf(buf, "Capabilities: 0x%02X", cfg[6]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1318 | iwe.u.data.length = strlen(buf); |
| 1319 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1320 | end_buf, |
| 1321 | &iwe, buf); |
| 1322 | kfree(buf); |
| 1323 | break; |
| 1324 | case WLAN_EID_SUPP_RATES: |
| 1325 | case WLAN_EID_EXT_SUPP_RATES: |
| 1326 | /* display all supported rates in readable format */ |
| 1327 | p = current_ev + iwe_stream_lcp_len(info); |
| 1328 | |
| 1329 | memset(&iwe, 0, sizeof(iwe)); |
| 1330 | iwe.cmd = SIOCGIWRATE; |
| 1331 | /* Those two flags are ignored... */ |
| 1332 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; |
| 1333 | |
| 1334 | for (i = 0; i < ie[1]; i++) { |
| 1335 | iwe.u.bitrate.value = |
| 1336 | ((ie[i + 2] & 0x7f) * 500000); |
| 1337 | p = iwe_stream_add_value(info, current_ev, p, |
| 1338 | end_buf, &iwe, IW_EV_PARAM_LEN); |
| 1339 | } |
| 1340 | current_ev = p; |
| 1341 | break; |
| 1342 | } |
| 1343 | rem -= ie[1] + 2; |
| 1344 | ie += ie[1] + 2; |
| 1345 | } |
| 1346 | |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 1347 | if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) || |
| 1348 | ismesh) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1349 | memset(&iwe, 0, sizeof(iwe)); |
| 1350 | iwe.cmd = SIOCGIWMODE; |
| 1351 | if (ismesh) |
| 1352 | iwe.u.mode = IW_MODE_MESH; |
| 1353 | else if (bss->pub.capability & WLAN_CAPABILITY_ESS) |
| 1354 | iwe.u.mode = IW_MODE_MASTER; |
| 1355 | else |
| 1356 | iwe.u.mode = IW_MODE_ADHOC; |
| 1357 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
| 1358 | &iwe, IW_EV_UINT_LEN); |
| 1359 | } |
| 1360 | |
| 1361 | buf = kmalloc(30, GFP_ATOMIC); |
| 1362 | if (buf) { |
| 1363 | memset(&iwe, 0, sizeof(iwe)); |
| 1364 | iwe.cmd = IWEVCUSTOM; |
| 1365 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->pub.tsf)); |
| 1366 | iwe.u.data.length = strlen(buf); |
| 1367 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 1368 | &iwe, buf); |
| 1369 | memset(&iwe, 0, sizeof(iwe)); |
| 1370 | iwe.cmd = IWEVCUSTOM; |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 1371 | sprintf(buf, " Last beacon: %ums ago", |
| 1372 | elapsed_jiffies_msecs(bss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1373 | iwe.u.data.length = strlen(buf); |
| 1374 | current_ev = iwe_stream_add_point(info, current_ev, |
| 1375 | end_buf, &iwe, buf); |
| 1376 | kfree(buf); |
| 1377 | } |
| 1378 | |
| 1379 | ieee80211_scan_add_ies(info, &bss->pub, ¤t_ev, end_buf); |
| 1380 | |
| 1381 | return current_ev; |
| 1382 | } |
| 1383 | |
| 1384 | |
| 1385 | static int ieee80211_scan_results(struct cfg80211_registered_device *dev, |
| 1386 | struct iw_request_info *info, |
| 1387 | char *buf, size_t len) |
| 1388 | { |
| 1389 | char *current_ev = buf; |
| 1390 | char *end_buf = buf + len; |
| 1391 | struct cfg80211_internal_bss *bss; |
| 1392 | |
| 1393 | spin_lock_bh(&dev->bss_lock); |
| 1394 | cfg80211_bss_expire(dev); |
| 1395 | |
| 1396 | list_for_each_entry(bss, &dev->bss_list, list) { |
| 1397 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { |
| 1398 | spin_unlock_bh(&dev->bss_lock); |
| 1399 | return -E2BIG; |
| 1400 | } |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 1401 | current_ev = ieee80211_bss(&dev->wiphy, info, bss, |
| 1402 | current_ev, end_buf); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1403 | } |
| 1404 | spin_unlock_bh(&dev->bss_lock); |
| 1405 | return current_ev - buf; |
| 1406 | } |
| 1407 | |
| 1408 | |
| 1409 | int cfg80211_wext_giwscan(struct net_device *dev, |
| 1410 | struct iw_request_info *info, |
| 1411 | struct iw_point *data, char *extra) |
| 1412 | { |
| 1413 | struct cfg80211_registered_device *rdev; |
| 1414 | int res; |
| 1415 | |
| 1416 | if (!netif_running(dev)) |
| 1417 | return -ENETDOWN; |
| 1418 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1419 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1420 | |
| 1421 | if (IS_ERR(rdev)) |
| 1422 | return PTR_ERR(rdev); |
| 1423 | |
| 1424 | if (rdev->scan_req) { |
| 1425 | res = -EAGAIN; |
| 1426 | goto out; |
| 1427 | } |
| 1428 | |
| 1429 | res = ieee80211_scan_results(rdev, info, extra, data->length); |
| 1430 | data->length = 0; |
| 1431 | if (res >= 0) { |
| 1432 | data->length = res; |
| 1433 | res = 0; |
| 1434 | } |
| 1435 | |
| 1436 | out: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 1437 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1438 | return res; |
| 1439 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 1440 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1441 | #endif |