4b7ad253bf92a680266441090f90a4defd866ab6
[libeap.git] / src / wps / wps_i.h
1 /*
2  * Wi-Fi Protected Setup - internal definitions
3  * Copyright (c) 2008, 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          * authenticator - Whether the local end is Authenticator
29          * 1 = Authenticator, 0 = Supplicant
30          */
31         int authenticator;
32
33         /**
34          * wps - Pointer to long term WPS context
35          */
36         struct wps_context *wps;
37
38         /**
39          * registrar - Pointer to WPS registrar data from wps_registrar_init()
40          * This is only used if the local end is Registrar.
41          */
42         struct wps_registrar *registrar;
43
44         enum {
45                 /* Enrollee states */
46                 SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7,
47                 RECV_M8, RECEIVED_M2D, WPS_MSG_DONE, RECV_ACK, WPS_FINISHED,
48                 SEND_WSC_NACK,
49
50                 /* Registrar states */
51                 RECV_M1, SEND_M2, RECV_M3, SEND_M4, RECV_M5, SEND_M6,
52                 RECV_M7, SEND_M8, RECV_DONE, SEND_M2D, RECV_M2D_ACK
53         } state;
54
55         u8 uuid_e[WPS_UUID_LEN];
56         u8 uuid_r[WPS_UUID_LEN];
57         u8 mac_addr_e[ETH_ALEN];
58         u8 nonce_e[WPS_NONCE_LEN];
59         u8 nonce_r[WPS_NONCE_LEN];
60         u8 psk1[WPS_PSK_LEN];
61         u8 psk2[WPS_PSK_LEN];
62         u8 snonce[2 * WPS_SECRET_NONCE_LEN];
63         u8 peer_hash1[WPS_HASH_LEN];
64         u8 peer_hash2[WPS_HASH_LEN];
65
66         struct wpabuf *dh_privkey;
67         struct wpabuf *dh_pubkey_e;
68         struct wpabuf *dh_pubkey_r;
69         u8 authkey[WPS_AUTHKEY_LEN];
70         u8 keywrapkey[WPS_KEYWRAPKEY_LEN];
71         u8 emsk[WPS_EMSK_LEN];
72         u8 mgmt_auth_key[WPS_MGMTAUTHKEY_LEN];
73         u8 mgmt_auth_key_id[WPS_MGMT_KEY_ID_LEN];
74         u8 mgmt_enc_key[WPS_MGMTENCKEY_LEN];
75         u8 mgmt_enc_key_id[WPS_MGMT_KEY_ID_LEN];
76
77         struct wpabuf *last_msg;
78
79         u8 *dev_password;
80         size_t dev_password_len;
81         u16 dev_pw_id;
82         int pbc;
83
84         /**
85          * request_type - Request Type attribute from (Re)AssocReq
86          */
87         u8 request_type;
88
89         /**
90          * encr_type - Available encryption types
91          */
92         u16 encr_type;
93
94         /**
95          * auth_type - Available authentication types
96          */
97         u16 auth_type;
98
99         u8 *new_psk;
100         size_t new_psk_len;
101
102         int wps_pin_revealed;
103         struct wps_credential cred;
104
105         struct wps_device_data peer_dev;
106
107         /**
108          * config_error - Configuration Error value to be used in NACK
109          */
110         u16 config_error;
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 *os_version; /* 4 octets */
133         const u8 *wps_state; /* 1 octet */
134         const u8 *authenticator; /* WPS_AUTHENTICATOR_LEN (8) octets */
135         const u8 *r_hash1; /* WPS_HASH_LEN (32) octets */
136         const u8 *r_hash2; /* WPS_HASH_LEN (32) octets */
137         const u8 *e_hash1; /* WPS_HASH_LEN (32) octets */
138         const u8 *e_hash2; /* WPS_HASH_LEN (32) octets */
139         const u8 *r_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
140         const u8 *r_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
141         const u8 *e_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
142         const u8 *e_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
143         const u8 *key_wrap_auth; /* WPS_KWA_LEN (8) octets */
144         const u8 *auth_type; /* 2 octets */
145         const u8 *encr_type; /* 2 octets */
146         const u8 *network_idx; /* 1 octet */
147         const u8 *network_key_idx; /* 1 octet */
148         const u8 *mac_addr; /* ETH_ALEN (6) octets */
149         const u8 *key_prov_auto; /* 1 octet (Bool) */
150         const u8 *dot1x_enabled; /* 1 octet (Bool) */
151         const u8 *selected_registrar; /* 1 octet (Bool) */
152         const u8 *request_type; /* 1 octet */
153         const u8 *response_type; /* 1 octet */
154
155         /* variable length fields */
156         const u8 *manufacturer;
157         size_t manufacturer_len;
158         const u8 *model_name;
159         size_t model_name_len;
160         const u8 *model_number;
161         size_t model_number_len;
162         const u8 *serial_number;
163         size_t serial_number_len;
164         const u8 *dev_name;
165         size_t dev_name_len;
166         const u8 *public_key;
167         size_t public_key_len;
168         const u8 *encr_settings;
169         size_t encr_settings_len;
170         const u8 *ssid; /* <= 32 octets */
171         size_t ssid_len;
172         const u8 *network_key; /* <= 64 octets */
173         size_t network_key_len;
174         const u8 *eap_type; /* <= 8 octets */
175         size_t eap_type_len;
176         const u8 *eap_identity; /* <= 64 octets */
177         size_t eap_identity_len;
178
179         /* attributes that can occur multiple times */
180 #define MAX_CRED_COUNT 10
181         const u8 *cred[MAX_CRED_COUNT];
182         size_t cred_len[MAX_CRED_COUNT];
183         size_t num_cred;
184 };
185
186 /* wps_common.c */
187 void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
188              const char *label, u8 *res, size_t res_len);
189 int wps_derive_keys(struct wps_data *wps);
190 int wps_derive_mgmt_keys(struct wps_data *wps);
191 void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
192                     size_t dev_passwd_len);
193 struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
194                                           size_t encr_len);
195 void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg);
196 void wps_success_event(struct wps_context *wps);
197
198 /* wps_attr_parse.c */
199 int wps_parse_msg(const struct wpabuf *msg, struct wps_parse_attr *attr);
200
201 /* wps_attr_build.c */
202 int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
203 int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
204 int wps_build_config_methods(struct wpabuf *msg, u16 methods);
205 int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
206 int wps_build_dev_password_id(struct wpabuf *msg, u16 id);
207 int wps_build_config_error(struct wpabuf *msg, u16 err);
208 int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
209 int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
210 int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
211                             struct wpabuf *plain);
212 int wps_build_version(struct wpabuf *msg);
213 int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
214 int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
215 int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
216 int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
217 int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
218 int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
219 int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
220
221 /* wps_attr_process.c */
222 int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
223                               const struct wpabuf *msg);
224 int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
225                               const u8 *key_wrap_auth);
226 int wps_process_cred(struct wps_parse_attr *attr,
227                      struct wps_credential *cred);
228 int wps_process_ap_settings(struct wps_parse_attr *attr,
229                             struct wps_credential *cred);
230
231 /* wps_enrollee.c */
232 struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
233                                      enum wsc_op_code *op_code);
234 enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
235                                               enum wsc_op_code op_code,
236                                               const struct wpabuf *msg);
237
238 /* wps_registrar.c */
239 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
240                                       enum wsc_op_code *op_code);
241 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
242                                                enum wsc_op_code op_code,
243                                                const struct wpabuf *msg);
244
245 #endif /* WPS_I_H */