Lines Matching refs:bss
2 * BSS table
19 #include "bss.h"
38 static void wpa_bss_set_hessid(struct wpa_bss *bss)
41 const u8 *ie = wpa_bss_get_ie(bss, WLAN_EID_INTERWORKING);
43 os_memset(bss->hessid, 0, ETH_ALEN);
47 os_memcpy(bss->hessid, ie + 3, ETH_ALEN);
49 os_memcpy(bss->hessid, ie + 5, ETH_ALEN);
55 * wpa_bss_anqp_alloc - Allocate ANQP data structure for a BSS entry
59 * shared by multiple BSS entries and each shared entry is freed with
110 * wpa_bss_anqp_unshare_alloc - Unshare ANQP data (if shared) in a BSS entry
111 * @bss: BSS entry
114 * This function ensures the specific BSS entry has an ANQP data structure that
115 * is not shared with any other BSS entry.
117 int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss)
121 if (bss->anqp && bss->anqp->users > 1) {
123 anqp = wpa_bss_anqp_clone(bss->anqp);
127 bss->anqp->users--;
128 bss->anqp = anqp;
132 if (bss->anqp)
136 bss->anqp = wpa_bss_anqp_alloc();
137 return bss->anqp ? 0 : -1;
152 /* Another BSS entry holds a pointer to this ANQP info */
177 static void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
183 if (wpa_s->last_scan_res[i] == bss) {
193 dl_list_del(&bss->list);
194 dl_list_del(&bss->list_id);
196 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Remove id %u BSSID " MACSTR
197 " SSID '%s' due to %s", bss->id, MAC2STR(bss->bssid),
198 wpa_ssid_txt(bss->ssid, bss->ssid_len), reason);
199 wpas_notify_bss_removed(wpa_s, bss->bssid, bss->id);
200 wpa_bss_anqp_free(bss->anqp);
201 os_free(bss);
206 * wpa_bss_get - Fetch a BSS table entry based on BSSID and SSID
211 * Returns: Pointer to the BSS entry or %NULL if not found
216 struct wpa_bss *bss;
219 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
220 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
221 bss->ssid_len == ssid_len &&
222 os_memcmp(bss->ssid, ssid, ssid_len) == 0)
223 return bss;
264 static int wpa_bss_known(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
271 if (ssid->ssid_len == bss->ssid_len &&
272 os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) == 0)
280 static int wpa_bss_in_use(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
282 return bss == wpa_s->current_bss ||
283 os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) == 0 ||
284 os_memcmp(bss->bssid, wpa_s->pending_bssid, ETH_ALEN) == 0;
290 struct wpa_bss *bss;
292 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
293 if (!wpa_bss_known(wpa_s, bss)) {
294 wpa_bss_remove(wpa_s, bss, __func__);
305 struct wpa_bss *bss;
317 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
318 if (!wpa_bss_in_use(wpa_s, bss)) {
319 wpa_bss_remove(wpa_s, bss, __func__);
333 struct wpa_bss *bss;
335 bss = os_zalloc(sizeof(*bss) + res->ie_len + res->beacon_ie_len);
336 if (bss == NULL)
338 bss->id = wpa_s->bss_next_id++;
339 bss->last_update_idx = wpa_s->bss_update_idx;
340 wpa_bss_copy_res(bss, res, fetch_time);
341 os_memcpy(bss->ssid, ssid, ssid_len);
342 bss->ssid_len = ssid_len;
343 bss->ie_len = res->ie_len;
344 bss->beacon_ie_len = res->beacon_ie_len;
345 os_memcpy(bss + 1, res + 1, res->ie_len + res->beacon_ie_len);
346 wpa_bss_set_hessid(bss);
350 wpa_printf(MSG_ERROR, "Increasing the MAX BSS count to %d "
356 dl_list_add_tail(&wpa_s->bss, &bss->list);
357 dl_list_add_tail(&wpa_s->bss_id, &bss->list_id);
359 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Add new id %u BSSID " MACSTR
361 bss->id, MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
362 wpas_notify_bss_added(wpa_s, bss->bssid, bss->id);
363 return bss;
394 wpa_printf(MSG_DEBUG, "bss: %s: cannot compare IEs", __func__);
464 const struct wpa_bss *bss)
467 wpas_notify_bss_freq_changed(wpa_s, bss->id);
470 wpas_notify_bss_signal_changed(wpa_s, bss->id);
473 wpas_notify_bss_privacy_changed(wpa_s, bss->id);
476 wpas_notify_bss_mode_changed(wpa_s, bss->id);
479 wpas_notify_bss_wpaie_changed(wpa_s, bss->id);
482 wpas_notify_bss_rsnie_changed(wpa_s, bss->id);
485 wpas_notify_bss_wps_changed(wpa_s, bss->id);
488 wpas_notify_bss_ies_changed(wpa_s, bss->id);
491 wpas_notify_bss_rates_changed(wpa_s, bss->id);
496 wpa_bss_update(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
501 changes = wpa_bss_compare_res(bss, res);
502 bss->scan_miss_count = 0;
503 bss->last_update_idx = wpa_s->bss_update_idx;
504 wpa_bss_copy_res(bss, res, fetch_time);
506 dl_list_del(&bss->list);
508 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
514 * Do not update the IEs in this BSS entry to avoid such loss of
518 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Do not update scan IEs for "
520 MAC2STR(bss->bssid));
523 if (bss->ie_len + bss->beacon_ie_len >=
525 os_memcpy(bss + 1, res + 1, res->ie_len + res->beacon_ie_len);
526 bss->ie_len = res->ie_len;
527 bss->beacon_ie_len = res->beacon_ie_len;
530 struct dl_list *prev = bss->list_id.prev;
531 dl_list_del(&bss->list_id);
532 nbss = os_realloc(bss, sizeof(*bss) + res->ie_len +
537 if (wpa_s->last_scan_res[i] == bss) {
542 if (wpa_s->current_bss == bss)
544 bss = nbss;
545 os_memcpy(bss + 1, res + 1,
547 bss->ie_len = res->ie_len;
548 bss->beacon_ie_len = res->beacon_ie_len;
550 dl_list_add(prev, &bss->list_id);
553 wpa_bss_set_hessid(bss);
554 dl_list_add_tail(&wpa_s->bss, &bss->list);
556 notify_bss_changes(wpa_s, changes, bss);
558 return bss;
563 * wpa_bss_update_start - Start a BSS table update from scan results
566 * This function is called at the start of each BSS table update round for new
574 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Start scan result update %u",
581 * wpa_bss_update_scan_res - Update a BSS table entry based on a scan result
586 * This function updates a BSS table entry (or adds one) based on a scan result.
595 struct wpa_bss *bss;
604 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Ignore driver BSS "
615 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: No SSID IE included for "
620 wpa_dbg(wpa_s, MSG_DEBUG, "BSS: Too long SSID IE included for "
633 wpa_printf(MSG_DEBUG, "BSS: No P2P IE - skipping BSS " MACSTR
644 bss = wpa_bss_get(wpa_s, res->bssid, ssid + 2, ssid[1]);
645 if (bss == NULL)
646 bss = wpa_bss_add(wpa_s, ssid + 2, ssid[1], res, fetch_time);
648 bss = wpa_bss_update(wpa_s, bss, res, fetch_time);
652 if (bss == wpa_s->last_scan_res[i]) {
660 if (bss == NULL)
678 wpa_s->last_scan_res[wpa_s->last_scan_res_used++] = bss;
682 static int wpa_bss_included_in_scan(const struct wpa_bss *bss,
694 if (bss->freq == info->freqs[i]) {
708 (s->ssid_len == bss->ssid_len &&
709 os_memcmp(s->ssid, bss->ssid, bss->ssid_len) ==
724 * wpa_bss_update_end - End a BSS table update from scan results
729 * This function is called at the end of each BSS table update round for new
736 struct wpa_bss *bss, *n;
742 dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
743 if (wpa_bss_in_use(wpa_s, bss))
745 if (!wpa_bss_included_in_scan(bss, info))
747 if (bss->last_update_idx < wpa_s->bss_update_idx)
748 bss->scan_miss_count++;
749 if (bss->scan_miss_count >=
751 wpa_bss_remove(wpa_s, bss, "no match in scan");
755 wpa_printf(MSG_DEBUG, "BSS: last_scan_res_used=%u/%u",
761 * wpa_bss_flush_by_age - Flush old BSS entries
765 * Remove BSS entries that have not been updated during the last @age seconds.
769 struct wpa_bss *bss, *n;
772 if (dl_list_empty(&wpa_s->bss))
778 dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
779 if (wpa_bss_in_use(wpa_s, bss))
782 if (os_reltime_before(&bss->last_update, &t)) {
783 wpa_bss_remove(wpa_s, bss, __func__);
801 * wpa_bss_init - Initialize BSS table
805 * This prepares BSS table lists and timer for periodic updates. The BSS table
810 dl_list_init(&wpa_s->bss);
819 * wpa_bss_flush - Flush all unused BSS entries
824 struct wpa_bss *bss, *n;
828 if (wpa_s->bss.next == NULL)
829 return; /* BSS table not yet initialized */
831 dl_list_for_each_safe(bss, n, &wpa_s->bss, struct wpa_bss, list) {
832 if (wpa_bss_in_use(wpa_s, bss))
834 wpa_bss_remove(wpa_s, bss, __func__);
840 * wpa_bss_deinit - Deinitialize BSS table
851 * wpa_bss_get_bssid - Fetch a BSS table entry based on BSSID
854 * Returns: Pointer to the BSS entry or %NULL if not found
859 struct wpa_bss *bss;
862 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
863 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
864 return bss;
871 * wpa_bss_get_bssid_latest - Fetch the latest BSS table entry based on BSSID
874 * Returns: Pointer to the BSS entry or %NULL if not found
876 * This function is like wpa_bss_get_bssid(), but full BSS table is iterated to
884 struct wpa_bss *bss, *found = NULL;
887 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
888 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) != 0)
891 os_reltime_before(&found->last_update, &bss->last_update))
892 found = bss;
900 * wpa_bss_get_p2p_dev_addr - Fetch a BSS table entry based on P2P Device Addr
903 * Returns: Pointer to the BSS entry or %NULL if not found
908 struct wpa_bss *bss;
909 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
911 if (p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
914 return bss;
922 * wpa_bss_get_id - Fetch a BSS table entry based on identifier
925 * Returns: Pointer to the BSS entry or %NULL if not found
929 struct wpa_bss *bss;
930 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
931 if (bss->id == id)
932 return bss;
939 * wpa_bss_get_id_range - Fetch a BSS table entry based on identifier range
943 * Returns: Pointer to the BSS entry or %NULL if not found
945 * This function is similar to wpa_bss_get_id() but allows a BSS entry with the
952 struct wpa_bss *bss;
953 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
954 if (bss->id >= idf && bss->id <= idl)
955 return bss;
962 * wpa_bss_get_ie - Fetch a specified information element from a BSS entry
963 * @bss: BSS table entry
967 * This function returns the first matching information element in the BSS
970 const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie)
974 pos = (const u8 *) (bss + 1);
975 end = pos + bss->ie_len;
990 * wpa_bss_get_vendor_ie - Fetch a vendor information element from a BSS entry
991 * @bss: BSS table entry
995 * This function returns the first matching information element in the BSS
998 const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type)
1002 pos = (const u8 *) (bss + 1);
1003 end = pos + bss->ie_len;
1019 * wpa_bss_get_vendor_ie_beacon - Fetch a vendor information from a BSS entry
1020 * @bss: BSS table entry
1024 * This function returns the first matching information element in the BSS
1030 const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss,
1035 if (bss->beacon_ie_len == 0)
1038 pos = (const u8 *) (bss + 1);
1039 pos += bss->ie_len;
1040 end = pos + bss->beacon_ie_len;
1056 * wpa_bss_get_vendor_ie_multi - Fetch vendor IE data from a BSS entry
1057 * @bss: BSS table entry
1062 * specific information elements in the BSS entry. The caller is responsible for
1065 struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
1071 buf = wpabuf_alloc(bss->ie_len);
1075 pos = (const u8 *) (bss + 1);
1076 end = pos + bss->ie_len;
1097 * wpa_bss_get_vendor_ie_multi_beacon - Fetch vendor IE data from a BSS entry
1098 * @bss: BSS table entry
1103 * specific information elements in the BSS entry. The caller is responsible for
1109 struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss,
1115 buf = wpabuf_alloc(bss->beacon_ie_len);
1119 pos = (const u8 *) (bss + 1);
1120 pos += bss->ie_len;
1121 end = pos + bss->beacon_ie_len;
1142 * wpa_bss_get_max_rate - Get maximum legacy TX rate supported in a BSS
1143 * @bss: BSS table entry
1146 int wpa_bss_get_max_rate(const struct wpa_bss *bss)
1152 ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1158 ie = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
1169 * wpa_bss_get_bit_rates - Get legacy TX rates supported in a BSS
1170 * @bss: BSS table entry
1177 int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates)
1184 ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1185 ie2 = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);