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