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