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