blob: 75b73f024ab032b7ad301efbf0780458087f000e [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd - IEEE 802.11i-2004 / WPA Authenticator
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003 * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
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"
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -070015#include "common/ieee802_11_defs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080017#define MAX_OWN_IE_OVERRIDE 256
18
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#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 */
25struct 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_DATA_LEN 44
46#define FT_R0KH_R1KH_RESP_DATA_LEN 76
47#define FT_R0KH_R1KH_PUSH_DATA_LEN 88
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070048#define FT_R0KH_R1KH_PULL_NONCE_LEN 16
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049
50struct ft_r0kh_r1kh_pull_frame {
51 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
52 u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */
53 le16 data_length; /* little endian length of data (44) */
54 u8 ap_address[ETH_ALEN];
55
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070056 u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070057 u8 pmk_r0_name[WPA_PMK_NAME_LEN];
58 u8 r1kh_id[FT_R1KH_ID_LEN];
59 u8 s1kh_id[ETH_ALEN];
60 u8 pad[4]; /* 8-octet boundary for AES key wrap */
61 u8 key_wrap_extra[8];
62} STRUCT_PACKED;
63
64struct ft_r0kh_r1kh_resp_frame {
65 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
66 u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */
67 le16 data_length; /* little endian length of data (76) */
68 u8 ap_address[ETH_ALEN];
69
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070070 u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN]; /* copied from pull */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070071 u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
72 u8 s1kh_id[ETH_ALEN]; /* copied from pull */
73 u8 pmk_r1[PMK_LEN];
74 u8 pmk_r1_name[WPA_PMK_NAME_LEN];
75 le16 pairwise;
76 u8 pad[2]; /* 8-octet boundary for AES key wrap */
77 u8 key_wrap_extra[8];
78} STRUCT_PACKED;
79
80struct ft_r0kh_r1kh_push_frame {
81 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
82 u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
83 le16 data_length; /* little endian length of data (88) */
84 u8 ap_address[ETH_ALEN];
85
86 /* Encrypted with AES key-wrap */
87 u8 timestamp[4]; /* current time in seconds since unix epoch, little
88 * endian */
89 u8 r1kh_id[FT_R1KH_ID_LEN];
90 u8 s1kh_id[ETH_ALEN];
91 u8 pmk_r0_name[WPA_PMK_NAME_LEN];
92 u8 pmk_r1[PMK_LEN];
93 u8 pmk_r1_name[WPA_PMK_NAME_LEN];
94 le16 pairwise;
95 u8 pad[6]; /* 8-octet boundary for AES key wrap */
96 u8 key_wrap_extra[8];
97} STRUCT_PACKED;
98
99#ifdef _MSC_VER
100#pragma pack(pop)
101#endif /* _MSC_VER */
102
103
104/* per STA state machine data */
105
106struct wpa_authenticator;
107struct wpa_state_machine;
108struct rsn_pmksa_cache_entry;
109struct eapol_state_machine;
110
111
112struct ft_remote_r0kh {
113 struct ft_remote_r0kh *next;
114 u8 addr[ETH_ALEN];
115 u8 id[FT_R0KH_ID_MAX_LEN];
116 size_t id_len;
117 u8 key[16];
118};
119
120
121struct ft_remote_r1kh {
122 struct ft_remote_r1kh *next;
123 u8 addr[ETH_ALEN];
124 u8 id[FT_R1KH_ID_LEN];
125 u8 key[16];
126};
127
128
129struct wpa_auth_config {
130 int wpa;
131 int wpa_key_mgmt;
132 int wpa_pairwise;
133 int wpa_group;
134 int wpa_group_rekey;
135 int wpa_strict_rekey;
136 int wpa_gmk_rekey;
137 int wpa_ptk_rekey;
138 int rsn_pairwise;
139 int rsn_preauth;
140 int eapol_version;
141 int peerkey;
142 int wmm_enabled;
143 int wmm_uapsd;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700144 int disable_pmksa_caching;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145 int okc;
146 int tx_status;
147#ifdef CONFIG_IEEE80211W
148 enum mfp_options ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700149 int group_mgmt_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150#endif /* CONFIG_IEEE80211W */
151#ifdef CONFIG_IEEE80211R
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700152 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153 size_t ssid_len;
154 u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
155 u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
156 size_t r0_key_holder_len;
157 u8 r1_key_holder[FT_R1KH_ID_LEN];
158 u32 r0_key_lifetime;
159 u32 reassociation_deadline;
160 struct ft_remote_r0kh *r0kh_list;
161 struct ft_remote_r1kh *r1kh_list;
162 int pmk_r1_push;
163 int ft_over_ds;
164#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700165 int disable_gtk;
166 int ap_mlme;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700167#ifdef CONFIG_TESTING_OPTIONS
168 double corrupt_gtk_rekey_mic_probability;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800169 u8 own_ie_override[MAX_OWN_IE_OVERRIDE];
170 size_t own_ie_override_len;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700171#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800172#ifdef CONFIG_P2P
173 u8 ip_addr_go[4];
174 u8 ip_addr_mask[4];
175 u8 ip_addr_start[4];
176 u8 ip_addr_end[4];
177#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178};
179
180typedef enum {
181 LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
182} logger_level;
183
184typedef enum {
185 WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
186 WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
187 WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
188} wpa_eapol_variable;
189
190struct wpa_auth_callbacks {
191 void *ctx;
192 void (*logger)(void *ctx, const u8 *addr, logger_level level,
193 const char *txt);
194 void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800195 int (*mic_failure_report)(void *ctx, const u8 *addr);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700196 void (*psk_failure_report)(void *ctx, const u8 *addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700197 void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
198 int value);
199 int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700200 const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
201 const u8 *prev_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
203 int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
204 const u8 *addr, int idx, u8 *key, size_t key_len);
205 int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
206 int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
207 size_t data_len, int encrypt);
208 int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
209 void *ctx), void *cb_ctx);
210 int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
211 void *ctx), void *cb_ctx);
212 int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
213 size_t data_len);
214#ifdef CONFIG_IEEE80211R
215 struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
216 int (*send_ft_action)(void *ctx, const u8 *dst,
217 const u8 *data, size_t data_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700218 int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800219 size_t tspec_ielen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800221#ifdef CONFIG_MESH
222 int (*start_ampe)(void *ctx, const u8 *sta_addr);
223#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224};
225
226struct wpa_authenticator * wpa_init(const u8 *addr,
227 struct wpa_auth_config *conf,
228 struct wpa_auth_callbacks *cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800229int wpa_init_keys(struct wpa_authenticator *wpa_auth);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230void wpa_deinit(struct wpa_authenticator *wpa_auth);
231int wpa_reconfig(struct wpa_authenticator *wpa_auth,
232 struct wpa_auth_config *conf);
233
234enum {
235 WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
236 WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
237 WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
238 WPA_INVALID_MDIE, WPA_INVALID_PROTO
239};
240
241int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
242 struct wpa_state_machine *sm,
243 const u8 *wpa_ie, size_t wpa_ie_len,
244 const u8 *mdie, size_t mdie_len);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800245int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
246 struct wpa_state_machine *sm,
247 const u8 *osen_ie, size_t osen_ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
249struct wpa_state_machine *
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700250wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
251 const u8 *p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700252int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
253 struct wpa_state_machine *sm);
254void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
255void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
256void wpa_receive(struct wpa_authenticator *wpa_auth,
257 struct wpa_state_machine *sm,
258 u8 *data, size_t data_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800259enum wpa_event {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260 WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
261 WPA_REAUTH_EAPOL, WPA_ASSOC_FT
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800262};
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700263void wpa_remove_ptk(struct wpa_state_machine *sm);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800264int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265void wpa_auth_sm_notify(struct wpa_state_machine *sm);
266void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
267int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
268int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
269void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
270int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
271int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
272int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
273int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
274int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
275 struct rsn_pmksa_cache_entry *entry);
276struct rsn_pmksa_cache_entry *
277wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
278void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
279const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
280 size_t *len);
281int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800282 unsigned int pmk_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283 int session_timeout, struct eapol_state_machine *eapol);
284int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
285 const u8 *pmk, size_t len, const u8 *sta_addr,
286 int session_timeout,
287 struct eapol_state_machine *eapol);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800288int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
289 const u8 *pmk);
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700290void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
291 const u8 *sta_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
293void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
294 struct wpa_state_machine *sm, int ack);
295
296#ifdef CONFIG_IEEE80211R
297u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
298 size_t max_len, int auth_alg,
299 const u8 *req_ies, size_t req_ies_len);
300void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
301 u16 auth_transaction, const u8 *ies, size_t ies_len,
302 void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
303 u16 auth_transaction, u16 resp,
304 const u8 *ies, size_t ies_len),
305 void *ctx);
306u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
307 size_t ies_len);
308int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
309int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
310 const u8 *data, size_t data_len);
311void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
312#endif /* CONFIG_IEEE80211R */
313
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700314void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
315void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
316int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700317int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700318
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800319int wpa_auth_uses_sae(struct wpa_state_machine *sm);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800320int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800321
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800322int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
323
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800324struct radius_das_attrs;
325int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
326 struct radius_das_attrs *attr);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800327void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800328
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800329int wpa_auth_ensure_group(struct wpa_authenticator *wpa_auth, int vlan_id);
330int wpa_auth_release_group(struct wpa_authenticator *wpa_auth, int vlan_id);
331
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332#endif /* WPA_AUTH_H */