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 #ifndef BSS_H
10 #define BSS_H
11 
12 struct wpa_scan_res;
13 
14 /**
15  * struct wpa_bss - BSS table
16  *
17  * This structure is used to store information about neighboring BSSes in
18  * generic format. It is mainly updated based on scan results from the driver.
19  */
20 struct wpa_bss {
21 	/** List entry for struct wpa_supplicant::bss */
22 	struct dl_list list;
23 	/** List entry for struct wpa_supplicant::bss_id */
24 	struct dl_list list_id;
25 	/** Unique identifier for this BSS entry */
26 	unsigned int id;
27 	/** Index of the last scan update */
28 	unsigned int last_update_idx;
29 	/** Information flags about the BSS/IBSS (WPA_BSS_*) */
30 	unsigned int flags;
31 	/** BSSID */
32 	u8 bssid[ETH_ALEN];
33 	/** SSID */
34 	u8 ssid[SSID_MAX_LEN];
35 	/** Length of SSID */
36 	size_t ssid_len;
37 	/** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
38 	int channel;
39 	/** Beacon interval in TUs (host byte order) */
40 	u16 beacon_int;
41 	/** Capability information field in host byte order */
42 	u16 caps;
43 	/** Signal quality */
44 	int qual;
45 	/** Noise level */
46 	int noise;
47 	/** Signal level */
48 	int level;
49 	/** Timestamp of last Beacon/Probe Response frame */
50 	u64 tsf;
51 	/** Timestamp of parent aganist which it was taken */
52 	u64 parent_tsf;
53 	/** Time of the last update (i.e., Beacon or Probe Response RX) */
54 	struct os_reltime last_update;
55 	/** Length of the following IE field in octets (from Probe Response) */
56 	size_t ie_len;
57 	/** Length of the following Beacon IE field in octets */
58 	size_t beacon_ie_len;
59 	/* followed by ie_len octets of IEs */
60 	/* followed by beacon_ie_len octets of IEs */
61 	u8 ies[];
62 };
63 
wpa_bss_ie_ptr(const struct wpa_bss * bss)64 static inline const u8 * wpa_bss_ie_ptr(const struct wpa_bss *bss)
65 {
66 	return bss->ies;
67 }
68 
69 void wpa_bss_update_start(struct wpa_supplicant *wpa_s);
70 void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
71 			     struct wpa_scan_res *res,
72 			     struct os_reltime *fetch_time);
73 void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
74 		    const char *reason);
75 void wpa_bss_update_end(struct wpa_supplicant *wpa_s);
76 int wpa_bss_init(struct wpa_supplicant *wpa_s);
77 void wpa_bss_deinit(struct wpa_supplicant *wpa_s);
78 void wpa_bss_flush(struct wpa_supplicant *wpa_s);
79 struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
80 			     const u8 *ssid, size_t ssid_len);
81 struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
82 				   const u8 *bssid);
83 const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie);
84 const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type);
85 int wpa_bss_ext_capab(const struct wpa_bss *bss, unsigned int capab);
86 struct wpa_bss * wpa_bss_get_next_bss(struct wpa_supplicant *wpa_s,
87 				   struct wpa_bss *prev_bss);
88 
89 void calculate_update_time(const struct os_reltime *fetch_time,
90 			   unsigned int age_ms,
91 			   struct os_reltime *update_time);
92 
93 #endif /* BSS_H */
94