wpa_auth.h revision 324697
1214501Srpaulo/*
2214501Srpaulo * hostapd - IEEE 802.11i-2004 / WPA Authenticator
3289549Srpaulo * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
4214501Srpaulo *
5252726Srpaulo * This software may be distributed under the terms of the BSD license.
6252726Srpaulo * See README for more details.
7214501Srpaulo */
8214501Srpaulo
9214501Srpaulo#ifndef WPA_AUTH_H
10214501Srpaulo#define WPA_AUTH_H
11214501Srpaulo
12214501Srpaulo#include "common/defs.h"
13214501Srpaulo#include "common/eapol_common.h"
14214501Srpaulo#include "common/wpa_common.h"
15289549Srpaulo#include "common/ieee802_11_defs.h"
16214501Srpaulo
17289549Srpaulo#define MAX_OWN_IE_OVERRIDE 256
18289549Srpaulo
19214501Srpaulo#ifdef _MSC_VER
20214501Srpaulo#pragma pack(push, 1)
21214501Srpaulo#endif /* _MSC_VER */
22214501Srpaulo
23214501Srpaulo/* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition
24214501Srpaulo */
25214501Srpaulostruct ft_rrb_frame {
26214501Srpaulo	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
27214501Srpaulo	u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
28214501Srpaulo	le16 action_length; /* little endian length of action_frame */
29214501Srpaulo	u8 ap_address[ETH_ALEN];
30214501Srpaulo	/*
31214501Srpaulo	 * Followed by action_length bytes of FT Action frame (from Category
32214501Srpaulo	 * field to the end of Action Frame body.
33214501Srpaulo	 */
34214501Srpaulo} STRUCT_PACKED;
35214501Srpaulo
36214501Srpaulo#define RSN_REMOTE_FRAME_TYPE_FT_RRB 1
37214501Srpaulo
38214501Srpaulo#define FT_PACKET_REQUEST 0
39214501Srpaulo#define FT_PACKET_RESPONSE 1
40214501Srpaulo/* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r */
41214501Srpaulo#define FT_PACKET_R0KH_R1KH_PULL 200
42214501Srpaulo#define FT_PACKET_R0KH_R1KH_RESP 201
43214501Srpaulo#define FT_PACKET_R0KH_R1KH_PUSH 202
44214501Srpaulo
45214501Srpaulo#define FT_R0KH_R1KH_PULL_DATA_LEN 44
46214501Srpaulo#define FT_R0KH_R1KH_RESP_DATA_LEN 76
47214501Srpaulo#define FT_R0KH_R1KH_PUSH_DATA_LEN 88
48281806Srpaulo#define FT_R0KH_R1KH_PULL_NONCE_LEN 16
49214501Srpaulo
50214501Srpaulostruct ft_r0kh_r1kh_pull_frame {
51214501Srpaulo	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
52214501Srpaulo	u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */
53214501Srpaulo	le16 data_length; /* little endian length of data (44) */
54214501Srpaulo	u8 ap_address[ETH_ALEN];
55214501Srpaulo
56281806Srpaulo	u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN];
57214501Srpaulo	u8 pmk_r0_name[WPA_PMK_NAME_LEN];
58214501Srpaulo	u8 r1kh_id[FT_R1KH_ID_LEN];
59214501Srpaulo	u8 s1kh_id[ETH_ALEN];
60214501Srpaulo	u8 pad[4]; /* 8-octet boundary for AES key wrap */
61214501Srpaulo	u8 key_wrap_extra[8];
62214501Srpaulo} STRUCT_PACKED;
63214501Srpaulo
64214501Srpaulostruct ft_r0kh_r1kh_resp_frame {
65214501Srpaulo	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
66214501Srpaulo	u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */
67214501Srpaulo	le16 data_length; /* little endian length of data (76) */
68214501Srpaulo	u8 ap_address[ETH_ALEN];
69214501Srpaulo
70281806Srpaulo	u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN]; /* copied from pull */
71214501Srpaulo	u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
72214501Srpaulo	u8 s1kh_id[ETH_ALEN]; /* copied from pull */
73214501Srpaulo	u8 pmk_r1[PMK_LEN];
74214501Srpaulo	u8 pmk_r1_name[WPA_PMK_NAME_LEN];
75214501Srpaulo	le16 pairwise;
76214501Srpaulo	u8 pad[2]; /* 8-octet boundary for AES key wrap */
77214501Srpaulo	u8 key_wrap_extra[8];
78214501Srpaulo} STRUCT_PACKED;
79214501Srpaulo
80214501Srpaulostruct ft_r0kh_r1kh_push_frame {
81214501Srpaulo	u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
82214501Srpaulo	u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
83214501Srpaulo	le16 data_length; /* little endian length of data (88) */
84214501Srpaulo	u8 ap_address[ETH_ALEN];
85214501Srpaulo
86214501Srpaulo	/* Encrypted with AES key-wrap */
87214501Srpaulo	u8 timestamp[4]; /* current time in seconds since unix epoch, little
88214501Srpaulo			  * endian */
89214501Srpaulo	u8 r1kh_id[FT_R1KH_ID_LEN];
90214501Srpaulo	u8 s1kh_id[ETH_ALEN];
91214501Srpaulo	u8 pmk_r0_name[WPA_PMK_NAME_LEN];
92214501Srpaulo	u8 pmk_r1[PMK_LEN];
93214501Srpaulo	u8 pmk_r1_name[WPA_PMK_NAME_LEN];
94214501Srpaulo	le16 pairwise;
95214501Srpaulo	u8 pad[6]; /* 8-octet boundary for AES key wrap */
96214501Srpaulo	u8 key_wrap_extra[8];
97214501Srpaulo} STRUCT_PACKED;
98214501Srpaulo
99214501Srpaulo#ifdef _MSC_VER
100214501Srpaulo#pragma pack(pop)
101214501Srpaulo#endif /* _MSC_VER */
102214501Srpaulo
103214501Srpaulo
104214501Srpaulo/* per STA state machine data */
105214501Srpaulo
106214501Srpaulostruct wpa_authenticator;
107214501Srpaulostruct wpa_state_machine;
108214501Srpaulostruct rsn_pmksa_cache_entry;
109214501Srpaulostruct eapol_state_machine;
110214501Srpaulo
111214501Srpaulo
112214501Srpaulostruct ft_remote_r0kh {
113214501Srpaulo	struct ft_remote_r0kh *next;
114214501Srpaulo	u8 addr[ETH_ALEN];
115214501Srpaulo	u8 id[FT_R0KH_ID_MAX_LEN];
116214501Srpaulo	size_t id_len;
117214501Srpaulo	u8 key[16];
118214501Srpaulo};
119214501Srpaulo
120214501Srpaulo
121214501Srpaulostruct ft_remote_r1kh {
122214501Srpaulo	struct ft_remote_r1kh *next;
123214501Srpaulo	u8 addr[ETH_ALEN];
124214501Srpaulo	u8 id[FT_R1KH_ID_LEN];
125214501Srpaulo	u8 key[16];
126214501Srpaulo};
127214501Srpaulo
128214501Srpaulo
129214501Srpaulostruct wpa_auth_config {
130214501Srpaulo	int wpa;
131214501Srpaulo	int wpa_key_mgmt;
132214501Srpaulo	int wpa_pairwise;
133214501Srpaulo	int wpa_group;
134214501Srpaulo	int wpa_group_rekey;
135214501Srpaulo	int wpa_strict_rekey;
136214501Srpaulo	int wpa_gmk_rekey;
137214501Srpaulo	int wpa_ptk_rekey;
138214501Srpaulo	int rsn_pairwise;
139214501Srpaulo	int rsn_preauth;
140214501Srpaulo	int eapol_version;
141214501Srpaulo	int peerkey;
142214501Srpaulo	int wmm_enabled;
143214501Srpaulo	int wmm_uapsd;
144252726Srpaulo	int disable_pmksa_caching;
145214501Srpaulo	int okc;
146252726Srpaulo	int tx_status;
147214501Srpaulo#ifdef CONFIG_IEEE80211W
148214501Srpaulo	enum mfp_options ieee80211w;
149281806Srpaulo	int group_mgmt_cipher;
150214501Srpaulo#endif /* CONFIG_IEEE80211W */
151214501Srpaulo#ifdef CONFIG_IEEE80211R
152289549Srpaulo	u8 ssid[SSID_MAX_LEN];
153214501Srpaulo	size_t ssid_len;
154214501Srpaulo	u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
155214501Srpaulo	u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
156214501Srpaulo	size_t r0_key_holder_len;
157214501Srpaulo	u8 r1_key_holder[FT_R1KH_ID_LEN];
158214501Srpaulo	u32 r0_key_lifetime;
159214501Srpaulo	u32 reassociation_deadline;
160214501Srpaulo	struct ft_remote_r0kh *r0kh_list;
161214501Srpaulo	struct ft_remote_r1kh *r1kh_list;
162214501Srpaulo	int pmk_r1_push;
163252726Srpaulo	int ft_over_ds;
164214501Srpaulo#endif /* CONFIG_IEEE80211R */
165252726Srpaulo	int disable_gtk;
166252726Srpaulo	int ap_mlme;
167281806Srpaulo#ifdef CONFIG_TESTING_OPTIONS
168281806Srpaulo	double corrupt_gtk_rekey_mic_probability;
169289549Srpaulo	u8 own_ie_override[MAX_OWN_IE_OVERRIDE];
170289549Srpaulo	size_t own_ie_override_len;
171281806Srpaulo#endif /* CONFIG_TESTING_OPTIONS */
172281806Srpaulo#ifdef CONFIG_P2P
173281806Srpaulo	u8 ip_addr_go[4];
174281806Srpaulo	u8 ip_addr_mask[4];
175281806Srpaulo	u8 ip_addr_start[4];
176281806Srpaulo	u8 ip_addr_end[4];
177281806Srpaulo#endif /* CONFIG_P2P */
178214501Srpaulo};
179214501Srpaulo
180214501Srpaulotypedef enum {
181214501Srpaulo	LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
182214501Srpaulo} logger_level;
183214501Srpaulo
184214501Srpaulotypedef enum {
185214501Srpaulo	WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
186214501Srpaulo	WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
187214501Srpaulo	WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
188214501Srpaulo} wpa_eapol_variable;
189214501Srpaulo
190214501Srpaulostruct wpa_auth_callbacks {
191214501Srpaulo	void *ctx;
192214501Srpaulo	void (*logger)(void *ctx, const u8 *addr, logger_level level,
193214501Srpaulo		       const char *txt);
194214501Srpaulo	void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
195252726Srpaulo	int (*mic_failure_report)(void *ctx, const u8 *addr);
196289549Srpaulo	void (*psk_failure_report)(void *ctx, const u8 *addr);
197214501Srpaulo	void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
198214501Srpaulo			  int value);
199214501Srpaulo	int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
200281806Srpaulo	const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
201281806Srpaulo			      const u8 *prev_psk);
202214501Srpaulo	int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
203214501Srpaulo	int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
204214501Srpaulo		       const u8 *addr, int idx, u8 *key, size_t key_len);
205214501Srpaulo	int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
206214501Srpaulo	int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
207214501Srpaulo			  size_t data_len, int encrypt);
208214501Srpaulo	int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
209214501Srpaulo						 void *ctx), void *cb_ctx);
210214501Srpaulo	int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
211214501Srpaulo						  void *ctx), void *cb_ctx);
212214501Srpaulo	int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
213214501Srpaulo			  size_t data_len);
214214501Srpaulo#ifdef CONFIG_IEEE80211R
215214501Srpaulo	struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
216214501Srpaulo	int (*send_ft_action)(void *ctx, const u8 *dst,
217214501Srpaulo			      const u8 *data, size_t data_len);
218252726Srpaulo	int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
219281806Srpaulo			 size_t tspec_ielen);
220214501Srpaulo#endif /* CONFIG_IEEE80211R */
221281806Srpaulo#ifdef CONFIG_MESH
222281806Srpaulo	int (*start_ampe)(void *ctx, const u8 *sta_addr);
223281806Srpaulo#endif /* CONFIG_MESH */
224214501Srpaulo};
225214501Srpaulo
226214501Srpaulostruct wpa_authenticator * wpa_init(const u8 *addr,
227214501Srpaulo				    struct wpa_auth_config *conf,
228214501Srpaulo				    struct wpa_auth_callbacks *cb);
229252726Srpauloint wpa_init_keys(struct wpa_authenticator *wpa_auth);
230214501Srpaulovoid wpa_deinit(struct wpa_authenticator *wpa_auth);
231214501Srpauloint wpa_reconfig(struct wpa_authenticator *wpa_auth,
232214501Srpaulo		 struct wpa_auth_config *conf);
233214501Srpaulo
234214501Srpauloenum {
235214501Srpaulo	WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
236214501Srpaulo	WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
237214501Srpaulo	WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
238214501Srpaulo	WPA_INVALID_MDIE, WPA_INVALID_PROTO
239214501Srpaulo};
240214501Srpaulo
241214501Srpauloint wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
242214501Srpaulo			struct wpa_state_machine *sm,
243214501Srpaulo			const u8 *wpa_ie, size_t wpa_ie_len,
244214501Srpaulo			const u8 *mdie, size_t mdie_len);
245281806Srpauloint wpa_validate_osen(struct wpa_authenticator *wpa_auth,
246281806Srpaulo		      struct wpa_state_machine *sm,
247281806Srpaulo		      const u8 *osen_ie, size_t osen_ie_len);
248214501Srpauloint wpa_auth_uses_mfp(struct wpa_state_machine *sm);
249214501Srpaulostruct wpa_state_machine *
250281806Srpaulowpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
251281806Srpaulo		  const u8 *p2p_dev_addr);
252214501Srpauloint wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
253214501Srpaulo			    struct wpa_state_machine *sm);
254214501Srpaulovoid wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
255214501Srpaulovoid wpa_auth_sta_deinit(struct wpa_state_machine *sm);
256214501Srpaulovoid wpa_receive(struct wpa_authenticator *wpa_auth,
257214501Srpaulo		 struct wpa_state_machine *sm,
258214501Srpaulo		 u8 *data, size_t data_len);
259289549Srpauloenum wpa_event {
260214501Srpaulo	WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
261214501Srpaulo	WPA_REAUTH_EAPOL, WPA_ASSOC_FT
262289549Srpaulo};
263214501Srpaulovoid wpa_remove_ptk(struct wpa_state_machine *sm);
264289549Srpauloint wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
265214501Srpaulovoid wpa_auth_sm_notify(struct wpa_state_machine *sm);
266214501Srpaulovoid wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
267214501Srpauloint wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
268214501Srpauloint wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
269214501Srpaulovoid wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
270214501Srpauloint wpa_auth_pairwise_set(struct wpa_state_machine *sm);
271214501Srpauloint wpa_auth_get_pairwise(struct wpa_state_machine *sm);
272214501Srpauloint wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
273214501Srpauloint wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
274324697Sgordonint wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm);
275214501Srpauloint wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
276214501Srpaulo			     struct rsn_pmksa_cache_entry *entry);
277214501Srpaulostruct rsn_pmksa_cache_entry *
278214501Srpaulowpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
279214501Srpaulovoid wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
280214501Srpauloconst u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
281214501Srpaulo			       size_t *len);
282214501Srpauloint wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
283214501Srpaulo		       int session_timeout, struct eapol_state_machine *eapol);
284214501Srpauloint wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
285214501Srpaulo			       const u8 *pmk, size_t len, const u8 *sta_addr,
286214501Srpaulo			       int session_timeout,
287214501Srpaulo			       struct eapol_state_machine *eapol);
288281806Srpauloint wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
289281806Srpaulo			   const u8 *pmk);
290281806Srpaulovoid wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
291281806Srpaulo			   const u8 *sta_addr);
292214501Srpauloint wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
293252726Srpaulovoid wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
294252726Srpaulo				  struct wpa_state_machine *sm, int ack);
295214501Srpaulo
296214501Srpaulo#ifdef CONFIG_IEEE80211R
297214501Srpaulou8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
298214501Srpaulo				 size_t max_len, int auth_alg,
299214501Srpaulo				 const u8 *req_ies, size_t req_ies_len);
300214501Srpaulovoid wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
301214501Srpaulo			 u16 auth_transaction, const u8 *ies, size_t ies_len,
302214501Srpaulo			 void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
303214501Srpaulo				    u16 auth_transaction, u16 resp,
304214501Srpaulo				    const u8 *ies, size_t ies_len),
305214501Srpaulo			 void *ctx);
306214501Srpaulou16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
307214501Srpaulo			    size_t ies_len);
308214501Srpauloint wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
309214501Srpauloint wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
310214501Srpaulo		  const u8 *data, size_t data_len);
311214501Srpaulovoid wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
312214501Srpaulo#endif /* CONFIG_IEEE80211R */
313214501Srpaulo
314252726Srpaulovoid wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
315252726Srpaulovoid wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
316252726Srpauloint wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
317252726Srpauloint wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
318252726Srpaulo
319252726Srpauloint wpa_auth_uses_sae(struct wpa_state_machine *sm);
320281806Srpauloint wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
321252726Srpaulo
322281806Srpauloint wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
323281806Srpaulo
324281806Srpaulostruct radius_das_attrs;
325281806Srpauloint wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
326281806Srpaulo					 struct radius_das_attrs *attr);
327281806Srpaulovoid wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth);
328281806Srpaulo
329214501Srpaulo#endif /* WPA_AUTH_H */
330