Lines Matching refs:wps

140 	struct wps_context *wps;
446 static int wps_build_wps_state(struct wps_context *wps, struct wpabuf *msg)
449 wps->wps_state);
452 wpabuf_put_u8(msg, wps->wps_state);
458 static void wps_registrar_free_pending_m2(struct wps_context *wps)
461 p = wps->upnp_msgs;
465 wps->upnp_msgs = p->next;
482 static int wps_build_ap_setup_locked(struct wps_context *wps,
485 if (wps->ap_setup_locked && wps->ap_setup_locked != 2) {
534 return wps_build_uuid_e(msg, reg->wps->uuid);
569 methods = reg->wps->config_methods;
576 wps_set_pushbutton(&methods, reg->wps->config_methods);
596 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
612 return wps_build_config_methods(msg, reg->wps->config_methods);
634 * @wps: Pointer to longterm WPS context
645 wps_registrar_init(struct wps_context *wps,
654 reg->wps = wps;
970 wps_pbc_timeout_event(reg->wps);
996 wps_pbc_overlap_event(reg->wps);
1011 wps_pbc_active_event(reg->wps);
1025 wps_pbc_disable_event(reg->wps);
1166 wps_pbc_overlap_event(reg->wps);
1217 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
1223 wps_set_pushbutton(&methods, reg->wps->config_methods);
1228 reg->selected_registrar, reg->wps->config_methods,
1250 if (reg->wps->dev.vendor_ext[i]) {
1252 vendor_len += wpabuf_len(reg->wps->dev.vendor_ext[i]);
1270 wps_build_wps_state(reg->wps, beacon) ||
1271 wps_build_ap_setup_locked(reg->wps, beacon) ||
1276 (reg->dualband && wps_build_rf_bands(&reg->wps->dev, beacon, 0)) ||
1278 wps_build_vendor_ext(&reg->wps->dev, beacon)) {
1285 if (wps_build_dev_name(&reg->wps->dev, beacon) ||
1286 wps_build_primary_dev_type(&reg->wps->dev, beacon)) {
1296 wps_build_wps_state(reg->wps, probe) ||
1297 wps_build_ap_setup_locked(reg->wps, probe) ||
1301 wps_build_resp_type(probe, reg->wps->ap ? WPS_RESP_AP :
1303 wps_build_uuid_e(probe, reg->wps->uuid) ||
1304 wps_build_device_attrs(&reg->wps->dev, probe) ||
1306 (reg->dualband && wps_build_rf_bands(&reg->wps->dev, probe, 0)) ||
1308 wps_build_vendor_ext(&reg->wps->dev, probe)) {
1349 static int wps_get_dev_password(struct wps_data *wps)
1354 os_free(wps->dev_password);
1355 wps->dev_password = NULL;
1357 if (wps->pbc) {
1362 } else if (wps->nfc_pw_token) {
1365 pin = wps->nfc_pw_token->dev_pw;
1366 pin_len = wps->nfc_pw_token->dev_pw_len;
1369 pin = wps_registrar_get_pin(wps->wps->registrar, wps->uuid_e,
1371 if (pin && wps->dev_pw_id >= 0x10) {
1377 wps->dev_pw_id = DEV_PW_DEFAULT;
1383 wps_cb_pin_needed(wps->wps->registrar, wps->uuid_e,
1384 &wps->peer_dev);
1388 wps->dev_password = os_malloc(pin_len);
1389 if (wps->dev_password == NULL)
1391 os_memcpy(wps->dev_password, pin, pin_len);
1392 wps->dev_password_len = pin_len;
1398 static int wps_build_uuid_r(struct wps_data *wps, struct wpabuf *msg)
1403 wpabuf_put_data(msg, wps->uuid_r, WPS_UUID_LEN);
1408 static int wps_build_r_hash(struct wps_data *wps, struct wpabuf *msg)
1414 if (random_get_bytes(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
1416 wpa_hexdump(MSG_DEBUG, "WPS: R-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
1418 wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
1420 if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
1431 addr[0] = wps->snonce;
1433 addr[1] = wps->psk1;
1435 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1436 len[2] = wpabuf_len(wps->dh_pubkey_e);
1437 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1438 len[3] = wpabuf_len(wps->dh_pubkey_r);
1439 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1447 addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
1448 addr[1] = wps->psk2;
1449 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1456 static int wps_build_r_snonce1(struct wps_data *wps, struct wpabuf *msg)
1461 wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
1466 static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
1471 wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
1572 int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
1576 if (wps->wps->registrar->skip_cred_build)
1580 if (wps->use_cred) {
1581 os_memcpy(&wps->cred, wps->use_cred, sizeof(wps->cred));
1584 os_memset(&wps->cred, 0, sizeof(wps->cred));
1586 os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
1587 wps->cred.ssid_len = wps->wps->ssid_len;
1590 if (wps->auth_type & WPS_AUTH_WPA2PSK)
1591 wps->auth_type = WPS_AUTH_WPA2PSK;
1592 else if (wps->auth_type & WPS_AUTH_WPAPSK)
1593 wps->auth_type = WPS_AUTH_WPAPSK;
1594 else if (wps->auth_type & WPS_AUTH_OPEN)
1595 wps->auth_type = WPS_AUTH_OPEN;
1596 else if (wps->auth_type & WPS_AUTH_SHARED)
1597 wps->auth_type = WPS_AUTH_SHARED;
1600 wps->auth_type);
1603 wps->cred.auth_type = wps->auth_type;
1605 if (wps->auth_type == WPS_AUTH_WPA2PSK ||
1606 wps->auth_type == WPS_AUTH_WPAPSK) {
1607 if (wps->encr_type & WPS_ENCR_AES)
1608 wps->encr_type = WPS_ENCR_AES;
1609 else if (wps->encr_type & WPS_ENCR_TKIP)
1610 wps->encr_type = WPS_ENCR_TKIP;
1617 if (wps->encr_type & WPS_ENCR_WEP)
1618 wps->encr_type = WPS_ENCR_WEP;
1619 else if (wps->encr_type & WPS_ENCR_NONE)
1620 wps->encr_type = WPS_ENCR_NONE;
1627 wps->cred.encr_type = wps->encr_type;
1631 os_memcpy(wps->cred.mac_addr, wps->mac_addr_e, ETH_ALEN);
1633 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->wps->ap &&
1634 !wps->wps->registrar->disable_auto_conf) {
1639 os_free(wps->new_psk);
1640 wps->new_psk = base64_encode(r, sizeof(r), &wps->new_psk_len);
1641 if (wps->new_psk == NULL)
1643 wps->new_psk_len--; /* remove newline */
1644 while (wps->new_psk_len &&
1645 wps->new_psk[wps->new_psk_len - 1] == '=')
1646 wps->new_psk_len--;
1648 wps->new_psk, wps->new_psk_len);
1649 os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
1650 wps->cred.key_len = wps->new_psk_len;
1651 } else if (!wps->wps->registrar->force_per_enrollee_psk &&
1652 wps->use_psk_key && wps->wps->psk_set) {
1655 wpa_snprintf_hex(hex, sizeof(hex), wps->wps->psk, 32);
1656 os_memcpy(wps->cred.key, hex, 32 * 2);
1657 wps->cred.key_len = 32 * 2;
1658 } else if (!wps->wps->registrar->force_per_enrollee_psk &&
1659 wps->wps->network_key) {
1660 os_memcpy(wps->cred.key, wps->wps->network_key,
1661 wps->wps->network_key_len);
1662 wps->cred.key_len = wps->wps->network_key_len;
1663 } else if (wps->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
1666 os_free(wps->new_psk);
1667 wps->new_psk_len = 32;
1668 wps->new_psk = os_malloc(wps->new_psk_len);
1669 if (wps->new_psk == NULL)
1671 if (random_get_bytes(wps->new_psk, wps->new_psk_len) < 0) {
1672 os_free(wps->new_psk);
1673 wps->new_psk = NULL;
1677 wps->new_psk, wps->new_psk_len);
1678 wpa_snprintf_hex(hex, sizeof(hex), wps->new_psk,
1679 wps->new_psk_len);
1680 os_memcpy(wps->cred.key, hex, wps->new_psk_len * 2);
1681 wps->cred.key_len = wps->new_psk_len * 2;
1700 os_memcpy(dummy.mac_addr, wps->mac_addr_e, ETH_ALEN);
1716 if (wps_build_credential(cred, &wps->cred)) {
1727 if (wps->wps->registrar->extra_cred) {
1729 wpabuf_put_buf(msg, wps->wps->registrar->extra_cred);
1736 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
1740 if (wps_build_credential(msg, &wps->cred))
1747 static struct wpabuf * wps_build_ap_cred(struct wps_data *wps)
1761 if (wps_build_ap_settings(wps, plain)) {
1776 static struct wpabuf * wps_build_m2(struct wps_data *wps)
1780 if (random_get_bytes(wps->nonce_r, WPS_NONCE_LEN) < 0)
1783 wps->nonce_r, WPS_NONCE_LEN);
1784 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
1793 wps_build_enrollee_nonce(wps, msg) ||
1794 wps_build_registrar_nonce(wps, msg) ||
1795 wps_build_uuid_r(wps, msg) ||
1796 wps_build_public_key(wps, msg) ||
1797 wps_derive_keys(wps) ||
1798 wps_build_auth_type_flags(wps, msg) ||
1799 wps_build_encr_type_flags(wps, msg) ||
1800 wps_build_conn_type_flags(wps, msg) ||
1801 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1802 wps_build_device_attrs(&wps->wps->dev, msg) ||
1803 wps_build_rf_bands(&wps->wps->dev, msg,
1804 wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
1805 wps_build_assoc_state(wps, msg) ||
1807 wps_build_dev_password_id(msg, wps->dev_pw_id) ||
1808 wps_build_os_version(&wps->wps->dev, msg) ||
1810 wps_build_authenticator(wps, msg)) {
1815 wps->int_reg = 1;
1816 wps->state = RECV_M3;
1821 static struct wpabuf * wps_build_m2d(struct wps_data *wps)
1824 u16 err = wps->config_error;
1831 if (wps->wps->ap && wps->wps->ap_setup_locked &&
1837 wps_build_enrollee_nonce(wps, msg) ||
1838 wps_build_registrar_nonce(wps, msg) ||
1839 wps_build_uuid_r(wps, msg) ||
1840 wps_build_auth_type_flags(wps, msg) ||
1841 wps_build_encr_type_flags(wps, msg) ||
1842 wps_build_conn_type_flags(wps, msg) ||
1843 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1844 wps_build_device_attrs(&wps->wps->dev, msg) ||
1845 wps_build_rf_bands(&wps->wps->dev, msg,
1846 wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
1847 wps_build_assoc_state(wps, msg) ||
1849 wps_build_os_version(&wps->wps->dev, msg) ||
1855 wps->state = RECV_M2D_ACK;
1860 static struct wpabuf * wps_build_m4(struct wps_data *wps)
1866 wps_derive_psk(wps, wps->dev_password, wps->dev_password_len);
1880 wps_build_enrollee_nonce(wps, msg) ||
1881 wps_build_r_hash(wps, msg) ||
1882 wps_build_r_snonce1(wps, plain) ||
1883 wps_build_key_wrap_auth(wps, plain) ||
1884 wps_build_encr_settings(wps, msg, plain) ||
1886 wps_build_authenticator(wps, msg)) {
1893 wps->state = RECV_M5;
1898 static struct wpabuf * wps_build_m6(struct wps_data *wps)
1916 wps_build_enrollee_nonce(wps, msg) ||
1917 wps_build_r_snonce2(wps, plain) ||
1918 wps_build_key_wrap_auth(wps, plain) ||
1919 wps_build_encr_settings(wps, msg, plain) ||
1921 wps_build_authenticator(wps, msg)) {
1928 wps->wps_pin_revealed = 1;
1929 wps->state = RECV_M7;
1934 static struct wpabuf * wps_build_m8(struct wps_data *wps)
1952 wps_build_enrollee_nonce(wps, msg) ||
1953 ((wps->wps->ap || wps->er) && wps_build_cred(wps, plain)) ||
1954 (!wps->wps->ap && !wps->er && wps_build_ap_settings(wps, plain)) ||
1955 wps_build_key_wrap_auth(wps, plain) ||
1956 wps_build_encr_settings(wps, msg, plain) ||
1958 wps_build_authenticator(wps, msg)) {
1965 wps->state = RECV_DONE;
1970 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
1976 if (!wps->int_reg && wps->wps->wps_upnp) {
1978 if (wps->ext_reg > 1)
1979 wps_registrar_free_pending_m2(wps->wps);
1980 p = wps->wps->upnp_msgs;
1992 wps->wps->upnp_msgs = NULL;
2006 if (wps->ext_reg == 0)
2007 wps->ext_reg = 1;
2011 if (wps->ext_reg) {
2018 switch (wps->state) {
2020 if (wps_get_dev_password(wps) < 0)
2021 msg = wps_build_m2d(wps);
2023 msg = wps_build_m2(wps);
2027 msg = wps_build_m2d(wps);
2031 msg = wps_build_m4(wps);
2035 msg = wps_build_m6(wps);
2039 msg = wps_build_m8(wps);
2043 msg = wps_build_wsc_ack(wps);
2047 msg = wps_build_wsc_nack(wps);
2052 "a message", wps->state);
2060 wpabuf_free(wps->last_msg);
2061 wps->last_msg = wpabuf_dup(msg);
2068 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
2075 os_memcpy(wps->nonce_e, e_nonce, WPS_NONCE_LEN);
2077 wps->nonce_e, WPS_NONCE_LEN);
2083 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
2090 if (os_memcmp(wps->nonce_r, r_nonce, WPS_NONCE_LEN) != 0) {
2099 static int wps_process_uuid_e(struct wps_data *wps, const u8 *uuid_e)
2106 os_memcpy(wps->uuid_e, uuid_e, WPS_UUID_LEN);
2107 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", wps->uuid_e, WPS_UUID_LEN);
2113 static int wps_process_dev_password_id(struct wps_data *wps, const u8 *pw_id)
2120 wps->dev_pw_id = WPA_GET_BE16(pw_id);
2121 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %d", wps->dev_pw_id);
2127 static int wps_process_e_hash1(struct wps_data *wps, const u8 *e_hash1)
2134 os_memcpy(wps->peer_hash1, e_hash1, WPS_HASH_LEN);
2135 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", wps->peer_hash1, WPS_HASH_LEN);
2141 static int wps_process_e_hash2(struct wps_data *wps, const u8 *e_hash2)
2148 os_memcpy(wps->peer_hash2, e_hash2, WPS_HASH_LEN);
2149 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", wps->peer_hash2, WPS_HASH_LEN);
2155 static int wps_process_e_snonce1(struct wps_data *wps, const u8 *e_snonce1)
2172 addr[1] = wps->psk1;
2174 addr[2] = wpabuf_head(wps->dh_pubkey_e);
2175 len[2] = wpabuf_len(wps->dh_pubkey_e);
2176 addr[3] = wpabuf_head(wps->dh_pubkey_r);
2177 len[3] = wpabuf_len(wps->dh_pubkey_r);
2178 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
2180 if (os_memcmp(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
2183 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
2184 wps_pwd_auth_fail_event(wps->wps, 0, 1, wps->mac_addr_e);
2195 static int wps_process_e_snonce2(struct wps_data *wps, const u8 *e_snonce2)
2212 addr[1] = wps->psk2;
2214 addr[2] = wpabuf_head(wps->dh_pubkey_e);
2215 len[2] = wpabuf_len(wps->dh_pubkey_e);
2216 addr[3] = wpabuf_head(wps->dh_pubkey_r);
2217 len[3] = wpabuf_len(wps->dh_pubkey_r);
2218 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
2220 if (os_memcmp(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
2223 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
2224 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
2225 wps_pwd_auth_fail_event(wps->wps, 0, 2, wps->mac_addr_e);
2231 wps->wps_pin_revealed = 0;
2232 wps_registrar_unlock_pin(wps->wps->registrar, wps->uuid_e);
2239 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
2245 static int wps_process_mac_addr(struct wps_data *wps, const u8 *mac_addr)
2254 os_memcpy(wps->mac_addr_e, mac_addr, ETH_ALEN);
2255 os_memcpy(wps->peer_dev.mac_addr, mac_addr, ETH_ALEN);
2261 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
2269 wpabuf_free(wps->dh_pubkey_e);
2270 wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
2271 if (wps->dh_pubkey_e == NULL)
2278 static int wps_process_auth_type_flags(struct wps_data *wps, const u8 *auth)
2292 wps->auth_type = wps->wps->auth_types & auth_types;
2293 if (wps->auth_type == 0) {
2296 wps->wps->auth_types, auth_types);
2308 wps->auth_type = wps->wps->auth_types;
2318 static int wps_process_encr_type_flags(struct wps_data *wps, const u8 *encr)
2332 wps->encr_type = wps->wps->encr_types & encr_types;
2333 if (wps->encr_type == 0) {
2336 wps->wps->encr_types, encr_types);
2348 wps->encr_type = wps->wps->encr_types;
2358 static int wps_process_conn_type_flags(struct wps_data *wps, const u8 *conn)
2373 static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
2396 if (!(m & WPS_CONFIG_DISPLAY) && !wps->use_psk_key) {
2404 wps->use_psk_key = 1;
2411 static int wps_process_wps_state(struct wps_data *wps, const u8 *state)
2426 static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc)
2442 static int wps_process_config_error(struct wps_data *wps, const u8 *err)
2458 static int wps_registrar_p2p_dev_addr_match(struct wps_data *wps)
2461 struct wps_registrar *reg = wps->wps->registrar;
2466 if (os_memcmp(reg->p2p_dev_addr, wps->p2p_dev_addr, ETH_ALEN) != 0) {
2471 MAC2STR(wps->p2p_dev_addr));
2479 static int wps_registrar_skip_overlap(struct wps_data *wps)
2482 struct wps_registrar *reg = wps->wps->registrar;
2487 if (os_memcmp(reg->p2p_dev_addr, wps->p2p_dev_addr, ETH_ALEN) == 0) {
2497 static enum wps_process_res wps_process_m1(struct wps_data *wps,
2502 if (wps->state != RECV_M1) {
2504 "receiving M1", wps->state);
2508 if (wps_process_uuid_e(wps, attr->uuid_e) ||
2509 wps_process_mac_addr(wps, attr->mac_addr) ||
2510 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
2511 wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
2512 wps_process_auth_type_flags(wps, attr->auth_type_flags) ||
2513 wps_process_encr_type_flags(wps, attr->encr_type_flags) ||
2514 wps_process_conn_type_flags(wps, attr->conn_type_flags) ||
2515 wps_process_config_methods(wps, attr->config_methods) ||
2516 wps_process_wps_state(wps, attr->wps_state) ||
2517 wps_process_device_attrs(&wps->peer_dev, attr) ||
2518 wps_process_rf_bands(&wps->peer_dev, attr->rf_bands) ||
2519 wps_process_assoc_state(wps, attr->assoc_state) ||
2520 wps_process_dev_password_id(wps, attr->dev_password_id) ||
2521 wps_process_config_error(wps, attr->config_error) ||
2522 wps_process_os_version(&wps->peer_dev, attr->os_version))
2525 if (wps->dev_pw_id < 0x10 &&
2526 wps->dev_pw_id != DEV_PW_DEFAULT &&
2527 wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
2528 wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
2529 wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
2530 (wps->dev_pw_id != DEV_PW_PUSHBUTTON ||
2531 !wps->wps->registrar->pbc)) {
2533 wps->dev_pw_id);
2534 wps->state = SEND_M2D;
2539 if (wps->dev_pw_id >= 0x10) {
2545 &wps->wps->registrar->nfc_pw_tokens, wps->dev_pw_id);
2550 wps->nfc_pw_token = token;
2554 if (os_memcmp(hash, wps->nfc_pw_token->pubkey_hash,
2564 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
2565 if ((wps->wps->registrar->force_pbc_overlap ||
2566 wps_registrar_pbc_overlap(wps->wps->registrar,
2567 wps->mac_addr_e, wps->uuid_e) ||
2568 !wps_registrar_p2p_dev_addr_match(wps)) &&
2569 !wps_registrar_skip_overlap(wps)) {
2572 wps->state = SEND_M2D;
2573 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2574 wps_pbc_overlap_event(wps->wps);
2575 wps_fail_event(wps->wps, WPS_M1,
2577 WPS_EI_NO_ERROR, wps->mac_addr_e);
2578 wps->wps->registrar->force_pbc_overlap = 1;
2581 wps_registrar_add_pbc_session(wps->wps->registrar,
2582 wps->mac_addr_e, wps->uuid_e);
2583 wps->pbc = 1;
2592 if (!wps->use_psk_key &&
2593 wps->peer_dev.manufacturer &&
2594 os_strncmp(wps->peer_dev.manufacturer, "Apple ", 6) == 0 &&
2595 wps->peer_dev.model_name &&
2596 os_strcmp(wps->peer_dev.model_name, "AirPort") == 0) {
2599 wps->use_psk_key = 1;
2603 wps->state = SEND_M2;
2608 static enum wps_process_res wps_process_m3(struct wps_data *wps,
2614 if (wps->state != RECV_M3) {
2616 "receiving M3", wps->state);
2617 wps->state = SEND_WSC_NACK;
2621 if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
2622 !wps_registrar_skip_overlap(wps)) {
2625 wps->state = SEND_WSC_NACK;
2626 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2630 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2631 wps_process_authenticator(wps, attr->authenticator, msg) ||
2632 wps_process_e_hash1(wps, attr->e_hash1) ||
2633 wps_process_e_hash2(wps, attr->e_hash2)) {
2634 wps->state = SEND_WSC_NACK;
2638 wps->state = SEND_M4;
2643 static enum wps_process_res wps_process_m5(struct wps_data *wps,
2652 if (wps->state != RECV_M5) {
2654 "receiving M5", wps->state);
2655 wps->state = SEND_WSC_NACK;
2659 if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
2660 !wps_registrar_skip_overlap(wps)) {
2663 wps->state = SEND_WSC_NACK;
2664 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2668 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2669 wps_process_authenticator(wps, attr->authenticator, msg)) {
2670 wps->state = SEND_WSC_NACK;
2674 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2679 wps->state = SEND_WSC_NACK;
2685 wps->state = SEND_WSC_NACK;
2692 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2693 wps_process_e_snonce1(wps, eattr.e_snonce1)) {
2695 wps->state = SEND_WSC_NACK;
2700 wps->state = SEND_M6;
2705 static void wps_sta_cred_cb(struct wps_data *wps)
2712 if (wps->cred.auth_type & WPS_AUTH_WPA2PSK)
2713 wps->cred.auth_type = WPS_AUTH_WPA2PSK;
2714 else if (wps->cred.auth_type & WPS_AUTH_WPAPSK)
2715 wps->cred.auth_type = WPS_AUTH_WPAPSK;
2716 if (wps->cred.encr_type & WPS_ENCR_AES)
2717 wps->cred.encr_type = WPS_ENCR_AES;
2718 else if (wps->cred.encr_type & WPS_ENCR_TKIP)
2719 wps->cred.encr_type = WPS_ENCR_TKIP;
2722 if (wps->wps->cred_cb)
2723 wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
2740 static int wps_process_ap_settings_r(struct wps_data *wps,
2745 if (wps->wps->ap || wps->er)
2749 if (wps_process_ap_settings(attr, &wps->cred) < 0)
2754 if (wps->new_ap_settings) {
2757 wps_cred_update(&wps->cred, wps->new_ap_settings);
2769 wps_registrar_pin_completed(wps->wps->registrar);
2771 msg = wps_build_ap_cred(wps);
2774 wps->cred.cred_attr = wpabuf_head(msg);
2775 wps->cred.cred_attr_len = wpabuf_len(msg);
2777 if (wps->ap_settings_cb) {
2778 wps->ap_settings_cb(wps->ap_settings_cb_ctx,
2779 &wps->cred);
2783 wps_sta_cred_cb(wps);
2785 wps->cred.cred_attr = NULL;
2786 wps->cred.cred_attr_len = 0;
2794 static enum wps_process_res wps_process_m7(struct wps_data *wps,
2803 if (wps->state != RECV_M7) {
2805 "receiving M7", wps->state);
2806 wps->state = SEND_WSC_NACK;
2810 if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
2811 !wps_registrar_skip_overlap(wps)) {
2814 wps->state = SEND_WSC_NACK;
2815 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2819 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2820 wps_process_authenticator(wps, attr->authenticator, msg)) {
2821 wps->state = SEND_WSC_NACK;
2825 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2830 wps->state = SEND_WSC_NACK;
2834 if (wps_validate_m7_encr(decrypted, wps->wps->ap || wps->er,
2837 wps->state = SEND_WSC_NACK;
2844 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2845 wps_process_e_snonce2(wps, eattr.e_snonce2) ||
2846 wps_process_ap_settings_r(wps, &eattr)) {
2848 wps->state = SEND_WSC_NACK;
2854 wps->state = SEND_M8;
2859 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
2872 wps->state = SEND_WSC_NACK;
2878 os_memcmp(wps->nonce_r, attr.registrar_nonce,
2889 if (wps->wps->wps_upnp && attr.mac_addr) {
2891 wps_free_pending_msgs(wps->wps->upnp_msgs);
2892 wps->wps->upnp_msgs = NULL;
2895 wps->wps->wps_upnp, attr.mac_addr,
2899 ret = wps_process_m1(wps, &attr);
2904 ret = wps_process_m3(wps, msg, &attr);
2905 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2906 wps_fail_event(wps->wps, WPS_M3, wps->config_error,
2907 wps->error_indication, wps->mac_addr_e);
2912 ret = wps_process_m5(wps, msg, &attr);
2913 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2914 wps_fail_event(wps->wps, WPS_M5, wps->config_error,
2915 wps->error_indication, wps->mac_addr_e);
2920 ret = wps_process_m7(wps, msg, &attr);
2921 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2922 wps_fail_event(wps->wps, WPS_M7, wps->config_error,
2923 wps->error_indication, wps->mac_addr_e);
2934 wpabuf_free(wps->last_msg);
2935 wps->last_msg = wpabuf_dup(msg);
2942 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
2964 if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK &&
2965 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2966 if (wps->wps->upnp_msgs)
2975 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
2982 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
2987 if (wps->state == RECV_M2D_ACK) {
2989 if (wps->wps->wps_upnp &&
2990 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2991 if (wps->wps->upnp_msgs)
2993 if (wps->ext_reg == 0)
2994 wps->ext_reg = 1;
3009 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
3018 old_state = wps->state;
3019 wps->state = SEND_WSC_NACK;
3036 if (wps->wps->wps_upnp && wps->ext_reg) {
3044 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
3051 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
3068 wps_fail_event(wps->wps, WPS_M2, config_error,
3069 wps->error_indication, wps->mac_addr_e);
3072 wps_fail_event(wps->wps, WPS_M4, config_error,
3073 wps->error_indication, wps->mac_addr_e);
3076 wps_fail_event(wps->wps, WPS_M6, config_error,
3077 wps->error_indication, wps->mac_addr_e);
3080 wps_fail_event(wps->wps, WPS_M8, config_error,
3081 wps->error_indication, wps->mac_addr_e);
3091 static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
3098 if (wps->state != RECV_DONE &&
3099 (!wps->wps->wps_upnp || !wps->ext_reg)) {
3101 "receiving WSC_Done", wps->state);
3120 if (wps->wps->wps_upnp && wps->ext_reg) {
3123 wps_device_store(wps->wps->registrar, &wps->peer_dev,
3124 wps->uuid_e);
3130 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
3137 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
3143 wps_device_store(wps->wps->registrar, &wps->peer_dev,
3144 wps->uuid_e);
3146 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
3147 wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
3154 os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
3155 cred.ssid_len = wps->wps->ssid_len;
3158 os_memcpy(cred.key, wps->new_psk, wps->new_psk_len);
3159 cred.key_len = wps->new_psk_len;
3161 wps->wps->wps_state = WPS_STATE_CONFIGURED;
3164 wps->new_psk, wps->new_psk_len);
3165 if (wps->wps->cred_cb)
3166 wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
3168 os_free(wps->new_psk);
3169 wps->new_psk = NULL;
3172 if (!wps->wps->ap && !wps->er)
3173 wps_sta_cred_cb(wps);
3175 if (wps->new_psk) {
3176 if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e,
3177 wps->p2p_dev_addr, wps->new_psk,
3178 wps->new_psk_len)) {
3182 os_free(wps->new_psk);
3183 wps->new_psk = NULL;
3186 wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e,
3187 wps->dev_password, wps->dev_password_len);
3189 if (wps->pbc) {
3190 wps_registrar_remove_pbc_session(wps->wps->registrar,
3191 wps->uuid_e,
3192 wps->p2p_dev_addr);
3193 wps_registrar_pbc_completed(wps->wps->registrar);
3194 os_get_time(&wps->wps->registrar->pbc_ignore_start);
3195 os_memcpy(wps->wps->registrar->pbc_ignore_uuid, wps->uuid_e,
3198 wps_registrar_pin_completed(wps->wps->registrar);
3203 wps_success_event(wps->wps, wps->mac_addr_e);
3209 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
3220 if (wps->wps->wps_upnp && op_code == WSC_MSG && wps->ext_reg == 1) {
3224 wps->ext_reg = 2; /* past M2/M2D phase */
3226 if (wps->ext_reg > 1)
3227 wps_registrar_free_pending_m2(wps->wps);
3228 if (wps->wps->wps_upnp && wps->ext_reg &&
3229 wps->wps->upnp_msgs == NULL &&
3240 upnp_wps_device_send_wlan_event(wps->wps->wps_upnp,
3241 wps->mac_addr_e,
3246 } else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) {
3255 return wps_process_wsc_msg(wps, msg);
3259 return wps_process_wsc_ack(wps, msg);
3263 return wps_process_wsc_nack(wps, msg);
3267 ret = wps_process_wsc_done(wps, msg);
3269 wps->state = SEND_WSC_NACK;
3270 wps_fail_event(wps->wps, WPS_WSC_DONE,
3271 wps->config_error,
3272 wps->error_indication, wps->mac_addr_e);
3340 if (reg->wps->wps_upnp == NULL)
3343 dl_list_for_each(s, &reg->wps->wps_upnp->subscriptions,
3385 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
3393 wps_set_pushbutton(&methods, reg->wps->config_methods);
3480 if (reg->wps->cred_cb)
3481 return reg->wps->cred_cb(reg->wps->cb_ctx, cred);