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