xref: /freebsd/contrib/wpa/src/ap/wpa_auth_i.h (revision 5b9c547c072b84410b50897cc53710c75b2f6b74)
1e28a4053SRui Paulo /*
2e28a4053SRui Paulo  * hostapd - IEEE 802.11i-2004 / WPA Authenticator: Internal definitions
3*5b9c547cSRui Paulo  * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
7e28a4053SRui Paulo  */
8e28a4053SRui Paulo 
9e28a4053SRui Paulo #ifndef WPA_AUTH_I_H
10e28a4053SRui Paulo #define WPA_AUTH_I_H
11e28a4053SRui Paulo 
12e28a4053SRui Paulo /* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */
13e28a4053SRui Paulo #define RSNA_MAX_EAPOL_RETRIES 4
14e28a4053SRui Paulo 
15e28a4053SRui Paulo struct wpa_group;
16e28a4053SRui Paulo 
17e28a4053SRui Paulo struct wpa_stsl_negotiation {
18e28a4053SRui Paulo 	struct wpa_stsl_negotiation *next;
19e28a4053SRui Paulo 	u8 initiator[ETH_ALEN];
20e28a4053SRui Paulo 	u8 peer[ETH_ALEN];
21e28a4053SRui Paulo };
22e28a4053SRui Paulo 
23e28a4053SRui Paulo 
24e28a4053SRui Paulo struct wpa_state_machine {
25e28a4053SRui Paulo 	struct wpa_authenticator *wpa_auth;
26e28a4053SRui Paulo 	struct wpa_group *group;
27e28a4053SRui Paulo 
28e28a4053SRui Paulo 	u8 addr[ETH_ALEN];
29*5b9c547cSRui Paulo 	u8 p2p_dev_addr[ETH_ALEN];
30e28a4053SRui Paulo 
31e28a4053SRui Paulo 	enum {
32e28a4053SRui Paulo 		WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
33e28a4053SRui Paulo 		WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
34e28a4053SRui Paulo 		WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
35e28a4053SRui Paulo 		WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
36e28a4053SRui Paulo 		WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
37e28a4053SRui Paulo 	} wpa_ptk_state;
38e28a4053SRui Paulo 
39e28a4053SRui Paulo 	enum {
40e28a4053SRui Paulo 		WPA_PTK_GROUP_IDLE = 0,
41e28a4053SRui Paulo 		WPA_PTK_GROUP_REKEYNEGOTIATING,
42e28a4053SRui Paulo 		WPA_PTK_GROUP_REKEYESTABLISHED,
43e28a4053SRui Paulo 		WPA_PTK_GROUP_KEYERROR
44e28a4053SRui Paulo 	} wpa_ptk_group_state;
45e28a4053SRui Paulo 
46e28a4053SRui Paulo 	Boolean Init;
47e28a4053SRui Paulo 	Boolean DeauthenticationRequest;
48e28a4053SRui Paulo 	Boolean AuthenticationRequest;
49e28a4053SRui Paulo 	Boolean ReAuthenticationRequest;
50e28a4053SRui Paulo 	Boolean Disconnect;
51e28a4053SRui Paulo 	int TimeoutCtr;
52e28a4053SRui Paulo 	int GTimeoutCtr;
53e28a4053SRui Paulo 	Boolean TimeoutEvt;
54e28a4053SRui Paulo 	Boolean EAPOLKeyReceived;
55e28a4053SRui Paulo 	Boolean EAPOLKeyPairwise;
56e28a4053SRui Paulo 	Boolean EAPOLKeyRequest;
57e28a4053SRui Paulo 	Boolean MICVerified;
58e28a4053SRui Paulo 	Boolean GUpdateStationKeys;
59e28a4053SRui Paulo 	u8 ANonce[WPA_NONCE_LEN];
60e28a4053SRui Paulo 	u8 SNonce[WPA_NONCE_LEN];
61*5b9c547cSRui Paulo 	u8 alt_SNonce[WPA_NONCE_LEN];
62*5b9c547cSRui Paulo 	u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN];
63e28a4053SRui Paulo 	u8 PMK[PMK_LEN];
64e28a4053SRui Paulo 	struct wpa_ptk PTK;
65e28a4053SRui Paulo 	Boolean PTK_valid;
66e28a4053SRui Paulo 	Boolean pairwise_set;
67e28a4053SRui Paulo 	int keycount;
68e28a4053SRui Paulo 	Boolean Pair;
69f05cddf9SRui Paulo 	struct wpa_key_replay_counter {
70e28a4053SRui Paulo 		u8 counter[WPA_REPLAY_COUNTER_LEN];
71e28a4053SRui Paulo 		Boolean valid;
72f05cddf9SRui Paulo 	} key_replay[RSNA_MAX_EAPOL_RETRIES],
73f05cddf9SRui Paulo 		prev_key_replay[RSNA_MAX_EAPOL_RETRIES];
74e28a4053SRui Paulo 	Boolean PInitAKeys; /* WPA only, not in IEEE 802.11i */
75e28a4053SRui Paulo 	Boolean PTKRequest; /* not in IEEE 802.11i state machine */
76e28a4053SRui Paulo 	Boolean has_GTK;
77e28a4053SRui Paulo 	Boolean PtkGroupInit; /* init request for PTK Group state machine */
78e28a4053SRui Paulo 
79e28a4053SRui Paulo 	u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
80e28a4053SRui Paulo 	size_t last_rx_eapol_key_len;
81e28a4053SRui Paulo 
82e28a4053SRui Paulo 	unsigned int changed:1;
83e28a4053SRui Paulo 	unsigned int in_step_loop:1;
84e28a4053SRui Paulo 	unsigned int pending_deinit:1;
85e28a4053SRui Paulo 	unsigned int started:1;
86e28a4053SRui Paulo 	unsigned int mgmt_frame_prot:1;
87f05cddf9SRui Paulo 	unsigned int rx_eapol_key_secure:1;
88f05cddf9SRui Paulo 	unsigned int update_snonce:1;
89*5b9c547cSRui Paulo 	unsigned int alt_snonce_valid:1;
90e28a4053SRui Paulo #ifdef CONFIG_IEEE80211R
91e28a4053SRui Paulo 	unsigned int ft_completed:1;
92e28a4053SRui Paulo 	unsigned int pmk_r1_name_valid:1;
93e28a4053SRui Paulo #endif /* CONFIG_IEEE80211R */
94f05cddf9SRui Paulo 	unsigned int is_wnmsleep:1;
95e28a4053SRui Paulo 
96e28a4053SRui Paulo 	u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
97e28a4053SRui Paulo 	int req_replay_counter_used;
98e28a4053SRui Paulo 
99e28a4053SRui Paulo 	u8 *wpa_ie;
100e28a4053SRui Paulo 	size_t wpa_ie_len;
101e28a4053SRui Paulo 
102e28a4053SRui Paulo 	enum {
103e28a4053SRui Paulo 		WPA_VERSION_NO_WPA = 0 /* WPA not used */,
104e28a4053SRui Paulo 		WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
105e28a4053SRui Paulo 		WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
106e28a4053SRui Paulo 	} wpa;
107e28a4053SRui Paulo 	int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
108e28a4053SRui Paulo 	int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
109e28a4053SRui Paulo 	struct rsn_pmksa_cache_entry *pmksa;
110e28a4053SRui Paulo 
111e28a4053SRui Paulo 	u32 dot11RSNAStatsTKIPLocalMICFailures;
112e28a4053SRui Paulo 	u32 dot11RSNAStatsTKIPRemoteMICFailures;
113e28a4053SRui Paulo 
114e28a4053SRui Paulo #ifdef CONFIG_IEEE80211R
115e28a4053SRui Paulo 	u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
116e28a4053SRui Paulo 	size_t xxkey_len;
117e28a4053SRui Paulo 	u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
118e28a4053SRui Paulo 					   * Request */
119e28a4053SRui Paulo 	u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
120e28a4053SRui Paulo 	size_t r0kh_id_len;
121e28a4053SRui Paulo 	u8 sup_pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name from EAPOL-Key
122e28a4053SRui Paulo 					       * message 2/4 */
123e28a4053SRui Paulo 	u8 *assoc_resp_ftie;
124*5b9c547cSRui Paulo 
125*5b9c547cSRui Paulo 	void (*ft_pending_cb)(void *ctx, const u8 *dst, const u8 *bssid,
126*5b9c547cSRui Paulo 			      u16 auth_transaction, u16 status,
127*5b9c547cSRui Paulo 			      const u8 *ies, size_t ies_len);
128*5b9c547cSRui Paulo 	void *ft_pending_cb_ctx;
129*5b9c547cSRui Paulo 	struct wpabuf *ft_pending_req_ies;
130*5b9c547cSRui Paulo 	u8 ft_pending_pull_nonce[FT_R0KH_R1KH_PULL_NONCE_LEN];
131*5b9c547cSRui Paulo 	u8 ft_pending_auth_transaction;
132*5b9c547cSRui Paulo 	u8 ft_pending_current_ap[ETH_ALEN];
133e28a4053SRui Paulo #endif /* CONFIG_IEEE80211R */
134f05cddf9SRui Paulo 
135f05cddf9SRui Paulo 	int pending_1_of_4_timeout;
136*5b9c547cSRui Paulo 
137*5b9c547cSRui Paulo #ifdef CONFIG_P2P
138*5b9c547cSRui Paulo 	u8 ip_addr[4];
139*5b9c547cSRui Paulo #endif /* CONFIG_P2P */
140e28a4053SRui Paulo };
141e28a4053SRui Paulo 
142e28a4053SRui Paulo 
143e28a4053SRui Paulo /* per group key state machine data */
144e28a4053SRui Paulo struct wpa_group {
145e28a4053SRui Paulo 	struct wpa_group *next;
146e28a4053SRui Paulo 	int vlan_id;
147e28a4053SRui Paulo 
148e28a4053SRui Paulo 	Boolean GInit;
149e28a4053SRui Paulo 	int GKeyDoneStations;
150e28a4053SRui Paulo 	Boolean GTKReKey;
151e28a4053SRui Paulo 	int GTK_len;
152e28a4053SRui Paulo 	int GN, GM;
153e28a4053SRui Paulo 	Boolean GTKAuthenticator;
154e28a4053SRui Paulo 	u8 Counter[WPA_NONCE_LEN];
155e28a4053SRui Paulo 
156e28a4053SRui Paulo 	enum {
157e28a4053SRui Paulo 		WPA_GROUP_GTK_INIT = 0,
158*5b9c547cSRui Paulo 		WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE,
159*5b9c547cSRui Paulo 		WPA_GROUP_FATAL_FAILURE
160e28a4053SRui Paulo 	} wpa_group_state;
161e28a4053SRui Paulo 
162e28a4053SRui Paulo 	u8 GMK[WPA_GMK_LEN];
163e28a4053SRui Paulo 	u8 GTK[2][WPA_GTK_MAX_LEN];
164e28a4053SRui Paulo 	u8 GNonce[WPA_NONCE_LEN];
165e28a4053SRui Paulo 	Boolean changed;
166f05cddf9SRui Paulo 	Boolean first_sta_seen;
167f05cddf9SRui Paulo 	Boolean reject_4way_hs_for_entropy;
168e28a4053SRui Paulo #ifdef CONFIG_IEEE80211W
169*5b9c547cSRui Paulo 	u8 IGTK[2][WPA_IGTK_MAX_LEN];
170e28a4053SRui Paulo 	int GN_igtk, GM_igtk;
171e28a4053SRui Paulo #endif /* CONFIG_IEEE80211W */
172e28a4053SRui Paulo };
173e28a4053SRui Paulo 
174e28a4053SRui Paulo 
175e28a4053SRui Paulo struct wpa_ft_pmk_cache;
176e28a4053SRui Paulo 
177e28a4053SRui Paulo /* per authenticator data */
178e28a4053SRui Paulo struct wpa_authenticator {
179e28a4053SRui Paulo 	struct wpa_group *group;
180e28a4053SRui Paulo 
181e28a4053SRui Paulo 	unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
182e28a4053SRui Paulo 	u32 dot11RSNAAuthenticationSuiteSelected;
183e28a4053SRui Paulo 	u32 dot11RSNAPairwiseCipherSelected;
184e28a4053SRui Paulo 	u32 dot11RSNAGroupCipherSelected;
185e28a4053SRui Paulo 	u8 dot11RSNAPMKIDUsed[PMKID_LEN];
186e28a4053SRui Paulo 	u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
187e28a4053SRui Paulo 	u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
188e28a4053SRui Paulo 	u32 dot11RSNAGroupCipherRequested; /* FIX: update */
189e28a4053SRui Paulo 	unsigned int dot11RSNATKIPCounterMeasuresInvoked;
190e28a4053SRui Paulo 	unsigned int dot11RSNA4WayHandshakeFailures;
191e28a4053SRui Paulo 
192e28a4053SRui Paulo 	struct wpa_stsl_negotiation *stsl_negotiations;
193e28a4053SRui Paulo 
194e28a4053SRui Paulo 	struct wpa_auth_config conf;
195e28a4053SRui Paulo 	struct wpa_auth_callbacks cb;
196e28a4053SRui Paulo 
197e28a4053SRui Paulo 	u8 *wpa_ie;
198e28a4053SRui Paulo 	size_t wpa_ie_len;
199e28a4053SRui Paulo 
200e28a4053SRui Paulo 	u8 addr[ETH_ALEN];
201e28a4053SRui Paulo 
202e28a4053SRui Paulo 	struct rsn_pmksa_cache *pmksa;
203e28a4053SRui Paulo 	struct wpa_ft_pmk_cache *ft_pmk_cache;
204*5b9c547cSRui Paulo 
205*5b9c547cSRui Paulo #ifdef CONFIG_P2P
206*5b9c547cSRui Paulo 	struct bitfield *ip_pool;
207*5b9c547cSRui Paulo #endif /* CONFIG_P2P */
208e28a4053SRui Paulo };
209e28a4053SRui Paulo 
210e28a4053SRui Paulo 
211e28a4053SRui Paulo int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
212e28a4053SRui Paulo 		     const u8 *pmkid);
213e28a4053SRui Paulo void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
214e28a4053SRui Paulo 		     logger_level level, const char *txt);
215e28a4053SRui Paulo void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
216e28a4053SRui Paulo 		      logger_level level, const char *fmt, ...);
217e28a4053SRui Paulo void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
218e28a4053SRui Paulo 		      struct wpa_state_machine *sm, int key_info,
219e28a4053SRui Paulo 		      const u8 *key_rsc, const u8 *nonce,
220e28a4053SRui Paulo 		      const u8 *kde, size_t kde_len,
221e28a4053SRui Paulo 		      int keyidx, int encr, int force_version);
222e28a4053SRui Paulo int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
223e28a4053SRui Paulo 			  int (*cb)(struct wpa_state_machine *sm, void *ctx),
224e28a4053SRui Paulo 			  void *cb_ctx);
225e28a4053SRui Paulo int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
226e28a4053SRui Paulo 			   int (*cb)(struct wpa_authenticator *a, void *ctx),
227e28a4053SRui Paulo 			   void *cb_ctx);
228e28a4053SRui Paulo 
229e28a4053SRui Paulo #ifdef CONFIG_PEERKEY
230e28a4053SRui Paulo int wpa_stsl_remove(struct wpa_authenticator *wpa_auth,
231e28a4053SRui Paulo 		    struct wpa_stsl_negotiation *neg);
232e28a4053SRui Paulo void wpa_smk_error(struct wpa_authenticator *wpa_auth,
233*5b9c547cSRui Paulo 		   struct wpa_state_machine *sm,
234*5b9c547cSRui Paulo 		   const u8 *key_data, size_t key_data_len);
235e28a4053SRui Paulo void wpa_smk_m1(struct wpa_authenticator *wpa_auth,
236*5b9c547cSRui Paulo 		struct wpa_state_machine *sm, struct wpa_eapol_key *key,
237*5b9c547cSRui Paulo 		const u8 *key_data, size_t key_data_len);
238e28a4053SRui Paulo void wpa_smk_m3(struct wpa_authenticator *wpa_auth,
239*5b9c547cSRui Paulo 		struct wpa_state_machine *sm, struct wpa_eapol_key *key,
240*5b9c547cSRui Paulo 		const u8 *key_data, size_t key_data_len);
241e28a4053SRui Paulo #endif /* CONFIG_PEERKEY */
242e28a4053SRui Paulo 
243e28a4053SRui Paulo #ifdef CONFIG_IEEE80211R
244e28a4053SRui Paulo int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
245e28a4053SRui Paulo int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
246e28a4053SRui Paulo 		   size_t r0kh_id_len,
247e28a4053SRui Paulo 		   const u8 *anonce, const u8 *snonce,
248e28a4053SRui Paulo 		   u8 *buf, size_t len, const u8 *subelem,
249e28a4053SRui Paulo 		   size_t subelem_len);
250e28a4053SRui Paulo int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
251*5b9c547cSRui Paulo 			   struct wpa_ptk *ptk);
252e28a4053SRui Paulo struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
253e28a4053SRui Paulo void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
254e28a4053SRui Paulo void wpa_ft_install_ptk(struct wpa_state_machine *sm);
255e28a4053SRui Paulo #endif /* CONFIG_IEEE80211R */
256e28a4053SRui Paulo 
257e28a4053SRui Paulo #endif /* WPA_AUTH_I_H */
258