1214501Srpaulo/*
2214501Srpaulo * hostapd / Station table
3346981Scy * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
4214501Srpaulo *
5252726Srpaulo * This software may be distributed under the terms of the BSD license.
6252726Srpaulo * See README for more details.
7214501Srpaulo */
8214501Srpaulo
9214501Srpaulo#ifndef STA_INFO_H
10214501Srpaulo#define STA_INFO_H
11214501Srpaulo
12281806Srpaulo#include "common/defs.h"
13281806Srpaulo#include "list.h"
14337817Scy#include "vlan.h"
15346981Scy#include "common/wpa_common.h"
16346981Scy#include "common/ieee802_11_defs.h"
17281806Srpaulo
18214501Srpaulo/* STA flags */
19214501Srpaulo#define WLAN_STA_AUTH BIT(0)
20214501Srpaulo#define WLAN_STA_ASSOC BIT(1)
21214501Srpaulo#define WLAN_STA_AUTHORIZED BIT(5)
22214501Srpaulo#define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
23214501Srpaulo#define WLAN_STA_SHORT_PREAMBLE BIT(7)
24214501Srpaulo#define WLAN_STA_PREAUTH BIT(8)
25214501Srpaulo#define WLAN_STA_WMM BIT(9)
26214501Srpaulo#define WLAN_STA_MFP BIT(10)
27214501Srpaulo#define WLAN_STA_HT BIT(11)
28214501Srpaulo#define WLAN_STA_WPS BIT(12)
29214501Srpaulo#define WLAN_STA_MAYBE_WPS BIT(13)
30214501Srpaulo#define WLAN_STA_WDS BIT(14)
31252726Srpaulo#define WLAN_STA_ASSOC_REQ_OK BIT(15)
32252726Srpaulo#define WLAN_STA_WPS2 BIT(16)
33252726Srpaulo#define WLAN_STA_GAS BIT(17)
34252726Srpaulo#define WLAN_STA_VHT BIT(18)
35281806Srpaulo#define WLAN_STA_WNM_SLEEP_MODE BIT(19)
36281806Srpaulo#define WLAN_STA_VHT_OPMODE_ENABLED BIT(20)
37281806Srpaulo#define WLAN_STA_VENDOR_VHT BIT(21)
38346981Scy#define WLAN_STA_PENDING_FILS_ERP BIT(22)
39346981Scy#define WLAN_STA_MULTI_AP BIT(23)
40351611Scy#define WLAN_STA_HE BIT(24)
41252726Srpaulo#define WLAN_STA_PENDING_DISASSOC_CB BIT(29)
42252726Srpaulo#define WLAN_STA_PENDING_DEAUTH_CB BIT(30)
43214501Srpaulo#define WLAN_STA_NONERP BIT(31)
44214501Srpaulo
45214501Srpaulo/* Maximum number of supported rates (from both Supported Rates and Extended
46214501Srpaulo * Supported Rates IEs). */
47214501Srpaulo#define WLAN_SUPP_RATES_MAX 32
48214501Srpaulo
49346981Scystruct hostapd_data;
50214501Srpaulo
51337817Scystruct mbo_non_pref_chan_info {
52337817Scy	struct mbo_non_pref_chan_info *next;
53337817Scy	u8 op_class;
54337817Scy	u8 pref;
55337817Scy	u8 reason_code;
56337817Scy	u8 num_channels;
57337817Scy	u8 channels[];
58337817Scy};
59337817Scy
60337817Scystruct pending_eapol_rx {
61337817Scy	struct wpabuf *buf;
62337817Scy	struct os_reltime rx_time;
63337817Scy};
64337817Scy
65214501Srpaulostruct sta_info {
66214501Srpaulo	struct sta_info *next; /* next entry in sta list */
67214501Srpaulo	struct sta_info *hnext; /* next entry in hash table list */
68214501Srpaulo	u8 addr[6];
69281806Srpaulo	be32 ipaddr;
70281806Srpaulo	struct dl_list ip6addr; /* list head for struct ip6addr */
71214501Srpaulo	u16 aid; /* STA's unique AID (1 .. 2007) or 0 if not yet assigned */
72346981Scy	u16 disconnect_reason_code; /* RADIUS server override */
73214501Srpaulo	u32 flags; /* Bitfield of WLAN_STA_* */
74214501Srpaulo	u16 capability;
75214501Srpaulo	u16 listen_interval; /* or beacon_int for APs */
76214501Srpaulo	u8 supported_rates[WLAN_SUPP_RATES_MAX];
77214501Srpaulo	int supported_rates_len;
78252726Srpaulo	u8 qosinfo; /* Valid when WLAN_STA_WMM is set */
79214501Srpaulo
80281806Srpaulo#ifdef CONFIG_MESH
81281806Srpaulo	enum mesh_plink_state plink_state;
82281806Srpaulo	u16 peer_lid;
83281806Srpaulo	u16 my_lid;
84337817Scy	u16 peer_aid;
85281806Srpaulo	u16 mpm_close_reason;
86281806Srpaulo	int mpm_retries;
87337817Scy	u8 my_nonce[WPA_NONCE_LEN];
88337817Scy	u8 peer_nonce[WPA_NONCE_LEN];
89281806Srpaulo	u8 aek[32];	/* SHA256 digest length */
90337817Scy	u8 mtk[WPA_TK_MAX_LEN];
91337817Scy	size_t mtk_len;
92337817Scy	u8 mgtk_rsc[6];
93337817Scy	u8 mgtk_key_id;
94337817Scy	u8 mgtk[WPA_TK_MAX_LEN];
95337817Scy	size_t mgtk_len;
96337817Scy	u8 igtk_rsc[6];
97337817Scy	u8 igtk[WPA_TK_MAX_LEN];
98337817Scy	size_t igtk_len;
99337817Scy	u16 igtk_key_id;
100281806Srpaulo	u8 sae_auth_retry;
101281806Srpaulo#endif /* CONFIG_MESH */
102281806Srpaulo
103214501Srpaulo	unsigned int nonerp_set:1;
104214501Srpaulo	unsigned int no_short_slot_time_set:1;
105214501Srpaulo	unsigned int no_short_preamble_set:1;
106214501Srpaulo	unsigned int no_ht_gf_set:1;
107214501Srpaulo	unsigned int no_ht_set:1;
108281806Srpaulo	unsigned int ht40_intolerant_set:1;
109214501Srpaulo	unsigned int ht_20mhz_set:1;
110252726Srpaulo	unsigned int no_p2p_set:1;
111281806Srpaulo	unsigned int qos_map_enabled:1;
112281806Srpaulo	unsigned int remediation:1;
113281806Srpaulo	unsigned int hs20_deauth_requested:1;
114281806Srpaulo	unsigned int session_timeout_set:1;
115281806Srpaulo	unsigned int radius_das_match:1;
116337817Scy	unsigned int ecsa_supported:1;
117337817Scy	unsigned int added_unassoc:1;
118346981Scy	unsigned int pending_wds_enable:1;
119346981Scy	unsigned int power_capab:1;
120346981Scy	unsigned int agreed_to_steer:1;
121346981Scy	unsigned int hs20_t_c_filtering:1;
122346981Scy	unsigned int ft_over_ds:1;
123351611Scy	unsigned int external_dh_updated:1;
124214501Srpaulo
125214501Srpaulo	u16 auth_alg;
126214501Srpaulo
127214501Srpaulo	enum {
128281806Srpaulo		STA_NULLFUNC = 0, STA_DISASSOC, STA_DEAUTH, STA_REMOVE,
129281806Srpaulo		STA_DISASSOC_FROM_CLI
130214501Srpaulo	} timeout_next;
131214501Srpaulo
132252726Srpaulo	u16 deauth_reason;
133252726Srpaulo	u16 disassoc_reason;
134252726Srpaulo
135214501Srpaulo	/* IEEE 802.1X related data */
136214501Srpaulo	struct eapol_state_machine *eapol_sm;
137214501Srpaulo
138337817Scy	struct pending_eapol_rx *pending_eapol_rx;
139337817Scy
140337817Scy	u64 acct_session_id;
141281806Srpaulo	struct os_reltime acct_session_start;
142214501Srpaulo	int acct_session_started;
143214501Srpaulo	int acct_terminate_cause; /* Acct-Terminate-Cause */
144214501Srpaulo	int acct_interim_interval; /* Acct-Interim-Interval */
145337817Scy	unsigned int acct_interim_errors;
146214501Srpaulo
147337817Scy	/* For extending 32-bit driver counters to 64-bit counters */
148337817Scy	u32 last_rx_bytes_hi;
149337817Scy	u32 last_rx_bytes_lo;
150337817Scy	u32 last_tx_bytes_hi;
151337817Scy	u32 last_tx_bytes_lo;
152214501Srpaulo
153214501Srpaulo	u8 *challenge; /* IEEE 802.11 Shared Key Authentication Challenge */
154214501Srpaulo
155214501Srpaulo	struct wpa_state_machine *wpa_sm;
156214501Srpaulo	struct rsn_preauth_interface *preauth_iface;
157214501Srpaulo
158289549Srpaulo	int vlan_id; /* 0: none, >0: VID */
159337817Scy	struct vlan_description *vlan_desc;
160289549Srpaulo	int vlan_id_bound; /* updated by ap_sta_bind_vlan() */
161252726Srpaulo	 /* PSKs from RADIUS authentication server */
162252726Srpaulo	struct hostapd_sta_wpa_psk_short *psk;
163214501Srpaulo
164252726Srpaulo	char *identity; /* User-Name from RADIUS */
165252726Srpaulo	char *radius_cui; /* Chargeable-User-Identity from RADIUS */
166252726Srpaulo
167214501Srpaulo	struct ieee80211_ht_capabilities *ht_capabilities;
168252726Srpaulo	struct ieee80211_vht_capabilities *vht_capabilities;
169346981Scy	struct ieee80211_vht_operation *vht_operation;
170281806Srpaulo	u8 vht_opmode;
171351611Scy	struct ieee80211_he_capabilities *he_capab;
172351611Scy	size_t he_capab_len;
173214501Srpaulo
174214501Srpaulo#ifdef CONFIG_IEEE80211W
175214501Srpaulo	int sa_query_count; /* number of pending SA Query requests;
176214501Srpaulo			     * 0 = no SA Query in progress */
177214501Srpaulo	int sa_query_timed_out;
178214501Srpaulo	u8 *sa_query_trans_id; /* buffer of WLAN_SA_QUERY_TR_ID_LEN *
179214501Srpaulo				* sa_query_count octets of pending SA Query
180214501Srpaulo				* transaction identifiers */
181281806Srpaulo	struct os_reltime sa_query_start;
182214501Srpaulo#endif /* CONFIG_IEEE80211W */
183214501Srpaulo
184346981Scy#if defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
185252726Srpaulo#define GAS_DIALOG_MAX 8 /* Max concurrent dialog number */
186252726Srpaulo	struct gas_dialog_info *gas_dialog;
187252726Srpaulo	u8 gas_dialog_next;
188346981Scy#endif /* CONFIG_INTERWORKING || CONFIG_DPP */
189252726Srpaulo
190214501Srpaulo	struct wpabuf *wps_ie; /* WPS IE from (Re)Association Request */
191252726Srpaulo	struct wpabuf *p2p_ie; /* P2P IE from (Re)Association Request */
192252726Srpaulo	struct wpabuf *hs20_ie; /* HS 2.0 IE from (Re)Association Request */
193346981Scy	/* Hotspot 2.0 Roaming Consortium from (Re)Association Request */
194346981Scy	struct wpabuf *roaming_consortium;
195281806Srpaulo	u8 remediation_method;
196281806Srpaulo	char *remediation_url; /* HS 2.0 Subscription Remediation Server URL */
197346981Scy	char *t_c_url; /* HS 2.0 Terms and Conditions Server URL */
198281806Srpaulo	struct wpabuf *hs20_deauth_req;
199281806Srpaulo	char *hs20_session_info_url;
200281806Srpaulo	int hs20_disassoc_timer;
201289549Srpaulo#ifdef CONFIG_FST
202289549Srpaulo	struct wpabuf *mb_ies; /* MB IEs from (Re)Association Request */
203289549Srpaulo#endif /* CONFIG_FST */
204252726Srpaulo
205281806Srpaulo	struct os_reltime connected_time;
206252726Srpaulo
207252726Srpaulo#ifdef CONFIG_SAE
208281806Srpaulo	struct sae_data *sae;
209337817Scy	unsigned int mesh_sae_pmksa_caching:1;
210252726Srpaulo#endif /* CONFIG_SAE */
211281806Srpaulo
212346981Scy	/* valid only if session_timeout_set == 1 */
213346981Scy	struct os_reltime session_timeout;
214281806Srpaulo
215281806Srpaulo	/* Last Authentication/(Re)Association Request/Action frame sequence
216281806Srpaulo	 * control */
217281806Srpaulo	u16 last_seq_ctrl;
218281806Srpaulo	/* Last Authentication/(Re)Association Request/Action frame subtype */
219281806Srpaulo	u8 last_subtype;
220337817Scy
221337817Scy#ifdef CONFIG_MBO
222337817Scy	u8 cell_capa; /* 0 = unknown (not an MBO STA); otherwise,
223337817Scy		       * enum mbo_cellular_capa values */
224337817Scy	struct mbo_non_pref_chan_info *non_pref_chan;
225346981Scy	int auth_rssi; /* Last Authentication frame RSSI */
226337817Scy#endif /* CONFIG_MBO */
227337817Scy
228337817Scy	u8 *supp_op_classes; /* Supported Operating Classes element, if
229337817Scy			      * received, starting from the Length field */
230337817Scy
231337817Scy	u8 rrm_enabled_capa[5];
232337817Scy
233346981Scy	s8 min_tx_power;
234346981Scy	s8 max_tx_power;
235346981Scy
236337817Scy#ifdef CONFIG_TAXONOMY
237337817Scy	struct wpabuf *probe_ie_taxonomy;
238337817Scy	struct wpabuf *assoc_ie_taxonomy;
239337817Scy#endif /* CONFIG_TAXONOMY */
240346981Scy
241346981Scy#ifdef CONFIG_FILS
242346981Scy	u8 fils_snonce[FILS_NONCE_LEN];
243346981Scy	u8 fils_session[FILS_SESSION_LEN];
244346981Scy	u8 fils_erp_pmkid[PMKID_LEN];
245346981Scy	u8 *fils_pending_assoc_req;
246346981Scy	size_t fils_pending_assoc_req_len;
247346981Scy	unsigned int fils_pending_assoc_is_reassoc:1;
248346981Scy	unsigned int fils_dhcp_rapid_commit_proxy:1;
249346981Scy	unsigned int fils_erp_pmkid_set:1;
250346981Scy	unsigned int fils_drv_assoc_finish:1;
251346981Scy	struct wpabuf *fils_hlp_resp;
252346981Scy	struct wpabuf *hlp_dhcp_discover;
253346981Scy	void (*fils_pending_cb)(struct hostapd_data *hapd, struct sta_info *sta,
254346981Scy				u16 resp, struct wpabuf *data, int pub);
255346981Scy#ifdef CONFIG_FILS_SK_PFS
256346981Scy	struct crypto_ecdh *fils_ecdh;
257346981Scy#endif /* CONFIG_FILS_SK_PFS */
258346981Scy	struct wpabuf *fils_dh_ss;
259346981Scy	struct wpabuf *fils_g_sta;
260346981Scy#endif /* CONFIG_FILS */
261346981Scy
262346981Scy#ifdef CONFIG_OWE
263346981Scy	u8 *owe_pmk;
264346981Scy	size_t owe_pmk_len;
265346981Scy	struct crypto_ecdh *owe_ecdh;
266346981Scy	u16 owe_group;
267346981Scy#endif /* CONFIG_OWE */
268346981Scy
269346981Scy	u8 *ext_capability;
270346981Scy	char *ifname_wds; /* WDS ifname, if in use */
271346981Scy
272346981Scy#ifdef CONFIG_DPP2
273346981Scy	struct dpp_pfs *dpp_pfs;
274346981Scy#endif /* CONFIG_DPP2 */
275346981Scy
276346981Scy#ifdef CONFIG_TESTING_OPTIONS
277346981Scy	enum wpa_alg last_tk_alg;
278346981Scy	int last_tk_key_idx;
279346981Scy	u8 last_tk[WPA_TK_MAX_LEN];
280346981Scy	size_t last_tk_len;
281346981Scy#endif /* CONFIG_TESTING_OPTIONS */
282351611Scy#ifdef CONFIG_AIRTIME_POLICY
283351611Scy	unsigned int airtime_weight;
284351611Scy	struct os_reltime backlogged_until;
285351611Scy#endif /* CONFIG_AIRTIME_POLICY */
286214501Srpaulo};
287214501Srpaulo
288214501Srpaulo
289214501Srpaulo/* Default value for maximum station inactivity. After AP_MAX_INACTIVITY has
290214501Srpaulo * passed since last received frame from the station, a nullfunc data frame is
291214501Srpaulo * sent to the station. If this frame is not acknowledged and no other frames
292214501Srpaulo * have been received, the station will be disassociated after
293252726Srpaulo * AP_DISASSOC_DELAY seconds. Similarly, the station will be deauthenticated
294214501Srpaulo * after AP_DEAUTH_DELAY seconds has passed after disassociation. */
295214501Srpaulo#define AP_MAX_INACTIVITY (5 * 60)
296337817Scy#define AP_DISASSOC_DELAY (3)
297214501Srpaulo#define AP_DEAUTH_DELAY (1)
298214501Srpaulo/* Number of seconds to keep STA entry with Authenticated flag after it has
299214501Srpaulo * been disassociated. */
300214501Srpaulo#define AP_MAX_INACTIVITY_AFTER_DISASSOC (1 * 30)
301214501Srpaulo/* Number of seconds to keep STA entry after it has been deauthenticated. */
302214501Srpaulo#define AP_MAX_INACTIVITY_AFTER_DEAUTH (1 * 5)
303214501Srpaulo
304214501Srpaulo
305214501Srpauloint ap_for_each_sta(struct hostapd_data *hapd,
306214501Srpaulo		    int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
307214501Srpaulo			      void *ctx),
308214501Srpaulo		    void *ctx);
309214501Srpaulostruct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta);
310281806Srpaulostruct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr);
311214501Srpaulovoid ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta);
312214501Srpaulovoid ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta);
313281806Srpaulovoid ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta);
314214501Srpaulovoid hostapd_free_stas(struct hostapd_data *hapd);
315214501Srpaulovoid ap_handle_timer(void *eloop_ctx, void *timeout_ctx);
316281806Srpaulovoid ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
317281806Srpaulo			      u32 session_timeout);
318214501Srpaulovoid ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
319214501Srpaulo			    u32 session_timeout);
320214501Srpaulovoid ap_sta_no_session_timeout(struct hostapd_data *hapd,
321214501Srpaulo			       struct sta_info *sta);
322281806Srpaulovoid ap_sta_session_warning_timeout(struct hostapd_data *hapd,
323281806Srpaulo				    struct sta_info *sta, int warning_time);
324214501Srpaulostruct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr);
325214501Srpaulovoid ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
326214501Srpaulo			 u16 reason);
327214501Srpaulovoid ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
328214501Srpaulo			   u16 reason);
329252726Srpaulo#ifdef CONFIG_WPS
330252726Srpauloint ap_sta_wps_cancel(struct hostapd_data *hapd,
331252726Srpaulo		      struct sta_info *sta, void *ctx);
332252726Srpaulo#endif /* CONFIG_WPS */
333289549Srpauloint ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta);
334337817Scyint ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
335337817Scy		    struct vlan_description *vlan_desc);
336214501Srpaulovoid ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
337214501Srpaulovoid ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
338214501Srpauloint ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta);
339346981Scyconst char * ap_sta_wpa_get_keyid(struct hostapd_data *hapd,
340346981Scy				  struct sta_info *sta);
341214501Srpaulovoid ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
342214501Srpaulo		       const u8 *addr, u16 reason);
343214501Srpaulo
344252726Srpaulovoid ap_sta_set_authorized(struct hostapd_data *hapd,
345252726Srpaulo			   struct sta_info *sta, int authorized);
346252726Srpaulostatic inline int ap_sta_is_authorized(struct sta_info *sta)
347252726Srpaulo{
348252726Srpaulo	return sta->flags & WLAN_STA_AUTHORIZED;
349252726Srpaulo}
350252726Srpaulo
351252726Srpaulovoid ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta);
352252726Srpaulovoid ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta);
353337817Scyvoid ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
354337817Scy				      struct sta_info *sta);
355252726Srpaulo
356281806Srpauloint ap_sta_flags_txt(u32 flags, char *buf, size_t buflen);
357346981Scyvoid ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
358346981Scy					    struct sta_info *sta);
359346981Scyint ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
360346981Scy						   struct sta_info *sta);
361281806Srpaulo
362214501Srpaulo#endif /* STA_INFO_H */
363