2 * Wi-Fi Protected Setup - Enrollee
3 * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "crypto/crypto.h"
13 #include "crypto/sha256.h"
14 #include "crypto/random.h"
16 #include "wps_dev_attr.h"
19 static int wps_build_wps_state(struct wps_data *wps, struct wpabuf *msg)
23 state = wps->wps->wps_state;
25 state = WPS_STATE_NOT_CONFIGURED;
26 wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
28 wpabuf_put_be16(msg, ATTR_WPS_STATE);
29 wpabuf_put_be16(msg, 1);
30 wpabuf_put_u8(msg, state);
35 static int wps_build_e_hash(struct wps_data *wps, struct wpabuf *msg)
41 if (random_get_bytes(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
43 wpa_hexdump(MSG_DEBUG, "WPS: E-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
44 wpa_hexdump(MSG_DEBUG, "WPS: E-S2",
45 wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
47 if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
48 wpa_printf(MSG_DEBUG, "WPS: DH public keys not available for "
53 wpa_printf(MSG_DEBUG, "WPS: * E-Hash1");
54 wpabuf_put_be16(msg, ATTR_E_HASH1);
55 wpabuf_put_be16(msg, SHA256_MAC_LEN);
56 hash = wpabuf_put(msg, SHA256_MAC_LEN);
57 /* E-Hash1 = HMAC_AuthKey(E-S1 || PSK1 || PK_E || PK_R) */
58 addr[0] = wps->snonce;
59 len[0] = WPS_SECRET_NONCE_LEN;
62 addr[2] = wpabuf_head(wps->dh_pubkey_e);
63 len[2] = wpabuf_len(wps->dh_pubkey_e);
64 addr[3] = wpabuf_head(wps->dh_pubkey_r);
65 len[3] = wpabuf_len(wps->dh_pubkey_r);
66 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
67 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", hash, SHA256_MAC_LEN);
69 wpa_printf(MSG_DEBUG, "WPS: * E-Hash2");
70 wpabuf_put_be16(msg, ATTR_E_HASH2);
71 wpabuf_put_be16(msg, SHA256_MAC_LEN);
72 hash = wpabuf_put(msg, SHA256_MAC_LEN);
73 /* E-Hash2 = HMAC_AuthKey(E-S2 || PSK2 || PK_E || PK_R) */
74 addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
76 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
77 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", hash, SHA256_MAC_LEN);
83 static int wps_build_e_snonce1(struct wps_data *wps, struct wpabuf *msg)
85 wpa_printf(MSG_DEBUG, "WPS: * E-SNonce1");
86 wpabuf_put_be16(msg, ATTR_E_SNONCE1);
87 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
88 wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
93 static int wps_build_e_snonce2(struct wps_data *wps, struct wpabuf *msg)
95 wpa_printf(MSG_DEBUG, "WPS: * E-SNonce2");
96 wpabuf_put_be16(msg, ATTR_E_SNONCE2);
97 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
98 wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
99 WPS_SECRET_NONCE_LEN);
104 static struct wpabuf * wps_build_m1(struct wps_data *wps)
109 if (random_get_bytes(wps->nonce_e, WPS_NONCE_LEN) < 0)
111 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
112 wps->nonce_e, WPS_NONCE_LEN);
114 wpa_printf(MSG_DEBUG, "WPS: Building Message M1");
115 msg = wpabuf_alloc(1000);
119 config_methods = wps->wps->config_methods;
120 if (wps->wps->ap && !wps->pbc_in_m1 &&
121 (wps->dev_password_len != 0 ||
122 (config_methods & WPS_CONFIG_DISPLAY))) {
124 * These are the methods that the AP supports as an Enrollee
125 * for adding external Registrars, so remove PushButton.
127 * As a workaround for Windows 7 mechanism for probing WPS
128 * capabilities from M1, leave PushButton option if no PIN
129 * method is available or if WPS configuration enables PBC
132 config_methods &= ~WPS_CONFIG_PUSHBUTTON;
133 config_methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
134 WPS_CONFIG_PHY_PUSHBUTTON);
137 if (wps_build_version(msg) ||
138 wps_build_msg_type(msg, WPS_M1) ||
139 wps_build_uuid_e(msg, wps->uuid_e) ||
140 wps_build_mac_addr(msg, wps->mac_addr_e) ||
141 wps_build_enrollee_nonce(wps, msg) ||
142 wps_build_public_key(wps, msg) ||
143 wps_build_auth_type_flags(wps, msg) ||
144 wps_build_encr_type_flags(wps, msg) ||
145 wps_build_conn_type_flags(wps, msg) ||
146 wps_build_config_methods(msg, config_methods) ||
147 wps_build_wps_state(wps, msg) ||
148 wps_build_device_attrs(&wps->wps->dev, msg) ||
149 wps_build_rf_bands(&wps->wps->dev, msg,
150 wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
151 wps_build_assoc_state(wps, msg) ||
152 wps_build_dev_password_id(msg, wps->dev_pw_id) ||
153 wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
154 wps_build_os_version(&wps->wps->dev, msg) ||
155 wps_build_wfa_ext(msg, 0, NULL, 0) ||
156 wps_build_vendor_ext_m1(&wps->wps->dev, msg)) {
161 wps->state = RECV_M2;
166 static struct wpabuf * wps_build_m3(struct wps_data *wps)
170 wpa_printf(MSG_DEBUG, "WPS: Building Message M3");
172 if (wps->dev_password == NULL) {
173 wpa_printf(MSG_DEBUG, "WPS: No Device Password available");
176 if (wps_derive_psk(wps, wps->dev_password, wps->dev_password_len) < 0)
179 if (wps->wps->ap && random_pool_ready() != 1) {
181 "WPS: Not enough entropy in random pool to proceed - do not allow AP PIN to be used");
185 msg = wpabuf_alloc(1000);
189 if (wps_build_version(msg) ||
190 wps_build_msg_type(msg, WPS_M3) ||
191 wps_build_registrar_nonce(wps, msg) ||
192 wps_build_e_hash(wps, msg) ||
193 wps_build_wfa_ext(msg, 0, NULL, 0) ||
194 wps_build_authenticator(wps, msg)) {
199 wps->state = RECV_M4;
204 static struct wpabuf * wps_build_m5(struct wps_data *wps)
206 struct wpabuf *msg, *plain;
208 wpa_printf(MSG_DEBUG, "WPS: Building Message M5");
210 plain = wpabuf_alloc(200);
214 msg = wpabuf_alloc(1000);
220 if (wps_build_version(msg) ||
221 wps_build_msg_type(msg, WPS_M5) ||
222 wps_build_registrar_nonce(wps, msg) ||
223 wps_build_e_snonce1(wps, plain) ||
224 wps_build_key_wrap_auth(wps, plain) ||
225 wps_build_encr_settings(wps, msg, plain) ||
226 wps_build_wfa_ext(msg, 0, NULL, 0) ||
227 wps_build_authenticator(wps, msg)) {
228 wpabuf_clear_free(plain);
232 wpabuf_clear_free(plain);
234 wps->state = RECV_M6;
239 static int wps_build_cred_ssid(struct wps_data *wps, struct wpabuf *msg)
241 wpa_printf(MSG_DEBUG, "WPS: * SSID");
242 wpabuf_put_be16(msg, ATTR_SSID);
243 wpabuf_put_be16(msg, wps->wps->ssid_len);
244 wpabuf_put_data(msg, wps->wps->ssid, wps->wps->ssid_len);
249 static int wps_build_cred_auth_type(struct wps_data *wps, struct wpabuf *msg)
251 u16 auth_type = wps->wps->ap_auth_type;
254 * Work around issues with Windows 7 WPS implementation not liking
255 * multiple Authentication Type bits in M7 AP Settings attribute by
256 * showing only the most secure option from current configuration.
258 if (auth_type & WPS_AUTH_WPA2PSK)
259 auth_type = WPS_AUTH_WPA2PSK;
260 else if (auth_type & WPS_AUTH_WPAPSK)
261 auth_type = WPS_AUTH_WPAPSK;
262 else if (auth_type & WPS_AUTH_OPEN)
263 auth_type = WPS_AUTH_OPEN;
265 wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)", auth_type);
266 wpabuf_put_be16(msg, ATTR_AUTH_TYPE);
267 wpabuf_put_be16(msg, 2);
268 wpabuf_put_be16(msg, auth_type);
273 static int wps_build_cred_encr_type(struct wps_data *wps, struct wpabuf *msg)
275 u16 encr_type = wps->wps->ap_encr_type;
278 * Work around issues with Windows 7 WPS implementation not liking
279 * multiple Encryption Type bits in M7 AP Settings attribute by
280 * showing only the most secure option from current configuration.
282 if (wps->wps->ap_auth_type & (WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK)) {
283 if (encr_type & WPS_ENCR_AES)
284 encr_type = WPS_ENCR_AES;
285 else if (encr_type & WPS_ENCR_TKIP)
286 encr_type = WPS_ENCR_TKIP;
289 wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)", encr_type);
290 wpabuf_put_be16(msg, ATTR_ENCR_TYPE);
291 wpabuf_put_be16(msg, 2);
292 wpabuf_put_be16(msg, encr_type);
297 static int wps_build_cred_network_key(struct wps_data *wps, struct wpabuf *msg)
299 if ((wps->wps->ap_auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) &&
300 wps->wps->network_key_len == 0) {
303 /* Generate a random per-device PSK */
304 if (random_pool_ready() != 1 ||
305 random_get_bytes(psk, sizeof(psk)) < 0) {
307 "WPS: Could not generate random PSK");
310 wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
312 wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%u)",
313 (unsigned int) wps->new_psk_len * 2);
314 wpa_snprintf_hex(hex, sizeof(hex), psk, sizeof(psk));
315 wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
316 wpabuf_put_be16(msg, sizeof(psk) * 2);
317 wpabuf_put_data(msg, hex, sizeof(psk) * 2);
318 if (wps->wps->registrar) {
319 wps_cb_new_psk(wps->wps->registrar,
320 wps->peer_dev.mac_addr,
321 wps->p2p_dev_addr, psk, sizeof(psk));
326 wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%u)",
327 (unsigned int) wps->wps->network_key_len);
328 wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
329 wpabuf_put_be16(msg, wps->wps->network_key_len);
330 wpabuf_put_data(msg, wps->wps->network_key, wps->wps->network_key_len);
335 static int wps_build_cred_mac_addr(struct wps_data *wps, struct wpabuf *msg)
337 wpa_printf(MSG_DEBUG, "WPS: * MAC Address (AP BSSID)");
338 wpabuf_put_be16(msg, ATTR_MAC_ADDR);
339 wpabuf_put_be16(msg, ETH_ALEN);
340 wpabuf_put_data(msg, wps->wps->dev.mac_addr, ETH_ALEN);
345 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *plain)
347 const u8 *start, *end;
350 if (wps->wps->ap_settings) {
351 wpa_printf(MSG_DEBUG, "WPS: * AP Settings (pre-configured)");
352 wpabuf_put_data(plain, wps->wps->ap_settings,
353 wps->wps->ap_settings_len);
357 wpa_printf(MSG_DEBUG, "WPS: * AP Settings based on current configuration");
358 start = wpabuf_put(plain, 0);
359 ret = wps_build_cred_ssid(wps, plain) ||
360 wps_build_cred_mac_addr(wps, plain) ||
361 wps_build_cred_auth_type(wps, plain) ||
362 wps_build_cred_encr_type(wps, plain) ||
363 wps_build_cred_network_key(wps, plain);
364 end = wpabuf_put(plain, 0);
366 wpa_hexdump_key(MSG_DEBUG, "WPS: Plaintext AP Settings",
373 static struct wpabuf * wps_build_m7(struct wps_data *wps)
375 struct wpabuf *msg, *plain;
377 wpa_printf(MSG_DEBUG, "WPS: Building Message M7");
379 plain = wpabuf_alloc(500 + wps->wps->ap_settings_len);
383 msg = wpabuf_alloc(1000 + wps->wps->ap_settings_len);
389 if (wps_build_version(msg) ||
390 wps_build_msg_type(msg, WPS_M7) ||
391 wps_build_registrar_nonce(wps, msg) ||
392 wps_build_e_snonce2(wps, plain) ||
393 (wps->wps->ap && wps_build_ap_settings(wps, plain)) ||
394 wps_build_key_wrap_auth(wps, plain) ||
395 wps_build_encr_settings(wps, msg, plain) ||
396 wps_build_wfa_ext(msg, 0, NULL, 0) ||
397 wps_build_authenticator(wps, msg)) {
398 wpabuf_clear_free(plain);
402 wpabuf_clear_free(plain);
404 if (wps->wps->ap && wps->wps->registrar) {
406 * If the Registrar is only learning our current configuration,
407 * it may not continue protocol run to successful completion.
408 * Store information here to make sure it remains available.
410 wps_device_store(wps->wps->registrar, &wps->peer_dev,
414 wps->state = RECV_M8;
419 static struct wpabuf * wps_build_wsc_done(struct wps_data *wps)
423 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_Done");
425 msg = wpabuf_alloc(1000);
429 if (wps_build_version(msg) ||
430 wps_build_msg_type(msg, WPS_WSC_DONE) ||
431 wps_build_enrollee_nonce(wps, msg) ||
432 wps_build_registrar_nonce(wps, msg) ||
433 wps_build_wfa_ext(msg, 0, NULL, 0)) {
439 wps->state = RECV_ACK;
441 wps_success_event(wps->wps, wps->peer_dev.mac_addr);
442 wps->state = WPS_FINISHED;
448 struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
449 enum wsc_op_code *op_code)
453 switch (wps->state) {
455 msg = wps_build_m1(wps);
459 msg = wps_build_m3(wps);
463 msg = wps_build_m5(wps);
467 msg = wps_build_m7(wps);
472 msg = wps_build_wsc_nack(wps);
476 msg = wps_build_wsc_ack(wps);
479 /* Another M2/M2D may be received */
480 wps->state = RECV_M2;
484 msg = wps_build_wsc_nack(wps);
488 msg = wps_build_wsc_done(wps);
492 wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
493 "a message", wps->state);
498 if (*op_code == WSC_MSG && msg) {
499 /* Save a copy of the last message for Authenticator derivation
501 wpabuf_free(wps->last_msg);
502 wps->last_msg = wpabuf_dup(msg);
509 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
511 if (r_nonce == NULL) {
512 wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
516 os_memcpy(wps->nonce_r, r_nonce, WPS_NONCE_LEN);
517 wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
518 wps->nonce_r, WPS_NONCE_LEN);
524 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
526 if (e_nonce == NULL) {
527 wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
531 if (os_memcmp(wps->nonce_e, e_nonce, WPS_NONCE_LEN) != 0) {
532 wpa_printf(MSG_DEBUG, "WPS: Invalid Enrollee Nonce received");
540 static int wps_process_uuid_r(struct wps_data *wps, const u8 *uuid_r)
542 if (uuid_r == NULL) {
543 wpa_printf(MSG_DEBUG, "WPS: No UUID-R received");
547 os_memcpy(wps->uuid_r, uuid_r, WPS_UUID_LEN);
548 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
554 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
557 if (pk == NULL || pk_len == 0) {
558 wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
562 if (wps->peer_pubkey_hash_set) {
563 u8 hash[WPS_HASH_LEN];
564 sha256_vector(1, &pk, &pk_len, hash);
565 if (os_memcmp_const(hash, wps->peer_pubkey_hash,
566 WPS_OOB_PUBKEY_HASH_LEN) != 0) {
567 wpa_printf(MSG_ERROR, "WPS: Public Key hash mismatch");
568 wpa_hexdump(MSG_DEBUG, "WPS: Received public key",
570 wpa_hexdump(MSG_DEBUG, "WPS: Calculated public key "
571 "hash", hash, WPS_OOB_PUBKEY_HASH_LEN);
572 wpa_hexdump(MSG_DEBUG, "WPS: Expected public key hash",
573 wps->peer_pubkey_hash,
574 WPS_OOB_PUBKEY_HASH_LEN);
575 wps->config_error = WPS_CFG_PUBLIC_KEY_HASH_MISMATCH;
580 wpabuf_free(wps->dh_pubkey_r);
581 wps->dh_pubkey_r = wpabuf_alloc_copy(pk, pk_len);
582 if (wps->dh_pubkey_r == NULL)
585 if (wps_derive_keys(wps) < 0)
592 static int wps_process_r_hash1(struct wps_data *wps, const u8 *r_hash1)
594 if (r_hash1 == NULL) {
595 wpa_printf(MSG_DEBUG, "WPS: No R-Hash1 received");
599 os_memcpy(wps->peer_hash1, r_hash1, WPS_HASH_LEN);
600 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", wps->peer_hash1, WPS_HASH_LEN);
606 static int wps_process_r_hash2(struct wps_data *wps, const u8 *r_hash2)
608 if (r_hash2 == NULL) {
609 wpa_printf(MSG_DEBUG, "WPS: No R-Hash2 received");
613 os_memcpy(wps->peer_hash2, r_hash2, WPS_HASH_LEN);
614 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", wps->peer_hash2, WPS_HASH_LEN);
620 static int wps_process_r_snonce1(struct wps_data *wps, const u8 *r_snonce1)
622 u8 hash[SHA256_MAC_LEN];
626 if (r_snonce1 == NULL) {
627 wpa_printf(MSG_DEBUG, "WPS: No R-SNonce1 received");
631 wpa_hexdump_key(MSG_DEBUG, "WPS: R-SNonce1", r_snonce1,
632 WPS_SECRET_NONCE_LEN);
634 /* R-Hash1 = HMAC_AuthKey(R-S1 || PSK1 || PK_E || PK_R) */
636 len[0] = WPS_SECRET_NONCE_LEN;
638 len[1] = WPS_PSK_LEN;
639 addr[2] = wpabuf_head(wps->dh_pubkey_e);
640 len[2] = wpabuf_len(wps->dh_pubkey_e);
641 addr[3] = wpabuf_head(wps->dh_pubkey_r);
642 len[3] = wpabuf_len(wps->dh_pubkey_r);
643 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
645 if (os_memcmp_const(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
646 wpa_printf(MSG_DEBUG, "WPS: R-Hash1 derived from R-S1 does "
647 "not match with the pre-committed value");
648 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
649 wps_pwd_auth_fail_event(wps->wps, 1, 1, wps->peer_dev.mac_addr);
653 wpa_printf(MSG_DEBUG, "WPS: Registrar proved knowledge of the first "
654 "half of the device password");
660 static int wps_process_r_snonce2(struct wps_data *wps, const u8 *r_snonce2)
662 u8 hash[SHA256_MAC_LEN];
666 if (r_snonce2 == NULL) {
667 wpa_printf(MSG_DEBUG, "WPS: No R-SNonce2 received");
671 wpa_hexdump_key(MSG_DEBUG, "WPS: R-SNonce2", r_snonce2,
672 WPS_SECRET_NONCE_LEN);
674 /* R-Hash2 = HMAC_AuthKey(R-S2 || PSK2 || PK_E || PK_R) */
676 len[0] = WPS_SECRET_NONCE_LEN;
678 len[1] = WPS_PSK_LEN;
679 addr[2] = wpabuf_head(wps->dh_pubkey_e);
680 len[2] = wpabuf_len(wps->dh_pubkey_e);
681 addr[3] = wpabuf_head(wps->dh_pubkey_r);
682 len[3] = wpabuf_len(wps->dh_pubkey_r);
683 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
685 if (os_memcmp_const(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
686 wpa_printf(MSG_DEBUG, "WPS: R-Hash2 derived from R-S2 does "
687 "not match with the pre-committed value");
688 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
689 wps_pwd_auth_fail_event(wps->wps, 1, 2, wps->peer_dev.mac_addr);
693 wpa_printf(MSG_DEBUG, "WPS: Registrar proved knowledge of the second "
694 "half of the device password");
700 static int wps_process_cred_e(struct wps_data *wps, const u8 *cred,
701 size_t cred_len, int wps2)
703 struct wps_parse_attr attr;
707 wpa_printf(MSG_DEBUG, "WPS: Received Credential");
708 os_memset(&wps->cred, 0, sizeof(wps->cred));
709 wpabuf_set(&msg, cred, cred_len);
710 if (wps_parse_msg(&msg, &attr) < 0 ||
711 wps_process_cred(&attr, &wps->cred))
714 if (os_memcmp(wps->cred.mac_addr, wps->wps->dev.mac_addr, ETH_ALEN) !=
716 wpa_printf(MSG_DEBUG, "WPS: MAC Address in the Credential ("
717 MACSTR ") does not match with own address (" MACSTR
718 ")", MAC2STR(wps->cred.mac_addr),
719 MAC2STR(wps->wps->dev.mac_addr));
721 * In theory, this could be consider fatal error, but there are
722 * number of deployed implementations using other address here
723 * due to unclarity in the specification. For interoperability
724 * reasons, allow this to be processed since we do not really
725 * use the MAC Address information for anything.
727 #ifdef CONFIG_WPS_STRICT
729 wpa_printf(MSG_INFO, "WPS: Do not accept incorrect "
730 "MAC Address in AP Settings");
733 #endif /* CONFIG_WPS_STRICT */
736 if (!(wps->cred.encr_type &
737 (WPS_ENCR_NONE | WPS_ENCR_TKIP | WPS_ENCR_AES))) {
738 if (wps->cred.encr_type & WPS_ENCR_WEP) {
739 wpa_printf(MSG_INFO, "WPS: Reject Credential "
740 "due to WEP configuration");
741 wps->error_indication = WPS_EI_SECURITY_WEP_PROHIBITED;
745 wpa_printf(MSG_INFO, "WPS: Reject Credential due to "
746 "invalid encr_type 0x%x", wps->cred.encr_type);
750 if (wps->wps->cred_cb) {
751 wps->cred.cred_attr = cred - 4;
752 wps->cred.cred_attr_len = cred_len + 4;
753 ret = wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
754 wps->cred.cred_attr = NULL;
755 wps->cred.cred_attr_len = 0;
762 static int wps_process_creds(struct wps_data *wps, const u8 *cred[],
763 u16 cred_len[], unsigned int num_cred, int wps2)
772 wpa_printf(MSG_DEBUG, "WPS: No Credential attributes "
777 for (i = 0; i < num_cred; i++) {
779 res = wps_process_cred_e(wps, cred[i], cred_len[i], wps2);
783 wpa_printf(MSG_DEBUG, "WPS: WEP credential skipped");
789 wpa_printf(MSG_DEBUG, "WPS: No valid Credential attribute "
798 static int wps_process_ap_settings_e(struct wps_data *wps,
799 struct wps_parse_attr *attr,
800 struct wpabuf *attrs, int wps2)
802 struct wps_credential cred;
808 if (wps_process_ap_settings(attr, &cred) < 0)
811 wpa_printf(MSG_INFO, "WPS: Received new AP configuration from "
814 if (os_memcmp(cred.mac_addr, wps->wps->dev.mac_addr, ETH_ALEN) !=
816 wpa_printf(MSG_DEBUG, "WPS: MAC Address in the AP Settings ("
817 MACSTR ") does not match with own address (" MACSTR
818 ")", MAC2STR(cred.mac_addr),
819 MAC2STR(wps->wps->dev.mac_addr));
821 * In theory, this could be consider fatal error, but there are
822 * number of deployed implementations using other address here
823 * due to unclarity in the specification. For interoperability
824 * reasons, allow this to be processed since we do not really
825 * use the MAC Address information for anything.
827 #ifdef CONFIG_WPS_STRICT
829 wpa_printf(MSG_INFO, "WPS: Do not accept incorrect "
830 "MAC Address in AP Settings");
833 #endif /* CONFIG_WPS_STRICT */
836 if (!(cred.encr_type & (WPS_ENCR_NONE | WPS_ENCR_TKIP | WPS_ENCR_AES)))
838 if (cred.encr_type & WPS_ENCR_WEP) {
839 wpa_printf(MSG_INFO, "WPS: Reject new AP settings "
840 "due to WEP configuration");
841 wps->error_indication = WPS_EI_SECURITY_WEP_PROHIBITED;
845 wpa_printf(MSG_INFO, "WPS: Reject new AP settings due to "
846 "invalid encr_type 0x%x", cred.encr_type);
850 #ifdef CONFIG_WPS_STRICT
852 if ((cred.encr_type & (WPS_ENCR_TKIP | WPS_ENCR_AES)) ==
854 (cred.auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) ==
856 wpa_printf(MSG_INFO, "WPS-STRICT: Invalid WSC 2.0 "
857 "AP Settings: WPA-Personal/TKIP only");
858 wps->error_indication =
859 WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED;
863 #endif /* CONFIG_WPS_STRICT */
865 if ((cred.encr_type & (WPS_ENCR_TKIP | WPS_ENCR_AES)) == WPS_ENCR_TKIP)
867 wpa_printf(MSG_DEBUG, "WPS: Upgrade encr_type TKIP -> "
869 cred.encr_type |= WPS_ENCR_AES;
872 if ((cred.auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) ==
874 wpa_printf(MSG_DEBUG, "WPS: Upgrade auth_type WPAPSK -> "
876 cred.auth_type |= WPS_AUTH_WPA2PSK;
879 if (wps->wps->cred_cb) {
880 cred.cred_attr = wpabuf_head(attrs);
881 cred.cred_attr_len = wpabuf_len(attrs);
882 ret = wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
889 static int wps_process_dev_pw_id(struct wps_data *wps, const u8 *dev_pw_id)
893 if (dev_pw_id == NULL) {
894 wpa_printf(MSG_DEBUG, "WPS: Device Password ID");
898 id = WPA_GET_BE16(dev_pw_id);
899 if (wps->dev_pw_id == id) {
900 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %u", id);
905 if ((id == DEV_PW_DEFAULT &&
906 wps->dev_pw_id == DEV_PW_REGISTRAR_SPECIFIED) ||
907 (id == DEV_PW_REGISTRAR_SPECIFIED &&
908 wps->dev_pw_id == DEV_PW_DEFAULT)) {
910 * Common P2P use cases indicate whether the PIN is from the
911 * client or GO using Device Password Id in M1/M2 in a way that
912 * does not look fully compliant with WSC specification. Anyway,
913 * this is deployed and needs to be allowed, so ignore changes
914 * between Registrar-Specified and Default PIN.
916 wpa_printf(MSG_DEBUG, "WPS: Allow PIN Device Password ID "
920 #endif /* CONFIG_P2P */
922 wpa_printf(MSG_DEBUG, "WPS: Registrar trying to change Device Password "
923 "ID from %u to %u", wps->dev_pw_id, id);
925 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON && id == DEV_PW_DEFAULT) {
926 wpa_printf(MSG_DEBUG,
927 "WPS: Workaround - ignore PBC-to-PIN change");
931 if (wps->alt_dev_password && wps->alt_dev_pw_id == id) {
932 wpa_printf(MSG_DEBUG, "WPS: Found a matching Device Password");
933 bin_clear_free(wps->dev_password, wps->dev_password_len);
934 wps->dev_pw_id = wps->alt_dev_pw_id;
935 wps->dev_password = wps->alt_dev_password;
936 wps->dev_password_len = wps->alt_dev_password_len;
937 wps->alt_dev_password = NULL;
938 wps->alt_dev_password_len = 0;
946 static enum wps_process_res wps_process_m2(struct wps_data *wps,
947 const struct wpabuf *msg,
948 struct wps_parse_attr *attr)
950 wpa_printf(MSG_DEBUG, "WPS: Received M2");
952 if (wps->state != RECV_M2) {
953 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
954 "receiving M2", wps->state);
955 wps->state = SEND_WSC_NACK;
959 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
960 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
961 wps_process_uuid_r(wps, attr->uuid_r) ||
962 wps_process_dev_pw_id(wps, attr->dev_password_id)) {
963 wps->state = SEND_WSC_NACK;
968 * Stop here on an AP as an Enrollee if AP Setup is locked unless the
969 * special locked mode is used to allow protocol run up to M7 in order
970 * to support external Registrars that only learn the current AP
971 * configuration without changing it.
974 ((wps->wps->ap_setup_locked && wps->wps->ap_setup_locked != 2) ||
975 wps->dev_password == NULL)) {
976 wpa_printf(MSG_DEBUG, "WPS: AP Setup is locked - refuse "
977 "registration of a new Registrar");
978 wps->config_error = WPS_CFG_SETUP_LOCKED;
979 wps->state = SEND_WSC_NACK;
983 if (wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
984 wps_process_authenticator(wps, attr->authenticator, msg) ||
985 wps_process_device_attrs(&wps->peer_dev, attr)) {
986 wps->state = SEND_WSC_NACK;
990 #ifdef CONFIG_WPS_NFC
991 if (wps->peer_pubkey_hash_set) {
992 struct wpabuf *decrypted;
993 struct wps_parse_attr eattr;
995 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
996 attr->encr_settings_len);
997 if (decrypted == NULL) {
998 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypt "
999 "Encrypted Settings attribute");
1000 wps->state = SEND_WSC_NACK;
1001 return WPS_CONTINUE;
1004 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted "
1005 "Settings attribute");
1006 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1007 wps_process_key_wrap_auth(wps, decrypted,
1008 eattr.key_wrap_auth) ||
1009 wps_process_creds(wps, eattr.cred, eattr.cred_len,
1010 eattr.num_cred, attr->version2 != NULL)) {
1011 wpabuf_clear_free(decrypted);
1012 wps->state = SEND_WSC_NACK;
1013 return WPS_CONTINUE;
1015 wpabuf_clear_free(decrypted);
1017 wps->state = WPS_MSG_DONE;
1018 return WPS_CONTINUE;
1020 #endif /* CONFIG_WPS_NFC */
1022 wps->state = SEND_M3;
1023 return WPS_CONTINUE;
1027 static enum wps_process_res wps_process_m2d(struct wps_data *wps,
1028 struct wps_parse_attr *attr)
1030 wpa_printf(MSG_DEBUG, "WPS: Received M2D");
1032 if (wps->state != RECV_M2) {
1033 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1034 "receiving M2D", wps->state);
1035 wps->state = SEND_WSC_NACK;
1036 return WPS_CONTINUE;
1039 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Manufacturer",
1040 attr->manufacturer, attr->manufacturer_len);
1041 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Model Name",
1042 attr->model_name, attr->model_name_len);
1043 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Model Number",
1044 attr->model_number, attr->model_number_len);
1045 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Serial Number",
1046 attr->serial_number, attr->serial_number_len);
1047 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Device Name",
1048 attr->dev_name, attr->dev_name_len);
1050 if (wps->wps->event_cb) {
1051 union wps_event_data data;
1052 struct wps_event_m2d *m2d = &data.m2d;
1053 os_memset(&data, 0, sizeof(data));
1054 if (attr->config_methods)
1055 m2d->config_methods =
1056 WPA_GET_BE16(attr->config_methods);
1057 m2d->manufacturer = attr->manufacturer;
1058 m2d->manufacturer_len = attr->manufacturer_len;
1059 m2d->model_name = attr->model_name;
1060 m2d->model_name_len = attr->model_name_len;
1061 m2d->model_number = attr->model_number;
1062 m2d->model_number_len = attr->model_number_len;
1063 m2d->serial_number = attr->serial_number;
1064 m2d->serial_number_len = attr->serial_number_len;
1065 m2d->dev_name = attr->dev_name;
1066 m2d->dev_name_len = attr->dev_name_len;
1067 m2d->primary_dev_type = attr->primary_dev_type;
1068 if (attr->config_error)
1070 WPA_GET_BE16(attr->config_error);
1071 if (attr->dev_password_id)
1072 m2d->dev_password_id =
1073 WPA_GET_BE16(attr->dev_password_id);
1074 wps->wps->event_cb(wps->wps->cb_ctx, WPS_EV_M2D, &data);
1077 wps->state = RECEIVED_M2D;
1078 return WPS_CONTINUE;
1082 static enum wps_process_res wps_process_m4(struct wps_data *wps,
1083 const struct wpabuf *msg,
1084 struct wps_parse_attr *attr)
1086 struct wpabuf *decrypted;
1087 struct wps_parse_attr eattr;
1089 wpa_printf(MSG_DEBUG, "WPS: Received M4");
1091 if (wps->state != RECV_M4) {
1092 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1093 "receiving M4", wps->state);
1094 wps->state = SEND_WSC_NACK;
1095 return WPS_CONTINUE;
1098 if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1099 wps_process_authenticator(wps, attr->authenticator, msg) ||
1100 wps_process_r_hash1(wps, attr->r_hash1) ||
1101 wps_process_r_hash2(wps, attr->r_hash2)) {
1102 wps->state = SEND_WSC_NACK;
1103 return WPS_CONTINUE;
1106 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1107 attr->encr_settings_len);
1108 if (decrypted == NULL) {
1109 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1110 "Settings attribute");
1111 wps->state = SEND_WSC_NACK;
1112 return WPS_CONTINUE;
1115 if (wps_validate_m4_encr(decrypted, attr->version2 != NULL) < 0) {
1116 wpabuf_clear_free(decrypted);
1117 wps->state = SEND_WSC_NACK;
1118 return WPS_CONTINUE;
1121 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1123 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1124 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1125 wps_process_r_snonce1(wps, eattr.r_snonce1)) {
1126 wpabuf_clear_free(decrypted);
1127 wps->state = SEND_WSC_NACK;
1128 return WPS_CONTINUE;
1130 wpabuf_clear_free(decrypted);
1132 wps->state = SEND_M5;
1133 return WPS_CONTINUE;
1137 static enum wps_process_res wps_process_m6(struct wps_data *wps,
1138 const struct wpabuf *msg,
1139 struct wps_parse_attr *attr)
1141 struct wpabuf *decrypted;
1142 struct wps_parse_attr eattr;
1144 wpa_printf(MSG_DEBUG, "WPS: Received M6");
1146 if (wps->state != RECV_M6) {
1147 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1148 "receiving M6", wps->state);
1149 wps->state = SEND_WSC_NACK;
1150 return WPS_CONTINUE;
1153 if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1154 wps_process_authenticator(wps, attr->authenticator, msg)) {
1155 wps->state = SEND_WSC_NACK;
1156 return WPS_CONTINUE;
1159 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1160 attr->encr_settings_len);
1161 if (decrypted == NULL) {
1162 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1163 "Settings attribute");
1164 wps->state = SEND_WSC_NACK;
1165 return WPS_CONTINUE;
1168 if (wps_validate_m6_encr(decrypted, attr->version2 != NULL) < 0) {
1169 wpabuf_clear_free(decrypted);
1170 wps->state = SEND_WSC_NACK;
1171 return WPS_CONTINUE;
1174 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1176 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1177 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1178 wps_process_r_snonce2(wps, eattr.r_snonce2)) {
1179 wpabuf_clear_free(decrypted);
1180 wps->state = SEND_WSC_NACK;
1181 return WPS_CONTINUE;
1183 wpabuf_clear_free(decrypted);
1186 wps->wps->event_cb(wps->wps->cb_ctx, WPS_EV_AP_PIN_SUCCESS,
1189 wps->state = SEND_M7;
1190 return WPS_CONTINUE;
1194 static enum wps_process_res wps_process_m8(struct wps_data *wps,
1195 const struct wpabuf *msg,
1196 struct wps_parse_attr *attr)
1198 struct wpabuf *decrypted;
1199 struct wps_parse_attr eattr;
1201 wpa_printf(MSG_DEBUG, "WPS: Received M8");
1203 if (wps->state != RECV_M8) {
1204 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1205 "receiving M8", wps->state);
1206 wps->state = SEND_WSC_NACK;
1207 return WPS_CONTINUE;
1210 if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1211 wps_process_authenticator(wps, attr->authenticator, msg)) {
1212 wps->state = SEND_WSC_NACK;
1213 return WPS_CONTINUE;
1216 if (wps->wps->ap && wps->wps->ap_setup_locked) {
1218 * Stop here if special ap_setup_locked == 2 mode allowed the
1219 * protocol to continue beyond M2. This allows ER to learn the
1220 * current AP settings without changing them.
1222 wpa_printf(MSG_DEBUG, "WPS: AP Setup is locked - refuse "
1223 "registration of a new Registrar");
1224 wps->config_error = WPS_CFG_SETUP_LOCKED;
1225 wps->state = SEND_WSC_NACK;
1226 return WPS_CONTINUE;
1229 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1230 attr->encr_settings_len);
1231 if (decrypted == NULL) {
1232 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1233 "Settings attribute");
1234 wps->state = SEND_WSC_NACK;
1235 return WPS_CONTINUE;
1238 if (wps_validate_m8_encr(decrypted, wps->wps->ap,
1239 attr->version2 != NULL) < 0) {
1240 wpabuf_clear_free(decrypted);
1241 wps->state = SEND_WSC_NACK;
1242 return WPS_CONTINUE;
1245 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1247 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1248 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1249 wps_process_creds(wps, eattr.cred, eattr.cred_len,
1250 eattr.num_cred, attr->version2 != NULL) ||
1251 wps_process_ap_settings_e(wps, &eattr, decrypted,
1252 attr->version2 != NULL)) {
1253 wpabuf_clear_free(decrypted);
1254 wps->state = SEND_WSC_NACK;
1255 return WPS_CONTINUE;
1257 wpabuf_clear_free(decrypted);
1259 wps->state = WPS_MSG_DONE;
1260 return WPS_CONTINUE;
1264 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
1265 const struct wpabuf *msg)
1267 struct wps_parse_attr attr;
1268 enum wps_process_res ret = WPS_CONTINUE;
1270 wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
1272 if (wps_parse_msg(msg, &attr) < 0)
1275 if (attr.enrollee_nonce == NULL ||
1276 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
1277 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
1281 if (attr.msg_type == NULL) {
1282 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
1283 wps->state = SEND_WSC_NACK;
1284 return WPS_CONTINUE;
1287 switch (*attr.msg_type) {
1289 if (wps_validate_m2(msg) < 0)
1291 ret = wps_process_m2(wps, msg, &attr);
1294 if (wps_validate_m2d(msg) < 0)
1296 ret = wps_process_m2d(wps, &attr);
1299 if (wps_validate_m4(msg) < 0)
1301 ret = wps_process_m4(wps, msg, &attr);
1302 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1303 wps_fail_event(wps->wps, WPS_M4, wps->config_error,
1304 wps->error_indication,
1305 wps->peer_dev.mac_addr);
1308 if (wps_validate_m6(msg) < 0)
1310 ret = wps_process_m6(wps, msg, &attr);
1311 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1312 wps_fail_event(wps->wps, WPS_M6, wps->config_error,
1313 wps->error_indication,
1314 wps->peer_dev.mac_addr);
1317 if (wps_validate_m8(msg) < 0)
1319 ret = wps_process_m8(wps, msg, &attr);
1320 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1321 wps_fail_event(wps->wps, WPS_M8, wps->config_error,
1322 wps->error_indication,
1323 wps->peer_dev.mac_addr);
1326 wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
1332 * Save a copy of the last message for Authenticator derivation if we
1333 * are continuing. However, skip M2D since it is not authenticated and
1334 * neither is the ACK/NACK response frame. This allows the possibly
1335 * following M2 to be processed correctly by using the previously sent
1336 * M1 in Authenticator derivation.
1338 if (ret == WPS_CONTINUE && *attr.msg_type != WPS_M2D) {
1339 /* Save a copy of the last message for Authenticator derivation
1341 wpabuf_free(wps->last_msg);
1342 wps->last_msg = wpabuf_dup(msg);
1349 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
1350 const struct wpabuf *msg)
1352 struct wps_parse_attr attr;
1354 wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
1356 if (wps_parse_msg(msg, &attr) < 0)
1359 if (attr.msg_type == NULL) {
1360 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
1364 if (*attr.msg_type != WPS_WSC_ACK) {
1365 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
1370 if (attr.registrar_nonce == NULL ||
1371 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
1373 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
1377 if (attr.enrollee_nonce == NULL ||
1378 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
1379 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
1383 if (wps->state == RECV_ACK && wps->wps->ap) {
1384 wpa_printf(MSG_DEBUG, "WPS: External Registrar registration "
1385 "completed successfully");
1386 wps_success_event(wps->wps, wps->peer_dev.mac_addr);
1387 wps->state = WPS_FINISHED;
1395 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
1396 const struct wpabuf *msg)
1398 struct wps_parse_attr attr;
1401 wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
1403 if (wps_parse_msg(msg, &attr) < 0)
1406 if (attr.msg_type == NULL) {
1407 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
1411 if (*attr.msg_type != WPS_WSC_NACK) {
1412 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
1417 if (attr.registrar_nonce == NULL ||
1418 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
1420 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
1421 wpa_hexdump(MSG_DEBUG, "WPS: Received Registrar Nonce",
1422 attr.registrar_nonce, WPS_NONCE_LEN);
1423 wpa_hexdump(MSG_DEBUG, "WPS: Expected Registrar Nonce",
1424 wps->nonce_r, WPS_NONCE_LEN);
1428 if (attr.enrollee_nonce == NULL ||
1429 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
1430 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
1431 wpa_hexdump(MSG_DEBUG, "WPS: Received Enrollee Nonce",
1432 attr.enrollee_nonce, WPS_NONCE_LEN);
1433 wpa_hexdump(MSG_DEBUG, "WPS: Expected Enrollee Nonce",
1434 wps->nonce_e, WPS_NONCE_LEN);
1438 if (attr.config_error == NULL) {
1439 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
1444 config_error = WPA_GET_BE16(attr.config_error);
1445 wpa_printf(MSG_DEBUG, "WPS: Registrar terminated negotiation with "
1446 "Configuration Error %d", config_error);
1448 switch (wps->state) {
1450 wps_fail_event(wps->wps, WPS_M3, config_error,
1451 wps->error_indication, wps->peer_dev.mac_addr);
1454 wps_fail_event(wps->wps, WPS_M5, config_error,
1455 wps->error_indication, wps->peer_dev.mac_addr);
1458 wps_fail_event(wps->wps, WPS_M7, config_error,
1459 wps->error_indication, wps->peer_dev.mac_addr);
1465 /* Followed by NACK if Enrollee is Supplicant or EAP-Failure if
1466 * Enrollee is Authenticator */
1467 wps->state = SEND_WSC_NACK;
1473 enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
1474 enum wsc_op_code op_code,
1475 const struct wpabuf *msg)
1478 wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
1480 (unsigned long) wpabuf_len(msg), op_code);
1482 if (op_code == WSC_UPnP) {
1483 /* Determine the OpCode based on message type attribute */
1484 struct wps_parse_attr attr;
1485 if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type) {
1486 if (*attr.msg_type == WPS_WSC_ACK)
1488 else if (*attr.msg_type == WPS_WSC_NACK)
1496 return wps_process_wsc_msg(wps, msg);
1498 if (wps_validate_wsc_ack(msg) < 0)
1500 return wps_process_wsc_ack(wps, msg);
1502 if (wps_validate_wsc_nack(msg) < 0)
1504 return wps_process_wsc_nack(wps, msg);
1506 wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);