blob: e13783ce1995fe3f847051ddb2b8f3c2700e2ddd [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * BSS table
Hai Shalom74f70d42019-02-11 14:42:39 -08003 * Copyright (c) 2009-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "common/ieee802_11_defs.h"
14#include "drivers/driver.h"
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -070015#include "eap_peer/eap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016#include "wpa_supplicant_i.h"
17#include "config.h"
18#include "notify.h"
19#include "scan.h"
20#include "bss.h"
21
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -070022static void wpa_bss_set_hessid(struct wpa_bss *bss)
23{
24#ifdef CONFIG_INTERWORKING
25 const u8 *ie = wpa_bss_get_ie(bss, WLAN_EID_INTERWORKING);
26 if (ie == NULL || (ie[1] != 7 && ie[1] != 9)) {
27 os_memset(bss->hessid, 0, ETH_ALEN);
28 return;
29 }
30 if (ie[1] == 7)
31 os_memcpy(bss->hessid, ie + 3, ETH_ALEN);
32 else
33 os_memcpy(bss->hessid, ie + 5, ETH_ALEN);
34#endif /* CONFIG_INTERWORKING */
35}
36
37
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080038/**
39 * wpa_bss_anqp_alloc - Allocate ANQP data structure for a BSS entry
40 * Returns: Allocated ANQP data structure or %NULL on failure
41 *
42 * The allocated ANQP data structure has its users count set to 1. It may be
43 * shared by multiple BSS entries and each shared entry is freed with
44 * wpa_bss_anqp_free().
45 */
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -070046struct wpa_bss_anqp * wpa_bss_anqp_alloc(void)
47{
48 struct wpa_bss_anqp *anqp;
49 anqp = os_zalloc(sizeof(*anqp));
50 if (anqp == NULL)
51 return NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080052#ifdef CONFIG_INTERWORKING
53 dl_list_init(&anqp->anqp_elems);
54#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -070055 anqp->users = 1;
56 return anqp;
57}
58
59
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080060/**
61 * wpa_bss_anqp_clone - Clone an ANQP data structure
62 * @anqp: ANQP data structure from wpa_bss_anqp_alloc()
63 * Returns: Cloned ANQP data structure or %NULL on failure
64 */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080065static struct wpa_bss_anqp * wpa_bss_anqp_clone(struct wpa_bss_anqp *anqp)
66{
67 struct wpa_bss_anqp *n;
68
69 n = os_zalloc(sizeof(*n));
70 if (n == NULL)
71 return NULL;
72
73#define ANQP_DUP(f) if (anqp->f) n->f = wpabuf_dup(anqp->f)
74#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080075 dl_list_init(&n->anqp_elems);
Dmitry Shmidt7f656022015-02-25 14:36:37 -080076 ANQP_DUP(capability_list);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080077 ANQP_DUP(venue_name);
78 ANQP_DUP(network_auth_type);
79 ANQP_DUP(roaming_consortium);
80 ANQP_DUP(ip_addr_type_availability);
81 ANQP_DUP(nai_realm);
82 ANQP_DUP(anqp_3gpp);
83 ANQP_DUP(domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -080084 ANQP_DUP(fils_realm_info);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080085#endif /* CONFIG_INTERWORKING */
86#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -080087 ANQP_DUP(hs20_capability_list);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080088 ANQP_DUP(hs20_operator_friendly_name);
89 ANQP_DUP(hs20_wan_metrics);
90 ANQP_DUP(hs20_connection_capability);
91 ANQP_DUP(hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080092 ANQP_DUP(hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -070093 ANQP_DUP(hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -080094 ANQP_DUP(hs20_osu_providers_nai_list);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080095#endif /* CONFIG_HS20 */
96#undef ANQP_DUP
97
98 return n;
99}
100
101
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800102/**
103 * wpa_bss_anqp_unshare_alloc - Unshare ANQP data (if shared) in a BSS entry
104 * @bss: BSS entry
105 * Returns: 0 on success, -1 on failure
106 *
107 * This function ensures the specific BSS entry has an ANQP data structure that
108 * is not shared with any other BSS entry.
109 */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800110int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss)
111{
112 struct wpa_bss_anqp *anqp;
113
114 if (bss->anqp && bss->anqp->users > 1) {
115 /* allocated, but shared - clone an unshared copy */
116 anqp = wpa_bss_anqp_clone(bss->anqp);
117 if (anqp == NULL)
118 return -1;
119 anqp->users = 1;
120 bss->anqp->users--;
121 bss->anqp = anqp;
122 return 0;
123 }
124
125 if (bss->anqp)
126 return 0; /* already allocated and not shared */
127
128 /* not allocated - allocate a new storage area */
129 bss->anqp = wpa_bss_anqp_alloc();
130 return bss->anqp ? 0 : -1;
131}
132
133
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800134/**
135 * wpa_bss_anqp_free - Free an ANQP data structure
136 * @anqp: ANQP data structure from wpa_bss_anqp_alloc() or wpa_bss_anqp_clone()
137 */
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700138static void wpa_bss_anqp_free(struct wpa_bss_anqp *anqp)
139{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800140#ifdef CONFIG_INTERWORKING
141 struct wpa_bss_anqp_elem *elem;
142#endif /* CONFIG_INTERWORKING */
143
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700144 if (anqp == NULL)
145 return;
146
147 anqp->users--;
148 if (anqp->users > 0) {
149 /* Another BSS entry holds a pointer to this ANQP info */
150 return;
151 }
152
153#ifdef CONFIG_INTERWORKING
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800154 wpabuf_free(anqp->capability_list);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700155 wpabuf_free(anqp->venue_name);
156 wpabuf_free(anqp->network_auth_type);
157 wpabuf_free(anqp->roaming_consortium);
158 wpabuf_free(anqp->ip_addr_type_availability);
159 wpabuf_free(anqp->nai_realm);
160 wpabuf_free(anqp->anqp_3gpp);
161 wpabuf_free(anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800162 wpabuf_free(anqp->fils_realm_info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800163
164 while ((elem = dl_list_first(&anqp->anqp_elems,
165 struct wpa_bss_anqp_elem, list))) {
166 dl_list_del(&elem->list);
167 wpabuf_free(elem->payload);
168 os_free(elem);
169 }
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700170#endif /* CONFIG_INTERWORKING */
171#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800172 wpabuf_free(anqp->hs20_capability_list);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700173 wpabuf_free(anqp->hs20_operator_friendly_name);
174 wpabuf_free(anqp->hs20_wan_metrics);
175 wpabuf_free(anqp->hs20_connection_capability);
176 wpabuf_free(anqp->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800177 wpabuf_free(anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700178 wpabuf_free(anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800179 wpabuf_free(anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700180#endif /* CONFIG_HS20 */
181
182 os_free(anqp);
183}
184
185
Dmitry Shmidt2e425d62014-11-10 11:18:27 -0800186static void wpa_bss_update_pending_connect(struct wpa_supplicant *wpa_s,
187 struct wpa_bss *old_bss,
188 struct wpa_bss *new_bss)
189{
190 struct wpa_radio_work *work;
191 struct wpa_connect_work *cwork;
192
193 work = radio_work_pending(wpa_s, "sme-connect");
194 if (!work)
195 work = radio_work_pending(wpa_s, "connect");
196 if (!work)
197 return;
198
199 cwork = work->ctx;
200 if (cwork->bss != old_bss)
201 return;
202
203 wpa_printf(MSG_DEBUG,
204 "Update BSS pointer for the pending connect radio work");
205 cwork->bss = new_bss;
206 if (!new_bss)
207 cwork->bss_removed = 1;
208}
209
210
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800211void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
212 const char *reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700214 if (wpa_s->last_scan_res) {
215 unsigned int i;
216 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
217 if (wpa_s->last_scan_res[i] == bss) {
218 os_memmove(&wpa_s->last_scan_res[i],
219 &wpa_s->last_scan_res[i + 1],
220 (wpa_s->last_scan_res_used - i - 1)
221 * sizeof(struct wpa_bss *));
222 wpa_s->last_scan_res_used--;
223 break;
224 }
225 }
226 }
Dmitry Shmidt2e425d62014-11-10 11:18:27 -0800227 wpa_bss_update_pending_connect(wpa_s, bss, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228 dl_list_del(&bss->list);
229 dl_list_del(&bss->list_id);
230 wpa_s->num_bss--;
231 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Remove id %u BSSID " MACSTR
Dmitry Shmidt04949592012-07-19 12:16:46 -0700232 " SSID '%s' due to %s", bss->id, MAC2STR(bss->bssid),
233 wpa_ssid_txt(bss->ssid, bss->ssid_len), reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234 wpas_notify_bss_removed(wpa_s, bss->bssid, bss->id);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700235 wpa_bss_anqp_free(bss->anqp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236 os_free(bss);
237}
238
239
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800240/**
241 * wpa_bss_get - Fetch a BSS table entry based on BSSID and SSID
242 * @wpa_s: Pointer to wpa_supplicant data
243 * @bssid: BSSID
244 * @ssid: SSID
245 * @ssid_len: Length of @ssid
246 * Returns: Pointer to the BSS entry or %NULL if not found
247 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
249 const u8 *ssid, size_t ssid_len)
250{
251 struct wpa_bss *bss;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700252 if (!wpa_supplicant_filter_bssid_match(wpa_s, bssid))
253 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
255 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
256 bss->ssid_len == ssid_len &&
257 os_memcmp(bss->ssid, ssid, ssid_len) == 0)
258 return bss;
259 }
260 return NULL;
261}
262
263
Dmitry Shmidt29333592017-01-09 12:27:11 -0800264void calculate_update_time(const struct os_reltime *fetch_time,
265 unsigned int age_ms,
266 struct os_reltime *update_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700267{
268 os_time_t usec;
269
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700270 update_time->sec = fetch_time->sec;
271 update_time->usec = fetch_time->usec;
272 update_time->sec -= age_ms / 1000;
273 usec = (age_ms % 1000) * 1000;
274 if (update_time->usec < usec) {
275 update_time->sec--;
276 update_time->usec += 1000000;
277 }
278 update_time->usec -= usec;
279}
280
281
282static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800283 struct os_reltime *fetch_time)
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700284{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285 dst->flags = src->flags;
286 os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
287 dst->freq = src->freq;
288 dst->beacon_int = src->beacon_int;
289 dst->caps = src->caps;
290 dst->qual = src->qual;
291 dst->noise = src->noise;
292 dst->level = src->level;
293 dst->tsf = src->tsf;
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800294 dst->est_throughput = src->est_throughput;
295 dst->snr = src->snr;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700297 calculate_update_time(fetch_time, src->age, &dst->last_update);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298}
299
300
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700301static int wpa_bss_is_wps_candidate(struct wpa_supplicant *wpa_s,
302 struct wpa_bss *bss)
303{
304#ifdef CONFIG_WPS
305 struct wpa_ssid *ssid;
306 struct wpabuf *wps_ie;
307 int pbc = 0, ret;
308
309 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
310 if (!wps_ie)
311 return 0;
312
313 if (wps_is_selected_pbc_registrar(wps_ie)) {
314 pbc = 1;
315 } else if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) {
316 wpabuf_free(wps_ie);
317 return 0;
318 }
319
320 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
321 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
322 continue;
323 if (ssid->ssid_len &&
324 (ssid->ssid_len != bss->ssid_len ||
325 os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) != 0))
326 continue;
327
328 if (pbc)
329 ret = eap_is_wps_pbc_enrollee(&ssid->eap);
330 else
331 ret = eap_is_wps_pin_enrollee(&ssid->eap);
332 wpabuf_free(wps_ie);
333 return ret;
334 }
335 wpabuf_free(wps_ie);
336#endif /* CONFIG_WPS */
337
338 return 0;
339}
340
341
Hai Shalom60840252021-02-19 19:02:11 -0800342static bool is_p2p_pending_bss(struct wpa_supplicant *wpa_s,
343 struct wpa_bss *bss)
344{
345#ifdef CONFIG_P2P
346 u8 addr[ETH_ALEN];
347
348 if (os_memcmp(bss->bssid, wpa_s->pending_join_iface_addr,
349 ETH_ALEN) == 0)
350 return true;
351 if (!is_zero_ether_addr(wpa_s->pending_join_dev_addr) &&
352 p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len, addr) == 0 &&
353 os_memcmp(addr, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0)
354 return true;
355#endif /* CONFIG_P2P */
356 return false;
357}
358
359
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800360static int wpa_bss_known(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
361{
362 struct wpa_ssid *ssid;
363
Hai Shalom60840252021-02-19 19:02:11 -0800364 if (is_p2p_pending_bss(wpa_s, bss))
365 return 1;
366
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800367 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
368 if (ssid->ssid == NULL || ssid->ssid_len == 0)
369 continue;
370 if (ssid->ssid_len == bss->ssid_len &&
371 os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) == 0)
372 return 1;
373 }
374
375 return 0;
376}
377
378
Dmitry Shmidt04949592012-07-19 12:16:46 -0700379static int wpa_bss_in_use(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
380{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800381 if (bss == wpa_s->current_bss)
382 return 1;
383
384 if (wpa_s->current_bss &&
385 (bss->ssid_len != wpa_s->current_bss->ssid_len ||
386 os_memcmp(bss->ssid, wpa_s->current_bss->ssid,
387 bss->ssid_len) != 0))
388 return 0; /* SSID has changed */
389
390 return !is_zero_ether_addr(bss->bssid) &&
391 (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) == 0 ||
392 os_memcmp(bss->bssid, wpa_s->pending_bssid, ETH_ALEN) == 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700393}
394
395
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800396static int wpa_bss_remove_oldest_unknown(struct wpa_supplicant *wpa_s)
397{
398 struct wpa_bss *bss;
399
400 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700401 if (!wpa_bss_known(wpa_s, bss) &&
402 !wpa_bss_is_wps_candidate(wpa_s, bss)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700403 wpa_bss_remove(wpa_s, bss, __func__);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800404 return 0;
405 }
406 }
407
408 return -1;
409}
410
411
Dmitry Shmidt04949592012-07-19 12:16:46 -0700412static int wpa_bss_remove_oldest(struct wpa_supplicant *wpa_s)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800413{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700414 struct wpa_bss *bss;
415
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416 /*
417 * Remove the oldest entry that does not match with any configured
418 * network.
419 */
420 if (wpa_bss_remove_oldest_unknown(wpa_s) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700421 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800422
423 /*
Dmitry Shmidt04949592012-07-19 12:16:46 -0700424 * Remove the oldest entry that isn't currently in use.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800425 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700426 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
427 if (!wpa_bss_in_use(wpa_s, bss)) {
428 wpa_bss_remove(wpa_s, bss, __func__);
429 return 0;
430 }
431 }
432
433 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800434}
435
436
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700437static struct wpa_bss * wpa_bss_add(struct wpa_supplicant *wpa_s,
438 const u8 *ssid, size_t ssid_len,
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800439 struct wpa_scan_res *res,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800440 struct os_reltime *fetch_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441{
442 struct wpa_bss *bss;
Hai Shalom81f62d82019-07-22 12:10:00 -0700443 char extra[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444
445 bss = os_zalloc(sizeof(*bss) + res->ie_len + res->beacon_ie_len);
446 if (bss == NULL)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700447 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448 bss->id = wpa_s->bss_next_id++;
449 bss->last_update_idx = wpa_s->bss_update_idx;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800450 wpa_bss_copy_res(bss, res, fetch_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 os_memcpy(bss->ssid, ssid, ssid_len);
452 bss->ssid_len = ssid_len;
453 bss->ie_len = res->ie_len;
454 bss->beacon_ie_len = res->beacon_ie_len;
Hai Shalom60840252021-02-19 19:02:11 -0800455 os_memcpy(bss->ies, res + 1, res->ie_len + res->beacon_ie_len);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700456 wpa_bss_set_hessid(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457
Jouni Malinen7a6c8302013-09-27 15:47:09 +0300458 if (wpa_s->num_bss + 1 > wpa_s->conf->bss_max_count &&
459 wpa_bss_remove_oldest(wpa_s) != 0) {
460 wpa_printf(MSG_ERROR, "Increasing the MAX BSS count to %d "
461 "because all BSSes are in use. We should normally "
462 "not get here!", (int) wpa_s->num_bss + 1);
463 wpa_s->conf->bss_max_count = wpa_s->num_bss + 1;
464 }
465
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 dl_list_add_tail(&wpa_s->bss, &bss->list);
467 dl_list_add_tail(&wpa_s->bss_id, &bss->list_id);
468 wpa_s->num_bss++;
Hai Shalom81f62d82019-07-22 12:10:00 -0700469 if (!is_zero_ether_addr(bss->hessid))
470 os_snprintf(extra, sizeof(extra), " HESSID " MACSTR,
471 MAC2STR(bss->hessid));
472 else
473 extra[0] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Add new id %u BSSID " MACSTR
Hai Shalom81f62d82019-07-22 12:10:00 -0700475 " SSID '%s' freq %d%s",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800476 bss->id, MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len),
Hai Shalom81f62d82019-07-22 12:10:00 -0700477 bss->freq, extra);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478 wpas_notify_bss_added(wpa_s, bss->bssid, bss->id);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700479 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480}
481
482
483static int are_ies_equal(const struct wpa_bss *old,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700484 const struct wpa_scan_res *new_res, u32 ie)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485{
486 const u8 *old_ie, *new_ie;
487 struct wpabuf *old_ie_buff = NULL;
488 struct wpabuf *new_ie_buff = NULL;
489 int new_ie_len, old_ie_len, ret, is_multi;
490
491 switch (ie) {
492 case WPA_IE_VENDOR_TYPE:
493 old_ie = wpa_bss_get_vendor_ie(old, ie);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700494 new_ie = wpa_scan_get_vendor_ie(new_res, ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495 is_multi = 0;
496 break;
497 case WPS_IE_VENDOR_TYPE:
498 old_ie_buff = wpa_bss_get_vendor_ie_multi(old, ie);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700499 new_ie_buff = wpa_scan_get_vendor_ie_multi(new_res, ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700500 is_multi = 1;
501 break;
502 case WLAN_EID_RSN:
503 case WLAN_EID_SUPP_RATES:
504 case WLAN_EID_EXT_SUPP_RATES:
505 old_ie = wpa_bss_get_ie(old, ie);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700506 new_ie = wpa_scan_get_ie(new_res, ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 is_multi = 0;
508 break;
509 default:
510 wpa_printf(MSG_DEBUG, "bss: %s: cannot compare IEs", __func__);
511 return 0;
512 }
513
514 if (is_multi) {
515 /* in case of multiple IEs stored in buffer */
516 old_ie = old_ie_buff ? wpabuf_head_u8(old_ie_buff) : NULL;
517 new_ie = new_ie_buff ? wpabuf_head_u8(new_ie_buff) : NULL;
518 old_ie_len = old_ie_buff ? wpabuf_len(old_ie_buff) : 0;
519 new_ie_len = new_ie_buff ? wpabuf_len(new_ie_buff) : 0;
520 } else {
521 /* in case of single IE */
522 old_ie_len = old_ie ? old_ie[1] + 2 : 0;
523 new_ie_len = new_ie ? new_ie[1] + 2 : 0;
524 }
525
526 if (!old_ie || !new_ie)
527 ret = !old_ie && !new_ie;
528 else
529 ret = (old_ie_len == new_ie_len &&
530 os_memcmp(old_ie, new_ie, old_ie_len) == 0);
531
532 wpabuf_free(old_ie_buff);
533 wpabuf_free(new_ie_buff);
534
535 return ret;
536}
537
538
539static u32 wpa_bss_compare_res(const struct wpa_bss *old,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700540 const struct wpa_scan_res *new_res)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541{
542 u32 changes = 0;
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700543 int caps_diff = old->caps ^ new_res->caps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700545 if (old->freq != new_res->freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546 changes |= WPA_BSS_FREQ_CHANGED_FLAG;
547
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700548 if (old->level != new_res->level)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549 changes |= WPA_BSS_SIGNAL_CHANGED_FLAG;
550
551 if (caps_diff & IEEE80211_CAP_PRIVACY)
552 changes |= WPA_BSS_PRIVACY_CHANGED_FLAG;
553
554 if (caps_diff & IEEE80211_CAP_IBSS)
555 changes |= WPA_BSS_MODE_CHANGED_FLAG;
556
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700557 if (old->ie_len == new_res->ie_len &&
Hai Shalom60840252021-02-19 19:02:11 -0800558 os_memcmp(wpa_bss_ie_ptr(old), new_res + 1, old->ie_len) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700559 return changes;
560 changes |= WPA_BSS_IES_CHANGED_FLAG;
561
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700562 if (!are_ies_equal(old, new_res, WPA_IE_VENDOR_TYPE))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 changes |= WPA_BSS_WPAIE_CHANGED_FLAG;
564
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700565 if (!are_ies_equal(old, new_res, WLAN_EID_RSN))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700566 changes |= WPA_BSS_RSNIE_CHANGED_FLAG;
567
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700568 if (!are_ies_equal(old, new_res, WPS_IE_VENDOR_TYPE))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700569 changes |= WPA_BSS_WPS_CHANGED_FLAG;
570
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700571 if (!are_ies_equal(old, new_res, WLAN_EID_SUPP_RATES) ||
572 !are_ies_equal(old, new_res, WLAN_EID_EXT_SUPP_RATES))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700573 changes |= WPA_BSS_RATES_CHANGED_FLAG;
574
575 return changes;
576}
577
578
Hai Shalom60840252021-02-19 19:02:11 -0800579void notify_bss_changes(struct wpa_supplicant *wpa_s, u32 changes,
580 const struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581{
582 if (changes & WPA_BSS_FREQ_CHANGED_FLAG)
583 wpas_notify_bss_freq_changed(wpa_s, bss->id);
584
585 if (changes & WPA_BSS_SIGNAL_CHANGED_FLAG)
586 wpas_notify_bss_signal_changed(wpa_s, bss->id);
587
588 if (changes & WPA_BSS_PRIVACY_CHANGED_FLAG)
589 wpas_notify_bss_privacy_changed(wpa_s, bss->id);
590
591 if (changes & WPA_BSS_MODE_CHANGED_FLAG)
592 wpas_notify_bss_mode_changed(wpa_s, bss->id);
593
594 if (changes & WPA_BSS_WPAIE_CHANGED_FLAG)
595 wpas_notify_bss_wpaie_changed(wpa_s, bss->id);
596
597 if (changes & WPA_BSS_RSNIE_CHANGED_FLAG)
598 wpas_notify_bss_rsnie_changed(wpa_s, bss->id);
599
600 if (changes & WPA_BSS_WPS_CHANGED_FLAG)
601 wpas_notify_bss_wps_changed(wpa_s, bss->id);
602
603 if (changes & WPA_BSS_IES_CHANGED_FLAG)
604 wpas_notify_bss_ies_changed(wpa_s, bss->id);
605
606 if (changes & WPA_BSS_RATES_CHANGED_FLAG)
607 wpas_notify_bss_rates_changed(wpa_s, bss->id);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700608
609 wpas_notify_bss_seen(wpa_s, bss->id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610}
611
612
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700613static struct wpa_bss *
614wpa_bss_update(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800615 struct wpa_scan_res *res, struct os_reltime *fetch_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616{
617 u32 changes;
618
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800619 if (bss->last_update_idx == wpa_s->bss_update_idx) {
620 struct os_reltime update_time;
621
622 /*
623 * Some drivers (e.g., cfg80211) include multiple BSS entries
624 * for the same BSS if that BSS's channel changes. The BSS list
625 * implementation in wpa_supplicant does not do that and we need
626 * to filter out the obsolete results here to make sure only the
627 * most current BSS information remains in the table.
628 */
629 wpa_printf(MSG_DEBUG, "BSS: " MACSTR
630 " has multiple entries in the scan results - select the most current one",
631 MAC2STR(bss->bssid));
632 calculate_update_time(fetch_time, res->age, &update_time);
633 wpa_printf(MSG_DEBUG,
634 "Previous last_update: %u.%06u (freq %d%s)",
635 (unsigned int) bss->last_update.sec,
636 (unsigned int) bss->last_update.usec,
637 bss->freq,
638 (bss->flags & WPA_BSS_ASSOCIATED) ? " assoc" : "");
639 wpa_printf(MSG_DEBUG, "New last_update: %u.%06u (freq %d%s)",
640 (unsigned int) update_time.sec,
641 (unsigned int) update_time.usec,
642 res->freq,
643 (res->flags & WPA_SCAN_ASSOCIATED) ? " assoc" : "");
644 if ((bss->flags & WPA_BSS_ASSOCIATED) ||
645 (!(res->flags & WPA_SCAN_ASSOCIATED) &&
646 !os_reltime_before(&bss->last_update, &update_time))) {
647 wpa_printf(MSG_DEBUG,
648 "Ignore this BSS entry since the previous update looks more current");
649 return bss;
650 }
651 wpa_printf(MSG_DEBUG,
652 "Accept this BSS entry since it looks more current than the previous update");
653 }
654
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700655 changes = wpa_bss_compare_res(bss, res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800656 if (changes & WPA_BSS_FREQ_CHANGED_FLAG)
657 wpa_printf(MSG_DEBUG, "BSS: " MACSTR " changed freq %d --> %d",
658 MAC2STR(bss->bssid), bss->freq, res->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659 bss->scan_miss_count = 0;
660 bss->last_update_idx = wpa_s->bss_update_idx;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800661 wpa_bss_copy_res(bss, res, fetch_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 /* Move the entry to the end of the list */
663 dl_list_del(&bss->list);
Dmitry Shmidt96571392013-10-14 12:54:46 -0700664#ifdef CONFIG_P2P
665 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
666 !wpa_scan_get_vendor_ie(res, P2P_IE_VENDOR_TYPE)) {
667 /*
668 * This can happen when non-P2P station interface runs a scan
669 * without P2P IE in the Probe Request frame. P2P GO would reply
670 * to that with a Probe Response that does not include P2P IE.
671 * Do not update the IEs in this BSS entry to avoid such loss of
672 * information that may be needed for P2P operations to
673 * determine group information.
674 */
675 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Do not update scan IEs for "
676 MACSTR " since that would remove P2P IE information",
677 MAC2STR(bss->bssid));
678 } else
679#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 if (bss->ie_len + bss->beacon_ie_len >=
681 res->ie_len + res->beacon_ie_len) {
Hai Shalom60840252021-02-19 19:02:11 -0800682 os_memcpy(bss->ies, res + 1, res->ie_len + res->beacon_ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 bss->ie_len = res->ie_len;
684 bss->beacon_ie_len = res->beacon_ie_len;
685 } else {
686 struct wpa_bss *nbss;
687 struct dl_list *prev = bss->list_id.prev;
688 dl_list_del(&bss->list_id);
689 nbss = os_realloc(bss, sizeof(*bss) + res->ie_len +
690 res->beacon_ie_len);
691 if (nbss) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700692 unsigned int i;
693 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
694 if (wpa_s->last_scan_res[i] == bss) {
695 wpa_s->last_scan_res[i] = nbss;
696 break;
697 }
698 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700699 if (wpa_s->current_bss == bss)
700 wpa_s->current_bss = nbss;
Dmitry Shmidt2e425d62014-11-10 11:18:27 -0800701 wpa_bss_update_pending_connect(wpa_s, bss, nbss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702 bss = nbss;
Hai Shalom60840252021-02-19 19:02:11 -0800703 os_memcpy(bss->ies, res + 1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704 res->ie_len + res->beacon_ie_len);
705 bss->ie_len = res->ie_len;
706 bss->beacon_ie_len = res->beacon_ie_len;
707 }
708 dl_list_add(prev, &bss->list_id);
709 }
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700710 if (changes & WPA_BSS_IES_CHANGED_FLAG)
711 wpa_bss_set_hessid(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 dl_list_add_tail(&wpa_s->bss, &bss->list);
713
714 notify_bss_changes(wpa_s, changes, bss);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700715
716 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717}
718
719
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800720/**
721 * wpa_bss_update_start - Start a BSS table update from scan results
722 * @wpa_s: Pointer to wpa_supplicant data
723 *
724 * This function is called at the start of each BSS table update round for new
725 * scan results. The actual scan result entries are indicated with calls to
726 * wpa_bss_update_scan_res() and the update round is finished with a call to
727 * wpa_bss_update_end().
728 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729void wpa_bss_update_start(struct wpa_supplicant *wpa_s)
730{
731 wpa_s->bss_update_idx++;
732 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Start scan result update %u",
733 wpa_s->bss_update_idx);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700734 wpa_s->last_scan_res_used = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700735}
736
737
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800738/**
739 * wpa_bss_update_scan_res - Update a BSS table entry based on a scan result
740 * @wpa_s: Pointer to wpa_supplicant data
741 * @res: Scan result
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800742 * @fetch_time: Time when the result was fetched from the driver
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800743 *
744 * This function updates a BSS table entry (or adds one) based on a scan result.
745 * This is called separately for each scan result between the calls to
746 * wpa_bss_update_start() and wpa_bss_update_end().
747 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800749 struct wpa_scan_res *res,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800750 struct os_reltime *fetch_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800752 const u8 *ssid, *p2p, *mesh;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 struct wpa_bss *bss;
754
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700755 if (wpa_s->conf->ignore_old_scan_res) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800756 struct os_reltime update;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700757 calculate_update_time(fetch_time, res->age, &update);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800758 if (os_reltime_before(&update, &wpa_s->scan_trigger_time)) {
759 struct os_reltime age;
760 os_reltime_sub(&wpa_s->scan_trigger_time, &update,
761 &age);
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700762 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Ignore driver BSS "
763 "table entry that is %u.%06u seconds older "
764 "than our scan trigger",
765 (unsigned int) age.sec,
766 (unsigned int) age.usec);
767 return;
768 }
769 }
770
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 ssid = wpa_scan_get_ie(res, WLAN_EID_SSID);
772 if (ssid == NULL) {
773 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: No SSID IE included for "
774 MACSTR, MAC2STR(res->bssid));
775 return;
776 }
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700777 if (ssid[1] > SSID_MAX_LEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Too long SSID IE included for "
779 MACSTR, MAC2STR(res->bssid));
780 return;
781 }
782
783 p2p = wpa_scan_get_vendor_ie(res, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700784#ifdef CONFIG_P2P
785 if (p2p == NULL &&
786 wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
787 /*
788 * If it's a P2P specific interface, then don't update
789 * the scan result without a P2P IE.
790 */
791 wpa_printf(MSG_DEBUG, "BSS: No P2P IE - skipping BSS " MACSTR
792 " update for P2P interface", MAC2STR(res->bssid));
793 return;
794 }
795#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 if (p2p && ssid[1] == P2P_WILDCARD_SSID_LEN &&
797 os_memcmp(ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) == 0)
798 return; /* Skip P2P listen discovery results here */
799
800 /* TODO: add option for ignoring BSSes we are not interested in
801 * (to save memory) */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800802
803 mesh = wpa_scan_get_ie(res, WLAN_EID_MESH_ID);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700804 if (mesh && mesh[1] <= SSID_MAX_LEN)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800805 ssid = mesh;
806
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 bss = wpa_bss_get(wpa_s, res->bssid, ssid + 2, ssid[1]);
808 if (bss == NULL)
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800809 bss = wpa_bss_add(wpa_s, ssid + 2, ssid[1], res, fetch_time);
Dmitry Shmidt56052862013-10-04 10:23:25 -0700810 else {
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800811 bss = wpa_bss_update(wpa_s, bss, res, fetch_time);
Dmitry Shmidt56052862013-10-04 10:23:25 -0700812 if (wpa_s->last_scan_res) {
813 unsigned int i;
814 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
815 if (bss == wpa_s->last_scan_res[i]) {
816 /* Already in the list */
817 return;
818 }
819 }
820 }
821 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700822
823 if (bss == NULL)
824 return;
825 if (wpa_s->last_scan_res_used >= wpa_s->last_scan_res_size) {
826 struct wpa_bss **n;
827 unsigned int siz;
828 if (wpa_s->last_scan_res_size == 0)
829 siz = 32;
830 else
831 siz = wpa_s->last_scan_res_size * 2;
832 n = os_realloc_array(wpa_s->last_scan_res, siz,
833 sizeof(struct wpa_bss *));
834 if (n == NULL)
835 return;
836 wpa_s->last_scan_res = n;
837 wpa_s->last_scan_res_size = siz;
838 }
839
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700840 if (wpa_s->last_scan_res)
841 wpa_s->last_scan_res[wpa_s->last_scan_res_used++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842}
843
844
845static int wpa_bss_included_in_scan(const struct wpa_bss *bss,
846 const struct scan_info *info)
847{
848 int found;
849 size_t i;
850
851 if (info == NULL)
852 return 1;
853
854 if (info->num_freqs) {
855 found = 0;
856 for (i = 0; i < info->num_freqs; i++) {
857 if (bss->freq == info->freqs[i]) {
858 found = 1;
859 break;
860 }
861 }
862 if (!found)
863 return 0;
864 }
865
866 if (info->num_ssids) {
867 found = 0;
868 for (i = 0; i < info->num_ssids; i++) {
869 const struct wpa_driver_scan_ssid *s = &info->ssids[i];
870 if ((s->ssid == NULL || s->ssid_len == 0) ||
871 (s->ssid_len == bss->ssid_len &&
872 os_memcmp(s->ssid, bss->ssid, bss->ssid_len) ==
873 0)) {
874 found = 1;
875 break;
876 }
877 }
878 if (!found)
879 return 0;
880 }
881
882 return 1;
883}
884
885
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800886/**
887 * wpa_bss_update_end - End a BSS table update from scan results
888 * @wpa_s: Pointer to wpa_supplicant data
889 * @info: Information about scan parameters
890 * @new_scan: Whether this update round was based on a new scan
891 *
892 * This function is called at the end of each BSS table update round for new
893 * scan results. The start of the update was indicated with a call to
894 * wpa_bss_update_start().
895 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info,
897 int new_scan)
898{
899 struct wpa_bss *bss, *n;
900
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800901 os_get_reltime(&wpa_s->last_scan);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800902 if ((info && info->aborted) || !new_scan)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903 return; /* do not expire entries without new scan */
904
905 dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
906 if (wpa_bss_in_use(wpa_s, bss))
907 continue;
908 if (!wpa_bss_included_in_scan(bss, info))
909 continue; /* expire only BSSes that were scanned */
910 if (bss->last_update_idx < wpa_s->bss_update_idx)
911 bss->scan_miss_count++;
912 if (bss->scan_miss_count >=
913 wpa_s->conf->bss_expiration_scan_count) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700914 wpa_bss_remove(wpa_s, bss, "no match in scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700915 }
916 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700917
Hai Shalomfdcde762020-04-02 11:19:20 -0700918 wpa_printf(MSG_DEBUG, "BSS: last_scan_res_used=%zu/%zu",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800919 wpa_s->last_scan_res_used, wpa_s->last_scan_res_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700920}
921
922
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800923/**
924 * wpa_bss_flush_by_age - Flush old BSS entries
925 * @wpa_s: Pointer to wpa_supplicant data
926 * @age: Maximum entry age in seconds
927 *
928 * Remove BSS entries that have not been updated during the last @age seconds.
929 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age)
931{
932 struct wpa_bss *bss, *n;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800933 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934
935 if (dl_list_empty(&wpa_s->bss))
936 return;
937
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800938 os_get_reltime(&t);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939 t.sec -= age;
940
941 dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
942 if (wpa_bss_in_use(wpa_s, bss))
943 continue;
944
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800945 if (os_reltime_before(&bss->last_update, &t)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700946 wpa_bss_remove(wpa_s, bss, __func__);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 } else
948 break;
949 }
950}
951
952
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800953/**
954 * wpa_bss_init - Initialize BSS table
955 * @wpa_s: Pointer to wpa_supplicant data
956 * Returns: 0 on success, -1 on failure
957 *
958 * This prepares BSS table lists and timer for periodic updates. The BSS table
959 * is deinitialized with wpa_bss_deinit() once not needed anymore.
960 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961int wpa_bss_init(struct wpa_supplicant *wpa_s)
962{
963 dl_list_init(&wpa_s->bss);
964 dl_list_init(&wpa_s->bss_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 return 0;
966}
967
968
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800969/**
970 * wpa_bss_flush - Flush all unused BSS entries
971 * @wpa_s: Pointer to wpa_supplicant data
972 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973void wpa_bss_flush(struct wpa_supplicant *wpa_s)
974{
975 struct wpa_bss *bss, *n;
976
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800977 wpa_s->clear_driver_scan_cache = 1;
978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700979 if (wpa_s->bss.next == NULL)
980 return; /* BSS table not yet initialized */
981
982 dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
983 if (wpa_bss_in_use(wpa_s, bss))
984 continue;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700985 wpa_bss_remove(wpa_s, bss, __func__);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 }
987}
988
989
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800990/**
991 * wpa_bss_deinit - Deinitialize BSS table
992 * @wpa_s: Pointer to wpa_supplicant data
993 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994void wpa_bss_deinit(struct wpa_supplicant *wpa_s)
995{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996 wpa_bss_flush(wpa_s);
997}
998
999
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001000/**
1001 * wpa_bss_get_bssid - Fetch a BSS table entry based on BSSID
1002 * @wpa_s: Pointer to wpa_supplicant data
1003 * @bssid: BSSID
1004 * Returns: Pointer to the BSS entry or %NULL if not found
1005 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
1007 const u8 *bssid)
1008{
1009 struct wpa_bss *bss;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001010 if (!wpa_supplicant_filter_bssid_match(wpa_s, bssid))
1011 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
1013 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
1014 return bss;
1015 }
1016 return NULL;
1017}
1018
1019
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001020/**
1021 * wpa_bss_get_bssid_latest - Fetch the latest BSS table entry based on BSSID
1022 * @wpa_s: Pointer to wpa_supplicant data
1023 * @bssid: BSSID
1024 * Returns: Pointer to the BSS entry or %NULL if not found
1025 *
1026 * This function is like wpa_bss_get_bssid(), but full BSS table is iterated to
1027 * find the entry that has the most recent update. This can help in finding the
1028 * correct entry in cases where the SSID of the AP may have changed recently
1029 * (e.g., in WPS reconfiguration cases).
1030 */
1031struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s,
1032 const u8 *bssid)
1033{
1034 struct wpa_bss *bss, *found = NULL;
1035 if (!wpa_supplicant_filter_bssid_match(wpa_s, bssid))
1036 return NULL;
1037 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
1038 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) != 0)
1039 continue;
1040 if (found == NULL ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001041 os_reltime_before(&found->last_update, &bss->last_update))
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001042 found = bss;
1043 }
1044 return found;
1045}
1046
1047
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001048#ifdef CONFIG_P2P
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001049/**
Hai Shalomc3565922019-10-28 11:58:20 -07001050 * wpa_bss_get_p2p_dev_addr - Fetch the latest BSS table entry based on P2P Device Addr
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001051 * @wpa_s: Pointer to wpa_supplicant data
1052 * @dev_addr: P2P Device Address of the GO
1053 * Returns: Pointer to the BSS entry or %NULL if not found
Hai Shalomc3565922019-10-28 11:58:20 -07001054 *
1055 * This function tries to find the entry that has the most recent update. This
1056 * can help in finding the correct entry in cases where the SSID of the P2P
1057 * Device may have changed recently.
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001058 */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001059struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s,
1060 const u8 *dev_addr)
1061{
Hai Shalomc3565922019-10-28 11:58:20 -07001062 struct wpa_bss *bss, *found = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001063 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
1064 u8 addr[ETH_ALEN];
Hai Shalom60840252021-02-19 19:02:11 -08001065 if (p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len,
Hai Shalomc3565922019-10-28 11:58:20 -07001066 addr) != 0 ||
1067 os_memcmp(addr, dev_addr, ETH_ALEN) != 0)
1068 continue;
1069 if (!found ||
1070 os_reltime_before(&found->last_update, &bss->last_update))
1071 found = bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001072 }
Hai Shalomc3565922019-10-28 11:58:20 -07001073 return found;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001074}
1075#endif /* CONFIG_P2P */
1076
1077
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001078/**
1079 * wpa_bss_get_id - Fetch a BSS table entry based on identifier
1080 * @wpa_s: Pointer to wpa_supplicant data
1081 * @id: Unique identifier (struct wpa_bss::id) assigned for the entry
1082 * Returns: Pointer to the BSS entry or %NULL if not found
1083 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
1085{
1086 struct wpa_bss *bss;
1087 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1088 if (bss->id == id)
1089 return bss;
1090 }
1091 return NULL;
1092}
1093
1094
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001095/**
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001096 * wpa_bss_get_id_range - Fetch a BSS table entry based on identifier range
1097 * @wpa_s: Pointer to wpa_supplicant data
1098 * @idf: Smallest allowed identifier assigned for the entry
1099 * @idf: Largest allowed identifier assigned for the entry
1100 * Returns: Pointer to the BSS entry or %NULL if not found
1101 *
1102 * This function is similar to wpa_bss_get_id() but allows a BSS entry with the
1103 * smallest id value to be fetched within the specified range without the
1104 * caller having to know the exact id.
1105 */
1106struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s,
1107 unsigned int idf, unsigned int idl)
1108{
1109 struct wpa_bss *bss;
1110 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
1111 if (bss->id >= idf && bss->id <= idl)
1112 return bss;
1113 }
1114 return NULL;
1115}
1116
1117
1118/**
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001119 * wpa_bss_get_ie - Fetch a specified information element from a BSS entry
1120 * @bss: BSS table entry
1121 * @ie: Information element identitifier (WLAN_EID_*)
1122 * Returns: Pointer to the information element (id field) or %NULL if not found
1123 *
1124 * This function returns the first matching information element in the BSS
1125 * entry.
1126 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie)
1128{
Hai Shalom60840252021-02-19 19:02:11 -08001129 return get_ie(wpa_bss_ie_ptr(bss), bss->ie_len, ie);
1130}
1131
1132
1133/**
1134 * wpa_bss_get_ie_ext - Fetch a specified extended IE from a BSS entry
1135 * @bss: BSS table entry
1136 * @ext: Information element extension identifier (WLAN_EID_EXT_*)
1137 * Returns: Pointer to the information element (id field) or %NULL if not found
1138 *
1139 * This function returns the first matching information element in the BSS
1140 * entry.
1141 */
1142const u8 * wpa_bss_get_ie_ext(const struct wpa_bss *bss, u8 ext)
1143{
1144 return get_ie_ext(wpa_bss_ie_ptr(bss), bss->ie_len, ext);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145}
1146
1147
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001148/**
1149 * wpa_bss_get_vendor_ie - Fetch a vendor information element from a BSS entry
1150 * @bss: BSS table entry
1151 * @vendor_type: Vendor type (four octets starting the IE payload)
1152 * Returns: Pointer to the information element (id field) or %NULL if not found
1153 *
1154 * This function returns the first matching information element in the BSS
1155 * entry.
1156 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type)
1158{
Hai Shalom60840252021-02-19 19:02:11 -08001159 const u8 *ies;
1160 const struct element *elem;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161
Hai Shalom60840252021-02-19 19:02:11 -08001162 ies = wpa_bss_ie_ptr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163
Hai Shalom60840252021-02-19 19:02:11 -08001164 for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, bss->ie_len) {
1165 if (elem->datalen >= 4 &&
1166 vendor_type == WPA_GET_BE32(elem->data))
1167 return &elem->id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001168 }
1169
1170 return NULL;
1171}
1172
1173
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001174/**
Dmitry Shmidt96571392013-10-14 12:54:46 -07001175 * wpa_bss_get_vendor_ie_beacon - Fetch a vendor information from a BSS entry
1176 * @bss: BSS table entry
1177 * @vendor_type: Vendor type (four octets starting the IE payload)
1178 * Returns: Pointer to the information element (id field) or %NULL if not found
1179 *
1180 * This function returns the first matching information element in the BSS
1181 * entry.
1182 *
1183 * This function is like wpa_bss_get_vendor_ie(), but uses IE buffer only
1184 * from Beacon frames instead of either Beacon or Probe Response frames.
1185 */
1186const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss,
1187 u32 vendor_type)
1188{
Hai Shalom60840252021-02-19 19:02:11 -08001189 const u8 *ies;
1190 const struct element *elem;
Dmitry Shmidt96571392013-10-14 12:54:46 -07001191
1192 if (bss->beacon_ie_len == 0)
1193 return NULL;
1194
Hai Shalom60840252021-02-19 19:02:11 -08001195 ies = wpa_bss_ie_ptr(bss);
1196 ies += bss->ie_len;
Dmitry Shmidt96571392013-10-14 12:54:46 -07001197
Hai Shalom60840252021-02-19 19:02:11 -08001198 for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies,
1199 bss->beacon_ie_len) {
1200 if (elem->datalen >= 4 &&
1201 vendor_type == WPA_GET_BE32(elem->data))
1202 return &elem->id;
Dmitry Shmidt96571392013-10-14 12:54:46 -07001203 }
1204
1205 return NULL;
1206}
1207
1208
1209/**
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001210 * wpa_bss_get_vendor_ie_multi - Fetch vendor IE data from a BSS entry
1211 * @bss: BSS table entry
1212 * @vendor_type: Vendor type (four octets starting the IE payload)
1213 * Returns: Pointer to the information element payload or %NULL if not found
1214 *
1215 * This function returns concatenated payload of possibly fragmented vendor
1216 * specific information elements in the BSS entry. The caller is responsible for
1217 * freeing the returned buffer.
1218 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
1220 u32 vendor_type)
1221{
1222 struct wpabuf *buf;
1223 const u8 *end, *pos;
1224
1225 buf = wpabuf_alloc(bss->ie_len);
1226 if (buf == NULL)
1227 return NULL;
1228
Hai Shalom60840252021-02-19 19:02:11 -08001229 pos = wpa_bss_ie_ptr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 end = pos + bss->ie_len;
1231
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001232 while (end - pos > 1) {
Hai Shalom60840252021-02-19 19:02:11 -08001233 u8 ie, len;
1234
1235 ie = pos[0];
1236 len = pos[1];
1237 if (len > end - pos - 2)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 break;
Hai Shalom60840252021-02-19 19:02:11 -08001239 pos += 2;
1240 if (ie == WLAN_EID_VENDOR_SPECIFIC && len >= 4 &&
1241 vendor_type == WPA_GET_BE32(pos))
1242 wpabuf_put_data(buf, pos + 4, len - 4);
1243 pos += len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 }
1245
1246 if (wpabuf_len(buf) == 0) {
1247 wpabuf_free(buf);
1248 buf = NULL;
1249 }
1250
1251 return buf;
1252}
1253
1254
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001255/**
1256 * wpa_bss_get_vendor_ie_multi_beacon - Fetch vendor IE data from a BSS entry
1257 * @bss: BSS table entry
1258 * @vendor_type: Vendor type (four octets starting the IE payload)
1259 * Returns: Pointer to the information element payload or %NULL if not found
1260 *
1261 * This function returns concatenated payload of possibly fragmented vendor
1262 * specific information elements in the BSS entry. The caller is responsible for
1263 * freeing the returned buffer.
1264 *
1265 * This function is like wpa_bss_get_vendor_ie_multi(), but uses IE buffer only
1266 * from Beacon frames instead of either Beacon or Probe Response frames.
1267 */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001268struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss,
1269 u32 vendor_type)
1270{
1271 struct wpabuf *buf;
1272 const u8 *end, *pos;
1273
1274 buf = wpabuf_alloc(bss->beacon_ie_len);
1275 if (buf == NULL)
1276 return NULL;
1277
Hai Shalom60840252021-02-19 19:02:11 -08001278 pos = wpa_bss_ie_ptr(bss);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001279 pos += bss->ie_len;
1280 end = pos + bss->beacon_ie_len;
1281
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001282 while (end - pos > 1) {
1283 if (2 + pos[1] > end - pos)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001284 break;
1285 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1286 vendor_type == WPA_GET_BE32(&pos[2]))
1287 wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
1288 pos += 2 + pos[1];
1289 }
1290
1291 if (wpabuf_len(buf) == 0) {
1292 wpabuf_free(buf);
1293 buf = NULL;
1294 }
1295
1296 return buf;
1297}
1298
1299
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001300/**
1301 * wpa_bss_get_max_rate - Get maximum legacy TX rate supported in a BSS
1302 * @bss: BSS table entry
1303 * Returns: Maximum legacy rate in units of 500 kbps
1304 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001305int wpa_bss_get_max_rate(const struct wpa_bss *bss)
1306{
1307 int rate = 0;
1308 const u8 *ie;
1309 int i;
1310
1311 ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1312 for (i = 0; ie && i < ie[1]; i++) {
1313 if ((ie[i + 2] & 0x7f) > rate)
1314 rate = ie[i + 2] & 0x7f;
1315 }
1316
1317 ie = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
1318 for (i = 0; ie && i < ie[1]; i++) {
1319 if ((ie[i + 2] & 0x7f) > rate)
1320 rate = ie[i + 2] & 0x7f;
1321 }
1322
1323 return rate;
1324}
1325
1326
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001327/**
1328 * wpa_bss_get_bit_rates - Get legacy TX rates supported in a BSS
1329 * @bss: BSS table entry
1330 * @rates: Buffer for returning a pointer to the rates list (units of 500 kbps)
1331 * Returns: number of legacy TX rates or -1 on failure
1332 *
1333 * The caller is responsible for freeing the returned buffer with os_free() in
1334 * case of success.
1335 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001336int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates)
1337{
1338 const u8 *ie, *ie2;
1339 int i, j;
1340 unsigned int len;
1341 u8 *r;
1342
1343 ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1344 ie2 = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
1345
1346 len = (ie ? ie[1] : 0) + (ie2 ? ie2[1] : 0);
1347
1348 r = os_malloc(len);
1349 if (!r)
1350 return -1;
1351
1352 for (i = 0; ie && i < ie[1]; i++)
1353 r[i] = ie[i + 2] & 0x7f;
1354
1355 for (j = 0; ie2 && j < ie2[1]; j++)
1356 r[i + j] = ie2[j + 2] & 0x7f;
1357
1358 *rates = r;
1359 return len;
1360}
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001361
1362
1363#ifdef CONFIG_FILS
Hai Shalom60840252021-02-19 19:02:11 -08001364const u8 * wpa_bss_get_fils_cache_id(const struct wpa_bss *bss)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001365{
1366 const u8 *ie;
1367
1368 if (bss) {
1369 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
1370 if (ie && ie[1] >= 4 && WPA_GET_LE16(ie + 2) & BIT(7))
1371 return ie + 4;
1372 }
1373
1374 return NULL;
1375}
1376#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08001377
1378
1379int wpa_bss_ext_capab(const struct wpa_bss *bss, unsigned int capab)
1380{
Hai Shalom60840252021-02-19 19:02:11 -08001381 if (!bss)
1382 return 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08001383 return ieee802_11_ext_capab(wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB),
1384 capab);
1385}