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