1214501Srpaulo/*
2214501Srpaulo * hostapd / Station table
3252726Srpaulo * Copyright (c) 2002-2011, 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
12214501Srpaulo/* STA flags */
13214501Srpaulo#define WLAN_STA_AUTH BIT(0)
14214501Srpaulo#define WLAN_STA_ASSOC BIT(1)
15214501Srpaulo#define WLAN_STA_PS BIT(2)
16214501Srpaulo#define WLAN_STA_TIM BIT(3)
17214501Srpaulo#define WLAN_STA_PERM BIT(4)
18214501Srpaulo#define WLAN_STA_AUTHORIZED BIT(5)
19214501Srpaulo#define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
20214501Srpaulo#define WLAN_STA_SHORT_PREAMBLE BIT(7)
21214501Srpaulo#define WLAN_STA_PREAUTH BIT(8)
22214501Srpaulo#define WLAN_STA_WMM BIT(9)
23214501Srpaulo#define WLAN_STA_MFP BIT(10)
24214501Srpaulo#define WLAN_STA_HT BIT(11)
25214501Srpaulo#define WLAN_STA_WPS BIT(12)
26214501Srpaulo#define WLAN_STA_MAYBE_WPS BIT(13)
27214501Srpaulo#define WLAN_STA_WDS BIT(14)
28252726Srpaulo#define WLAN_STA_ASSOC_REQ_OK BIT(15)
29252726Srpaulo#define WLAN_STA_WPS2 BIT(16)
30252726Srpaulo#define WLAN_STA_GAS BIT(17)
31252726Srpaulo#define WLAN_STA_VHT BIT(18)
32252726Srpaulo#define WLAN_STA_PENDING_DISASSOC_CB BIT(29)
33252726Srpaulo#define WLAN_STA_PENDING_DEAUTH_CB BIT(30)
34214501Srpaulo#define WLAN_STA_NONERP BIT(31)
35214501Srpaulo
36214501Srpaulo/* Maximum number of supported rates (from both Supported Rates and Extended
37214501Srpaulo * Supported Rates IEs). */
38214501Srpaulo#define WLAN_SUPP_RATES_MAX 32
39214501Srpaulo
40214501Srpaulo
41214501Srpaulostruct sta_info {
42214501Srpaulo	struct sta_info *next; /* next entry in sta list */
43214501Srpaulo	struct sta_info *hnext; /* next entry in hash table list */
44214501Srpaulo	u8 addr[6];
45214501Srpaulo	u16 aid; /* STA's unique AID (1 .. 2007) or 0 if not yet assigned */
46214501Srpaulo	u32 flags; /* Bitfield of WLAN_STA_* */
47214501Srpaulo	u16 capability;
48214501Srpaulo	u16 listen_interval; /* or beacon_int for APs */
49214501Srpaulo	u8 supported_rates[WLAN_SUPP_RATES_MAX];
50214501Srpaulo	int supported_rates_len;
51252726Srpaulo	u8 qosinfo; /* Valid when WLAN_STA_WMM is set */
52214501Srpaulo
53214501Srpaulo	unsigned int nonerp_set:1;
54214501Srpaulo	unsigned int no_short_slot_time_set:1;
55214501Srpaulo	unsigned int no_short_preamble_set:1;
56214501Srpaulo	unsigned int no_ht_gf_set:1;
57214501Srpaulo	unsigned int no_ht_set:1;
58214501Srpaulo	unsigned int ht_20mhz_set:1;
59252726Srpaulo	unsigned int no_p2p_set:1;
60214501Srpaulo
61214501Srpaulo	u16 auth_alg;
62214501Srpaulo	u8 previous_ap[6];
63214501Srpaulo
64214501Srpaulo	enum {
65214501Srpaulo		STA_NULLFUNC = 0, STA_DISASSOC, STA_DEAUTH, STA_REMOVE
66214501Srpaulo	} timeout_next;
67214501Srpaulo
68252726Srpaulo	u16 deauth_reason;
69252726Srpaulo	u16 disassoc_reason;
70252726Srpaulo
71214501Srpaulo	/* IEEE 802.1X related data */
72214501Srpaulo	struct eapol_state_machine *eapol_sm;
73214501Srpaulo
74214501Srpaulo	/* IEEE 802.11f (IAPP) related data */
75214501Srpaulo	struct ieee80211_mgmt *last_assoc_req;
76214501Srpaulo
77214501Srpaulo	u32 acct_session_id_hi;
78214501Srpaulo	u32 acct_session_id_lo;
79214501Srpaulo	time_t acct_session_start;
80214501Srpaulo	int acct_session_started;
81214501Srpaulo	int acct_terminate_cause; /* Acct-Terminate-Cause */
82214501Srpaulo	int acct_interim_interval; /* Acct-Interim-Interval */
83214501Srpaulo
84214501Srpaulo	unsigned long last_rx_bytes;
85214501Srpaulo	unsigned long last_tx_bytes;
86214501Srpaulo	u32 acct_input_gigawords; /* Acct-Input-Gigawords */
87214501Srpaulo	u32 acct_output_gigawords; /* Acct-Output-Gigawords */
88214501Srpaulo
89214501Srpaulo	u8 *challenge; /* IEEE 802.11 Shared Key Authentication Challenge */
90214501Srpaulo
91214501Srpaulo	struct wpa_state_machine *wpa_sm;
92214501Srpaulo	struct rsn_preauth_interface *preauth_iface;
93214501Srpaulo
94214501Srpaulo	struct hostapd_ssid *ssid; /* SSID selection based on (Re)AssocReq */
95214501Srpaulo	struct hostapd_ssid *ssid_probe; /* SSID selection based on ProbeReq */
96214501Srpaulo
97214501Srpaulo	int vlan_id;
98252726Srpaulo	 /* PSKs from RADIUS authentication server */
99252726Srpaulo	struct hostapd_sta_wpa_psk_short *psk;
100214501Srpaulo
101252726Srpaulo	char *identity; /* User-Name from RADIUS */
102252726Srpaulo	char *radius_cui; /* Chargeable-User-Identity from RADIUS */
103252726Srpaulo
104214501Srpaulo	struct ieee80211_ht_capabilities *ht_capabilities;
105252726Srpaulo	struct ieee80211_vht_capabilities *vht_capabilities;
106214501Srpaulo
107214501Srpaulo#ifdef CONFIG_IEEE80211W
108214501Srpaulo	int sa_query_count; /* number of pending SA Query requests;
109214501Srpaulo			     * 0 = no SA Query in progress */
110214501Srpaulo	int sa_query_timed_out;
111214501Srpaulo	u8 *sa_query_trans_id; /* buffer of WLAN_SA_QUERY_TR_ID_LEN *
112214501Srpaulo				* sa_query_count octets of pending SA Query
113214501Srpaulo				* transaction identifiers */
114214501Srpaulo	struct os_time sa_query_start;
115214501Srpaulo#endif /* CONFIG_IEEE80211W */
116214501Srpaulo
117252726Srpaulo#ifdef CONFIG_INTERWORKING
118252726Srpaulo#define GAS_DIALOG_MAX 8 /* Max concurrent dialog number */
119252726Srpaulo	struct gas_dialog_info *gas_dialog;
120252726Srpaulo	u8 gas_dialog_next;
121252726Srpaulo#endif /* CONFIG_INTERWORKING */
122252726Srpaulo
123214501Srpaulo	struct wpabuf *wps_ie; /* WPS IE from (Re)Association Request */
124252726Srpaulo	struct wpabuf *p2p_ie; /* P2P IE from (Re)Association Request */
125252726Srpaulo	struct wpabuf *hs20_ie; /* HS 2.0 IE from (Re)Association Request */
126252726Srpaulo
127252726Srpaulo	struct os_time connected_time;
128252726Srpaulo
129252726Srpaulo#ifdef CONFIG_SAE
130252726Srpaulo	enum { SAE_INIT, SAE_COMMIT, SAE_CONFIRM } sae_state;
131252726Srpaulo	u16 sae_send_confirm;
132252726Srpaulo#endif /* CONFIG_SAE */
133214501Srpaulo};
134214501Srpaulo
135214501Srpaulo
136214501Srpaulo/* Default value for maximum station inactivity. After AP_MAX_INACTIVITY has
137214501Srpaulo * passed since last received frame from the station, a nullfunc data frame is
138214501Srpaulo * sent to the station. If this frame is not acknowledged and no other frames
139214501Srpaulo * have been received, the station will be disassociated after
140252726Srpaulo * AP_DISASSOC_DELAY seconds. Similarly, the station will be deauthenticated
141214501Srpaulo * after AP_DEAUTH_DELAY seconds has passed after disassociation. */
142214501Srpaulo#define AP_MAX_INACTIVITY (5 * 60)
143214501Srpaulo#define AP_DISASSOC_DELAY (1)
144214501Srpaulo#define AP_DEAUTH_DELAY (1)
145214501Srpaulo/* Number of seconds to keep STA entry with Authenticated flag after it has
146214501Srpaulo * been disassociated. */
147214501Srpaulo#define AP_MAX_INACTIVITY_AFTER_DISASSOC (1 * 30)
148214501Srpaulo/* Number of seconds to keep STA entry after it has been deauthenticated. */
149214501Srpaulo#define AP_MAX_INACTIVITY_AFTER_DEAUTH (1 * 5)
150214501Srpaulo
151214501Srpaulo
152214501Srpaulostruct hostapd_data;
153214501Srpaulo
154214501Srpauloint ap_for_each_sta(struct hostapd_data *hapd,
155214501Srpaulo		    int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
156214501Srpaulo			      void *ctx),
157214501Srpaulo		    void *ctx);
158214501Srpaulostruct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta);
159214501Srpaulovoid ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta);
160214501Srpaulovoid ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta);
161214501Srpaulovoid hostapd_free_stas(struct hostapd_data *hapd);
162214501Srpaulovoid ap_handle_timer(void *eloop_ctx, void *timeout_ctx);
163214501Srpaulovoid ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
164214501Srpaulo			    u32 session_timeout);
165214501Srpaulovoid ap_sta_no_session_timeout(struct hostapd_data *hapd,
166214501Srpaulo			       struct sta_info *sta);
167214501Srpaulostruct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr);
168214501Srpaulovoid ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
169214501Srpaulo			 u16 reason);
170214501Srpaulovoid ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
171214501Srpaulo			   u16 reason);
172252726Srpaulo#ifdef CONFIG_WPS
173252726Srpauloint ap_sta_wps_cancel(struct hostapd_data *hapd,
174252726Srpaulo		      struct sta_info *sta, void *ctx);
175252726Srpaulo#endif /* CONFIG_WPS */
176214501Srpauloint ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
177214501Srpaulo		     int old_vlanid);
178214501Srpaulovoid ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
179214501Srpaulovoid ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
180214501Srpauloint ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta);
181214501Srpaulovoid ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
182214501Srpaulo		       const u8 *addr, u16 reason);
183214501Srpaulo
184252726Srpaulovoid ap_sta_set_authorized(struct hostapd_data *hapd,
185252726Srpaulo			   struct sta_info *sta, int authorized);
186252726Srpaulostatic inline int ap_sta_is_authorized(struct sta_info *sta)
187252726Srpaulo{
188252726Srpaulo	return sta->flags & WLAN_STA_AUTHORIZED;
189252726Srpaulo}
190252726Srpaulo
191252726Srpaulovoid ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta);
192252726Srpaulovoid ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta);
193252726Srpaulo
194214501Srpaulo#endif /* STA_INFO_H */
195