Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2 | /* |
| 3 | * cfg80211 scan result handling |
| 4 | * |
| 5 | * Copyright 2008 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7 | * Copyright 2016 Intel Deutschland GmbH |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018-2019 Intel Corporation |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9 | */ |
| 10 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/wireless.h> |
| 15 | #include <linux/nl80211.h> |
| 16 | #include <linux/etherdevice.h> |
| 17 | #include <net/arp.h> |
| 18 | #include <net/cfg80211.h> |
Johannes Berg | 262eb9b2 | 2011-07-13 10:39:09 +0200 | [diff] [blame] | 19 | #include <net/cfg80211-wext.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 20 | #include <net/iw_handler.h> |
| 21 | #include "core.h" |
| 22 | #include "nl80211.h" |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 23 | #include "wext-compat.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 24 | #include "rdev-ops.h" |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 25 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 26 | /** |
| 27 | * DOC: BSS tree/list structure |
| 28 | * |
| 29 | * At the top level, the BSS list is kept in both a list in each |
| 30 | * registered device (@bss_list) as well as an RB-tree for faster |
| 31 | * lookup. In the RB-tree, entries can be looked up using their |
| 32 | * channel, MESHID, MESHCONF (for MBSSes) or channel, BSSID, SSID |
| 33 | * for other BSSes. |
| 34 | * |
| 35 | * Due to the possibility of hidden SSIDs, there's a second level |
| 36 | * structure, the "hidden_list" and "hidden_beacon_bss" pointer. |
| 37 | * The hidden_list connects all BSSes belonging to a single AP |
| 38 | * that has a hidden SSID, and connects beacon and probe response |
| 39 | * entries. For a probe response entry for a hidden SSID, the |
| 40 | * hidden_beacon_bss pointer points to the BSS struct holding the |
| 41 | * beacon's information. |
| 42 | * |
| 43 | * Reference counting is done for all these references except for |
| 44 | * the hidden_list, so that a beacon BSS struct that is otherwise |
| 45 | * not referenced has one reference for being on the bss_list and |
| 46 | * one for each probe response entry that points to it using the |
| 47 | * hidden_beacon_bss pointer. When a BSS struct that has such a |
| 48 | * pointer is get/put, the refcount update is also propagated to |
| 49 | * the referenced struct, this ensure that it cannot get removed |
| 50 | * while somebody is using the probe response version. |
| 51 | * |
| 52 | * Note that the hidden_beacon_bss pointer never changes, due to |
| 53 | * the reference counting. Therefore, no locking is needed for |
| 54 | * it. |
| 55 | * |
| 56 | * Also note that the hidden_beacon_bss pointer is only relevant |
| 57 | * if the driver uses something other than the IEs, e.g. private |
| 58 | * data stored stored in the BSS struct, since the beacon IEs are |
| 59 | * also linked into the probe response struct. |
| 60 | */ |
| 61 | |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 62 | /* |
| 63 | * Limit the number of BSS entries stored in mac80211. Each one is |
| 64 | * a bit over 4k at most, so this limits to roughly 4-5M of memory. |
| 65 | * If somebody wants to really attack this though, they'd likely |
| 66 | * use small beacons, and only one type of frame, limiting each of |
| 67 | * the entries to a much smaller size (in order to generate more |
| 68 | * entries in total, so overhead is bigger.) |
| 69 | */ |
| 70 | static int bss_entries_limit = 1000; |
| 71 | module_param(bss_entries_limit, int, 0644); |
| 72 | MODULE_PARM_DESC(bss_entries_limit, |
| 73 | "limit to number of scan BSS entries (per wiphy, default 1000)"); |
| 74 | |
Rajkumar Manoharan | f9616e0 | 2012-04-13 16:38:40 +0530 | [diff] [blame] | 75 | #define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 76 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 77 | static void bss_free(struct cfg80211_internal_bss *bss) |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 78 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 79 | struct cfg80211_bss_ies *ies; |
Johannes Berg | b629ea3 | 2012-11-28 22:14:56 +0100 | [diff] [blame] | 80 | |
| 81 | if (WARN_ON(atomic_read(&bss->hold))) |
| 82 | return; |
| 83 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 84 | ies = (void *)rcu_access_pointer(bss->pub.beacon_ies); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 85 | if (ies && !bss->pub.hidden_beacon_bss) |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 86 | kfree_rcu(ies, rcu_head); |
| 87 | ies = (void *)rcu_access_pointer(bss->pub.proberesp_ies); |
| 88 | if (ies) |
| 89 | kfree_rcu(ies, rcu_head); |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 90 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 91 | /* |
| 92 | * This happens when the module is removed, it doesn't |
| 93 | * really matter any more save for completeness |
| 94 | */ |
| 95 | if (!list_empty(&bss->hidden_list)) |
| 96 | list_del(&bss->hidden_list); |
| 97 | |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 98 | kfree(bss); |
| 99 | } |
| 100 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 101 | static inline void bss_ref_get(struct cfg80211_registered_device *rdev, |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 102 | struct cfg80211_internal_bss *bss) |
Johannes Berg | 0532d4f | 2013-02-01 01:34:36 +0100 | [diff] [blame] | 103 | { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 104 | lockdep_assert_held(&rdev->bss_lock); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 105 | |
| 106 | bss->refcount++; |
| 107 | if (bss->pub.hidden_beacon_bss) { |
| 108 | bss = container_of(bss->pub.hidden_beacon_bss, |
| 109 | struct cfg80211_internal_bss, |
| 110 | pub); |
| 111 | bss->refcount++; |
| 112 | } |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 113 | if (bss->pub.transmitted_bss) { |
| 114 | bss = container_of(bss->pub.transmitted_bss, |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 115 | struct cfg80211_internal_bss, |
| 116 | pub); |
| 117 | bss->refcount++; |
| 118 | } |
Johannes Berg | 0532d4f | 2013-02-01 01:34:36 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 121 | static inline void bss_ref_put(struct cfg80211_registered_device *rdev, |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 122 | struct cfg80211_internal_bss *bss) |
Johannes Berg | 0532d4f | 2013-02-01 01:34:36 +0100 | [diff] [blame] | 123 | { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 124 | lockdep_assert_held(&rdev->bss_lock); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 125 | |
| 126 | if (bss->pub.hidden_beacon_bss) { |
| 127 | struct cfg80211_internal_bss *hbss; |
| 128 | hbss = container_of(bss->pub.hidden_beacon_bss, |
| 129 | struct cfg80211_internal_bss, |
| 130 | pub); |
| 131 | hbss->refcount--; |
| 132 | if (hbss->refcount == 0) |
| 133 | bss_free(hbss); |
| 134 | } |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 135 | |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 136 | if (bss->pub.transmitted_bss) { |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 137 | struct cfg80211_internal_bss *tbss; |
| 138 | |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 139 | tbss = container_of(bss->pub.transmitted_bss, |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 140 | struct cfg80211_internal_bss, |
| 141 | pub); |
| 142 | tbss->refcount--; |
| 143 | if (tbss->refcount == 0) |
| 144 | bss_free(tbss); |
| 145 | } |
| 146 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 147 | bss->refcount--; |
| 148 | if (bss->refcount == 0) |
| 149 | bss_free(bss); |
Johannes Berg | 0532d4f | 2013-02-01 01:34:36 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 152 | static bool __cfg80211_unlink_bss(struct cfg80211_registered_device *rdev, |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 153 | struct cfg80211_internal_bss *bss) |
| 154 | { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 155 | lockdep_assert_held(&rdev->bss_lock); |
Johannes Berg | 4b1af47 | 2013-02-01 01:05:43 +0100 | [diff] [blame] | 156 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 157 | if (!list_empty(&bss->hidden_list)) { |
| 158 | /* |
| 159 | * don't remove the beacon entry if it has |
| 160 | * probe responses associated with it |
| 161 | */ |
| 162 | if (!bss->pub.hidden_beacon_bss) |
| 163 | return false; |
| 164 | /* |
| 165 | * if it's a probe response entry break its |
| 166 | * link to the other entries in the group |
| 167 | */ |
| 168 | list_del_init(&bss->hidden_list); |
| 169 | } |
| 170 | |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 171 | list_del_init(&bss->list); |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 172 | list_del_init(&bss->pub.nontrans_list); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 173 | rb_erase(&bss->rbn, &rdev->bss_tree); |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 174 | rdev->bss_entries--; |
| 175 | WARN_ONCE((rdev->bss_entries == 0) ^ list_empty(&rdev->bss_list), |
| 176 | "rdev bss entries[%d]/list[empty:%d] corruption\n", |
| 177 | rdev->bss_entries, list_empty(&rdev->bss_list)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 178 | bss_ref_put(rdev, bss); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 179 | return true; |
Amitkumar Karwar | e8e27c6 | 2012-10-11 21:03:33 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 182 | static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen, |
| 183 | const u8 *subelement, size_t subie_len, |
| 184 | u8 *new_ie, gfp_t gfp) |
| 185 | { |
| 186 | u8 *pos, *tmp; |
| 187 | const u8 *tmp_old, *tmp_new; |
| 188 | u8 *sub_copy; |
| 189 | |
| 190 | /* copy subelement as we need to change its content to |
| 191 | * mark an ie after it is processed. |
| 192 | */ |
| 193 | sub_copy = kmalloc(subie_len, gfp); |
| 194 | if (!sub_copy) |
| 195 | return 0; |
| 196 | memcpy(sub_copy, subelement, subie_len); |
| 197 | |
| 198 | pos = &new_ie[0]; |
| 199 | |
| 200 | /* set new ssid */ |
| 201 | tmp_new = cfg80211_find_ie(WLAN_EID_SSID, sub_copy, subie_len); |
| 202 | if (tmp_new) { |
| 203 | memcpy(pos, tmp_new, tmp_new[1] + 2); |
| 204 | pos += (tmp_new[1] + 2); |
| 205 | } |
| 206 | |
| 207 | /* go through IEs in ie (skip SSID) and subelement, |
| 208 | * merge them into new_ie |
| 209 | */ |
| 210 | tmp_old = cfg80211_find_ie(WLAN_EID_SSID, ie, ielen); |
| 211 | tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie; |
| 212 | |
| 213 | while (tmp_old + tmp_old[1] + 2 - ie <= ielen) { |
| 214 | if (tmp_old[0] == 0) { |
| 215 | tmp_old++; |
| 216 | continue; |
| 217 | } |
| 218 | |
Sara Sharon | c17fe04 | 2019-01-29 14:00:58 +0200 | [diff] [blame] | 219 | if (tmp_old[0] == WLAN_EID_EXTENSION) |
| 220 | tmp = (u8 *)cfg80211_find_ext_ie(tmp_old[2], sub_copy, |
| 221 | subie_len); |
| 222 | else |
| 223 | tmp = (u8 *)cfg80211_find_ie(tmp_old[0], sub_copy, |
| 224 | subie_len); |
| 225 | |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 226 | if (!tmp) { |
| 227 | /* ie in old ie but not in subelement */ |
| 228 | if (tmp_old[0] != WLAN_EID_MULTIPLE_BSSID) { |
| 229 | memcpy(pos, tmp_old, tmp_old[1] + 2); |
| 230 | pos += tmp_old[1] + 2; |
| 231 | } |
| 232 | } else { |
| 233 | /* ie in transmitting ie also in subelement, |
| 234 | * copy from subelement and flag the ie in subelement |
Sara Sharon | c17fe04 | 2019-01-29 14:00:58 +0200 | [diff] [blame] | 235 | * as copied (by setting eid field to WLAN_EID_SSID, |
| 236 | * which is skipped anyway). |
| 237 | * For vendor ie, compare OUI + type + subType to |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 238 | * determine if they are the same ie. |
| 239 | */ |
| 240 | if (tmp_old[0] == WLAN_EID_VENDOR_SPECIFIC) { |
| 241 | if (!memcmp(tmp_old + 2, tmp + 2, 5)) { |
| 242 | /* same vendor ie, copy from |
| 243 | * subelement |
| 244 | */ |
| 245 | memcpy(pos, tmp, tmp[1] + 2); |
| 246 | pos += tmp[1] + 2; |
Sara Sharon | c17fe04 | 2019-01-29 14:00:58 +0200 | [diff] [blame] | 247 | tmp[0] = WLAN_EID_SSID; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 248 | } else { |
| 249 | memcpy(pos, tmp_old, tmp_old[1] + 2); |
| 250 | pos += tmp_old[1] + 2; |
| 251 | } |
| 252 | } else { |
| 253 | /* copy ie from subelement into new ie */ |
| 254 | memcpy(pos, tmp, tmp[1] + 2); |
| 255 | pos += tmp[1] + 2; |
Sara Sharon | c17fe04 | 2019-01-29 14:00:58 +0200 | [diff] [blame] | 256 | tmp[0] = WLAN_EID_SSID; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | if (tmp_old + tmp_old[1] + 2 - ie == ielen) |
| 261 | break; |
| 262 | |
| 263 | tmp_old += tmp_old[1] + 2; |
| 264 | } |
| 265 | |
| 266 | /* go through subelement again to check if there is any ie not |
| 267 | * copied to new ie, skip ssid, capability, bssid-index ie |
| 268 | */ |
| 269 | tmp_new = sub_copy; |
| 270 | while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) { |
| 271 | if (!(tmp_new[0] == WLAN_EID_NON_TX_BSSID_CAP || |
Sara Sharon | 5bd9d10 | 2019-03-15 17:39:02 +0200 | [diff] [blame^] | 272 | tmp_new[0] == WLAN_EID_SSID)) { |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 273 | memcpy(pos, tmp_new, tmp_new[1] + 2); |
| 274 | pos += tmp_new[1] + 2; |
| 275 | } |
| 276 | if (tmp_new + tmp_new[1] + 2 - sub_copy == subie_len) |
| 277 | break; |
| 278 | tmp_new += tmp_new[1] + 2; |
| 279 | } |
| 280 | |
| 281 | kfree(sub_copy); |
| 282 | return pos - new_ie; |
| 283 | } |
| 284 | |
| 285 | static bool is_bss(struct cfg80211_bss *a, const u8 *bssid, |
| 286 | const u8 *ssid, size_t ssid_len) |
| 287 | { |
| 288 | const struct cfg80211_bss_ies *ies; |
| 289 | const u8 *ssidie; |
| 290 | |
| 291 | if (bssid && !ether_addr_equal(a->bssid, bssid)) |
| 292 | return false; |
| 293 | |
| 294 | if (!ssid) |
| 295 | return true; |
| 296 | |
| 297 | ies = rcu_access_pointer(a->ies); |
| 298 | if (!ies) |
| 299 | return false; |
| 300 | ssidie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len); |
| 301 | if (!ssidie) |
| 302 | return false; |
| 303 | if (ssidie[1] != ssid_len) |
| 304 | return false; |
| 305 | return memcmp(ssidie + 2, ssid, ssid_len) == 0; |
| 306 | } |
| 307 | |
| 308 | static int |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 309 | cfg80211_add_nontrans_list(struct cfg80211_bss *trans_bss, |
| 310 | struct cfg80211_bss *nontrans_bss) |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 311 | { |
| 312 | const u8 *ssid; |
| 313 | size_t ssid_len; |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 314 | struct cfg80211_bss *bss = NULL; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 315 | |
| 316 | rcu_read_lock(); |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 317 | ssid = ieee80211_bss_get_ie(nontrans_bss, WLAN_EID_SSID); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 318 | if (!ssid) { |
| 319 | rcu_read_unlock(); |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | ssid_len = ssid[1]; |
| 323 | ssid = ssid + 2; |
| 324 | rcu_read_unlock(); |
| 325 | |
| 326 | /* check if nontrans_bss is in the list */ |
| 327 | list_for_each_entry(bss, &trans_bss->nontrans_list, nontrans_list) { |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 328 | if (is_bss(bss, nontrans_bss->bssid, ssid, ssid_len)) |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | /* add to the list */ |
| 333 | list_add_tail(&nontrans_bss->nontrans_list, &trans_bss->nontrans_list); |
| 334 | return 0; |
| 335 | } |
| 336 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 337 | static void __cfg80211_bss_expire(struct cfg80211_registered_device *rdev, |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 338 | unsigned long expire_time) |
| 339 | { |
| 340 | struct cfg80211_internal_bss *bss, *tmp; |
| 341 | bool expired = false; |
| 342 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 343 | lockdep_assert_held(&rdev->bss_lock); |
Johannes Berg | 4b1af47 | 2013-02-01 01:05:43 +0100 | [diff] [blame] | 344 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 345 | list_for_each_entry_safe(bss, tmp, &rdev->bss_list, list) { |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 346 | if (atomic_read(&bss->hold)) |
| 347 | continue; |
| 348 | if (!time_after(expire_time, bss->ts)) |
| 349 | continue; |
| 350 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 351 | if (__cfg80211_unlink_bss(rdev, bss)) |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 352 | expired = true; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | if (expired) |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 356 | rdev->bss_generation++; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 359 | static bool cfg80211_bss_expire_oldest(struct cfg80211_registered_device *rdev) |
| 360 | { |
| 361 | struct cfg80211_internal_bss *bss, *oldest = NULL; |
| 362 | bool ret; |
| 363 | |
| 364 | lockdep_assert_held(&rdev->bss_lock); |
| 365 | |
| 366 | list_for_each_entry(bss, &rdev->bss_list, list) { |
| 367 | if (atomic_read(&bss->hold)) |
| 368 | continue; |
| 369 | |
| 370 | if (!list_empty(&bss->hidden_list) && |
| 371 | !bss->pub.hidden_beacon_bss) |
| 372 | continue; |
| 373 | |
| 374 | if (oldest && time_before(oldest->ts, bss->ts)) |
| 375 | continue; |
| 376 | oldest = bss; |
| 377 | } |
| 378 | |
| 379 | if (WARN_ON(!oldest)) |
| 380 | return false; |
| 381 | |
| 382 | /* |
| 383 | * The callers make sure to increase rdev->bss_generation if anything |
| 384 | * gets removed (and a new entry added), so there's no need to also do |
| 385 | * it here. |
| 386 | */ |
| 387 | |
| 388 | ret = __cfg80211_unlink_bss(rdev, oldest); |
| 389 | WARN_ON(!ret); |
| 390 | return ret; |
| 391 | } |
| 392 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 393 | void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, |
| 394 | bool send_message) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 395 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 396 | struct cfg80211_scan_request *request; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 397 | struct wireless_dev *wdev; |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 398 | struct sk_buff *msg; |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 399 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 400 | union iwreq_data wrqu; |
| 401 | #endif |
| 402 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 403 | ASSERT_RTNL(); |
Johannes Berg | 01a0ac4 | 2009-08-20 21:36:16 +0200 | [diff] [blame] | 404 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 405 | if (rdev->scan_msg) { |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 406 | nl80211_send_scan_msg(rdev, rdev->scan_msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 407 | rdev->scan_msg = NULL; |
| 408 | return; |
| 409 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 410 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 411 | request = rdev->scan_req; |
Johannes Berg | 01a0ac4 | 2009-08-20 21:36:16 +0200 | [diff] [blame] | 412 | if (!request) |
| 413 | return; |
| 414 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 415 | wdev = request->wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 416 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 417 | /* |
| 418 | * This must be before sending the other events! |
| 419 | * Otherwise, wpa_supplicant gets completely confused with |
| 420 | * wext events. |
| 421 | */ |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 422 | if (wdev->netdev) |
| 423 | cfg80211_sme_scan_done(wdev->netdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 424 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 425 | if (!request->info.aborted && |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 426 | request->flags & NL80211_SCAN_FLAG_FLUSH) { |
| 427 | /* flush entries from previous scans */ |
| 428 | spin_lock_bh(&rdev->bss_lock); |
| 429 | __cfg80211_bss_expire(rdev, request->scan_start); |
| 430 | spin_unlock_bh(&rdev->bss_lock); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 431 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 432 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 433 | msg = nl80211_build_scan_msg(rdev, wdev, request->info.aborted); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 434 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 435 | #ifdef CONFIG_CFG80211_WEXT |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 436 | if (wdev->netdev && !request->info.aborted) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 437 | memset(&wrqu, 0, sizeof(wrqu)); |
| 438 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 439 | wireless_send_event(wdev->netdev, SIOCGIWSCAN, &wrqu, NULL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 440 | } |
| 441 | #endif |
| 442 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 443 | if (wdev->netdev) |
| 444 | dev_put(wdev->netdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 445 | |
Johannes Berg | 36e6fea | 2009-08-12 22:21:21 +0200 | [diff] [blame] | 446 | rdev->scan_req = NULL; |
Eliad Peller | 4a58e7c | 2013-12-05 18:30:17 +0200 | [diff] [blame] | 447 | kfree(request); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 448 | |
| 449 | if (!send_message) |
| 450 | rdev->scan_msg = msg; |
| 451 | else |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 452 | nl80211_send_scan_msg(rdev, msg); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 453 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 454 | |
Johannes Berg | 36e6fea | 2009-08-12 22:21:21 +0200 | [diff] [blame] | 455 | void __cfg80211_scan_done(struct work_struct *wk) |
| 456 | { |
| 457 | struct cfg80211_registered_device *rdev; |
| 458 | |
| 459 | rdev = container_of(wk, struct cfg80211_registered_device, |
| 460 | scan_done_wk); |
| 461 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 462 | rtnl_lock(); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 463 | ___cfg80211_scan_done(rdev, true); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 464 | rtnl_unlock(); |
Johannes Berg | 36e6fea | 2009-08-12 22:21:21 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 467 | void cfg80211_scan_done(struct cfg80211_scan_request *request, |
| 468 | struct cfg80211_scan_info *info) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 469 | { |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 470 | trace_cfg80211_scan_done(request, info); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 471 | WARN_ON(request != wiphy_to_rdev(request->wiphy)->scan_req); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 472 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 473 | request->info = *info; |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 474 | request->notified = true; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 475 | queue_work(cfg80211_wq, &wiphy_to_rdev(request->wiphy)->scan_done_wk); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 476 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 477 | EXPORT_SYMBOL(cfg80211_scan_done); |
| 478 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 479 | void cfg80211_add_sched_scan_req(struct cfg80211_registered_device *rdev, |
| 480 | struct cfg80211_sched_scan_request *req) |
| 481 | { |
| 482 | ASSERT_RTNL(); |
| 483 | |
| 484 | list_add_rcu(&req->list, &rdev->sched_scan_req_list); |
| 485 | } |
| 486 | |
| 487 | static void cfg80211_del_sched_scan_req(struct cfg80211_registered_device *rdev, |
| 488 | struct cfg80211_sched_scan_request *req) |
| 489 | { |
| 490 | ASSERT_RTNL(); |
| 491 | |
| 492 | list_del_rcu(&req->list); |
| 493 | kfree_rcu(req, rcu_head); |
| 494 | } |
| 495 | |
| 496 | static struct cfg80211_sched_scan_request * |
| 497 | cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid) |
| 498 | { |
| 499 | struct cfg80211_sched_scan_request *pos; |
| 500 | |
Arend Van Spriel | 1b57b62 | 2017-05-23 09:58:07 +0100 | [diff] [blame] | 501 | WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held()); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 502 | |
Arend Van Spriel | 1b57b62 | 2017-05-23 09:58:07 +0100 | [diff] [blame] | 503 | list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 504 | if (pos->reqid == reqid) |
| 505 | return pos; |
| 506 | } |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 507 | return NULL; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /* |
| 511 | * Determines if a scheduled scan request can be handled. When a legacy |
| 512 | * scheduled scan is running no other scheduled scan is allowed regardless |
| 513 | * whether the request is for legacy or multi-support scan. When a multi-support |
| 514 | * scheduled scan is running a request for legacy scan is not allowed. In this |
| 515 | * case a request for multi-support scan can be handled if resources are |
| 516 | * available, ie. struct wiphy::max_sched_scan_reqs limit is not yet reached. |
| 517 | */ |
| 518 | int cfg80211_sched_scan_req_possible(struct cfg80211_registered_device *rdev, |
| 519 | bool want_multi) |
| 520 | { |
| 521 | struct cfg80211_sched_scan_request *pos; |
| 522 | int i = 0; |
| 523 | |
| 524 | list_for_each_entry(pos, &rdev->sched_scan_req_list, list) { |
| 525 | /* request id zero means legacy in progress */ |
| 526 | if (!i && !pos->reqid) |
| 527 | return -EINPROGRESS; |
| 528 | i++; |
| 529 | } |
| 530 | |
| 531 | if (i) { |
| 532 | /* no legacy allowed when multi request(s) are active */ |
| 533 | if (!want_multi) |
| 534 | return -EINPROGRESS; |
| 535 | |
| 536 | /* resource limit reached */ |
| 537 | if (i == rdev->wiphy.max_sched_scan_reqs) |
| 538 | return -ENOSPC; |
| 539 | } |
| 540 | return 0; |
| 541 | } |
| 542 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 543 | void cfg80211_sched_scan_results_wk(struct work_struct *work) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 544 | { |
| 545 | struct cfg80211_registered_device *rdev; |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 546 | struct cfg80211_sched_scan_request *req, *tmp; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 547 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 548 | rdev = container_of(work, struct cfg80211_registered_device, |
| 549 | sched_scan_res_wk); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 550 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 551 | rtnl_lock(); |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 552 | list_for_each_entry_safe(req, tmp, &rdev->sched_scan_req_list, list) { |
| 553 | if (req->report_results) { |
| 554 | req->report_results = false; |
| 555 | if (req->flags & NL80211_SCAN_FLAG_FLUSH) { |
| 556 | /* flush entries from previous scans */ |
| 557 | spin_lock_bh(&rdev->bss_lock); |
| 558 | __cfg80211_bss_expire(rdev, req->scan_start); |
| 559 | spin_unlock_bh(&rdev->bss_lock); |
| 560 | req->scan_start = jiffies; |
| 561 | } |
| 562 | nl80211_send_sched_scan(req, |
| 563 | NL80211_CMD_SCHED_SCAN_RESULTS); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 564 | } |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 565 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 566 | rtnl_unlock(); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 567 | } |
| 568 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 569 | void cfg80211_sched_scan_results(struct wiphy *wiphy, u64 reqid) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 570 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 571 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 572 | struct cfg80211_sched_scan_request *request; |
| 573 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 574 | trace_cfg80211_sched_scan_results(wiphy, reqid); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 575 | /* ignore if we're not scanning */ |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 576 | |
Arend Van Spriel | 1b57b62 | 2017-05-23 09:58:07 +0100 | [diff] [blame] | 577 | rcu_read_lock(); |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 578 | request = cfg80211_find_sched_scan_req(rdev, reqid); |
| 579 | if (request) { |
| 580 | request->report_results = true; |
| 581 | queue_work(cfg80211_wq, &rdev->sched_scan_res_wk); |
| 582 | } |
Arend Van Spriel | 1b57b62 | 2017-05-23 09:58:07 +0100 | [diff] [blame] | 583 | rcu_read_unlock(); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 584 | } |
| 585 | EXPORT_SYMBOL(cfg80211_sched_scan_results); |
| 586 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 587 | void cfg80211_sched_scan_stopped_rtnl(struct wiphy *wiphy, u64 reqid) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 588 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 589 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 590 | |
Eliad Peller | 792e6aa | 2014-04-30 16:14:23 +0300 | [diff] [blame] | 591 | ASSERT_RTNL(); |
| 592 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 593 | trace_cfg80211_sched_scan_stopped(wiphy, reqid); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 594 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 595 | __cfg80211_stop_sched_scan(rdev, reqid, true); |
Eliad Peller | 792e6aa | 2014-04-30 16:14:23 +0300 | [diff] [blame] | 596 | } |
| 597 | EXPORT_SYMBOL(cfg80211_sched_scan_stopped_rtnl); |
| 598 | |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 599 | void cfg80211_sched_scan_stopped(struct wiphy *wiphy, u64 reqid) |
Eliad Peller | 792e6aa | 2014-04-30 16:14:23 +0300 | [diff] [blame] | 600 | { |
| 601 | rtnl_lock(); |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 602 | cfg80211_sched_scan_stopped_rtnl(wiphy, reqid); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 603 | rtnl_unlock(); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 604 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 605 | EXPORT_SYMBOL(cfg80211_sched_scan_stopped); |
| 606 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 607 | int cfg80211_stop_sched_scan_req(struct cfg80211_registered_device *rdev, |
| 608 | struct cfg80211_sched_scan_request *req, |
| 609 | bool driver_initiated) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 610 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 611 | ASSERT_RTNL(); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 612 | |
Luciano Coelho | 85a9994 | 2011-05-12 16:28:29 +0300 | [diff] [blame] | 613 | if (!driver_initiated) { |
Arend Van Spriel | 3a3ecf1 | 2017-04-21 13:05:02 +0100 | [diff] [blame] | 614 | int err = rdev_sched_scan_stop(rdev, req->dev, req->reqid); |
Luciano Coelho | 85a9994 | 2011-05-12 16:28:29 +0300 | [diff] [blame] | 615 | if (err) |
| 616 | return err; |
| 617 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 618 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 619 | nl80211_send_sched_scan(req, NL80211_CMD_SCHED_SCAN_STOPPED); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 620 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 621 | cfg80211_del_sched_scan_req(rdev, req); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 622 | |
Jesper Juhl | 3b4670f | 2011-06-29 22:49:33 +0200 | [diff] [blame] | 623 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 624 | } |
| 625 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 626 | int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev, |
| 627 | u64 reqid, bool driver_initiated) |
| 628 | { |
| 629 | struct cfg80211_sched_scan_request *sched_scan_req; |
| 630 | |
| 631 | ASSERT_RTNL(); |
| 632 | |
| 633 | sched_scan_req = cfg80211_find_sched_scan_req(rdev, reqid); |
Arend Van Spriel | b34939b | 2017-04-28 13:40:28 +0100 | [diff] [blame] | 634 | if (!sched_scan_req) |
| 635 | return -ENOENT; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 636 | |
| 637 | return cfg80211_stop_sched_scan_req(rdev, sched_scan_req, |
| 638 | driver_initiated); |
| 639 | } |
| 640 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 641 | void cfg80211_bss_age(struct cfg80211_registered_device *rdev, |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 642 | unsigned long age_secs) |
| 643 | { |
| 644 | struct cfg80211_internal_bss *bss; |
| 645 | unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC); |
| 646 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 647 | spin_lock_bh(&rdev->bss_lock); |
| 648 | list_for_each_entry(bss, &rdev->bss_list, list) |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 649 | bss->ts -= age_jiffies; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 650 | spin_unlock_bh(&rdev->bss_lock); |
Dan Williams | cb3a8ee | 2009-02-11 17:14:43 -0500 | [diff] [blame] | 651 | } |
| 652 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 653 | void cfg80211_bss_expire(struct cfg80211_registered_device *rdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 654 | { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 655 | __cfg80211_bss_expire(rdev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 656 | } |
| 657 | |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 658 | const struct element * |
| 659 | cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len, |
| 660 | const u8 *match, unsigned int match_len, |
| 661 | unsigned int match_offset) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 662 | { |
Johannes Berg | 0f3b07f | 2019-02-07 21:44:41 +0100 | [diff] [blame] | 663 | const struct element *elem; |
| 664 | |
Johannes Berg | 0f3b07f | 2019-02-07 21:44:41 +0100 | [diff] [blame] | 665 | for_each_element_id(elem, eid, ies, len) { |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 666 | if (elem->datalen >= match_offset + match_len && |
| 667 | !memcmp(elem->data + match_offset, match, match_len)) |
| 668 | return elem; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 669 | } |
Luca Coelho | fbd05e4 | 2016-09-15 18:15:09 +0300 | [diff] [blame] | 670 | |
| 671 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 672 | } |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 673 | EXPORT_SYMBOL(cfg80211_find_elem_match); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 674 | |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 675 | const struct element *cfg80211_find_vendor_elem(unsigned int oui, int oui_type, |
| 676 | const u8 *ies, |
| 677 | unsigned int len) |
Eliad Peller | 0c28ec5 | 2011-09-15 11:53:01 +0300 | [diff] [blame] | 678 | { |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 679 | const struct element *elem; |
Luca Coelho | fbd05e4 | 2016-09-15 18:15:09 +0300 | [diff] [blame] | 680 | u8 match[] = { oui >> 16, oui >> 8, oui, oui_type }; |
| 681 | int match_len = (oui_type < 0) ? 3 : sizeof(match); |
Eliad Peller | 0c28ec5 | 2011-09-15 11:53:01 +0300 | [diff] [blame] | 682 | |
Emmanuel Grumbach | 9e9ea43 | 2016-05-03 16:08:07 +0300 | [diff] [blame] | 683 | if (WARN_ON(oui_type > 0xff)) |
| 684 | return NULL; |
| 685 | |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 686 | elem = cfg80211_find_elem_match(WLAN_EID_VENDOR_SPECIFIC, ies, len, |
| 687 | match, match_len, 0); |
Eliad Peller | 0c28ec5 | 2011-09-15 11:53:01 +0300 | [diff] [blame] | 688 | |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 689 | if (!elem || elem->datalen < 4) |
Luca Coelho | fbd05e4 | 2016-09-15 18:15:09 +0300 | [diff] [blame] | 690 | return NULL; |
Luciano Coelho | 6719429 | 2013-02-12 20:11:38 +0200 | [diff] [blame] | 691 | |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 692 | return elem; |
Eliad Peller | 0c28ec5 | 2011-09-15 11:53:01 +0300 | [diff] [blame] | 693 | } |
Johannes Berg | 49a68e0 | 2019-02-07 23:26:38 +0100 | [diff] [blame] | 694 | EXPORT_SYMBOL(cfg80211_find_vendor_elem); |
Eliad Peller | 0c28ec5 | 2011-09-15 11:53:01 +0300 | [diff] [blame] | 695 | |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 696 | /** |
| 697 | * enum bss_compare_mode - BSS compare mode |
| 698 | * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find) |
| 699 | * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode |
| 700 | * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode |
| 701 | */ |
| 702 | enum bss_compare_mode { |
| 703 | BSS_CMP_REGULAR, |
| 704 | BSS_CMP_HIDE_ZLEN, |
| 705 | BSS_CMP_HIDE_NUL, |
| 706 | }; |
| 707 | |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 708 | static int cmp_bss(struct cfg80211_bss *a, |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 709 | struct cfg80211_bss *b, |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 710 | enum bss_compare_mode mode) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 711 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 712 | const struct cfg80211_bss_ies *a_ies, *b_ies; |
Johannes Berg | 3af6341 | 2013-01-30 00:40:20 +0100 | [diff] [blame] | 713 | const u8 *ie1 = NULL; |
| 714 | const u8 *ie2 = NULL; |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 715 | int i, r; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 716 | |
Johannes Berg | 3af6341 | 2013-01-30 00:40:20 +0100 | [diff] [blame] | 717 | if (a->channel != b->channel) |
| 718 | return b->channel->center_freq - a->channel->center_freq; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 719 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 720 | a_ies = rcu_access_pointer(a->ies); |
| 721 | if (!a_ies) |
| 722 | return -1; |
| 723 | b_ies = rcu_access_pointer(b->ies); |
| 724 | if (!b_ies) |
| 725 | return 1; |
| 726 | |
Johannes Berg | 3af6341 | 2013-01-30 00:40:20 +0100 | [diff] [blame] | 727 | if (WLAN_CAPABILITY_IS_STA_BSS(a->capability)) |
| 728 | ie1 = cfg80211_find_ie(WLAN_EID_MESH_ID, |
| 729 | a_ies->data, a_ies->len); |
| 730 | if (WLAN_CAPABILITY_IS_STA_BSS(b->capability)) |
| 731 | ie2 = cfg80211_find_ie(WLAN_EID_MESH_ID, |
| 732 | b_ies->data, b_ies->len); |
| 733 | if (ie1 && ie2) { |
| 734 | int mesh_id_cmp; |
| 735 | |
| 736 | if (ie1[1] == ie2[1]) |
| 737 | mesh_id_cmp = memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
| 738 | else |
| 739 | mesh_id_cmp = ie2[1] - ie1[1]; |
| 740 | |
| 741 | ie1 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, |
| 742 | a_ies->data, a_ies->len); |
| 743 | ie2 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, |
| 744 | b_ies->data, b_ies->len); |
| 745 | if (ie1 && ie2) { |
| 746 | if (mesh_id_cmp) |
| 747 | return mesh_id_cmp; |
| 748 | if (ie1[1] != ie2[1]) |
| 749 | return ie2[1] - ie1[1]; |
| 750 | return memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
| 751 | } |
| 752 | } |
| 753 | |
Johannes Berg | 3af6341 | 2013-01-30 00:40:20 +0100 | [diff] [blame] | 754 | r = memcmp(a->bssid, b->bssid, sizeof(a->bssid)); |
| 755 | if (r) |
| 756 | return r; |
| 757 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 758 | ie1 = cfg80211_find_ie(WLAN_EID_SSID, a_ies->data, a_ies->len); |
| 759 | 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] | 760 | |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 761 | if (!ie1 && !ie2) |
| 762 | return 0; |
| 763 | |
Johannes Berg | f94f8b1 | 2012-11-28 22:42:34 +0100 | [diff] [blame] | 764 | /* |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 765 | * Note that with "hide_ssid", the function returns a match if |
| 766 | * the already-present BSS ("b") is a hidden SSID beacon for |
| 767 | * the new BSS ("a"). |
Johannes Berg | f94f8b1 | 2012-11-28 22:42:34 +0100 | [diff] [blame] | 768 | */ |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 769 | |
| 770 | /* sort missing IE before (left of) present IE */ |
| 771 | if (!ie1) |
| 772 | return -1; |
| 773 | if (!ie2) |
| 774 | return 1; |
| 775 | |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 776 | switch (mode) { |
| 777 | case BSS_CMP_HIDE_ZLEN: |
| 778 | /* |
| 779 | * In ZLEN mode we assume the BSS entry we're |
| 780 | * looking for has a zero-length SSID. So if |
| 781 | * the one we're looking at right now has that, |
| 782 | * return 0. Otherwise, return the difference |
| 783 | * in length, but since we're looking for the |
| 784 | * 0-length it's really equivalent to returning |
| 785 | * the length of the one we're looking at. |
| 786 | * |
| 787 | * No content comparison is needed as we assume |
| 788 | * the content length is zero. |
| 789 | */ |
| 790 | return ie2[1]; |
| 791 | case BSS_CMP_REGULAR: |
| 792 | default: |
| 793 | /* sort by length first, then by contents */ |
| 794 | if (ie1[1] != ie2[1]) |
| 795 | return ie2[1] - ie1[1]; |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 796 | return memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 797 | case BSS_CMP_HIDE_NUL: |
| 798 | if (ie1[1] != ie2[1]) |
| 799 | return ie2[1] - ie1[1]; |
| 800 | /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */ |
| 801 | for (i = 0; i < ie2[1]; i++) |
| 802 | if (ie2[i + 2]) |
| 803 | return -1; |
| 804 | return 0; |
| 805 | } |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 806 | } |
| 807 | |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 808 | static bool cfg80211_bss_type_match(u16 capability, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 809 | enum nl80211_band band, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 810 | enum ieee80211_bss_type bss_type) |
| 811 | { |
| 812 | bool ret = true; |
| 813 | u16 mask, val; |
| 814 | |
| 815 | if (bss_type == IEEE80211_BSS_TYPE_ANY) |
| 816 | return ret; |
| 817 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 818 | if (band == NL80211_BAND_60GHZ) { |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 819 | mask = WLAN_CAPABILITY_DMG_TYPE_MASK; |
| 820 | switch (bss_type) { |
| 821 | case IEEE80211_BSS_TYPE_ESS: |
| 822 | val = WLAN_CAPABILITY_DMG_TYPE_AP; |
| 823 | break; |
| 824 | case IEEE80211_BSS_TYPE_PBSS: |
| 825 | val = WLAN_CAPABILITY_DMG_TYPE_PBSS; |
| 826 | break; |
| 827 | case IEEE80211_BSS_TYPE_IBSS: |
| 828 | val = WLAN_CAPABILITY_DMG_TYPE_IBSS; |
| 829 | break; |
| 830 | default: |
| 831 | return false; |
| 832 | } |
| 833 | } else { |
| 834 | mask = WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS; |
| 835 | switch (bss_type) { |
| 836 | case IEEE80211_BSS_TYPE_ESS: |
| 837 | val = WLAN_CAPABILITY_ESS; |
| 838 | break; |
| 839 | case IEEE80211_BSS_TYPE_IBSS: |
| 840 | val = WLAN_CAPABILITY_IBSS; |
| 841 | break; |
| 842 | case IEEE80211_BSS_TYPE_MBSS: |
| 843 | val = 0; |
| 844 | break; |
| 845 | default: |
| 846 | return false; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | ret = ((capability & mask) == val); |
| 851 | return ret; |
| 852 | } |
| 853 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 854 | /* Returned bss is reference counted and must be cleaned up appropriately. */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 855 | struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy, |
| 856 | struct ieee80211_channel *channel, |
| 857 | const u8 *bssid, |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 858 | const u8 *ssid, size_t ssid_len, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 859 | enum ieee80211_bss_type bss_type, |
| 860 | enum ieee80211_privacy privacy) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 861 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 862 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 863 | struct cfg80211_internal_bss *bss, *res = NULL; |
Johannes Berg | ccb6c13 | 2010-07-13 10:55:38 +0200 | [diff] [blame] | 864 | unsigned long now = jiffies; |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 865 | int bss_privacy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 866 | |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 867 | trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, bss_type, |
| 868 | privacy); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 869 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 870 | spin_lock_bh(&rdev->bss_lock); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 871 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 872 | list_for_each_entry(bss, &rdev->bss_list, list) { |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 873 | if (!cfg80211_bss_type_match(bss->pub.capability, |
| 874 | bss->pub.channel->band, bss_type)) |
| 875 | continue; |
| 876 | |
| 877 | bss_privacy = (bss->pub.capability & WLAN_CAPABILITY_PRIVACY); |
| 878 | if ((privacy == IEEE80211_PRIVACY_ON && !bss_privacy) || |
| 879 | (privacy == IEEE80211_PRIVACY_OFF && bss_privacy)) |
Johannes Berg | 79420f0 | 2009-02-10 21:25:59 +0100 | [diff] [blame] | 880 | continue; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 881 | if (channel && bss->pub.channel != channel) |
| 882 | continue; |
Johannes Berg | c14a740 | 2014-04-09 22:36:50 +0200 | [diff] [blame] | 883 | if (!is_valid_ether_addr(bss->pub.bssid)) |
| 884 | continue; |
Johannes Berg | ccb6c13 | 2010-07-13 10:55:38 +0200 | [diff] [blame] | 885 | /* Don't get expired BSS structs */ |
| 886 | if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) && |
| 887 | !atomic_read(&bss->hold)) |
| 888 | continue; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 889 | if (is_bss(&bss->pub, bssid, ssid, ssid_len)) { |
| 890 | res = bss; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 891 | bss_ref_get(rdev, res); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 892 | break; |
| 893 | } |
| 894 | } |
| 895 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 896 | spin_unlock_bh(&rdev->bss_lock); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 897 | if (!res) |
| 898 | return NULL; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 899 | trace_cfg80211_return_bss(&res->pub); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 900 | return &res->pub; |
| 901 | } |
| 902 | EXPORT_SYMBOL(cfg80211_get_bss); |
| 903 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 904 | static void rb_insert_bss(struct cfg80211_registered_device *rdev, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 905 | struct cfg80211_internal_bss *bss) |
| 906 | { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 907 | struct rb_node **p = &rdev->bss_tree.rb_node; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 908 | struct rb_node *parent = NULL; |
| 909 | struct cfg80211_internal_bss *tbss; |
| 910 | int cmp; |
| 911 | |
| 912 | while (*p) { |
| 913 | parent = *p; |
| 914 | tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn); |
| 915 | |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 916 | cmp = cmp_bss(&bss->pub, &tbss->pub, BSS_CMP_REGULAR); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 917 | |
| 918 | if (WARN_ON(!cmp)) { |
| 919 | /* will sort of leak this BSS */ |
| 920 | return; |
| 921 | } |
| 922 | |
| 923 | if (cmp < 0) |
| 924 | p = &(*p)->rb_left; |
| 925 | else |
| 926 | p = &(*p)->rb_right; |
| 927 | } |
| 928 | |
| 929 | rb_link_node(&bss->rbn, parent, p); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 930 | rb_insert_color(&bss->rbn, &rdev->bss_tree); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | static struct cfg80211_internal_bss * |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 934 | rb_find_bss(struct cfg80211_registered_device *rdev, |
Johannes Berg | 5622f5b | 2013-01-30 00:26:45 +0100 | [diff] [blame] | 935 | struct cfg80211_internal_bss *res, |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 936 | enum bss_compare_mode mode) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 937 | { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 938 | struct rb_node *n = rdev->bss_tree.rb_node; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 939 | struct cfg80211_internal_bss *bss; |
| 940 | int r; |
| 941 | |
| 942 | while (n) { |
| 943 | bss = rb_entry(n, struct cfg80211_internal_bss, rbn); |
Johannes Berg | 4593c4c | 2013-02-01 19:20:03 +0100 | [diff] [blame] | 944 | r = cmp_bss(&res->pub, &bss->pub, mode); |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 945 | |
| 946 | if (r == 0) |
| 947 | return bss; |
| 948 | else if (r < 0) |
| 949 | n = n->rb_left; |
| 950 | else |
| 951 | n = n->rb_right; |
| 952 | } |
| 953 | |
| 954 | return NULL; |
| 955 | } |
| 956 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 957 | static bool cfg80211_combine_bsses(struct cfg80211_registered_device *rdev, |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 958 | struct cfg80211_internal_bss *new) |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 959 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 960 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 961 | struct cfg80211_internal_bss *bss; |
| 962 | const u8 *ie; |
| 963 | int i, ssidlen; |
| 964 | u8 fold = 0; |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 965 | u32 n_entries = 0; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 966 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 967 | ies = rcu_access_pointer(new->pub.beacon_ies); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 968 | if (WARN_ON(!ies)) |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 969 | return false; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 970 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 971 | ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len); |
| 972 | if (!ie) { |
| 973 | /* nothing to do */ |
| 974 | return true; |
| 975 | } |
| 976 | |
| 977 | ssidlen = ie[1]; |
| 978 | for (i = 0; i < ssidlen; i++) |
| 979 | fold |= ie[2 + i]; |
| 980 | |
| 981 | if (fold) { |
| 982 | /* not a hidden SSID */ |
| 983 | return true; |
| 984 | } |
| 985 | |
| 986 | /* This is the bad part ... */ |
| 987 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 988 | list_for_each_entry(bss, &rdev->bss_list, list) { |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 989 | /* |
| 990 | * we're iterating all the entries anyway, so take the |
| 991 | * opportunity to validate the list length accounting |
| 992 | */ |
| 993 | n_entries++; |
| 994 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 995 | if (!ether_addr_equal(bss->pub.bssid, new->pub.bssid)) |
| 996 | continue; |
| 997 | if (bss->pub.channel != new->pub.channel) |
| 998 | continue; |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 999 | if (bss->pub.scan_width != new->pub.scan_width) |
| 1000 | continue; |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1001 | if (rcu_access_pointer(bss->pub.beacon_ies)) |
| 1002 | continue; |
| 1003 | ies = rcu_access_pointer(bss->pub.ies); |
| 1004 | if (!ies) |
| 1005 | continue; |
| 1006 | ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len); |
| 1007 | if (!ie) |
| 1008 | continue; |
| 1009 | if (ssidlen && ie[1] != ssidlen) |
| 1010 | continue; |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1011 | if (WARN_ON_ONCE(bss->pub.hidden_beacon_bss)) |
| 1012 | continue; |
| 1013 | if (WARN_ON_ONCE(!list_empty(&bss->hidden_list))) |
| 1014 | list_del(&bss->hidden_list); |
| 1015 | /* combine them */ |
| 1016 | list_add(&bss->hidden_list, &new->hidden_list); |
| 1017 | bss->pub.hidden_beacon_bss = &new->pub; |
| 1018 | new->refcount += bss->refcount; |
| 1019 | rcu_assign_pointer(bss->pub.beacon_ies, |
| 1020 | new->pub.beacon_ies); |
| 1021 | } |
| 1022 | |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 1023 | WARN_ONCE(n_entries != rdev->bss_entries, |
| 1024 | "rdev bss entries[%d]/list[len:%d] corruption\n", |
| 1025 | rdev->bss_entries, n_entries); |
| 1026 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1027 | return true; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1030 | struct cfg80211_non_tx_bss { |
| 1031 | struct cfg80211_bss *tx_bss; |
| 1032 | u8 max_bssid_indicator; |
| 1033 | u8 bssid_index; |
| 1034 | }; |
| 1035 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 1036 | /* Returned bss is reference counted and must be cleaned up appropriately. */ |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 1037 | static struct cfg80211_internal_bss * |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1038 | cfg80211_bss_update(struct cfg80211_registered_device *rdev, |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 1039 | struct cfg80211_internal_bss *tmp, |
| 1040 | bool signal_valid) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1041 | { |
| 1042 | struct cfg80211_internal_bss *found = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1043 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1044 | if (WARN_ON(!tmp->pub.channel)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1045 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1046 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1047 | tmp->ts = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1048 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1049 | spin_lock_bh(&rdev->bss_lock); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1050 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1051 | if (WARN_ON(!rcu_access_pointer(tmp->pub.ies))) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1052 | spin_unlock_bh(&rdev->bss_lock); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1053 | return NULL; |
| 1054 | } |
| 1055 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1056 | found = rb_find_bss(rdev, tmp, BSS_CMP_REGULAR); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1057 | |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 1058 | if (found) { |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 1059 | /* Update IEs */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1060 | if (rcu_access_pointer(tmp->pub.proberesp_ies)) { |
| 1061 | const struct cfg80211_bss_ies *old; |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 1062 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1063 | old = rcu_access_pointer(found->pub.proberesp_ies); |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 1064 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1065 | rcu_assign_pointer(found->pub.proberesp_ies, |
| 1066 | tmp->pub.proberesp_ies); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 1067 | /* Override possible earlier Beacon frame IEs */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1068 | rcu_assign_pointer(found->pub.ies, |
| 1069 | tmp->pub.proberesp_ies); |
| 1070 | if (old) |
| 1071 | kfree_rcu((struct cfg80211_bss_ies *)old, |
| 1072 | rcu_head); |
| 1073 | } else if (rcu_access_pointer(tmp->pub.beacon_ies)) { |
Johannes Berg | 9537f22 | 2013-02-01 01:19:48 +0100 | [diff] [blame] | 1074 | const struct cfg80211_bss_ies *old; |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1075 | struct cfg80211_internal_bss *bss; |
| 1076 | |
| 1077 | if (found->pub.hidden_beacon_bss && |
| 1078 | !list_empty(&found->hidden_list)) { |
Johannes Berg | 1345ee6 | 2013-03-06 10:31:05 +0100 | [diff] [blame] | 1079 | const struct cfg80211_bss_ies *f; |
| 1080 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1081 | /* |
| 1082 | * The found BSS struct is one of the probe |
| 1083 | * response members of a group, but we're |
| 1084 | * receiving a beacon (beacon_ies in the tmp |
| 1085 | * bss is used). This can only mean that the |
| 1086 | * AP changed its beacon from not having an |
| 1087 | * SSID to showing it, which is confusing so |
| 1088 | * drop this information. |
| 1089 | */ |
Johannes Berg | 1345ee6 | 2013-03-06 10:31:05 +0100 | [diff] [blame] | 1090 | |
| 1091 | f = rcu_access_pointer(tmp->pub.beacon_ies); |
| 1092 | kfree_rcu((struct cfg80211_bss_ies *)f, |
| 1093 | rcu_head); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1094 | goto drop; |
| 1095 | } |
Johannes Berg | 915de2f | 2012-11-28 22:39:37 +0100 | [diff] [blame] | 1096 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1097 | old = rcu_access_pointer(found->pub.beacon_ies); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 1098 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1099 | rcu_assign_pointer(found->pub.beacon_ies, |
| 1100 | tmp->pub.beacon_ies); |
Sven Neumann | 01123e2 | 2010-12-09 15:05:24 +0100 | [diff] [blame] | 1101 | |
| 1102 | /* Override IEs if they were from a beacon before */ |
Johannes Berg | 9537f22 | 2013-02-01 01:19:48 +0100 | [diff] [blame] | 1103 | if (old == rcu_access_pointer(found->pub.ies)) |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1104 | rcu_assign_pointer(found->pub.ies, |
| 1105 | tmp->pub.beacon_ies); |
Johannes Berg | cd1658f | 2009-04-16 15:00:58 +0200 | [diff] [blame] | 1106 | |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1107 | /* Assign beacon IEs to all sub entries */ |
| 1108 | list_for_each_entry(bss, &found->hidden_list, |
| 1109 | hidden_list) { |
| 1110 | const struct cfg80211_bss_ies *ies; |
| 1111 | |
| 1112 | ies = rcu_access_pointer(bss->pub.beacon_ies); |
| 1113 | WARN_ON(ies != old); |
| 1114 | |
| 1115 | rcu_assign_pointer(bss->pub.beacon_ies, |
| 1116 | tmp->pub.beacon_ies); |
| 1117 | } |
| 1118 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1119 | if (old) |
| 1120 | kfree_rcu((struct cfg80211_bss_ies *)old, |
| 1121 | rcu_head); |
| 1122 | } |
Johannes Berg | 1345ee6 | 2013-03-06 10:31:05 +0100 | [diff] [blame] | 1123 | |
| 1124 | found->pub.beacon_interval = tmp->pub.beacon_interval; |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 1125 | /* |
| 1126 | * don't update the signal if beacon was heard on |
| 1127 | * adjacent channel. |
| 1128 | */ |
| 1129 | if (signal_valid) |
| 1130 | found->pub.signal = tmp->pub.signal; |
Johannes Berg | 1345ee6 | 2013-03-06 10:31:05 +0100 | [diff] [blame] | 1131 | found->pub.capability = tmp->pub.capability; |
| 1132 | found->ts = tmp->ts; |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1133 | found->ts_boottime = tmp->ts_boottime; |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 1134 | found->parent_tsf = tmp->parent_tsf; |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 1135 | found->pub.chains = tmp->pub.chains; |
| 1136 | memcpy(found->pub.chain_signal, tmp->pub.chain_signal, |
| 1137 | IEEE80211_MAX_CHAINS); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 1138 | ether_addr_copy(found->parent_bssid, tmp->parent_bssid); |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1139 | found->pub.max_bssid_indicator = tmp->pub.max_bssid_indicator; |
| 1140 | found->pub.bssid_index = tmp->pub.bssid_index; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1141 | } else { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1142 | struct cfg80211_internal_bss *new; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 1143 | struct cfg80211_internal_bss *hidden; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1144 | struct cfg80211_bss_ies *ies; |
Dmitry Tarnyagin | dd9dfb9 | 2011-11-04 17:12:07 +0100 | [diff] [blame] | 1145 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1146 | /* |
| 1147 | * create a copy -- the "res" variable that is passed in |
| 1148 | * is allocated on the stack since it's not needed in the |
| 1149 | * more common case of an update |
| 1150 | */ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1151 | new = kzalloc(sizeof(*new) + rdev->wiphy.bss_priv_size, |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1152 | GFP_ATOMIC); |
| 1153 | if (!new) { |
| 1154 | ies = (void *)rcu_dereference(tmp->pub.beacon_ies); |
| 1155 | if (ies) |
| 1156 | kfree_rcu(ies, rcu_head); |
| 1157 | ies = (void *)rcu_dereference(tmp->pub.proberesp_ies); |
| 1158 | if (ies) |
| 1159 | kfree_rcu(ies, rcu_head); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1160 | goto drop; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1161 | } |
| 1162 | memcpy(new, tmp, sizeof(*new)); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1163 | new->refcount = 1; |
| 1164 | INIT_LIST_HEAD(&new->hidden_list); |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1165 | INIT_LIST_HEAD(&new->pub.nontrans_list); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1166 | |
| 1167 | if (rcu_access_pointer(tmp->pub.proberesp_ies)) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1168 | hidden = rb_find_bss(rdev, tmp, BSS_CMP_HIDE_ZLEN); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1169 | if (!hidden) |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1170 | hidden = rb_find_bss(rdev, tmp, |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1171 | BSS_CMP_HIDE_NUL); |
| 1172 | if (hidden) { |
| 1173 | new->pub.hidden_beacon_bss = &hidden->pub; |
| 1174 | list_add(&new->hidden_list, |
| 1175 | &hidden->hidden_list); |
| 1176 | hidden->refcount++; |
| 1177 | rcu_assign_pointer(new->pub.beacon_ies, |
| 1178 | hidden->pub.beacon_ies); |
| 1179 | } |
| 1180 | } else { |
| 1181 | /* |
| 1182 | * Ok so we found a beacon, and don't have an entry. If |
| 1183 | * it's a beacon with hidden SSID, we might be in for an |
| 1184 | * expensive search for any probe responses that should |
| 1185 | * be grouped with this beacon for updates ... |
| 1186 | */ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1187 | if (!cfg80211_combine_bsses(rdev, new)) { |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1188 | kfree(new); |
| 1189 | goto drop; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 1193 | if (rdev->bss_entries >= bss_entries_limit && |
| 1194 | !cfg80211_bss_expire_oldest(rdev)) { |
| 1195 | kfree(new); |
| 1196 | goto drop; |
| 1197 | } |
| 1198 | |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 1199 | /* This must be before the call to bss_ref_get */ |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1200 | if (tmp->pub.transmitted_bss) { |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 1201 | struct cfg80211_internal_bss *pbss = |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1202 | container_of(tmp->pub.transmitted_bss, |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 1203 | struct cfg80211_internal_bss, |
| 1204 | pub); |
| 1205 | |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1206 | new->pub.transmitted_bss = tmp->pub.transmitted_bss; |
Sara Sharon | a3584f56d | 2019-01-21 12:22:21 +0200 | [diff] [blame] | 1207 | bss_ref_get(rdev, pbss); |
| 1208 | } |
| 1209 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1210 | list_add_tail(&new->list, &rdev->bss_list); |
Johannes Berg | 9853a55 | 2016-11-15 12:05:11 +0100 | [diff] [blame] | 1211 | rdev->bss_entries++; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1212 | rb_insert_bss(rdev, new); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1213 | found = new; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1216 | rdev->bss_generation++; |
| 1217 | bss_ref_get(rdev, found); |
| 1218 | spin_unlock_bh(&rdev->bss_lock); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1219 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1220 | return found; |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1221 | drop: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1222 | spin_unlock_bh(&rdev->bss_lock); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1223 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1224 | } |
| 1225 | |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1226 | /* |
| 1227 | * Update RX channel information based on the available frame payload |
| 1228 | * information. This is mainly for the 2.4 GHz band where frames can be received |
| 1229 | * from neighboring channels and the Beacon frames use the DSSS Parameter Set |
| 1230 | * element to indicate the current (transmitting) channel, but this might also |
| 1231 | * be needed on other bands if RX frequency does not match with the actual |
| 1232 | * operating channel of a BSS. |
| 1233 | */ |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1234 | static struct ieee80211_channel * |
| 1235 | cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen, |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1236 | struct ieee80211_channel *channel, |
| 1237 | enum nl80211_bss_scan_width scan_width) |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1238 | { |
| 1239 | const u8 *tmp; |
| 1240 | u32 freq; |
| 1241 | int channel_number = -1; |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1242 | struct ieee80211_channel *alt_channel; |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1243 | |
| 1244 | tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen); |
| 1245 | if (tmp && tmp[1] == 1) { |
| 1246 | channel_number = tmp[2]; |
| 1247 | } else { |
| 1248 | tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen); |
| 1249 | if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) { |
| 1250 | struct ieee80211_ht_operation *htop = (void *)(tmp + 2); |
| 1251 | |
| 1252 | channel_number = htop->primary_chan; |
| 1253 | } |
| 1254 | } |
| 1255 | |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1256 | if (channel_number < 0) { |
| 1257 | /* No channel information in frame payload */ |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1258 | return channel; |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1259 | } |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1260 | |
| 1261 | freq = ieee80211_channel_to_frequency(channel_number, channel->band); |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1262 | alt_channel = ieee80211_get_channel(wiphy, freq); |
| 1263 | if (!alt_channel) { |
| 1264 | if (channel->band == NL80211_BAND_2GHZ) { |
| 1265 | /* |
| 1266 | * Better not allow unexpected channels when that could |
| 1267 | * be going beyond the 1-11 range (e.g., discovering |
| 1268 | * BSS on channel 12 when radio is configured for |
| 1269 | * channel 11. |
| 1270 | */ |
| 1271 | return NULL; |
| 1272 | } |
| 1273 | |
| 1274 | /* No match for the payload channel number - ignore it */ |
| 1275 | return channel; |
| 1276 | } |
| 1277 | |
| 1278 | if (scan_width == NL80211_BSS_CHAN_WIDTH_10 || |
| 1279 | scan_width == NL80211_BSS_CHAN_WIDTH_5) { |
| 1280 | /* |
| 1281 | * Ignore channel number in 5 and 10 MHz channels where there |
| 1282 | * may not be an n:1 or 1:n mapping between frequencies and |
| 1283 | * channel numbers. |
| 1284 | */ |
| 1285 | return channel; |
| 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * Use the channel determined through the payload channel number |
| 1290 | * instead of the RX channel reported by the driver. |
| 1291 | */ |
| 1292 | if (alt_channel->flags & IEEE80211_CHAN_DISABLED) |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1293 | return NULL; |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1294 | return alt_channel; |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1295 | } |
| 1296 | |
Ben Greear | 0e3a39b | 2013-06-19 14:06:27 -0700 | [diff] [blame] | 1297 | /* Returned bss is reference counted and must be cleaned up appropriately. */ |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1298 | static struct cfg80211_bss * |
| 1299 | cfg80211_inform_single_bss_data(struct wiphy *wiphy, |
| 1300 | struct cfg80211_inform_bss *data, |
| 1301 | enum cfg80211_bss_frame_type ftype, |
| 1302 | const u8 *bssid, u64 tsf, u16 capability, |
| 1303 | u16 beacon_interval, const u8 *ie, size_t ielen, |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1304 | struct cfg80211_non_tx_bss *non_tx_data, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1305 | gfp_t gfp) |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1306 | { |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1307 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1308 | struct cfg80211_bss_ies *ies; |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 1309 | struct ieee80211_channel *channel; |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1310 | struct cfg80211_internal_bss tmp = {}, *res; |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 1311 | int bss_type; |
Emmanuel Grumbach | 67af981 | 2014-05-18 10:15:24 +0300 | [diff] [blame] | 1312 | bool signal_valid; |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1313 | |
| 1314 | if (WARN_ON(!wiphy)) |
| 1315 | return NULL; |
| 1316 | |
Sujith | 22fe88d | 2010-05-13 10:34:08 +0530 | [diff] [blame] | 1317 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1318 | (data->signal < 0 || data->signal > 100))) |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1319 | return NULL; |
| 1320 | |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1321 | channel = cfg80211_get_bss_channel(wiphy, ie, ielen, data->chan, |
| 1322 | data->scan_width); |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1323 | if (!channel) |
| 1324 | return NULL; |
| 1325 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1326 | memcpy(tmp.pub.bssid, bssid, ETH_ALEN); |
| 1327 | tmp.pub.channel = channel; |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1328 | tmp.pub.scan_width = data->scan_width; |
| 1329 | tmp.pub.signal = data->signal; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1330 | tmp.pub.beacon_interval = beacon_interval; |
| 1331 | tmp.pub.capability = capability; |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1332 | tmp.ts_boottime = data->boottime_ns; |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1333 | if (non_tx_data) { |
| 1334 | tmp.pub.transmitted_bss = non_tx_data->tx_bss; |
| 1335 | tmp.pub.bssid_index = non_tx_data->bssid_index; |
| 1336 | tmp.pub.max_bssid_indicator = non_tx_data->max_bssid_indicator; |
| 1337 | } |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1338 | |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 1339 | /* |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 1340 | * If we do not know here whether the IEs are from a Beacon or Probe |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 1341 | * Response frame, we need to pick one of the options and only use it |
| 1342 | * with the driver that does not provide the full Beacon/Probe Response |
| 1343 | * frame. Use Beacon frame pointer to avoid indicating that this should |
Johannes Berg | 50521aa | 2013-01-30 21:33:19 +0100 | [diff] [blame] | 1344 | * override the IEs pointer should we have received an earlier |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1345 | * indication of Probe Response data. |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 1346 | */ |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 1347 | ies = kzalloc(sizeof(*ies) + ielen, gfp); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1348 | if (!ies) |
| 1349 | return NULL; |
| 1350 | ies->len = ielen; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 1351 | ies->tsf = tsf; |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 1352 | ies->from_beacon = false; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1353 | memcpy(ies->data, ie, ielen); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1354 | |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 1355 | switch (ftype) { |
| 1356 | case CFG80211_BSS_FTYPE_BEACON: |
| 1357 | ies->from_beacon = true; |
Luca Coelho | 925b597 | 2018-12-15 11:03:21 +0200 | [diff] [blame] | 1358 | /* fall through */ |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 1359 | case CFG80211_BSS_FTYPE_UNKNOWN: |
| 1360 | rcu_assign_pointer(tmp.pub.beacon_ies, ies); |
| 1361 | break; |
| 1362 | case CFG80211_BSS_FTYPE_PRESP: |
| 1363 | rcu_assign_pointer(tmp.pub.proberesp_ies, ies); |
| 1364 | break; |
| 1365 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1366 | rcu_assign_pointer(tmp.pub.ies, ies); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1367 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1368 | signal_valid = abs(data->chan->center_freq - channel->center_freq) <= |
Emmanuel Grumbach | 67af981 | 2014-05-18 10:15:24 +0300 | [diff] [blame] | 1369 | wiphy->max_adj_channel_rssi_comp; |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1370 | res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1371 | if (!res) |
| 1372 | return NULL; |
| 1373 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1374 | if (channel->band == NL80211_BAND_60GHZ) { |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 1375 | bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK; |
| 1376 | if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP || |
| 1377 | bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS) |
| 1378 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 1379 | } else { |
| 1380 | if (res->pub.capability & WLAN_CAPABILITY_ESS) |
| 1381 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 1382 | } |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1383 | |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1384 | if (non_tx_data && non_tx_data->tx_bss) { |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1385 | /* this is a nontransmitting bss, we need to add it to |
| 1386 | * transmitting bss' list if it is not there |
| 1387 | */ |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1388 | if (cfg80211_add_nontrans_list(non_tx_data->tx_bss, |
| 1389 | &res->pub)) { |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1390 | if (__cfg80211_unlink_bss(rdev, res)) |
| 1391 | rdev->bss_generation++; |
| 1392 | } |
| 1393 | } |
| 1394 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 1395 | trace_cfg80211_return_bss(&res->pub); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1396 | /* cfg80211_bss_update gives us a referenced result */ |
| 1397 | return &res->pub; |
| 1398 | } |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1399 | |
| 1400 | static void cfg80211_parse_mbssid_data(struct wiphy *wiphy, |
| 1401 | struct cfg80211_inform_bss *data, |
| 1402 | enum cfg80211_bss_frame_type ftype, |
| 1403 | const u8 *bssid, u64 tsf, |
| 1404 | u16 beacon_interval, const u8 *ie, |
| 1405 | size_t ielen, |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1406 | struct cfg80211_non_tx_bss *non_tx_data, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1407 | gfp_t gfp) |
| 1408 | { |
Johannes Berg | 1c8745f | 2019-02-07 22:36:33 +0100 | [diff] [blame] | 1409 | const u8 *mbssid_index_ie; |
| 1410 | const struct element *elem, *sub; |
| 1411 | size_t new_ie_len; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1412 | u8 new_bssid[ETH_ALEN]; |
| 1413 | u8 *new_ie; |
| 1414 | u16 capability; |
| 1415 | struct cfg80211_bss *bss; |
| 1416 | |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1417 | if (!non_tx_data) |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1418 | return; |
| 1419 | if (!cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen)) |
| 1420 | return; |
Sara Sharon | 213ed57 | 2019-01-16 23:02:03 +0200 | [diff] [blame] | 1421 | if (!wiphy->support_mbssid) |
| 1422 | return; |
| 1423 | if (wiphy->support_only_he_mbssid && |
| 1424 | !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ie, ielen)) |
| 1425 | return; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1426 | |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1427 | new_ie = kmalloc(IEEE80211_MAX_DATA_LEN, gfp); |
| 1428 | if (!new_ie) |
| 1429 | return; |
| 1430 | |
Johannes Berg | 1c8745f | 2019-02-07 22:36:33 +0100 | [diff] [blame] | 1431 | for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, ie, ielen) { |
| 1432 | if (elem->datalen < 4) |
| 1433 | continue; |
| 1434 | for_each_element(sub, elem->data + 1, elem->datalen - 1) { |
| 1435 | if (sub->id != 0 || sub->datalen < 4) { |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1436 | /* not a valid BSS profile */ |
| 1437 | continue; |
| 1438 | } |
| 1439 | |
Johannes Berg | 1c8745f | 2019-02-07 22:36:33 +0100 | [diff] [blame] | 1440 | if (sub->data[0] != WLAN_EID_NON_TX_BSSID_CAP || |
| 1441 | sub->data[1] != 2) { |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1442 | /* The first element within the Nontransmitted |
| 1443 | * BSSID Profile is not the Nontransmitted |
| 1444 | * BSSID Capability element. |
| 1445 | */ |
| 1446 | continue; |
| 1447 | } |
| 1448 | |
| 1449 | /* found a Nontransmitted BSSID Profile */ |
| 1450 | mbssid_index_ie = cfg80211_find_ie |
| 1451 | (WLAN_EID_MULTI_BSSID_IDX, |
Johannes Berg | 1c8745f | 2019-02-07 22:36:33 +0100 | [diff] [blame] | 1452 | sub->data, sub->datalen); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1453 | if (!mbssid_index_ie || mbssid_index_ie[1] < 1 || |
| 1454 | mbssid_index_ie[2] == 0) { |
| 1455 | /* No valid Multiple BSSID-Index element */ |
| 1456 | continue; |
| 1457 | } |
| 1458 | |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1459 | non_tx_data->bssid_index = mbssid_index_ie[2]; |
| 1460 | non_tx_data->max_bssid_indicator = elem->data[0]; |
| 1461 | |
| 1462 | cfg80211_gen_new_bssid(bssid, |
| 1463 | non_tx_data->max_bssid_indicator, |
| 1464 | non_tx_data->bssid_index, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1465 | new_bssid); |
| 1466 | memset(new_ie, 0, IEEE80211_MAX_DATA_LEN); |
Johannes Berg | 1c8745f | 2019-02-07 22:36:33 +0100 | [diff] [blame] | 1467 | new_ie_len = cfg80211_gen_new_ie(ie, ielen, sub->data, |
| 1468 | sub->datalen, new_ie, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1469 | gfp); |
| 1470 | if (!new_ie_len) |
| 1471 | continue; |
| 1472 | |
Johannes Berg | 1c8745f | 2019-02-07 22:36:33 +0100 | [diff] [blame] | 1473 | capability = get_unaligned_le16(sub->data + 2); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1474 | bss = cfg80211_inform_single_bss_data(wiphy, data, |
| 1475 | ftype, |
| 1476 | new_bssid, tsf, |
| 1477 | capability, |
| 1478 | beacon_interval, |
| 1479 | new_ie, |
| 1480 | new_ie_len, |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1481 | non_tx_data, |
| 1482 | gfp); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1483 | if (!bss) |
| 1484 | break; |
| 1485 | cfg80211_put_bss(wiphy, bss); |
| 1486 | } |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | kfree(new_ie); |
| 1490 | } |
| 1491 | |
| 1492 | struct cfg80211_bss * |
| 1493 | cfg80211_inform_bss_data(struct wiphy *wiphy, |
| 1494 | struct cfg80211_inform_bss *data, |
| 1495 | enum cfg80211_bss_frame_type ftype, |
| 1496 | const u8 *bssid, u64 tsf, u16 capability, |
| 1497 | u16 beacon_interval, const u8 *ie, size_t ielen, |
| 1498 | gfp_t gfp) |
| 1499 | { |
| 1500 | struct cfg80211_bss *res; |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1501 | struct cfg80211_non_tx_bss non_tx_data; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1502 | |
| 1503 | res = cfg80211_inform_single_bss_data(wiphy, data, ftype, bssid, tsf, |
| 1504 | capability, beacon_interval, ie, |
| 1505 | ielen, NULL, gfp); |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1506 | non_tx_data.tx_bss = res; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1507 | cfg80211_parse_mbssid_data(wiphy, data, ftype, bssid, tsf, |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1508 | beacon_interval, ie, ielen, &non_tx_data, |
| 1509 | gfp); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1510 | return res; |
| 1511 | } |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1512 | EXPORT_SYMBOL(cfg80211_inform_bss_data); |
Jussi Kivilinna | 06aa7af | 2009-03-26 23:40:09 +0200 | [diff] [blame] | 1513 | |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1514 | static void |
| 1515 | cfg80211_parse_mbssid_frame_data(struct wiphy *wiphy, |
| 1516 | struct cfg80211_inform_bss *data, |
| 1517 | struct ieee80211_mgmt *mgmt, size_t len, |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1518 | struct cfg80211_non_tx_bss *non_tx_data, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1519 | gfp_t gfp) |
| 1520 | { |
| 1521 | enum cfg80211_bss_frame_type ftype; |
| 1522 | const u8 *ie = mgmt->u.probe_resp.variable; |
| 1523 | size_t ielen = len - offsetof(struct ieee80211_mgmt, |
| 1524 | u.probe_resp.variable); |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1525 | |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1526 | ftype = ieee80211_is_beacon(mgmt->frame_control) ? |
| 1527 | CFG80211_BSS_FTYPE_BEACON : CFG80211_BSS_FTYPE_PRESP; |
| 1528 | |
| 1529 | cfg80211_parse_mbssid_data(wiphy, data, ftype, mgmt->bssid, |
| 1530 | le64_to_cpu(mgmt->u.probe_resp.timestamp), |
| 1531 | le16_to_cpu(mgmt->u.probe_resp.beacon_int), |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1532 | ie, ielen, non_tx_data, gfp); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | static void |
| 1536 | cfg80211_update_notlisted_nontrans(struct wiphy *wiphy, |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1537 | struct cfg80211_bss *nontrans_bss, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1538 | struct ieee80211_mgmt *mgmt, size_t len, |
| 1539 | gfp_t gfp) |
| 1540 | { |
| 1541 | u8 *ie, *new_ie, *pos; |
| 1542 | const u8 *nontrans_ssid, *trans_ssid, *mbssid; |
| 1543 | size_t ielen = len - offsetof(struct ieee80211_mgmt, |
| 1544 | u.probe_resp.variable); |
| 1545 | size_t new_ie_len; |
| 1546 | struct cfg80211_bss_ies *new_ies; |
| 1547 | const struct cfg80211_bss_ies *old; |
| 1548 | u8 cpy_len; |
| 1549 | |
| 1550 | ie = mgmt->u.probe_resp.variable; |
| 1551 | |
| 1552 | new_ie_len = ielen; |
| 1553 | trans_ssid = cfg80211_find_ie(WLAN_EID_SSID, ie, ielen); |
| 1554 | if (!trans_ssid) |
| 1555 | return; |
| 1556 | new_ie_len -= trans_ssid[1]; |
| 1557 | mbssid = cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen); |
| 1558 | if (!mbssid) |
| 1559 | return; |
| 1560 | new_ie_len -= mbssid[1]; |
| 1561 | rcu_read_lock(); |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1562 | nontrans_ssid = ieee80211_bss_get_ie(nontrans_bss, WLAN_EID_SSID); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1563 | if (!nontrans_ssid) { |
| 1564 | rcu_read_unlock(); |
| 1565 | return; |
| 1566 | } |
| 1567 | new_ie_len += nontrans_ssid[1]; |
| 1568 | rcu_read_unlock(); |
| 1569 | |
| 1570 | /* generate new ie for nontrans BSS |
| 1571 | * 1. replace SSID with nontrans BSS' SSID |
| 1572 | * 2. skip MBSSID IE |
| 1573 | */ |
| 1574 | new_ie = kzalloc(new_ie_len, gfp); |
| 1575 | if (!new_ie) |
| 1576 | return; |
| 1577 | new_ies = kzalloc(sizeof(*new_ies) + new_ie_len, gfp); |
Sara Sharon | bede8d2 | 2019-01-30 08:48:21 +0200 | [diff] [blame] | 1578 | if (!new_ies) |
| 1579 | goto out_free; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1580 | |
| 1581 | pos = new_ie; |
| 1582 | |
| 1583 | /* copy the nontransmitted SSID */ |
| 1584 | cpy_len = nontrans_ssid[1] + 2; |
| 1585 | memcpy(pos, nontrans_ssid, cpy_len); |
| 1586 | pos += cpy_len; |
| 1587 | /* copy the IEs between SSID and MBSSID */ |
| 1588 | cpy_len = trans_ssid[1] + 2; |
| 1589 | memcpy(pos, (trans_ssid + cpy_len), (mbssid - (trans_ssid + cpy_len))); |
| 1590 | pos += (mbssid - (trans_ssid + cpy_len)); |
| 1591 | /* copy the IEs after MBSSID */ |
| 1592 | cpy_len = mbssid[1] + 2; |
| 1593 | memcpy(pos, mbssid + cpy_len, ((ie + ielen) - (mbssid + cpy_len))); |
| 1594 | |
| 1595 | /* update ie */ |
| 1596 | new_ies->len = new_ie_len; |
| 1597 | new_ies->tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp); |
| 1598 | new_ies->from_beacon = ieee80211_is_beacon(mgmt->frame_control); |
| 1599 | memcpy(new_ies->data, new_ie, new_ie_len); |
| 1600 | if (ieee80211_is_probe_resp(mgmt->frame_control)) { |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1601 | old = rcu_access_pointer(nontrans_bss->proberesp_ies); |
| 1602 | rcu_assign_pointer(nontrans_bss->proberesp_ies, new_ies); |
| 1603 | rcu_assign_pointer(nontrans_bss->ies, new_ies); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1604 | if (old) |
| 1605 | kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head); |
| 1606 | } else { |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1607 | old = rcu_access_pointer(nontrans_bss->beacon_ies); |
| 1608 | rcu_assign_pointer(nontrans_bss->beacon_ies, new_ies); |
| 1609 | rcu_assign_pointer(nontrans_bss->ies, new_ies); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1610 | if (old) |
| 1611 | kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head); |
| 1612 | } |
Sara Sharon | bede8d2 | 2019-01-30 08:48:21 +0200 | [diff] [blame] | 1613 | |
| 1614 | out_free: |
| 1615 | kfree(new_ie); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | /* cfg80211_inform_bss_width_frame helper */ |
| 1619 | static struct cfg80211_bss * |
| 1620 | cfg80211_inform_single_bss_frame_data(struct wiphy *wiphy, |
| 1621 | struct cfg80211_inform_bss *data, |
| 1622 | struct ieee80211_mgmt *mgmt, size_t len, |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1623 | struct cfg80211_non_tx_bss *non_tx_data, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1624 | gfp_t gfp) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1625 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1626 | struct cfg80211_internal_bss tmp = {}, *res; |
| 1627 | struct cfg80211_bss_ies *ies; |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 1628 | struct ieee80211_channel *channel; |
Emmanuel Grumbach | 67af981 | 2014-05-18 10:15:24 +0300 | [diff] [blame] | 1629 | bool signal_valid; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1630 | size_t ielen = len - offsetof(struct ieee80211_mgmt, |
| 1631 | u.probe_resp.variable); |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 1632 | int bss_type; |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 1633 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1634 | BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) != |
| 1635 | offsetof(struct ieee80211_mgmt, u.beacon.variable)); |
| 1636 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1637 | trace_cfg80211_inform_bss_frame(wiphy, data, mgmt, len); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 1638 | |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 1639 | if (WARN_ON(!mgmt)) |
| 1640 | return NULL; |
| 1641 | |
| 1642 | if (WARN_ON(!wiphy)) |
| 1643 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1644 | |
Sujith | 22fe88d | 2010-05-13 10:34:08 +0530 | [diff] [blame] | 1645 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1646 | (data->signal < 0 || data->signal > 100))) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1647 | return NULL; |
| 1648 | |
Mariusz Kozlowski | bef9bac | 2011-03-26 19:26:55 +0100 | [diff] [blame] | 1649 | if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable))) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1650 | return NULL; |
| 1651 | |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1652 | channel = cfg80211_get_bss_channel(wiphy, mgmt->u.beacon.variable, |
Jouni Malinen | 119f94a | 2018-09-05 18:52:22 +0300 | [diff] [blame] | 1653 | ielen, data->chan, data->scan_width); |
Johannes Berg | 0172bb7 | 2012-11-23 14:23:30 +0100 | [diff] [blame] | 1654 | if (!channel) |
| 1655 | return NULL; |
| 1656 | |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 1657 | ies = kzalloc(sizeof(*ies) + ielen, gfp); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1658 | if (!ies) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1659 | return NULL; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1660 | ies->len = ielen; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 1661 | ies->tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 1662 | ies->from_beacon = ieee80211_is_beacon(mgmt->frame_control); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1663 | memcpy(ies->data, mgmt->u.probe_resp.variable, ielen); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1664 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1665 | if (ieee80211_is_probe_resp(mgmt->frame_control)) |
| 1666 | rcu_assign_pointer(tmp.pub.proberesp_ies, ies); |
| 1667 | else |
| 1668 | rcu_assign_pointer(tmp.pub.beacon_ies, ies); |
| 1669 | rcu_assign_pointer(tmp.pub.ies, ies); |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 1670 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1671 | memcpy(tmp.pub.bssid, mgmt->bssid, ETH_ALEN); |
| 1672 | tmp.pub.channel = channel; |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1673 | tmp.pub.scan_width = data->scan_width; |
| 1674 | tmp.pub.signal = data->signal; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1675 | tmp.pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int); |
| 1676 | tmp.pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info); |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1677 | tmp.ts_boottime = data->boottime_ns; |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 1678 | tmp.parent_tsf = data->parent_tsf; |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 1679 | tmp.pub.chains = data->chains; |
| 1680 | memcpy(tmp.pub.chain_signal, data->chain_signal, IEEE80211_MAX_CHAINS); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 1681 | ether_addr_copy(tmp.parent_bssid, data->parent_bssid); |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1682 | if (non_tx_data) { |
| 1683 | tmp.pub.transmitted_bss = non_tx_data->tx_bss; |
| 1684 | tmp.pub.bssid_index = non_tx_data->bssid_index; |
| 1685 | tmp.pub.max_bssid_indicator = non_tx_data->max_bssid_indicator; |
| 1686 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1687 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1688 | signal_valid = abs(data->chan->center_freq - channel->center_freq) <= |
Emmanuel Grumbach | 67af981 | 2014-05-18 10:15:24 +0300 | [diff] [blame] | 1689 | wiphy->max_adj_channel_rssi_comp; |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1690 | res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1691 | if (!res) |
| 1692 | return NULL; |
| 1693 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1694 | if (channel->band == NL80211_BAND_60GHZ) { |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 1695 | bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK; |
| 1696 | if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP || |
| 1697 | bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS) |
| 1698 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 1699 | } else { |
| 1700 | if (res->pub.capability & WLAN_CAPABILITY_ESS) |
| 1701 | regulatory_hint_found_beacon(wiphy, channel, gfp); |
| 1702 | } |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1703 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 1704 | trace_cfg80211_return_bss(&res->pub); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1705 | /* cfg80211_bss_update gives us a referenced result */ |
| 1706 | return &res->pub; |
| 1707 | } |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1708 | |
| 1709 | struct cfg80211_bss * |
| 1710 | cfg80211_inform_bss_frame_data(struct wiphy *wiphy, |
| 1711 | struct cfg80211_inform_bss *data, |
| 1712 | struct ieee80211_mgmt *mgmt, size_t len, |
| 1713 | gfp_t gfp) |
| 1714 | { |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1715 | struct cfg80211_bss *res, *tmp_bss; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1716 | const u8 *ie = mgmt->u.probe_resp.variable; |
| 1717 | const struct cfg80211_bss_ies *ies1, *ies2; |
| 1718 | size_t ielen = len - offsetof(struct ieee80211_mgmt, |
| 1719 | u.probe_resp.variable); |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1720 | struct cfg80211_non_tx_bss non_tx_data; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1721 | |
| 1722 | res = cfg80211_inform_single_bss_frame_data(wiphy, data, mgmt, |
| 1723 | len, NULL, gfp); |
Sara Sharon | 213ed57 | 2019-01-16 23:02:03 +0200 | [diff] [blame] | 1724 | if (!res || !wiphy->support_mbssid || |
| 1725 | !cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen)) |
| 1726 | return res; |
| 1727 | if (wiphy->support_only_he_mbssid && |
| 1728 | !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ie, ielen)) |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1729 | return res; |
| 1730 | |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1731 | non_tx_data.tx_bss = res; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1732 | /* process each non-transmitting bss */ |
Sara Sharon | 0cd01ef | 2019-01-22 09:50:50 +0200 | [diff] [blame] | 1733 | cfg80211_parse_mbssid_frame_data(wiphy, data, mgmt, len, |
| 1734 | &non_tx_data, gfp); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1735 | |
| 1736 | /* check if the res has other nontransmitting bss which is not |
| 1737 | * in MBSSID IE |
| 1738 | */ |
| 1739 | ies1 = rcu_access_pointer(res->ies); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1740 | |
| 1741 | /* go through nontrans_list, if the timestamp of the BSS is |
| 1742 | * earlier than the timestamp of the transmitting BSS then |
| 1743 | * update it |
| 1744 | */ |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1745 | list_for_each_entry(tmp_bss, &res->nontrans_list, |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1746 | nontrans_list) { |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1747 | ies2 = rcu_access_pointer(tmp_bss->ies); |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1748 | if (ies2->tsf < ies1->tsf) |
| 1749 | cfg80211_update_notlisted_nontrans(wiphy, tmp_bss, |
| 1750 | mgmt, len, gfp); |
| 1751 | } |
| 1752 | |
| 1753 | return res; |
| 1754 | } |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 1755 | EXPORT_SYMBOL(cfg80211_inform_bss_frame_data); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1756 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 1757 | void cfg80211_ref_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
Johannes Berg | 4c0c0b7 | 2012-01-20 13:55:26 +0100 | [diff] [blame] | 1758 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1759 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 4c0c0b7 | 2012-01-20 13:55:26 +0100 | [diff] [blame] | 1760 | struct cfg80211_internal_bss *bss; |
| 1761 | |
| 1762 | if (!pub) |
| 1763 | return; |
| 1764 | |
| 1765 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1766 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1767 | spin_lock_bh(&rdev->bss_lock); |
| 1768 | bss_ref_get(rdev, bss); |
| 1769 | spin_unlock_bh(&rdev->bss_lock); |
Johannes Berg | 4c0c0b7 | 2012-01-20 13:55:26 +0100 | [diff] [blame] | 1770 | } |
| 1771 | EXPORT_SYMBOL(cfg80211_ref_bss); |
| 1772 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 1773 | void cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1774 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1775 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1776 | struct cfg80211_internal_bss *bss; |
| 1777 | |
| 1778 | if (!pub) |
| 1779 | return; |
| 1780 | |
| 1781 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
Johannes Berg | 776b358 | 2013-02-01 02:06:18 +0100 | [diff] [blame] | 1782 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1783 | spin_lock_bh(&rdev->bss_lock); |
| 1784 | bss_ref_put(rdev, bss); |
| 1785 | spin_unlock_bh(&rdev->bss_lock); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1786 | } |
| 1787 | EXPORT_SYMBOL(cfg80211_put_bss); |
| 1788 | |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 1789 | void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
| 1790 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1791 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1792 | struct cfg80211_internal_bss *bss, *tmp1; |
| 1793 | struct cfg80211_bss *nontrans_bss, *tmp; |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 1794 | |
| 1795 | if (WARN_ON(!pub)) |
| 1796 | return; |
| 1797 | |
| 1798 | bss = container_of(pub, struct cfg80211_internal_bss, pub); |
| 1799 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1800 | spin_lock_bh(&rdev->bss_lock); |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1801 | if (list_empty(&bss->list)) |
| 1802 | goto out; |
Peng Xu | 0b8fb82 | 2019-01-21 12:14:57 +0200 | [diff] [blame] | 1803 | |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1804 | list_for_each_entry_safe(nontrans_bss, tmp, |
| 1805 | &pub->nontrans_list, |
| 1806 | nontrans_list) { |
| 1807 | tmp1 = container_of(nontrans_bss, |
| 1808 | struct cfg80211_internal_bss, pub); |
| 1809 | if (__cfg80211_unlink_bss(rdev, tmp1)) |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1810 | rdev->bss_generation++; |
Johannes Berg | 3207390 | 2010-10-06 21:18:04 +0200 | [diff] [blame] | 1811 | } |
Sara Sharon | 7011ba5 | 2019-01-21 12:25:59 +0200 | [diff] [blame] | 1812 | |
| 1813 | if (__cfg80211_unlink_bss(rdev, bss)) |
| 1814 | rdev->bss_generation++; |
| 1815 | out: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1816 | spin_unlock_bh(&rdev->bss_lock); |
Johannes Berg | d491af1 | 2009-02-10 21:25:58 +0100 | [diff] [blame] | 1817 | } |
| 1818 | EXPORT_SYMBOL(cfg80211_unlink_bss); |
| 1819 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1820 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 9f419f3 | 2013-05-08 21:34:22 +0200 | [diff] [blame] | 1821 | static struct cfg80211_registered_device * |
| 1822 | cfg80211_get_dev_from_ifindex(struct net *net, int ifindex) |
| 1823 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1824 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 9f419f3 | 2013-05-08 21:34:22 +0200 | [diff] [blame] | 1825 | struct net_device *dev; |
| 1826 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1827 | ASSERT_RTNL(); |
| 1828 | |
Johannes Berg | 9f419f3 | 2013-05-08 21:34:22 +0200 | [diff] [blame] | 1829 | dev = dev_get_by_index(net, ifindex); |
| 1830 | if (!dev) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1831 | return ERR_PTR(-ENODEV); |
| 1832 | if (dev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1833 | rdev = wiphy_to_rdev(dev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1834 | else |
Johannes Berg | 9f419f3 | 2013-05-08 21:34:22 +0200 | [diff] [blame] | 1835 | rdev = ERR_PTR(-ENODEV); |
| 1836 | dev_put(dev); |
Johannes Berg | 9f419f3 | 2013-05-08 21:34:22 +0200 | [diff] [blame] | 1837 | return rdev; |
| 1838 | } |
| 1839 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1840 | int cfg80211_wext_siwscan(struct net_device *dev, |
| 1841 | struct iw_request_info *info, |
| 1842 | union iwreq_data *wrqu, char *extra) |
| 1843 | { |
| 1844 | struct cfg80211_registered_device *rdev; |
| 1845 | struct wiphy *wiphy; |
| 1846 | struct iw_scan_req *wreq = NULL; |
Johannes Berg | 65486c8 | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1847 | struct cfg80211_scan_request *creq = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1848 | int i, err, n_channels = 0; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1849 | enum nl80211_band band; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1850 | |
| 1851 | if (!netif_running(dev)) |
| 1852 | return -ENETDOWN; |
| 1853 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1854 | if (wrqu->data.length == sizeof(struct iw_scan_req)) |
| 1855 | wreq = (struct iw_scan_req *)extra; |
| 1856 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1857 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1858 | |
| 1859 | if (IS_ERR(rdev)) |
| 1860 | return PTR_ERR(rdev); |
| 1861 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 1862 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1863 | err = -EBUSY; |
| 1864 | goto out; |
| 1865 | } |
| 1866 | |
| 1867 | wiphy = &rdev->wiphy; |
| 1868 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1869 | /* Determine number of channels, needed to allocate creq */ |
| 1870 | if (wreq && wreq->num_channels) |
| 1871 | n_channels = wreq->num_channels; |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 1872 | else |
| 1873 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1874 | |
| 1875 | creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) + |
| 1876 | n_channels * sizeof(void *), |
| 1877 | GFP_ATOMIC); |
| 1878 | if (!creq) { |
| 1879 | err = -ENOMEM; |
| 1880 | goto out; |
| 1881 | } |
| 1882 | |
| 1883 | creq->wiphy = wiphy; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 1884 | creq->wdev = dev->ieee80211_ptr; |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 1885 | /* SSIDs come after channels */ |
| 1886 | creq->ssids = (void *)&creq->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1887 | creq->n_channels = n_channels; |
| 1888 | creq->n_ssids = 1; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 1889 | creq->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1890 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1891 | /* translate "Scan on frequencies" request */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1892 | i = 0; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1893 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1894 | int j; |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 1895 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1896 | if (!wiphy->bands[band]) |
| 1897 | continue; |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 1898 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1899 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 1900 | /* ignore disabled channels */ |
| 1901 | if (wiphy->bands[band]->channels[j].flags & |
| 1902 | IEEE80211_CHAN_DISABLED) |
| 1903 | continue; |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1904 | |
| 1905 | /* If we have a wireless request structure and the |
| 1906 | * wireless request specifies frequencies, then search |
| 1907 | * for the matching hardware channel. |
| 1908 | */ |
| 1909 | if (wreq && wreq->num_channels) { |
| 1910 | int k; |
| 1911 | int wiphy_freq = wiphy->bands[band]->channels[j].center_freq; |
| 1912 | for (k = 0; k < wreq->num_channels; k++) { |
Zhao, Gang | 96998e3 | 2014-04-09 09:28:06 +0800 | [diff] [blame] | 1913 | struct iw_freq *freq = |
| 1914 | &wreq->channel_list[k]; |
| 1915 | int wext_freq = |
| 1916 | cfg80211_wext_freq(freq); |
| 1917 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1918 | if (wext_freq == wiphy_freq) |
| 1919 | goto wext_freq_found; |
| 1920 | } |
| 1921 | goto wext_freq_not_found; |
| 1922 | } |
| 1923 | |
| 1924 | wext_freq_found: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1925 | creq->channels[i] = &wiphy->bands[band]->channels[j]; |
| 1926 | i++; |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1927 | wext_freq_not_found: ; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1928 | } |
| 1929 | } |
Holger Schurig | 8862dc5 | 2009-09-11 10:13:55 +0200 | [diff] [blame] | 1930 | /* No channels found? */ |
| 1931 | if (!i) { |
| 1932 | err = -EINVAL; |
| 1933 | goto out; |
| 1934 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1935 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1936 | /* Set real number of channels specified in creq->channels[] */ |
| 1937 | creq->n_channels = i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1938 | |
Holger Schurig | b2e3abd | 2009-09-09 13:09:54 +0200 | [diff] [blame] | 1939 | /* translate "Scan for SSID" request */ |
| 1940 | if (wreq) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1941 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Johannes Berg | 65486c8 | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1942 | if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) { |
| 1943 | err = -EINVAL; |
| 1944 | goto out; |
| 1945 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1946 | memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len); |
| 1947 | creq->ssids[0].ssid_len = wreq->essid_len; |
| 1948 | } |
| 1949 | if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE) |
| 1950 | creq->n_ssids = 0; |
| 1951 | } |
| 1952 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1953 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 1954 | if (wiphy->bands[i]) |
| 1955 | creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 1956 | |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 1957 | eth_broadcast_addr(creq->bssid); |
| 1958 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1959 | rdev->scan_req = creq; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1960 | err = rdev_scan(rdev, creq); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1961 | if (err) { |
| 1962 | rdev->scan_req = NULL; |
Johannes Berg | 65486c8 | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1963 | /* creq will be freed below */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1964 | } else { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 1965 | nl80211_send_scan_start(rdev, dev->ieee80211_ptr); |
Johannes Berg | 65486c8 | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1966 | /* creq now owned by driver */ |
| 1967 | creq = NULL; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1968 | dev_hold(dev); |
| 1969 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1970 | out: |
Johannes Berg | 65486c8 | 2009-12-23 15:33:35 +0100 | [diff] [blame] | 1971 | kfree(creq); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1972 | return err; |
| 1973 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 1974 | EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1975 | |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 1976 | static char *ieee80211_scan_add_ies(struct iw_request_info *info, |
| 1977 | const struct cfg80211_bss_ies *ies, |
| 1978 | char *current_ev, char *end_buf) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1979 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1980 | const u8 *pos, *end, *next; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1981 | struct iw_event iwe; |
| 1982 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1983 | if (!ies) |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 1984 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1985 | |
| 1986 | /* |
| 1987 | * If needed, fragment the IEs buffer (at IE boundaries) into short |
| 1988 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. |
| 1989 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 1990 | pos = ies->data; |
| 1991 | end = pos + ies->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1992 | |
| 1993 | while (end - pos > IW_GENERIC_IE_MAX) { |
| 1994 | next = pos + 2 + pos[1]; |
| 1995 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) |
| 1996 | next = next + 2 + next[1]; |
| 1997 | |
| 1998 | memset(&iwe, 0, sizeof(iwe)); |
| 1999 | iwe.cmd = IWEVGENIE; |
| 2000 | iwe.u.data.length = next - pos; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2001 | current_ev = iwe_stream_add_point_check(info, current_ev, |
| 2002 | end_buf, &iwe, |
| 2003 | (void *)pos); |
| 2004 | if (IS_ERR(current_ev)) |
| 2005 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2006 | pos = next; |
| 2007 | } |
| 2008 | |
| 2009 | if (end > pos) { |
| 2010 | memset(&iwe, 0, sizeof(iwe)); |
| 2011 | iwe.cmd = IWEVGENIE; |
| 2012 | iwe.u.data.length = end - pos; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2013 | current_ev = iwe_stream_add_point_check(info, current_ev, |
| 2014 | end_buf, &iwe, |
| 2015 | (void *)pos); |
| 2016 | if (IS_ERR(current_ev)) |
| 2017 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2018 | } |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2019 | |
| 2020 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2021 | } |
| 2022 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2023 | static char * |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 2024 | ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info, |
| 2025 | struct cfg80211_internal_bss *bss, char *current_ev, |
| 2026 | char *end_buf) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2027 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2028 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2029 | struct iw_event iwe; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2030 | const u8 *ie; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2031 | u8 buf[50]; |
| 2032 | u8 *cfg, *p, *tmp; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2033 | int rem, i, sig; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2034 | bool ismesh = false; |
| 2035 | |
| 2036 | memset(&iwe, 0, sizeof(iwe)); |
| 2037 | iwe.cmd = SIOCGIWAP; |
| 2038 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 2039 | memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2040 | current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe, |
| 2041 | IW_EV_ADDR_LEN); |
| 2042 | if (IS_ERR(current_ev)) |
| 2043 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2044 | |
| 2045 | memset(&iwe, 0, sizeof(iwe)); |
| 2046 | iwe.cmd = SIOCGIWFREQ; |
| 2047 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq); |
| 2048 | iwe.u.freq.e = 0; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2049 | current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe, |
| 2050 | IW_EV_FREQ_LEN); |
| 2051 | if (IS_ERR(current_ev)) |
| 2052 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2053 | |
| 2054 | memset(&iwe, 0, sizeof(iwe)); |
| 2055 | iwe.cmd = SIOCGIWFREQ; |
| 2056 | iwe.u.freq.m = bss->pub.channel->center_freq; |
| 2057 | iwe.u.freq.e = 6; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2058 | current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe, |
| 2059 | IW_EV_FREQ_LEN); |
| 2060 | if (IS_ERR(current_ev)) |
| 2061 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2062 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 2063 | if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2064 | memset(&iwe, 0, sizeof(iwe)); |
| 2065 | iwe.cmd = IWEVQUAL; |
| 2066 | iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED | |
| 2067 | IW_QUAL_NOISE_INVALID | |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 2068 | IW_QUAL_QUAL_UPDATED; |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 2069 | switch (wiphy->signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2070 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 2071 | sig = bss->pub.signal / 100; |
| 2072 | iwe.u.qual.level = sig; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2073 | iwe.u.qual.updated |= IW_QUAL_DBM; |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 2074 | if (sig < -110) /* rather bad */ |
| 2075 | sig = -110; |
| 2076 | else if (sig > -40) /* perfect */ |
| 2077 | sig = -40; |
| 2078 | /* will give a range of 0 .. 70 */ |
| 2079 | iwe.u.qual.qual = sig + 110; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2080 | break; |
| 2081 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 2082 | iwe.u.qual.level = bss->pub.signal; |
Johannes Berg | a77b855 | 2009-02-18 18:27:22 +0100 | [diff] [blame] | 2083 | /* will give range 0 .. 100 */ |
| 2084 | iwe.u.qual.qual = bss->pub.signal; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2085 | break; |
| 2086 | default: |
| 2087 | /* not reached */ |
| 2088 | break; |
| 2089 | } |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2090 | current_ev = iwe_stream_add_event_check(info, current_ev, |
| 2091 | end_buf, &iwe, |
| 2092 | IW_EV_QUAL_LEN); |
| 2093 | if (IS_ERR(current_ev)) |
| 2094 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | memset(&iwe, 0, sizeof(iwe)); |
| 2098 | iwe.cmd = SIOCGIWENCODE; |
| 2099 | if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY) |
| 2100 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 2101 | else |
| 2102 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 2103 | iwe.u.data.length = 0; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2104 | current_ev = iwe_stream_add_point_check(info, current_ev, end_buf, |
| 2105 | &iwe, ""); |
| 2106 | if (IS_ERR(current_ev)) |
| 2107 | return current_ev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2108 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2109 | rcu_read_lock(); |
| 2110 | ies = rcu_dereference(bss->pub.ies); |
Johannes Berg | 83c7aa1 | 2013-02-05 16:51:29 +0100 | [diff] [blame] | 2111 | rem = ies->len; |
| 2112 | ie = ies->data; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2113 | |
Johannes Berg | 83c7aa1 | 2013-02-05 16:51:29 +0100 | [diff] [blame] | 2114 | while (rem >= 2) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2115 | /* invalid data */ |
| 2116 | if (ie[1] > rem - 2) |
| 2117 | break; |
| 2118 | |
| 2119 | switch (ie[0]) { |
| 2120 | case WLAN_EID_SSID: |
| 2121 | memset(&iwe, 0, sizeof(iwe)); |
| 2122 | iwe.cmd = SIOCGIWESSID; |
| 2123 | iwe.u.data.length = ie[1]; |
| 2124 | iwe.u.data.flags = 1; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2125 | current_ev = iwe_stream_add_point_check(info, |
| 2126 | current_ev, |
| 2127 | end_buf, &iwe, |
| 2128 | (u8 *)ie + 2); |
| 2129 | if (IS_ERR(current_ev)) |
| 2130 | goto unlock; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2131 | break; |
| 2132 | case WLAN_EID_MESH_ID: |
| 2133 | memset(&iwe, 0, sizeof(iwe)); |
| 2134 | iwe.cmd = SIOCGIWESSID; |
| 2135 | iwe.u.data.length = ie[1]; |
| 2136 | iwe.u.data.flags = 1; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2137 | current_ev = iwe_stream_add_point_check(info, |
| 2138 | current_ev, |
| 2139 | end_buf, &iwe, |
| 2140 | (u8 *)ie + 2); |
| 2141 | if (IS_ERR(current_ev)) |
| 2142 | goto unlock; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2143 | break; |
| 2144 | case WLAN_EID_MESH_CONFIG: |
| 2145 | ismesh = true; |
Rui Paulo | 136cfa2 | 2009-11-18 18:40:00 +0000 | [diff] [blame] | 2146 | if (ie[1] != sizeof(struct ieee80211_meshconf_ie)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2147 | break; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2148 | cfg = (u8 *)ie + 2; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2149 | memset(&iwe, 0, sizeof(iwe)); |
| 2150 | iwe.cmd = IWEVCUSTOM; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 2151 | sprintf(buf, "Mesh Network Path Selection Protocol ID: " |
| 2152 | "0x%02X", cfg[0]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2153 | iwe.u.data.length = strlen(buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2154 | current_ev = iwe_stream_add_point_check(info, |
| 2155 | current_ev, |
| 2156 | end_buf, |
| 2157 | &iwe, buf); |
| 2158 | if (IS_ERR(current_ev)) |
| 2159 | goto unlock; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 2160 | sprintf(buf, "Path Selection Metric ID: 0x%02X", |
| 2161 | cfg[1]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2162 | iwe.u.data.length = strlen(buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2163 | current_ev = iwe_stream_add_point_check(info, |
| 2164 | current_ev, |
| 2165 | end_buf, |
| 2166 | &iwe, buf); |
| 2167 | if (IS_ERR(current_ev)) |
| 2168 | goto unlock; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 2169 | sprintf(buf, "Congestion Control Mode ID: 0x%02X", |
| 2170 | cfg[2]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2171 | iwe.u.data.length = strlen(buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2172 | current_ev = iwe_stream_add_point_check(info, |
| 2173 | current_ev, |
| 2174 | end_buf, |
| 2175 | &iwe, buf); |
| 2176 | if (IS_ERR(current_ev)) |
| 2177 | goto unlock; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 2178 | sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2179 | iwe.u.data.length = strlen(buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2180 | current_ev = iwe_stream_add_point_check(info, |
| 2181 | current_ev, |
| 2182 | end_buf, |
| 2183 | &iwe, buf); |
| 2184 | if (IS_ERR(current_ev)) |
| 2185 | goto unlock; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 2186 | sprintf(buf, "Authentication ID: 0x%02X", cfg[4]); |
| 2187 | iwe.u.data.length = strlen(buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2188 | current_ev = iwe_stream_add_point_check(info, |
| 2189 | current_ev, |
| 2190 | end_buf, |
| 2191 | &iwe, buf); |
| 2192 | if (IS_ERR(current_ev)) |
| 2193 | goto unlock; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 2194 | sprintf(buf, "Formation Info: 0x%02X", cfg[5]); |
| 2195 | iwe.u.data.length = strlen(buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2196 | current_ev = iwe_stream_add_point_check(info, |
| 2197 | current_ev, |
| 2198 | end_buf, |
| 2199 | &iwe, buf); |
| 2200 | if (IS_ERR(current_ev)) |
| 2201 | goto unlock; |
Rui Paulo | 76aa5e7 | 2009-11-18 18:22:59 +0000 | [diff] [blame] | 2202 | sprintf(buf, "Capabilities: 0x%02X", cfg[6]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2203 | iwe.u.data.length = strlen(buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2204 | current_ev = iwe_stream_add_point_check(info, |
| 2205 | current_ev, |
| 2206 | end_buf, |
| 2207 | &iwe, buf); |
| 2208 | if (IS_ERR(current_ev)) |
| 2209 | goto unlock; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2210 | break; |
| 2211 | case WLAN_EID_SUPP_RATES: |
| 2212 | case WLAN_EID_EXT_SUPP_RATES: |
| 2213 | /* display all supported rates in readable format */ |
| 2214 | p = current_ev + iwe_stream_lcp_len(info); |
| 2215 | |
| 2216 | memset(&iwe, 0, sizeof(iwe)); |
| 2217 | iwe.cmd = SIOCGIWRATE; |
| 2218 | /* Those two flags are ignored... */ |
| 2219 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; |
| 2220 | |
| 2221 | for (i = 0; i < ie[1]; i++) { |
| 2222 | iwe.u.bitrate.value = |
| 2223 | ((ie[i + 2] & 0x7f) * 500000); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2224 | tmp = p; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2225 | p = iwe_stream_add_value(info, current_ev, p, |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2226 | end_buf, &iwe, |
| 2227 | IW_EV_PARAM_LEN); |
| 2228 | if (p == tmp) { |
| 2229 | current_ev = ERR_PTR(-E2BIG); |
| 2230 | goto unlock; |
| 2231 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2232 | } |
| 2233 | current_ev = p; |
| 2234 | break; |
| 2235 | } |
| 2236 | rem -= ie[1] + 2; |
| 2237 | ie += ie[1] + 2; |
| 2238 | } |
| 2239 | |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 2240 | if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) || |
| 2241 | ismesh) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2242 | memset(&iwe, 0, sizeof(iwe)); |
| 2243 | iwe.cmd = SIOCGIWMODE; |
| 2244 | if (ismesh) |
| 2245 | iwe.u.mode = IW_MODE_MESH; |
| 2246 | else if (bss->pub.capability & WLAN_CAPABILITY_ESS) |
| 2247 | iwe.u.mode = IW_MODE_MASTER; |
| 2248 | else |
| 2249 | iwe.u.mode = IW_MODE_ADHOC; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2250 | current_ev = iwe_stream_add_event_check(info, current_ev, |
| 2251 | end_buf, &iwe, |
| 2252 | IW_EV_UINT_LEN); |
| 2253 | if (IS_ERR(current_ev)) |
| 2254 | goto unlock; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2255 | } |
| 2256 | |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2257 | memset(&iwe, 0, sizeof(iwe)); |
| 2258 | iwe.cmd = IWEVCUSTOM; |
| 2259 | sprintf(buf, "tsf=%016llx", (unsigned long long)(ies->tsf)); |
| 2260 | iwe.u.data.length = strlen(buf); |
| 2261 | current_ev = iwe_stream_add_point_check(info, current_ev, end_buf, |
| 2262 | &iwe, buf); |
| 2263 | if (IS_ERR(current_ev)) |
| 2264 | goto unlock; |
| 2265 | memset(&iwe, 0, sizeof(iwe)); |
| 2266 | iwe.cmd = IWEVCUSTOM; |
| 2267 | sprintf(buf, " Last beacon: %ums ago", |
| 2268 | elapsed_jiffies_msecs(bss->ts)); |
| 2269 | iwe.u.data.length = strlen(buf); |
| 2270 | current_ev = iwe_stream_add_point_check(info, current_ev, |
| 2271 | end_buf, &iwe, buf); |
| 2272 | if (IS_ERR(current_ev)) |
| 2273 | goto unlock; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2274 | |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2275 | current_ev = ieee80211_scan_add_ies(info, ies, current_ev, end_buf); |
| 2276 | |
| 2277 | unlock: |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2278 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2279 | return current_ev; |
| 2280 | } |
| 2281 | |
| 2282 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2283 | static int ieee80211_scan_results(struct cfg80211_registered_device *rdev, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2284 | struct iw_request_info *info, |
| 2285 | char *buf, size_t len) |
| 2286 | { |
| 2287 | char *current_ev = buf; |
| 2288 | char *end_buf = buf + len; |
| 2289 | struct cfg80211_internal_bss *bss; |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2290 | int err = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2291 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2292 | spin_lock_bh(&rdev->bss_lock); |
| 2293 | cfg80211_bss_expire(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2294 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2295 | list_for_each_entry(bss, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2296 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2297 | err = -E2BIG; |
| 2298 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2299 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2300 | current_ev = ieee80211_bss(&rdev->wiphy, info, bss, |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 2301 | current_ev, end_buf); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2302 | if (IS_ERR(current_ev)) { |
| 2303 | err = PTR_ERR(current_ev); |
| 2304 | break; |
| 2305 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2306 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2307 | spin_unlock_bh(&rdev->bss_lock); |
James Minor | 76a70e9 | 2015-02-24 12:58:20 -0600 | [diff] [blame] | 2308 | |
| 2309 | if (err) |
| 2310 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2311 | return current_ev - buf; |
| 2312 | } |
| 2313 | |
| 2314 | |
| 2315 | int cfg80211_wext_giwscan(struct net_device *dev, |
| 2316 | struct iw_request_info *info, |
| 2317 | struct iw_point *data, char *extra) |
| 2318 | { |
| 2319 | struct cfg80211_registered_device *rdev; |
| 2320 | int res; |
| 2321 | |
| 2322 | if (!netif_running(dev)) |
| 2323 | return -ENETDOWN; |
| 2324 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2325 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2326 | |
| 2327 | if (IS_ERR(rdev)) |
| 2328 | return PTR_ERR(rdev); |
| 2329 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 2330 | if (rdev->scan_req || rdev->scan_msg) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2331 | return -EAGAIN; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2332 | |
| 2333 | res = ieee80211_scan_results(rdev, info, extra, data->length); |
| 2334 | data->length = 0; |
| 2335 | if (res >= 0) { |
| 2336 | data->length = res; |
| 2337 | res = 0; |
| 2338 | } |
| 2339 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2340 | return res; |
| 2341 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 2342 | EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2343 | #endif |