• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hostapd - IEEE 802.11i-2004 / WPA Authenticator: Internal definitions
3  * Copyright (c) 2004-2007, 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 /* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */
13 #define RSNA_MAX_EAPOL_RETRIES 4
14 
15 struct wpa_group;
16 
17 struct wpa_stsl_negotiation {
18 	struct wpa_stsl_negotiation *next;
19 	u8 initiator[ETH_ALEN];
20 	u8 peer[ETH_ALEN];
21 };
22 
23 
24 struct wpa_state_machine {
25 	struct wpa_authenticator *wpa_auth;
26 	struct wpa_group *group;
27 
28 	u8 addr[ETH_ALEN];
29 	u8 p2p_dev_addr[ETH_ALEN];
30 
31 	enum {
32 		WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
33 		WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
34 		WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
35 		WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
36 		WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
37 	} wpa_ptk_state;
38 
39 	enum {
40 		WPA_PTK_GROUP_IDLE = 0,
41 		WPA_PTK_GROUP_REKEYNEGOTIATING,
42 		WPA_PTK_GROUP_REKEYESTABLISHED,
43 		WPA_PTK_GROUP_KEYERROR
44 	} wpa_ptk_group_state;
45 
46 	Boolean Init;
47 	Boolean DeauthenticationRequest;
48 	Boolean AuthenticationRequest;
49 	Boolean ReAuthenticationRequest;
50 	Boolean Disconnect;
51 	int TimeoutCtr;
52 	int GTimeoutCtr;
53 	Boolean TimeoutEvt;
54 	Boolean EAPOLKeyReceived;
55 	Boolean EAPOLKeyPairwise;
56 	Boolean EAPOLKeyRequest;
57 	Boolean MICVerified;
58 	Boolean GUpdateStationKeys;
59 	u8 ANonce[WPA_NONCE_LEN];
60 	u8 SNonce[WPA_NONCE_LEN];
61 	u8 PMK[PMK_LEN];
62 	struct wpa_ptk PTK;
63 	Boolean PTK_valid;
64 	Boolean pairwise_set;
65 	int keycount;
66 	Boolean Pair;
67 	struct wpa_key_replay_counter {
68 		u8 counter[WPA_REPLAY_COUNTER_LEN];
69 		Boolean valid;
70 	} key_replay[RSNA_MAX_EAPOL_RETRIES],
71 		prev_key_replay[RSNA_MAX_EAPOL_RETRIES];
72 	Boolean PInitAKeys; /* WPA only, not in IEEE 802.11i */
73 	Boolean PTKRequest; /* not in IEEE 802.11i state machine */
74 	Boolean has_GTK;
75 	Boolean PtkGroupInit; /* init request for PTK Group state machine */
76 
77 	u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
78 	size_t last_rx_eapol_key_len;
79 
80 	unsigned int changed:1;
81 	unsigned int in_step_loop:1;
82 	unsigned int pending_deinit:1;
83 	unsigned int started:1;
84 	unsigned int mgmt_frame_prot:1;
85 	unsigned int rx_eapol_key_secure:1;
86 	unsigned int update_snonce:1;
87 #ifdef CONFIG_IEEE80211R
88 	unsigned int ft_completed:1;
89 	unsigned int pmk_r1_name_valid:1;
90 #endif /* CONFIG_IEEE80211R */
91 	unsigned int is_wnmsleep:1;
92 
93 	u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
94 	int req_replay_counter_used;
95 
96 	u8 *wpa_ie;
97 	size_t wpa_ie_len;
98 
99 	enum {
100 		WPA_VERSION_NO_WPA = 0 /* WPA not used */,
101 		WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
102 		WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
103 	} wpa;
104 	int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
105 	int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
106 	struct rsn_pmksa_cache_entry *pmksa;
107 
108 	u32 dot11RSNAStatsTKIPLocalMICFailures;
109 	u32 dot11RSNAStatsTKIPRemoteMICFailures;
110 
111 #ifdef CONFIG_IEEE80211R
112 	u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
113 	size_t xxkey_len;
114 	u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
115 					   * Request */
116 	u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
117 	size_t r0kh_id_len;
118 	u8 sup_pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name from EAPOL-Key
119 					       * message 2/4 */
120 	u8 *assoc_resp_ftie;
121 
122 	void (*ft_pending_cb)(void *ctx, const u8 *dst, const u8 *bssid,
123 			      u16 auth_transaction, u16 status,
124 			      const u8 *ies, size_t ies_len);
125 	void *ft_pending_cb_ctx;
126 	struct wpabuf *ft_pending_req_ies;
127 	u8 ft_pending_pull_nonce[FT_R0KH_R1KH_PULL_NONCE_LEN];
128 	u8 ft_pending_auth_transaction;
129 	u8 ft_pending_current_ap[ETH_ALEN];
130 #endif /* CONFIG_IEEE80211R */
131 
132 	int pending_1_of_4_timeout;
133 
134 #ifdef CONFIG_P2P
135 	u8 ip_addr[4];
136 #endif /* CONFIG_P2P */
137 };
138 
139 
140 /* per group key state machine data */
141 struct wpa_group {
142 	struct wpa_group *next;
143 	int vlan_id;
144 
145 	Boolean GInit;
146 	int GKeyDoneStations;
147 	Boolean GTKReKey;
148 	int GTK_len;
149 	int GN, GM;
150 	Boolean GTKAuthenticator;
151 	u8 Counter[WPA_NONCE_LEN];
152 
153 	enum {
154 		WPA_GROUP_GTK_INIT = 0,
155 		WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE,
156 		WPA_GROUP_FATAL_FAILURE
157 	} wpa_group_state;
158 
159 	u8 GMK[WPA_GMK_LEN];
160 	u8 GTK[2][WPA_GTK_MAX_LEN];
161 	u8 GNonce[WPA_NONCE_LEN];
162 	Boolean changed;
163 	Boolean first_sta_seen;
164 	Boolean reject_4way_hs_for_entropy;
165 #ifdef CONFIG_IEEE80211W
166 	u8 IGTK[2][WPA_IGTK_MAX_LEN];
167 	int GN_igtk, GM_igtk;
168 #endif /* CONFIG_IEEE80211W */
169 };
170 
171 
172 struct wpa_ft_pmk_cache;
173 
174 /* per authenticator data */
175 struct wpa_authenticator {
176 	struct wpa_group *group;
177 
178 	unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
179 	u32 dot11RSNAAuthenticationSuiteSelected;
180 	u32 dot11RSNAPairwiseCipherSelected;
181 	u32 dot11RSNAGroupCipherSelected;
182 	u8 dot11RSNAPMKIDUsed[PMKID_LEN];
183 	u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
184 	u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
185 	u32 dot11RSNAGroupCipherRequested; /* FIX: update */
186 	unsigned int dot11RSNATKIPCounterMeasuresInvoked;
187 	unsigned int dot11RSNA4WayHandshakeFailures;
188 
189 	struct wpa_stsl_negotiation *stsl_negotiations;
190 
191 	struct wpa_auth_config conf;
192 	struct wpa_auth_callbacks cb;
193 
194 	u8 *wpa_ie;
195 	size_t wpa_ie_len;
196 
197 	u8 addr[ETH_ALEN];
198 
199 	struct rsn_pmksa_cache *pmksa;
200 	struct wpa_ft_pmk_cache *ft_pmk_cache;
201 
202 #ifdef CONFIG_P2P
203 	struct bitfield *ip_pool;
204 #endif /* CONFIG_P2P */
205 };
206 
207 
208 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
209 		     const u8 *pmkid);
210 void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
211 		     logger_level level, const char *txt);
212 void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
213 		      logger_level level, const char *fmt, ...);
214 void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
215 		      struct wpa_state_machine *sm, int key_info,
216 		      const u8 *key_rsc, const u8 *nonce,
217 		      const u8 *kde, size_t kde_len,
218 		      int keyidx, int encr, int force_version);
219 int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
220 			  int (*cb)(struct wpa_state_machine *sm, void *ctx),
221 			  void *cb_ctx);
222 int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
223 			   int (*cb)(struct wpa_authenticator *a, void *ctx),
224 			   void *cb_ctx);
225 
226 #ifdef CONFIG_PEERKEY
227 int wpa_stsl_remove(struct wpa_authenticator *wpa_auth,
228 		    struct wpa_stsl_negotiation *neg);
229 void wpa_smk_error(struct wpa_authenticator *wpa_auth,
230 		   struct wpa_state_machine *sm, struct wpa_eapol_key *key);
231 void wpa_smk_m1(struct wpa_authenticator *wpa_auth,
232 		struct wpa_state_machine *sm, struct wpa_eapol_key *key);
233 void wpa_smk_m3(struct wpa_authenticator *wpa_auth,
234 		struct wpa_state_machine *sm, struct wpa_eapol_key *key);
235 #endif /* CONFIG_PEERKEY */
236 
237 #ifdef CONFIG_IEEE80211R
238 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
239 int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
240 		   size_t r0kh_id_len,
241 		   const u8 *anonce, const u8 *snonce,
242 		   u8 *buf, size_t len, const u8 *subelem,
243 		   size_t subelem_len);
244 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
245 			   struct wpa_ptk *ptk, size_t ptk_len);
246 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
247 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
248 void wpa_ft_install_ptk(struct wpa_state_machine *sm);
249 #endif /* CONFIG_IEEE80211R */
250 
251 #endif /* WPA_AUTH_I_H */
252