1/*
2 * BSS table
3 * Copyright (c) 2009-2015, 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
12struct wpa_scan_res;
13
14#define WPA_BSS_QUAL_INVALID		BIT(0)
15#define WPA_BSS_NOISE_INVALID		BIT(1)
16#define WPA_BSS_LEVEL_INVALID		BIT(2)
17#define WPA_BSS_LEVEL_DBM		BIT(3)
18#define WPA_BSS_AUTHENTICATED		BIT(4)
19#define WPA_BSS_ASSOCIATED		BIT(5)
20#define WPA_BSS_ANQP_FETCH_TRIED	BIT(6)
21
22struct wpa_bss_anqp_elem {
23	struct dl_list list;
24	u16 infoid;
25	struct wpabuf *payload;
26};
27
28/**
29 * struct wpa_bss_anqp - ANQP data for a BSS entry (struct wpa_bss)
30 */
31struct wpa_bss_anqp {
32	/** Number of BSS entries referring to this ANQP data instance */
33	unsigned int users;
34#ifdef CONFIG_INTERWORKING
35	struct wpabuf *capability_list;
36	struct wpabuf *venue_name;
37	struct wpabuf *network_auth_type;
38	struct wpabuf *roaming_consortium;
39	struct wpabuf *ip_addr_type_availability;
40	struct wpabuf *nai_realm;
41	struct wpabuf *anqp_3gpp;
42	struct wpabuf *domain_name;
43	struct wpabuf *fils_realm_info;
44	struct dl_list anqp_elems; /* list of struct wpa_bss_anqp_elem */
45#endif /* CONFIG_INTERWORKING */
46#ifdef CONFIG_HS20
47	struct wpabuf *hs20_capability_list;
48	struct wpabuf *hs20_operator_friendly_name;
49	struct wpabuf *hs20_wan_metrics;
50	struct wpabuf *hs20_connection_capability;
51	struct wpabuf *hs20_operating_class;
52	struct wpabuf *hs20_osu_providers_list;
53#endif /* CONFIG_HS20 */
54};
55
56/**
57 * struct wpa_bss - BSS table
58 *
59 * This structure is used to store information about neighboring BSSes in
60 * generic format. It is mainly updated based on scan results from the driver.
61 */
62struct wpa_bss {
63	/** List entry for struct wpa_supplicant::bss */
64	struct dl_list list;
65	/** List entry for struct wpa_supplicant::bss_id */
66	struct dl_list list_id;
67	/** Unique identifier for this BSS entry */
68	unsigned int id;
69	/** Number of counts without seeing this BSS */
70	unsigned int scan_miss_count;
71	/** Index of the last scan update */
72	unsigned int last_update_idx;
73	/** Information flags about the BSS/IBSS (WPA_BSS_*) */
74	unsigned int flags;
75	/** BSSID */
76	u8 bssid[ETH_ALEN];
77	/** HESSID */
78	u8 hessid[ETH_ALEN];
79	/** SSID */
80	u8 ssid[SSID_MAX_LEN];
81	/** Length of SSID */
82	size_t ssid_len;
83	/** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
84	int freq;
85	/** Beacon interval in TUs (host byte order) */
86	u16 beacon_int;
87	/** Capability information field in host byte order */
88	u16 caps;
89	/** Signal quality */
90	int qual;
91	/** Noise level */
92	int noise;
93	/** Signal level */
94	int level;
95	/** Timestamp of last Beacon/Probe Response frame */
96	u64 tsf;
97	/** Time of the last update (i.e., Beacon or Probe Response RX) */
98	struct os_reltime last_update;
99	/** Estimated throughput in kbps */
100	unsigned int est_throughput;
101	/** Signal-to-noise ratio in dB */
102	int snr;
103	/** ANQP data */
104	struct wpa_bss_anqp *anqp;
105	/** Length of the following IE field in octets (from Probe Response) */
106	size_t ie_len;
107	/** Length of the following Beacon IE field in octets */
108	size_t beacon_ie_len;
109	/* followed by ie_len octets of IEs */
110	/* followed by beacon_ie_len octets of IEs */
111};
112
113void wpa_bss_update_start(struct wpa_supplicant *wpa_s);
114void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
115			     struct wpa_scan_res *res,
116			     struct os_reltime *fetch_time);
117void wpa_bss_remove(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
118		    const char *reason);
119void wpa_bss_update_end(struct wpa_supplicant *wpa_s, struct scan_info *info,
120			int new_scan);
121int wpa_bss_init(struct wpa_supplicant *wpa_s);
122void wpa_bss_deinit(struct wpa_supplicant *wpa_s);
123void wpa_bss_flush(struct wpa_supplicant *wpa_s);
124void wpa_bss_flush_by_age(struct wpa_supplicant *wpa_s, int age);
125struct wpa_bss * wpa_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid,
126			     const u8 *ssid, size_t ssid_len);
127struct wpa_bss * wpa_bss_get_bssid(struct wpa_supplicant *wpa_s,
128				   const u8 *bssid);
129struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s,
130					  const u8 *bssid);
131struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s,
132					  const u8 *dev_addr);
133struct wpa_bss * wpa_bss_get_id(struct wpa_supplicant *wpa_s, unsigned int id);
134struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s,
135				      unsigned int idf, unsigned int idl);
136const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie);
137const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type);
138const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss,
139					u32 vendor_type);
140struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
141					    u32 vendor_type);
142struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss,
143						   u32 vendor_type);
144int wpa_bss_get_max_rate(const struct wpa_bss *bss);
145int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates);
146struct wpa_bss_anqp * wpa_bss_anqp_alloc(void);
147int wpa_bss_anqp_unshare_alloc(struct wpa_bss *bss);
148
149static inline int bss_is_dmg(const struct wpa_bss *bss)
150{
151	return bss->freq > 45000;
152}
153
154/**
155 * Test whether a BSS is a PBSS.
156 * This checks whether a BSS is a DMG-band PBSS. PBSS is used for P2P DMG
157 * network.
158 */
159static inline int bss_is_pbss(struct wpa_bss *bss)
160{
161	return bss_is_dmg(bss) &&
162		(bss->caps & IEEE80211_CAP_DMG_MASK) == IEEE80211_CAP_DMG_PBSS;
163}
164
165static inline void wpa_bss_update_level(struct wpa_bss *bss, int new_level)
166{
167	if (bss != NULL && new_level < 0)
168		bss->level = new_level;
169}
170
171void calculate_update_time(const struct os_reltime *fetch_time,
172			   unsigned int age_ms,
173			   struct os_reltime *update_time);
174
175#endif /* BSS_H */
176