Fix small HTTP processing issues
[wpasupplicant] / hostapd / wpa.h
1 /*
2  * hostapd - IEEE 802.11i-2004 / WPA Authenticator
3  * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef WPA_AUTH_H
16 #define WPA_AUTH_H
17
18 #include "defs.h"
19 #include "eapol_common.h"
20 #include "wpa_common.h"
21
22 #ifdef _MSC_VER
23 #pragma pack(push, 1)
24 #endif /* _MSC_VER */
25
26 /* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition
27  */
28 struct ft_rrb_frame {
29         u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
30         u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
31         le16 action_length; /* little endian length of action_frame */
32         u8 ap_address[ETH_ALEN];
33         /*
34          * Followed by action_length bytes of FT Action frame (from Category
35          * field to the end of Action Frame body.
36          */
37 } STRUCT_PACKED;
38
39 #define RSN_REMOTE_FRAME_TYPE_FT_RRB 1
40
41 #define FT_PACKET_REQUEST 0
42 #define FT_PACKET_RESPONSE 1
43 /* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r */
44 #define FT_PACKET_R0KH_R1KH_PULL 200
45 #define FT_PACKET_R0KH_R1KH_RESP 201
46 #define FT_PACKET_R0KH_R1KH_PUSH 202
47
48 #ifndef ETH_P_RRB
49 #define ETH_P_RRB 0x890D
50 #endif /* ETH_P_RRB */
51
52 #define FT_R0KH_R1KH_PULL_DATA_LEN 44
53 #define FT_R0KH_R1KH_RESP_DATA_LEN 76
54 #define FT_R0KH_R1KH_PUSH_DATA_LEN 80
55
56 struct ft_r0kh_r1kh_pull_frame {
57         u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
58         u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */
59         le16 data_length; /* little endian length of data (44) */
60         u8 ap_address[ETH_ALEN];
61
62         u8 nonce[16];
63         u8 pmk_r0_name[WPA_PMK_NAME_LEN];
64         u8 r1kh_id[FT_R1KH_ID_LEN];
65         u8 s1kh_id[ETH_ALEN];
66         u8 pad[4]; /* 8-octet boundary for AES key wrap */
67         u8 key_wrap_extra[8];
68 } STRUCT_PACKED;
69
70 struct ft_r0kh_r1kh_resp_frame {
71         u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
72         u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */
73         le16 data_length; /* little endian length of data (76) */
74         u8 ap_address[ETH_ALEN];
75
76         u8 nonce[16]; /* copied from pull */
77         u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
78         u8 s1kh_id[ETH_ALEN]; /* copied from pull */
79         u8 pmk_r1[PMK_LEN];
80         u8 pmk_r1_name[WPA_PMK_NAME_LEN];
81         u8 pad[4]; /* 8-octet boundary for AES key wrap */
82         u8 key_wrap_extra[8];
83 } STRUCT_PACKED;
84
85 struct ft_r0kh_r1kh_push_frame {
86         u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
87         u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
88         le16 data_length; /* little endian length of data (80) */
89         u8 ap_address[ETH_ALEN];
90
91         /* Encrypted with AES key-wrap */
92         u8 timestamp[4]; /* current time in seconds since unix epoch, little
93                           * endian */
94         u8 r1kh_id[FT_R1KH_ID_LEN];
95         u8 s1kh_id[ETH_ALEN];
96         u8 pmk_r0_name[WPA_PMK_NAME_LEN];
97         u8 pmk_r1[PMK_LEN];
98         u8 pmk_r1_name[WPA_PMK_NAME_LEN];
99         u8 key_wrap_extra[8];
100 } STRUCT_PACKED;
101
102 #ifdef _MSC_VER
103 #pragma pack(pop)
104 #endif /* _MSC_VER */
105
106
107 /* per STA state machine data */
108
109 struct wpa_authenticator;
110 struct wpa_state_machine;
111 struct rsn_pmksa_cache_entry;
112 struct eapol_state_machine;
113
114
115 struct ft_remote_r0kh {
116         struct ft_remote_r0kh *next;
117         u8 addr[ETH_ALEN];
118         u8 id[FT_R0KH_ID_MAX_LEN];
119         size_t id_len;
120         u8 key[16];
121 };
122
123
124 struct ft_remote_r1kh {
125         struct ft_remote_r1kh *next;
126         u8 addr[ETH_ALEN];
127         u8 id[FT_R1KH_ID_LEN];
128         u8 key[16];
129 };
130
131
132 struct wpa_auth_config {
133         int wpa;
134         int wpa_key_mgmt;
135         int wpa_pairwise;
136         int wpa_group;
137         int wpa_group_rekey;
138         int wpa_strict_rekey;
139         int wpa_gmk_rekey;
140         int wpa_ptk_rekey;
141         int rsn_pairwise;
142         int rsn_preauth;
143         int eapol_version;
144         int peerkey;
145         int wmm_enabled;
146         int okc;
147 #ifdef CONFIG_IEEE80211W
148         enum {
149                 WPA_NO_IEEE80211W = 0,
150                 WPA_IEEE80211W_OPTIONAL = 1,
151                 WPA_IEEE80211W_REQUIRED = 2
152         } ieee80211w;
153 #endif /* CONFIG_IEEE80211W */
154 #ifdef CONFIG_IEEE80211R
155 #define SSID_LEN 32
156         u8 ssid[SSID_LEN];
157         size_t ssid_len;
158         u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
159         u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
160         size_t r0_key_holder_len;
161         u8 r1_key_holder[FT_R1KH_ID_LEN];
162         u32 r0_key_lifetime;
163         u32 reassociation_deadline;
164         struct ft_remote_r0kh *r0kh_list;
165         struct ft_remote_r1kh *r1kh_list;
166         int pmk_r1_push;
167 #endif /* CONFIG_IEEE80211R */
168 };
169
170 typedef enum {
171         LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
172 } logger_level;
173
174 typedef enum {
175         WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
176         WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
177         WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
178 } wpa_eapol_variable;
179
180 struct wpa_auth_callbacks {
181         void *ctx;
182         void (*logger)(void *ctx, const u8 *addr, logger_level level,
183                        const char *txt);
184         void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
185         void (*mic_failure_report)(void *ctx, const u8 *addr);
186         void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
187                           int value);
188         int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
189         const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *prev_psk);
190         int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
191         int (*set_key)(void *ctx, int vlan_id, wpa_alg alg, const u8 *addr,
192                        int idx, u8 *key, size_t key_len);
193         int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
194         int (*get_seqnum_igtk)(void *ctx, const u8 *addr, int idx, u8 *seq);
195         int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
196                           size_t data_len, int encrypt);
197         int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
198                                                  void *ctx), void *cb_ctx);
199         int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
200                                                   void *ctx), void *cb_ctx);
201         int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
202                           size_t data_len);
203 #ifdef CONFIG_IEEE80211R
204         struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
205         int (*send_ft_action)(void *ctx, const u8 *dst,
206                               const u8 *data, size_t data_len);
207 #endif /* CONFIG_IEEE80211R */
208 };
209
210 struct wpa_authenticator * wpa_init(const u8 *addr,
211                                     struct wpa_auth_config *conf,
212                                     struct wpa_auth_callbacks *cb);
213 void wpa_deinit(struct wpa_authenticator *wpa_auth);
214 int wpa_reconfig(struct wpa_authenticator *wpa_auth,
215                  struct wpa_auth_config *conf);
216
217 enum {
218         WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
219         WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
220         WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
221         WPA_INVALID_MDIE, WPA_INVALID_PROTO
222 };
223         
224 int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
225                         struct wpa_state_machine *sm,
226                         const u8 *wpa_ie, size_t wpa_ie_len,
227                         const u8 *mdie, size_t mdie_len);
228 int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
229 struct wpa_state_machine *
230 wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr);
231 void wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
232                              struct wpa_state_machine *sm);
233 void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
234 void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
235 void wpa_receive(struct wpa_authenticator *wpa_auth,
236                  struct wpa_state_machine *sm,
237                  u8 *data, size_t data_len);
238 typedef enum {
239         WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
240         WPA_REAUTH_EAPOL, WPA_ASSOC_FT
241 } wpa_event;
242 void wpa_remove_ptk(struct wpa_state_machine *sm);
243 void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event);
244 void wpa_auth_sm_notify(struct wpa_state_machine *sm);
245 void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
246 int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
247 int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
248 void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
249 int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
250 int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
251 int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
252 int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
253 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
254                              struct rsn_pmksa_cache_entry *entry);
255 struct rsn_pmksa_cache_entry *
256 wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
257 void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
258 const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
259                                size_t *len);
260 int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
261                        int session_timeout, struct eapol_state_machine *eapol);
262 int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
263                                const u8 *pmk, size_t len, const u8 *sta_addr,
264                                int session_timeout,
265                                struct eapol_state_machine *eapol);
266 int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
267
268 #ifdef CONFIG_IEEE80211R
269 u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
270                                  size_t max_len, int auth_alg,
271                                  const u8 *req_ies, size_t req_ies_len);
272 void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
273                          u16 auth_transaction, const u8 *ies, size_t ies_len,
274                          void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
275                                     u16 auth_transaction, u16 resp,
276                                     const u8 *ies, size_t ies_len),
277                          void *ctx);
278 u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
279                             size_t ies_len);
280 int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
281 int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
282                   const u8 *data, size_t data_len);
283 void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
284 #endif /* CONFIG_IEEE80211R */
285
286 #endif /* WPA_AUTH_H */