• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hostapd - IEEE 802.11i-2004 / WPA Authenticator
3  * Copyright (c) 2004-2015, 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_H
10 #define WPA_AUTH_H
11 
12 #include "common/defs.h"
13 #include "common/eapol_common.h"
14 #include "common/wpa_common.h"
15 #include "common/ieee802_11_defs.h"
16 
17 #define MAX_OWN_IE_OVERRIDE 256
18 
19 #ifdef _MSC_VER
20 #pragma pack(push, 1)
21 #endif /* _MSC_VER */
22 
23 /* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition
24  */
25 struct ft_rrb_frame {
26 	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
27 	u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
28 	le16 action_length; /* little endian length of action_frame */
29 	u8 ap_address[ETH_ALEN];
30 	/*
31 	 * Followed by action_length bytes of FT Action frame (from Category
32 	 * field to the end of Action Frame body.
33 	 */
34 } STRUCT_PACKED;
35 
36 #define RSN_REMOTE_FRAME_TYPE_FT_RRB 1
37 
38 #define FT_PACKET_REQUEST 0
39 #define FT_PACKET_RESPONSE 1
40 /* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r */
41 #define FT_PACKET_R0KH_R1KH_PULL 200
42 #define FT_PACKET_R0KH_R1KH_RESP 201
43 #define FT_PACKET_R0KH_R1KH_PUSH 202
44 
45 #define FT_R0KH_R1KH_PULL_NONCE_LEN 16
46 #define FT_R0KH_R1KH_PULL_DATA_LEN (FT_R0KH_R1KH_PULL_NONCE_LEN + \
47 				    WPA_PMK_NAME_LEN + FT_R1KH_ID_LEN + \
48 				    ETH_ALEN)
49 #define FT_R0KH_R1KH_PULL_PAD_LEN ((8 - FT_R0KH_R1KH_PULL_DATA_LEN % 8) % 8)
50 
51 struct ft_r0kh_r1kh_pull_frame {
52 	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
53 	u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */
54 	le16 data_length; /* little endian length of data (44) */
55 	u8 ap_address[ETH_ALEN];
56 
57 	u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN];
58 	u8 pmk_r0_name[WPA_PMK_NAME_LEN];
59 	u8 r1kh_id[FT_R1KH_ID_LEN];
60 	u8 s1kh_id[ETH_ALEN];
61 	u8 pad[FT_R0KH_R1KH_PULL_PAD_LEN]; /* 8-octet boundary for AES block */
62 	u8 key_wrap_extra[8];
63 } STRUCT_PACKED;
64 
65 #define FT_R0KH_R1KH_RESP_DATA_LEN (FT_R0KH_R1KH_PULL_NONCE_LEN + \
66 				    FT_R1KH_ID_LEN + ETH_ALEN + PMK_LEN + \
67 				    WPA_PMK_NAME_LEN + 2)
68 #define FT_R0KH_R1KH_RESP_PAD_LEN ((8 - FT_R0KH_R1KH_RESP_DATA_LEN % 8) % 8)
69 struct ft_r0kh_r1kh_resp_frame {
70 	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
71 	u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */
72 	le16 data_length; /* little endian length of data (78) */
73 	u8 ap_address[ETH_ALEN];
74 
75 	u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN]; /* copied from pull */
76 	u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
77 	u8 s1kh_id[ETH_ALEN]; /* copied from pull */
78 	u8 pmk_r1[PMK_LEN];
79 	u8 pmk_r1_name[WPA_PMK_NAME_LEN];
80 	le16 pairwise;
81 	u8 pad[FT_R0KH_R1KH_RESP_PAD_LEN]; /* 8-octet boundary for AES block */
82 	u8 key_wrap_extra[8];
83 } STRUCT_PACKED;
84 
85 #define FT_R0KH_R1KH_PUSH_DATA_LEN (4 + FT_R1KH_ID_LEN + ETH_ALEN + \
86 				    WPA_PMK_NAME_LEN + PMK_LEN + \
87 				    WPA_PMK_NAME_LEN + 2)
88 #define FT_R0KH_R1KH_PUSH_PAD_LEN ((8 - FT_R0KH_R1KH_PUSH_DATA_LEN % 8) % 8)
89 struct ft_r0kh_r1kh_push_frame {
90 	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
91 	u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
92 	le16 data_length; /* little endian length of data (82) */
93 	u8 ap_address[ETH_ALEN];
94 
95 	/* Encrypted with AES key-wrap */
96 	u8 timestamp[4]; /* current time in seconds since unix epoch, little
97 			  * endian */
98 	u8 r1kh_id[FT_R1KH_ID_LEN];
99 	u8 s1kh_id[ETH_ALEN];
100 	u8 pmk_r0_name[WPA_PMK_NAME_LEN];
101 	u8 pmk_r1[PMK_LEN];
102 	u8 pmk_r1_name[WPA_PMK_NAME_LEN];
103 	le16 pairwise;
104 	u8 pad[FT_R0KH_R1KH_PUSH_PAD_LEN]; /* 8-octet boundary for AES block */
105 	u8 key_wrap_extra[8];
106 } STRUCT_PACKED;
107 
108 #ifdef _MSC_VER
109 #pragma pack(pop)
110 #endif /* _MSC_VER */
111 
112 
113 /* per STA state machine data */
114 
115 struct wpa_authenticator;
116 struct wpa_state_machine;
117 struct rsn_pmksa_cache_entry;
118 struct eapol_state_machine;
119 
120 
121 struct ft_remote_r0kh {
122 	struct ft_remote_r0kh *next;
123 	u8 addr[ETH_ALEN];
124 	u8 id[FT_R0KH_ID_MAX_LEN];
125 	size_t id_len;
126 	u8 key[16];
127 };
128 
129 
130 struct ft_remote_r1kh {
131 	struct ft_remote_r1kh *next;
132 	u8 addr[ETH_ALEN];
133 	u8 id[FT_R1KH_ID_LEN];
134 	u8 key[16];
135 };
136 
137 
138 struct wpa_auth_config {
139 	int wpa;
140 	int wpa_key_mgmt;
141 	int wpa_pairwise;
142 	int wpa_group;
143 	int wpa_group_rekey;
144 	int wpa_strict_rekey;
145 	int wpa_gmk_rekey;
146 	int wpa_ptk_rekey;
147 	u32 wpa_group_update_count;
148 	u32 wpa_pairwise_update_count;
149 	int rsn_pairwise;
150 	int rsn_preauth;
151 	int eapol_version;
152 	int peerkey;
153 	int wmm_enabled;
154 	int wmm_uapsd;
155 	int disable_pmksa_caching;
156 	int okc;
157 	int tx_status;
158 #ifdef CONFIG_IEEE80211W
159 	enum mfp_options ieee80211w;
160 	int group_mgmt_cipher;
161 #endif /* CONFIG_IEEE80211W */
162 #ifdef CONFIG_IEEE80211R_AP
163 	u8 ssid[SSID_MAX_LEN];
164 	size_t ssid_len;
165 	u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
166 	u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
167 	size_t r0_key_holder_len;
168 	u8 r1_key_holder[FT_R1KH_ID_LEN];
169 	u32 r0_key_lifetime;
170 	u32 reassociation_deadline;
171 	struct ft_remote_r0kh *r0kh_list;
172 	struct ft_remote_r1kh *r1kh_list;
173 	int pmk_r1_push;
174 	int ft_over_ds;
175 	int ft_psk_generate_local;
176 #endif /* CONFIG_IEEE80211R_AP */
177 	int disable_gtk;
178 	int ap_mlme;
179 #ifdef CONFIG_TESTING_OPTIONS
180 	double corrupt_gtk_rekey_mic_probability;
181 	u8 own_ie_override[MAX_OWN_IE_OVERRIDE];
182 	size_t own_ie_override_len;
183 #endif /* CONFIG_TESTING_OPTIONS */
184 #ifdef CONFIG_P2P
185 	u8 ip_addr_go[4];
186 	u8 ip_addr_mask[4];
187 	u8 ip_addr_start[4];
188 	u8 ip_addr_end[4];
189 #endif /* CONFIG_P2P */
190 };
191 
192 typedef enum {
193 	LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
194 } logger_level;
195 
196 typedef enum {
197 	WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
198 	WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
199 	WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
200 } wpa_eapol_variable;
201 
202 struct wpa_auth_callbacks {
203 	void (*logger)(void *ctx, const u8 *addr, logger_level level,
204 		       const char *txt);
205 	void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
206 	int (*mic_failure_report)(void *ctx, const u8 *addr);
207 	void (*psk_failure_report)(void *ctx, const u8 *addr);
208 	void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
209 			  int value);
210 	int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
211 	const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
212 			      const u8 *prev_psk);
213 	int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
214 	int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
215 		       const u8 *addr, int idx, u8 *key, size_t key_len);
216 	int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
217 	int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
218 			  size_t data_len, int encrypt);
219 	int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
220 						 void *ctx), void *cb_ctx);
221 	int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
222 						  void *ctx), void *cb_ctx);
223 	int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
224 			  size_t data_len);
225 #ifdef CONFIG_IEEE80211R_AP
226 	struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
227 	int (*send_ft_action)(void *ctx, const u8 *dst,
228 			      const u8 *data, size_t data_len);
229 	int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
230 			 size_t tspec_ielen);
231 #endif /* CONFIG_IEEE80211R_AP */
232 #ifdef CONFIG_MESH
233 	int (*start_ampe)(void *ctx, const u8 *sta_addr);
234 #endif /* CONFIG_MESH */
235 };
236 
237 struct wpa_authenticator * wpa_init(const u8 *addr,
238 				    struct wpa_auth_config *conf,
239 				    const struct wpa_auth_callbacks *cb,
240 				    void *cb_ctx);
241 int wpa_init_keys(struct wpa_authenticator *wpa_auth);
242 void wpa_deinit(struct wpa_authenticator *wpa_auth);
243 int wpa_reconfig(struct wpa_authenticator *wpa_auth,
244 		 struct wpa_auth_config *conf);
245 
246 enum {
247 	WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
248 	WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
249 	WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
250 	WPA_INVALID_MDIE, WPA_INVALID_PROTO
251 };
252 
253 int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
254 			struct wpa_state_machine *sm,
255 			const u8 *wpa_ie, size_t wpa_ie_len,
256 			const u8 *mdie, size_t mdie_len);
257 int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
258 		      struct wpa_state_machine *sm,
259 		      const u8 *osen_ie, size_t osen_ie_len);
260 int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
261 struct wpa_state_machine *
262 wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
263 		  const u8 *p2p_dev_addr);
264 int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
265 			    struct wpa_state_machine *sm);
266 void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
267 void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
268 void wpa_receive(struct wpa_authenticator *wpa_auth,
269 		 struct wpa_state_machine *sm,
270 		 u8 *data, size_t data_len);
271 enum wpa_event {
272 	WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
273 	WPA_REAUTH_EAPOL, WPA_ASSOC_FT, WPA_DRV_STA_REMOVED
274 };
275 void wpa_remove_ptk(struct wpa_state_machine *sm);
276 int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
277 void wpa_auth_sm_notify(struct wpa_state_machine *sm);
278 void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
279 int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
280 int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
281 void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
282 int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
283 int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
284 int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
285 int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
286 int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm);
287 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
288 			     struct rsn_pmksa_cache_entry *entry);
289 struct rsn_pmksa_cache_entry *
290 wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
291 void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
292 const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
293 			       size_t *len);
294 int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
295 		       unsigned int pmk_len,
296 		       int session_timeout, struct eapol_state_machine *eapol);
297 int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
298 			       const u8 *pmk, size_t len, const u8 *sta_addr,
299 			       int session_timeout,
300 			       struct eapol_state_machine *eapol);
301 int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
302 			   const u8 *pmk, const u8 *pmkid);
303 void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
304 			   const u8 *sta_addr);
305 int wpa_auth_pmksa_list(struct wpa_authenticator *wpa_auth, char *buf,
306 			size_t len);
307 void wpa_auth_pmksa_flush(struct wpa_authenticator *wpa_auth);
308 int wpa_auth_pmksa_list_mesh(struct wpa_authenticator *wpa_auth, const u8 *addr,
309 			     char *buf, size_t len);
310 struct rsn_pmksa_cache_entry *
311 wpa_auth_pmksa_create_entry(const u8 *aa, const u8 *spa, const u8 *pmk,
312 			    const u8 *pmkid, int expiration);
313 int wpa_auth_pmksa_add_entry(struct wpa_authenticator *wpa_auth,
314 			     struct rsn_pmksa_cache_entry *entry);
315 struct rsn_pmksa_cache_entry *
316 wpa_auth_pmksa_get(struct wpa_authenticator *wpa_auth, const u8 *sta_addr,
317 		   const u8 *pmkid);
318 void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry *pmksa,
319 			      struct wpa_state_machine *sm,
320 			      struct wpa_authenticator *wpa_auth,
321 			      u8 *pmkid, u8 *pmk);
322 int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
323 void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
324 				  struct wpa_state_machine *sm, int ack);
325 
326 #ifdef CONFIG_IEEE80211R_AP
327 u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
328 				 size_t max_len, int auth_alg,
329 				 const u8 *req_ies, size_t req_ies_len);
330 void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
331 			 u16 auth_transaction, const u8 *ies, size_t ies_len,
332 			 void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
333 				    u16 auth_transaction, u16 resp,
334 				    const u8 *ies, size_t ies_len),
335 			 void *ctx);
336 u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
337 			    size_t ies_len);
338 int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
339 int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
340 		  const u8 *data, size_t data_len);
341 void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
342 #endif /* CONFIG_IEEE80211R_AP */
343 
344 void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
345 void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
346 int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
347 int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
348 
349 int wpa_auth_uses_sae(struct wpa_state_machine *sm);
350 int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
351 
352 int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
353 
354 struct radius_das_attrs;
355 int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
356 					 struct radius_das_attrs *attr);
357 void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth);
358 
359 int wpa_auth_ensure_group(struct wpa_authenticator *wpa_auth, int vlan_id);
360 int wpa_auth_release_group(struct wpa_authenticator *wpa_auth, int vlan_id);
361 int fils_auth_pmk_to_ptk(struct wpa_state_machine *sm, const u8 *pmk,
362 			 size_t pmk_len, const u8 *snonce, const u8 *anonce);
363 int fils_decrypt_assoc(struct wpa_state_machine *sm, const u8 *fils_session,
364 		       const struct ieee80211_mgmt *mgmt, size_t frame_len,
365 		       u8 *pos, size_t left);
366 int fils_encrypt_assoc(struct wpa_state_machine *sm, u8 *buf,
367 		       size_t current_len, size_t max_len,
368 		       const struct wpabuf *hlp);
369 int fils_set_tk(struct wpa_state_machine *sm);
370 
371 #endif /* WPA_AUTH_H */
372