WPS ER: Do not try to process AP Settings in proxied M7 to ER
[libeap.git] / src / wps / wps_i.h
1 /*
2  * Wi-Fi Protected Setup - internal definitions
3  * Copyright (c) 2008-2009, 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 WPS_I_H
16 #define WPS_I_H
17
18 #include "wps.h"
19
20 /**
21  * struct wps_data - WPS registration protocol data
22  *
23  * This data is stored at the EAP-WSC server/peer method and it is kept for a
24  * single registration protocol run.
25  */
26 struct wps_data {
27         /**
28          * wps - Pointer to long term WPS context
29          */
30         struct wps_context *wps;
31
32         /**
33          * registrar - Whether this end is a Registrar
34          */
35         int registrar;
36
37         /**
38          * er - Whether the local end is an external registrar
39          */
40         int er;
41
42         enum {
43                 /* Enrollee states */
44                 SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7,
45                 RECV_M8, RECEIVED_M2D, WPS_MSG_DONE, RECV_ACK, WPS_FINISHED,
46                 SEND_WSC_NACK,
47
48                 /* Registrar states */
49                 RECV_M1, SEND_M2, RECV_M3, SEND_M4, RECV_M5, SEND_M6,
50                 RECV_M7, SEND_M8, RECV_DONE, SEND_M2D, RECV_M2D_ACK
51         } state;
52
53         u8 uuid_e[WPS_UUID_LEN];
54         u8 uuid_r[WPS_UUID_LEN];
55         u8 mac_addr_e[ETH_ALEN];
56         u8 nonce_e[WPS_NONCE_LEN];
57         u8 nonce_r[WPS_NONCE_LEN];
58         u8 psk1[WPS_PSK_LEN];
59         u8 psk2[WPS_PSK_LEN];
60         u8 snonce[2 * WPS_SECRET_NONCE_LEN];
61         u8 peer_hash1[WPS_HASH_LEN];
62         u8 peer_hash2[WPS_HASH_LEN];
63
64         struct wpabuf *dh_privkey;
65         struct wpabuf *dh_pubkey_e;
66         struct wpabuf *dh_pubkey_r;
67         u8 authkey[WPS_AUTHKEY_LEN];
68         u8 keywrapkey[WPS_KEYWRAPKEY_LEN];
69         u8 emsk[WPS_EMSK_LEN];
70
71         struct wpabuf *last_msg;
72
73         u8 *dev_password;
74         size_t dev_password_len;
75         u16 dev_pw_id;
76         int pbc;
77
78         /**
79          * request_type - Request Type attribute from (Re)AssocReq
80          */
81         u8 request_type;
82
83         /**
84          * encr_type - Available encryption types
85          */
86         u16 encr_type;
87
88         /**
89          * auth_type - Available authentication types
90          */
91         u16 auth_type;
92
93         u8 *new_psk;
94         size_t new_psk_len;
95
96         int wps_pin_revealed;
97         struct wps_credential cred;
98
99         struct wps_device_data peer_dev;
100
101         /**
102          * config_error - Configuration Error value to be used in NACK
103          */
104         u16 config_error;
105
106         int ext_reg;
107
108         struct wps_credential *new_ap_settings;
109
110         void *dh_ctx;
111 };
112
113
114 struct wps_parse_attr {
115         /* fixed length fields */
116         const u8 *version; /* 1 octet */
117         const u8 *msg_type; /* 1 octet */
118         const u8 *enrollee_nonce; /* WPS_NONCE_LEN (16) octets */
119         const u8 *registrar_nonce; /* WPS_NONCE_LEN (16) octets */
120         const u8 *uuid_r; /* WPS_UUID_LEN (16) octets */
121         const u8 *uuid_e; /* WPS_UUID_LEN (16) octets */
122         const u8 *auth_type_flags; /* 2 octets */
123         const u8 *encr_type_flags; /* 2 octets */
124         const u8 *conn_type_flags; /* 1 octet */
125         const u8 *config_methods; /* 2 octets */
126         const u8 *sel_reg_config_methods; /* 2 octets */
127         const u8 *primary_dev_type; /* 8 octets */
128         const u8 *rf_bands; /* 1 octet */
129         const u8 *assoc_state; /* 2 octets */
130         const u8 *config_error; /* 2 octets */
131         const u8 *dev_password_id; /* 2 octets */
132         const u8 *oob_dev_password; /* WPS_OOB_DEVICE_PASSWORD_ATTR_LEN (54)
133                                      * octets */
134         const u8 *os_version; /* 4 octets */
135         const u8 *wps_state; /* 1 octet */
136         const u8 *authenticator; /* WPS_AUTHENTICATOR_LEN (8) octets */
137         const u8 *r_hash1; /* WPS_HASH_LEN (32) octets */
138         const u8 *r_hash2; /* WPS_HASH_LEN (32) octets */
139         const u8 *e_hash1; /* WPS_HASH_LEN (32) octets */
140         const u8 *e_hash2; /* WPS_HASH_LEN (32) octets */
141         const u8 *r_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
142         const u8 *r_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
143         const u8 *e_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
144         const u8 *e_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
145         const u8 *key_wrap_auth; /* WPS_KWA_LEN (8) octets */
146         const u8 *auth_type; /* 2 octets */
147         const u8 *encr_type; /* 2 octets */
148         const u8 *network_idx; /* 1 octet */
149         const u8 *network_key_idx; /* 1 octet */
150         const u8 *mac_addr; /* ETH_ALEN (6) octets */
151         const u8 *key_prov_auto; /* 1 octet (Bool) */
152         const u8 *dot1x_enabled; /* 1 octet (Bool) */
153         const u8 *selected_registrar; /* 1 octet (Bool) */
154         const u8 *request_type; /* 1 octet */
155         const u8 *response_type; /* 1 octet */
156         const u8 *ap_setup_locked; /* 1 octet */
157
158         /* variable length fields */
159         const u8 *manufacturer;
160         size_t manufacturer_len;
161         const u8 *model_name;
162         size_t model_name_len;
163         const u8 *model_number;
164         size_t model_number_len;
165         const u8 *serial_number;
166         size_t serial_number_len;
167         const u8 *dev_name;
168         size_t dev_name_len;
169         const u8 *public_key;
170         size_t public_key_len;
171         const u8 *encr_settings;
172         size_t encr_settings_len;
173         const u8 *ssid; /* <= 32 octets */
174         size_t ssid_len;
175         const u8 *network_key; /* <= 64 octets */
176         size_t network_key_len;
177         const u8 *eap_type; /* <= 8 octets */
178         size_t eap_type_len;
179         const u8 *eap_identity; /* <= 64 octets */
180         size_t eap_identity_len;
181
182         /* attributes that can occur multiple times */
183 #define MAX_CRED_COUNT 10
184         const u8 *cred[MAX_CRED_COUNT];
185         size_t cred_len[MAX_CRED_COUNT];
186         size_t num_cred;
187 };
188
189 /* wps_common.c */
190 void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
191              const char *label, u8 *res, size_t res_len);
192 int wps_derive_keys(struct wps_data *wps);
193 void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
194                     size_t dev_passwd_len);
195 struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
196                                           size_t encr_len);
197 void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg);
198 void wps_success_event(struct wps_context *wps);
199 void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part);
200 void wps_pbc_overlap_event(struct wps_context *wps);
201 void wps_pbc_timeout_event(struct wps_context *wps);
202
203 extern struct oob_device_data oob_ufd_device_data;
204 extern struct oob_device_data oob_nfc_device_data;
205 extern struct oob_nfc_device_data oob_nfc_pn531_device_data;
206
207 /* wps_attr_parse.c */
208 int wps_parse_msg(const struct wpabuf *msg, struct wps_parse_attr *attr);
209
210 /* wps_attr_build.c */
211 int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
212 int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
213 int wps_build_config_methods(struct wpabuf *msg, u16 methods);
214 int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
215 int wps_build_dev_password_id(struct wpabuf *msg, u16 id);
216 int wps_build_config_error(struct wpabuf *msg, u16 err);
217 int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
218 int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
219 int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
220                             struct wpabuf *plain);
221 int wps_build_version(struct wpabuf *msg);
222 int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
223 int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
224 int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
225 int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
226 int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
227 int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
228 int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
229 int wps_build_oob_dev_password(struct wpabuf *msg, struct wps_context *wps);
230
231 /* wps_attr_process.c */
232 int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
233                               const struct wpabuf *msg);
234 int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
235                               const u8 *key_wrap_auth);
236 int wps_process_cred(struct wps_parse_attr *attr,
237                      struct wps_credential *cred);
238 int wps_process_ap_settings(struct wps_parse_attr *attr,
239                             struct wps_credential *cred);
240
241 /* wps_enrollee.c */
242 struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
243                                      enum wsc_op_code *op_code);
244 enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
245                                               enum wsc_op_code op_code,
246                                               const struct wpabuf *msg);
247
248 /* wps_registrar.c */
249 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
250                                       enum wsc_op_code *op_code);
251 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
252                                                enum wsc_op_code op_code,
253                                                const struct wpabuf *msg);
254 int wps_build_cred(struct wps_data *wps, struct wpabuf *msg);
255 int wps_device_store(struct wps_registrar *reg,
256                      struct wps_device_data *dev, const u8 *uuid);
257
258 /* ndef.c */
259 struct wpabuf * ndef_parse_wifi(struct wpabuf *buf);
260 struct wpabuf * ndef_build_wifi(struct wpabuf *buf);
261
262 static inline int wps_version_supported(const u8 *version)
263 {
264         /* Require major version match, but allow minor version differences */
265         return version && (*version & 0xf0) == (WPS_VERSION & 0xf0);
266 }
267
268 #endif /* WPS_I_H */