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