]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/ap/wpa_auth.h
FT: Add support for wildcard R0KH/R1KH
[thirdparty/hostap.git] / src / ap / wpa_auth.h
CommitLineData
6fc6879b
JM
1/*
2 * hostapd - IEEE 802.11i-2004 / WPA Authenticator
09368515 3 * Copyright (c) 2004-2017, Jouni Malinen <j@w1.fi>
6fc6879b 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
6fc6879b
JM
7 */
8
9#ifndef WPA_AUTH_H
10#define WPA_AUTH_H
11
90973fb2
JM
12#include "common/defs.h"
13#include "common/eapol_common.h"
14#include "common/wpa_common.h"
d6c3067d 15#include "common/ieee802_11_defs.h"
6fc6879b 16
bc02843e
JM
17#define MAX_OWN_IE_OVERRIDE 256
18
6fc6879b
JM
19#ifdef _MSC_VER
20#pragma pack(push, 1)
21#endif /* _MSC_VER */
22
c1e033b0
JM
23/* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition
24 */
6fc6879b
JM
25struct ft_rrb_frame {
26 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
27 u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
2eba45c8 28 le16 action_length; /* little endian length of action_frame */
6fc6879b
JM
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
50bd8e0a
MB
40
41/* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r. These
42 * use OUI Extended EtherType as the encapsulating format. */
43#define FT_PACKET_R0KH_R1KH_PULL 0x01
44#define FT_PACKET_R0KH_R1KH_RESP 0x02
45#define FT_PACKET_R0KH_R1KH_PUSH 0x03
eefe8630
MB
46#define FT_PACKET_R0KH_R1KH_SEQ_REQ 0x04
47#define FT_PACKET_R0KH_R1KH_SEQ_RESP 0x05
6fc6879b 48
245fc96e
MB
49/* packet layout
50 * IEEE 802 extended OUI ethertype frame header
51 * u16 authlen (little endian)
52 * multiple of struct ft_rrb_tlv (authenticated only, length = authlen)
53 * multiple of struct ft_rrb_tlv (AES-SIV encrypted, AES-SIV needs an extra
54 * blocksize length)
55 *
56 * AES-SIV AAD;
57 * source MAC address (6)
58 * authenticated-only TLVs (authlen)
59 * subtype (1; FT_PACKET_*)
60 */
6fc6879b 61
245fc96e
MB
62#define FT_RRB_NONCE_LEN 16
63
64#define FT_RRB_LAST_EMPTY 0 /* placeholder or padding */
65
eefe8630 66#define FT_RRB_SEQ 1 /* struct ft_rrb_seq */
245fc96e
MB
67#define FT_RRB_NONCE 2 /* size FT_RRB_NONCE_LEN */
68#define FT_RRB_TIMESTAMP 3 /* le32 unix seconds */
69
70#define FT_RRB_R0KH_ID 4 /* FT_R0KH_ID_MAX_LEN */
71#define FT_RRB_R1KH_ID 5 /* FT_R1KH_ID_LEN */
72#define FT_RRB_S1KH_ID 6 /* ETH_ALEN */
6fc6879b 73
245fc96e
MB
74#define FT_RRB_PMK_R0_NAME 7 /* WPA_PMK_NAME_LEN */
75#define FT_RRB_PMK_R0 8 /* PMK_LEN */
76#define FT_RRB_PMK_R1_NAME 9 /* WPA_PMK_NAME_LEN */
77#define FT_RRB_PMK_R1 10 /* PMK_LEN */
78
79#define FT_RRB_PAIRWISE 11 /* le16 */
80
81struct ft_rrb_tlv {
82 le16 type;
83 le16 len;
84 /* followed by data of length len */
6fc6879b
JM
85} STRUCT_PACKED;
86
eefe8630
MB
87struct ft_rrb_seq {
88 le32 dom;
89 le32 seq;
90 le32 ts;
91} STRUCT_PACKED;
92
245fc96e
MB
93/* session TLVs:
94 * required: PMK_R1, PMK_R1_NAME, PAIRWISE
95 *
96 * pull frame TLVs:
97 * auth:
eefe8630 98 * required: SEQ, NONCE, R0KH_ID, R1KH_ID
245fc96e
MB
99 * encrypted:
100 * required: PMK_R0_NAME, S1KH_ID
101 *
102 * response frame TLVs:
103 * auth:
eefe8630 104 * required: SEQ, NONCE, R0KH_ID, R1KH_ID
245fc96e 105 * encrypted:
3a46cf93
MB
106 * required: S1KH_ID
107 * optional: session TLVs
245fc96e
MB
108 *
109 * push frame TLVs:
110 * auth:
eefe8630 111 * required: SEQ, R0KH_ID, R1KH_ID
245fc96e
MB
112 * encrypted:
113 * required: S1KH_ID, PMK_R0_NAME, session TLVs
eefe8630
MB
114 *
115 * sequence number request frame TLVs:
116 * auth:
117 * required: R0KH_ID, R1KH_ID, NONCE
118 *
119 * sequence number response frame TLVs:
120 * auth:
121 * required: SEQ, NONCE, R0KH_ID, R1KH_ID
245fc96e
MB
122 */
123
6fc6879b
JM
124#ifdef _MSC_VER
125#pragma pack(pop)
126#endif /* _MSC_VER */
127
128
129/* per STA state machine data */
130
131struct wpa_authenticator;
132struct wpa_state_machine;
133struct rsn_pmksa_cache_entry;
134struct eapol_state_machine;
eefe8630 135struct ft_remote_seq;
6fc6879b
JM
136
137
138struct ft_remote_r0kh {
139 struct ft_remote_r0kh *next;
140 u8 addr[ETH_ALEN];
141 u8 id[FT_R0KH_ID_MAX_LEN];
142 size_t id_len;
245fc96e 143 u8 key[32];
eefe8630 144 struct ft_remote_seq *seq;
6fc6879b
JM
145};
146
147
148struct ft_remote_r1kh {
149 struct ft_remote_r1kh *next;
150 u8 addr[ETH_ALEN];
151 u8 id[FT_R1KH_ID_LEN];
245fc96e 152 u8 key[32];
eefe8630 153 struct ft_remote_seq *seq;
6fc6879b
JM
154};
155
156
157struct wpa_auth_config {
158 int wpa;
159 int wpa_key_mgmt;
160 int wpa_pairwise;
161 int wpa_group;
162 int wpa_group_rekey;
163 int wpa_strict_rekey;
164 int wpa_gmk_rekey;
581a8cde 165 int wpa_ptk_rekey;
41f140d3
GK
166 u32 wpa_group_update_count;
167 u32 wpa_pairwise_update_count;
6fc6879b
JM
168 int rsn_pairwise;
169 int rsn_preauth;
170 int eapol_version;
171 int peerkey;
3ae0800c 172 int wmm_enabled;
721abef9 173 int wmm_uapsd;
cb465555 174 int disable_pmksa_caching;
bf98f7f3 175 int okc;
e4bf4db9 176 int tx_status;
6fc6879b 177#ifdef CONFIG_IEEE80211W
70f8cc8e 178 enum mfp_options ieee80211w;
8dd9f9cd 179 int group_mgmt_cipher;
6fc6879b 180#endif /* CONFIG_IEEE80211W */
4ec1fd8e 181#ifdef CONFIG_IEEE80211R_AP
d6c3067d 182 u8 ssid[SSID_MAX_LEN];
6fc6879b
JM
183 size_t ssid_len;
184 u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
185 u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
186 size_t r0_key_holder_len;
187 u8 r1_key_holder[FT_R1KH_ID_LEN];
188 u32 r0_key_lifetime;
3a46cf93
MB
189 int rkh_pos_timeout;
190 int rkh_neg_timeout;
191 int rkh_pull_timeout; /* ms */
192 int rkh_pull_retries;
6fc6879b 193 u32 reassociation_deadline;
3a46cf93
MB
194 struct ft_remote_r0kh **r0kh_list;
195 struct ft_remote_r1kh **r1kh_list;
6fc6879b 196 int pmk_r1_push;
d7956add 197 int ft_over_ds;
96590564 198 int ft_psk_generate_local;
4ec1fd8e 199#endif /* CONFIG_IEEE80211R_AP */
83421850 200 int disable_gtk;
88b32a99 201 int ap_mlme;
7af092a0
JB
202#ifdef CONFIG_TESTING_OPTIONS
203 double corrupt_gtk_rekey_mic_probability;
bc02843e
JM
204 u8 own_ie_override[MAX_OWN_IE_OVERRIDE];
205 size_t own_ie_override_len;
7af092a0 206#endif /* CONFIG_TESTING_OPTIONS */
25ef8529
JM
207#ifdef CONFIG_P2P
208 u8 ip_addr_go[4];
209 u8 ip_addr_mask[4];
210 u8 ip_addr_start[4];
211 u8 ip_addr_end[4];
212#endif /* CONFIG_P2P */
7eace378
JM
213#ifdef CONFIG_FILS
214 unsigned int fils_cache_id_set:1;
215 u8 fils_cache_id[FILS_CACHE_ID_LEN];
216#endif /* CONFIG_FILS */
6fc6879b
JM
217};
218
219typedef enum {
220 LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
221} logger_level;
222
223typedef enum {
224 WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
225 WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
226 WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
227} wpa_eapol_variable;
228
229struct wpa_auth_callbacks {
6fc6879b
JM
230 void (*logger)(void *ctx, const u8 *addr, logger_level level,
231 const char *txt);
232 void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
c772d054 233 int (*mic_failure_report)(void *ctx, const u8 *addr);
2c502460 234 void (*psk_failure_report)(void *ctx, const u8 *addr);
6fc6879b
JM
235 void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
236 int value);
237 int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
759fd76b
JM
238 const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
239 const u8 *prev_psk);
6fc6879b 240 int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
71934751
JM
241 int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
242 const u8 *addr, int idx, u8 *key, size_t key_len);
6fc6879b 243 int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
6fc6879b
JM
244 int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
245 size_t data_len, int encrypt);
246 int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
247 void *ctx), void *cb_ctx);
bf98f7f3
JM
248 int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
249 void *ctx), void *cb_ctx);
6fc6879b
JM
250 int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
251 size_t data_len);
50bd8e0a
MB
252 int (*send_oui)(void *ctx, const u8 *dst, u8 oui_suffix, const u8 *data,
253 size_t data_len);
4ec1fd8e 254#ifdef CONFIG_IEEE80211R_AP
6fc6879b
JM
255 struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
256 int (*send_ft_action)(void *ctx, const u8 *dst,
257 const u8 *data, size_t data_len);
88b32a99 258 int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
006309b5 259 size_t tspec_ielen);
4ec1fd8e 260#endif /* CONFIG_IEEE80211R_AP */
0f950df0
TP
261#ifdef CONFIG_MESH
262 int (*start_ampe)(void *ctx, const u8 *sta_addr);
263#endif /* CONFIG_MESH */
6fc6879b
JM
264};
265
266struct wpa_authenticator * wpa_init(const u8 *addr,
267 struct wpa_auth_config *conf,
cef8fac0
JB
268 const struct wpa_auth_callbacks *cb,
269 void *cb_ctx);
bdffdc5d 270int wpa_init_keys(struct wpa_authenticator *wpa_auth);
6fc6879b
JM
271void wpa_deinit(struct wpa_authenticator *wpa_auth);
272int wpa_reconfig(struct wpa_authenticator *wpa_auth,
273 struct wpa_auth_config *conf);
274
275enum {
276 WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
277 WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
278 WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
2100a768 279 WPA_INVALID_MDIE, WPA_INVALID_PROTO
6fc6879b 280};
91d91abf 281
6fc6879b
JM
282int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
283 struct wpa_state_machine *sm,
284 const u8 *wpa_ie, size_t wpa_ie_len,
09368515
JM
285 const u8 *mdie, size_t mdie_len,
286 const u8 *owe_dh, size_t owe_dh_len);
a14896e8
JM
287int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
288 struct wpa_state_machine *sm,
289 const u8 *osen_ie, size_t osen_ie_len);
f3f7540e 290int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
6fc6879b 291struct wpa_state_machine *
94ddef3e
JM
292wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
293 const u8 *p2p_dev_addr);
6f9b5d16
JM
294int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
295 struct wpa_state_machine *sm);
a8d05fca 296void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
6fc6879b
JM
297void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
298void wpa_receive(struct wpa_authenticator *wpa_auth,
299 struct wpa_state_machine *sm,
300 u8 *data, size_t data_len);
bb119228 301enum wpa_event {
6fc6879b 302 WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
957bff83 303 WPA_REAUTH_EAPOL, WPA_ASSOC_FT, WPA_ASSOC_FILS
bb119228 304};
6fc6879b 305void wpa_remove_ptk(struct wpa_state_machine *sm);
bb119228 306int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
6fc6879b
JM
307void wpa_auth_sm_notify(struct wpa_state_machine *sm);
308void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
309int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
310int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
311void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
312int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
ff36ff00 313int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
6fc6879b
JM
314int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
315int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
316int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
317 struct rsn_pmksa_cache_entry *entry);
318struct rsn_pmksa_cache_entry *
319wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
320void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
321const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
322 size_t *len);
323int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
207976f0 324 unsigned int pmk_len,
6fc6879b
JM
325 int session_timeout, struct eapol_state_machine *eapol);
326int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
327 const u8 *pmk, size_t len, const u8 *sta_addr,
328 int session_timeout,
329 struct eapol_state_machine *eapol);
f2991170 330int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
70c93963 331 const u8 *pmk, const u8 *pmkid);
901d1fe1
JM
332void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
333 const u8 *sta_addr);
b8daac18
MH
334int wpa_auth_pmksa_list(struct wpa_authenticator *wpa_auth, char *buf,
335 size_t len);
4c522c77 336void wpa_auth_pmksa_flush(struct wpa_authenticator *wpa_auth);
4d77d80e
MH
337int wpa_auth_pmksa_list_mesh(struct wpa_authenticator *wpa_auth, const u8 *addr,
338 char *buf, size_t len);
339struct rsn_pmksa_cache_entry *
340wpa_auth_pmksa_create_entry(const u8 *aa, const u8 *spa, const u8 *pmk,
341 const u8 *pmkid, int expiration);
342int wpa_auth_pmksa_add_entry(struct wpa_authenticator *wpa_auth,
343 struct rsn_pmksa_cache_entry *entry);
9f2cf23e 344struct rsn_pmksa_cache_entry *
c1bd4bac
JM
345wpa_auth_pmksa_get(struct wpa_authenticator *wpa_auth, const u8 *sta_addr,
346 const u8 *pmkid);
7eace378
JM
347struct rsn_pmksa_cache_entry *
348wpa_auth_pmksa_get_fils_cache_id(struct wpa_authenticator *wpa_auth,
349 const u8 *sta_addr, const u8 *pmkid);
9f2cf23e
MH
350void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry *pmksa,
351 struct wpa_state_machine *sm,
352 struct wpa_authenticator *wpa_auth,
353 u8 *pmkid, u8 *pmk);
6fc6879b 354int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
e4bf4db9
JM
355void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
356 struct wpa_state_machine *sm, int ack);
6fc6879b 357
4ec1fd8e 358#ifdef CONFIG_IEEE80211R_AP
6fc6879b 359u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
f238cf9f
JM
360 size_t max_len, int auth_alg,
361 const u8 *req_ies, size_t req_ies_len);
6fc6879b
JM
362void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
363 u16 auth_transaction, const u8 *ies, size_t ies_len,
364 void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
365 u16 auth_transaction, u16 resp,
366 const u8 *ies, size_t ies_len),
367 void *ctx);
368u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
369 size_t ies_len);
370int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
371int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
372 const u8 *data, size_t data_len);
50bd8e0a
MB
373void wpa_ft_rrb_oui_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
374 const u8 *dst_addr, u8 oui_suffix, const u8 *data,
375 size_t data_len);
6fc6879b 376void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
eefe8630 377void wpa_ft_deinit(struct wpa_authenticator *wpa_auth);
3a46cf93 378void wpa_ft_sta_deinit(struct wpa_state_machine *sm);
4ec1fd8e 379#endif /* CONFIG_IEEE80211R_AP */
6fc6879b 380
d32d94db
XC
381void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
382void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
383int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
d32d94db 384int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
d32d94db 385
c10347f2 386int wpa_auth_uses_sae(struct wpa_state_machine *sm);
aa189ac9 387int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
c10347f2 388
25ef8529
JM
389int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
390
cbc210de
JM
391struct radius_das_attrs;
392int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
393 struct radius_das_attrs *attr);
34782730 394void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth);
cbc210de 395
7cebc8e2
MB
396int wpa_auth_ensure_group(struct wpa_authenticator *wpa_auth, int vlan_id);
397int wpa_auth_release_group(struct wpa_authenticator *wpa_auth, int vlan_id);
c4fd6d8a
JM
398int fils_auth_pmk_to_ptk(struct wpa_state_machine *sm, const u8 *pmk,
399 size_t pmk_len, const u8 *snonce, const u8 *anonce);
78815f3d
JM
400int fils_decrypt_assoc(struct wpa_state_machine *sm, const u8 *fils_session,
401 const struct ieee80211_mgmt *mgmt, size_t frame_len,
402 u8 *pos, size_t left);
e73ffa09 403int fils_encrypt_assoc(struct wpa_state_machine *sm, u8 *buf,
91d91abf
JM
404 size_t current_len, size_t max_len,
405 const struct wpabuf *hlp);
da24c5aa 406int fils_set_tk(struct wpa_state_machine *sm);
fa61bff6
JM
407u8 * hostapd_eid_assoc_fils_session(struct wpa_state_machine *sm, u8 *eid,
408 const u8 *fils_session);
087631b9
JM
409const u8 * wpa_fils_validate_fils_session(struct wpa_state_machine *sm,
410 const u8 *ies, size_t ies_len,
411 const u8 *fils_session);
bd599353
JM
412int wpa_fils_validate_key_confirm(struct wpa_state_machine *sm, const u8 *ies,
413 size_t ies_len);
7cebc8e2 414
5db997e3 415int wpa_auth_write_fte(struct wpa_authenticator *wpa_auth, u8 *buf, size_t len);
8acbf85f
JM
416void wpa_auth_get_fils_aead_params(struct wpa_state_machine *sm,
417 u8 *fils_anonce, u8 *fils_snonce,
418 u8 *fils_kek, size_t *fils_kek_len);
5db997e3 419
6fc6879b 420#endif /* WPA_AUTH_H */