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