blob: 3ab3e3d5d084ed85cde9b7fa0a2bb80b0db0ee65 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd - IEEE 802.11i-2004 / WPA Authenticator
3 * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
4 *
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"
15
16#ifdef _MSC_VER
17#pragma pack(push, 1)
18#endif /* _MSC_VER */
19
20/* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition
21 */
22struct ft_rrb_frame {
23 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
24 u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
25 le16 action_length; /* little endian length of action_frame */
26 u8 ap_address[ETH_ALEN];
27 /*
28 * Followed by action_length bytes of FT Action frame (from Category
29 * field to the end of Action Frame body.
30 */
31} STRUCT_PACKED;
32
33#define RSN_REMOTE_FRAME_TYPE_FT_RRB 1
34
35#define FT_PACKET_REQUEST 0
36#define FT_PACKET_RESPONSE 1
37/* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r */
38#define FT_PACKET_R0KH_R1KH_PULL 200
39#define FT_PACKET_R0KH_R1KH_RESP 201
40#define FT_PACKET_R0KH_R1KH_PUSH 202
41
42#define FT_R0KH_R1KH_PULL_DATA_LEN 44
43#define FT_R0KH_R1KH_RESP_DATA_LEN 76
44#define FT_R0KH_R1KH_PUSH_DATA_LEN 88
45
46struct ft_r0kh_r1kh_pull_frame {
47 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
48 u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */
49 le16 data_length; /* little endian length of data (44) */
50 u8 ap_address[ETH_ALEN];
51
52 u8 nonce[16];
53 u8 pmk_r0_name[WPA_PMK_NAME_LEN];
54 u8 r1kh_id[FT_R1KH_ID_LEN];
55 u8 s1kh_id[ETH_ALEN];
56 u8 pad[4]; /* 8-octet boundary for AES key wrap */
57 u8 key_wrap_extra[8];
58} STRUCT_PACKED;
59
60struct ft_r0kh_r1kh_resp_frame {
61 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
62 u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */
63 le16 data_length; /* little endian length of data (76) */
64 u8 ap_address[ETH_ALEN];
65
66 u8 nonce[16]; /* copied from pull */
67 u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
68 u8 s1kh_id[ETH_ALEN]; /* copied from pull */
69 u8 pmk_r1[PMK_LEN];
70 u8 pmk_r1_name[WPA_PMK_NAME_LEN];
71 le16 pairwise;
72 u8 pad[2]; /* 8-octet boundary for AES key wrap */
73 u8 key_wrap_extra[8];
74} STRUCT_PACKED;
75
76struct ft_r0kh_r1kh_push_frame {
77 u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
78 u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
79 le16 data_length; /* little endian length of data (88) */
80 u8 ap_address[ETH_ALEN];
81
82 /* Encrypted with AES key-wrap */
83 u8 timestamp[4]; /* current time in seconds since unix epoch, little
84 * endian */
85 u8 r1kh_id[FT_R1KH_ID_LEN];
86 u8 s1kh_id[ETH_ALEN];
87 u8 pmk_r0_name[WPA_PMK_NAME_LEN];
88 u8 pmk_r1[PMK_LEN];
89 u8 pmk_r1_name[WPA_PMK_NAME_LEN];
90 le16 pairwise;
91 u8 pad[6]; /* 8-octet boundary for AES key wrap */
92 u8 key_wrap_extra[8];
93} STRUCT_PACKED;
94
95#ifdef _MSC_VER
96#pragma pack(pop)
97#endif /* _MSC_VER */
98
99
100/* per STA state machine data */
101
102struct wpa_authenticator;
103struct wpa_state_machine;
104struct rsn_pmksa_cache_entry;
105struct eapol_state_machine;
106
107
108struct ft_remote_r0kh {
109 struct ft_remote_r0kh *next;
110 u8 addr[ETH_ALEN];
111 u8 id[FT_R0KH_ID_MAX_LEN];
112 size_t id_len;
113 u8 key[16];
114};
115
116
117struct ft_remote_r1kh {
118 struct ft_remote_r1kh *next;
119 u8 addr[ETH_ALEN];
120 u8 id[FT_R1KH_ID_LEN];
121 u8 key[16];
122};
123
124
125struct wpa_auth_config {
126 int wpa;
127 int wpa_key_mgmt;
128 int wpa_pairwise;
129 int wpa_group;
130 int wpa_group_rekey;
131 int wpa_strict_rekey;
132 int wpa_gmk_rekey;
133 int wpa_ptk_rekey;
134 int rsn_pairwise;
135 int rsn_preauth;
136 int eapol_version;
137 int peerkey;
138 int wmm_enabled;
139 int wmm_uapsd;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700140 int disable_pmksa_caching;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700141 int okc;
142 int tx_status;
143#ifdef CONFIG_IEEE80211W
144 enum mfp_options ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700145 int group_mgmt_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700146#endif /* CONFIG_IEEE80211W */
147#ifdef CONFIG_IEEE80211R
148#define SSID_LEN 32
149 u8 ssid[SSID_LEN];
150 size_t ssid_len;
151 u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
152 u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
153 size_t r0_key_holder_len;
154 u8 r1_key_holder[FT_R1KH_ID_LEN];
155 u32 r0_key_lifetime;
156 u32 reassociation_deadline;
157 struct ft_remote_r0kh *r0kh_list;
158 struct ft_remote_r1kh *r1kh_list;
159 int pmk_r1_push;
160 int ft_over_ds;
161#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700162 int disable_gtk;
163 int ap_mlme;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700164#ifdef CONFIG_TESTING_OPTIONS
165 double corrupt_gtk_rekey_mic_probability;
166#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800167#ifdef CONFIG_P2P
168 u8 ip_addr_go[4];
169 u8 ip_addr_mask[4];
170 u8 ip_addr_start[4];
171 u8 ip_addr_end[4];
172#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173};
174
175typedef enum {
176 LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
177} logger_level;
178
179typedef enum {
180 WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
181 WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
182 WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
183} wpa_eapol_variable;
184
185struct wpa_auth_callbacks {
186 void *ctx;
187 void (*logger)(void *ctx, const u8 *addr, logger_level level,
188 const char *txt);
189 void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800190 int (*mic_failure_report)(void *ctx, const u8 *addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191 void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
192 int value);
193 int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700194 const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
195 const u8 *prev_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196 int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
197 int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
198 const u8 *addr, int idx, u8 *key, size_t key_len);
199 int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
200 int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
201 size_t data_len, int encrypt);
202 int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
203 void *ctx), void *cb_ctx);
204 int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
205 void *ctx), void *cb_ctx);
206 int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
207 size_t data_len);
208#ifdef CONFIG_IEEE80211R
209 struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
210 int (*send_ft_action)(void *ctx, const u8 *dst,
211 const u8 *data, size_t data_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700212 int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800213 size_t tspec_ielen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214#endif /* CONFIG_IEEE80211R */
215};
216
217struct wpa_authenticator * wpa_init(const u8 *addr,
218 struct wpa_auth_config *conf,
219 struct wpa_auth_callbacks *cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800220int wpa_init_keys(struct wpa_authenticator *wpa_auth);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221void wpa_deinit(struct wpa_authenticator *wpa_auth);
222int wpa_reconfig(struct wpa_authenticator *wpa_auth,
223 struct wpa_auth_config *conf);
224
225enum {
226 WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
227 WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
228 WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
229 WPA_INVALID_MDIE, WPA_INVALID_PROTO
230};
231
232int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
233 struct wpa_state_machine *sm,
234 const u8 *wpa_ie, size_t wpa_ie_len,
235 const u8 *mdie, size_t mdie_len);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800236int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
237 struct wpa_state_machine *sm,
238 const u8 *osen_ie, size_t osen_ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
240struct wpa_state_machine *
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700241wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
242 const u8 *p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
244 struct wpa_state_machine *sm);
245void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
246void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
247void wpa_receive(struct wpa_authenticator *wpa_auth,
248 struct wpa_state_machine *sm,
249 u8 *data, size_t data_len);
250typedef enum {
251 WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
252 WPA_REAUTH_EAPOL, WPA_ASSOC_FT
253} wpa_event;
254void wpa_remove_ptk(struct wpa_state_machine *sm);
255int wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event);
256void wpa_auth_sm_notify(struct wpa_state_machine *sm);
257void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
258int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
259int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
260void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
261int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
262int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
263int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
264int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
265int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
266 struct rsn_pmksa_cache_entry *entry);
267struct rsn_pmksa_cache_entry *
268wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
269void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
270const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
271 size_t *len);
272int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
273 int session_timeout, struct eapol_state_machine *eapol);
274int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
275 const u8 *pmk, size_t len, const u8 *sta_addr,
276 int session_timeout,
277 struct eapol_state_machine *eapol);
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700278void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
279 const u8 *sta_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
281void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
282 struct wpa_state_machine *sm, int ack);
283
284#ifdef CONFIG_IEEE80211R
285u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
286 size_t max_len, int auth_alg,
287 const u8 *req_ies, size_t req_ies_len);
288void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
289 u16 auth_transaction, const u8 *ies, size_t ies_len,
290 void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
291 u16 auth_transaction, u16 resp,
292 const u8 *ies, size_t ies_len),
293 void *ctx);
294u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
295 size_t ies_len);
296int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
297int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
298 const u8 *data, size_t data_len);
299void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
300#endif /* CONFIG_IEEE80211R */
301
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700302void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
303void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
304int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700305int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700306
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800307int wpa_auth_uses_sae(struct wpa_state_machine *sm);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800308int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800309
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800310int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312#endif /* WPA_AUTH_H */