Remove experimental non-AP STA code from hostapd
[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         Boolean PtkGroupInit; /* init request for PTK Group state machine */
75
76         u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
77         size_t last_rx_eapol_key_len;
78
79         unsigned int changed:1;
80         unsigned int in_step_loop:1;
81         unsigned int pending_deinit:1;
82         unsigned int started:1;
83         unsigned int mgmt_frame_prot:1;
84 #ifdef CONFIG_IEEE80211R
85         unsigned int ft_completed:1;
86         unsigned int pmk_r1_name_valid:1;
87 #endif /* CONFIG_IEEE80211R */
88
89         u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
90         int req_replay_counter_used;
91
92         u8 *wpa_ie;
93         size_t wpa_ie_len;
94
95         enum {
96                 WPA_VERSION_NO_WPA = 0 /* WPA not used */,
97                 WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
98                 WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
99         } wpa;
100         int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
101         int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
102         struct rsn_pmksa_cache_entry *pmksa;
103
104         u32 dot11RSNAStatsTKIPLocalMICFailures;
105         u32 dot11RSNAStatsTKIPRemoteMICFailures;
106
107 #ifdef CONFIG_IEEE80211R
108         u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
109         size_t xxkey_len;
110         u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
111                                            * Request */
112         u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
113         size_t r0kh_id_len;
114 #endif /* CONFIG_IEEE80211R */
115 };
116
117
118 /* per group key state machine data */
119 struct wpa_group {
120         struct wpa_group *next;
121         int vlan_id;
122
123         Boolean GInit;
124         int GKeyDoneStations;
125         Boolean GTKReKey;
126         int GTK_len;
127         int GN, GM;
128         Boolean GTKAuthenticator;
129         u8 Counter[WPA_NONCE_LEN];
130
131         enum {
132                 WPA_GROUP_GTK_INIT = 0,
133                 WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE
134         } wpa_group_state;
135
136         u8 GMK[WPA_GMK_LEN];
137         u8 GTK[2][WPA_GTK_MAX_LEN];
138         u8 GNonce[WPA_NONCE_LEN];
139         Boolean changed;
140 #ifdef CONFIG_IEEE80211W
141         u8 IGTK[2][WPA_IGTK_LEN];
142         int GN_igtk, GM_igtk;
143 #endif /* CONFIG_IEEE80211W */
144 };
145
146
147 struct wpa_ft_pmk_cache;
148
149 /* per authenticator data */
150 struct wpa_authenticator {
151         struct wpa_group *group;
152
153         unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
154         u32 dot11RSNAAuthenticationSuiteSelected;
155         u32 dot11RSNAPairwiseCipherSelected;
156         u32 dot11RSNAGroupCipherSelected;
157         u8 dot11RSNAPMKIDUsed[PMKID_LEN];
158         u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
159         u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
160         u32 dot11RSNAGroupCipherRequested; /* FIX: update */
161         unsigned int dot11RSNATKIPCounterMeasuresInvoked;
162         unsigned int dot11RSNA4WayHandshakeFailures;
163
164         struct wpa_stsl_negotiation *stsl_negotiations;
165
166         struct wpa_auth_config conf;
167         struct wpa_auth_callbacks cb;
168
169         u8 *wpa_ie;
170         size_t wpa_ie_len;
171
172         u8 addr[ETH_ALEN];
173
174         struct rsn_pmksa_cache *pmksa;
175         struct wpa_ft_pmk_cache *ft_pmk_cache;
176 };
177
178
179 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
180                      const u8 *pmkid);
181 void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
182                      logger_level level, const char *txt);
183 void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
184                       logger_level level, const char *fmt, ...);
185 void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
186                       struct wpa_state_machine *sm, int key_info,
187                       const u8 *key_rsc, const u8 *nonce,
188                       const u8 *kde, size_t kde_len,
189                       int keyidx, int encr, int force_version);
190 int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
191                           int (*cb)(struct wpa_state_machine *sm, void *ctx),
192                           void *cb_ctx);
193 int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
194                            int (*cb)(struct wpa_authenticator *a, void *ctx),
195                            void *cb_ctx);
196
197 #ifdef CONFIG_PEERKEY
198 int wpa_stsl_remove(struct wpa_authenticator *wpa_auth,
199                     struct wpa_stsl_negotiation *neg);
200 void wpa_smk_error(struct wpa_authenticator *wpa_auth,
201                    struct wpa_state_machine *sm, struct wpa_eapol_key *key);
202 void wpa_smk_m1(struct wpa_authenticator *wpa_auth,
203                 struct wpa_state_machine *sm, struct wpa_eapol_key *key);
204 void wpa_smk_m3(struct wpa_authenticator *wpa_auth,
205                 struct wpa_state_machine *sm, struct wpa_eapol_key *key);
206 #endif /* CONFIG_PEERKEY */
207
208 #ifdef CONFIG_IEEE80211R
209 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
210 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
211                            struct wpa_ptk *ptk);
212 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
213 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
214 #endif /* CONFIG_IEEE80211R */
215
216 #endif /* WPA_AUTH_I_H */