Added support for opportunistic key caching (OKC)
[libeap.git] / hostapd / wpa_auth_i.h
1 /*
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 struct wpa_group;
19
20 struct wpa_stsl_negotiation {
21         struct wpa_stsl_negotiation *next;
22         u8 initiator[ETH_ALEN];
23         u8 peer[ETH_ALEN];
24 };
25
26
27 struct wpa_state_machine {
28         struct wpa_authenticator *wpa_auth;
29         struct wpa_group *group;
30
31         u8 addr[ETH_ALEN];
32
33         enum {
34                 WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
35                 WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
36                 WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
37                 WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
38                 WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
39         } wpa_ptk_state;
40
41         enum {
42                 WPA_PTK_GROUP_IDLE = 0,
43                 WPA_PTK_GROUP_REKEYNEGOTIATING,
44                 WPA_PTK_GROUP_REKEYESTABLISHED,
45                 WPA_PTK_GROUP_KEYERROR
46         } wpa_ptk_group_state;
47
48         Boolean Init;
49         Boolean DeauthenticationRequest;
50         Boolean AuthenticationRequest;
51         Boolean ReAuthenticationRequest;
52         Boolean Disconnect;
53         int TimeoutCtr;
54         int GTimeoutCtr;
55         Boolean TimeoutEvt;
56         Boolean EAPOLKeyReceived;
57         Boolean EAPOLKeyPairwise;
58         Boolean EAPOLKeyRequest;
59         Boolean MICVerified;
60         Boolean GUpdateStationKeys;
61         u8 ANonce[WPA_NONCE_LEN];
62         u8 SNonce[WPA_NONCE_LEN];
63         u8 PMK[PMK_LEN];
64         struct wpa_ptk PTK;
65         Boolean PTK_valid;
66         Boolean pairwise_set;
67         int keycount;
68         Boolean Pair;
69         u8 key_replay_counter[WPA_REPLAY_COUNTER_LEN];
70         Boolean key_replay_counter_valid;
71         Boolean PInitAKeys; /* WPA only, not in IEEE 802.11i */
72         Boolean PTKRequest; /* not in IEEE 802.11i state machine */
73         Boolean has_GTK;
74
75         u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
76         size_t last_rx_eapol_key_len;
77
78         unsigned int changed:1;
79         unsigned int in_step_loop:1;
80         unsigned int pending_deinit:1;
81         unsigned int started:1;
82         unsigned int mgmt_frame_prot:1;
83 #ifdef CONFIG_IEEE80211R
84         unsigned int ft_completed:1;
85         unsigned int pmk_r1_name_valid:1;
86 #endif /* CONFIG_IEEE80211R */
87
88         u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
89         int req_replay_counter_used;
90
91         u8 *wpa_ie;
92         size_t wpa_ie_len;
93
94         enum {
95                 WPA_VERSION_NO_WPA = 0 /* WPA not used */,
96                 WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
97                 WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
98         } wpa;
99         int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
100         int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
101         struct rsn_pmksa_cache_entry *pmksa;
102
103         u32 dot11RSNAStatsTKIPLocalMICFailures;
104         u32 dot11RSNAStatsTKIPRemoteMICFailures;
105
106 #ifdef CONFIG_IEEE80211R
107         u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
108         size_t xxkey_len;
109         u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
110                                            * Request */
111         u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
112         size_t r0kh_id_len;
113 #endif /* CONFIG_IEEE80211R */
114 };
115
116
117 /* per group key state machine data */
118 struct wpa_group {
119         struct wpa_group *next;
120         int vlan_id;
121
122         Boolean GInit;
123         int GKeyDoneStations;
124         Boolean GTKReKey;
125         int GTK_len;
126         int GN, GM;
127         Boolean GTKAuthenticator;
128         u8 Counter[WPA_NONCE_LEN];
129
130         enum {
131                 WPA_GROUP_GTK_INIT = 0,
132                 WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE
133         } wpa_group_state;
134
135         u8 GMK[WPA_GMK_LEN];
136         u8 GTK[2][WPA_GTK_MAX_LEN];
137         u8 GNonce[WPA_NONCE_LEN];
138         Boolean changed;
139 #ifdef CONFIG_IEEE80211W
140         u8 IGTK[2][WPA_IGTK_LEN];
141         int GN_igtk, GM_igtk;
142 #endif /* CONFIG_IEEE80211W */
143 };
144
145
146 struct wpa_ft_pmk_cache;
147
148 /* per authenticator data */
149 struct wpa_authenticator {
150         struct wpa_group *group;
151
152         unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
153         u32 dot11RSNAAuthenticationSuiteSelected;
154         u32 dot11RSNAPairwiseCipherSelected;
155         u32 dot11RSNAGroupCipherSelected;
156         u8 dot11RSNAPMKIDUsed[PMKID_LEN];
157         u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
158         u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
159         u32 dot11RSNAGroupCipherRequested; /* FIX: update */
160         unsigned int dot11RSNATKIPCounterMeasuresInvoked;
161         unsigned int dot11RSNA4WayHandshakeFailures;
162
163         struct wpa_stsl_negotiation *stsl_negotiations;
164
165         struct wpa_auth_config conf;
166         struct wpa_auth_callbacks cb;
167
168         u8 *wpa_ie;
169         size_t wpa_ie_len;
170
171         u8 addr[ETH_ALEN];
172
173         struct rsn_pmksa_cache *pmksa;
174         struct wpa_ft_pmk_cache *ft_pmk_cache;
175 };
176
177
178 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
179                      const u8 *pmkid);
180 void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
181                      logger_level level, const char *txt);
182 void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
183                       logger_level level, const char *fmt, ...);
184 void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
185                       struct wpa_state_machine *sm, int key_info,
186                       const u8 *key_rsc, const u8 *nonce,
187                       const u8 *kde, size_t kde_len,
188                       int keyidx, int encr, int force_version);
189 int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
190                           int (*cb)(struct wpa_state_machine *sm, void *ctx),
191                           void *cb_ctx);
192 int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
193                            int (*cb)(struct wpa_authenticator *a, void *ctx),
194                            void *cb_ctx);
195
196 #ifdef CONFIG_PEERKEY
197 int wpa_stsl_remove(struct wpa_authenticator *wpa_auth,
198                     struct wpa_stsl_negotiation *neg);
199 void wpa_smk_error(struct wpa_authenticator *wpa_auth,
200                    struct wpa_state_machine *sm, struct wpa_eapol_key *key);
201 void wpa_smk_m1(struct wpa_authenticator *wpa_auth,
202                 struct wpa_state_machine *sm, struct wpa_eapol_key *key);
203 void wpa_smk_m3(struct wpa_authenticator *wpa_auth,
204                 struct wpa_state_machine *sm, struct wpa_eapol_key *key);
205 #endif /* CONFIG_PEERKEY */
206
207 #ifdef CONFIG_IEEE80211R
208 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
209 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
210                            struct wpa_ptk *ptk);
211 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
212 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
213 #endif /* CONFIG_IEEE80211R */
214
215 #endif /* WPA_AUTH_I_H */