• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hostapd - IEEE 802.11i-2004 / WPA Authenticator: Internal definitions
3  * Copyright (c) 2004-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 WPA_AUTH_I_H
10 #define WPA_AUTH_I_H
11 
12 #include "utils/list.h"
13 
14 /* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */
15 #define RSNA_MAX_EAPOL_RETRIES 4
16 
17 struct wpa_group;
18 
19 struct wpa_state_machine {
20 	struct wpa_authenticator *wpa_auth;
21 	struct wpa_group *group;
22 
23 	u8 addr[ETH_ALEN];
24 	u8 p2p_dev_addr[ETH_ALEN];
25 	u16 auth_alg;
26 
27 	enum {
28 		WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
29 		WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
30 		WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
31 		WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
32 		WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
33 	} wpa_ptk_state;
34 
35 	enum {
36 		WPA_PTK_GROUP_IDLE = 0,
37 		WPA_PTK_GROUP_REKEYNEGOTIATING,
38 		WPA_PTK_GROUP_REKEYESTABLISHED,
39 		WPA_PTK_GROUP_KEYERROR
40 	} wpa_ptk_group_state;
41 
42 	bool Init;
43 	bool DeauthenticationRequest;
44 	bool AuthenticationRequest;
45 	bool ReAuthenticationRequest;
46 	bool Disconnect;
47 	u16 disconnect_reason; /* specific reason code to use with Disconnect */
48 	u32 TimeoutCtr;
49 	u32 GTimeoutCtr;
50 	bool TimeoutEvt;
51 	bool EAPOLKeyReceived;
52 	bool EAPOLKeyPairwise;
53 	bool EAPOLKeyRequest;
54 	bool MICVerified;
55 	bool GUpdateStationKeys;
56 	u8 ANonce[WPA_NONCE_LEN];
57 	u8 SNonce[WPA_NONCE_LEN];
58 	u8 alt_SNonce[WPA_NONCE_LEN];
59 	u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN];
60 	u8 PMK[PMK_LEN_MAX];
61 	unsigned int pmk_len;
62 	u8 pmkid[PMKID_LEN]; /* valid if pmkid_set == 1 */
63 	struct wpa_ptk PTK;
64 	u8 keyidx_active;
65 	bool use_ext_key_id;
66 	bool PTK_valid;
67 	bool pairwise_set;
68 	bool tk_already_set;
69 	int keycount;
70 	bool Pair;
71 	struct wpa_key_replay_counter {
72 		u8 counter[WPA_REPLAY_COUNTER_LEN];
73 		bool valid;
74 	} key_replay[RSNA_MAX_EAPOL_RETRIES],
75 		prev_key_replay[RSNA_MAX_EAPOL_RETRIES];
76 	bool PInitAKeys; /* WPA only, not in IEEE 802.11i */
77 	bool PTKRequest; /* not in IEEE 802.11i state machine */
78 	bool has_GTK;
79 	bool PtkGroupInit; /* init request for PTK Group state machine */
80 
81 	u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
82 	size_t last_rx_eapol_key_len;
83 
84 	unsigned int changed:1;
85 	unsigned int in_step_loop:1;
86 	unsigned int pending_deinit:1;
87 	unsigned int started:1;
88 	unsigned int mgmt_frame_prot:1;
89 	unsigned int rx_eapol_key_secure:1;
90 	unsigned int update_snonce:1;
91 	unsigned int alt_snonce_valid:1;
92 	unsigned int waiting_radius_psk:1;
93 #ifdef CONFIG_IEEE80211R_AP
94 	unsigned int ft_completed:1;
95 	unsigned int pmk_r1_name_valid:1;
96 #endif /* CONFIG_IEEE80211R_AP */
97 	unsigned int is_wnmsleep:1;
98 	unsigned int pmkid_set:1;
99 
100 	unsigned int ptkstart_without_success;
101 
102 #ifdef CONFIG_OCV
103 	int ocv_enabled;
104 #endif /* CONFIG_OCV */
105 
106 	u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
107 	int req_replay_counter_used;
108 
109 	u8 *wpa_ie;
110 	size_t wpa_ie_len;
111 	u8 *rsnxe;
112 	size_t rsnxe_len;
113 
114 	enum {
115 		WPA_VERSION_NO_WPA = 0 /* WPA not used */,
116 		WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
117 		WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
118 	} wpa;
119 	int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
120 	int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
121 	struct rsn_pmksa_cache_entry *pmksa;
122 
123 	u32 dot11RSNAStatsTKIPLocalMICFailures;
124 	u32 dot11RSNAStatsTKIPRemoteMICFailures;
125 
126 #ifdef CONFIG_IEEE80211R_AP
127 	u8 xxkey[PMK_LEN_MAX]; /* PSK or the second 256 bits of MSK, or the
128 				* first 384 bits of MSK */
129 	size_t xxkey_len;
130 	u8 pmk_r1[PMK_LEN_MAX];
131 	unsigned int pmk_r1_len;
132 	u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
133 					   * Request */
134 	u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
135 	size_t r0kh_id_len;
136 	u8 sup_pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name from EAPOL-Key
137 					       * message 2/4 */
138 	u8 *assoc_resp_ftie;
139 
140 	void (*ft_pending_cb)(void *ctx, const u8 *dst, const u8 *bssid,
141 			      u16 auth_transaction, u16 status,
142 			      const u8 *ies, size_t ies_len);
143 	void *ft_pending_cb_ctx;
144 	struct wpabuf *ft_pending_req_ies;
145 	u8 ft_pending_pull_nonce[FT_RRB_NONCE_LEN];
146 	u8 ft_pending_auth_transaction;
147 	u8 ft_pending_current_ap[ETH_ALEN];
148 	int ft_pending_pull_left_retries;
149 #endif /* CONFIG_IEEE80211R_AP */
150 
151 	int pending_1_of_4_timeout;
152 
153 #ifdef CONFIG_P2P
154 	u8 ip_addr[4];
155 #endif /* CONFIG_P2P */
156 
157 #ifdef CONFIG_FILS
158 	u8 fils_key_auth_sta[FILS_MAX_KEY_AUTH_LEN];
159 	u8 fils_key_auth_ap[FILS_MAX_KEY_AUTH_LEN];
160 	size_t fils_key_auth_len;
161 	unsigned int fils_completed:1;
162 #endif /* CONFIG_FILS */
163 
164 #ifdef CONFIG_DPP2
165 	struct wpabuf *dpp_z;
166 #endif /* CONFIG_DPP2 */
167 
168 #ifdef CONFIG_TESTING_OPTIONS
169 	void (*eapol_status_cb)(void *ctx1, void *ctx2);
170 	void *eapol_status_cb_ctx1;
171 	void *eapol_status_cb_ctx2;
172 #endif /* CONFIG_TESTING_OPTIONS */
173 };
174 
175 
176 /* per group key state machine data */
177 struct wpa_group {
178 	struct wpa_group *next;
179 	int vlan_id;
180 
181 	bool GInit;
182 	int GKeyDoneStations;
183 	bool GTKReKey;
184 	int GTK_len;
185 	int GN, GM;
186 	bool GTKAuthenticator;
187 	u8 Counter[WPA_NONCE_LEN];
188 
189 	enum {
190 		WPA_GROUP_GTK_INIT = 0,
191 		WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE,
192 		WPA_GROUP_FATAL_FAILURE
193 	} wpa_group_state;
194 
195 	u8 GMK[WPA_GMK_LEN];
196 	u8 GTK[2][WPA_GTK_MAX_LEN];
197 	u8 GNonce[WPA_NONCE_LEN];
198 	bool changed;
199 	bool first_sta_seen;
200 	bool reject_4way_hs_for_entropy;
201 	u8 IGTK[2][WPA_IGTK_MAX_LEN];
202 	u8 BIGTK[2][WPA_IGTK_MAX_LEN];
203 	int GN_igtk, GM_igtk;
204 	int GN_bigtk, GM_bigtk;
205 	/* Number of references except those in struct wpa_group->next */
206 	unsigned int references;
207 	unsigned int num_setup_iface;
208 };
209 
210 
211 struct wpa_ft_pmk_cache;
212 
213 /* per authenticator data */
214 struct wpa_authenticator {
215 	struct wpa_group *group;
216 
217 	unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
218 	u32 dot11RSNAAuthenticationSuiteSelected;
219 	u32 dot11RSNAPairwiseCipherSelected;
220 	u32 dot11RSNAGroupCipherSelected;
221 	u8 dot11RSNAPMKIDUsed[PMKID_LEN];
222 	u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
223 	u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
224 	u32 dot11RSNAGroupCipherRequested; /* FIX: update */
225 	unsigned int dot11RSNATKIPCounterMeasuresInvoked;
226 	unsigned int dot11RSNA4WayHandshakeFailures;
227 
228 	struct wpa_auth_config conf;
229 	const struct wpa_auth_callbacks *cb;
230 	void *cb_ctx;
231 
232 	u8 *wpa_ie;
233 	size_t wpa_ie_len;
234 
235 	u8 addr[ETH_ALEN];
236 
237 	struct rsn_pmksa_cache *pmksa;
238 	struct wpa_ft_pmk_cache *ft_pmk_cache;
239 
240 #ifdef CONFIG_P2P
241 	struct bitfield *ip_pool;
242 #endif /* CONFIG_P2P */
243 };
244 
245 
246 #ifdef CONFIG_IEEE80211R_AP
247 
248 #define FT_REMOTE_SEQ_BACKLOG 16
249 struct ft_remote_seq_rx {
250 	u32 dom;
251 	struct os_reltime time_offset; /* local time - offset = remote time */
252 
253 	/* accepted sequence numbers: (offset ... offset + 0x40000000]
254 	 *   (except those in last)
255 	 * dropped sequence numbers: (offset - 0x40000000 ... offset]
256 	 * all others trigger SEQ_REQ message (except first message)
257 	 */
258 	u32 last[FT_REMOTE_SEQ_BACKLOG];
259 	unsigned int num_last;
260 	u32 offsetidx;
261 
262 	struct dl_list queue; /* send nonces + rrb msgs awaiting seq resp */
263 };
264 
265 struct ft_remote_seq_tx {
266 	u32 dom; /* non zero if initialized */
267 	u32 seq;
268 };
269 
270 struct ft_remote_seq {
271 	struct ft_remote_seq_rx rx;
272 	struct ft_remote_seq_tx tx;
273 };
274 
275 #endif /* CONFIG_IEEE80211R_AP */
276 
277 
278 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
279 		     const u8 *pmkid);
280 int wpa_write_rsnxe(struct wpa_auth_config *conf, u8 *buf, size_t len);
281 void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
282 		     logger_level level, const char *txt);
283 void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
284 		      logger_level level, const char *fmt, ...)
285 	PRINTF_FORMAT(4, 5);
286 void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
287 		      struct wpa_state_machine *sm, int key_info,
288 		      const u8 *key_rsc, const u8 *nonce,
289 		      const u8 *kde, size_t kde_len,
290 		      int keyidx, int encr, int force_version);
291 int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
292 			  int (*cb)(struct wpa_state_machine *sm, void *ctx),
293 			  void *cb_ctx);
294 int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
295 			   int (*cb)(struct wpa_authenticator *a, void *ctx),
296 			   void *cb_ctx);
297 
298 #ifdef CONFIG_IEEE80211R_AP
299 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
300 int wpa_write_ftie(struct wpa_auth_config *conf, int use_sha384,
301 		   const u8 *r0kh_id, size_t r0kh_id_len,
302 		   const u8 *anonce, const u8 *snonce,
303 		   u8 *buf, size_t len, const u8 *subelem,
304 		   size_t subelem_len, int rsnxe_used);
305 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, struct wpa_ptk *ptk);
306 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
307 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
308 void wpa_ft_install_ptk(struct wpa_state_machine *sm, int retry);
309 int wpa_ft_store_pmk_fils(struct wpa_state_machine *sm, const u8 *pmk_r0,
310 			  const u8 *pmk_r0_name);
311 #endif /* CONFIG_IEEE80211R_AP */
312 
313 #endif /* WPA_AUTH_I_H */
314