/src/hostap/wpa_supplicant/bss.c
Line | Count | Source |
1 | | /* |
2 | | * BSS table |
3 | | * Copyright (c) 2009-2019, Jouni Malinen <j@w1.fi> |
4 | | * |
5 | | * This software may be distributed under the terms of the BSD license. |
6 | | * See README for more details. |
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" |
15 | | #include "eap_peer/eap.h" |
16 | | #include "rsn_supp/wpa.h" |
17 | | #include "wpa_supplicant_i.h" |
18 | | #include "config.h" |
19 | | #include "notify.h" |
20 | | #include "scan.h" |
21 | | #include "bssid_ignore.h" |
22 | | #include "bss.h" |
23 | | |
24 | | static void wpa_bss_set_hessid(struct wpa_bss *bss) |
25 | 3.09k | { |
26 | 3.09k | #ifdef CONFIG_INTERWORKING |
27 | 3.09k | const u8 *ie = wpa_bss_get_ie(bss, WLAN_EID_INTERWORKING); |
28 | 3.09k | if (ie == NULL || (ie[1] != 7 && ie[1] != 9)) { |
29 | 3.08k | os_memset(bss->hessid, 0, ETH_ALEN); |
30 | 3.08k | return; |
31 | 3.08k | } |
32 | 15 | if (ie[1] == 7) |
33 | 13 | os_memcpy(bss->hessid, ie + 3, ETH_ALEN); |
34 | 2 | else |
35 | 2 | os_memcpy(bss->hessid, ie + 5, ETH_ALEN); |
36 | 15 | #endif /* CONFIG_INTERWORKING */ |
37 | 15 | } |
38 | | |
39 | | |
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 | | */ |
48 | | struct wpa_bss_anqp * wpa_bss_anqp_alloc(void) |
49 | 0 | { |
50 | 0 | struct wpa_bss_anqp *anqp; |
51 | 0 | anqp = os_zalloc(sizeof(*anqp)); |
52 | 0 | if (anqp == NULL) |
53 | 0 | return NULL; |
54 | 0 | #ifdef CONFIG_INTERWORKING |
55 | 0 | dl_list_init(&anqp->anqp_elems); |
56 | 0 | #endif /* CONFIG_INTERWORKING */ |
57 | 0 | anqp->users = 1; |
58 | 0 | return anqp; |
59 | 0 | } |
60 | | |
61 | | |
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 | | */ |
67 | | static struct wpa_bss_anqp * wpa_bss_anqp_clone(struct wpa_bss_anqp *anqp) |
68 | 0 | { |
69 | 0 | struct wpa_bss_anqp *n; |
70 | |
|
71 | 0 | n = os_zalloc(sizeof(*n)); |
72 | 0 | if (n == NULL) |
73 | 0 | return NULL; |
74 | | |
75 | 0 | #define ANQP_DUP(f) if (anqp->f) n->f = wpabuf_dup(anqp->f) |
76 | 0 | #ifdef CONFIG_INTERWORKING |
77 | 0 | dl_list_init(&n->anqp_elems); |
78 | 0 | ANQP_DUP(capability_list); |
79 | 0 | ANQP_DUP(venue_name); |
80 | 0 | ANQP_DUP(network_auth_type); |
81 | 0 | ANQP_DUP(roaming_consortium); |
82 | 0 | ANQP_DUP(ip_addr_type_availability); |
83 | 0 | ANQP_DUP(nai_realm); |
84 | 0 | ANQP_DUP(anqp_3gpp); |
85 | 0 | ANQP_DUP(domain_name); |
86 | 0 | ANQP_DUP(fils_realm_info); |
87 | 0 | #endif /* CONFIG_INTERWORKING */ |
88 | 0 | #ifdef CONFIG_HS20 |
89 | 0 | ANQP_DUP(hs20_capability_list); |
90 | 0 | ANQP_DUP(hs20_operator_friendly_name); |
91 | 0 | ANQP_DUP(hs20_wan_metrics); |
92 | 0 | ANQP_DUP(hs20_connection_capability); |
93 | 0 | ANQP_DUP(hs20_operating_class); |
94 | 0 | #endif /* CONFIG_HS20 */ |
95 | 0 | #undef ANQP_DUP |
96 | |
|
97 | 0 | return n; |
98 | 0 | } |
99 | | |
100 | | |
101 | | /** |
102 | | * wpa_bss_anqp_unshare_alloc - Unshare ANQP data (if shared) in a BSS entry |
103 | | * @bss: BSS entry |
104 | | * Returns: 0 on success, -1 on failure |
105 | | * |
106 | | * This function ensures the specific BSS entry has an ANQP data structure that |
107 | | * is not shared with any other BSS entry. |
108 | | */ |
109 | | int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss) |
110 | 0 | { |
111 | 0 | struct wpa_bss_anqp *anqp; |
112 | |
|
113 | 0 | if (bss->anqp && bss->anqp->users > 1) { |
114 | | /* allocated, but shared - clone an unshared copy */ |
115 | 0 | anqp = wpa_bss_anqp_clone(bss->anqp); |
116 | 0 | if (anqp == NULL) |
117 | 0 | return -1; |
118 | 0 | anqp->users = 1; |
119 | 0 | bss->anqp->users--; |
120 | 0 | bss->anqp = anqp; |
121 | 0 | return 0; |
122 | 0 | } |
123 | | |
124 | 0 | if (bss->anqp) |
125 | 0 | return 0; /* already allocated and not shared */ |
126 | | |
127 | | /* not allocated - allocate a new storage area */ |
128 | 0 | bss->anqp = wpa_bss_anqp_alloc(); |
129 | 0 | return bss->anqp ? 0 : -1; |
130 | 0 | } |
131 | | |
132 | | |
133 | | /** |
134 | | * wpa_bss_anqp_free - Free an ANQP data structure |
135 | | * @anqp: ANQP data structure from wpa_bss_anqp_alloc() or wpa_bss_anqp_clone() |
136 | | */ |
137 | | static void wpa_bss_anqp_free(struct wpa_bss_anqp *anqp) |
138 | 3.09k | { |
139 | 3.09k | #ifdef CONFIG_INTERWORKING |
140 | 3.09k | struct wpa_bss_anqp_elem *elem; |
141 | 3.09k | #endif /* CONFIG_INTERWORKING */ |
142 | | |
143 | 3.09k | if (anqp == NULL) |
144 | 3.09k | return; |
145 | | |
146 | 0 | anqp->users--; |
147 | 0 | if (anqp->users > 0) { |
148 | | /* Another BSS entry holds a pointer to this ANQP info */ |
149 | 0 | return; |
150 | 0 | } |
151 | | |
152 | 0 | #ifdef CONFIG_INTERWORKING |
153 | 0 | wpabuf_free(anqp->capability_list); |
154 | 0 | wpabuf_free(anqp->venue_name); |
155 | 0 | wpabuf_free(anqp->network_auth_type); |
156 | 0 | wpabuf_free(anqp->roaming_consortium); |
157 | 0 | wpabuf_free(anqp->ip_addr_type_availability); |
158 | 0 | wpabuf_free(anqp->nai_realm); |
159 | 0 | wpabuf_free(anqp->anqp_3gpp); |
160 | 0 | wpabuf_free(anqp->domain_name); |
161 | 0 | wpabuf_free(anqp->fils_realm_info); |
162 | |
|
163 | 0 | while ((elem = dl_list_first(&anqp->anqp_elems, |
164 | 0 | struct wpa_bss_anqp_elem, list))) { |
165 | 0 | dl_list_del(&elem->list); |
166 | 0 | wpabuf_free(elem->payload); |
167 | 0 | os_free(elem); |
168 | 0 | } |
169 | 0 | #endif /* CONFIG_INTERWORKING */ |
170 | 0 | #ifdef CONFIG_HS20 |
171 | 0 | wpabuf_free(anqp->hs20_capability_list); |
172 | 0 | wpabuf_free(anqp->hs20_operator_friendly_name); |
173 | 0 | wpabuf_free(anqp->hs20_wan_metrics); |
174 | 0 | wpabuf_free(anqp->hs20_connection_capability); |
175 | 0 | wpabuf_free(anqp->hs20_operating_class); |
176 | 0 | #endif /* CONFIG_HS20 */ |
177 | |
|
178 | 0 | os_free(anqp); |
179 | 0 | } |
180 | | |
181 | | |
182 | | static struct wpa_connect_work * |
183 | | wpa_bss_check_pending_connect(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
184 | 3.09k | { |
185 | 3.09k | struct wpa_radio_work *work; |
186 | 3.09k | struct wpa_connect_work *cwork; |
187 | | |
188 | 3.09k | work = radio_work_pending(wpa_s, "sme-connect"); |
189 | 3.09k | if (!work) |
190 | 3.09k | work = radio_work_pending(wpa_s, "connect"); |
191 | 3.09k | if (!work) |
192 | 3.09k | return NULL; |
193 | | |
194 | 0 | cwork = work->ctx; |
195 | 0 | if (cwork->bss != bss) |
196 | 0 | return NULL; |
197 | | |
198 | 0 | return cwork; |
199 | 0 | } |
200 | | |
201 | | |
202 | | static void wpa_bss_update_pending_connect(struct wpa_connect_work *cwork, |
203 | | struct wpa_bss *new_bss) |
204 | 0 | { |
205 | 0 | wpa_printf(MSG_DEBUG, |
206 | 0 | "Update BSS pointer for the pending connect radio work"); |
207 | 0 | cwork->bss = new_bss; |
208 | 0 | if (!new_bss) |
209 | 0 | cwork->bss_removed = 1; |
210 | 0 | } |
211 | | |
212 | | |
213 | | void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
214 | | const char *reason) |
215 | 3.09k | { |
216 | 3.09k | struct wpa_connect_work *cwork; |
217 | 3.09k | unsigned int j; |
218 | | |
219 | 3.09k | if (wpa_s->last_scan_res) { |
220 | 3.09k | unsigned int i; |
221 | 3.09k | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
222 | 3.09k | if (wpa_s->last_scan_res[i] == bss) { |
223 | 3.09k | os_memmove(&wpa_s->last_scan_res[i], |
224 | 3.09k | &wpa_s->last_scan_res[i + 1], |
225 | 3.09k | (wpa_s->last_scan_res_used - i - 1) |
226 | 3.09k | * sizeof(struct wpa_bss *)); |
227 | 3.09k | wpa_s->last_scan_res_used--; |
228 | 3.09k | break; |
229 | 3.09k | } |
230 | 3.09k | } |
231 | 3.09k | } |
232 | 3.09k | cwork = wpa_bss_check_pending_connect(wpa_s, bss); |
233 | 3.09k | if (cwork) |
234 | 0 | wpa_bss_update_pending_connect(cwork, NULL); |
235 | 3.09k | dl_list_del(&bss->list); |
236 | 3.09k | dl_list_del(&bss->list_id); |
237 | 3.09k | wpa_s->num_bss--; |
238 | 3.09k | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Remove id %u BSSID " MACSTR |
239 | 3.09k | " SSID '%s' due to %s", bss->id, MAC2STR(bss->bssid), |
240 | 3.09k | wpa_ssid_txt(bss->ssid, bss->ssid_len), reason); |
241 | 3.09k | wpas_notify_bss_removed(wpa_s, bss->bssid, bss->id); |
242 | 3.09k | wpa_bss_anqp_free(bss->anqp); |
243 | | |
244 | 3.09k | if (wpa_s->current_bss == bss) { |
245 | 0 | wpa_printf(MSG_DEBUG, |
246 | 0 | "BSS: Clear current_bss due to bss removal"); |
247 | 0 | wpa_s->current_bss = NULL; |
248 | 0 | } |
249 | | |
250 | 3.09k | #ifdef CONFIG_INTERWORKING |
251 | 3.09k | if (wpa_s->interworking_gas_bss == bss) { |
252 | 0 | wpa_printf(MSG_DEBUG, |
253 | 0 | "BSS: Clear interworking_gas_bss due to bss removal"); |
254 | 0 | wpa_s->interworking_gas_bss = NULL; |
255 | 0 | } |
256 | 3.09k | #endif /* CONFIG_INTERWORKING */ |
257 | | |
258 | 3.09k | #ifdef CONFIG_WNM |
259 | 3.09k | if (wpa_s->wnm_target_bss == bss) { |
260 | 0 | wpa_printf(MSG_DEBUG, |
261 | 0 | "BSS: Clear wnm_target_bss due to bss removal"); |
262 | 0 | wpa_s->wnm_target_bss = NULL; |
263 | 0 | } |
264 | 3.09k | #endif /* CONFIG_WNM */ |
265 | | |
266 | 3.09k | if (wpa_s->ml_connect_probe_bss == bss) { |
267 | 0 | wpa_printf(MSG_DEBUG, |
268 | 0 | "BSS: Clear ml_connect_probe_bss due to bss removal"); |
269 | 0 | wpa_s->ml_connect_probe_bss = NULL; |
270 | 0 | } |
271 | | |
272 | 49.5k | for (j = 0; j < MAX_NUM_MLD_LINKS; j++) { |
273 | 46.4k | if (wpa_s->links[j].bss == bss) { |
274 | 0 | wpa_printf(MSG_DEBUG, |
275 | 0 | "BSS: Clear links[%d].bss due to bss removal", |
276 | 0 | j); |
277 | 0 | wpa_s->valid_links &= ~BIT(j); |
278 | 0 | wpa_s->links[j].bss = NULL; |
279 | 0 | } |
280 | 46.4k | } |
281 | | |
282 | 3.09k | os_free(bss); |
283 | 3.09k | } |
284 | | |
285 | | |
286 | | /** |
287 | | * wpa_bss_get - Fetch a BSS table entry based on BSSID and SSID |
288 | | * @wpa_s: Pointer to wpa_supplicant data |
289 | | * @bssid: BSSID, or %NULL to match any BSSID |
290 | | * @ssid: SSID |
291 | | * @ssid_len: Length of @ssid |
292 | | * Returns: Pointer to the BSS entry or %NULL if not found |
293 | | */ |
294 | | struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid, |
295 | | const u8 *ssid, size_t ssid_len) |
296 | 3.09k | { |
297 | 3.09k | struct wpa_bss *bss; |
298 | | |
299 | 3.09k | if (bssid && !wpa_supplicant_filter_bssid_match(wpa_s, bssid)) |
300 | 0 | return NULL; |
301 | 3.09k | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
302 | 0 | if ((!bssid || ether_addr_equal(bss->bssid, bssid)) && |
303 | 0 | bss->ssid_len == ssid_len && |
304 | 0 | os_memcmp(bss->ssid, ssid, ssid_len) == 0) |
305 | 0 | return bss; |
306 | 0 | } |
307 | 3.09k | return NULL; |
308 | 3.09k | } |
309 | | |
310 | | /** |
311 | | * wpa_bss_get_connection - Fetch a BSS table entry based on BSSID and SSID. |
312 | | * @wpa_s: Pointer to wpa_supplicant data |
313 | | * @bssid: BSSID, or %NULL to match any BSSID |
314 | | * @ssid: SSID |
315 | | * @ssid_len: Length of @ssid |
316 | | * Returns: Pointer to the BSS entry or %NULL if not found |
317 | | * |
318 | | * This function is similar to wpa_bss_get() but it will also return OWE |
319 | | * transition mode encrypted networks for which transition-element matches |
320 | | * @ssid. |
321 | | */ |
322 | | struct wpa_bss * wpa_bss_get_connection(struct wpa_supplicant *wpa_s, |
323 | | const u8 *bssid, |
324 | | const u8 *ssid, size_t ssid_len) |
325 | 0 | { |
326 | 0 | struct wpa_bss *bss; |
327 | | #ifdef CONFIG_OWE |
328 | | const u8 *owe, *owe_bssid, *owe_ssid; |
329 | | size_t owe_ssid_len; |
330 | | #endif /* CONFIG_OWE */ |
331 | |
|
332 | 0 | if (bssid && !wpa_supplicant_filter_bssid_match(wpa_s, bssid)) |
333 | 0 | return NULL; |
334 | 0 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
335 | 0 | if (bssid && !ether_addr_equal(bss->bssid, bssid)) |
336 | 0 | continue; |
337 | | |
338 | 0 | if (bss->ssid_len == ssid_len && |
339 | 0 | os_memcmp(bss->ssid, ssid, ssid_len) == 0) |
340 | 0 | return bss; |
341 | |
|
342 | | #ifdef CONFIG_OWE |
343 | | /* Check if OWE transition mode element is present and matches |
344 | | * the SSID */ |
345 | | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
346 | | if (!owe) |
347 | | continue; |
348 | | |
349 | | if (wpas_get_owe_trans_network(owe, &owe_bssid, &owe_ssid, |
350 | | &owe_ssid_len)) |
351 | | continue; |
352 | | |
353 | | if (bss->ssid_len && |
354 | | owe_ssid_len == ssid_len && |
355 | | os_memcmp(owe_ssid, ssid, ssid_len) == 0) |
356 | | return bss; |
357 | | #endif /* CONFIG_OWE */ |
358 | 0 | } |
359 | 0 | return NULL; |
360 | 0 | } |
361 | | |
362 | | |
363 | | void calculate_update_time(const struct os_reltime *fetch_time, |
364 | | unsigned int age_ms, |
365 | | struct os_reltime *update_time) |
366 | 3.09k | { |
367 | 3.09k | os_time_t usec; |
368 | | |
369 | 3.09k | update_time->sec = fetch_time->sec; |
370 | 3.09k | update_time->usec = fetch_time->usec; |
371 | 3.09k | update_time->sec -= age_ms / 1000; |
372 | 3.09k | usec = (age_ms % 1000) * 1000; |
373 | 3.09k | if (update_time->usec < usec) { |
374 | 0 | update_time->sec--; |
375 | 0 | update_time->usec += 1000000; |
376 | 0 | } |
377 | 3.09k | update_time->usec -= usec; |
378 | 3.09k | } |
379 | | |
380 | | |
381 | | static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src, |
382 | | struct os_reltime *fetch_time) |
383 | 3.09k | { |
384 | 3.09k | dst->flags = src->flags; |
385 | 3.09k | os_memcpy(dst->bssid, src->bssid, ETH_ALEN); |
386 | 3.09k | dst->freq = src->freq; |
387 | 3.09k | dst->max_cw = src->max_cw; |
388 | 3.09k | dst->beacon_int = src->beacon_int; |
389 | 3.09k | dst->caps = src->caps; |
390 | 3.09k | dst->qual = src->qual; |
391 | 3.09k | dst->noise = src->noise; |
392 | 3.09k | dst->level = src->level; |
393 | 3.09k | dst->tsf = src->tsf; |
394 | 3.09k | dst->beacon_newer = src->beacon_newer; |
395 | 3.09k | dst->est_throughput = src->est_throughput; |
396 | 3.09k | dst->snr = src->snr; |
397 | | |
398 | 3.09k | calculate_update_time(fetch_time, src->age, &dst->last_update); |
399 | 3.09k | } |
400 | | |
401 | | |
402 | | static int wpa_bss_is_wps_candidate(struct wpa_supplicant *wpa_s, |
403 | | struct wpa_bss *bss) |
404 | 0 | { |
405 | | #ifdef CONFIG_WPS |
406 | | struct wpa_ssid *ssid; |
407 | | struct wpabuf *wps_ie; |
408 | | int pbc = 0, ret; |
409 | | |
410 | 0 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
411 | 0 | if (!wps_ie) |
412 | 0 | return 0; |
413 | | |
414 | 0 | if (wps_is_selected_pbc_registrar(wps_ie)) { |
415 | 0 | pbc = 1; |
416 | 0 | } else if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) { |
417 | 0 | wpabuf_free(wps_ie); |
418 | 0 | return 0; |
419 | 0 | } |
420 | | |
421 | 0 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
422 | 0 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS)) |
423 | 0 | continue; |
424 | 0 | if (ssid->ssid_len && |
425 | 0 | (ssid->ssid_len != bss->ssid_len || |
426 | 0 | os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) != 0)) |
427 | 0 | continue; |
428 | | |
429 | 0 | if (pbc) |
430 | 0 | ret = eap_is_wps_pbc_enrollee(&ssid->eap); |
431 | 0 | else |
432 | 0 | ret = eap_is_wps_pin_enrollee(&ssid->eap); |
433 | 0 | wpabuf_free(wps_ie); |
434 | 0 | return ret; |
435 | 0 | } |
436 | 0 | wpabuf_free(wps_ie); |
437 | 0 | #endif /* CONFIG_WPS */ |
438 | |
|
439 | 0 | return 0; |
440 | 0 | } Unexecuted instantiation: bss.c:wpa_bss_is_wps_candidate Unexecuted instantiation: bss.c:wpa_bss_is_wps_candidate |
441 | | |
442 | | |
443 | | static bool is_p2p_pending_bss(struct wpa_supplicant *wpa_s, |
444 | | struct wpa_bss *bss) |
445 | 0 | { |
446 | | #ifdef CONFIG_P2P |
447 | | u8 addr[ETH_ALEN]; |
448 | | |
449 | | if (ether_addr_equal(bss->bssid, wpa_s->pending_join_iface_addr)) |
450 | | return true; |
451 | | if (!is_zero_ether_addr(wpa_s->pending_join_dev_addr) && |
452 | | p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len, addr) == 0 && |
453 | | ether_addr_equal(addr, wpa_s->pending_join_dev_addr)) |
454 | | return true; |
455 | | #endif /* CONFIG_P2P */ |
456 | 0 | return false; |
457 | 0 | } |
458 | | |
459 | | |
460 | | #ifdef CONFIG_OWE |
461 | | static int wpa_bss_owe_trans_known(struct wpa_supplicant *wpa_s, |
462 | | struct wpa_bss *bss, |
463 | | const u8 *entry_ssid, size_t entry_ssid_len) |
464 | | { |
465 | | const u8 *owe, *owe_bssid, *owe_ssid; |
466 | | size_t owe_ssid_len; |
467 | | |
468 | | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
469 | | if (!owe) |
470 | | return 0; |
471 | | |
472 | | if (wpas_get_owe_trans_network(owe, &owe_bssid, &owe_ssid, |
473 | | &owe_ssid_len)) |
474 | | return 0; |
475 | | |
476 | | return entry_ssid_len == owe_ssid_len && |
477 | | os_memcmp(owe_ssid, entry_ssid, owe_ssid_len) == 0; |
478 | | } |
479 | | #endif /* CONFIG_OWE */ |
480 | | |
481 | | |
482 | | static int wpa_bss_known(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
483 | 0 | { |
484 | 0 | struct wpa_ssid *ssid; |
485 | |
|
486 | 0 | if (is_p2p_pending_bss(wpa_s, bss)) |
487 | 0 | return 1; |
488 | | |
489 | 0 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
490 | 0 | if (ssid->ssid == NULL || ssid->ssid_len == 0) |
491 | 0 | continue; |
492 | 0 | if (ssid->ssid_len == bss->ssid_len && |
493 | 0 | os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) == 0) |
494 | 0 | return 1; |
495 | | #ifdef CONFIG_OWE |
496 | | if (wpa_bss_owe_trans_known(wpa_s, bss, ssid->ssid, |
497 | | ssid->ssid_len)) |
498 | | return 1; |
499 | | #endif /* CONFIG_OWE */ |
500 | 0 | } |
501 | | |
502 | 0 | return 0; |
503 | 0 | } |
504 | | |
505 | | |
506 | | static int wpa_bss_in_use(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
507 | 3.09k | { |
508 | 3.09k | int i; |
509 | | |
510 | 3.09k | if (bss == wpa_s->current_bss) |
511 | 0 | return 1; |
512 | | |
513 | 3.09k | if (bss == wpa_s->ml_connect_probe_bss) |
514 | 0 | return 1; |
515 | | |
516 | 3.09k | #ifdef CONFIG_WNM |
517 | 3.09k | if (bss == wpa_s->wnm_target_bss) |
518 | 0 | return 1; |
519 | 3.09k | #endif /* CONFIG_WNM */ |
520 | | |
521 | 3.09k | if (wpa_s->current_bss && |
522 | 0 | (bss->ssid_len != wpa_s->current_bss->ssid_len || |
523 | 0 | os_memcmp(bss->ssid, wpa_s->current_bss->ssid, |
524 | 0 | bss->ssid_len) != 0)) |
525 | 0 | return 0; /* SSID has changed */ |
526 | | |
527 | 3.09k | if (!is_zero_ether_addr(bss->bssid) && |
528 | 0 | (ether_addr_equal(bss->bssid, wpa_s->bssid) || |
529 | 0 | ether_addr_equal(bss->bssid, wpa_s->pending_bssid))) |
530 | 0 | return 1; |
531 | | |
532 | 3.09k | if (!wpa_s->valid_links) |
533 | 3.09k | return 0; |
534 | | |
535 | 0 | for_each_link(wpa_s->valid_links, i) { |
536 | 0 | if (ether_addr_equal(bss->bssid, wpa_s->links[i].bssid)) |
537 | 0 | return 1; |
538 | 0 | } |
539 | | |
540 | 0 | return 0; |
541 | 0 | } |
542 | | |
543 | | |
544 | | static int wpa_bss_remove_oldest_unknown(struct wpa_supplicant *wpa_s) |
545 | 0 | { |
546 | 0 | struct wpa_bss *bss; |
547 | |
|
548 | 0 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
549 | 0 | if (!wpa_bss_known(wpa_s, bss) && |
550 | 0 | !wpa_bss_in_use(wpa_s, bss) && |
551 | 0 | !wpa_bss_is_wps_candidate(wpa_s, bss)) { |
552 | 0 | wpa_bss_remove(wpa_s, bss, __func__); |
553 | 0 | return 0; |
554 | 0 | } |
555 | 0 | } |
556 | | |
557 | 0 | return -1; |
558 | 0 | } |
559 | | |
560 | | |
561 | | static int wpa_bss_remove_oldest(struct wpa_supplicant *wpa_s) |
562 | 0 | { |
563 | 0 | struct wpa_bss *bss; |
564 | | |
565 | | /* |
566 | | * Remove the oldest entry that does not match with any configured |
567 | | * network. |
568 | | */ |
569 | 0 | if (wpa_bss_remove_oldest_unknown(wpa_s) == 0) |
570 | 0 | return 0; |
571 | | |
572 | | /* |
573 | | * Remove the oldest entry that isn't currently in use. |
574 | | */ |
575 | 0 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
576 | 0 | if (!wpa_bss_in_use(wpa_s, bss)) { |
577 | 0 | wpa_bss_remove(wpa_s, bss, __func__); |
578 | 0 | return 0; |
579 | 0 | } |
580 | 0 | } |
581 | | |
582 | 0 | return -1; |
583 | 0 | } |
584 | | |
585 | | |
586 | | static struct wpa_bss * wpa_bss_add(struct wpa_supplicant *wpa_s, |
587 | | const u8 *ssid, size_t ssid_len, |
588 | | struct wpa_scan_res *res, |
589 | | struct os_reltime *fetch_time) |
590 | 3.09k | { |
591 | 3.09k | struct wpa_bss *bss; |
592 | 3.09k | char extra[100]; |
593 | 3.09k | char *pos, *end; |
594 | 3.09k | int ret = 0; |
595 | | |
596 | 3.09k | bss = os_zalloc(sizeof(*bss) + res->ie_len + res->beacon_ie_len); |
597 | 3.09k | if (bss == NULL) |
598 | 0 | return NULL; |
599 | 3.09k | bss->id = wpa_s->bss_next_id++; |
600 | 3.09k | bss->last_update_idx = wpa_s->bss_update_idx; |
601 | 3.09k | wpa_bss_copy_res(bss, res, fetch_time); |
602 | 3.09k | os_memcpy(bss->ssid, ssid, ssid_len); |
603 | 3.09k | bss->ssid_len = ssid_len; |
604 | 3.09k | bss->ie_len = res->ie_len; |
605 | 3.09k | bss->beacon_ie_len = res->beacon_ie_len; |
606 | 3.09k | os_memcpy(bss->ies, res + 1, res->ie_len + res->beacon_ie_len); |
607 | 3.09k | wpa_bss_set_hessid(bss); |
608 | | |
609 | 3.09k | wpa_bss_parse_basic_ml_element(wpa_s, bss); |
610 | | |
611 | 3.09k | if (wpa_s->num_bss + 1 > wpa_s->conf->bss_max_count && |
612 | 0 | wpa_bss_remove_oldest(wpa_s) != 0) { |
613 | 0 | wpa_printf(MSG_ERROR, "Increasing the MAX BSS count to %d " |
614 | 0 | "because all BSSes are in use. We should normally " |
615 | 0 | "not get here!", (int) wpa_s->num_bss + 1); |
616 | 0 | wpa_s->conf->bss_max_count = wpa_s->num_bss + 1; |
617 | 0 | } |
618 | | |
619 | 3.09k | dl_list_add_tail(&wpa_s->bss, &bss->list); |
620 | 3.09k | dl_list_add_tail(&wpa_s->bss_id, &bss->list_id); |
621 | 3.09k | wpa_s->num_bss++; |
622 | | |
623 | 3.09k | extra[0] = '\0'; |
624 | 3.09k | pos = extra; |
625 | 3.09k | end = pos + sizeof(extra); |
626 | 3.09k | if (!is_zero_ether_addr(bss->hessid)) |
627 | 15 | ret = os_snprintf(pos, end - pos, " HESSID " MACSTR, |
628 | 15 | MAC2STR(bss->hessid)); |
629 | | |
630 | 3.09k | if (!is_zero_ether_addr(bss->mld_addr) && |
631 | 679 | !os_snprintf_error(end - pos, ret)) { |
632 | 679 | pos += ret; |
633 | 679 | ret = os_snprintf(pos, end - pos, " MLD ADDR " MACSTR, |
634 | 679 | MAC2STR(bss->mld_addr)); |
635 | 679 | } |
636 | | |
637 | 3.09k | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Add new id %u BSSID " MACSTR |
638 | 3.09k | " SSID '%s' freq %d%s", |
639 | 3.09k | bss->id, MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len), |
640 | 3.09k | bss->freq, extra); |
641 | 3.09k | wpas_notify_bss_added(wpa_s, bss->bssid, bss->id); |
642 | 3.09k | return bss; |
643 | 3.09k | } |
644 | | |
645 | | |
646 | | static int are_ies_equal(const struct wpa_bss *old, |
647 | | const struct wpa_scan_res *new_res, u32 ie) |
648 | 0 | { |
649 | 0 | const u8 *old_ie, *new_ie; |
650 | 0 | struct wpabuf *old_ie_buff = NULL; |
651 | 0 | struct wpabuf *new_ie_buff = NULL; |
652 | 0 | int new_ie_len, old_ie_len, ret, is_multi; |
653 | |
|
654 | 0 | switch (ie) { |
655 | 0 | case WPA_IE_VENDOR_TYPE: |
656 | 0 | old_ie = wpa_bss_get_vendor_ie(old, ie); |
657 | 0 | new_ie = wpa_scan_get_vendor_ie(new_res, ie); |
658 | 0 | is_multi = 0; |
659 | 0 | break; |
660 | 0 | case WPS_IE_VENDOR_TYPE: |
661 | 0 | old_ie_buff = wpa_bss_get_vendor_ie_multi(old, ie); |
662 | 0 | new_ie_buff = wpa_scan_get_vendor_ie_multi(new_res, ie); |
663 | 0 | is_multi = 1; |
664 | 0 | break; |
665 | 0 | case WLAN_EID_RSN: |
666 | 0 | case WLAN_EID_SUPP_RATES: |
667 | 0 | case WLAN_EID_EXT_SUPP_RATES: |
668 | 0 | old_ie = wpa_bss_get_ie(old, ie); |
669 | 0 | new_ie = wpa_scan_get_ie(new_res, ie); |
670 | 0 | is_multi = 0; |
671 | 0 | break; |
672 | 0 | default: |
673 | 0 | wpa_printf(MSG_DEBUG, "bss: %s: cannot compare IEs", __func__); |
674 | 0 | return 0; |
675 | 0 | } |
676 | | |
677 | 0 | if (is_multi) { |
678 | | /* in case of multiple IEs stored in buffer */ |
679 | 0 | old_ie = old_ie_buff ? wpabuf_head_u8(old_ie_buff) : NULL; |
680 | 0 | new_ie = new_ie_buff ? wpabuf_head_u8(new_ie_buff) : NULL; |
681 | 0 | old_ie_len = old_ie_buff ? wpabuf_len(old_ie_buff) : 0; |
682 | 0 | new_ie_len = new_ie_buff ? wpabuf_len(new_ie_buff) : 0; |
683 | 0 | } else { |
684 | | /* in case of single IE */ |
685 | 0 | old_ie_len = old_ie ? old_ie[1] + 2 : 0; |
686 | 0 | new_ie_len = new_ie ? new_ie[1] + 2 : 0; |
687 | 0 | } |
688 | |
|
689 | 0 | if (!old_ie || !new_ie) |
690 | 0 | ret = !old_ie && !new_ie; |
691 | 0 | else |
692 | 0 | ret = (old_ie_len == new_ie_len && |
693 | 0 | os_memcmp(old_ie, new_ie, old_ie_len) == 0); |
694 | |
|
695 | 0 | wpabuf_free(old_ie_buff); |
696 | 0 | wpabuf_free(new_ie_buff); |
697 | |
|
698 | 0 | return ret; |
699 | 0 | } |
700 | | |
701 | | |
702 | | static u32 wpa_bss_compare_res(const struct wpa_bss *old, |
703 | | const struct wpa_scan_res *new_res) |
704 | 0 | { |
705 | 0 | u32 changes = 0; |
706 | 0 | int caps_diff = old->caps ^ new_res->caps; |
707 | |
|
708 | 0 | if (old->freq != new_res->freq) |
709 | 0 | changes |= WPA_BSS_FREQ_CHANGED_FLAG; |
710 | |
|
711 | 0 | if (old->level != new_res->level) |
712 | 0 | changes |= WPA_BSS_SIGNAL_CHANGED_FLAG; |
713 | |
|
714 | 0 | if (caps_diff & IEEE80211_CAP_PRIVACY) |
715 | 0 | changes |= WPA_BSS_PRIVACY_CHANGED_FLAG; |
716 | |
|
717 | 0 | if (caps_diff & IEEE80211_CAP_IBSS) |
718 | 0 | changes |= WPA_BSS_MODE_CHANGED_FLAG; |
719 | |
|
720 | 0 | if (old->ie_len == new_res->ie_len && |
721 | 0 | os_memcmp(wpa_bss_ie_ptr(old), new_res + 1, old->ie_len) == 0) |
722 | 0 | return changes; |
723 | 0 | changes |= WPA_BSS_IES_CHANGED_FLAG; |
724 | |
|
725 | 0 | if (!are_ies_equal(old, new_res, WPA_IE_VENDOR_TYPE)) |
726 | 0 | changes |= WPA_BSS_WPAIE_CHANGED_FLAG; |
727 | |
|
728 | 0 | if (!are_ies_equal(old, new_res, WLAN_EID_RSN)) |
729 | 0 | changes |= WPA_BSS_RSNIE_CHANGED_FLAG; |
730 | |
|
731 | 0 | if (!are_ies_equal(old, new_res, WPS_IE_VENDOR_TYPE)) |
732 | 0 | changes |= WPA_BSS_WPS_CHANGED_FLAG; |
733 | |
|
734 | 0 | if (!are_ies_equal(old, new_res, WLAN_EID_SUPP_RATES) || |
735 | 0 | !are_ies_equal(old, new_res, WLAN_EID_EXT_SUPP_RATES)) |
736 | 0 | changes |= WPA_BSS_RATES_CHANGED_FLAG; |
737 | |
|
738 | 0 | return changes; |
739 | 0 | } |
740 | | |
741 | | |
742 | | void notify_bss_changes(struct wpa_supplicant *wpa_s, u32 changes, |
743 | | const struct wpa_bss *bss) |
744 | 0 | { |
745 | 0 | if (changes & WPA_BSS_FREQ_CHANGED_FLAG) |
746 | 0 | wpas_notify_bss_freq_changed(wpa_s, bss->id); |
747 | |
|
748 | 0 | if (changes & WPA_BSS_SIGNAL_CHANGED_FLAG) |
749 | 0 | wpas_notify_bss_signal_changed(wpa_s, bss->id); |
750 | |
|
751 | 0 | if (changes & WPA_BSS_PRIVACY_CHANGED_FLAG) |
752 | 0 | wpas_notify_bss_privacy_changed(wpa_s, bss->id); |
753 | |
|
754 | 0 | if (changes & WPA_BSS_MODE_CHANGED_FLAG) |
755 | 0 | wpas_notify_bss_mode_changed(wpa_s, bss->id); |
756 | |
|
757 | 0 | if (changes & WPA_BSS_WPAIE_CHANGED_FLAG) |
758 | 0 | wpas_notify_bss_wpaie_changed(wpa_s, bss->id); |
759 | |
|
760 | 0 | if (changes & WPA_BSS_RSNIE_CHANGED_FLAG) |
761 | 0 | wpas_notify_bss_rsnie_changed(wpa_s, bss->id); |
762 | |
|
763 | 0 | if (changes & WPA_BSS_WPS_CHANGED_FLAG) |
764 | 0 | wpas_notify_bss_wps_changed(wpa_s, bss->id); |
765 | |
|
766 | 0 | if (changes & WPA_BSS_IES_CHANGED_FLAG) |
767 | 0 | wpas_notify_bss_ies_changed(wpa_s, bss->id); |
768 | |
|
769 | 0 | if (changes & WPA_BSS_RATES_CHANGED_FLAG) |
770 | 0 | wpas_notify_bss_rates_changed(wpa_s, bss->id); |
771 | |
|
772 | 0 | wpas_notify_bss_seen(wpa_s, bss->id); |
773 | 0 | } |
774 | | |
775 | | |
776 | | static struct wpa_bss * |
777 | | wpa_bss_update(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
778 | | struct wpa_scan_res *res, struct os_reltime *fetch_time) |
779 | 0 | { |
780 | 0 | u32 changes; |
781 | |
|
782 | 0 | if (bss->last_update_idx == wpa_s->bss_update_idx) { |
783 | 0 | struct os_reltime update_time; |
784 | | |
785 | | /* |
786 | | * Some drivers (e.g., cfg80211) include multiple BSS entries |
787 | | * for the same BSS if that BSS's channel changes. The BSS list |
788 | | * implementation in wpa_supplicant does not do that and we need |
789 | | * to filter out the obsolete results here to make sure only the |
790 | | * most current BSS information remains in the table. |
791 | | */ |
792 | 0 | wpa_printf(MSG_DEBUG, "BSS: " MACSTR |
793 | 0 | " has multiple entries in the scan results - select the most current one", |
794 | 0 | MAC2STR(bss->bssid)); |
795 | 0 | calculate_update_time(fetch_time, res->age, &update_time); |
796 | 0 | wpa_printf(MSG_DEBUG, |
797 | 0 | "Previous last_update: %u.%06u (freq %d%s)", |
798 | 0 | (unsigned int) bss->last_update.sec, |
799 | 0 | (unsigned int) bss->last_update.usec, |
800 | 0 | bss->freq, |
801 | 0 | (bss->flags & WPA_BSS_ASSOCIATED) ? " assoc" : ""); |
802 | 0 | wpa_printf(MSG_DEBUG, "New last_update: %u.%06u (freq %d%s)", |
803 | 0 | (unsigned int) update_time.sec, |
804 | 0 | (unsigned int) update_time.usec, |
805 | 0 | res->freq, |
806 | 0 | (res->flags & WPA_SCAN_ASSOCIATED) ? " assoc" : ""); |
807 | 0 | if ((bss->flags & WPA_BSS_ASSOCIATED) || |
808 | 0 | (!(res->flags & WPA_SCAN_ASSOCIATED) && |
809 | 0 | !os_reltime_before(&bss->last_update, &update_time))) { |
810 | 0 | wpa_printf(MSG_DEBUG, |
811 | 0 | "Ignore this BSS entry since the previous update looks more current"); |
812 | 0 | return bss; |
813 | 0 | } |
814 | 0 | wpa_printf(MSG_DEBUG, |
815 | 0 | "Accept this BSS entry since it looks more current than the previous update"); |
816 | 0 | } |
817 | | |
818 | 0 | changes = wpa_bss_compare_res(bss, res); |
819 | 0 | if (changes & WPA_BSS_FREQ_CHANGED_FLAG) |
820 | 0 | wpa_printf(MSG_DEBUG, "BSS: " MACSTR " changed freq %d --> %d", |
821 | 0 | MAC2STR(bss->bssid), bss->freq, res->freq); |
822 | 0 | bss->scan_miss_count = 0; |
823 | 0 | bss->last_update_idx = wpa_s->bss_update_idx; |
824 | 0 | wpa_bss_copy_res(bss, res, fetch_time); |
825 | | /* Move the entry to the end of the list */ |
826 | 0 | dl_list_del(&bss->list); |
827 | | #ifdef CONFIG_P2P |
828 | | if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
829 | | !wpa_scan_get_vendor_ie(res, P2P_IE_VENDOR_TYPE) && |
830 | | !(changes & WPA_BSS_FREQ_CHANGED_FLAG)) { |
831 | | /* |
832 | | * This can happen when non-P2P station interface runs a scan |
833 | | * without P2P IE in the Probe Request frame. P2P GO would reply |
834 | | * to that with a Probe Response that does not include P2P IE. |
835 | | * Do not update the IEs in this BSS entry to avoid such loss of |
836 | | * information that may be needed for P2P operations to |
837 | | * determine group information. |
838 | | */ |
839 | | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Do not update scan IEs for " |
840 | | MACSTR " since that would remove P2P IE information", |
841 | | MAC2STR(bss->bssid)); |
842 | | } else |
843 | | #endif /* CONFIG_P2P */ |
844 | 0 | if (bss->ie_len + bss->beacon_ie_len >= |
845 | 0 | res->ie_len + res->beacon_ie_len) { |
846 | 0 | os_memcpy(bss->ies, res + 1, res->ie_len + res->beacon_ie_len); |
847 | 0 | bss->ie_len = res->ie_len; |
848 | 0 | bss->beacon_ie_len = res->beacon_ie_len; |
849 | 0 | } else { |
850 | 0 | struct wpa_bss *nbss; |
851 | 0 | struct dl_list *prev = bss->list_id.prev; |
852 | 0 | struct wpa_connect_work *cwork; |
853 | 0 | unsigned int i, j; |
854 | 0 | bool update_current_bss = wpa_s->current_bss == bss; |
855 | 0 | bool update_ml_probe_bss = wpa_s->ml_connect_probe_bss == bss; |
856 | 0 | int update_link_bss = -1; |
857 | 0 | #ifdef CONFIG_WNM |
858 | 0 | bool update_wnm_target = wpa_s->wnm_target_bss == bss; |
859 | 0 | #endif /* CONFIG_WNM */ |
860 | 0 | #ifdef CONFIG_INTERWORKING |
861 | 0 | bool update_interworking = wpa_s->interworking_gas_bss == bss; |
862 | 0 | #endif /* CONFIG_INTERWORKING */ |
863 | |
|
864 | 0 | for (j = 0; j < MAX_NUM_MLD_LINKS; j++) { |
865 | 0 | if (wpa_s->links[j].bss == bss) { |
866 | 0 | update_link_bss = j; |
867 | 0 | break; |
868 | 0 | } |
869 | 0 | } |
870 | |
|
871 | 0 | cwork = wpa_bss_check_pending_connect(wpa_s, bss); |
872 | |
|
873 | 0 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
874 | 0 | if (wpa_s->last_scan_res[i] == bss) |
875 | 0 | break; |
876 | 0 | } |
877 | |
|
878 | 0 | dl_list_del(&bss->list_id); |
879 | 0 | nbss = os_realloc(bss, sizeof(*bss) + res->ie_len + |
880 | 0 | res->beacon_ie_len); |
881 | 0 | if (nbss) { |
882 | 0 | if (i != wpa_s->last_scan_res_used) |
883 | 0 | wpa_s->last_scan_res[i] = nbss; |
884 | |
|
885 | 0 | if (update_current_bss) |
886 | 0 | wpa_s->current_bss = nbss; |
887 | |
|
888 | 0 | if (update_ml_probe_bss) |
889 | 0 | wpa_s->ml_connect_probe_bss = nbss; |
890 | |
|
891 | 0 | if (update_link_bss >= 0) |
892 | 0 | wpa_s->links[update_link_bss].bss = nbss; |
893 | |
|
894 | 0 | #ifdef CONFIG_WNM |
895 | 0 | if (update_wnm_target) |
896 | 0 | wpa_s->wnm_target_bss = nbss; |
897 | 0 | #endif /* CONFIG_WNM */ |
898 | 0 | #ifdef CONFIG_INTERWORKING |
899 | 0 | if (update_interworking) |
900 | 0 | wpa_s->interworking_gas_bss = nbss; |
901 | 0 | #endif /* CONFIG_INTERWORKING */ |
902 | |
|
903 | 0 | if (cwork) |
904 | 0 | wpa_bss_update_pending_connect(cwork, nbss); |
905 | |
|
906 | 0 | bss = nbss; |
907 | 0 | os_memcpy(bss->ies, res + 1, |
908 | 0 | res->ie_len + res->beacon_ie_len); |
909 | 0 | bss->ie_len = res->ie_len; |
910 | 0 | bss->beacon_ie_len = res->beacon_ie_len; |
911 | 0 | } |
912 | 0 | dl_list_add(prev, &bss->list_id); |
913 | 0 | } |
914 | 0 | if (changes & WPA_BSS_IES_CHANGED_FLAG) { |
915 | 0 | wpa_bss_set_hessid(bss); |
916 | |
|
917 | 0 | wpa_bss_parse_basic_ml_element(wpa_s, bss); |
918 | 0 | } |
919 | 0 | dl_list_add_tail(&wpa_s->bss, &bss->list); |
920 | |
|
921 | 0 | notify_bss_changes(wpa_s, changes, bss); |
922 | |
|
923 | 0 | return bss; |
924 | 0 | } |
925 | | |
926 | | |
927 | | /** |
928 | | * wpa_bss_update_start - Start a BSS table update from scan results |
929 | | * @wpa_s: Pointer to wpa_supplicant data |
930 | | * |
931 | | * This function is called at the start of each BSS table update round for new |
932 | | * scan results. The actual scan result entries are indicated with calls to |
933 | | * wpa_bss_update_scan_res() and the update round is finished with a call to |
934 | | * wpa_bss_update_end(). |
935 | | */ |
936 | | void wpa_bss_update_start(struct wpa_supplicant *wpa_s) |
937 | 3.14k | { |
938 | 3.14k | wpa_s->bss_update_idx++; |
939 | 3.14k | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Start scan result update %u", |
940 | 3.14k | wpa_s->bss_update_idx); |
941 | 3.14k | wpa_s->last_scan_res_used = 0; |
942 | 3.14k | } |
943 | | |
944 | | |
945 | | /** |
946 | | * wpa_bss_update_scan_res - Update a BSS table entry based on a scan result |
947 | | * @wpa_s: Pointer to wpa_supplicant data |
948 | | * @res: Scan result |
949 | | * @fetch_time: Time when the result was fetched from the driver |
950 | | * |
951 | | * This function updates a BSS table entry (or adds one) based on a scan result. |
952 | | * This is called separately for each scan result between the calls to |
953 | | * wpa_bss_update_start() and wpa_bss_update_end(). |
954 | | */ |
955 | | void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s, |
956 | | struct wpa_scan_res *res, |
957 | | struct os_reltime *fetch_time) |
958 | 3.14k | { |
959 | 3.14k | const u8 *ssid, *p2p, *mesh; |
960 | 3.14k | struct wpa_bss *bss; |
961 | | |
962 | 3.14k | if (wpa_s->conf->ignore_old_scan_res) { |
963 | 0 | struct os_reltime update; |
964 | 0 | calculate_update_time(fetch_time, res->age, &update); |
965 | 0 | if (os_reltime_before(&update, &wpa_s->scan_trigger_time)) { |
966 | 0 | struct os_reltime age; |
967 | 0 | os_reltime_sub(&wpa_s->scan_trigger_time, &update, |
968 | 0 | &age); |
969 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Ignore driver BSS " |
970 | 0 | "table entry that is %u.%06u seconds older " |
971 | 0 | "than our scan trigger", |
972 | 0 | (unsigned int) age.sec, |
973 | 0 | (unsigned int) age.usec); |
974 | 0 | return; |
975 | 0 | } |
976 | 0 | } |
977 | | |
978 | 3.14k | ssid = wpa_scan_get_ie(res, WLAN_EID_SSID); |
979 | 3.14k | if (ssid == NULL) { |
980 | 41 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: No SSID IE included for " |
981 | 41 | MACSTR, MAC2STR(res->bssid)); |
982 | 41 | return; |
983 | 41 | } |
984 | 3.10k | if (ssid[1] > SSID_MAX_LEN) { |
985 | 3 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Too long SSID IE included for " |
986 | 3 | MACSTR, MAC2STR(res->bssid)); |
987 | 3 | return; |
988 | 3 | } |
989 | | |
990 | 3.10k | p2p = wpa_scan_get_vendor_ie(res, P2P_IE_VENDOR_TYPE); |
991 | | #ifdef CONFIG_P2P |
992 | | if (p2p == NULL && |
993 | | wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
994 | | /* |
995 | | * If it's a P2P specific interface, then don't update |
996 | | * the scan result without a P2P IE. |
997 | | */ |
998 | | wpa_printf(MSG_DEBUG, "BSS: No P2P IE - skipping BSS " MACSTR |
999 | | " update for P2P interface", MAC2STR(res->bssid)); |
1000 | | return; |
1001 | | } |
1002 | | #endif /* CONFIG_P2P */ |
1003 | 3.10k | if (p2p && ssid[1] == P2P_WILDCARD_SSID_LEN && |
1004 | 54 | os_memcmp(ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == 0) |
1005 | 1 | return; /* Skip P2P listen discovery results here */ |
1006 | | |
1007 | | /* TODO: add option for ignoring BSSes we are not interested in |
1008 | | * (to save memory) */ |
1009 | | |
1010 | 3.09k | mesh = wpa_scan_get_ie(res, WLAN_EID_MESH_ID); |
1011 | 3.09k | if (mesh && mesh[1] <= SSID_MAX_LEN) |
1012 | 26 | ssid = mesh; |
1013 | | |
1014 | 3.09k | bss = wpa_bss_get(wpa_s, res->bssid, ssid + 2, ssid[1]); |
1015 | 3.09k | if (bss == NULL) |
1016 | 3.09k | bss = wpa_bss_add(wpa_s, ssid + 2, ssid[1], res, fetch_time); |
1017 | 0 | else { |
1018 | 0 | bss = wpa_bss_update(wpa_s, bss, res, fetch_time); |
1019 | 0 | if (wpa_s->last_scan_res) { |
1020 | 0 | unsigned int i; |
1021 | 0 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
1022 | 0 | if (bss == wpa_s->last_scan_res[i]) { |
1023 | | /* Already in the list */ |
1024 | 0 | return; |
1025 | 0 | } |
1026 | 0 | } |
1027 | 0 | } |
1028 | 0 | } |
1029 | | |
1030 | 3.09k | if (bss == NULL) |
1031 | 0 | return; |
1032 | 3.09k | if (wpa_s->last_scan_res_used >= wpa_s->last_scan_res_size) { |
1033 | 3.09k | struct wpa_bss **n; |
1034 | 3.09k | unsigned int siz; |
1035 | 3.09k | if (wpa_s->last_scan_res_size == 0) |
1036 | 3.09k | siz = 32; |
1037 | 0 | else |
1038 | 0 | siz = wpa_s->last_scan_res_size * 2; |
1039 | 3.09k | n = os_realloc_array(wpa_s->last_scan_res, siz, |
1040 | 3.09k | sizeof(struct wpa_bss *)); |
1041 | 3.09k | if (n == NULL) |
1042 | 0 | return; |
1043 | 3.09k | wpa_s->last_scan_res = n; |
1044 | 3.09k | wpa_s->last_scan_res_size = siz; |
1045 | 3.09k | } |
1046 | | |
1047 | 3.09k | if (wpa_s->last_scan_res) |
1048 | 3.09k | wpa_s->last_scan_res[wpa_s->last_scan_res_used++] = bss; |
1049 | 3.09k | } |
1050 | | |
1051 | | |
1052 | | static int wpa_bss_included_in_scan(const struct wpa_bss *bss, |
1053 | | const struct scan_info *info) |
1054 | 3.09k | { |
1055 | 3.09k | int found; |
1056 | 3.09k | size_t i; |
1057 | | |
1058 | 3.09k | if (info == NULL) |
1059 | 3.09k | return 1; |
1060 | | |
1061 | 0 | if (info->num_freqs) { |
1062 | 0 | found = 0; |
1063 | 0 | for (i = 0; i < info->num_freqs; i++) { |
1064 | 0 | if (bss->freq == info->freqs[i]) { |
1065 | 0 | found = 1; |
1066 | 0 | break; |
1067 | 0 | } |
1068 | 0 | } |
1069 | 0 | if (!found) |
1070 | 0 | return 0; |
1071 | 0 | } |
1072 | | |
1073 | 0 | if (info->num_ssids) { |
1074 | 0 | found = 0; |
1075 | 0 | for (i = 0; i < info->num_ssids; i++) { |
1076 | 0 | const struct wpa_driver_scan_ssid *s = &info->ssids[i]; |
1077 | 0 | if ((s->ssid == NULL || s->ssid_len == 0) || |
1078 | 0 | (s->ssid_len == bss->ssid_len && |
1079 | 0 | os_memcmp(s->ssid, bss->ssid, bss->ssid_len) == |
1080 | 0 | 0)) { |
1081 | 0 | found = 1; |
1082 | 0 | break; |
1083 | 0 | } |
1084 | 0 | } |
1085 | 0 | if (!found) |
1086 | 0 | return 0; |
1087 | 0 | } |
1088 | | |
1089 | 0 | return 1; |
1090 | 0 | } |
1091 | | |
1092 | | |
1093 | | /** |
1094 | | * wpa_bss_update_end - End a BSS table update from scan results |
1095 | | * @wpa_s: Pointer to wpa_supplicant data |
1096 | | * @info: Information about scan parameters |
1097 | | * @new_scan: Whether this update round was based on a new scan |
1098 | | * |
1099 | | * This function is called at the end of each BSS table update round for new |
1100 | | * scan results. The start of the update was indicated with a call to |
1101 | | * wpa_bss_update_start(). |
1102 | | */ |
1103 | | void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info, |
1104 | | int new_scan) |
1105 | 3.14k | { |
1106 | 3.14k | struct wpa_bss *bss, *n; |
1107 | | |
1108 | 3.14k | os_get_reltime(&wpa_s->last_scan); |
1109 | 3.14k | if ((info && info->aborted) || !new_scan) |
1110 | 0 | return; /* do not expire entries without new scan */ |
1111 | | |
1112 | 3.14k | dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) { |
1113 | 3.09k | if (wpa_bss_in_use(wpa_s, bss)) |
1114 | 0 | continue; |
1115 | 3.09k | if (!wpa_bss_included_in_scan(bss, info)) |
1116 | 0 | continue; /* expire only BSSes that were scanned */ |
1117 | 3.09k | if (bss->last_update_idx < wpa_s->bss_update_idx) |
1118 | 0 | bss->scan_miss_count++; |
1119 | 3.09k | if (bss->scan_miss_count >= |
1120 | 3.09k | wpa_s->conf->bss_expiration_scan_count) { |
1121 | 3.09k | wpa_bss_remove(wpa_s, bss, "no match in scan"); |
1122 | 3.09k | } |
1123 | 3.09k | } |
1124 | | |
1125 | 3.14k | wpa_printf(MSG_DEBUG, "BSS: last_scan_res_used=%zu/%zu", |
1126 | 3.14k | wpa_s->last_scan_res_used, wpa_s->last_scan_res_size); |
1127 | 3.14k | } |
1128 | | |
1129 | | |
1130 | | /** |
1131 | | * wpa_bss_flush_by_age - Flush old BSS entries |
1132 | | * @wpa_s: Pointer to wpa_supplicant data |
1133 | | * @age: Maximum entry age in seconds |
1134 | | * |
1135 | | * Remove BSS entries that have not been updated during the last @age seconds. |
1136 | | */ |
1137 | | void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age) |
1138 | 0 | { |
1139 | 0 | struct wpa_bss *bss, *n; |
1140 | 0 | struct os_reltime t; |
1141 | |
|
1142 | 0 | if (dl_list_empty(&wpa_s->bss)) |
1143 | 0 | return; |
1144 | | |
1145 | 0 | os_get_reltime(&t); |
1146 | |
|
1147 | 0 | if (t.sec < age) |
1148 | 0 | return; /* avoid underflow; there can be no older entries */ |
1149 | | |
1150 | 0 | t.sec -= age; |
1151 | |
|
1152 | 0 | dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) { |
1153 | 0 | if (wpa_bss_in_use(wpa_s, bss)) |
1154 | 0 | continue; |
1155 | | |
1156 | 0 | if (wpa_s->reassoc_same_ess && |
1157 | 0 | wpa_s->wpa_state != WPA_COMPLETED && |
1158 | 0 | wpa_s->last_ssid && |
1159 | 0 | wpa_s->last_ssid->ssid && |
1160 | 0 | bss->ssid_len == wpa_s->last_ssid->ssid_len && |
1161 | 0 | os_memcmp(bss->ssid, wpa_s->last_ssid->ssid, |
1162 | 0 | bss->ssid_len) == 0) |
1163 | 0 | continue; |
1164 | | |
1165 | 0 | if (os_reltime_before(&bss->last_update, &t)) { |
1166 | 0 | wpa_bss_remove(wpa_s, bss, __func__); |
1167 | 0 | } else |
1168 | 0 | break; |
1169 | 0 | } |
1170 | 0 | } |
1171 | | |
1172 | | |
1173 | | /** |
1174 | | * wpa_bss_init - Initialize BSS table |
1175 | | * @wpa_s: Pointer to wpa_supplicant data |
1176 | | * Returns: 0 on success, -1 on failure |
1177 | | * |
1178 | | * This prepares BSS table lists and timer for periodic updates. The BSS table |
1179 | | * is deinitialized with wpa_bss_deinit() once not needed anymore. |
1180 | | */ |
1181 | | int wpa_bss_init(struct wpa_supplicant *wpa_s) |
1182 | 4.69k | { |
1183 | 4.69k | dl_list_init(&wpa_s->bss); |
1184 | 4.69k | dl_list_init(&wpa_s->bss_id); |
1185 | 4.69k | return 0; |
1186 | 4.69k | } |
1187 | | |
1188 | | |
1189 | | /** |
1190 | | * wpa_bss_flush - Flush all unused BSS entries |
1191 | | * @wpa_s: Pointer to wpa_supplicant data |
1192 | | */ |
1193 | | void wpa_bss_flush(struct wpa_supplicant *wpa_s) |
1194 | 4.69k | { |
1195 | 4.69k | struct wpa_bss *bss, *n; |
1196 | | |
1197 | 4.69k | wpa_s->clear_driver_scan_cache = 1; |
1198 | | |
1199 | 4.69k | if (wpa_s->bss.next == NULL) |
1200 | 0 | return; /* BSS table not yet initialized */ |
1201 | | |
1202 | 4.69k | dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) { |
1203 | 0 | if (wpa_bss_in_use(wpa_s, bss)) |
1204 | 0 | continue; |
1205 | 0 | wpa_bss_remove(wpa_s, bss, __func__); |
1206 | 0 | } |
1207 | 4.69k | } |
1208 | | |
1209 | | |
1210 | | /** |
1211 | | * wpa_bss_deinit - Deinitialize BSS table |
1212 | | * @wpa_s: Pointer to wpa_supplicant data |
1213 | | */ |
1214 | | void wpa_bss_deinit(struct wpa_supplicant *wpa_s) |
1215 | 0 | { |
1216 | 0 | wpa_bss_flush(wpa_s); |
1217 | 0 | } |
1218 | | |
1219 | | |
1220 | | /** |
1221 | | * wpa_bss_get_bssid - Fetch a BSS table entry based on BSSID |
1222 | | * @wpa_s: Pointer to wpa_supplicant data |
1223 | | * @bssid: BSSID |
1224 | | * Returns: Pointer to the BSS entry or %NULL if not found |
1225 | | */ |
1226 | | struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s, |
1227 | | const u8 *bssid) |
1228 | 0 | { |
1229 | 0 | struct wpa_bss *bss; |
1230 | 0 | if (!wpa_supplicant_filter_bssid_match(wpa_s, bssid)) |
1231 | 0 | return NULL; |
1232 | 0 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) { |
1233 | 0 | if (ether_addr_equal(bss->bssid, bssid)) |
1234 | 0 | return bss; |
1235 | 0 | } |
1236 | 0 | return NULL; |
1237 | 0 | } |
1238 | | |
1239 | | |
1240 | | /** |
1241 | | * wpa_bss_get_bssid_latest - Fetch the latest BSS table entry based on BSSID |
1242 | | * @wpa_s: Pointer to wpa_supplicant data |
1243 | | * @bssid: BSSID |
1244 | | * Returns: Pointer to the BSS entry or %NULL if not found |
1245 | | * |
1246 | | * This function is like wpa_bss_get_bssid(), but full BSS table is iterated to |
1247 | | * find the entry that has the most recent update. This can help in finding the |
1248 | | * correct entry in cases where the SSID of the AP may have changed recently |
1249 | | * (e.g., in WPS reconfiguration cases). |
1250 | | */ |
1251 | | struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s, |
1252 | | const u8 *bssid) |
1253 | 0 | { |
1254 | 0 | struct wpa_bss *bss, *found = NULL; |
1255 | 0 | if (!wpa_supplicant_filter_bssid_match(wpa_s, bssid)) |
1256 | 0 | return NULL; |
1257 | 0 | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) { |
1258 | 0 | if (!ether_addr_equal(bss->bssid, bssid)) |
1259 | 0 | continue; |
1260 | 0 | if (found == NULL || |
1261 | 0 | os_reltime_before(&found->last_update, &bss->last_update)) |
1262 | 0 | found = bss; |
1263 | 0 | } |
1264 | 0 | return found; |
1265 | 0 | } |
1266 | | |
1267 | | |
1268 | | #ifdef CONFIG_P2P |
1269 | | /** |
1270 | | * wpa_bss_get_p2p_dev_addr - Fetch the latest BSS table entry based on P2P Device Addr |
1271 | | * @wpa_s: Pointer to wpa_supplicant data |
1272 | | * @dev_addr: P2P Device Address of the GO |
1273 | | * Returns: Pointer to the BSS entry or %NULL if not found |
1274 | | * |
1275 | | * This function tries to find the entry that has the most recent update. This |
1276 | | * can help in finding the correct entry in cases where the SSID of the P2P |
1277 | | * Device may have changed recently. |
1278 | | */ |
1279 | | struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s, |
1280 | | const u8 *dev_addr) |
1281 | | { |
1282 | | struct wpa_bss *bss, *found = NULL; |
1283 | | dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) { |
1284 | | u8 addr[ETH_ALEN]; |
1285 | | if (p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len, |
1286 | | addr) != 0 || |
1287 | | !ether_addr_equal(addr, dev_addr)) |
1288 | | continue; |
1289 | | if (!found || |
1290 | | os_reltime_before(&found->last_update, &bss->last_update)) |
1291 | | found = bss; |
1292 | | } |
1293 | | return found; |
1294 | | } |
1295 | | #endif /* CONFIG_P2P */ |
1296 | | |
1297 | | |
1298 | | /** |
1299 | | * wpa_bss_get_id - Fetch a BSS table entry based on identifier |
1300 | | * @wpa_s: Pointer to wpa_supplicant data |
1301 | | * @id: Unique identifier (struct wpa_bss::id) assigned for the entry |
1302 | | * Returns: Pointer to the BSS entry or %NULL if not found |
1303 | | */ |
1304 | | struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id) |
1305 | 0 | { |
1306 | 0 | struct wpa_bss *bss; |
1307 | 0 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
1308 | 0 | if (bss->id == id) |
1309 | 0 | return bss; |
1310 | 0 | } |
1311 | 0 | return NULL; |
1312 | 0 | } |
1313 | | |
1314 | | |
1315 | | /** |
1316 | | * wpa_bss_get_id_range - Fetch a BSS table entry based on identifier range |
1317 | | * @wpa_s: Pointer to wpa_supplicant data |
1318 | | * @idf: Smallest allowed identifier assigned for the entry |
1319 | | * @idf: Largest allowed identifier assigned for the entry |
1320 | | * Returns: Pointer to the BSS entry or %NULL if not found |
1321 | | * |
1322 | | * This function is similar to wpa_bss_get_id() but allows a BSS entry with the |
1323 | | * smallest id value to be fetched within the specified range without the |
1324 | | * caller having to know the exact id. |
1325 | | */ |
1326 | | struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s, |
1327 | | unsigned int idf, unsigned int idl) |
1328 | 0 | { |
1329 | 0 | struct wpa_bss *bss; |
1330 | 0 | dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) { |
1331 | 0 | if (bss->id >= idf && bss->id <= idl) |
1332 | 0 | return bss; |
1333 | 0 | } |
1334 | 0 | return NULL; |
1335 | 0 | } |
1336 | | |
1337 | | |
1338 | | /** |
1339 | | * wpa_bss_get_ie - Fetch a specified information element from a BSS entry |
1340 | | * @bss: BSS table entry |
1341 | | * @ie: Information element identitifier (WLAN_EID_*) |
1342 | | * Returns: Pointer to the information element (id field) or %NULL if not found |
1343 | | * |
1344 | | * This function returns the first matching information element in the BSS |
1345 | | * entry. |
1346 | | */ |
1347 | | const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie) |
1348 | 6.55k | { |
1349 | 6.55k | return get_ie(wpa_bss_ie_ptr(bss), bss->ie_len, ie); |
1350 | 6.55k | } |
1351 | | |
1352 | | |
1353 | | /** |
1354 | | * wpa_bss_get_ie_beacon - Fetch a specified information element from a BSS entry |
1355 | | * @bss: BSS table entry |
1356 | | * @ie: Information element identitifier (WLAN_EID_*) |
1357 | | * Returns: Pointer to the information element (id field) or %NULL if not found |
1358 | | * |
1359 | | * This function returns the first matching information element in the BSS |
1360 | | * entry. |
1361 | | * |
1362 | | * This function is like wpa_bss_get_ie(), but uses IE buffer only from Beacon |
1363 | | * frames instead of either Beacon or Probe Response frames. |
1364 | | */ |
1365 | | const u8 * wpa_bss_get_ie_beacon(const struct wpa_bss *bss, u8 ie) |
1366 | 0 | { |
1367 | 0 | const u8 *ies; |
1368 | |
|
1369 | 0 | if (bss->beacon_ie_len == 0) |
1370 | 0 | return NULL; |
1371 | | |
1372 | 0 | ies = wpa_bss_ie_ptr(bss); |
1373 | 0 | ies += bss->ie_len; |
1374 | 0 | return get_ie(ies, bss->beacon_ie_len, ie); |
1375 | 0 | } |
1376 | | |
1377 | | |
1378 | | /** |
1379 | | * wpa_bss_get_ie_ext - Fetch a specified extended IE from a BSS entry |
1380 | | * @bss: BSS table entry |
1381 | | * @ext: Information element extension identifier (WLAN_EID_EXT_*) |
1382 | | * Returns: Pointer to the information element (id field) or %NULL if not found |
1383 | | * |
1384 | | * This function returns the first matching information element in the BSS |
1385 | | * entry. |
1386 | | */ |
1387 | | const u8 * wpa_bss_get_ie_ext(const struct wpa_bss *bss, u8 ext) |
1388 | 0 | { |
1389 | 0 | return get_ie_ext(wpa_bss_ie_ptr(bss), bss->ie_len, ext); |
1390 | 0 | } |
1391 | | |
1392 | | |
1393 | | /** |
1394 | | * wpa_bss_get_vendor_ie - Fetch a vendor information element from a BSS entry |
1395 | | * @bss: BSS table entry |
1396 | | * @vendor_type: Vendor type (four octets starting the IE payload) |
1397 | | * Returns: Pointer to the information element (id field) or %NULL if not found |
1398 | | * |
1399 | | * This function returns the first matching information element in the BSS |
1400 | | * entry. |
1401 | | */ |
1402 | | const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type) |
1403 | 0 | { |
1404 | 0 | const u8 *ies; |
1405 | 0 | const struct element *elem; |
1406 | |
|
1407 | 0 | ies = wpa_bss_ie_ptr(bss); |
1408 | |
|
1409 | 0 | for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, bss->ie_len) { |
1410 | 0 | if (elem->datalen >= 4 && |
1411 | 0 | vendor_type == WPA_GET_BE32(elem->data)) |
1412 | 0 | return &elem->id; |
1413 | 0 | } |
1414 | | |
1415 | 0 | return NULL; |
1416 | 0 | } |
1417 | | |
1418 | | |
1419 | | /** |
1420 | | * wpa_bss_get_vendor_ie_beacon - Fetch a vendor information from a BSS entry |
1421 | | * @bss: BSS table entry |
1422 | | * @vendor_type: Vendor type (four octets starting the IE payload) |
1423 | | * Returns: Pointer to the information element (id field) or %NULL if not found |
1424 | | * |
1425 | | * This function returns the first matching information element in the BSS |
1426 | | * entry. |
1427 | | * |
1428 | | * This function is like wpa_bss_get_vendor_ie(), but uses IE buffer only |
1429 | | * from Beacon frames instead of either Beacon or Probe Response frames. |
1430 | | */ |
1431 | | const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss, |
1432 | | u32 vendor_type) |
1433 | 0 | { |
1434 | 0 | const u8 *ies; |
1435 | 0 | const struct element *elem; |
1436 | |
|
1437 | 0 | if (bss->beacon_ie_len == 0) |
1438 | 0 | return NULL; |
1439 | | |
1440 | 0 | ies = wpa_bss_ie_ptr(bss); |
1441 | 0 | ies += bss->ie_len; |
1442 | |
|
1443 | 0 | for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, |
1444 | 0 | bss->beacon_ie_len) { |
1445 | 0 | if (elem->datalen >= 4 && |
1446 | 0 | vendor_type == WPA_GET_BE32(elem->data)) |
1447 | 0 | return &elem->id; |
1448 | 0 | } |
1449 | | |
1450 | 0 | return NULL; |
1451 | 0 | } |
1452 | | |
1453 | | |
1454 | | /** |
1455 | | * wpa_bss_get_vendor_ie_multi - Fetch vendor IE data from a BSS entry |
1456 | | * @bss: BSS table entry |
1457 | | * @vendor_type: Vendor type (four octets starting the IE payload) |
1458 | | * Returns: Pointer to the information element payload or %NULL if not found |
1459 | | * |
1460 | | * This function returns concatenated payload of possibly fragmented vendor |
1461 | | * specific information elements in the BSS entry. The caller is responsible for |
1462 | | * freeing the returned buffer. |
1463 | | */ |
1464 | | struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss, |
1465 | | u32 vendor_type) |
1466 | 0 | { |
1467 | 0 | struct wpabuf *buf; |
1468 | 0 | const u8 *end, *pos; |
1469 | |
|
1470 | 0 | buf = wpabuf_alloc(bss->ie_len); |
1471 | 0 | if (buf == NULL) |
1472 | 0 | return NULL; |
1473 | | |
1474 | 0 | pos = wpa_bss_ie_ptr(bss); |
1475 | 0 | end = pos + bss->ie_len; |
1476 | |
|
1477 | 0 | while (end - pos > 1) { |
1478 | 0 | u8 ie, len; |
1479 | |
|
1480 | 0 | ie = pos[0]; |
1481 | 0 | len = pos[1]; |
1482 | 0 | if (len > end - pos - 2) |
1483 | 0 | break; |
1484 | 0 | pos += 2; |
1485 | 0 | if (ie == WLAN_EID_VENDOR_SPECIFIC && len >= 4 && |
1486 | 0 | vendor_type == WPA_GET_BE32(pos)) |
1487 | 0 | wpabuf_put_data(buf, pos + 4, len - 4); |
1488 | 0 | pos += len; |
1489 | 0 | } |
1490 | |
|
1491 | 0 | if (wpabuf_len(buf) == 0) { |
1492 | 0 | wpabuf_free(buf); |
1493 | 0 | buf = NULL; |
1494 | 0 | } |
1495 | |
|
1496 | 0 | return buf; |
1497 | 0 | } |
1498 | | |
1499 | | |
1500 | | /** |
1501 | | * wpa_bss_get_vendor_ie_multi_beacon - Fetch vendor IE data from a BSS entry |
1502 | | * @bss: BSS table entry |
1503 | | * @vendor_type: Vendor type (four octets starting the IE payload) |
1504 | | * Returns: Pointer to the information element payload or %NULL if not found |
1505 | | * |
1506 | | * This function returns concatenated payload of possibly fragmented vendor |
1507 | | * specific information elements in the BSS entry. The caller is responsible for |
1508 | | * freeing the returned buffer. |
1509 | | * |
1510 | | * This function is like wpa_bss_get_vendor_ie_multi(), but uses IE buffer only |
1511 | | * from Beacon frames instead of either Beacon or Probe Response frames. |
1512 | | */ |
1513 | | struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss, |
1514 | | u32 vendor_type) |
1515 | 0 | { |
1516 | 0 | struct wpabuf *buf; |
1517 | 0 | const u8 *end, *pos; |
1518 | |
|
1519 | 0 | buf = wpabuf_alloc(bss->beacon_ie_len); |
1520 | 0 | if (buf == NULL) |
1521 | 0 | return NULL; |
1522 | | |
1523 | 0 | pos = wpa_bss_ie_ptr(bss); |
1524 | 0 | pos += bss->ie_len; |
1525 | 0 | end = pos + bss->beacon_ie_len; |
1526 | |
|
1527 | 0 | while (end - pos > 1) { |
1528 | 0 | u8 id, len; |
1529 | |
|
1530 | 0 | id = *pos++; |
1531 | 0 | len = *pos++; |
1532 | 0 | if (len > end - pos) |
1533 | 0 | break; |
1534 | 0 | if (id == WLAN_EID_VENDOR_SPECIFIC && len >= 4 && |
1535 | 0 | vendor_type == WPA_GET_BE32(pos)) |
1536 | 0 | wpabuf_put_data(buf, pos + 4, len - 4); |
1537 | 0 | pos += len; |
1538 | 0 | } |
1539 | |
|
1540 | 0 | if (wpabuf_len(buf) == 0) { |
1541 | 0 | wpabuf_free(buf); |
1542 | 0 | buf = NULL; |
1543 | 0 | } |
1544 | |
|
1545 | 0 | return buf; |
1546 | 0 | } |
1547 | | |
1548 | | |
1549 | | /** |
1550 | | * wpa_bss_get_max_rate - Get maximum legacy TX rate supported in a BSS |
1551 | | * @bss: BSS table entry |
1552 | | * Returns: Maximum legacy rate in units of 500 kbps |
1553 | | */ |
1554 | | int wpa_bss_get_max_rate(const struct wpa_bss *bss) |
1555 | 0 | { |
1556 | 0 | int rate = 0; |
1557 | 0 | const u8 *ie; |
1558 | 0 | int i; |
1559 | |
|
1560 | 0 | ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES); |
1561 | 0 | for (i = 0; ie && i < ie[1]; i++) { |
1562 | 0 | if ((ie[i + 2] & 0x7f) > rate) |
1563 | 0 | rate = ie[i + 2] & 0x7f; |
1564 | 0 | } |
1565 | |
|
1566 | 0 | ie = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES); |
1567 | 0 | for (i = 0; ie && i < ie[1]; i++) { |
1568 | 0 | if ((ie[i + 2] & 0x7f) > rate) |
1569 | 0 | rate = ie[i + 2] & 0x7f; |
1570 | 0 | } |
1571 | |
|
1572 | 0 | return rate; |
1573 | 0 | } |
1574 | | |
1575 | | |
1576 | | /** |
1577 | | * wpa_bss_get_bit_rates - Get legacy TX rates supported in a BSS |
1578 | | * @bss: BSS table entry |
1579 | | * @rates: Buffer for returning a pointer to the rates list (units of 500 kbps) |
1580 | | * Returns: number of legacy TX rates or -1 on failure |
1581 | | * |
1582 | | * The caller is responsible for freeing the returned buffer with os_free() in |
1583 | | * case of success. |
1584 | | */ |
1585 | | int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates) |
1586 | 0 | { |
1587 | 0 | const u8 *ie, *ie2; |
1588 | 0 | int i, j; |
1589 | 0 | unsigned int len; |
1590 | 0 | u8 *r; |
1591 | |
|
1592 | 0 | ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES); |
1593 | 0 | ie2 = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES); |
1594 | |
|
1595 | 0 | len = (ie ? ie[1] : 0) + (ie2 ? ie2[1] : 0); |
1596 | |
|
1597 | 0 | r = os_malloc(len); |
1598 | 0 | if (!r) |
1599 | 0 | return -1; |
1600 | | |
1601 | 0 | for (i = 0; ie && i < ie[1]; i++) |
1602 | 0 | r[i] = ie[i + 2] & 0x7f; |
1603 | |
|
1604 | 0 | for (j = 0; ie2 && j < ie2[1]; j++) |
1605 | 0 | r[i + j] = ie2[j + 2] & 0x7f; |
1606 | |
|
1607 | 0 | *rates = r; |
1608 | 0 | return len; |
1609 | 0 | } |
1610 | | |
1611 | | |
1612 | | #ifdef CONFIG_FILS |
1613 | | const u8 * wpa_bss_get_fils_cache_id(const struct wpa_bss *bss) |
1614 | | { |
1615 | | const u8 *ie; |
1616 | | |
1617 | | if (bss) { |
1618 | | ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); |
1619 | | if (ie && ie[1] >= 4 && WPA_GET_LE16(ie + 2) & BIT(7)) |
1620 | | return ie + 4; |
1621 | | } |
1622 | | |
1623 | | return NULL; |
1624 | | } |
1625 | | #endif /* CONFIG_FILS */ |
1626 | | |
1627 | | |
1628 | | int wpa_bss_ext_capab(const struct wpa_bss *bss, unsigned int capab) |
1629 | 0 | { |
1630 | 0 | if (!bss) |
1631 | 0 | return 0; |
1632 | 0 | return ieee802_11_ext_capab(wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB), |
1633 | 0 | capab); |
1634 | 0 | } |
1635 | | |
1636 | | |
1637 | | static void |
1638 | | wpa_bss_parse_ml_rnr_ap_info(struct wpa_supplicant *wpa_s, |
1639 | | struct wpa_bss *bss, u8 ap_mld_id, |
1640 | | const struct ieee80211_neighbor_ap_info *ap_info, |
1641 | | size_t len, u16 *seen) |
1642 | 2.47k | { |
1643 | 2.47k | const u8 *pos, *end; |
1644 | 2.47k | const u8 *mld_params; |
1645 | 2.47k | u8 count, mld_params_offset; |
1646 | 2.47k | u8 i, type, link_id; |
1647 | | |
1648 | 2.47k | count = RNR_TBTT_INFO_COUNT_VAL(ap_info->tbtt_info_hdr) + 1; |
1649 | 2.47k | type = ap_info->tbtt_info_hdr & RNR_TBTT_INFO_HDR_TYPE_MSK; |
1650 | | |
1651 | | /* MLD information is at offset 13 or at start */ |
1652 | 2.47k | if (type == 0 && ap_info->tbtt_info_len >= RNR_TBTT_INFO_MLD_LEN) { |
1653 | | /* MLD info is appended */ |
1654 | 1.44k | mld_params_offset = RNR_TBTT_INFO_LEN; |
1655 | 1.44k | } else { |
1656 | | /* TODO: Support NSTR AP */ |
1657 | 1.03k | return; |
1658 | 1.03k | } |
1659 | | |
1660 | 1.44k | pos = (const u8 *) ap_info; |
1661 | 1.44k | end = pos + len; |
1662 | 1.44k | pos += sizeof(*ap_info); |
1663 | | |
1664 | 5.14k | for (i = 0; i < count; i++, pos += ap_info->tbtt_info_len) { |
1665 | 3.70k | if (end - pos < ap_info->tbtt_info_len) |
1666 | 0 | break; |
1667 | | |
1668 | 3.70k | mld_params = pos + mld_params_offset; |
1669 | | |
1670 | 3.70k | link_id = *(mld_params + 1) & EHT_ML_LINK_ID_MSK; |
1671 | 3.70k | if (link_id >= MAX_NUM_MLD_LINKS) |
1672 | 252 | continue; |
1673 | | |
1674 | 3.45k | if (*mld_params != ap_mld_id) { |
1675 | 725 | wpa_printf(MSG_DEBUG, |
1676 | 725 | "MLD: Reported link not part of MLD"); |
1677 | 2.72k | } else if (!(BIT(link_id) & *seen)) { |
1678 | 1.33k | struct mld_link *l; |
1679 | | |
1680 | 1.33k | *seen |= BIT(link_id); |
1681 | 1.33k | wpa_printf(MSG_DEBUG, "MLD: mld ID=%u, link ID=%u", |
1682 | 1.33k | *mld_params, link_id); |
1683 | | |
1684 | 1.33k | bss->valid_links |= BIT(link_id); |
1685 | 1.33k | l = &bss->mld_links[link_id]; |
1686 | 1.33k | os_memcpy(l->bssid, pos + 1, ETH_ALEN); |
1687 | 1.33k | l->disabled = mld_params[2] & |
1688 | 1.33k | RNR_TBTT_INFO_MLD_PARAM2_LINK_DISABLED; |
1689 | 1.33k | l->freq = ieee80211_chan_to_freq(NULL, |
1690 | 1.33k | ap_info->op_class, |
1691 | 1.33k | ap_info->channel); |
1692 | 1.33k | } |
1693 | 3.45k | } |
1694 | 1.44k | } |
1695 | | |
1696 | | |
1697 | | /** |
1698 | | * wpa_bss_validate_rsne_ml - Validate RSN IEs (RSNE/RSNOE/RSNO2E) of a BSS |
1699 | | * @wpa_s: Pointer to wpa_supplicant data |
1700 | | * @ssid: Network config |
1701 | | * @bss: BSS table entry |
1702 | | * @rsne_type_p: Type of RSNE to validate. If -1 is given, choose as per the |
1703 | | * presence of RSN elements (association link); otherwise, validate |
1704 | | * against the requested type (other affiliated links). |
1705 | | * @ref_rsne: Buffer for RSNE data; filled in from the main link to compare |
1706 | | * against and used internally |
1707 | | * Returns: true if the BSS configuration matches local profile and the elements |
1708 | | * meet MLO requirements, false otherwise |
1709 | | */ |
1710 | | static bool |
1711 | | wpa_bss_validate_rsne_ml(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
1712 | | struct wpa_bss *bss, int *rsne_type_p, |
1713 | | struct wpa_ie_data *ref_rsne) |
1714 | 0 | { |
1715 | 0 | struct ieee802_11_elems elems; |
1716 | 0 | struct wpa_ie_data wpa_ie; |
1717 | 0 | const u8 *rsne; |
1718 | 0 | size_t rsne_len; |
1719 | 0 | int rsne_type; |
1720 | 0 | const u8 *ies_pos = wpa_bss_ie_ptr(bss); |
1721 | 0 | size_t ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
1722 | |
|
1723 | 0 | if (wpas_security_profile_active(wpa_s) && ssid->security_profiles) { |
1724 | 0 | const u8 *sp; |
1725 | | |
1726 | | /* A security profile match is sufficient to allow the link to |
1727 | | * be used. */ |
1728 | 0 | sp = wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_SECURITY_PROFILE); |
1729 | 0 | if (security_profile_select_best(sp, ssid->security_profiles)) |
1730 | 0 | return true; |
1731 | 0 | } |
1732 | | |
1733 | 0 | if (ieee802_11_parse_elems(ies_pos, ies_len, &elems, 0) == |
1734 | 0 | ParseFailed) { |
1735 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: Failed to parse elements"); |
1736 | 0 | return false; |
1737 | 0 | } |
1738 | | |
1739 | 0 | if (elems.rsne_override_2 && wpas_rsn_overriding(wpa_s, ssid)) { |
1740 | 0 | rsne = elems.rsne_override_2; |
1741 | 0 | rsne_len = elems.rsne_override_2_len; |
1742 | 0 | rsne_type = 2; |
1743 | 0 | } else if (elems.rsne_override && wpas_rsn_overriding(wpa_s, ssid)) { |
1744 | 0 | rsne = elems.rsne_override; |
1745 | 0 | rsne_len = elems.rsne_override_len; |
1746 | 0 | rsne_type = 1; |
1747 | 0 | } else { |
1748 | 0 | rsne = elems.rsn_ie; |
1749 | 0 | rsne_len = elems.rsn_ie_len; |
1750 | 0 | rsne_type = 0; |
1751 | 0 | } |
1752 | |
|
1753 | 0 | if (!rsne || |
1754 | 0 | wpa_parse_wpa_ie(rsne - 2, 2 + rsne_len, &wpa_ie)) { |
1755 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No RSN element"); |
1756 | 0 | return false; |
1757 | 0 | } |
1758 | | |
1759 | 0 | if (*rsne_type_p != -1 && *rsne_type_p != rsne_type) { |
1760 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1761 | 0 | "MLD: No matching RSN element (RSNO mismatch)"); |
1762 | 0 | return false; |
1763 | 0 | } |
1764 | | |
1765 | 0 | if (!(wpa_ie.capabilities & WPA_CAPABILITY_MFPC) || |
1766 | 0 | wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION) { |
1767 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1768 | 0 | "MLD: No management frame protection"); |
1769 | 0 | return false; |
1770 | 0 | } |
1771 | | |
1772 | | /* |
1773 | | * Security Profile element preference (IEEE P802.11bn/D2.0, 37.33): |
1774 | | * If this link's AP advertises a Security Profile element whose |
1775 | | * profile number implies an AKM/cipher that matches the STA's |
1776 | | * config, augment wpa_ie.key_mgmt/pairwise_cipher so the checks below |
1777 | | * pass even when the RSNE/RSNOE/RSNO2E does not explicitly list those |
1778 | | * values. Without this, an AP MLD that only advertises CCMP/legacy AKMs |
1779 | | * in its RSNE but supports GCMP-256 via a Security Profile would have |
1780 | | * this link (and potentially all links, since they share the same |
1781 | | * requirement) wrongly excluded from the usable-links bitmap. |
1782 | | */ |
1783 | 0 | if (wpas_security_profile_active(wpa_s)) { |
1784 | 0 | const u8 *sp; |
1785 | 0 | int sp_key_mgmt; |
1786 | |
|
1787 | 0 | sp = wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_SECURITY_PROFILE); |
1788 | |
|
1789 | 0 | sp_key_mgmt = security_profile_get_key_mgmt(sp, ssid->key_mgmt); |
1790 | 0 | if (!sp_key_mgmt || |
1791 | 0 | !(ssid->pairwise_cipher & WPA_CIPHER_GCMP_256)) |
1792 | 0 | goto no_sp_match; |
1793 | | |
1794 | 0 | if (!(wpa_ie.pairwise_cipher & WPA_CIPHER_GCMP_256)) { |
1795 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1796 | 0 | "MLD: Security Profile element overrides RSNE pairwise cipher (GCMP-256)"); |
1797 | 0 | wpa_ie.pairwise_cipher |= WPA_CIPHER_GCMP_256; |
1798 | 0 | } |
1799 | |
|
1800 | 0 | if (!(wpa_ie.key_mgmt & ssid->key_mgmt)) { |
1801 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1802 | 0 | "MLD: Security Profile element overrides RSN element AKM (key_mgmt=0x%x)", |
1803 | 0 | sp_key_mgmt); |
1804 | 0 | wpa_ie.key_mgmt |= sp_key_mgmt; |
1805 | 0 | } |
1806 | 0 | no_sp_match: |
1807 | 0 | } |
1808 | | |
1809 | 0 | wpa_ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK | |
1810 | 0 | WPA_KEY_MGMT_PSK_SHA256); |
1811 | 0 | if (!(wpa_ie.key_mgmt & ssid->key_mgmt)) { |
1812 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No valid key management"); |
1813 | 0 | return false; |
1814 | 0 | } |
1815 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: key_mgmt=0x%x", wpa_ie.key_mgmt); |
1816 | |
|
1817 | 0 | wpa_ie.pairwise_cipher &= ~(WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | |
1818 | 0 | WPA_CIPHER_WEP104 | WPA_CIPHER_TKIP); |
1819 | 0 | if (!(wpa_ie.pairwise_cipher & ssid->pairwise_cipher)) { |
1820 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No valid pairwise cipher"); |
1821 | 0 | return false; |
1822 | 0 | } |
1823 | | |
1824 | 0 | if (*rsne_type_p == -1) { |
1825 | 0 | os_memcpy(ref_rsne, &wpa_ie, sizeof(wpa_ie)); |
1826 | |
|
1827 | 0 | *rsne_type_p = rsne_type; |
1828 | 0 | } else { |
1829 | | /* Verify the neighbor given rsne_type_p and ref_rsne */ |
1830 | 0 | if (!(wpa_ie.key_mgmt & ref_rsne->key_mgmt)) { |
1831 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1832 | 0 | "MLD: Neighbor without common AKM"); |
1833 | 0 | return false; |
1834 | 0 | } |
1835 | | |
1836 | 0 | if (!(wpa_ie.pairwise_cipher & ref_rsne->pairwise_cipher)) { |
1837 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1838 | 0 | "MLD: Neighbor without common pairwise cipher"); |
1839 | 0 | return false; |
1840 | 0 | } |
1841 | 0 | } |
1842 | | |
1843 | 0 | return true; |
1844 | 0 | } |
1845 | | |
1846 | | |
1847 | | /* |
1848 | | * SME-based association with an AP MLD requires the driver to have a |
1849 | | * sufficiently recent scan entry for every requested link. With nl80211-based |
1850 | | * drivers, cfg80211 rejects the association if the BSS entry for any link is |
1851 | | * older than 30 seconds (IEEE80211_SCAN_RESULT_EXPIRE). Since the BSS table in |
1852 | | * wpa_supplicant keeps entries considerably longer than that |
1853 | | * (bss_expiration_age, 180 seconds by default) and does not refresh entries for |
1854 | | * the links of the current AP MLD while associated, consider an affiliated link |
1855 | | * with an older scan entry to be missing so that an ML probe request gets used |
1856 | | * to refresh the information before association. Leave some margin below the |
1857 | | * kernel limit to cover the time needed for authentication. |
1858 | | */ |
1859 | 0 | #define WPA_BSS_ML_LINK_FRESH_AGE 25 /* seconds */ |
1860 | | |
1861 | | /** |
1862 | | * wpa_bss_get_usable_links - Retrieve the usable links of the AP MLD |
1863 | | * @wpa_s: Pointer to wpa_supplicant data |
1864 | | * @bss: BSS table entry |
1865 | | * @ssid: Target SSID (or %NULL) |
1866 | | * @missing_links: Result bitmask of links that were not discovered (or %NULL) |
1867 | | * Returns: Bitmap of links that are usable, or 0 for non-MLD or failure |
1868 | | * |
1869 | | * Validate each link of the MLD to verify that it is compatible and connection |
1870 | | * to each of the links is allowed. |
1871 | | */ |
1872 | | u16 wpa_bss_get_usable_links(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
1873 | | struct wpa_ssid *ssid, u16 *missing_links) |
1874 | 0 | { |
1875 | 0 | struct wpa_ie_data rsne; |
1876 | 0 | struct os_reltime now; |
1877 | 0 | int rsne_type; |
1878 | 0 | u16 usable_links = 0; |
1879 | 0 | u8 link_id; |
1880 | |
|
1881 | 0 | if (!bss->valid_links) |
1882 | 0 | return 0; |
1883 | | |
1884 | 0 | os_get_reltime(&now); |
1885 | |
|
1886 | 0 | rsne_type = -1; |
1887 | 0 | os_memset(&rsne, 0, sizeof(rsne)); |
1888 | 0 | if (ssid && |
1889 | 0 | !wpa_bss_validate_rsne_ml(wpa_s, ssid, bss, &rsne_type, &rsne)) { |
1890 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No valid key management"); |
1891 | 0 | return 0; |
1892 | 0 | } |
1893 | | |
1894 | 0 | usable_links = BIT(bss->mld_link_id); |
1895 | |
|
1896 | 0 | for_each_link(bss->valid_links, link_id) { |
1897 | 0 | struct wpa_bss *neigh_bss; |
1898 | 0 | u16 ext_mld_capa_mask; |
1899 | |
|
1900 | 0 | if (link_id == bss->mld_link_id) |
1901 | 0 | continue; |
1902 | | |
1903 | 0 | if (ssid && ssid->ssid_len) |
1904 | 0 | neigh_bss = wpa_bss_get(wpa_s, |
1905 | 0 | bss->mld_links[link_id].bssid, |
1906 | 0 | ssid->ssid, |
1907 | 0 | ssid->ssid_len); |
1908 | 0 | else |
1909 | 0 | neigh_bss = wpa_bss_get_bssid(wpa_s, |
1910 | 0 | bss->mld_links[link_id].bssid); |
1911 | |
|
1912 | 0 | if (!neigh_bss) { |
1913 | 0 | if (missing_links) |
1914 | 0 | *missing_links |= BIT(link_id); |
1915 | 0 | continue; |
1916 | 0 | } |
1917 | | |
1918 | 0 | if (os_reltime_expired(&now, &neigh_bss->last_update, |
1919 | 0 | WPA_BSS_ML_LINK_FRESH_AGE)) { |
1920 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1921 | 0 | "MLD: Scan entry for neighbor " MACSTR |
1922 | 0 | " is too old for association; consider link %u missing", |
1923 | 0 | MAC2STR(neigh_bss->bssid), link_id); |
1924 | 0 | if (missing_links) |
1925 | 0 | *missing_links |= BIT(link_id); |
1926 | 0 | continue; |
1927 | 0 | } |
1928 | | |
1929 | | /* Check that the affiliated links are for the same AP MLD and |
1930 | | * the information matches */ |
1931 | 0 | if (!neigh_bss->valid_links) { |
1932 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1933 | 0 | "MLD: Neighbor without Multi-Link support"); |
1934 | 0 | continue; |
1935 | 0 | } |
1936 | | |
1937 | 0 | if (neigh_bss->mld_link_id != link_id) { |
1938 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1939 | 0 | "MLD: Neighbor has unexpected link ID (%d != %d)", |
1940 | 0 | neigh_bss->mld_link_id, link_id); |
1941 | 0 | continue; |
1942 | 0 | } |
1943 | | |
1944 | 0 | if (!ether_addr_equal(bss->mld_addr, neigh_bss->mld_addr)) { |
1945 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1946 | 0 | "MLD: Neighbor has a different MLD MAC address (" |
1947 | 0 | MACSTR " != " MACSTR ")", |
1948 | 0 | MAC2STR(neigh_bss->mld_addr), |
1949 | 0 | MAC2STR(bss->mld_addr)); |
1950 | 0 | continue; |
1951 | 0 | } |
1952 | | |
1953 | 0 | if ((bss->mld_capa & ~EHT_ML_MLD_CAPA_RESERVED) != |
1954 | 0 | (neigh_bss->mld_capa & ~EHT_ML_MLD_CAPA_RESERVED)) { |
1955 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1956 | 0 | "MLD: Neighbor's MLD Capabilities do not match (0x%04x != 0x%04x)", |
1957 | 0 | neigh_bss->mld_capa, bss->mld_capa); |
1958 | 0 | continue; |
1959 | 0 | } |
1960 | | |
1961 | 0 | if ((bss->eml_capa & ~EHT_ML_EML_CAPA_RESERVED) != |
1962 | 0 | (neigh_bss->eml_capa & ~EHT_ML_EML_CAPA_RESERVED)) { |
1963 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1964 | 0 | "MLD: Neighbor's EML Capabilities do not match (0x%04x != 0x%04x", |
1965 | 0 | neigh_bss->eml_capa, bss->eml_capa); |
1966 | 0 | continue; |
1967 | 0 | } |
1968 | | |
1969 | | /* |
1970 | | * Check well-defined values in Extended MLD Capabilities. |
1971 | | * In particular the Recommended Max Simultaneous Links |
1972 | | * subfield may change over time and is reserved depending on |
1973 | | * the frame that it is carried in. |
1974 | | * See IEEE Std 802.11be-2024, Table 9-417o. |
1975 | | */ |
1976 | 0 | ext_mld_capa_mask = |
1977 | 0 | EHT_ML_EXT_MLD_CAPA_OP_PARAM_UPDATE | |
1978 | 0 | EHT_ML_EXT_MLD_CAPA_NSTR_UPDATE | |
1979 | 0 | EHT_ML_EXT_MLD_CAPA_EMLSR_ENA_ONE_LINK; |
1980 | 0 | if ((bss->ext_mld_capa & ext_mld_capa_mask) != |
1981 | 0 | (neigh_bss->ext_mld_capa & ext_mld_capa_mask)) { |
1982 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1983 | 0 | "MLD: Neighbors Extended MLD Capabilities do not match (0x%04x != 0x%04x)", |
1984 | 0 | neigh_bss->ext_mld_capa, bss->ext_mld_capa); |
1985 | 0 | continue; |
1986 | 0 | } |
1987 | | |
1988 | 0 | if (ssid) { |
1989 | | /* As per IEEE Std 802.11be-2024, 12.6.2 (RSNA |
1990 | | * selection), all APs affiliated with an AP MLD shall |
1991 | | * advertise at least one common AKM suite selector in |
1992 | | * the AKM Suite List field of the RSNE. Discard links |
1993 | | * that do not have compatible configuration with the |
1994 | | * association link. |
1995 | | */ |
1996 | 0 | if (!wpa_bss_validate_rsne_ml(wpa_s, ssid, neigh_bss, |
1997 | 0 | &rsne_type, &rsne)) { |
1998 | 0 | wpa_printf(MSG_DEBUG, |
1999 | 0 | "MLD: Discard link %u due to RSN parameter mismatch", |
2000 | 0 | link_id); |
2001 | 0 | continue; |
2002 | 0 | } |
2003 | 0 | } |
2004 | | |
2005 | 0 | if ((!ssid || |
2006 | 0 | wpa_scan_res_match(wpa_s, 0, neigh_bss, ssid, 1, 0, |
2007 | 0 | true)) && |
2008 | 0 | !wpa_bssid_ignore_is_listed(wpa_s, neigh_bss->bssid)) { |
2009 | 0 | usable_links |= BIT(link_id); |
2010 | 0 | } |
2011 | 0 | } |
2012 | |
|
2013 | 0 | return usable_links; |
2014 | 0 | } |
2015 | | |
2016 | | |
2017 | | /** |
2018 | | * wpa_bss_parse_basic_ml_element - Parse the Basic Multi-Link element |
2019 | | * @wpa_s: Pointer to wpa_supplicant data |
2020 | | * @bss: BSS table entry |
2021 | | * |
2022 | | * Parses the Basic Multi-Link element of the BSS into @link_info using the scan |
2023 | | * information stored in the wpa_supplicant data to fill in information for |
2024 | | * links where possible. |
2025 | | */ |
2026 | | void wpa_bss_parse_basic_ml_element(struct wpa_supplicant *wpa_s, |
2027 | | struct wpa_bss *bss) |
2028 | 3.09k | { |
2029 | 3.09k | struct ieee802_11_elems elems; |
2030 | 3.09k | struct wpabuf *mlbuf = NULL; |
2031 | 3.09k | const struct element *elem; |
2032 | 3.09k | size_t ml_ie_len; |
2033 | 3.09k | const struct ieee80211_eht_ml *eht_ml; |
2034 | 3.09k | const struct eht_ml_basic_common_info *ml_basic_common_info; |
2035 | 3.09k | const u8 *mbssid_idx_elem; |
2036 | 3.09k | u8 i, pos, link_id, ap_mld_id; |
2037 | 3.09k | const u16 control_mask = |
2038 | 3.09k | MULTI_LINK_CONTROL_TYPE_MASK | |
2039 | 3.09k | BASIC_MULTI_LINK_CTRL_PRES_LINK_ID | |
2040 | 3.09k | BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT | |
2041 | 3.09k | BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA; |
2042 | 3.09k | const u16 control = |
2043 | 3.09k | MULTI_LINK_CONTROL_TYPE_BASIC | |
2044 | 3.09k | BASIC_MULTI_LINK_CTRL_PRES_LINK_ID | |
2045 | 3.09k | BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT | |
2046 | 3.09k | BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA; |
2047 | 3.09k | u16 seen; |
2048 | 3.09k | const u8 *ies_pos = wpa_bss_ie_ptr(bss); |
2049 | 3.09k | size_t ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
2050 | 3.09k | struct mld_link *l; |
2051 | | |
2052 | 3.09k | if (ieee802_11_parse_elems(ies_pos, ies_len, &elems, 1) == |
2053 | 3.09k | ParseFailed) { |
2054 | 195 | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: Failed to parse elements"); |
2055 | 195 | goto out; |
2056 | 195 | } |
2057 | | |
2058 | 2.90k | mlbuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true); |
2059 | 2.90k | if (!mlbuf) { |
2060 | 2.01k | wpa_dbg(wpa_s, MSG_DEBUG, "MLD: No Multi-Link element"); |
2061 | 2.01k | goto out; |
2062 | 2.01k | } |
2063 | | |
2064 | 893 | ml_ie_len = wpabuf_len(mlbuf); |
2065 | | |
2066 | | /* |
2067 | | * for ext ID + 2 control + common info len |
2068 | | */ |
2069 | 893 | if (ml_ie_len < sizeof(*eht_ml) + sizeof(*ml_basic_common_info)) |
2070 | 12 | goto out; |
2071 | | |
2072 | 881 | eht_ml = (const struct ieee80211_eht_ml *) wpabuf_head(mlbuf); |
2073 | 881 | if ((le_to_host16(eht_ml->ml_control) & control_mask) != control) { |
2074 | 38 | wpa_printf(MSG_DEBUG, |
2075 | 38 | "MLD: Unexpected Multi-Link element control=0x%x (mask 0x%x expected 0x%x)", |
2076 | 38 | le_to_host16(eht_ml->ml_control), control_mask, |
2077 | 38 | control); |
2078 | 38 | goto out; |
2079 | 38 | } |
2080 | | |
2081 | 843 | ml_basic_common_info = |
2082 | 843 | (const struct eht_ml_basic_common_info *) eht_ml->variable; |
2083 | | |
2084 | 843 | if (ml_ie_len < sizeof(*eht_ml) + ml_basic_common_info->len) |
2085 | 6 | goto out; |
2086 | | |
2087 | | /* Minimum Common info length to be valid */ |
2088 | 837 | if (ml_basic_common_info->len < |
2089 | 837 | sizeof(*ml_basic_common_info) + 1 + 1 + 2) |
2090 | 66 | goto out; |
2091 | | |
2092 | | /* Link ID Info, BSS Parameters Change Count (see control/control_mask) |
2093 | | */ |
2094 | 771 | pos = 1 + 1; |
2095 | | |
2096 | | /* Medium Synchronization Delay Information */ |
2097 | 771 | if (le_to_host16(eht_ml->ml_control) & |
2098 | 771 | BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) { |
2099 | 56 | if (ml_basic_common_info->len < |
2100 | 56 | sizeof(*ml_basic_common_info) + pos + 2) |
2101 | 0 | goto out; |
2102 | 56 | pos += 2; |
2103 | 56 | } |
2104 | | |
2105 | | /* EML Capabilities */ |
2106 | 771 | bss->eml_capa = 0; |
2107 | 771 | if (le_to_host16(eht_ml->ml_control) & |
2108 | 771 | BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) { |
2109 | 122 | if (ml_basic_common_info->len < |
2110 | 122 | sizeof(*ml_basic_common_info) + pos + 2) |
2111 | 2 | goto out; |
2112 | 120 | bss->eml_capa = |
2113 | 120 | WPA_GET_LE16(&ml_basic_common_info->variable[pos]); |
2114 | 120 | pos += 2; |
2115 | 120 | } |
2116 | | |
2117 | | /* MLD Capabilities And Operations (always present, see |
2118 | | * control/control_mask) */ |
2119 | 769 | if (ml_basic_common_info->len < sizeof(*ml_basic_common_info) + pos + 2) |
2120 | 4 | goto out; |
2121 | 765 | bss->mld_capa = WPA_GET_LE16(&ml_basic_common_info->variable[pos]); |
2122 | 765 | pos += 2; |
2123 | | |
2124 | | /* AP MLD ID from MLE if present (see comment below) */ |
2125 | 765 | if (le_to_host16(eht_ml->ml_control) & |
2126 | 765 | BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) { |
2127 | 60 | if (ml_basic_common_info->len < |
2128 | 60 | sizeof(*ml_basic_common_info) + pos + 1) |
2129 | 4 | goto out; |
2130 | | |
2131 | 56 | ap_mld_id = ml_basic_common_info->variable[pos]; |
2132 | | |
2133 | 56 | pos++; |
2134 | 705 | } else { |
2135 | 705 | ap_mld_id = 0; |
2136 | 705 | } |
2137 | | |
2138 | | /* Extended MLD Capabilities And Operations */ |
2139 | 761 | bss->ext_mld_capa = 0; |
2140 | 761 | if (le_to_host16(eht_ml->ml_control) & |
2141 | 761 | BASIC_MULTI_LINK_CTRL_PRES_EXT_MLD_CAP) { |
2142 | 56 | if (ml_basic_common_info->len < |
2143 | 56 | sizeof(*ml_basic_common_info) + pos + 2) |
2144 | 4 | goto out; |
2145 | | |
2146 | 52 | bss->ext_mld_capa = |
2147 | 52 | WPA_GET_LE16(&ml_basic_common_info->variable[pos]); |
2148 | | |
2149 | 52 | pos += 2; |
2150 | 52 | } |
2151 | | |
2152 | 757 | if (ml_basic_common_info->len < sizeof(*ml_basic_common_info) + pos) |
2153 | 0 | goto out; |
2154 | | |
2155 | 757 | link_id = ml_basic_common_info->variable[0] & EHT_ML_LINK_ID_MSK; |
2156 | 757 | if (link_id >= MAX_NUM_MLD_LINKS) { |
2157 | 11 | wpa_printf(MSG_DEBUG, "MLD: Invalid link ID %u in Basic MLE", |
2158 | 11 | link_id); |
2159 | 11 | goto out; |
2160 | 11 | } |
2161 | | |
2162 | 746 | os_memcpy(bss->mld_addr, ml_basic_common_info->mld_addr, ETH_ALEN); |
2163 | | |
2164 | 746 | bss->mld_link_id = link_id; |
2165 | 746 | bss->valid_links = BIT(link_id); |
2166 | 746 | seen = bss->valid_links; |
2167 | | |
2168 | 746 | l = &bss->mld_links[link_id]; |
2169 | 746 | os_memcpy(l->bssid, bss->bssid, ETH_ALEN); |
2170 | 746 | l->freq = bss->freq; |
2171 | | |
2172 | 746 | bss->mld_bss_non_transmitted = false; |
2173 | | |
2174 | | /* |
2175 | | * We should be able to rely on the Multiple BSSID Index element |
2176 | | * to be included if the BSS is nontransmitted. Both if it was |
2177 | | * extracted from a beacon and if it came from an ML probe |
2178 | | * response (i.e. not listed in IEEE Std 802.11be-2024, 35.3.3.4). |
2179 | | * |
2180 | | * Note that the AP MLD ID and the Multiple-BSSID Index will be |
2181 | | * identical if the information was reported by the |
2182 | | * corresponding transmitting AP (IEEE Std 802.11be-2024, 9.4.2.169.2). |
2183 | | * As an AP MLD ID will not be explicitly provided we need to |
2184 | | * rely on the Multiple-BSSID Index element. This is generally the case |
2185 | | * when the BSS information was read from a Multiple-BSSID element. |
2186 | | * |
2187 | | * The alternative scenario is a BSS discovered using a |
2188 | | * Multi-Link Probe Response. In that case, we can still |
2189 | | * determine whether the BSS is nontransmitted or not using the |
2190 | | * Multiple BSSID-Index element. However, the AP MLD ID may be |
2191 | | * different inside the ML Probe Response and the driver also |
2192 | | * needs to deal with this during inheritance. |
2193 | | * |
2194 | | * We assume the driver either |
2195 | | * - includes the appropriate AP MLD ID in the MLE it generates |
2196 | | * (see above), or |
2197 | | * - rewrites the RNR so that the AP MLD ID matches the |
2198 | | * Multiple-BSSID Index element. |
2199 | | */ |
2200 | 746 | mbssid_idx_elem = wpa_bss_get_ie(bss, WLAN_EID_MULTIPLE_BSSID_INDEX); |
2201 | 746 | if (mbssid_idx_elem && mbssid_idx_elem[1] >= 1) { |
2202 | 26 | if (!(le_to_host16(eht_ml->ml_control) & |
2203 | 26 | BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID)) |
2204 | 25 | ap_mld_id = mbssid_idx_elem[2]; |
2205 | 26 | bss->mld_bss_non_transmitted = !!mbssid_idx_elem[2]; |
2206 | 26 | } |
2207 | | |
2208 | 791k | for_each_element_id(elem, WLAN_EID_REDUCED_NEIGHBOR_REPORT, |
2209 | 791k | wpa_bss_ie_ptr(bss), |
2210 | 791k | bss->ie_len ? bss->ie_len : bss->beacon_ie_len) { |
2211 | 1.83k | const struct ieee80211_neighbor_ap_info *ap_info; |
2212 | 1.83k | const u8 *ap_info_pos = elem->data; |
2213 | 1.83k | size_t len = elem->datalen; |
2214 | | |
2215 | | /* RNR IE may contain more than one Neighbor AP Info */ |
2216 | 4.31k | while (sizeof(*ap_info) <= len) { |
2217 | 2.53k | size_t ap_info_len = sizeof(*ap_info); |
2218 | 2.53k | u8 count; |
2219 | | |
2220 | 2.53k | ap_info = (const struct ieee80211_neighbor_ap_info *) |
2221 | 2.53k | ap_info_pos; |
2222 | 2.53k | count = RNR_TBTT_INFO_COUNT_VAL(ap_info->tbtt_info_hdr) + 1; |
2223 | 2.53k | ap_info_len += count * ap_info->tbtt_info_len; |
2224 | | |
2225 | 2.53k | if (ap_info_len > len) |
2226 | 56 | goto out; |
2227 | | |
2228 | 2.47k | wpa_bss_parse_ml_rnr_ap_info(wpa_s, bss, ap_mld_id, |
2229 | 2.47k | ap_info, len, &seen); |
2230 | | |
2231 | 2.47k | ap_info_pos += ap_info_len; |
2232 | 2.47k | len -= ap_info_len; |
2233 | 2.47k | } |
2234 | 1.83k | } |
2235 | | |
2236 | 690 | wpa_printf(MSG_DEBUG, "MLD: valid_links=0x%04hx", |
2237 | 690 | bss->valid_links); |
2238 | | |
2239 | 10.3k | for_each_link(bss->valid_links, i) { |
2240 | 2.00k | wpa_printf(MSG_DEBUG, "MLD: link=%u, bssid=" MACSTR, |
2241 | 2.00k | i, MAC2STR(bss->mld_links[i].bssid)); |
2242 | 2.00k | } |
2243 | | |
2244 | 690 | wpabuf_free(mlbuf); |
2245 | 690 | return; |
2246 | | |
2247 | 2.40k | out: |
2248 | 2.40k | os_memset(bss->mld_addr, 0, ETH_ALEN); |
2249 | 2.40k | bss->valid_links = 0; |
2250 | 2.40k | wpabuf_free(mlbuf); |
2251 | 2.40k | } |
2252 | | |
2253 | | |
2254 | | /* |
2255 | | * wpa_bss_parse_reconf_ml_element - Parse the Reconfiguration ML element |
2256 | | * @wpa_s: Pointer to wpa_supplicant data |
2257 | | * @bss: BSS table entry |
2258 | | * Returns: The bitmap of links that are going to be removed |
2259 | | */ |
2260 | | u16 wpa_bss_parse_reconf_ml_element(struct wpa_supplicant *wpa_s, |
2261 | | struct wpa_bss *bss) |
2262 | 0 | { |
2263 | 0 | struct ieee802_11_elems elems; |
2264 | 0 | struct wpabuf *mlbuf; |
2265 | 0 | const u8 *pos = wpa_bss_ie_ptr(bss); |
2266 | 0 | size_t len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
2267 | 0 | const struct ieee80211_eht_ml *ml; |
2268 | 0 | const struct eht_ml_reconf_common_info *common_info; |
2269 | 0 | u16 removed_links = 0; |
2270 | 0 | u8 expected_ml_common_len; |
2271 | |
|
2272 | 0 | if (ieee802_11_parse_elems(pos, len, &elems, 1) == ParseFailed) |
2273 | 0 | return 0; |
2274 | | |
2275 | 0 | if (!elems.reconf_mle || !elems.reconf_mle_len) |
2276 | 0 | return 0; |
2277 | | |
2278 | 0 | mlbuf = ieee802_11_defrag(elems.reconf_mle, elems.reconf_mle_len, true); |
2279 | 0 | if (!mlbuf) |
2280 | 0 | return 0; |
2281 | | |
2282 | 0 | ml = (const struct ieee80211_eht_ml *) wpabuf_head(mlbuf); |
2283 | 0 | len = wpabuf_len(mlbuf); |
2284 | | |
2285 | | /* There must be at least one octet for the Common Info Length subfield |
2286 | | */ |
2287 | 0 | if (len < sizeof(*ml) + 1UL) |
2288 | 0 | goto out; |
2289 | | |
2290 | 0 | expected_ml_common_len = 1; |
2291 | 0 | if (le_to_host16(ml->ml_control) & |
2292 | 0 | RECONF_MULTI_LINK_CTRL_PRES_MLD_MAC_ADDR) |
2293 | 0 | expected_ml_common_len += ETH_ALEN; |
2294 | |
|
2295 | 0 | common_info = (const struct eht_ml_reconf_common_info *) ml->variable; |
2296 | 0 | if (len < sizeof(*ml) + common_info->len) { |
2297 | 0 | wpa_printf(MSG_DEBUG, |
2298 | 0 | "MLD: Unexpected Reconfiguration ML element length: (%zu < %zu)", |
2299 | 0 | len, sizeof(*ml) + common_info->len); |
2300 | 0 | goto out; |
2301 | 0 | } |
2302 | | |
2303 | 0 | if (common_info->len < expected_ml_common_len) { |
2304 | 0 | wpa_printf(MSG_DEBUG, |
2305 | 0 | "MLD: Invalid common info len=%u; min expected=%u", |
2306 | 0 | common_info->len, expected_ml_common_len); |
2307 | 0 | goto out; |
2308 | 0 | } |
2309 | | |
2310 | 0 | pos = ml->variable + common_info->len; |
2311 | 0 | len -= sizeof(*ml) + common_info->len; |
2312 | |
|
2313 | 0 | while (len >= 2 + sizeof(struct ieee80211_eht_per_sta_profile)) { |
2314 | 0 | size_t sub_elem_len; |
2315 | 0 | int num_frag_subelems; |
2316 | |
|
2317 | 0 | num_frag_subelems = |
2318 | 0 | ieee802_11_defrag_mle_subelem(mlbuf, pos, |
2319 | 0 | &sub_elem_len); |
2320 | 0 | if (num_frag_subelems < 0) { |
2321 | 0 | wpa_printf(MSG_DEBUG, |
2322 | 0 | "MLD: Failed to parse MLE subelem"); |
2323 | 0 | break; |
2324 | 0 | } |
2325 | | |
2326 | 0 | if ((size_t) num_frag_subelems * 2 > len) |
2327 | 0 | goto out; |
2328 | 0 | len -= num_frag_subelems * 2; |
2329 | |
|
2330 | 0 | if (2 + sub_elem_len > len) { |
2331 | 0 | wpa_printf(MSG_DEBUG, |
2332 | 0 | "MLD: Invalid link info len: %zu %zu", |
2333 | 0 | 2 + sub_elem_len, len); |
2334 | 0 | goto out; |
2335 | 0 | } |
2336 | | |
2337 | 0 | if (*pos == MULTI_LINK_SUB_ELEM_ID_PER_STA_PROFILE && |
2338 | 0 | sub_elem_len >= 2) { |
2339 | 0 | const struct ieee80211_eht_per_sta_profile *sta_prof = |
2340 | 0 | (const struct ieee80211_eht_per_sta_profile *) |
2341 | 0 | (pos + 2); |
2342 | 0 | u16 control = le_to_host16(sta_prof->sta_control); |
2343 | 0 | u8 link_id; |
2344 | |
|
2345 | 0 | link_id = control & EHT_PER_STA_RECONF_CTRL_LINK_ID_MSK; |
2346 | 0 | if (link_id < MAX_NUM_MLD_LINKS) |
2347 | 0 | removed_links |= BIT(link_id); |
2348 | 0 | } |
2349 | |
|
2350 | 0 | pos += 2 + sub_elem_len; |
2351 | 0 | len -= 2 + sub_elem_len; |
2352 | 0 | } |
2353 | | |
2354 | 0 | wpa_printf(MSG_DEBUG, "MLD: Reconfiguration: removed_links=0x%x", |
2355 | 0 | removed_links); |
2356 | 0 | out: |
2357 | 0 | wpabuf_free(mlbuf); |
2358 | 0 | return removed_links; |
2359 | 0 | } |
2360 | | |
2361 | | |
2362 | | #ifndef CONFIG_NO_WPA |
2363 | | |
2364 | | static bool wpa_bss_supported_cipher(struct wpa_supplicant *wpa_s, |
2365 | | int pairwise_cipher) |
2366 | 0 | { |
2367 | 0 | if (!wpa_s->drv_enc) |
2368 | 0 | return true; |
2369 | | |
2370 | 0 | if ((pairwise_cipher & WPA_CIPHER_CCMP) && |
2371 | 0 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_CCMP)) |
2372 | 0 | return true; |
2373 | | |
2374 | 0 | if ((pairwise_cipher & WPA_CIPHER_GCMP) && |
2375 | 0 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP)) |
2376 | 0 | return true; |
2377 | | |
2378 | 0 | if ((pairwise_cipher & WPA_CIPHER_CCMP_256) && |
2379 | 0 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_CCMP_256)) |
2380 | 0 | return true; |
2381 | | |
2382 | 0 | if ((pairwise_cipher & WPA_CIPHER_GCMP_256) && |
2383 | 0 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP_256)) |
2384 | 0 | return true; |
2385 | | |
2386 | 0 | return false; |
2387 | 0 | } |
2388 | | |
2389 | | |
2390 | | static bool wpa_bss_supported_key_mgmt(struct wpa_supplicant *wpa_s, |
2391 | | int key_mgmt) |
2392 | 0 | { |
2393 | 0 | if (!wpa_s->drv_key_mgmt) |
2394 | 0 | return true; |
2395 | | |
2396 | 0 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X) && |
2397 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) |
2398 | 0 | return true; |
2399 | 0 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) && |
2400 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256)) |
2401 | 0 | return true; |
2402 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) && |
2403 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT)) |
2404 | 0 | return true; |
2405 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) && |
2406 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384)) |
2407 | 0 | return true; |
2408 | 0 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) && |
2409 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B)) |
2410 | 0 | return true; |
2411 | 0 | if ((key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) && |
2412 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192)) |
2413 | 0 | return true; |
2414 | 0 | if ((key_mgmt & WPA_KEY_MGMT_PSK) && |
2415 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) |
2416 | 0 | return true; |
2417 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FT_PSK) && |
2418 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK)) |
2419 | 0 | return true; |
2420 | 0 | if ((key_mgmt & WPA_KEY_MGMT_PSK_SHA256) && |
2421 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256)) |
2422 | 0 | return true; |
2423 | 0 | if ((key_mgmt & WPA_KEY_MGMT_SAE) && |
2424 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE)) |
2425 | 0 | return true; |
2426 | 0 | if ((key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) && |
2427 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY)) |
2428 | 0 | return true; |
2429 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FT_SAE) && |
2430 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE)) |
2431 | 0 | return true; |
2432 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) && |
2433 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY)) |
2434 | 0 | return true; |
2435 | 0 | if ((key_mgmt & WPA_KEY_MGMT_OWE) && |
2436 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE)) |
2437 | 0 | return true; |
2438 | 0 | if ((key_mgmt & WPA_KEY_MGMT_DPP) && |
2439 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP)) |
2440 | 0 | return true; |
2441 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FILS_SHA256) && |
2442 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256)) |
2443 | 0 | return true; |
2444 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FILS_SHA384) && |
2445 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384)) |
2446 | 0 | return true; |
2447 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) && |
2448 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256)) |
2449 | 0 | return true; |
2450 | 0 | if ((key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) && |
2451 | 0 | (wpa_s->drv_key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384)) |
2452 | 0 | return true; |
2453 | | |
2454 | 0 | return false; |
2455 | 0 | } |
2456 | | |
2457 | | |
2458 | | static bool wpa_bss_supported_rsne(struct wpa_supplicant *wpa_s, |
2459 | | struct wpa_ssid *ssid, const u8 *ie) |
2460 | 0 | { |
2461 | 0 | struct wpa_ie_data data; |
2462 | |
|
2463 | 0 | if (wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) < 0) |
2464 | 0 | return false; |
2465 | | |
2466 | | /* Check that there is a supported AKM and pairwise cipher based on |
2467 | | * overall capabilities */ |
2468 | 0 | if (!data.pairwise_cipher || !data.key_mgmt) |
2469 | 0 | return false; |
2470 | | |
2471 | 0 | if (wpa_s->drv_capa_known) { |
2472 | 0 | if (!wpa_bss_supported_cipher(wpa_s, data.pairwise_cipher) || |
2473 | 0 | !wpa_bss_supported_key_mgmt(wpa_s, data.key_mgmt)) |
2474 | 0 | return false; |
2475 | 0 | } |
2476 | | |
2477 | 0 | if (ssid) { |
2478 | | /* Check that there is a supported AKM and pairwise cipher |
2479 | | * based on the specific network profile. */ |
2480 | 0 | if ((ssid->pairwise_cipher & data.pairwise_cipher) == 0) |
2481 | 0 | return false; |
2482 | 0 | if ((ssid->key_mgmt & data.key_mgmt) == 0) |
2483 | 0 | return false; |
2484 | 0 | } |
2485 | | |
2486 | 0 | return true; |
2487 | 0 | } |
2488 | | |
2489 | | #endif /* CONFIG_NO_WPA */ |
2490 | | |
2491 | | |
2492 | | const u8 * wpa_bss_get_rsne(struct wpa_supplicant *wpa_s, |
2493 | | const struct wpa_bss *bss, struct wpa_ssid *ssid, |
2494 | | bool mlo) |
2495 | 0 | { |
2496 | 0 | #ifndef CONFIG_NO_WPA |
2497 | 0 | const u8 *ie; |
2498 | |
|
2499 | 0 | if (wpas_rsn_overriding(wpa_s, ssid)) { |
2500 | 0 | if (!ssid) |
2501 | 0 | ssid = wpa_s->current_ssid; |
2502 | | |
2503 | | /* MLO cases for RSN overriding are required to use RSNE |
2504 | | * Override 2 element and RSNXE Override element together. */ |
2505 | 0 | ie = wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE); |
2506 | 0 | if (mlo && ie && |
2507 | 0 | !wpa_bss_get_vendor_ie(bss, |
2508 | 0 | RSNXE_OVERRIDE_IE_VENDOR_TYPE)) { |
2509 | 0 | wpa_printf(MSG_DEBUG, "BSS " MACSTR |
2510 | 0 | " advertises RSNE Override 2 element without RSNXE Override element - ignore RSNE Override 2 element for MLO", |
2511 | 0 | MAC2STR(bss->bssid)); |
2512 | 0 | } else if (ie && wpa_bss_supported_rsne(wpa_s, ssid, ie)) { |
2513 | 0 | return ie; |
2514 | 0 | } |
2515 | | |
2516 | 0 | if (!mlo) { |
2517 | 0 | ie = wpa_bss_get_vendor_ie( |
2518 | 0 | bss, RSNE_OVERRIDE_IE_VENDOR_TYPE); |
2519 | 0 | if (ie && wpa_bss_supported_rsne(wpa_s, ssid, ie)) |
2520 | 0 | return ie; |
2521 | 0 | } |
2522 | 0 | } |
2523 | 0 | #endif /* CONFIG_NO_WPA */ |
2524 | | |
2525 | 0 | return wpa_bss_get_ie(bss, WLAN_EID_RSN); |
2526 | 0 | } |
2527 | | |
2528 | | |
2529 | | const u8 * wpa_bss_get_rsnxe(struct wpa_supplicant *wpa_s, |
2530 | | const struct wpa_bss *bss, struct wpa_ssid *ssid, |
2531 | | bool mlo) |
2532 | 0 | { |
2533 | 0 | const u8 *ie; |
2534 | |
|
2535 | 0 | if (wpas_rsn_overriding(wpa_s, ssid)) { |
2536 | 0 | ie = wpa_bss_get_vendor_ie(bss, RSNXE_OVERRIDE_IE_VENDOR_TYPE); |
2537 | 0 | if (ie) { |
2538 | 0 | const u8 *tmp; |
2539 | |
|
2540 | 0 | tmp = wpa_bss_get_rsne(wpa_s, bss, ssid, mlo); |
2541 | 0 | if (!tmp || tmp[0] == WLAN_EID_RSN) { |
2542 | | /* An acceptable RSNE override element was not |
2543 | | * found, so need to ignore RSNXE overriding. */ |
2544 | 0 | goto out; |
2545 | 0 | } |
2546 | | |
2547 | 0 | return ie; |
2548 | 0 | } |
2549 | | |
2550 | | /* MLO cases for RSN overriding are required to use RSNE |
2551 | | * Override 2 element and RSNXE Override element together. */ |
2552 | 0 | if (mlo && wpa_bss_get_vendor_ie( |
2553 | 0 | bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE)) { |
2554 | 0 | wpa_printf(MSG_DEBUG, "BSS " MACSTR |
2555 | 0 | " advertises RSNXE Override element without RSNE Override 2 element - ignore RSNXE Override element for MLO", |
2556 | 0 | MAC2STR(bss->bssid)); |
2557 | 0 | goto out; |
2558 | 0 | } |
2559 | 0 | } |
2560 | | |
2561 | 0 | out: |
2562 | 0 | return wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
2563 | 0 | } |
2564 | | |
2565 | | |
2566 | | bool wpa_bss_security_profile_enabled(const struct wpa_bss *bss, int profile) |
2567 | 0 | { |
2568 | 0 | const u8 *sp; |
2569 | |
|
2570 | 0 | sp = wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_SECURITY_PROFILE); |
2571 | 0 | return security_profile_is_enabled(sp, profile); |
2572 | 0 | } |