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