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