Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSS table |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3 | * Copyright (c) 2009-2019, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
| 10 | |
| 11 | #include "utils/common.h" |
| 12 | #include "utils/eloop.h" |
| 13 | #include "common/ieee802_11_defs.h" |
| 14 | #include "drivers/driver.h" |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 15 | #include "eap_peer/eap.h" |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 16 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 17 | #include "wpa_supplicant_i.h" |
| 18 | #include "config.h" |
| 19 | #include "notify.h" |
| 20 | #include "scan.h" |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 21 | #include "bssid_ignore.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include "bss.h" |
| 23 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 24 | static void wpa_bss_set_hessid(struct wpa_bss *bss) |
| 25 | { |
| 26 | #ifdef CONFIG_INTERWORKING |
| 27 | const u8 *ie = wpa_bss_get_ie(bss, WLAN_EID_INTERWORKING); |
| 28 | if (ie == NULL || (ie[1] != 7 && ie[1] != 9)) { |
| 29 | os_memset(bss->hessid, 0, ETH_ALEN); |
| 30 | return; |
| 31 | } |
| 32 | if (ie[1] == 7) |
| 33 | os_memcpy(bss->hessid, ie + 3, ETH_ALEN); |
| 34 | else |
| 35 | os_memcpy(bss->hessid, ie + 5, ETH_ALEN); |
| 36 | #endif /* CONFIG_INTERWORKING */ |
| 37 | } |
| 38 | |
| 39 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 40 | /** |
| 41 | * wpa_bss_anqp_alloc - Allocate ANQP data structure for a BSS entry |
| 42 | * Returns: Allocated ANQP data structure or %NULL on failure |
| 43 | * |
| 44 | * The allocated ANQP data structure has its users count set to 1. It may be |
| 45 | * shared by multiple BSS entries and each shared entry is freed with |
| 46 | * wpa_bss_anqp_free(). |
| 47 | */ |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 48 | struct wpa_bss_anqp * wpa_bss_anqp_alloc(void) |
| 49 | { |
| 50 | struct wpa_bss_anqp *anqp; |
| 51 | anqp = os_zalloc(sizeof(*anqp)); |
| 52 | if (anqp == NULL) |
| 53 | return NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 54 | #ifdef CONFIG_INTERWORKING |
| 55 | dl_list_init(&anqp->anqp_elems); |
| 56 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 57 | anqp->users = 1; |
| 58 | return anqp; |
| 59 | } |
| 60 | |
| 61 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 62 | /** |
| 63 | * wpa_bss_anqp_clone - Clone an ANQP data structure |
| 64 | * @anqp: ANQP data structure from wpa_bss_anqp_alloc() |
| 65 | * Returns: Cloned ANQP data structure or %NULL on failure |
| 66 | */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 67 | static struct wpa_bss_anqp * wpa_bss_anqp_clone(struct wpa_bss_anqp *anqp) |
| 68 | { |
| 69 | struct wpa_bss_anqp *n; |
| 70 | |
| 71 | n = os_zalloc(sizeof(*n)); |
| 72 | if (n == NULL) |
| 73 | return NULL; |
| 74 | |
| 75 | #define ANQP_DUP(f) if (anqp->f) n->f = wpabuf_dup(anqp->f) |
| 76 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 77 | dl_list_init(&n->anqp_elems); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 78 | ANQP_DUP(capability_list); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 79 | ANQP_DUP(venue_name); |
| 80 | ANQP_DUP(network_auth_type); |
| 81 | ANQP_DUP(roaming_consortium); |
| 82 | ANQP_DUP(ip_addr_type_availability); |
| 83 | ANQP_DUP(nai_realm); |
| 84 | ANQP_DUP(anqp_3gpp); |
| 85 | ANQP_DUP(domain_name); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 86 | ANQP_DUP(fils_realm_info); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 87 | #endif /* CONFIG_INTERWORKING */ |
| 88 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 89 | ANQP_DUP(hs20_capability_list); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 90 | ANQP_DUP(hs20_operator_friendly_name); |
| 91 | ANQP_DUP(hs20_wan_metrics); |
| 92 | ANQP_DUP(hs20_connection_capability); |
| 93 | ANQP_DUP(hs20_operating_class); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 94 | ANQP_DUP(hs20_osu_providers_list); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 95 | ANQP_DUP(hs20_operator_icon_metadata); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 96 | ANQP_DUP(hs20_osu_providers_nai_list); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 97 | #endif /* CONFIG_HS20 */ |
| 98 | #undef ANQP_DUP |
| 99 | |
| 100 | return n; |
| 101 | } |
| 102 | |
| 103 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 104 | /** |
| 105 | * wpa_bss_anqp_unshare_alloc - Unshare ANQP data (if shared) in a BSS entry |
| 106 | * @bss: BSS entry |
| 107 | * Returns: 0 on success, -1 on failure |
| 108 | * |
| 109 | * This function ensures the specific BSS entry has an ANQP data structure that |
| 110 | * is not shared with any other BSS entry. |
| 111 | */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 112 | int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss) |
| 113 | { |
| 114 | struct wpa_bss_anqp *anqp; |
| 115 | |
| 116 | if (bss->anqp && bss->anqp->users > 1) { |
| 117 | /* allocated, but shared - clone an unshared copy */ |
| 118 | anqp = wpa_bss_anqp_clone(bss->anqp); |
| 119 | if (anqp == NULL) |
| 120 | return -1; |
| 121 | anqp->users = 1; |
| 122 | bss->anqp->users--; |
| 123 | bss->anqp = anqp; |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | if (bss->anqp) |
| 128 | return 0; /* already allocated and not shared */ |
| 129 | |
| 130 | /* not allocated - allocate a new storage area */ |
| 131 | bss->anqp = wpa_bss_anqp_alloc(); |
| 132 | return bss->anqp ? 0 : -1; |
| 133 | } |
| 134 | |
| 135 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 136 | /** |
| 137 | * wpa_bss_anqp_free - Free an ANQP data structure |
| 138 | * @anqp: ANQP data structure from wpa_bss_anqp_alloc() or wpa_bss_anqp_clone() |
| 139 | */ |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 140 | static void wpa_bss_anqp_free(struct wpa_bss_anqp *anqp) |
| 141 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 142 | #ifdef CONFIG_INTERWORKING |
| 143 | struct wpa_bss_anqp_elem *elem; |
| 144 | #endif /* CONFIG_INTERWORKING */ |
| 145 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 146 | if (anqp == NULL) |
| 147 | return; |
| 148 | |
| 149 | anqp->users--; |
| 150 | if (anqp->users > 0) { |
| 151 | /* Another BSS entry holds a pointer to this ANQP info */ |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 156 | wpabuf_free(anqp->capability_list); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 157 | wpabuf_free(anqp->venue_name); |
| 158 | wpabuf_free(anqp->network_auth_type); |
| 159 | wpabuf_free(anqp->roaming_consortium); |
| 160 | wpabuf_free(anqp->ip_addr_type_availability); |
| 161 | wpabuf_free(anqp->nai_realm); |
| 162 | wpabuf_free(anqp->anqp_3gpp); |
| 163 | wpabuf_free(anqp->domain_name); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 164 | wpabuf_free(anqp->fils_realm_info); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 165 | |
| 166 | while ((elem = dl_list_first(&anqp->anqp_elems, |
| 167 | struct wpa_bss_anqp_elem, list))) { |
| 168 | dl_list_del(&elem->list); |
| 169 | wpabuf_free(elem->payload); |
| 170 | os_free(elem); |
| 171 | } |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 172 | #endif /* CONFIG_INTERWORKING */ |
| 173 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 174 | wpabuf_free(anqp->hs20_capability_list); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 175 | wpabuf_free(anqp->hs20_operator_friendly_name); |
| 176 | wpabuf_free(anqp->hs20_wan_metrics); |
| 177 | wpabuf_free(anqp->hs20_connection_capability); |
| 178 | wpabuf_free(anqp->hs20_operating_class); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 179 | wpabuf_free(anqp->hs20_osu_providers_list); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 180 | wpabuf_free(anqp->hs20_operator_icon_metadata); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 181 | wpabuf_free(anqp->hs20_osu_providers_nai_list); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 182 | #endif /* CONFIG_HS20 */ |
| 183 | |
| 184 | os_free(anqp); |
| 185 | } |
| 186 | |
| 187 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 188 | static struct wpa_connect_work * |
| 189 | wpa_bss_check_pending_connect(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 190 | { |
| 191 | struct wpa_radio_work *work; |
| 192 | struct wpa_connect_work *cwork; |
| 193 | |
| 194 | work = radio_work_pending(wpa_s, "sme-connect"); |
| 195 | if (!work) |
| 196 | work = radio_work_pending(wpa_s, "connect"); |
| 197 | if (!work) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 198 | return NULL; |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 199 | |
| 200 | cwork = work->ctx; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 201 | if (cwork->bss != bss) |
| 202 | return NULL; |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 203 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 204 | return cwork; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | static void wpa_bss_update_pending_connect(struct wpa_connect_work *cwork, |
| 209 | struct wpa_bss *new_bss) |
| 210 | { |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 211 | wpa_printf(MSG_DEBUG, |
| 212 | "Update BSS pointer for the pending connect radio work"); |
| 213 | cwork->bss = new_bss; |
| 214 | if (!new_bss) |
| 215 | cwork->bss_removed = 1; |
| 216 | } |
| 217 | |
| 218 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 219 | void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 220 | const char *reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 221 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 222 | struct wpa_connect_work *cwork; |
| 223 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 224 | if (wpa_s->last_scan_res) { |
| 225 | unsigned int i; |
| 226 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 227 | if (wpa_s->last_scan_res[i] == bss) { |
| 228 | os_memmove(&wpa_s->last_scan_res[i], |
| 229 | &wpa_s->last_scan_res[i + 1], |
| 230 | (wpa_s->last_scan_res_used - i - 1) |
| 231 | * sizeof(struct wpa_bss *)); |
| 232 | wpa_s->last_scan_res_used--; |
| 233 | break; |
| 234 | } |
| 235 | } |
| 236 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 237 | cwork = wpa_bss_check_pending_connect(wpa_s, bss); |
| 238 | if (cwork) |
| 239 | wpa_bss_update_pending_connect(cwork, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 240 | dl_list_del(&bss->list); |
| 241 | dl_list_del(&bss->list_id); |
| 242 | wpa_s->num_bss--; |
| 243 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Remove id %u BSSID " MACSTR |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 244 | " SSID '%s' due to %s", bss->id, MAC2STR(bss->bssid), |
| 245 | wpa_ssid_txt(bss->ssid, bss->ssid_len), reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 246 | wpas_notify_bss_removed(wpa_s, bss->bssid, bss->id); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 247 | wpa_bss_anqp_free(bss->anqp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 248 | os_free(bss); |
| 249 | } |
| 250 | |
| 251 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 252 | /** |
| 253 | * wpa_bss_get - Fetch a BSS table entry based on BSSID and SSID |
| 254 | * @wpa_s: Pointer to wpa_supplicant data |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 255 | * @bssid: BSSID, or %NULL to match any BSSID |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 256 | * @ssid: SSID |
| 257 | * @ssid_len: Length of @ssid |
| 258 | * Returns: Pointer to the BSS entry or %NULL if not found |
| 259 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 260 | struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 261 | const u8 *ssid, size_t ssid_len) |
| 262 | { |
| 263 | struct wpa_bss *bss; |
Matthew Wang | afc981e | 2023-03-17 21:30:12 +0000 | [diff] [blame] | 264 | |
| 265 | if (bssid && !wpa_supplicant_filter_bssid_match(wpa_s, bssid)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 266 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 267 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 268 | if ((!bssid || ether_addr_equal(bss->bssid, bssid)) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 269 | bss->ssid_len == ssid_len && |
| 270 | os_memcmp(bss->ssid, ssid, ssid_len) == 0) |
| 271 | return bss; |
| 272 | } |
| 273 | return NULL; |
| 274 | } |
| 275 | |
| 276 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 277 | void calculate_update_time(const struct os_reltime *fetch_time, |
| 278 | unsigned int age_ms, |
| 279 | struct os_reltime *update_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 280 | { |
| 281 | os_time_t usec; |
| 282 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 283 | update_time->sec = fetch_time->sec; |
| 284 | update_time->usec = fetch_time->usec; |
| 285 | update_time->sec -= age_ms / 1000; |
| 286 | usec = (age_ms % 1000) * 1000; |
| 287 | if (update_time->usec < usec) { |
| 288 | update_time->sec--; |
| 289 | update_time->usec += 1000000; |
| 290 | } |
| 291 | update_time->usec -= usec; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 296 | struct os_reltime *fetch_time) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 297 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 298 | dst->flags = src->flags; |
| 299 | os_memcpy(dst->bssid, src->bssid, ETH_ALEN); |
| 300 | dst->freq = src->freq; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 301 | dst->max_cw = src->max_cw; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 302 | dst->beacon_int = src->beacon_int; |
| 303 | dst->caps = src->caps; |
| 304 | dst->qual = src->qual; |
| 305 | dst->noise = src->noise; |
| 306 | dst->level = src->level; |
| 307 | dst->tsf = src->tsf; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 308 | dst->beacon_newer = src->beacon_newer; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 309 | dst->est_throughput = src->est_throughput; |
| 310 | dst->snr = src->snr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 311 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 312 | calculate_update_time(fetch_time, src->age, &dst->last_update); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 316 | static int wpa_bss_is_wps_candidate(struct wpa_supplicant *wpa_s, |
| 317 | struct wpa_bss *bss) |
| 318 | { |
| 319 | #ifdef CONFIG_WPS |
| 320 | struct wpa_ssid *ssid; |
| 321 | struct wpabuf *wps_ie; |
| 322 | int pbc = 0, ret; |
| 323 | |
| 324 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 325 | if (!wps_ie) |
| 326 | return 0; |
| 327 | |
| 328 | if (wps_is_selected_pbc_registrar(wps_ie)) { |
| 329 | pbc = 1; |
| 330 | } else if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) { |
| 331 | wpabuf_free(wps_ie); |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 336 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS)) |
| 337 | continue; |
| 338 | if (ssid->ssid_len && |
| 339 | (ssid->ssid_len != bss->ssid_len || |
| 340 | os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) != 0)) |
| 341 | continue; |
| 342 | |
| 343 | if (pbc) |
| 344 | ret = eap_is_wps_pbc_enrollee(&ssid->eap); |
| 345 | else |
| 346 | ret = eap_is_wps_pin_enrollee(&ssid->eap); |
| 347 | wpabuf_free(wps_ie); |
| 348 | return ret; |
| 349 | } |
| 350 | wpabuf_free(wps_ie); |
| 351 | #endif /* CONFIG_WPS */ |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 357 | static bool is_p2p_pending_bss(struct wpa_supplicant *wpa_s, |
| 358 | struct wpa_bss *bss) |
| 359 | { |
| 360 | #ifdef CONFIG_P2P |
| 361 | u8 addr[ETH_ALEN]; |
| 362 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 363 | if (ether_addr_equal(bss->bssid, wpa_s->pending_join_iface_addr)) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 364 | return true; |
| 365 | if (!is_zero_ether_addr(wpa_s->pending_join_dev_addr) && |
| 366 | p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len, addr) == 0 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 367 | ether_addr_equal(addr, wpa_s->pending_join_dev_addr)) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 368 | return true; |
| 369 | #endif /* CONFIG_P2P */ |
| 370 | return false; |
| 371 | } |
| 372 | |
| 373 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 374 | static int wpa_bss_known(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
| 375 | { |
| 376 | struct wpa_ssid *ssid; |
| 377 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 378 | if (is_p2p_pending_bss(wpa_s, bss)) |
| 379 | return 1; |
| 380 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 381 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 382 | if (ssid->ssid == NULL || ssid->ssid_len == 0) |
| 383 | continue; |
| 384 | if (ssid->ssid_len == bss->ssid_len && |
| 385 | os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) == 0) |
| 386 | return 1; |
| 387 | } |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 393 | static int wpa_bss_in_use(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
| 394 | { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 395 | int i; |
| 396 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 397 | if (bss == wpa_s->current_bss) |
| 398 | return 1; |
| 399 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 400 | if (bss == wpa_s->ml_connect_probe_bss) |
| 401 | return 1; |
| 402 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 403 | #ifdef CONFIG_WNM |
| 404 | if (bss == wpa_s->wnm_target_bss) |
| 405 | return 1; |
| 406 | #endif /* CONFIG_WNM */ |
| 407 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 408 | if (wpa_s->current_bss && |
| 409 | (bss->ssid_len != wpa_s->current_bss->ssid_len || |
| 410 | os_memcmp(bss->ssid, wpa_s->current_bss->ssid, |
| 411 | bss->ssid_len) != 0)) |
| 412 | return 0; /* SSID has changed */ |
| 413 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 414 | if (!is_zero_ether_addr(bss->bssid) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 415 | (ether_addr_equal(bss->bssid, wpa_s->bssid) || |
| 416 | ether_addr_equal(bss->bssid, wpa_s->pending_bssid))) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 417 | return 1; |
| 418 | |
| 419 | if (!wpa_s->valid_links) |
| 420 | return 0; |
| 421 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 422 | for_each_link(wpa_s->valid_links, i) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 423 | if (ether_addr_equal(bss->bssid, wpa_s->links[i].bssid)) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 424 | return 1; |
| 425 | } |
| 426 | |
| 427 | return 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 431 | static int wpa_bss_remove_oldest_unknown(struct wpa_supplicant *wpa_s) |
| 432 | { |
| 433 | struct wpa_bss *bss; |
| 434 | |
| 435 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 436 | if (!wpa_bss_known(wpa_s, bss) && |
| 437 | !wpa_bss_is_wps_candidate(wpa_s, bss)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 438 | wpa_bss_remove(wpa_s, bss, __func__); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 439 | return 0; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | return -1; |
| 444 | } |
| 445 | |
| 446 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 447 | static int wpa_bss_remove_oldest(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 448 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 449 | struct wpa_bss *bss; |
| 450 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 451 | /* |
| 452 | * Remove the oldest entry that does not match with any configured |
| 453 | * network. |
| 454 | */ |
| 455 | if (wpa_bss_remove_oldest_unknown(wpa_s) == 0) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 456 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 457 | |
| 458 | /* |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 459 | * Remove the oldest entry that isn't currently in use. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 460 | */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 461 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 462 | if (!wpa_bss_in_use(wpa_s, bss)) { |
| 463 | wpa_bss_remove(wpa_s, bss, __func__); |
| 464 | return 0; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 472 | static struct wpa_bss * wpa_bss_add(struct wpa_supplicant *wpa_s, |
| 473 | const u8 *ssid, size_t ssid_len, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 474 | struct wpa_scan_res *res, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 475 | struct os_reltime *fetch_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 476 | { |
| 477 | struct wpa_bss *bss; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 478 | char extra[100]; |
| 479 | const u8 *ml_ie; |
| 480 | char *pos, *end; |
| 481 | int ret = 0; |
| 482 | const u8 *mld_addr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 483 | |
| 484 | bss = os_zalloc(sizeof(*bss) + res->ie_len + res->beacon_ie_len); |
| 485 | if (bss == NULL) |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 486 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 487 | bss->id = wpa_s->bss_next_id++; |
| 488 | bss->last_update_idx = wpa_s->bss_update_idx; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 489 | wpa_bss_copy_res(bss, res, fetch_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 490 | os_memcpy(bss->ssid, ssid, ssid_len); |
| 491 | bss->ssid_len = ssid_len; |
| 492 | bss->ie_len = res->ie_len; |
| 493 | bss->beacon_ie_len = res->beacon_ie_len; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 494 | os_memcpy(bss->ies, res + 1, res->ie_len + res->beacon_ie_len); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 495 | wpa_bss_set_hessid(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 496 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 497 | os_memset(bss->mld_addr, 0, ETH_ALEN); |
| 498 | ml_ie = wpa_scan_get_ml_ie(res, MULTI_LINK_CONTROL_TYPE_BASIC); |
| 499 | if (ml_ie) { |
| 500 | mld_addr = get_basic_mle_mld_addr(&ml_ie[3], ml_ie[1] - 1); |
| 501 | if (mld_addr) |
| 502 | os_memcpy(bss->mld_addr, mld_addr, ETH_ALEN); |
| 503 | } |
| 504 | |
Jouni Malinen | 7a6c830 | 2013-09-27 15:47:09 +0300 | [diff] [blame] | 505 | if (wpa_s->num_bss + 1 > wpa_s->conf->bss_max_count && |
| 506 | wpa_bss_remove_oldest(wpa_s) != 0) { |
| 507 | wpa_printf(MSG_ERROR, "Increasing the MAX BSS count to %d " |
| 508 | "because all BSSes are in use. We should normally " |
| 509 | "not get here!", (int) wpa_s->num_bss + 1); |
| 510 | wpa_s->conf->bss_max_count = wpa_s->num_bss + 1; |
| 511 | } |
| 512 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 513 | dl_list_add_tail(&wpa_s->bss, &bss->list); |
| 514 | dl_list_add_tail(&wpa_s->bss_id, &bss->list_id); |
| 515 | wpa_s->num_bss++; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 516 | |
| 517 | extra[0] = '\0'; |
| 518 | pos = extra; |
| 519 | end = pos + sizeof(extra); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 520 | if (!is_zero_ether_addr(bss->hessid)) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 521 | ret = os_snprintf(pos, end - pos, " HESSID " MACSTR, |
| 522 | MAC2STR(bss->hessid)); |
| 523 | |
| 524 | if (!is_zero_ether_addr(bss->mld_addr) && |
| 525 | !os_snprintf_error(end - pos, ret)) { |
| 526 | pos += ret; |
| 527 | ret = os_snprintf(pos, end - pos, " MLD ADDR " MACSTR, |
| 528 | MAC2STR(bss->mld_addr)); |
| 529 | } |
| 530 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 531 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Add new id %u BSSID " MACSTR |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 532 | " SSID '%s' freq %d%s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 533 | bss->id, MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len), |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 534 | bss->freq, extra); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 535 | wpas_notify_bss_added(wpa_s, bss->bssid, bss->id); |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 536 | return bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
| 540 | static int are_ies_equal(const struct wpa_bss *old, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 541 | const struct wpa_scan_res *new_res, u32 ie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 542 | { |
| 543 | const u8 *old_ie, *new_ie; |
| 544 | struct wpabuf *old_ie_buff = NULL; |
| 545 | struct wpabuf *new_ie_buff = NULL; |
| 546 | int new_ie_len, old_ie_len, ret, is_multi; |
| 547 | |
| 548 | switch (ie) { |
| 549 | case WPA_IE_VENDOR_TYPE: |
| 550 | old_ie = wpa_bss_get_vendor_ie(old, ie); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 551 | new_ie = wpa_scan_get_vendor_ie(new_res, ie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 552 | is_multi = 0; |
| 553 | break; |
| 554 | case WPS_IE_VENDOR_TYPE: |
| 555 | old_ie_buff = wpa_bss_get_vendor_ie_multi(old, ie); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 556 | new_ie_buff = wpa_scan_get_vendor_ie_multi(new_res, ie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 557 | is_multi = 1; |
| 558 | break; |
| 559 | case WLAN_EID_RSN: |
| 560 | case WLAN_EID_SUPP_RATES: |
| 561 | case WLAN_EID_EXT_SUPP_RATES: |
| 562 | old_ie = wpa_bss_get_ie(old, ie); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 563 | new_ie = wpa_scan_get_ie(new_res, ie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 564 | is_multi = 0; |
| 565 | break; |
| 566 | default: |
| 567 | wpa_printf(MSG_DEBUG, "bss: %s: cannot compare IEs", __func__); |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | if (is_multi) { |
| 572 | /* in case of multiple IEs stored in buffer */ |
| 573 | old_ie = old_ie_buff ? wpabuf_head_u8(old_ie_buff) : NULL; |
| 574 | new_ie = new_ie_buff ? wpabuf_head_u8(new_ie_buff) : NULL; |
| 575 | old_ie_len = old_ie_buff ? wpabuf_len(old_ie_buff) : 0; |
| 576 | new_ie_len = new_ie_buff ? wpabuf_len(new_ie_buff) : 0; |
| 577 | } else { |
| 578 | /* in case of single IE */ |
| 579 | old_ie_len = old_ie ? old_ie[1] + 2 : 0; |
| 580 | new_ie_len = new_ie ? new_ie[1] + 2 : 0; |
| 581 | } |
| 582 | |
| 583 | if (!old_ie || !new_ie) |
| 584 | ret = !old_ie && !new_ie; |
| 585 | else |
| 586 | ret = (old_ie_len == new_ie_len && |
| 587 | os_memcmp(old_ie, new_ie, old_ie_len) == 0); |
| 588 | |
| 589 | wpabuf_free(old_ie_buff); |
| 590 | wpabuf_free(new_ie_buff); |
| 591 | |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | |
| 596 | static u32 wpa_bss_compare_res(const struct wpa_bss *old, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 597 | const struct wpa_scan_res *new_res) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 598 | { |
| 599 | u32 changes = 0; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 600 | int caps_diff = old->caps ^ new_res->caps; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 601 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 602 | if (old->freq != new_res->freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 603 | changes |= WPA_BSS_FREQ_CHANGED_FLAG; |
| 604 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 605 | if (old->level != new_res->level) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 606 | changes |= WPA_BSS_SIGNAL_CHANGED_FLAG; |
| 607 | |
| 608 | if (caps_diff & IEEE80211_CAP_PRIVACY) |
| 609 | changes |= WPA_BSS_PRIVACY_CHANGED_FLAG; |
| 610 | |
| 611 | if (caps_diff & IEEE80211_CAP_IBSS) |
| 612 | changes |= WPA_BSS_MODE_CHANGED_FLAG; |
| 613 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 614 | if (old->ie_len == new_res->ie_len && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 615 | os_memcmp(wpa_bss_ie_ptr(old), new_res + 1, old->ie_len) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 616 | return changes; |
| 617 | changes |= WPA_BSS_IES_CHANGED_FLAG; |
| 618 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 619 | if (!are_ies_equal(old, new_res, WPA_IE_VENDOR_TYPE)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 620 | changes |= WPA_BSS_WPAIE_CHANGED_FLAG; |
| 621 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 622 | if (!are_ies_equal(old, new_res, WLAN_EID_RSN)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 623 | changes |= WPA_BSS_RSNIE_CHANGED_FLAG; |
| 624 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 625 | if (!are_ies_equal(old, new_res, WPS_IE_VENDOR_TYPE)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 626 | changes |= WPA_BSS_WPS_CHANGED_FLAG; |
| 627 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 628 | if (!are_ies_equal(old, new_res, WLAN_EID_SUPP_RATES) || |
| 629 | !are_ies_equal(old, new_res, WLAN_EID_EXT_SUPP_RATES)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 630 | changes |= WPA_BSS_RATES_CHANGED_FLAG; |
| 631 | |
| 632 | return changes; |
| 633 | } |
| 634 | |
| 635 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 636 | void notify_bss_changes(struct wpa_supplicant *wpa_s, u32 changes, |
| 637 | const struct wpa_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 638 | { |
| 639 | if (changes & WPA_BSS_FREQ_CHANGED_FLAG) |
| 640 | wpas_notify_bss_freq_changed(wpa_s, bss->id); |
| 641 | |
| 642 | if (changes & WPA_BSS_SIGNAL_CHANGED_FLAG) |
| 643 | wpas_notify_bss_signal_changed(wpa_s, bss->id); |
| 644 | |
| 645 | if (changes & WPA_BSS_PRIVACY_CHANGED_FLAG) |
| 646 | wpas_notify_bss_privacy_changed(wpa_s, bss->id); |
| 647 | |
| 648 | if (changes & WPA_BSS_MODE_CHANGED_FLAG) |
| 649 | wpas_notify_bss_mode_changed(wpa_s, bss->id); |
| 650 | |
| 651 | if (changes & WPA_BSS_WPAIE_CHANGED_FLAG) |
| 652 | wpas_notify_bss_wpaie_changed(wpa_s, bss->id); |
| 653 | |
| 654 | if (changes & WPA_BSS_RSNIE_CHANGED_FLAG) |
| 655 | wpas_notify_bss_rsnie_changed(wpa_s, bss->id); |
| 656 | |
| 657 | if (changes & WPA_BSS_WPS_CHANGED_FLAG) |
| 658 | wpas_notify_bss_wps_changed(wpa_s, bss->id); |
| 659 | |
| 660 | if (changes & WPA_BSS_IES_CHANGED_FLAG) |
| 661 | wpas_notify_bss_ies_changed(wpa_s, bss->id); |
| 662 | |
| 663 | if (changes & WPA_BSS_RATES_CHANGED_FLAG) |
| 664 | wpas_notify_bss_rates_changed(wpa_s, bss->id); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 665 | |
| 666 | wpas_notify_bss_seen(wpa_s, bss->id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 670 | static struct wpa_bss * |
| 671 | wpa_bss_update(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 672 | struct wpa_scan_res *res, struct os_reltime *fetch_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 673 | { |
| 674 | u32 changes; |
| 675 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 676 | if (bss->last_update_idx == wpa_s->bss_update_idx) { |
| 677 | struct os_reltime update_time; |
| 678 | |
| 679 | /* |
| 680 | * Some drivers (e.g., cfg80211) include multiple BSS entries |
| 681 | * for the same BSS if that BSS's channel changes. The BSS list |
| 682 | * implementation in wpa_supplicant does not do that and we need |
| 683 | * to filter out the obsolete results here to make sure only the |
| 684 | * most current BSS information remains in the table. |
| 685 | */ |
| 686 | wpa_printf(MSG_DEBUG, "BSS: " MACSTR |
| 687 | " has multiple entries in the scan results - select the most current one", |
| 688 | MAC2STR(bss->bssid)); |
| 689 | calculate_update_time(fetch_time, res->age, &update_time); |
| 690 | wpa_printf(MSG_DEBUG, |
| 691 | "Previous last_update: %u.%06u (freq %d%s)", |
| 692 | (unsigned int) bss->last_update.sec, |
| 693 | (unsigned int) bss->last_update.usec, |
| 694 | bss->freq, |
| 695 | (bss->flags & WPA_BSS_ASSOCIATED) ? " assoc" : ""); |
| 696 | wpa_printf(MSG_DEBUG, "New last_update: %u.%06u (freq %d%s)", |
| 697 | (unsigned int) update_time.sec, |
| 698 | (unsigned int) update_time.usec, |
| 699 | res->freq, |
| 700 | (res->flags & WPA_SCAN_ASSOCIATED) ? " assoc" : ""); |
| 701 | if ((bss->flags & WPA_BSS_ASSOCIATED) || |
| 702 | (!(res->flags & WPA_SCAN_ASSOCIATED) && |
| 703 | !os_reltime_before(&bss->last_update, &update_time))) { |
| 704 | wpa_printf(MSG_DEBUG, |
| 705 | "Ignore this BSS entry since the previous update looks more current"); |
| 706 | return bss; |
| 707 | } |
| 708 | wpa_printf(MSG_DEBUG, |
| 709 | "Accept this BSS entry since it looks more current than the previous update"); |
| 710 | } |
| 711 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 712 | changes = wpa_bss_compare_res(bss, res); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 713 | if (changes & WPA_BSS_FREQ_CHANGED_FLAG) |
| 714 | wpa_printf(MSG_DEBUG, "BSS: " MACSTR " changed freq %d --> %d", |
| 715 | MAC2STR(bss->bssid), bss->freq, res->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 716 | bss->scan_miss_count = 0; |
| 717 | bss->last_update_idx = wpa_s->bss_update_idx; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 718 | wpa_bss_copy_res(bss, res, fetch_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 719 | /* Move the entry to the end of the list */ |
| 720 | dl_list_del(&bss->list); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 721 | #ifdef CONFIG_P2P |
| 722 | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 723 | !wpa_scan_get_vendor_ie(res, P2P_IE_VENDOR_TYPE) && |
| 724 | !(changes & WPA_BSS_FREQ_CHANGED_FLAG)) { |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 725 | /* |
| 726 | * This can happen when non-P2P station interface runs a scan |
| 727 | * without P2P IE in the Probe Request frame. P2P GO would reply |
| 728 | * to that with a Probe Response that does not include P2P IE. |
| 729 | * Do not update the IEs in this BSS entry to avoid such loss of |
| 730 | * information that may be needed for P2P operations to |
| 731 | * determine group information. |
| 732 | */ |
| 733 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Do not update scan IEs for " |
| 734 | MACSTR " since that would remove P2P IE information", |
| 735 | MAC2STR(bss->bssid)); |
| 736 | } else |
| 737 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 738 | if (bss->ie_len + bss->beacon_ie_len >= |
| 739 | res->ie_len + res->beacon_ie_len) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 740 | os_memcpy(bss->ies, res + 1, res->ie_len + res->beacon_ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 741 | bss->ie_len = res->ie_len; |
| 742 | bss->beacon_ie_len = res->beacon_ie_len; |
| 743 | } else { |
| 744 | struct wpa_bss *nbss; |
| 745 | struct dl_list *prev = bss->list_id.prev; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 746 | struct wpa_connect_work *cwork; |
| 747 | unsigned int i; |
| 748 | bool update_current_bss = wpa_s->current_bss == bss; |
| 749 | bool update_ml_probe_bss = wpa_s->ml_connect_probe_bss == bss; |
| 750 | |
| 751 | cwork = wpa_bss_check_pending_connect(wpa_s, bss); |
| 752 | |
| 753 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 754 | if (wpa_s->last_scan_res[i] == bss) |
| 755 | break; |
| 756 | } |
| 757 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 758 | dl_list_del(&bss->list_id); |
| 759 | nbss = os_realloc(bss, sizeof(*bss) + res->ie_len + |
| 760 | res->beacon_ie_len); |
| 761 | if (nbss) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 762 | if (i != wpa_s->last_scan_res_used) |
| 763 | wpa_s->last_scan_res[i] = nbss; |
| 764 | |
| 765 | if (update_current_bss) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 766 | wpa_s->current_bss = nbss; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 767 | |
| 768 | if (update_ml_probe_bss) |
| 769 | wpa_s->ml_connect_probe_bss = nbss; |
| 770 | |
| 771 | if (cwork) |
| 772 | wpa_bss_update_pending_connect(cwork, nbss); |
| 773 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 774 | bss = nbss; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 775 | os_memcpy(bss->ies, res + 1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 776 | res->ie_len + res->beacon_ie_len); |
| 777 | bss->ie_len = res->ie_len; |
| 778 | bss->beacon_ie_len = res->beacon_ie_len; |
| 779 | } |
| 780 | dl_list_add(prev, &bss->list_id); |
| 781 | } |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 782 | if (changes & WPA_BSS_IES_CHANGED_FLAG) { |
| 783 | const u8 *ml_ie, *mld_addr; |
| 784 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 785 | wpa_bss_set_hessid(bss); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 786 | os_memset(bss->mld_addr, 0, ETH_ALEN); |
| 787 | ml_ie = wpa_scan_get_ml_ie(res, MULTI_LINK_CONTROL_TYPE_BASIC); |
| 788 | if (ml_ie) { |
| 789 | mld_addr = get_basic_mle_mld_addr(&ml_ie[3], |
| 790 | ml_ie[1] - 1); |
| 791 | if (mld_addr) |
| 792 | os_memcpy(bss->mld_addr, mld_addr, ETH_ALEN); |
| 793 | } |
| 794 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 795 | dl_list_add_tail(&wpa_s->bss, &bss->list); |
| 796 | |
| 797 | notify_bss_changes(wpa_s, changes, bss); |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 798 | |
| 799 | return bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 803 | /** |
| 804 | * wpa_bss_update_start - Start a BSS table update from scan results |
| 805 | * @wpa_s: Pointer to wpa_supplicant data |
| 806 | * |
| 807 | * This function is called at the start of each BSS table update round for new |
| 808 | * scan results. The actual scan result entries are indicated with calls to |
| 809 | * wpa_bss_update_scan_res() and the update round is finished with a call to |
| 810 | * wpa_bss_update_end(). |
| 811 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 812 | void wpa_bss_update_start(struct wpa_supplicant *wpa_s) |
| 813 | { |
| 814 | wpa_s->bss_update_idx++; |
| 815 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Start scan result update %u", |
| 816 | wpa_s->bss_update_idx); |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 817 | wpa_s->last_scan_res_used = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 821 | /** |
| 822 | * wpa_bss_update_scan_res - Update a BSS table entry based on a scan result |
| 823 | * @wpa_s: Pointer to wpa_supplicant data |
| 824 | * @res: Scan result |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 825 | * @fetch_time: Time when the result was fetched from the driver |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 826 | * |
| 827 | * This function updates a BSS table entry (or adds one) based on a scan result. |
| 828 | * This is called separately for each scan result between the calls to |
| 829 | * wpa_bss_update_start() and wpa_bss_update_end(). |
| 830 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 831 | void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 832 | struct wpa_scan_res *res, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 833 | struct os_reltime *fetch_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 834 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 835 | const u8 *ssid, *p2p, *mesh; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 836 | struct wpa_bss *bss; |
| 837 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 838 | if (wpa_s->conf->ignore_old_scan_res) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 839 | struct os_reltime update; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 840 | calculate_update_time(fetch_time, res->age, &update); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 841 | if (os_reltime_before(&update, &wpa_s->scan_trigger_time)) { |
| 842 | struct os_reltime age; |
| 843 | os_reltime_sub(&wpa_s->scan_trigger_time, &update, |
| 844 | &age); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 845 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Ignore driver BSS " |
| 846 | "table entry that is %u.%06u seconds older " |
| 847 | "than our scan trigger", |
| 848 | (unsigned int) age.sec, |
| 849 | (unsigned int) age.usec); |
| 850 | return; |
| 851 | } |
| 852 | } |
| 853 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 854 | ssid = wpa_scan_get_ie(res, WLAN_EID_SSID); |
| 855 | if (ssid == NULL) { |
| 856 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: No SSID IE included for " |
| 857 | MACSTR, MAC2STR(res->bssid)); |
| 858 | return; |
| 859 | } |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 860 | if (ssid[1] > SSID_MAX_LEN) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 861 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Too long SSID IE included for " |
| 862 | MACSTR, MAC2STR(res->bssid)); |
| 863 | return; |
| 864 | } |
| 865 | |
| 866 | p2p = wpa_scan_get_vendor_ie(res, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 867 | #ifdef CONFIG_P2P |
| 868 | if (p2p == NULL && |
| 869 | wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 870 | /* |
| 871 | * If it's a P2P specific interface, then don't update |
| 872 | * the scan result without a P2P IE. |
| 873 | */ |
| 874 | wpa_printf(MSG_DEBUG, "BSS: No P2P IE - skipping BSS " MACSTR |
| 875 | " update for P2P interface", MAC2STR(res->bssid)); |
| 876 | return; |
| 877 | } |
| 878 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 879 | if (p2p && ssid[1] == P2P_WILDCARD_SSID_LEN && |
| 880 | os_memcmp(ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == 0) |
| 881 | return; /* Skip P2P listen discovery results here */ |
| 882 | |
| 883 | /* TODO: add option for ignoring BSSes we are not interested in |
| 884 | * (to save memory) */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 885 | |
| 886 | mesh = wpa_scan_get_ie(res, WLAN_EID_MESH_ID); |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 887 | if (mesh && mesh[1] <= SSID_MAX_LEN) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 888 | ssid = mesh; |
| 889 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 890 | bss = wpa_bss_get(wpa_s, res->bssid, ssid + 2, ssid[1]); |
| 891 | if (bss == NULL) |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 892 | bss = wpa_bss_add(wpa_s, ssid + 2, ssid[1], res, fetch_time); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 893 | else { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 894 | bss = wpa_bss_update(wpa_s, bss, res, fetch_time); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 895 | if (wpa_s->last_scan_res) { |
| 896 | unsigned int i; |
| 897 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 898 | if (bss == wpa_s->last_scan_res[i]) { |
| 899 | /* Already in the list */ |
| 900 | return; |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | } |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 905 | |
| 906 | if (bss == NULL) |
| 907 | return; |
| 908 | if (wpa_s->last_scan_res_used >= wpa_s->last_scan_res_size) { |
| 909 | struct wpa_bss **n; |
| 910 | unsigned int siz; |
| 911 | if (wpa_s->last_scan_res_size == 0) |
| 912 | siz = 32; |
| 913 | else |
| 914 | siz = wpa_s->last_scan_res_size * 2; |
| 915 | n = os_realloc_array(wpa_s->last_scan_res, siz, |
| 916 | sizeof(struct wpa_bss *)); |
| 917 | if (n == NULL) |
| 918 | return; |
| 919 | wpa_s->last_scan_res = n; |
| 920 | wpa_s->last_scan_res_size = siz; |
| 921 | } |
| 922 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 923 | if (wpa_s->last_scan_res) |
| 924 | wpa_s->last_scan_res[wpa_s->last_scan_res_used++] = bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | |
| 928 | static int wpa_bss_included_in_scan(const struct wpa_bss *bss, |
| 929 | const struct scan_info *info) |
| 930 | { |
| 931 | int found; |
| 932 | size_t i; |
| 933 | |
| 934 | if (info == NULL) |
| 935 | return 1; |
| 936 | |
| 937 | if (info->num_freqs) { |
| 938 | found = 0; |
| 939 | for (i = 0; i < info->num_freqs; i++) { |
| 940 | if (bss->freq == info->freqs[i]) { |
| 941 | found = 1; |
| 942 | break; |
| 943 | } |
| 944 | } |
| 945 | if (!found) |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | if (info->num_ssids) { |
| 950 | found = 0; |
| 951 | for (i = 0; i < info->num_ssids; i++) { |
| 952 | const struct wpa_driver_scan_ssid *s = &info->ssids[i]; |
| 953 | if ((s->ssid == NULL || s->ssid_len == 0) || |
| 954 | (s->ssid_len == bss->ssid_len && |
| 955 | os_memcmp(s->ssid, bss->ssid, bss->ssid_len) == |
| 956 | 0)) { |
| 957 | found = 1; |
| 958 | break; |
| 959 | } |
| 960 | } |
| 961 | if (!found) |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | return 1; |
| 966 | } |
| 967 | |
| 968 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 969 | /** |
| 970 | * wpa_bss_update_end - End a BSS table update from scan results |
| 971 | * @wpa_s: Pointer to wpa_supplicant data |
| 972 | * @info: Information about scan parameters |
| 973 | * @new_scan: Whether this update round was based on a new scan |
| 974 | * |
| 975 | * This function is called at the end of each BSS table update round for new |
| 976 | * scan results. The start of the update was indicated with a call to |
| 977 | * wpa_bss_update_start(). |
| 978 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 979 | void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info, |
| 980 | int new_scan) |
| 981 | { |
| 982 | struct wpa_bss *bss, *n; |
| 983 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 984 | os_get_reltime(&wpa_s->last_scan); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 985 | if ((info && info->aborted) || !new_scan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 986 | return; /* do not expire entries without new scan */ |
| 987 | |
| 988 | dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) { |
| 989 | if (wpa_bss_in_use(wpa_s, bss)) |
| 990 | continue; |
| 991 | if (!wpa_bss_included_in_scan(bss, info)) |
| 992 | continue; /* expire only BSSes that were scanned */ |
| 993 | if (bss->last_update_idx < wpa_s->bss_update_idx) |
| 994 | bss->scan_miss_count++; |
| 995 | if (bss->scan_miss_count >= |
| 996 | wpa_s->conf->bss_expiration_scan_count) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 997 | wpa_bss_remove(wpa_s, bss, "no match in scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 998 | } |
| 999 | } |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1000 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1001 | wpa_printf(MSG_DEBUG, "BSS: last_scan_res_used=%zu/%zu", |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1002 | wpa_s->last_scan_res_used, wpa_s->last_scan_res_size); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1006 | /** |
| 1007 | * wpa_bss_flush_by_age - Flush old BSS entries |
| 1008 | * @wpa_s: Pointer to wpa_supplicant data |
| 1009 | * @age: Maximum entry age in seconds |
| 1010 | * |
| 1011 | * Remove BSS entries that have not been updated during the last @age seconds. |
| 1012 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1013 | void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age) |
| 1014 | { |
| 1015 | struct wpa_bss *bss, *n; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1016 | struct os_reltime t; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1017 | |
| 1018 | if (dl_list_empty(&wpa_s->bss)) |
| 1019 | return; |
| 1020 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1021 | os_get_reltime(&t); |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1022 | |
| 1023 | if (t.sec < age) |
| 1024 | return; /* avoid underflow; there can be no older entries */ |
| 1025 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1026 | t.sec -= age; |
| 1027 | |
| 1028 | dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) { |
| 1029 | if (wpa_bss_in_use(wpa_s, bss)) |
| 1030 | continue; |
| 1031 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1032 | if (wpa_s->reassoc_same_ess && |
| 1033 | wpa_s->wpa_state != WPA_COMPLETED && |
| 1034 | wpa_s->last_ssid && |
| 1035 | bss->ssid_len == wpa_s->last_ssid->ssid_len && |
| 1036 | os_memcmp(bss->ssid, wpa_s->last_ssid->ssid, |
| 1037 | bss->ssid_len) == 0) |
| 1038 | continue; |
| 1039 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1040 | if (os_reltime_before(&bss->last_update, &t)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1041 | wpa_bss_remove(wpa_s, bss, __func__); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1042 | } else |
| 1043 | break; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1048 | /** |
| 1049 | * wpa_bss_init - Initialize BSS table |
| 1050 | * @wpa_s: Pointer to wpa_supplicant data |
| 1051 | * Returns: 0 on success, -1 on failure |
| 1052 | * |
| 1053 | * This prepares BSS table lists and timer for periodic updates. The BSS table |
| 1054 | * is deinitialized with wpa_bss_deinit() once not needed anymore. |
| 1055 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1056 | int wpa_bss_init(struct wpa_supplicant *wpa_s) |
| 1057 | { |
| 1058 | dl_list_init(&wpa_s->bss); |
| 1059 | dl_list_init(&wpa_s->bss_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1064 | /** |
| 1065 | * wpa_bss_flush - Flush all unused BSS entries |
| 1066 | * @wpa_s: Pointer to wpa_supplicant data |
| 1067 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1068 | void wpa_bss_flush(struct wpa_supplicant *wpa_s) |
| 1069 | { |
| 1070 | struct wpa_bss *bss, *n; |
| 1071 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1072 | wpa_s->clear_driver_scan_cache = 1; |
| 1073 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1074 | if (wpa_s->bss.next == NULL) |
| 1075 | return; /* BSS table not yet initialized */ |
| 1076 | |
| 1077 | dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) { |
| 1078 | if (wpa_bss_in_use(wpa_s, bss)) |
| 1079 | continue; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1080 | wpa_bss_remove(wpa_s, bss, __func__); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1085 | /** |
| 1086 | * wpa_bss_deinit - Deinitialize BSS table |
| 1087 | * @wpa_s: Pointer to wpa_supplicant data |
| 1088 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1089 | void wpa_bss_deinit(struct wpa_supplicant *wpa_s) |
| 1090 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1091 | wpa_bss_flush(wpa_s); |
| 1092 | } |
| 1093 | |
| 1094 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1095 | /** |
| 1096 | * wpa_bss_get_bssid - Fetch a BSS table entry based on BSSID |
| 1097 | * @wpa_s: Pointer to wpa_supplicant data |
| 1098 | * @bssid: BSSID |
| 1099 | * Returns: Pointer to the BSS entry or %NULL if not found |
| 1100 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1101 | struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s, |
| 1102 | const u8 *bssid) |
| 1103 | { |
| 1104 | struct wpa_bss *bss; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1105 | if (!wpa_supplicant_filter_bssid_match(wpa_s, bssid)) |
| 1106 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1107 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1108 | if (ether_addr_equal(bss->bssid, bssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1109 | return bss; |
| 1110 | } |
| 1111 | return NULL; |
| 1112 | } |
| 1113 | |
| 1114 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1115 | /** |
| 1116 | * wpa_bss_get_bssid_latest - Fetch the latest BSS table entry based on BSSID |
| 1117 | * @wpa_s: Pointer to wpa_supplicant data |
| 1118 | * @bssid: BSSID |
| 1119 | * Returns: Pointer to the BSS entry or %NULL if not found |
| 1120 | * |
| 1121 | * This function is like wpa_bss_get_bssid(), but full BSS table is iterated to |
| 1122 | * find the entry that has the most recent update. This can help in finding the |
| 1123 | * correct entry in cases where the SSID of the AP may have changed recently |
| 1124 | * (e.g., in WPS reconfiguration cases). |
| 1125 | */ |
| 1126 | struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s, |
| 1127 | const u8 *bssid) |
| 1128 | { |
| 1129 | struct wpa_bss *bss, *found = NULL; |
| 1130 | if (!wpa_supplicant_filter_bssid_match(wpa_s, bssid)) |
| 1131 | return NULL; |
| 1132 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1133 | if (!ether_addr_equal(bss->bssid, bssid)) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1134 | continue; |
| 1135 | if (found == NULL || |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1136 | os_reltime_before(&found->last_update, &bss->last_update)) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1137 | found = bss; |
| 1138 | } |
| 1139 | return found; |
| 1140 | } |
| 1141 | |
| 1142 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1143 | #ifdef CONFIG_P2P |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1144 | /** |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1145 | * wpa_bss_get_p2p_dev_addr - Fetch the latest BSS table entry based on P2P Device Addr |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1146 | * @wpa_s: Pointer to wpa_supplicant data |
| 1147 | * @dev_addr: P2P Device Address of the GO |
| 1148 | * Returns: Pointer to the BSS entry or %NULL if not found |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1149 | * |
| 1150 | * This function tries to find the entry that has the most recent update. This |
| 1151 | * can help in finding the correct entry in cases where the SSID of the P2P |
| 1152 | * Device may have changed recently. |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1153 | */ |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1154 | struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s, |
| 1155 | const u8 *dev_addr) |
| 1156 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1157 | struct wpa_bss *bss, *found = NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1158 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1159 | u8 addr[ETH_ALEN]; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1160 | if (p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1161 | addr) != 0 || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1162 | !ether_addr_equal(addr, dev_addr)) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1163 | continue; |
| 1164 | if (!found || |
| 1165 | os_reltime_before(&found->last_update, &bss->last_update)) |
| 1166 | found = bss; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1167 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1168 | return found; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1169 | } |
| 1170 | #endif /* CONFIG_P2P */ |
| 1171 | |
| 1172 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1173 | /** |
| 1174 | * wpa_bss_get_id - Fetch a BSS table entry based on identifier |
| 1175 | * @wpa_s: Pointer to wpa_supplicant data |
| 1176 | * @id: Unique identifier (struct wpa_bss::id) assigned for the entry |
| 1177 | * Returns: Pointer to the BSS entry or %NULL if not found |
| 1178 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1179 | struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id) |
| 1180 | { |
| 1181 | struct wpa_bss *bss; |
| 1182 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1183 | if (bss->id == id) |
| 1184 | return bss; |
| 1185 | } |
| 1186 | return NULL; |
| 1187 | } |
| 1188 | |
| 1189 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1190 | /** |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1191 | * wpa_bss_get_id_range - Fetch a BSS table entry based on identifier range |
| 1192 | * @wpa_s: Pointer to wpa_supplicant data |
| 1193 | * @idf: Smallest allowed identifier assigned for the entry |
| 1194 | * @idf: Largest allowed identifier assigned for the entry |
| 1195 | * Returns: Pointer to the BSS entry or %NULL if not found |
| 1196 | * |
| 1197 | * This function is similar to wpa_bss_get_id() but allows a BSS entry with the |
| 1198 | * smallest id value to be fetched within the specified range without the |
| 1199 | * caller having to know the exact id. |
| 1200 | */ |
| 1201 | struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s, |
| 1202 | unsigned int idf, unsigned int idl) |
| 1203 | { |
| 1204 | struct wpa_bss *bss; |
| 1205 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
| 1206 | if (bss->id >= idf && bss->id <= idl) |
| 1207 | return bss; |
| 1208 | } |
| 1209 | return NULL; |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | /** |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1214 | * wpa_bss_get_ie - Fetch a specified information element from a BSS entry |
| 1215 | * @bss: BSS table entry |
| 1216 | * @ie: Information element identitifier (WLAN_EID_*) |
| 1217 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 1218 | * |
| 1219 | * This function returns the first matching information element in the BSS |
| 1220 | * entry. |
| 1221 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1222 | const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie) |
| 1223 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1224 | return get_ie(wpa_bss_ie_ptr(bss), bss->ie_len, ie); |
| 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | /** |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1229 | * wpa_bss_get_ie_beacon - Fetch a specified information element from a BSS entry |
| 1230 | * @bss: BSS table entry |
| 1231 | * @ie: Information element identitifier (WLAN_EID_*) |
| 1232 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 1233 | * |
| 1234 | * This function returns the first matching information element in the BSS |
| 1235 | * entry. |
| 1236 | * |
| 1237 | * This function is like wpa_bss_get_ie(), but uses IE buffer only from Beacon |
| 1238 | * frames instead of either Beacon or Probe Response frames. |
| 1239 | */ |
| 1240 | const u8 * wpa_bss_get_ie_beacon(const struct wpa_bss *bss, u8 ie) |
| 1241 | { |
| 1242 | const u8 *ies; |
| 1243 | |
| 1244 | if (bss->beacon_ie_len == 0) |
| 1245 | return NULL; |
| 1246 | |
| 1247 | ies = wpa_bss_ie_ptr(bss); |
| 1248 | ies += bss->ie_len; |
| 1249 | return get_ie(ies, bss->beacon_ie_len, ie); |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | /** |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1254 | * wpa_bss_get_ie_ext - Fetch a specified extended IE from a BSS entry |
| 1255 | * @bss: BSS table entry |
| 1256 | * @ext: Information element extension identifier (WLAN_EID_EXT_*) |
| 1257 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 1258 | * |
| 1259 | * This function returns the first matching information element in the BSS |
| 1260 | * entry. |
| 1261 | */ |
| 1262 | const u8 * wpa_bss_get_ie_ext(const struct wpa_bss *bss, u8 ext) |
| 1263 | { |
| 1264 | return get_ie_ext(wpa_bss_ie_ptr(bss), bss->ie_len, ext); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1268 | /** |
| 1269 | * wpa_bss_get_vendor_ie - Fetch a vendor information element from a BSS entry |
| 1270 | * @bss: BSS table entry |
| 1271 | * @vendor_type: Vendor type (four octets starting the IE payload) |
| 1272 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 1273 | * |
| 1274 | * This function returns the first matching information element in the BSS |
| 1275 | * entry. |
| 1276 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1277 | const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type) |
| 1278 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1279 | const u8 *ies; |
| 1280 | const struct element *elem; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1281 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1282 | ies = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1283 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1284 | for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, bss->ie_len) { |
| 1285 | if (elem->datalen >= 4 && |
| 1286 | vendor_type == WPA_GET_BE32(elem->data)) |
| 1287 | return &elem->id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | return NULL; |
| 1291 | } |
| 1292 | |
| 1293 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1294 | /** |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1295 | * wpa_bss_get_vendor_ie_beacon - Fetch a vendor information from a BSS entry |
| 1296 | * @bss: BSS table entry |
| 1297 | * @vendor_type: Vendor type (four octets starting the IE payload) |
| 1298 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 1299 | * |
| 1300 | * This function returns the first matching information element in the BSS |
| 1301 | * entry. |
| 1302 | * |
| 1303 | * This function is like wpa_bss_get_vendor_ie(), but uses IE buffer only |
| 1304 | * from Beacon frames instead of either Beacon or Probe Response frames. |
| 1305 | */ |
| 1306 | const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss, |
| 1307 | u32 vendor_type) |
| 1308 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1309 | const u8 *ies; |
| 1310 | const struct element *elem; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1311 | |
| 1312 | if (bss->beacon_ie_len == 0) |
| 1313 | return NULL; |
| 1314 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1315 | ies = wpa_bss_ie_ptr(bss); |
| 1316 | ies += bss->ie_len; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1317 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1318 | for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, |
| 1319 | bss->beacon_ie_len) { |
| 1320 | if (elem->datalen >= 4 && |
| 1321 | vendor_type == WPA_GET_BE32(elem->data)) |
| 1322 | return &elem->id; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | return NULL; |
| 1326 | } |
| 1327 | |
| 1328 | |
| 1329 | /** |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1330 | * wpa_bss_get_vendor_ie_multi - Fetch vendor IE data from a BSS entry |
| 1331 | * @bss: BSS table entry |
| 1332 | * @vendor_type: Vendor type (four octets starting the IE payload) |
| 1333 | * Returns: Pointer to the information element payload or %NULL if not found |
| 1334 | * |
| 1335 | * This function returns concatenated payload of possibly fragmented vendor |
| 1336 | * specific information elements in the BSS entry. The caller is responsible for |
| 1337 | * freeing the returned buffer. |
| 1338 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1339 | struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss, |
| 1340 | u32 vendor_type) |
| 1341 | { |
| 1342 | struct wpabuf *buf; |
| 1343 | const u8 *end, *pos; |
| 1344 | |
| 1345 | buf = wpabuf_alloc(bss->ie_len); |
| 1346 | if (buf == NULL) |
| 1347 | return NULL; |
| 1348 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1349 | pos = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1350 | end = pos + bss->ie_len; |
| 1351 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1352 | while (end - pos > 1) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1353 | u8 ie, len; |
| 1354 | |
| 1355 | ie = pos[0]; |
| 1356 | len = pos[1]; |
| 1357 | if (len > end - pos - 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1358 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1359 | pos += 2; |
| 1360 | if (ie == WLAN_EID_VENDOR_SPECIFIC && len >= 4 && |
| 1361 | vendor_type == WPA_GET_BE32(pos)) |
| 1362 | wpabuf_put_data(buf, pos + 4, len - 4); |
| 1363 | pos += len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | if (wpabuf_len(buf) == 0) { |
| 1367 | wpabuf_free(buf); |
| 1368 | buf = NULL; |
| 1369 | } |
| 1370 | |
| 1371 | return buf; |
| 1372 | } |
| 1373 | |
| 1374 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1375 | /** |
| 1376 | * wpa_bss_get_vendor_ie_multi_beacon - Fetch vendor IE data from a BSS entry |
| 1377 | * @bss: BSS table entry |
| 1378 | * @vendor_type: Vendor type (four octets starting the IE payload) |
| 1379 | * Returns: Pointer to the information element payload or %NULL if not found |
| 1380 | * |
| 1381 | * This function returns concatenated payload of possibly fragmented vendor |
| 1382 | * specific information elements in the BSS entry. The caller is responsible for |
| 1383 | * freeing the returned buffer. |
| 1384 | * |
| 1385 | * This function is like wpa_bss_get_vendor_ie_multi(), but uses IE buffer only |
| 1386 | * from Beacon frames instead of either Beacon or Probe Response frames. |
| 1387 | */ |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1388 | struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss, |
| 1389 | u32 vendor_type) |
| 1390 | { |
| 1391 | struct wpabuf *buf; |
| 1392 | const u8 *end, *pos; |
| 1393 | |
| 1394 | buf = wpabuf_alloc(bss->beacon_ie_len); |
| 1395 | if (buf == NULL) |
| 1396 | return NULL; |
| 1397 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1398 | pos = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1399 | pos += bss->ie_len; |
| 1400 | end = pos + bss->beacon_ie_len; |
| 1401 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1402 | while (end - pos > 1) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1403 | u8 id, len; |
| 1404 | |
| 1405 | id = *pos++; |
| 1406 | len = *pos++; |
| 1407 | if (len > end - pos) |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1408 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1409 | if (id == WLAN_EID_VENDOR_SPECIFIC && len >= 4 && |
| 1410 | vendor_type == WPA_GET_BE32(pos)) |
| 1411 | wpabuf_put_data(buf, pos + 4, len - 4); |
| 1412 | pos += len; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | if (wpabuf_len(buf) == 0) { |
| 1416 | wpabuf_free(buf); |
| 1417 | buf = NULL; |
| 1418 | } |
| 1419 | |
| 1420 | return buf; |
| 1421 | } |
| 1422 | |
| 1423 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1424 | /** |
| 1425 | * wpa_bss_get_max_rate - Get maximum legacy TX rate supported in a BSS |
| 1426 | * @bss: BSS table entry |
| 1427 | * Returns: Maximum legacy rate in units of 500 kbps |
| 1428 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1429 | int wpa_bss_get_max_rate(const struct wpa_bss *bss) |
| 1430 | { |
| 1431 | int rate = 0; |
| 1432 | const u8 *ie; |
| 1433 | int i; |
| 1434 | |
| 1435 | ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES); |
| 1436 | for (i = 0; ie && i < ie[1]; i++) { |
| 1437 | if ((ie[i + 2] & 0x7f) > rate) |
| 1438 | rate = ie[i + 2] & 0x7f; |
| 1439 | } |
| 1440 | |
| 1441 | ie = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES); |
| 1442 | for (i = 0; ie && i < ie[1]; i++) { |
| 1443 | if ((ie[i + 2] & 0x7f) > rate) |
| 1444 | rate = ie[i + 2] & 0x7f; |
| 1445 | } |
| 1446 | |
| 1447 | return rate; |
| 1448 | } |
| 1449 | |
| 1450 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1451 | /** |
| 1452 | * wpa_bss_get_bit_rates - Get legacy TX rates supported in a BSS |
| 1453 | * @bss: BSS table entry |
| 1454 | * @rates: Buffer for returning a pointer to the rates list (units of 500 kbps) |
| 1455 | * Returns: number of legacy TX rates or -1 on failure |
| 1456 | * |
| 1457 | * The caller is responsible for freeing the returned buffer with os_free() in |
| 1458 | * case of success. |
| 1459 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1460 | int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates) |
| 1461 | { |
| 1462 | const u8 *ie, *ie2; |
| 1463 | int i, j; |
| 1464 | unsigned int len; |
| 1465 | u8 *r; |
| 1466 | |
| 1467 | ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES); |
| 1468 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES); |
| 1469 | |
| 1470 | len = (ie ? ie[1] : 0) + (ie2 ? ie2[1] : 0); |
| 1471 | |
| 1472 | r = os_malloc(len); |
| 1473 | if (!r) |
| 1474 | return -1; |
| 1475 | |
| 1476 | for (i = 0; ie && i < ie[1]; i++) |
| 1477 | r[i] = ie[i + 2] & 0x7f; |
| 1478 | |
| 1479 | for (j = 0; ie2 && j < ie2[1]; j++) |
| 1480 | r[i + j] = ie2[j + 2] & 0x7f; |
| 1481 | |
| 1482 | *rates = r; |
| 1483 | return len; |
| 1484 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1485 | |
| 1486 | |
| 1487 | #ifdef CONFIG_FILS |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1488 | const u8 * wpa_bss_get_fils_cache_id(const struct wpa_bss *bss) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1489 | { |
| 1490 | const u8 *ie; |
| 1491 | |
| 1492 | if (bss) { |
| 1493 | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); |
| 1494 | if (ie && ie[1] >= 4 && WPA_GET_LE16(ie + 2) & BIT(7)) |
| 1495 | return ie + 4; |
| 1496 | } |
| 1497 | |
| 1498 | return NULL; |
| 1499 | } |
| 1500 | #endif /* CONFIG_FILS */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1501 | |
| 1502 | |
| 1503 | int wpa_bss_ext_capab(const struct wpa_bss *bss, unsigned int capab) |
| 1504 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1505 | if (!bss) |
| 1506 | return 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1507 | return ieee802_11_ext_capab(wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB), |
| 1508 | capab); |
| 1509 | } |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1510 | |
| 1511 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1512 | static void |
| 1513 | wpa_bss_parse_ml_rnr_ap_info(struct wpa_supplicant *wpa_s, |
| 1514 | struct wpa_bss *bss, u8 mbssid_idx, |
| 1515 | const struct ieee80211_neighbor_ap_info *ap_info, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1516 | size_t len, u16 *seen, u16 *missing, |
| 1517 | struct wpa_ssid *ssid) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1518 | { |
| 1519 | const u8 *pos, *end; |
| 1520 | const u8 *mld_params; |
| 1521 | u8 count, mld_params_offset; |
| 1522 | u8 i, type, link_id; |
| 1523 | |
| 1524 | count = RNR_TBTT_INFO_COUNT_VAL(ap_info->tbtt_info_hdr) + 1; |
| 1525 | type = ap_info->tbtt_info_hdr & RNR_TBTT_INFO_HDR_TYPE_MSK; |
| 1526 | |
| 1527 | /* MLD information is at offset 13 or at start */ |
| 1528 | if (type == 0 && ap_info->tbtt_info_len >= RNR_TBTT_INFO_MLD_LEN) { |
| 1529 | /* MLD info is appended */ |
| 1530 | mld_params_offset = RNR_TBTT_INFO_LEN; |
| 1531 | } else { |
| 1532 | /* TODO: Support NSTR AP */ |
| 1533 | return; |
| 1534 | } |
| 1535 | |
| 1536 | pos = (const u8 *) ap_info; |
| 1537 | end = pos + len; |
| 1538 | pos += sizeof(*ap_info); |
| 1539 | |
| 1540 | for (i = 0; i < count; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1541 | u8 bss_params; |
| 1542 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1543 | if (end - pos < ap_info->tbtt_info_len) |
| 1544 | break; |
| 1545 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1546 | bss_params = pos[1 + ETH_ALEN + 4]; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1547 | mld_params = pos + mld_params_offset; |
| 1548 | |
| 1549 | link_id = *(mld_params + 1) & EHT_ML_LINK_ID_MSK; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1550 | if (link_id >= MAX_NUM_MLD_LINKS) |
| 1551 | return; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1552 | |
| 1553 | if (*mld_params != mbssid_idx) { |
| 1554 | wpa_printf(MSG_DEBUG, |
| 1555 | "MLD: Reported link not part of MLD"); |
| 1556 | } else if (!(BIT(link_id) & *seen)) { |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1557 | struct wpa_bss *neigh_bss; |
| 1558 | |
| 1559 | if (ssid && ssid->ssid_len) |
| 1560 | neigh_bss = wpa_bss_get(wpa_s, pos + 1, |
| 1561 | ssid->ssid, |
| 1562 | ssid->ssid_len); |
| 1563 | else |
| 1564 | neigh_bss = wpa_bss_get_bssid(wpa_s, pos + 1); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1565 | |
| 1566 | *seen |= BIT(link_id); |
| 1567 | wpa_printf(MSG_DEBUG, "MLD: mld ID=%u, link ID=%u", |
| 1568 | *mld_params, link_id); |
| 1569 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1570 | if (!neigh_bss) { |
| 1571 | *missing |= BIT(link_id); |
| 1572 | } else if ((!ssid || |
| 1573 | (bss_params & (RNR_BSS_PARAM_SAME_SSID | |
| 1574 | RNR_BSS_PARAM_CO_LOCATED)) || |
| 1575 | wpa_scan_res_match(wpa_s, 0, neigh_bss, |
| 1576 | ssid, 1, 0)) && |
| 1577 | !wpa_bssid_ignore_is_listed( |
| 1578 | wpa_s, neigh_bss->bssid)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1579 | struct mld_link *l; |
| 1580 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1581 | bss->valid_links |= BIT(link_id); |
| 1582 | l = &bss->mld_links[link_id]; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1583 | os_memcpy(l->bssid, pos + 1, ETH_ALEN); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1584 | l->freq = neigh_bss->freq; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1585 | l->disabled = mld_params[2] & |
| 1586 | RNR_TBTT_INFO_MLD_PARAM2_LINK_DISABLED; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | pos += ap_info->tbtt_info_len; |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | |
| 1595 | /** |
| 1596 | * wpa_bss_parse_basic_ml_element - Parse the Basic Multi-Link element |
| 1597 | * @wpa_s: Pointer to wpa_supplicant data |
| 1598 | * @bss: BSS table entry |
| 1599 | * @mld_addr: AP MLD address (or %NULL) |
| 1600 | * @link_info: Array to store link information (or %NULL), |
| 1601 | * should be initialized and #MAX_NUM_MLD_LINKS elements long |
| 1602 | * @missing_links: Result bitmask of links that were not discovered (or %NULL) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1603 | * @ssid: Target SSID (or %NULL) |
| 1604 | * @ap_mld_id: On return would hold the corresponding AP MLD ID (or %NULL) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1605 | * Returns: 0 on success or -1 for non-MLD or parsing failures |
| 1606 | * |
| 1607 | * Parses the Basic Multi-Link element of the BSS into @link_info using the scan |
| 1608 | * information stored in the wpa_supplicant data to fill in information for |
| 1609 | * links where possible. The @missing_links out parameter will contain any links |
| 1610 | * for which no corresponding BSS was found. |
| 1611 | */ |
| 1612 | int wpa_bss_parse_basic_ml_element(struct wpa_supplicant *wpa_s, |
| 1613 | struct wpa_bss *bss, |
| 1614 | u8 *ap_mld_addr, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1615 | u16 *missing_links, |
| 1616 | struct wpa_ssid *ssid, |
| 1617 | u8 *ap_mld_id) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1618 | { |
| 1619 | struct ieee802_11_elems elems; |
| 1620 | struct wpabuf *mlbuf; |
| 1621 | const struct element *elem; |
| 1622 | u8 mbssid_idx = 0; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1623 | size_t ml_ie_len; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1624 | const struct ieee80211_eht_ml *eht_ml; |
| 1625 | const struct eht_ml_basic_common_info *ml_basic_common_info; |
| 1626 | u8 i, link_id; |
| 1627 | const u16 control_mask = |
| 1628 | MULTI_LINK_CONTROL_TYPE_MASK | |
| 1629 | BASIC_MULTI_LINK_CTRL_PRES_LINK_ID | |
| 1630 | BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT | |
| 1631 | BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA; |
| 1632 | const u16 control = |
| 1633 | MULTI_LINK_CONTROL_TYPE_BASIC | |
| 1634 | BASIC_MULTI_LINK_CTRL_PRES_LINK_ID | |
| 1635 | BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT | |
| 1636 | BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA; |
| 1637 | u16 missing = 0; |
| 1638 | u16 seen; |
| 1639 | const u8 *ies_pos = wpa_bss_ie_ptr(bss); |
| 1640 | size_t ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
| 1641 | int ret = -1; |
| 1642 | struct mld_link *l; |
| 1643 | |
| 1644 | if (ieee802_11_parse_elems(ies_pos, ies_len, &elems, 1) == |
| 1645 | ParseFailed) { |
| 1646 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: Failed to parse elements"); |
| 1647 | return ret; |
| 1648 | } |
| 1649 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1650 | mlbuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1651 | if (!mlbuf) { |
| 1652 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No Multi-Link element"); |
| 1653 | return ret; |
| 1654 | } |
| 1655 | |
| 1656 | ml_ie_len = wpabuf_len(mlbuf); |
| 1657 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1658 | if (ssid) { |
| 1659 | struct wpa_ie_data ie; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1660 | const u8 *rsne; |
| 1661 | size_t rsne_len; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1662 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1663 | if (elems.rsne_override_2 && wpas_rsn_overriding(wpa_s)) { |
| 1664 | rsne = elems.rsne_override_2; |
| 1665 | rsne_len = elems.rsne_override_2_len; |
| 1666 | } else if (elems.rsne_override && |
| 1667 | wpas_rsn_overriding(wpa_s)) { |
| 1668 | rsne = elems.rsne_override; |
| 1669 | rsne_len = elems.rsne_override_len; |
| 1670 | } else { |
| 1671 | rsne = elems.rsn_ie; |
| 1672 | rsne_len = elems.rsn_ie_len; |
| 1673 | } |
| 1674 | if (!rsne || |
| 1675 | wpa_parse_wpa_ie(rsne - 2, 2 + rsne_len, &ie)) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1676 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No RSN element"); |
| 1677 | goto out; |
| 1678 | } |
| 1679 | |
| 1680 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) || |
| 1681 | wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION) { |
| 1682 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1683 | "MLD: No management frame protection"); |
| 1684 | goto out; |
| 1685 | } |
| 1686 | |
| 1687 | ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK | |
| 1688 | WPA_KEY_MGMT_PSK_SHA256); |
| 1689 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
| 1690 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1691 | "MLD: No valid key management"); |
| 1692 | goto out; |
| 1693 | } |
| 1694 | } |
| 1695 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1696 | /* |
| 1697 | * for ext ID + 2 control + common info len + MLD address + |
| 1698 | * link info |
| 1699 | */ |
| 1700 | if (ml_ie_len < 2UL + 1UL + ETH_ALEN + 1UL) |
| 1701 | goto out; |
| 1702 | |
| 1703 | eht_ml = (const struct ieee80211_eht_ml *) wpabuf_head(mlbuf); |
| 1704 | if ((le_to_host16(eht_ml->ml_control) & control_mask) != control) { |
| 1705 | wpa_printf(MSG_DEBUG, |
| 1706 | "MLD: Unexpected Multi-Link element control=0x%x (mask 0x%x expected 0x%x)", |
| 1707 | le_to_host16(eht_ml->ml_control), control_mask, |
| 1708 | control); |
| 1709 | goto out; |
| 1710 | } |
| 1711 | |
| 1712 | ml_basic_common_info = |
| 1713 | (const struct eht_ml_basic_common_info *) eht_ml->variable; |
| 1714 | |
| 1715 | /* Common info length should be valid */ |
| 1716 | if (ml_basic_common_info->len < ETH_ALEN + 1UL) |
| 1717 | goto out; |
| 1718 | |
| 1719 | /* Get the MLD address and MLD link ID */ |
| 1720 | if (ap_mld_addr) |
| 1721 | os_memcpy(ap_mld_addr, ml_basic_common_info->mld_addr, |
| 1722 | ETH_ALEN); |
| 1723 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1724 | link_id = ml_basic_common_info->variable[0] & EHT_ML_LINK_ID_MSK; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1725 | |
| 1726 | bss->mld_link_id = link_id; |
| 1727 | seen = bss->valid_links = BIT(link_id); |
| 1728 | |
| 1729 | l = &bss->mld_links[link_id]; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1730 | os_memcpy(l->bssid, bss->bssid, ETH_ALEN); |
| 1731 | l->freq = bss->freq; |
| 1732 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1733 | |
| 1734 | /* |
| 1735 | * The AP MLD ID in the RNR corresponds to the MBSSID index, see |
| 1736 | * IEEE P802.11be/D4.0, 9.4.2.169.2 (Neighbor AP Information field). |
| 1737 | * |
| 1738 | * For the transmitting BSSID it is clear that both the MBSSID index |
| 1739 | * and the AP MLD ID in the RNR are zero. |
| 1740 | * |
| 1741 | * For nontransmitted BSSIDs we will have a BSS generated from the |
| 1742 | * MBSSID element(s) using inheritance rules. Included in the elements |
| 1743 | * is the MBSSID Index Element. The RNR is copied from the Beacon/Probe |
| 1744 | * Response frame that was send by the transmitting BSSID. As such, the |
| 1745 | * reported AP MLD ID in the RNR will match the value in the MBSSID |
| 1746 | * Index Element. |
| 1747 | */ |
| 1748 | elem = (const struct element *) |
| 1749 | wpa_bss_get_ie(bss, WLAN_EID_MULTIPLE_BSSID_INDEX); |
| 1750 | if (elem && elem->datalen >= 1) |
| 1751 | mbssid_idx = elem->data[0]; |
| 1752 | |
| 1753 | for_each_element_id(elem, WLAN_EID_REDUCED_NEIGHBOR_REPORT, |
| 1754 | wpa_bss_ie_ptr(bss), |
| 1755 | bss->ie_len ? bss->ie_len : bss->beacon_ie_len) { |
| 1756 | const struct ieee80211_neighbor_ap_info *ap_info; |
| 1757 | const u8 *pos = elem->data; |
| 1758 | size_t len = elem->datalen; |
| 1759 | |
| 1760 | /* RNR IE may contain more than one Neighbor AP Info */ |
| 1761 | while (sizeof(*ap_info) <= len) { |
| 1762 | size_t ap_info_len = sizeof(*ap_info); |
| 1763 | u8 count; |
| 1764 | |
| 1765 | ap_info = (const struct ieee80211_neighbor_ap_info *) |
| 1766 | pos; |
| 1767 | count = RNR_TBTT_INFO_COUNT_VAL(ap_info->tbtt_info_hdr) + 1; |
| 1768 | ap_info_len += count * ap_info->tbtt_info_len; |
| 1769 | |
| 1770 | if (ap_info_len > len) |
| 1771 | goto out; |
| 1772 | |
| 1773 | wpa_bss_parse_ml_rnr_ap_info(wpa_s, bss, mbssid_idx, |
| 1774 | ap_info, len, &seen, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1775 | &missing, ssid); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1776 | |
| 1777 | pos += ap_info_len; |
| 1778 | len -= ap_info_len; |
| 1779 | } |
| 1780 | } |
| 1781 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1782 | wpa_printf(MSG_DEBUG, "MLD: valid_links=%04hx (unresolved: 0x%04hx)", |
| 1783 | bss->valid_links, missing); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1784 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1785 | for_each_link(bss->valid_links, i) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1786 | wpa_printf(MSG_DEBUG, "MLD: link=%u, bssid=" MACSTR, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1787 | i, MAC2STR(bss->mld_links[i].bssid)); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | if (missing_links) |
| 1791 | *missing_links = missing; |
| 1792 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1793 | if (ap_mld_id) |
| 1794 | *ap_mld_id = mbssid_idx; |
| 1795 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1796 | ret = 0; |
| 1797 | out: |
| 1798 | wpabuf_free(mlbuf); |
| 1799 | return ret; |
| 1800 | } |
| 1801 | |
| 1802 | |
| 1803 | /* |
| 1804 | * wpa_bss_parse_reconf_ml_element - Parse the Reconfiguration ML element |
| 1805 | * @wpa_s: Pointer to wpa_supplicant data |
| 1806 | * @bss: BSS table entry |
| 1807 | * Returns: The bitmap of links that are going to be removed |
| 1808 | */ |
| 1809 | u16 wpa_bss_parse_reconf_ml_element(struct wpa_supplicant *wpa_s, |
| 1810 | struct wpa_bss *bss) |
| 1811 | { |
| 1812 | struct ieee802_11_elems elems; |
| 1813 | struct wpabuf *mlbuf; |
| 1814 | const u8 *pos = wpa_bss_ie_ptr(bss); |
| 1815 | size_t len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
| 1816 | const struct ieee80211_eht_ml *ml; |
| 1817 | u16 removed_links = 0; |
| 1818 | u8 ml_common_len; |
| 1819 | |
| 1820 | if (ieee802_11_parse_elems(pos, len, &elems, 1) == ParseFailed) |
| 1821 | return 0; |
| 1822 | |
| 1823 | if (!elems.reconf_mle || !elems.reconf_mle_len) |
| 1824 | return 0; |
| 1825 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1826 | mlbuf = ieee802_11_defrag(elems.reconf_mle, elems.reconf_mle_len, true); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1827 | if (!mlbuf) |
| 1828 | return 0; |
| 1829 | |
| 1830 | ml = (const struct ieee80211_eht_ml *) wpabuf_head(mlbuf); |
| 1831 | len = wpabuf_len(mlbuf); |
| 1832 | |
| 1833 | if (len < sizeof(*ml)) |
| 1834 | goto out; |
| 1835 | |
| 1836 | ml_common_len = 1; |
| 1837 | if (ml->ml_control & RECONF_MULTI_LINK_CTRL_PRES_MLD_MAC_ADDR) |
| 1838 | ml_common_len += ETH_ALEN; |
| 1839 | |
| 1840 | if (len < sizeof(*ml) + ml_common_len) { |
| 1841 | wpa_printf(MSG_DEBUG, |
| 1842 | "MLD: Unexpected Reconfiguration ML element length: (%zu < %zu)", |
| 1843 | len, sizeof(*ml) + ml_common_len); |
| 1844 | goto out; |
| 1845 | } |
| 1846 | |
| 1847 | pos = ml->variable + ml_common_len; |
| 1848 | len -= sizeof(*ml) + ml_common_len; |
| 1849 | |
| 1850 | while (len >= 2 + sizeof(struct ieee80211_eht_per_sta_profile)) { |
| 1851 | size_t sub_elem_len = *(pos + 1); |
| 1852 | |
| 1853 | if (2 + sub_elem_len > len) { |
| 1854 | wpa_printf(MSG_DEBUG, |
| 1855 | "MLD: Invalid link info len: %zu %zu", |
| 1856 | 2 + sub_elem_len, len); |
| 1857 | goto out; |
| 1858 | } |
| 1859 | |
| 1860 | if (*pos == EHT_ML_SUB_ELEM_PER_STA_PROFILE) { |
| 1861 | const struct ieee80211_eht_per_sta_profile *sta_prof = |
| 1862 | (const struct ieee80211_eht_per_sta_profile *) |
| 1863 | (pos + 2); |
| 1864 | u16 control = le_to_host16(sta_prof->sta_control); |
| 1865 | u8 link_id; |
| 1866 | |
| 1867 | link_id = control & EHT_PER_STA_RECONF_CTRL_LINK_ID_MSK; |
| 1868 | removed_links |= BIT(link_id); |
| 1869 | } |
| 1870 | |
| 1871 | pos += 2 + sub_elem_len; |
| 1872 | len -= 2 + sub_elem_len; |
| 1873 | } |
| 1874 | |
| 1875 | wpa_printf(MSG_DEBUG, "MLD: Reconfiguration: removed_links=0x%x", |
| 1876 | removed_links); |
| 1877 | out: |
| 1878 | wpabuf_free(mlbuf); |
| 1879 | return removed_links; |
| 1880 | } |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1881 | |
| 1882 | |
| 1883 | static bool wpa_bss_supported_cipher(struct wpa_supplicant *wpa_s, |
| 1884 | int pairwise_cipher) |
| 1885 | { |
| 1886 | if (!wpa_s->drv_enc) |
| 1887 | return true; |
| 1888 | |
| 1889 | if ((pairwise_cipher & WPA_CIPHER_CCMP) && |
| 1890 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_CCMP)) |
| 1891 | return true; |
| 1892 | |
| 1893 | if ((pairwise_cipher & WPA_CIPHER_GCMP) && |
| 1894 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP)) |
| 1895 | return true; |
| 1896 | |
| 1897 | if ((pairwise_cipher & WPA_CIPHER_CCMP_256) && |
| 1898 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_CCMP_256)) |
| 1899 | return true; |
| 1900 | |
| 1901 | if ((pairwise_cipher & WPA_CIPHER_GCMP_256) && |
| 1902 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP_256)) |
| 1903 | return true; |
| 1904 | |
| 1905 | return false; |
| 1906 | } |
| 1907 | |
| 1908 | |
| 1909 | static bool wpa_bss_supported_key_mgmt(struct wpa_supplicant *wpa_s, |
| 1910 | int key_mgmt) |
| 1911 | { |
| 1912 | if (!wpa_s->drv_key_mgmt) |
| 1913 | return true; |
| 1914 | |
| 1915 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X) && |
| 1916 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) |
| 1917 | return true; |
| 1918 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) && |
| 1919 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256)) |
| 1920 | return true; |
| 1921 | if ((key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) && |
| 1922 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT)) |
| 1923 | return true; |
| 1924 | if ((key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) && |
| 1925 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384)) |
| 1926 | return true; |
| 1927 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) && |
| 1928 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B)) |
| 1929 | return true; |
| 1930 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) && |
| 1931 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192)) |
| 1932 | return true; |
| 1933 | if ((key_mgmt & WPA_KEY_MGMT_PSK) && |
| 1934 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) |
| 1935 | return true; |
| 1936 | if ((key_mgmt & WPA_KEY_MGMT_FT_PSK) && |
| 1937 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK)) |
| 1938 | return true; |
| 1939 | if ((key_mgmt & WPA_KEY_MGMT_PSK_SHA256) && |
| 1940 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256)) |
| 1941 | return true; |
| 1942 | if ((key_mgmt & WPA_KEY_MGMT_SAE) && |
| 1943 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE)) |
| 1944 | return true; |
| 1945 | if ((key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) && |
| 1946 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY)) |
| 1947 | return true; |
| 1948 | if ((key_mgmt & WPA_KEY_MGMT_FT_SAE) && |
| 1949 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE)) |
| 1950 | return true; |
| 1951 | if ((key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) && |
| 1952 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY)) |
| 1953 | return true; |
| 1954 | if ((key_mgmt & WPA_KEY_MGMT_OWE) && |
| 1955 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE)) |
| 1956 | return true; |
| 1957 | if ((key_mgmt & WPA_KEY_MGMT_DPP) && |
| 1958 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP)) |
| 1959 | return true; |
| 1960 | if ((key_mgmt & WPA_KEY_MGMT_FILS_SHA256) && |
| 1961 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256)) |
| 1962 | return true; |
| 1963 | if ((key_mgmt & WPA_KEY_MGMT_FILS_SHA384) && |
| 1964 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384)) |
| 1965 | return true; |
| 1966 | if ((key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) && |
| 1967 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256)) |
| 1968 | return true; |
| 1969 | if ((key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) && |
| 1970 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384)) |
| 1971 | return true; |
| 1972 | |
| 1973 | return false; |
| 1974 | } |
| 1975 | |
| 1976 | |
| 1977 | static bool wpa_bss_supported_rsne(struct wpa_supplicant *wpa_s, |
| 1978 | struct wpa_ssid *ssid, const u8 *ie) |
| 1979 | { |
| 1980 | struct wpa_ie_data data; |
| 1981 | |
| 1982 | if (wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) < 0) |
| 1983 | return false; |
| 1984 | |
| 1985 | /* Check that there is a supported AKM and pairwise cipher based on |
| 1986 | * overall capabilities */ |
| 1987 | if (!data.pairwise_cipher || !data.key_mgmt) |
| 1988 | return false; |
| 1989 | |
| 1990 | if (wpa_s->drv_capa_known) { |
| 1991 | if (!wpa_bss_supported_cipher(wpa_s, data.pairwise_cipher) || |
| 1992 | !wpa_bss_supported_key_mgmt(wpa_s, data.key_mgmt)) |
| 1993 | return false; |
| 1994 | } |
| 1995 | |
| 1996 | if (ssid) { |
| 1997 | /* Check that there is a supported AKM and pairwise cipher |
| 1998 | * based on the specific network profile. */ |
| 1999 | if ((ssid->pairwise_cipher & data.pairwise_cipher) == 0) |
| 2000 | return false; |
| 2001 | if ((ssid->key_mgmt & data.key_mgmt) == 0) |
| 2002 | return false; |
| 2003 | } |
| 2004 | |
| 2005 | return true; |
| 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | const u8 * wpa_bss_get_rsne(struct wpa_supplicant *wpa_s, |
| 2010 | const struct wpa_bss *bss, struct wpa_ssid *ssid, |
| 2011 | bool mlo) |
| 2012 | { |
| 2013 | const u8 *ie; |
| 2014 | |
| 2015 | if (wpas_rsn_overriding(wpa_s)) { |
| 2016 | if (!ssid) |
| 2017 | ssid = wpa_s->current_ssid; |
| 2018 | |
| 2019 | /* MLO cases for RSN overriding are required to use RSNE |
| 2020 | * Override 2 element and RSNXE Override element together. */ |
| 2021 | ie = wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE); |
| 2022 | if (mlo && ie && |
| 2023 | !wpa_bss_get_vendor_ie(bss, |
| 2024 | RSNXE_OVERRIDE_IE_VENDOR_TYPE)) { |
| 2025 | wpa_printf(MSG_DEBUG, "BSS " MACSTR |
| 2026 | " advertises RSNE Override 2 element without RSNXE Override element - ignore RSNE Override 2 element for MLO", |
| 2027 | MAC2STR(bss->bssid)); |
| 2028 | } else if (ie && wpa_bss_supported_rsne(wpa_s, ssid, ie)) { |
| 2029 | return ie; |
| 2030 | } |
| 2031 | |
| 2032 | if (!mlo) { |
| 2033 | ie = wpa_bss_get_vendor_ie( |
| 2034 | bss, RSNE_OVERRIDE_IE_VENDOR_TYPE); |
| 2035 | if (ie && wpa_bss_supported_rsne(wpa_s, ssid, ie)) |
| 2036 | return ie; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | return wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 2041 | } |
| 2042 | |
| 2043 | |
| 2044 | const u8 * wpa_bss_get_rsnxe(struct wpa_supplicant *wpa_s, |
| 2045 | const struct wpa_bss *bss, struct wpa_ssid *ssid, |
| 2046 | bool mlo) |
| 2047 | { |
| 2048 | const u8 *ie; |
| 2049 | |
| 2050 | if (wpas_rsn_overriding(wpa_s)) { |
| 2051 | ie = wpa_bss_get_vendor_ie(bss, RSNXE_OVERRIDE_IE_VENDOR_TYPE); |
| 2052 | if (ie) { |
| 2053 | const u8 *tmp; |
| 2054 | |
| 2055 | tmp = wpa_bss_get_rsne(wpa_s, bss, ssid, mlo); |
| 2056 | if (!tmp || tmp[0] == WLAN_EID_RSN) { |
| 2057 | /* An acceptable RSNE override element was not |
| 2058 | * found, so need to ignore RSNXE overriding. */ |
| 2059 | goto out; |
| 2060 | } |
| 2061 | |
| 2062 | return ie; |
| 2063 | } |
| 2064 | |
| 2065 | /* MLO cases for RSN overriding are required to use RSNE |
| 2066 | * Override 2 element and RSNXE Override element together. */ |
| 2067 | if (mlo && wpa_bss_get_vendor_ie( |
| 2068 | bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE)) { |
| 2069 | wpa_printf(MSG_DEBUG, "BSS " MACSTR |
| 2070 | " advertises RSNXE Override element without RSNE Override 2 element - ignore RSNXE Override element for MLO", |
| 2071 | MAC2STR(bss->bssid)); |
| 2072 | goto out; |
| 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | out: |
| 2077 | return wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
| 2078 | } |