Home | History | Annotate | Download | only in wps

Lines Matching refs:wps

140 	struct wps_context *wps;
196 wpa_printf(MSG_DEBUG, "WPS: Add authorized MAC " MACSTR,
200 wpa_printf(MSG_DEBUG, "WPS: Authorized MAC was "
208 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs",
217 wpa_printf(MSG_DEBUG, "WPS: Remove authorized MAC " MACSTR,
224 wpa_printf(MSG_DEBUG, "WPS: Authorized MAC was not in the "
233 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs",
378 wpa_printf(MSG_DEBUG, "WPS: Removing PBC session for "
380 wpa_hexdump(MSG_DEBUG, "WPS: Removed UUID-E",
401 wpa_printf(MSG_DEBUG, "WPS: Checking active PBC sessions for overlap");
404 wpa_printf(MSG_DEBUG, "WPS: Add one for the requested UUID");
405 wpa_hexdump(MSG_DEBUG, "WPS: Requested UUID",
411 wpa_printf(MSG_DEBUG, "WPS: Consider PBC session with " MACSTR,
413 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E",
416 wpa_printf(MSG_DEBUG, "WPS: PBC walk time has "
422 wpa_printf(MSG_DEBUG, "WPS: Same Enrollee");
427 wpa_printf(MSG_DEBUG, "WPS: New Enrollee");
434 wpa_printf(MSG_DEBUG, "WPS: %u active PBC session(s) found", count);
440 static int wps_build_wps_state(struct wps_context *wps, struct wpabuf *msg)
442 wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
443 wps->wps_state);
446 wpabuf_put_u8(msg, wps->wps_state);
452 static void wps_registrar_free_pending_m2(struct wps_context *wps)
455 p = wps->upnp_msgs;
459 wps->upnp_msgs = p->next;
462 wpa_printf(MSG_DEBUG, "WPS UPnP: Drop pending M2/M2D");
476 static int wps_build_ap_setup_locked(struct wps_context *wps,
479 if (wps->ap_setup_locked && wps->ap_setup_locked != 2) {
480 wpa_printf(MSG_DEBUG, "WPS: * AP Setup Locked");
494 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar");
510 wpa_printf(MSG_DEBUG, "WPS: * Device Password ID (%d)", id);
528 return wps_build_uuid_e(msg, reg->wps->uuid);
563 methods = reg->wps->config_methods;
570 wps_set_pushbutton(&methods, reg->wps->config_methods);
573 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar Config Methods (%x)",
590 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
595 wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
606 return wps_build_config_methods(msg, reg->wps->config_methods);
627 * wps_registrar_init - Initialize WPS Registrar data
628 * @wps: Pointer to longterm WPS context
632 * This function is used to initialize WPS Registrar functionality. It can be
639 wps_registrar_init(struct wps_context *wps,
648 reg->wps = wps;
681 * wps_registrar_deinit - Deinitialize WPS Registrar data
740 wpa_printf(MSG_DEBUG, "WPS: A new PIN configured (timeout=%d)",
742 wpa_hexdump(MSG_DEBUG, "WPS: UUID", uuid, WPS_UUID_LEN);
743 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
787 wpa_hexdump(MSG_DEBUG, "WPS: Expired PIN for UUID",
815 wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
839 wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
871 wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
889 wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
916 wpa_printf(MSG_DEBUG, "WPS: Invalidating used "
944 wpa_printf(MSG_DEBUG, "WPS: PBC timed out - disable PBC mode");
945 wps_pbc_timeout_event(reg->wps);
969 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - do not start PBC "
971 wps_pbc_overlap_event(reg->wps);
974 wpa_printf(MSG_DEBUG, "WPS: Button pushed - PBC mode started");
996 wpa_printf(MSG_DEBUG, "WPS: PBC completed - stopping PBC mode");
1004 wpa_printf(MSG_DEBUG, "WPS: PIN completed using internal Registrar");
1025 wpa_hexdump_key(MSG_DEBUG, "WPS: Invalidated wildcard PIN",
1034 wpa_printf(MSG_DEBUG, "WPS: PBC is set - cancelling it");
1040 wpa_printf(MSG_DEBUG, "WPS: PIN is set - cancelling it");
1053 * @wps_data: WPS IE contents
1055 * This function is called on an AP when a Probe Request with WPS IE is
1057 * situation with other WPS APs.
1066 "WPS: Probe Request with WPS data received",
1073 wpa_printf(MSG_DEBUG, "WPS: No Config Methods attribute in "
1079 wpa_printf(MSG_DEBUG, "WPS: No Device Password Id attribute "
1105 wpa_printf(MSG_DEBUG, "WPS: Probe Request for PBC received from "
1108 wpa_printf(MSG_DEBUG, "WPS: Invalid Probe Request WPS IE: No "
1112 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E from Probe Request", attr.uuid_e,
1117 wpa_printf(MSG_DEBUG, "WPS: PBC session overlap detected");
1119 wps_pbc_overlap_event(reg->wps);
1169 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
1175 wps_set_pushbutton(&methods, reg->wps->config_methods);
1178 wpa_printf(MSG_DEBUG, "WPS: wps_cb_set_sel_reg: sel_reg=%d "
1180 reg->selected_registrar, reg->wps->config_methods,
1202 if (reg->wps->dev.vendor_ext[i]) {
1204 vendor_len += wpabuf_len(reg->wps->dev.vendor_ext[i]);
1219 wpa_printf(MSG_DEBUG, "WPS: Build Beacon IEs");
1222 wps_build_wps_state(reg->wps, beacon) ||
1223 wps_build_ap_setup_locked(reg->wps, beacon) ||
1228 (reg->dualband && wps_build_rf_bands(&reg->wps->dev, beacon)) ||
1230 wps_build_vendor_ext(&reg->wps->dev, beacon)) {
1237 if (wps_build_dev_name(&reg->wps->dev, beacon) ||
1238 wps_build_primary_dev_type(&reg->wps->dev, beacon)) {
1245 wpa_printf(MSG_DEBUG, "WPS: Build Probe Response IEs");
1248 wps_build_wps_state(reg->wps, probe) ||
1249 wps_build_ap_setup_locked(reg->wps, probe) ||
1253 wps_build_resp_type(probe, reg->wps->ap ? WPS_RESP_AP :
1255 wps_build_uuid_e(probe, reg->wps->uuid) ||
1256 wps_build_device_attrs(&reg->wps->dev, probe) ||
1258 wps_build_rf_bands(&reg->wps->dev, probe) ||
1260 wps_build_vendor_ext(&reg->wps->dev, probe)) {
1281 * the correct (non-WPS) behavior would be to ask for the
1289 0x00 /* no legacy 802.1X or MS WPS */
1291 wpa_printf(MSG_DEBUG, "WPS: Add Microsoft Provisioning IE "
1301 static int wps_get_dev_password(struct wps_data *wps)
1306 os_free(wps->dev_password);
1307 wps->dev_password = NULL;
1309 if (wps->pbc) {
1310 wpa_printf(MSG_DEBUG, "WPS: Use default PIN for PBC");
1314 } else if (wps->nfc_pw_token) {
1315 wpa_printf(MSG_DEBUG, "WPS: Use OOB Device Password from NFC "
1317 pin = wps->nfc_pw_token->dev_pw;
1318 pin_len = wps->nfc_pw_token->dev_pw_len;
1321 pin = wps_registrar_get_pin(wps->wps->registrar, wps->uuid_e,
1325 wpa_printf(MSG_DEBUG, "WPS: No Device Password available for "
1327 wps_cb_pin_needed(wps->wps->registrar, wps->uuid_e,
1328 &wps->peer_dev);
1332 wps->dev_password = os_malloc(pin_len);
1333 if (wps->dev_password == NULL)
1335 os_memcpy(wps->dev_password, pin, pin_len);
1336 wps->dev_password_len = pin_len;
1342 static int wps_build_uuid_r(struct wps_data *wps, struct wpabuf *msg)
1344 wpa_printf(MSG_DEBUG, "WPS: * UUID-R");
1347 wpabuf_put_data(msg, wps->uuid_r, WPS_UUID_LEN);
1352 static int wps_build_r_hash(struct wps_data *wps, struct wpabuf *msg)
1358 if (random_get_bytes(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
1360 wpa_hexdump(MSG_DEBUG, "WPS: R-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
1361 wpa_hexdump(MSG_DEBUG, "WPS: R-S2",
1362 wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
1364 if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
1365 wpa_printf(MSG_DEBUG, "WPS: DH public keys not available for "
1370 wpa_printf(MSG_DEBUG, "WPS: * R-Hash1");
1375 addr[0] = wps->snonce;
1377 addr[1] = wps->psk1;
1379 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1380 len[2] = wpabuf_len(wps->dh_pubkey_e);
1381 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1382 len[3] = wpabuf_len(wps->dh_pubkey_r);
1383 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1384 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", hash, SHA256_MAC_LEN);
1386 wpa_printf(MSG_DEBUG, "WPS: * R-Hash2");
1391 addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
1392 addr[1] = wps->psk2;
1393 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1394 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", hash, SHA256_MAC_LEN);
1400 static int wps_build_r_snonce1(struct wps_data *wps, struct wpabuf *msg)
1402 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce1");
1405 wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
1410 static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
1412 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce2");
1415 wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
1424 wpa_printf(MSG_DEBUG, "WPS: * Network Index (1)");
1435 wpa_printf(MSG_DEBUG, "WPS: * SSID");
1436 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID for Credential",
1448 wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)",
1460 wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)",
1472 wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%d)",
1474 wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
1486 wpa_printf(MSG_DEBUG, "WPS: * MAC Address (" MACSTR ")",
1528 int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
1532 if (wps->wps->registrar->skip_cred_build)
1535 wpa_printf(MSG_DEBUG, "WPS: * Credential");
1536 if (wps->use_cred) {
1537 os_memcpy(&wps->cred, wps->use_cred, sizeof(wps->cred));
1540 os_memset(&wps->cred, 0, sizeof(wps->cred));
1542 os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
1543 wps->cred.ssid_len = wps->wps->ssid_len;
1546 if (wps->auth_type & WPS_AUTH_WPA2PSK)
1547 wps->auth_type = WPS_AUTH_WPA2PSK;
1548 else if (wps->auth_type & WPS_AUTH_WPAPSK)
1549 wps->auth_type = WPS_AUTH_WPAPSK;
1550 else if (wps->auth_type & WPS_AUTH_OPEN)
1551 wps->auth_type = WPS_AUTH_OPEN;
1552 else if (wps->auth_type & WPS_AUTH_SHARED)
1553 wps->auth_type = WPS_AUTH_SHARED;
1555 wpa_printf(MSG_DEBUG, "WPS: Unsupported auth_type 0x%x",
1556 wps->auth_type);
1559 wps->cred.auth_type = wps->auth_type;
1561 if (wps->auth_type == WPS_AUTH_WPA2PSK ||
1562 wps->auth_type == WPS_AUTH_WPAPSK) {
1563 if (wps->encr_type & WPS_ENCR_AES)
1564 wps->encr_type = WPS_ENCR_AES;
1565 else if (wps->encr_type & WPS_ENCR_TKIP)
1566 wps->encr_type = WPS_ENCR_TKIP;
1568 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1573 if (wps->encr_type & WPS_ENCR_WEP)
1574 wps->encr_type = WPS_ENCR_WEP;
1575 else if (wps->encr_type & WPS_ENCR_NONE)
1576 wps->encr_type = WPS_ENCR_NONE;
1578 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1583 wps->cred.encr_type = wps->encr_type;
1587 os_memcpy(wps->cred.mac_addr, wps->mac_addr_e, ETH_ALEN);
1589 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->wps->ap &&
1590 !wps->wps->registrar->disable_auto_conf) {
1595 os_free(wps->new_psk);
1596 wps->new_psk = base64_encode(r, sizeof(r), &wps->new_psk_len);
1597 if (wps->new_psk == NULL)
1599 wps->new_psk_len--; /* remove newline */
1600 while (wps->new_psk_len &&
1601 wps->new_psk[wps->new_psk_len - 1] == '=')
1602 wps->new_psk_len--;
1603 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Generated passphrase",
1604 wps->new_psk, wps->new_psk_len);
1605 os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
1606 wps->cred.key_len = wps->new_psk_len;
1607 } else if (wps->use_psk_key && wps->wps->psk_set) {
1609 wpa_printf(MSG_DEBUG, "WPS: Use PSK format for Network Key");
1610 wpa_snprintf_hex(hex, sizeof(hex), wps->wps->psk, 32);
1611 os_memcpy(wps->cred.key, hex, 32 * 2);
1612 wps->cred.key_len = 32 * 2;
1613 } else if (wps->wps->network_key) {
1614 os_memcpy(wps->cred.key, wps->wps->network_key,
1615 wps->wps->network_key_len);
1616 wps->cred.key_len = wps->wps->network_key_len;
1617 } else if (wps->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
1620 os_free(wps->new_psk);
1621 wps->new_psk_len = 32;
1622 wps->new_psk = os_malloc(wps->new_psk_len);
1623 if (wps->new_psk == NULL)
1625 if (random_get_bytes(wps->new_psk, wps->new_psk_len) < 0) {
1626 os_free(wps->new_psk);
1627 wps->new_psk = NULL;
1630 wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
1631 wps->new_psk, wps->new_psk_len);
1632 wpa_snprintf_hex(hex, sizeof(hex), wps->new_psk,
1633 wps->new_psk_len);
1634 os_memcpy(wps->cred.key, hex, wps->new_psk_len * 2);
1635 wps->cred.key_len = wps->new_psk_len * 2;
1646 wpa_printf(MSG_DEBUG, "WPS: Add dummy credential");
1654 os_memcpy(dummy.mac_addr, wps->mac_addr_e, ETH_ALEN);
1656 wpa_hexdump_buf(MSG_DEBUG, "WPS: Dummy Credential", cred);
1670 if (wps_build_credential(cred, &wps->cred)) {
1681 if (wps->wps->registrar->extra_cred) {
1682 wpa_printf(MSG_DEBUG, "WPS: * Credential (pre-configured)");
1683 wpabuf_put_buf(msg, wps->wps->registrar->extra_cred);
1690 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
1692 wpa_printf(MSG_DEBUG, "WPS: * AP Settings");
1694 if (wps_build_credential(msg, &wps->cred))
1701 static struct wpabuf * wps_build_ap_cred(struct wps_data *wps)
1715 if (wps_build_ap_settings(wps, plain)) {
1730 static struct wpabuf * wps_build_m2(struct wps_data *wps)
1734 if (random_get_bytes(wps->nonce_r, WPS_NONCE_LEN) < 0)
1736 wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
1737 wps->nonce_r, WPS_NONCE_LEN);
1738 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
1740 wpa_printf(MSG_DEBUG, "WPS: Building Message M2");
1747 wps_build_enrollee_nonce(wps, msg) ||
1748 wps_build_registrar_nonce(wps, msg) ||
1749 wps_build_uuid_r(wps, msg) ||
1750 wps_build_public_key(wps, msg) ||
1751 wps_derive_keys(wps) ||
1752 wps_build_auth_type_flags(wps, msg) ||
1753 wps_build_encr_type_flags(wps, msg) ||
1754 wps_build_conn_type_flags(wps, msg) ||
1755 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1756 wps_build_device_attrs(&wps->wps->dev, msg) ||
1757 wps_build_rf_bands(&wps->wps->dev, msg) ||
1758 wps_build_assoc_state(wps, msg) ||
1760 wps_build_dev_password_id(msg, wps->dev_pw_id) ||
1761 wps_build_os_version(&wps->wps->dev, msg) ||
1763 wps_build_authenticator(wps, msg)) {
1768 wps->int_reg = 1;
1769 wps->state = RECV_M3;
1774 static struct wpabuf * wps_build_m2d(struct wps_data *wps)
1777 u16 err = wps->config_error;
1779 wpa_printf(MSG_DEBUG, "WPS: Building Message M2D");
1784 if (wps->wps->ap && wps->wps->ap_setup_locked &&
1790 wps_build_enrollee_nonce(wps, msg) ||
1791 wps_build_registrar_nonce(wps, msg) ||
1792 wps_build_uuid_r(wps, msg) ||
1793 wps_build_auth_type_flags(wps, msg) ||
1794 wps_build_encr_type_flags(wps, msg) ||
1795 wps_build_conn_type_flags(wps, msg) ||
1796 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1797 wps_build_device_attrs(&wps->wps->dev, msg) ||
1798 wps_build_rf_bands(&wps->wps->dev, msg) ||
1799 wps_build_assoc_state(wps, msg) ||
1801 wps_build_os_version(&wps->wps->dev, msg) ||
1807 wps->state = RECV_M2D_ACK;
1812 static struct wpabuf * wps_build_m4(struct wps_data *wps)
1816 wpa_printf(MSG_DEBUG, "WPS: Building Message M4");
1818 wps_derive_psk(wps, wps->dev_password, wps->dev_password_len);
1832 wps_build_enrollee_nonce(wps, msg) ||
1833 wps_build_r_hash(wps, msg) ||
1834 wps_build_r_snonce1(wps, plain) ||
1835 wps_build_key_wrap_auth(wps, plain) ||
1836 wps, msg, plain) ||
1838 wps_build_authenticator(wps, msg)) {
1845 wps->state = RECV_M5;
1850 static struct wpabuf * wps_build_m6(struct wps_data *wps)
1854 wpa_printf(MSG_DEBUG, "WPS: Building Message M6");
1868 wps_build_enrollee_nonce(wps, msg) ||
1869 wps_build_r_snonce2(wps, plain) ||
1870 wps_build_key_wrap_auth(wps, plain) ||
1871 wps_build_encr_settings(wps, msg, plain) ||
1873 wps_build_authenticator(wps, msg)) {
1880 wps->wps_pin_revealed = 1;
1881 wps->state = RECV_M7;
1886 static struct wpabuf * wps_build_m8(struct wps_data *wps)
1890 wpa_printf(MSG_DEBUG, "WPS: Building Message M8");
1904 wps_build_enrollee_nonce(wps, msg) ||
1905 ((wps->wps->ap || wps->er) && wps_build_cred(wps, plain)) ||
1906 (!wps->wps->ap && !wps->er && wps_build_ap_settings(wps, plain)) ||
1907 wps_build_key_wrap_auth(wps, plain) ||
1908 wps_build_encr_settings(wps, msg, plain) ||
1910 wps_build_authenticator(wps, msg)) {
1917 wps->state = RECV_DONE;
1922 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
1928 if (!wps->int_reg && wps->wps->wps_upnp) {
1930 if (wps->ext_reg > 1)
1931 wps_registrar_free_pending_m2(wps->wps);
1932 p = wps->wps->upnp_msgs;
1939 wpa_printf(MSG_DEBUG, "WPS: Use pending message from "
1944 wps->wps->upnp_msgs = NULL;
1958 if (wps->ext_reg == 0)
1959 wps->ext_reg = 1;
1963 if (wps->ext_reg) {
1964 wpa_printf(MSG_DEBUG, "WPS: Using external Registrar, but no "
1970 switch (wps->state) {
1972 if (wps_get_dev_password(wps) < 0)
1973 msg = wps_build_m2d(wps);
1975 msg = wps_build_m2(wps);
1979 msg = wps_build_m2d(wps);
1983 msg = wps_build_m4(wps);
1987 msg = wps_build_m6(wps);
1991 msg = wps_build_m8(wps);
1995 msg = wps_build_wsc_ack(wps);
1999 msg = wps_build_wsc_nack(wps);
2003 wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
2004 "a message", wps->state);
2012 wpabuf_free(wps->last_msg);
2013 wps->last_msg = wpabuf_dup(msg);
2020 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
2023 wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
2027 os_memcpy(wps->nonce_e, e_nonce, WPS_NONCE_LEN);
2028 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
2029 wps->nonce_e, WPS_NONCE_LEN);
2035 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
2038 wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
2042 if (os_memcmp(wps->nonce_r, r_nonce, WPS_NONCE_LEN) != 0) {
2043 wpa_printf(MSG_DEBUG, "WPS: Invalid Registrar Nonce received");
2051 static int wps_process_uuid_e(struct wps_data *wps, const u8 *uuid_e)
2054 wpa_printf(MSG_DEBUG, "WPS: No UUID-E received");
2058 os_memcpy(wps->uuid_e, uuid_e, WPS_UUID_LEN);
2059 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", wps->uuid_e, WPS_UUID_LEN);
2065 static int wps_process_dev_password_id(struct wps_data *wps, const u8 *pw_id)
2068 wpa_printf(MSG_DEBUG, "WPS: No Device Password ID received");
2072 wps->dev_pw_id = WPA_GET_BE16(pw_id);
2073 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %d", wps->dev_pw_id);
2079 static int wps_process_e_hash1(struct wps_data *wps, const u8 *e_hash1)
2082 wpa_printf(MSG_DEBUG, "WPS: No E-Hash1 received");
2086 os_memcpy(wps->peer_hash1, e_hash1, WPS_HASH_LEN);
2087 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", wps->peer_hash1, WPS_HASH_LEN);
2093 static int wps_process_e_hash2(struct wps_data *wps, const u8 *e_hash2)
2096 wpa_printf(MSG_DEBUG, "WPS: No E-Hash2 received");
2100 os_memcpy(wps->peer_hash2, e_hash2, WPS_HASH_LEN);
2101 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", wps->peer_hash2, WPS_HASH_LEN);
2107 static int wps_process_e_snonce1(struct wps_data *wps, const u8 *e_snonce1)
2114 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce1 received");
2118 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce1", e_snonce1,
2124 addr[1] = wps->psk1;
2126 addr[2] = wpabuf_head(wps->dh_pubkey_e);
2127 len[2] = wpabuf_len(wps->dh_pubkey_e);
2128 addr[3] = wpabuf_head(wps->dh_pubkey_r);
2129 len[3] = wpabuf_len(wps->dh_pubkey_r);
2130 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
2132 if (os_memcmp(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
2133 wpa_printf(MSG_DEBUG, "WPS: E-Hash1 derived from E-S1 does "
2135 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
2136 wps_pwd_auth_fail_event(wps->wps, 0, 1);
2140 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the first "
2147 static int wps_process_e_snonce2(struct wps_data *wps, const u8 *e_snonce2)
2154 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce2 received");
2158 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce2", e_snonce2,
2164 addr[1] = wps->psk2;
2166 addr[2] = wpabuf_head(wps->dh_pubkey_e);
2167 len[2] = wpabuf_len(wps->dh_pubkey_e);
2168 addr[3] = wpabuf_head(wps->dh_pubkey_r);
2169 len[3] = wpabuf_len(wps->dh_pubkey_r);
2170 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
2172 if (os_memcmp(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
2173 wpa_printf(MSG_DEBUG, "WPS: E-Hash2 derived from E-S2 does "
2175 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
2176 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
2177 wps_pwd_auth_fail_event(wps->wps, 0, 2);
2181 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the second "
2183 wps->wps_pin_revealed = 0;
2184 wps_registrar_unlock_pin(wps->wps->registrar, wps->uuid_e);
2187 * In case wildcard PIN is used and WPS handshake succeeds in the first
2191 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
2197 static int wps_process_mac_addr(struct wps_data *wps, const u8 *mac_addr)
2200 wpa_printf(MSG_DEBUG, "WPS: No MAC Address received");
2204 wpa_printf(MSG_DEBUG, "WPS: Enrollee MAC Address " MACSTR,
2206 os_memcpy(wps->mac_addr_e, mac_addr, ETH_ALEN);
2207 os_memcpy(wps->peer_dev.mac_addr, mac_addr, ETH_ALEN);
2213 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
2217 wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
2222 if (wps->wps->oob_conf.pubkey_hash != NULL) {
2229 wpabuf_head(wps->wps->oob_conf.pubkey_hash),
2231 wpa_printf(MSG_ERROR, "WPS: Public Key hash error");
2237 wpabuf_free(wps->dh_pubkey_e);
2238 wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
2239 if (wps->dh_pubkey_e == NULL)
2246 static int wps_process_auth_type_flags(struct wps_data *wps, const u8 *auth)
2251 wpa_printf(MSG_DEBUG, "WPS: No Authentication Type flags "
2258 wpa_printf(MSG_DEBUG, "WPS: Enrollee Authentication Type flags 0x%x",
2260 wps->auth_type = wps->wps->auth_types & auth_types;
2261 if (wps->auth_type == 0) {
2262 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
2264 wps->wps->auth_types, auth_types);
2273 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
2276 wps->auth_type = wps->wps->auth_types;
2286 static int wps_process_encr_type_flags(struct wps_data *wps, const u8 *encr)
2291 wpa_printf(MSG_DEBUG, "WPS: No Encryption Type flags "
2298 wpa_printf(MSG_DEBUG, "WPS: Enrollee Encryption Type flags 0x%x",
2300 wps->encr_type = wps->wps->encr_types & encr_types;
2301 if (wps->encr_type == 0) {
2302 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
2304 wps->wps->encr_types, encr_types);
2313 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
2316 wps->encr_type = wps->wps->encr_types;
2326 static int wps_process_conn_type_flags(struct wps_data *wps, const u8 *conn)
2329 wpa_printf(MSG_DEBUG, "WPS: No Connection Type flags "
2334 wpa_printf(MSG_DEBUG, "WPS: Enrollee Connection Type flags 0x%x",
2341 static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
2346 wpa_printf(MSG_DEBUG, "WPS: No Config Methods received");
2352 wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x"
2364 if (!(m & WPS_CONFIG_DISPLAY) && !wps->use_psk_key) {
2370 wpa_printf(MSG_DEBUG, "WPS: Prefer PSK format key due to "
2372 wps->use_psk_key = 1;
2379 static int wps_process_wps_state(struct wps_data *wps, const u8 *state)
2382 wpa_printf(MSG_DEBUG, "WPS: No Wi-Fi Protected Setup State "
2387 wpa_printf(MSG_DEBUG, "WPS: Enrollee Wi-Fi Protected Setup State %d",
2394 static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc)
2399 wpa_printf(MSG_DEBUG, "WPS: No Association State received");
2404 wpa_printf(MSG_DEBUG, "WPS: Enrollee Association State %d", a);
2410 static int wps_process_config_error(struct wps_data *wps, const u8 *err)
2415 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error received");
2420 wpa_printf(MSG_DEBUG, "WPS: Enrollee Configuration Error %d", e);
2426 static int wps_registrar_p2p_dev_addr_match(struct wps_data *wps)
2429 struct wps_registrar *reg = wps->wps->registrar;
2434 if (os_memcmp(reg->p2p_dev_addr, wps->p2p_dev_addr, ETH_ALEN) != 0) {
2435 wpa_printf(MSG_DEBUG, "WPS: No match on P2P Device Address "
2439 MAC2STR(wps->p2p_dev_addr));
2447 static int wps_registrar_skip_overlap(struct wps_data *wps)
2450 struct wps_registrar *reg = wps->wps->registrar;
2455 if (os_memcmp(reg->p2p_dev_addr, wps->p2p_dev_addr, ETH_ALEN) == 0) {
2456 wpa_printf(MSG_DEBUG, "WPS: Skip PBC overlap due to selected "
2465 static enum wps_process_res wps_process_m1(struct wps_data *wps,
2468 wpa_printf(MSG_DEBUG, "WPS: Received M1");
2470 if (wps->state != RECV_M1) {
2471 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2472 "receiving M1", wps->state);
2476 if (wps_process_uuid_e(wps, attr->uuid_e) ||
2477 wps_process_mac_addr(wps, attr->mac_addr) ||
2478 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
2479 wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
2480 wps_process_auth_type_flags(wps, attr->auth_type_flags) ||
2481 wps_process_encr_type_flags(wps, attr->encr_type_flags) ||
2482 wps_process_conn_type_flags(wps, attr->conn_type_flags) ||
2483 wps_process_config_methods(wps, attr->config_methods) ||
2484 wps_process_wps_state(wps, attr->wps_state) ||
2485 wps_process_device_attrs(&wps->peer_dev, attr) ||
2486 wps_process_rf_bands(&wps->peer_dev, attr->rf_bands) ||
2487 wps_process_assoc_state(wps, attr->assoc_state) ||
2488 wps_process_dev_password_id(wps, attr->dev_password_id) ||
2489 wps, attr->config_error) ||
2490 wps_process_os_version(&wps->peer_dev, attr->os_version))
2493 if (wps->dev_pw_id < 0x10 &&
2494 wps->dev_pw_id != DEV_PW_DEFAULT &&
2495 wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
2496 wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
2497 wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
2498 (wps->dev_pw_id != DEV_PW_PUSHBUTTON ||
2499 !wps->wps->registrar->pbc)) {
2500 wpa_printf(MSG_DEBUG, "WPS: Unsupported Device Password ID %d",
2501 wps->dev_pw_id);
2502 wps->state = SEND_M2D;
2507 if (wps->dev_pw_id >= 0x10) {
2513 &wps->wps->registrar->nfc_pw_tokens, wps->dev_pw_id);
2515 wpa_printf(MSG_DEBUG, "WPS: Found matching NFC "
2518 wps->nfc_pw_token = token;
2522 if (os_memcmp(hash, wps->nfc_pw_token->pubkey_hash,
2524 wpa_printf(MSG_ERROR, "WPS: Public Key hash "
2533 if (wps->dev_pw_id >= 0x10 && wps->nfc_pw_token == NULL &&
2534 wps->dev_pw_id != wps->wps->oob_dev_pw_id) {
2535 wpa_printf(MSG_DEBUG, "WPS: OOB Device Password ID "
2536 "%d mismatch", wps->dev_pw_id);
2537 wps->state = SEND_M2D;
2542 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
2543 if ((wps->wps->registrar->force_pbc_overlap ||
2544 wps_registrar_pbc_overlap(wps->wps->registrar,
2545 wps->mac_addr_e, wps->uuid_e) ||
2546 !wps_registrar_p2p_dev_addr_match(wps)) &&
2547 !wps_registrar_skip_overlap(wps)) {
2548 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - deny PBC "
2550 wps->state = SEND_M2D;
2551 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2552 wps_pbc_overlap_event(wps->wps);
2553 wps_fail_event(wps->wps, WPS_M1,
2556 wps->wps->registrar->force_pbc_overlap = 1;
2559 wps_registrar_add_pbc_session(wps->wps->registrar,
2560 wps->mac_addr_e, wps->uuid_e);
2561 wps->pbc = 1;
2570 if (!wps->use_psk_key &&
2571 wps->peer_dev.manufacturer &&
2572 os_strncmp(wps->peer_dev.manufacturer, "Apple ", 6) == 0 &&
2573 wps->peer_dev.model_name &&
2574 os_strcmp(wps->peer_dev.model_name, "AirPort") == 0) {
2575 wpa_printf(MSG_DEBUG, "WPS: Workaround - Force Network Key in "
2577 wps->use_psk_key = 1;
2581 wps->state = SEND_M2;
2586 static enum wps_process_res wps_process_m3(struct wps_data *wps,
2590 wpa_printf(MSG_DEBUG, "WPS: Received M3");
2592 if (wps->state != RECV_M3) {
2593 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2594 "receiving M3", wps->state);
2595 wps->state = SEND_WSC_NACK;
2599 if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
2600 !wps_registrar_skip_overlap(wps)) {
2601 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2603 wps->state = SEND_WSC_NACK;
2604 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2608 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2609 wps_process_authenticator(wps, attr->authenticator, msg) ||
2610 wps_process_e_hash1(wps, attr->e_hash1) ||
2611 wps_process_e_hash2(wps, attr->e_hash2)) {
2612 wps->state = SEND_WSC_NACK;
2616 wps->state = SEND_M4;
2621 static enum wps_process_res wps_process_m5(struct wps_data *wps,
2628 wpa_printf(MSG_DEBUG, "WPS: Received M5");
2630 if (wps->state != RECV_M5) {
2631 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2632 "receiving M5", wps->state);
2633 wps->state = SEND_WSC_NACK;
2637 if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
2638 !wps_registrar_skip_overlap(wps)) {
2639 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2641 wps->state = SEND_WSC_NACK;
2642 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2646 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2647 wps_process_authenticator(wps, attr->authenticator, msg)) {
2648 wps->state = SEND_WSC_NACK;
2652 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2655 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
2657 wps->state = SEND_WSC_NACK;
2663 wps->state = SEND_WSC_NACK;
2667 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2670 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2671 wps_process_e_snonce1(wps, eattr.e_snonce1)) {
2673 wps->state = SEND_WSC_NACK;
2678 wps->state = SEND_M6;
2683 static void wps_sta_cred_cb(struct wps_data *wps)
2690 if (wps->cred.auth_type & WPS_AUTH_WPA2PSK)
2691 wps->cred.auth_type = WPS_AUTH_WPA2PSK;
2692 else if (wps->cred.auth_type & WPS_AUTH_WPAPSK)
2693 wps->cred.auth_type = WPS_AUTH_WPAPSK;
2694 if (wps->cred.encr_type & WPS_ENCR_AES)
2695 wps->cred.encr_type = WPS_ENCR_AES;
2696 else if (wps->cred.encr_type & WPS_ENCR_TKIP)
2697 wps->cred.encr_type = WPS_ENCR_TKIP;
2698 wpa_printf(MSG_DEBUG, "WPS: Update local configuration based on the "
2700 if (wps->wps->cred_cb)
2701 wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
2718 static int wps_process_ap_settings_r(struct wps_data *wps,
2723 if (wps->wps->ap || wps->er)
2727 if (wps_process_ap_settings(attr, &wps->cred) < 0)
2730 wpa_printf(MSG_INFO, "WPS: Received old AP configuration from AP");
2732 if (wps->new_ap_settings) {
2733 wpa_printf(MSG_INFO, "WPS: Update AP configuration based on "
2735 wps_cred_update(&wps->cred, wps->new_ap_settings);
2747 wps_registrar_pin_completed(wps->wps->registrar);
2749 msg = wps_build_ap_cred(wps);
2752 wps->cred.cred_attr = wpabuf_head(msg);
2753 wps->cred.cred_attr_len = wpabuf_len(msg);
2755 if (wps->ap_settings_cb) {
2756 wps->ap_settings_cb(wps->ap_settings_cb_ctx,
2757 &wps->cred);
2761 wps_sta_cred_cb(wps);
2763 wps->cred.cred_attr = NULL;
2764 wps->cred.cred_attr_len = 0;
2772 static enum wps_process_res wps_process_m7(struct wps_data *wps,
2779 wpa_printf(MSG_DEBUG, "WPS: Received M7");
2781 if (wps->state != RECV_M7) {
2782 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2783 "receiving M7", wps->state);
2784 wps->state = SEND_WSC_NACK;
2788 if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
2789 !wps_registrar_skip_overlap(wps)) {
2790 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2792 wps->state = SEND_WSC_NACK;
2793 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2797 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2798 wps_process_authenticator(wps, attr->authenticator, msg)) {
2799 wps->state = SEND_WSC_NACK;
2803 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2806 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypt Encrypted "
2808 wps->state = SEND_WSC_NACK;
2812 if (wps_validate_m7_encr(decrypted, wps->wps->ap || wps->er,
2815 wps->state = SEND_WSC_NACK;
2819 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2822 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2823 wps_process_e_snonce2(wps, eattr.e_snonce2) ||
2824 wps_process_ap_settings_r(wps, &eattr)) {
2826 wps->state = SEND_WSC_NACK;
2832 wps->state = SEND_M8;
2837 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
2843 wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
2849 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2850 wps->state = SEND_WSC_NACK;
2856 os_memcmp(wps->nonce_r, attr.registrar_nonce,
2858 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2867 if (wps->wps->wps_upnp && attr.mac_addr) {
2869 wps_free_pending_msgs(wps->wps->upnp_msgs);
2870 wps->wps->upnp_msgs = NULL;
2873 wps->wps->wps_upnp, attr.mac_addr,
2877 ret = wps_process_m1(wps, &attr);
2882 ret = wps_process_m3(wps, msg, &attr);
2883 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2884 wps_fail_event(wps->wps, WPS_M3, wps->config_error,
2885 wps->error_indication);
2890 ret = wps_process_m5(wps, msg, &attr);
2891 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2892 wps_fail_event(wps->wps, WPS_M5, wps->config_error,
2893 wps->error_indication);
2898 ret = wps_process_m7(wps, msg, &attr);
2899 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2900 wps_fail_event(wps->wps, WPS_M7, wps->config_error,
2901 wps->error_indication);
2904 wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
2912 wpabuf_free(wps->last_msg);
2913 wps->last_msg = wpabuf_dup(msg);
2920 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
2925 wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
2931 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2936 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2942 if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK &&
2943 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2944 if (wps->wps->upnp_msgs)
2946 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2953 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
2955 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2960 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
2961 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2965 if (wps->state == RECV_M2D_ACK) {
2967 if (wps->wps->wps_upnp &&
2968 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2969 if (wps->wps->upnp_msgs)
2971 if (wps->ext_reg == 0)
2972 wps->ext_reg = 1;
2973 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2979 wpa_printf(MSG_DEBUG, "WPS: No more registrars available - "
2987 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
2994 wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
2996 old_state = wps->state;
2997 wps->state = SEND_WSC_NACK;
3003 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
3008 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
3014 if (wps->wps->wps_upnp && wps->ext_reg) {
3015 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
3022 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
3024 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
3029 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
3030 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
3035 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
3041 wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
3046 wps_fail_event(wps->wps, WPS_M2, config_error,
3047 wps->error_indication);
3050 wps_fail_event(wps->wps, WPS_M4, config_error,
3051 wps->error_indication);
3054 wps_fail_event(wps->wps, WPS_M6, config_error,
3055 wps->error_indication);
3058 wps_fail_event(wps->wps, WPS_M8, config_error,
3059 wps->error_indication);
3069 static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
3074 wpa_printf(MSG_DEBUG, "WPS: Received WSC_Done");
3076 if (wps->state != RECV_DONE &&
3077 (!wps->wps->wps_upnp || !wps->ext_reg)) {
3078 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
3079 "receiving WSC_Done", wps->state);
3087 WPS: No Message Type attribute");
3092 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
3098 if (wps->wps->wps_upnp && wps->ext_reg) {
3099 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
3101 wps_device_store(wps->wps->registrar, &wps->peer_dev,
3102 wps->uuid_e);
3108 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
3110 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
3115 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
3116 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
3120 wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully");
3121 wps_device_store(wps->wps->registrar, &wps->peer_dev,
3122 wps->uuid_e);
3124 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
3125 wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
3128 wpa_printf(MSG_DEBUG, "WPS: Moving to Configured state based "
3132 os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
3133 cred.ssid_len = wps->wps->ssid_len;
3136 os_memcpy(cred.key, wps->new_psk, wps->new_psk_len);
3137 cred.key_len = wps->new_psk_len;
3139 wps->wps->wps_state = WPS_STATE_CONFIGURED;
3141 "WPS: Generated random passphrase",
3142 wps->new_psk, wps->new_psk_len);
3143 if (wps->wps->cred_cb)
3144 wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
3146 os_free(wps->new_psk);
3147 wps->new_psk = NULL;
3150 if (!wps->wps->ap && !wps->er)
3151 wps_sta_cred_cb(wps);
3153 if (wps->new_psk) {
3154 if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e,
3155 wps->new_psk, wps->new_psk_len)) {
3156 wpa_printf(MSG_DEBUG, "WPS: Failed to configure the "
3159 os_free(wps->new_psk);
3160 wps->new_psk = NULL;
3163 wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e,
3164 wps->dev_password, wps->dev_password_len);
3166 if (wps->pbc) {
3167 wps_registrar_remove_pbc_session(wps->wps->registrar,
3168 wps->uuid_e,
3169 wps->p2p_dev_addr);
3170 wps_registrar_pbc_completed(wps->wps->registrar);
3172 wps_registrar_pin_completed(wps->wps->registrar);
3177 wps_success_event(wps->wps);
3183 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
3189 wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
3194 if (wps->wps->wps_upnp && op_code == WSC_MSG && wps->ext_reg == 1) {
3198 wps->ext_reg = 2; /* past M2/M2D phase */
3200 if (wps->ext_reg > 1)
3201 wps_registrar_free_pending_m2(wps->wps);
3202 if (wps->wps->wps_upnp && wps->ext_reg &&
3203 wps->wps->upnp_msgs == NULL &&
3212 wpa_printf(MSG_DEBUG, "WPS: Sending received message (type %d)"
3214 upnp_wps_device_send_wlan_event(wps->wps->wps_upnp,
3215 wps->mac_addr_e,
3220 } else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) {
3221 wpa_printf(MSG_DEBUG, "WPS: Skip internal processing - using "
3229 return wps_process_wsc_msg(wps, msg);
3233 return wps_process_wsc_ack(wps, msg);
3237 return wps_process_wsc_nack(wps, msg);
3241 ret = wps_process_wsc_done(wps, msg);
3243 wps->state = SEND_WSC_NACK;
3244 wps_fail_event(wps->wps, WPS_WSC_DONE,
3245 wps->config_error,
3246 wps->error_indication);
3250 wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);
3267 wpa_printf(MSG_DEBUG, "WPS: Selected Registrar timeout - "
3280 wpa_printf(MSG_DEBUG, "WPS: External Registrar selected (dev_pw_id=%d "
3296 wpa_printf(MSG_DEBUG, "WPS: Add authorized MAC into union: "
3302 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs union",
3314 if (reg->wps->wps_upnp == NULL)
3317 dl_list_for_each(s, &reg->wps->wps_upnp->subscriptions,
3322 wpa_printf(MSG_DEBUG, "WPS: External Registrar %s:%d",
3329 wpa_printf(MSG_DEBUG, "WPS: External Registrar not "
3345 wpa_printf(MSG_DEBUG, "WPS: Selected registrar information changed");
3352 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs union (start with own)",
3358 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
3366 wps_set_pushbutton(&methods, reg->wps->config_methods);
3368 wpa_printf(MSG_DEBUG, "WPS: Internal Registrar selected "
3372 wpa_printf(MSG_DEBUG, "WPS: Internal Registrar not selected");
3427 wpa_printf(MSG_INFO, "WPS: Reject new AP settings "
3432 wpa_printf(MSG_INFO, "WPS: Reject new AP settings due to "
3439 wpa_printf(MSG_DEBUG, "WPS: Upgrade encr_type TKIP -> "
3446 wpa_printf(MSG_DEBUG, "WPS: Upgrade auth_type WPAPSK -> "
3452 if (reg->wps->cred_cb)
3453 return reg->wps->cred_cb(reg->wps->cb_ctx, cred);
3517 wpa_printf(MSG_DEBUG, "WPS: Add NFC Password Token for Password ID %u",
3520 wpa_hexdump(MSG_DEBUG, "WPS: Public Key Hash",
3522 wpa_hexdump_key(MSG_DEBUG, "WPS: Device Password", dev_pw, dev_pw_len);