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)
108 u8 multi_ap_backhaul_sta = 0;
110 if (random_get_bytes(wps->nonce_e, WPS_NONCE_LEN) < 0)
112 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
113 wps->nonce_e, WPS_NONCE_LEN);
115 wpa_printf(MSG_DEBUG, "WPS: Building Message M1");
116 msg = wpabuf_alloc(1000);
120 config_methods = wps->wps->config_methods;
121 if (wps->wps->ap && !wps->pbc_in_m1 &&
122 (wps->dev_password_len != 0 ||
123 (config_methods & WPS_CONFIG_DISPLAY))) {
125 * These are the methods that the AP supports as an Enrollee
126 * for adding external Registrars, so remove PushButton.
128 * As a workaround for Windows 7 mechanism for probing WPS
129 * capabilities from M1, leave PushButton option if no PIN
130 * method is available or if WPS configuration enables PBC
133 config_methods &= ~WPS_CONFIG_PUSHBUTTON;
134 config_methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
135 WPS_CONFIG_PHY_PUSHBUTTON);
138 if (wps->multi_ap_backhaul_sta)
139 multi_ap_backhaul_sta = MULTI_AP_BACKHAUL_STA;
141 if (wps_build_version(msg) ||
142 wps_build_msg_type(msg, WPS_M1) ||
143 wps_build_uuid_e(msg, wps->uuid_e) ||
144 wps_build_mac_addr(msg, wps->mac_addr_e) ||
145 wps_build_enrollee_nonce(wps, msg) ||
146 wps_build_public_key(wps, msg) ||
147 wps_build_auth_type_flags(wps, msg) ||
148 wps_build_encr_type_flags(wps, msg) ||
149 wps_build_conn_type_flags(wps, msg) ||
150 wps_build_config_methods(msg, config_methods) ||
151 wps_build_wps_state(wps, msg) ||
152 wps_build_device_attrs(&wps->wps->dev, msg) ||
153 wps_build_rf_bands(&wps->wps->dev, msg,
154 wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
155 wps_build_assoc_state(wps, msg) ||
156 wps_build_dev_password_id(msg, wps->dev_pw_id) ||
157 wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
158 wps_build_os_version(&wps->wps->dev, msg) ||
159 wps_build_wfa_ext(msg, 0, NULL, 0, multi_ap_backhaul_sta) ||
160 wps_build_vendor_ext_m1(&wps->wps->dev, msg)) {
165 wps->state = RECV_M2;
170 static struct wpabuf * wps_build_m3(struct wps_data *wps)
174 wpa_printf(MSG_DEBUG, "WPS: Building Message M3");
176 if (wps->dev_password == NULL) {
177 wpa_printf(MSG_DEBUG, "WPS: No Device Password available");
180 if (wps_derive_psk(wps, wps->dev_password, wps->dev_password_len) < 0)
183 if (wps->wps->ap && random_pool_ready() != 1) {
185 "WPS: Not enough entropy in random pool to proceed - do not allow AP PIN to be used");
189 msg = wpabuf_alloc(1000);
193 if (wps_build_version(msg) ||
194 wps_build_msg_type(msg, WPS_M3) ||
195 wps_build_registrar_nonce(wps, msg) ||
196 wps_build_e_hash(wps, msg) ||
197 wps_build_wfa_ext(msg, 0, NULL, 0, 0) ||
198 wps_build_authenticator(wps, msg)) {
203 wps->state = RECV_M4;
208 static struct wpabuf * wps_build_m5(struct wps_data *wps)
210 struct wpabuf *msg, *plain;
212 wpa_printf(MSG_DEBUG, "WPS: Building Message M5");
214 plain = wpabuf_alloc(200);
218 msg = wpabuf_alloc(1000);
224 if (wps_build_version(msg) ||
225 wps_build_msg_type(msg, WPS_M5) ||
226 wps_build_registrar_nonce(wps, msg) ||
227 wps_build_e_snonce1(wps, plain) ||
228 wps_build_key_wrap_auth(wps, plain) ||
229 wps_build_encr_settings(wps, msg, plain) ||
230 wps_build_wfa_ext(msg, 0, NULL, 0, 0) ||
231 wps_build_authenticator(wps, msg)) {
232 wpabuf_clear_free(plain);
236 wpabuf_clear_free(plain);
238 wps->state = RECV_M6;
243 static int wps_build_cred_ssid(struct wps_data *wps, struct wpabuf *msg)
245 wpa_printf(MSG_DEBUG, "WPS: * SSID");
246 wpabuf_put_be16(msg, ATTR_SSID);
247 wpabuf_put_be16(msg, wps->wps->ssid_len);
248 wpabuf_put_data(msg, wps->wps->ssid, wps->wps->ssid_len);
253 static int wps_build_cred_auth_type(struct wps_data *wps, struct wpabuf *msg)
255 u16 auth_type = wps->wps->ap_auth_type;
258 * Work around issues with Windows 7 WPS implementation not liking
259 * multiple Authentication Type bits in M7 AP Settings attribute by
260 * showing only the most secure option from current configuration.
262 if (auth_type & WPS_AUTH_WPA2PSK)
263 auth_type = WPS_AUTH_WPA2PSK;
264 else if (auth_type & WPS_AUTH_WPAPSK)
265 auth_type = WPS_AUTH_WPAPSK;
266 else if (auth_type & WPS_AUTH_OPEN)
267 auth_type = WPS_AUTH_OPEN;
269 wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)", auth_type);
270 wpabuf_put_be16(msg, ATTR_AUTH_TYPE);
271 wpabuf_put_be16(msg, 2);
272 wpabuf_put_be16(msg, auth_type);
277 static int wps_build_cred_encr_type(struct wps_data *wps, struct wpabuf *msg)
279 u16 encr_type = wps->wps->ap_encr_type;
282 * Work around issues with Windows 7 WPS implementation not liking
283 * multiple Encryption Type bits in M7 AP Settings attribute by
284 * showing only the most secure option from current configuration.
286 if (wps->wps->ap_auth_type & (WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK)) {
287 if (encr_type & WPS_ENCR_AES)
288 encr_type = WPS_ENCR_AES;
289 else if (encr_type & WPS_ENCR_TKIP)
290 encr_type = WPS_ENCR_TKIP;
293 wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)", encr_type);
294 wpabuf_put_be16(msg, ATTR_ENCR_TYPE);
295 wpabuf_put_be16(msg, 2);
296 wpabuf_put_be16(msg, encr_type);
301 static int wps_build_cred_network_key(struct wps_data *wps, struct wpabuf *msg)
303 if ((wps->wps->ap_auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) &&
304 wps->wps->network_key_len == 0) {
307 /* Generate a random per-device PSK */
308 if (random_pool_ready() != 1 ||
309 random_get_bytes(psk, sizeof(psk)) < 0) {
311 "WPS: Could not generate random PSK");
314 wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
316 wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%u)",
317 (unsigned int) wps->new_psk_len * 2);
318 wpa_snprintf_hex(hex, sizeof(hex), psk, sizeof(psk));
319 wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
320 wpabuf_put_be16(msg, sizeof(psk) * 2);
321 wpabuf_put_data(msg, hex, sizeof(psk) * 2);
322 if (wps->wps->registrar) {
323 wps_cb_new_psk(wps->wps->registrar,
324 wps->peer_dev.mac_addr,
325 wps->p2p_dev_addr, psk, sizeof(psk));
330 wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%u)",
331 (unsigned int) wps->wps->network_key_len);
332 wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
333 wpabuf_put_be16(msg, wps->wps->network_key_len);
334 wpabuf_put_data(msg, wps->wps->network_key, wps->wps->network_key_len);
339 static int wps_build_cred_mac_addr(struct wps_data *wps, struct wpabuf *msg)
341 wpa_printf(MSG_DEBUG, "WPS: * MAC Address (AP BSSID)");
342 wpabuf_put_be16(msg, ATTR_MAC_ADDR);
343 wpabuf_put_be16(msg, ETH_ALEN);
344 wpabuf_put_data(msg, wps->wps->dev.mac_addr, ETH_ALEN);
349 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *plain)
351 const u8 *start, *end;
354 if (wps->wps->ap_settings) {
355 wpa_printf(MSG_DEBUG, "WPS: * AP Settings (pre-configured)");
356 wpabuf_put_data(plain, wps->wps->ap_settings,
357 wps->wps->ap_settings_len);
361 wpa_printf(MSG_DEBUG, "WPS: * AP Settings based on current configuration");
362 start = wpabuf_put(plain, 0);
363 ret = wps_build_cred_ssid(wps, plain) ||
364 wps_build_cred_mac_addr(wps, plain) ||
365 wps_build_cred_auth_type(wps, plain) ||
366 wps_build_cred_encr_type(wps, plain) ||
367 wps_build_cred_network_key(wps, plain);
368 end = wpabuf_put(plain, 0);
370 wpa_hexdump_key(MSG_DEBUG, "WPS: Plaintext AP Settings",
377 static struct wpabuf * wps_build_m7(struct wps_data *wps)
379 struct wpabuf *msg, *plain;
381 wpa_printf(MSG_DEBUG, "WPS: Building Message M7");
383 plain = wpabuf_alloc(500 + wps->wps->ap_settings_len);
387 msg = wpabuf_alloc(1000 + wps->wps->ap_settings_len);
393 if (wps_build_version(msg) ||
394 wps_build_msg_type(msg, WPS_M7) ||
395 wps_build_registrar_nonce(wps, msg) ||
396 wps_build_e_snonce2(wps, plain) ||
397 (wps->wps->ap && wps_build_ap_settings(wps, plain)) ||
398 wps_build_key_wrap_auth(wps, plain) ||
399 wps_build_encr_settings(wps, msg, plain) ||
400 wps_build_wfa_ext(msg, 0, NULL, 0, 0) ||
401 wps_build_authenticator(wps, msg)) {
402 wpabuf_clear_free(plain);
406 wpabuf_clear_free(plain);
408 if (wps->wps->ap && wps->wps->registrar) {
410 * If the Registrar is only learning our current configuration,
411 * it may not continue protocol run to successful completion.
412 * Store information here to make sure it remains available.
414 wps_device_store(wps->wps->registrar, &wps->peer_dev,
418 wps->state = RECV_M8;
423 static struct wpabuf * wps_build_wsc_done(struct wps_data *wps)
427 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_Done");
429 msg = wpabuf_alloc(1000);
433 if (wps_build_version(msg) ||
434 wps_build_msg_type(msg, WPS_WSC_DONE) ||
435 wps_build_enrollee_nonce(wps, msg) ||
436 wps_build_registrar_nonce(wps, msg) ||
437 wps_build_wfa_ext(msg, 0, NULL, 0, 0)) {
443 wps->state = RECV_ACK;
445 wps_success_event(wps->wps, wps->peer_dev.mac_addr);
446 wps->state = WPS_FINISHED;
452 struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
453 enum wsc_op_code *op_code)
457 switch (wps->state) {
459 msg = wps_build_m1(wps);
463 msg = wps_build_m3(wps);
467 msg = wps_build_m5(wps);
471 msg = wps_build_m7(wps);
476 msg = wps_build_wsc_nack(wps);
480 msg = wps_build_wsc_ack(wps);
483 /* Another M2/M2D may be received */
484 wps->state = RECV_M2;
488 msg = wps_build_wsc_nack(wps);
492 msg = wps_build_wsc_done(wps);
496 wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
497 "a message", wps->state);
502 if (*op_code == WSC_MSG && msg) {
503 /* Save a copy of the last message for Authenticator derivation
505 wpabuf_free(wps->last_msg);
506 wps->last_msg = wpabuf_dup(msg);
513 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
515 if (r_nonce == NULL) {
516 wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
520 os_memcpy(wps->nonce_r, r_nonce, WPS_NONCE_LEN);
521 wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
522 wps->nonce_r, WPS_NONCE_LEN);
528 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
530 if (e_nonce == NULL) {
531 wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
535 if (os_memcmp(wps->nonce_e, e_nonce, WPS_NONCE_LEN) != 0) {
536 wpa_printf(MSG_DEBUG, "WPS: Invalid Enrollee Nonce received");
544 static int wps_process_uuid_r(struct wps_data *wps, const u8 *uuid_r)
546 if (uuid_r == NULL) {
547 wpa_printf(MSG_DEBUG, "WPS: No UUID-R received");
551 os_memcpy(wps->uuid_r, uuid_r, WPS_UUID_LEN);
552 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
558 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
561 if (pk == NULL || pk_len == 0) {
562 wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
566 if (wps->peer_pubkey_hash_set) {
567 u8 hash[WPS_HASH_LEN];
568 sha256_vector(1, &pk, &pk_len, hash);
569 if (os_memcmp_const(hash, wps->peer_pubkey_hash,
570 WPS_OOB_PUBKEY_HASH_LEN) != 0) {
571 wpa_printf(MSG_ERROR, "WPS: Public Key hash mismatch");
572 wpa_hexdump(MSG_DEBUG, "WPS: Received public key",
574 wpa_hexdump(MSG_DEBUG, "WPS: Calculated public key "
575 "hash", hash, WPS_OOB_PUBKEY_HASH_LEN);
576 wpa_hexdump(MSG_DEBUG, "WPS: Expected public key hash",
577 wps->peer_pubkey_hash,
578 WPS_OOB_PUBKEY_HASH_LEN);
579 wps->config_error = WPS_CFG_PUBLIC_KEY_HASH_MISMATCH;
584 wpabuf_free(wps->dh_pubkey_r);
585 wps->dh_pubkey_r = wpabuf_alloc_copy(pk, pk_len);
586 if (wps->dh_pubkey_r == NULL)
589 if (wps_derive_keys(wps) < 0)
596 static int wps_process_r_hash1(struct wps_data *wps, const u8 *r_hash1)
598 if (r_hash1 == NULL) {
599 wpa_printf(MSG_DEBUG, "WPS: No R-Hash1 received");
603 os_memcpy(wps->peer_hash1, r_hash1, WPS_HASH_LEN);
604 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", wps->peer_hash1, WPS_HASH_LEN);
610 static int wps_process_r_hash2(struct wps_data *wps, const u8 *r_hash2)
612 if (r_hash2 == NULL) {
613 wpa_printf(MSG_DEBUG, "WPS: No R-Hash2 received");
617 os_memcpy(wps->peer_hash2, r_hash2, WPS_HASH_LEN);
618 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", wps->peer_hash2, WPS_HASH_LEN);
624 static int wps_process_r_snonce1(struct wps_data *wps, const u8 *r_snonce1)
626 u8 hash[SHA256_MAC_LEN];
630 if (r_snonce1 == NULL) {
631 wpa_printf(MSG_DEBUG, "WPS: No R-SNonce1 received");
635 wpa_hexdump_key(MSG_DEBUG, "WPS: R-SNonce1", r_snonce1,
636 WPS_SECRET_NONCE_LEN);
638 /* R-Hash1 = HMAC_AuthKey(R-S1 || PSK1 || PK_E || PK_R) */
640 len[0] = WPS_SECRET_NONCE_LEN;
642 len[1] = WPS_PSK_LEN;
643 addr[2] = wpabuf_head(wps->dh_pubkey_e);
644 len[2] = wpabuf_len(wps->dh_pubkey_e);
645 addr[3] = wpabuf_head(wps->dh_pubkey_r);
646 len[3] = wpabuf_len(wps->dh_pubkey_r);
647 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
649 if (os_memcmp_const(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
650 wpa_printf(MSG_DEBUG, "WPS: R-Hash1 derived from R-S1 does "
651 "not match with the pre-committed value");
652 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
653 wps_pwd_auth_fail_event(wps->wps, 1, 1, wps->peer_dev.mac_addr);
657 wpa_printf(MSG_DEBUG, "WPS: Registrar proved knowledge of the first "
658 "half of the device password");
664 static int wps_process_r_snonce2(struct wps_data *wps, const u8 *r_snonce2)
666 u8 hash[SHA256_MAC_LEN];
670 if (r_snonce2 == NULL) {
671 wpa_printf(MSG_DEBUG, "WPS: No R-SNonce2 received");
675 wpa_hexdump_key(MSG_DEBUG, "WPS: R-SNonce2", r_snonce2,
676 WPS_SECRET_NONCE_LEN);
678 /* R-Hash2 = HMAC_AuthKey(R-S2 || PSK2 || PK_E || PK_R) */
680 len[0] = WPS_SECRET_NONCE_LEN;
682 len[1] = WPS_PSK_LEN;
683 addr[2] = wpabuf_head(wps->dh_pubkey_e);
684 len[2] = wpabuf_len(wps->dh_pubkey_e);
685 addr[3] = wpabuf_head(wps->dh_pubkey_r);
686 len[3] = wpabuf_len(wps->dh_pubkey_r);
687 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
689 if (os_memcmp_const(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
690 wpa_printf(MSG_DEBUG, "WPS: R-Hash2 derived from R-S2 does "
691 "not match with the pre-committed value");
692 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
693 wps_pwd_auth_fail_event(wps->wps, 1, 2, wps->peer_dev.mac_addr);
697 wpa_printf(MSG_DEBUG, "WPS: Registrar proved knowledge of the second "
698 "half of the device password");
704 static int wps_process_cred_e(struct wps_data *wps, const u8 *cred,
705 size_t cred_len, int wps2)
707 struct wps_parse_attr attr;
711 wpa_printf(MSG_DEBUG, "WPS: Received Credential");
712 os_memset(&wps->cred, 0, sizeof(wps->cred));
713 wpabuf_set(&msg, cred, cred_len);
714 if (wps_parse_msg(&msg, &attr) < 0 ||
715 wps_process_cred(&attr, &wps->cred))
718 if (os_memcmp(wps->cred.mac_addr, wps->wps->dev.mac_addr, ETH_ALEN) !=
720 wpa_printf(MSG_DEBUG, "WPS: MAC Address in the Credential ("
721 MACSTR ") does not match with own address (" MACSTR
722 ")", MAC2STR(wps->cred.mac_addr),
723 MAC2STR(wps->wps->dev.mac_addr));
725 * In theory, this could be consider fatal error, but there are
726 * number of deployed implementations using other address here
727 * due to unclarity in the specification. For interoperability
728 * reasons, allow this to be processed since we do not really
729 * use the MAC Address information for anything.
731 #ifdef CONFIG_WPS_STRICT
733 wpa_printf(MSG_INFO, "WPS: Do not accept incorrect "
734 "MAC Address in AP Settings");
737 #endif /* CONFIG_WPS_STRICT */
740 if (!(wps->cred.encr_type &
741 (WPS_ENCR_NONE | WPS_ENCR_TKIP | WPS_ENCR_AES))) {
742 if (wps->cred.encr_type & WPS_ENCR_WEP) {
743 wpa_printf(MSG_INFO, "WPS: Reject Credential "
744 "due to WEP configuration");
745 wps->error_indication = WPS_EI_SECURITY_WEP_PROHIBITED;
749 wpa_printf(MSG_INFO, "WPS: Reject Credential due to "
750 "invalid encr_type 0x%x", wps->cred.encr_type);
754 if (wps->wps->cred_cb) {
755 wps->cred.cred_attr = cred - 4;
756 wps->cred.cred_attr_len = cred_len + 4;
757 ret = wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
758 wps->cred.cred_attr = NULL;
759 wps->cred.cred_attr_len = 0;
766 static int wps_process_creds(struct wps_data *wps, const u8 *cred[],
767 u16 cred_len[], unsigned int num_cred, int wps2)
776 wpa_printf(MSG_DEBUG, "WPS: No Credential attributes "
781 for (i = 0; i < num_cred; i++) {
783 res = wps_process_cred_e(wps, cred[i], cred_len[i], wps2);
787 wpa_printf(MSG_DEBUG, "WPS: WEP credential skipped");
793 wpa_printf(MSG_DEBUG, "WPS: No valid Credential attribute "
802 static int wps_process_ap_settings_e(struct wps_data *wps,
803 struct wps_parse_attr *attr,
804 struct wpabuf *attrs, int wps2)
806 struct wps_credential cred;
812 if (wps_process_ap_settings(attr, &cred) < 0)
815 wpa_printf(MSG_INFO, "WPS: Received new AP configuration from "
818 if (os_memcmp(cred.mac_addr, wps->wps->dev.mac_addr, ETH_ALEN) !=
820 wpa_printf(MSG_DEBUG, "WPS: MAC Address in the AP Settings ("
821 MACSTR ") does not match with own address (" MACSTR
822 ")", MAC2STR(cred.mac_addr),
823 MAC2STR(wps->wps->dev.mac_addr));
825 * In theory, this could be consider fatal error, but there are
826 * number of deployed implementations using other address here
827 * due to unclarity in the specification. For interoperability
828 * reasons, allow this to be processed since we do not really
829 * use the MAC Address information for anything.
831 #ifdef CONFIG_WPS_STRICT
833 wpa_printf(MSG_INFO, "WPS: Do not accept incorrect "
834 "MAC Address in AP Settings");
837 #endif /* CONFIG_WPS_STRICT */
840 if (!(cred.encr_type & (WPS_ENCR_NONE | WPS_ENCR_TKIP | WPS_ENCR_AES)))
842 if (cred.encr_type & WPS_ENCR_WEP) {
843 wpa_printf(MSG_INFO, "WPS: Reject new AP settings "
844 "due to WEP configuration");
845 wps->error_indication = WPS_EI_SECURITY_WEP_PROHIBITED;
849 wpa_printf(MSG_INFO, "WPS: Reject new AP settings due to "
850 "invalid encr_type 0x%x", cred.encr_type);
854 #ifdef CONFIG_WPS_STRICT
856 if ((cred.encr_type & (WPS_ENCR_TKIP | WPS_ENCR_AES)) ==
858 (cred.auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) ==
860 wpa_printf(MSG_INFO, "WPS-STRICT: Invalid WSC 2.0 "
861 "AP Settings: WPA-Personal/TKIP only");
862 wps->error_indication =
863 WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED;
867 #endif /* CONFIG_WPS_STRICT */
869 if ((cred.encr_type & (WPS_ENCR_TKIP | WPS_ENCR_AES)) == WPS_ENCR_TKIP)
871 wpa_printf(MSG_DEBUG, "WPS: Upgrade encr_type TKIP -> "
873 cred.encr_type |= WPS_ENCR_AES;
876 if ((cred.auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) ==
878 wpa_printf(MSG_DEBUG, "WPS: Upgrade auth_type WPAPSK -> "
880 cred.auth_type |= WPS_AUTH_WPA2PSK;
883 if (wps->wps->cred_cb) {
884 cred.cred_attr = wpabuf_head(attrs);
885 cred.cred_attr_len = wpabuf_len(attrs);
886 ret = wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
893 static int wps_process_dev_pw_id(struct wps_data *wps, const u8 *dev_pw_id)
897 if (dev_pw_id == NULL) {
898 wpa_printf(MSG_DEBUG, "WPS: Device Password ID");
902 id = WPA_GET_BE16(dev_pw_id);
903 if (wps->dev_pw_id == id) {
904 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %u", id);
909 if ((id == DEV_PW_DEFAULT &&
910 wps->dev_pw_id == DEV_PW_REGISTRAR_SPECIFIED) ||
911 (id == DEV_PW_REGISTRAR_SPECIFIED &&
912 wps->dev_pw_id == DEV_PW_DEFAULT)) {
914 * Common P2P use cases indicate whether the PIN is from the
915 * client or GO using Device Password Id in M1/M2 in a way that
916 * does not look fully compliant with WSC specification. Anyway,
917 * this is deployed and needs to be allowed, so ignore changes
918 * between Registrar-Specified and Default PIN.
920 wpa_printf(MSG_DEBUG, "WPS: Allow PIN Device Password ID "
924 #endif /* CONFIG_P2P */
926 wpa_printf(MSG_DEBUG, "WPS: Registrar trying to change Device Password "
927 "ID from %u to %u", wps->dev_pw_id, id);
929 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON && id == DEV_PW_DEFAULT) {
930 wpa_printf(MSG_DEBUG,
931 "WPS: Workaround - ignore PBC-to-PIN change");
935 if (wps->alt_dev_password && wps->alt_dev_pw_id == id) {
936 wpa_printf(MSG_DEBUG, "WPS: Found a matching Device Password");
937 bin_clear_free(wps->dev_password, wps->dev_password_len);
938 wps->dev_pw_id = wps->alt_dev_pw_id;
939 wps->dev_password = wps->alt_dev_password;
940 wps->dev_password_len = wps->alt_dev_password_len;
941 wps->alt_dev_password = NULL;
942 wps->alt_dev_password_len = 0;
950 static enum wps_process_res wps_process_m2(struct wps_data *wps,
951 const struct wpabuf *msg,
952 struct wps_parse_attr *attr)
954 wpa_printf(MSG_DEBUG, "WPS: Received M2");
956 if (wps->state != RECV_M2) {
957 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
958 "receiving M2", wps->state);
959 wps->state = SEND_WSC_NACK;
963 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
964 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
965 wps_process_uuid_r(wps, attr->uuid_r) ||
966 wps_process_dev_pw_id(wps, attr->dev_password_id)) {
967 wps->state = SEND_WSC_NACK;
972 * Stop here on an AP as an Enrollee if AP Setup is locked unless the
973 * special locked mode is used to allow protocol run up to M7 in order
974 * to support external Registrars that only learn the current AP
975 * configuration without changing it.
978 ((wps->wps->ap_setup_locked && wps->wps->ap_setup_locked != 2) ||
979 wps->dev_password == NULL)) {
980 wpa_printf(MSG_DEBUG, "WPS: AP Setup is locked - refuse "
981 "registration of a new Registrar");
982 wps->config_error = WPS_CFG_SETUP_LOCKED;
983 wps->state = SEND_WSC_NACK;
987 if (wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
988 wps_process_authenticator(wps, attr->authenticator, msg) ||
989 wps_process_device_attrs(&wps->peer_dev, attr)) {
990 wps->state = SEND_WSC_NACK;
994 #ifdef CONFIG_WPS_NFC
995 if (wps->peer_pubkey_hash_set) {
996 struct wpabuf *decrypted;
997 struct wps_parse_attr eattr;
999 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1000 attr->encr_settings_len);
1001 if (decrypted == NULL) {
1002 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypt "
1003 "Encrypted Settings attribute");
1004 wps->state = SEND_WSC_NACK;
1005 return WPS_CONTINUE;
1008 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted "
1009 "Settings attribute");
1010 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1011 wps_process_key_wrap_auth(wps, decrypted,
1012 eattr.key_wrap_auth) ||
1013 wps_process_creds(wps, eattr.cred, eattr.cred_len,
1014 eattr.num_cred, attr->version2 != NULL)) {
1015 wpabuf_clear_free(decrypted);
1016 wps->state = SEND_WSC_NACK;
1017 return WPS_CONTINUE;
1019 wpabuf_clear_free(decrypted);
1021 wps->state = WPS_MSG_DONE;
1022 return WPS_CONTINUE;
1024 #endif /* CONFIG_WPS_NFC */
1026 wps->state = SEND_M3;
1027 return WPS_CONTINUE;
1031 static enum wps_process_res wps_process_m2d(struct wps_data *wps,
1032 struct wps_parse_attr *attr)
1034 wpa_printf(MSG_DEBUG, "WPS: Received M2D");
1036 if (wps->state != RECV_M2) {
1037 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1038 "receiving M2D", wps->state);
1039 wps->state = SEND_WSC_NACK;
1040 return WPS_CONTINUE;
1043 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Manufacturer",
1044 attr->manufacturer, attr->manufacturer_len);
1045 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Model Name",
1046 attr->model_name, attr->model_name_len);
1047 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Model Number",
1048 attr->model_number, attr->model_number_len);
1049 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Serial Number",
1050 attr->serial_number, attr->serial_number_len);
1051 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Device Name",
1052 attr->dev_name, attr->dev_name_len);
1054 if (wps->wps->event_cb) {
1055 union wps_event_data data;
1056 struct wps_event_m2d *m2d = &data.m2d;
1057 os_memset(&data, 0, sizeof(data));
1058 if (attr->config_methods)
1059 m2d->config_methods =
1060 WPA_GET_BE16(attr->config_methods);
1061 m2d->manufacturer = attr->manufacturer;
1062 m2d->manufacturer_len = attr->manufacturer_len;
1063 m2d->model_name = attr->model_name;
1064 m2d->model_name_len = attr->model_name_len;
1065 m2d->model_number = attr->model_number;
1066 m2d->model_number_len = attr->model_number_len;
1067 m2d->serial_number = attr->serial_number;
1068 m2d->serial_number_len = attr->serial_number_len;
1069 m2d->dev_name = attr->dev_name;
1070 m2d->dev_name_len = attr->dev_name_len;
1071 m2d->primary_dev_type = attr->primary_dev_type;
1072 if (attr->config_error)
1074 WPA_GET_BE16(attr->config_error);
1075 if (attr->dev_password_id)
1076 m2d->dev_password_id =
1077 WPA_GET_BE16(attr->dev_password_id);
1078 wps->wps->event_cb(wps->wps->cb_ctx, WPS_EV_M2D, &data);
1081 wps->state = RECEIVED_M2D;
1082 return WPS_CONTINUE;
1086 static enum wps_process_res wps_process_m4(struct wps_data *wps,
1087 const struct wpabuf *msg,
1088 struct wps_parse_attr *attr)
1090 struct wpabuf *decrypted;
1091 struct wps_parse_attr eattr;
1093 wpa_printf(MSG_DEBUG, "WPS: Received M4");
1095 if (wps->state != RECV_M4) {
1096 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1097 "receiving M4", wps->state);
1098 wps->state = SEND_WSC_NACK;
1099 return WPS_CONTINUE;
1102 if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1103 wps_process_authenticator(wps, attr->authenticator, msg) ||
1104 wps_process_r_hash1(wps, attr->r_hash1) ||
1105 wps_process_r_hash2(wps, attr->r_hash2)) {
1106 wps->state = SEND_WSC_NACK;
1107 return WPS_CONTINUE;
1110 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1111 attr->encr_settings_len);
1112 if (decrypted == NULL) {
1113 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1114 "Settings attribute");
1115 wps->state = SEND_WSC_NACK;
1116 return WPS_CONTINUE;
1119 if (wps_validate_m4_encr(decrypted, attr->version2 != NULL) < 0) {
1120 wpabuf_clear_free(decrypted);
1121 wps->state = SEND_WSC_NACK;
1122 return WPS_CONTINUE;
1125 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1127 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1128 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1129 wps_process_r_snonce1(wps, eattr.r_snonce1)) {
1130 wpabuf_clear_free(decrypted);
1131 wps->state = SEND_WSC_NACK;
1132 return WPS_CONTINUE;
1134 wpabuf_clear_free(decrypted);
1136 wps->state = SEND_M5;
1137 return WPS_CONTINUE;
1141 static enum wps_process_res wps_process_m6(struct wps_data *wps,
1142 const struct wpabuf *msg,
1143 struct wps_parse_attr *attr)
1145 struct wpabuf *decrypted;
1146 struct wps_parse_attr eattr;
1148 wpa_printf(MSG_DEBUG, "WPS: Received M6");
1150 if (wps->state != RECV_M6) {
1151 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1152 "receiving M6", wps->state);
1153 wps->state = SEND_WSC_NACK;
1154 return WPS_CONTINUE;
1157 if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1158 wps_process_authenticator(wps, attr->authenticator, msg)) {
1159 wps->state = SEND_WSC_NACK;
1160 return WPS_CONTINUE;
1163 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1164 attr->encr_settings_len);
1165 if (decrypted == NULL) {
1166 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1167 "Settings attribute");
1168 wps->state = SEND_WSC_NACK;
1169 return WPS_CONTINUE;
1172 if (wps_validate_m6_encr(decrypted, attr->version2 != NULL) < 0) {
1173 wpabuf_clear_free(decrypted);
1174 wps->state = SEND_WSC_NACK;
1175 return WPS_CONTINUE;
1178 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1180 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1181 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1182 wps_process_r_snonce2(wps, eattr.r_snonce2)) {
1183 wpabuf_clear_free(decrypted);
1184 wps->state = SEND_WSC_NACK;
1185 return WPS_CONTINUE;
1187 wpabuf_clear_free(decrypted);
1190 wps->wps->event_cb(wps->wps->cb_ctx, WPS_EV_AP_PIN_SUCCESS,
1193 wps->state = SEND_M7;
1194 return WPS_CONTINUE;
1198 static enum wps_process_res wps_process_m8(struct wps_data *wps,
1199 const struct wpabuf *msg,
1200 struct wps_parse_attr *attr)
1202 struct wpabuf *decrypted;
1203 struct wps_parse_attr eattr;
1205 wpa_printf(MSG_DEBUG, "WPS: Received M8");
1207 if (wps->state != RECV_M8) {
1208 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1209 "receiving M8", wps->state);
1210 wps->state = SEND_WSC_NACK;
1211 return WPS_CONTINUE;
1214 if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1215 wps_process_authenticator(wps, attr->authenticator, msg)) {
1216 wps->state = SEND_WSC_NACK;
1217 return WPS_CONTINUE;
1220 if (wps->wps->ap && wps->wps->ap_setup_locked) {
1222 * Stop here if special ap_setup_locked == 2 mode allowed the
1223 * protocol to continue beyond M2. This allows ER to learn the
1224 * current AP settings without changing them.
1226 wpa_printf(MSG_DEBUG, "WPS: AP Setup is locked - refuse "
1227 "registration of a new Registrar");
1228 wps->config_error = WPS_CFG_SETUP_LOCKED;
1229 wps->state = SEND_WSC_NACK;
1230 return WPS_CONTINUE;
1233 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1234 attr->encr_settings_len);
1235 if (decrypted == NULL) {
1236 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1237 "Settings attribute");
1238 wps->state = SEND_WSC_NACK;
1239 return WPS_CONTINUE;
1242 if (wps_validate_m8_encr(decrypted, wps->wps->ap,
1243 attr->version2 != NULL) < 0) {
1244 wpabuf_clear_free(decrypted);
1245 wps->state = SEND_WSC_NACK;
1246 return WPS_CONTINUE;
1249 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1251 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1252 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1253 wps_process_creds(wps, eattr.cred, eattr.cred_len,
1254 eattr.num_cred, attr->version2 != NULL) ||
1255 wps_process_ap_settings_e(wps, &eattr, decrypted,
1256 attr->version2 != NULL)) {
1257 wpabuf_clear_free(decrypted);
1258 wps->state = SEND_WSC_NACK;
1259 return WPS_CONTINUE;
1261 wpabuf_clear_free(decrypted);
1263 wps->state = WPS_MSG_DONE;
1264 return WPS_CONTINUE;
1268 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
1269 const struct wpabuf *msg)
1271 struct wps_parse_attr attr;
1272 enum wps_process_res ret = WPS_CONTINUE;
1274 wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
1276 if (wps_parse_msg(msg, &attr) < 0)
1279 if (attr.enrollee_nonce == NULL ||
1280 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
1281 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
1285 if (attr.msg_type == NULL) {
1286 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
1287 wps->state = SEND_WSC_NACK;
1288 return WPS_CONTINUE;
1291 switch (*attr.msg_type) {
1293 if (wps_validate_m2(msg) < 0)
1295 ret = wps_process_m2(wps, msg, &attr);
1298 if (wps_validate_m2d(msg) < 0)
1300 ret = wps_process_m2d(wps, &attr);
1303 if (wps_validate_m4(msg) < 0)
1305 ret = wps_process_m4(wps, msg, &attr);
1306 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1307 wps_fail_event(wps->wps, WPS_M4, wps->config_error,
1308 wps->error_indication,
1309 wps->peer_dev.mac_addr);
1312 if (wps_validate_m6(msg) < 0)
1314 ret = wps_process_m6(wps, msg, &attr);
1315 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1316 wps_fail_event(wps->wps, WPS_M6, wps->config_error,
1317 wps->error_indication,
1318 wps->peer_dev.mac_addr);
1321 if (wps_validate_m8(msg) < 0)
1323 ret = wps_process_m8(wps, msg, &attr);
1324 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1325 wps_fail_event(wps->wps, WPS_M8, wps->config_error,
1326 wps->error_indication,
1327 wps->peer_dev.mac_addr);
1330 wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
1336 * Save a copy of the last message for Authenticator derivation if we
1337 * are continuing. However, skip M2D since it is not authenticated and
1338 * neither is the ACK/NACK response frame. This allows the possibly
1339 * following M2 to be processed correctly by using the previously sent
1340 * M1 in Authenticator derivation.
1342 if (ret == WPS_CONTINUE && *attr.msg_type != WPS_M2D) {
1343 /* Save a copy of the last message for Authenticator derivation
1345 wpabuf_free(wps->last_msg);
1346 wps->last_msg = wpabuf_dup(msg);
1353 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
1354 const struct wpabuf *msg)
1356 struct wps_parse_attr attr;
1358 wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
1360 if (wps_parse_msg(msg, &attr) < 0)
1363 if (attr.msg_type == NULL) {
1364 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
1368 if (*attr.msg_type != WPS_WSC_ACK) {
1369 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
1374 if (attr.registrar_nonce == NULL ||
1375 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
1377 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
1381 if (attr.enrollee_nonce == NULL ||
1382 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
1383 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
1387 if (wps->state == RECV_ACK && wps->wps->ap) {
1388 wpa_printf(MSG_DEBUG, "WPS: External Registrar registration "
1389 "completed successfully");
1390 wps_success_event(wps->wps, wps->peer_dev.mac_addr);
1391 wps->state = WPS_FINISHED;
1399 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
1400 const struct wpabuf *msg)
1402 struct wps_parse_attr attr;
1405 wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
1407 if (wps_parse_msg(msg, &attr) < 0)
1410 if (attr.msg_type == NULL) {
1411 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
1415 if (*attr.msg_type != WPS_WSC_NACK) {
1416 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
1421 if (attr.registrar_nonce == NULL ||
1422 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
1424 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
1425 wpa_hexdump(MSG_DEBUG, "WPS: Received Registrar Nonce",
1426 attr.registrar_nonce, WPS_NONCE_LEN);
1427 wpa_hexdump(MSG_DEBUG, "WPS: Expected Registrar Nonce",
1428 wps->nonce_r, WPS_NONCE_LEN);
1432 if (attr.enrollee_nonce == NULL ||
1433 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
1434 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
1435 wpa_hexdump(MSG_DEBUG, "WPS: Received Enrollee Nonce",
1436 attr.enrollee_nonce, WPS_NONCE_LEN);
1437 wpa_hexdump(MSG_DEBUG, "WPS: Expected Enrollee Nonce",
1438 wps->nonce_e, WPS_NONCE_LEN);
1442 if (attr.config_error == NULL) {
1443 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
1448 config_error = WPA_GET_BE16(attr.config_error);
1449 wpa_printf(MSG_DEBUG, "WPS: Registrar terminated negotiation with "
1450 "Configuration Error %d", config_error);
1452 switch (wps->state) {
1454 wps_fail_event(wps->wps, WPS_M3, config_error,
1455 wps->error_indication, wps->peer_dev.mac_addr);
1458 wps_fail_event(wps->wps, WPS_M5, config_error,
1459 wps->error_indication, wps->peer_dev.mac_addr);
1462 wps_fail_event(wps->wps, WPS_M7, config_error,
1463 wps->error_indication, wps->peer_dev.mac_addr);
1469 /* Followed by NACK if Enrollee is Supplicant or EAP-Failure if
1470 * Enrollee is Authenticator */
1471 wps->state = SEND_WSC_NACK;
1477 enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
1478 enum wsc_op_code op_code,
1479 const struct wpabuf *msg)
1482 wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
1484 (unsigned long) wpabuf_len(msg), op_code);
1486 if (op_code == WSC_UPnP) {
1487 /* Determine the OpCode based on message type attribute */
1488 struct wps_parse_attr attr;
1489 if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type) {
1490 if (*attr.msg_type == WPS_WSC_ACK)
1492 else if (*attr.msg_type == WPS_WSC_NACK)
1500 return wps_process_wsc_msg(wps, msg);
1502 if (wps_validate_wsc_ack(msg) < 0)
1504 return wps_process_wsc_ack(wps, msg);
1506 if (wps_validate_wsc_nack(msg) < 0)
1508 return wps_process_wsc_nack(wps, msg);
1510 wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);