Home | History | Annotate | Download | only in wps

Lines Matching defs:wps

82 	struct wps_context *wps;
215 static int wps_build_wps_state(struct wps_context *wps, struct wpabuf *msg)
217 wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
218 wps->wps_state);
221 wpabuf_put_u8(msg, wps->wps_state);
227 static void wps_registrar_free_pending_m2(struct wps_context *wps)
230 p = wps->upnp_msgs;
234 wps->upnp_msgs = p->next;
237 wpa_printf(MSG_DEBUG, "WPS UPnP: Drop pending M2/M2D");
251 static int wps_build_ap_setup_locked(struct wps_context *wps,
254 if (wps->ap_setup_locked) {
255 wpa_printf(MSG_DEBUG, "WPS: * AP Setup Locked");
269 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar");
285 wpa_printf(MSG_DEBUG, "WPS: * Device Password ID (%d)", id);
299 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
304 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar Config Methods (%x)",
318 wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
330 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
339 u8 resp = reg->wps->ap ? WPS_RESP_AP : WPS_RESP_REGISTRAR;
340 wpa_printf(MSG_DEBUG, "WPS: * Response Type (%d)", resp);
349 * wps_registrar_init - Initialize WPS Registrar data
350 * @wps: Pointer to longterm WPS context
354 * This function is used to initialize WPS Registrar functionality. It can be
361 wps_registrar_init(struct wps_context *wps,
368 reg->wps = wps;
398 * wps_registrar_deinit - Deinitialize WPS Registrar data
452 wpa_printf(MSG_DEBUG, "WPS: A new PIN configured (timeout=%d)",
454 wpa_hexdump(MSG_DEBUG, "WPS: UUID", uuid, WPS_UUID_LEN);
455 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
485 wpa_hexdump(MSG_DEBUG, "WPS: Expired PIN for UUID",
514 wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
548 wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
566 wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
594 wpa_printf(MSG_DEBUG, "WPS: Invalidating used "
620 wpa_printf(MSG_DEBUG, "WPS: PBC timed out - disable PBC mode");
621 wps_pbc_timeout_event(reg->wps);
638 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - do not start PBC "
640 wps_pbc_overlap_event(reg->wps);
643 wpa_printf(MSG_DEBUG, "WPS: Button pushed - PBC mode started");
658 wpa_printf(MSG_DEBUG, "WPS: PBC completed - stopping PBC mode");
665 wpa_printf(MSG_DEBUG, "WPS: PIN completed using internal Registrar");
676 * @wps_data: WPS IE contents
678 WPS IE is
680 * situation with other WPS APs.
689 "WPS: Probe Request with WPS data received",
695 wpa_printf(MSG_DEBUG, "WPS: Unsupported ProbeReq WPS IE "
701 wpa_printf(MSG_DEBUG, "WPS: No Config Methods attribute in "
710 wpa_printf(MSG_DEBUG, "WPS: Probe Request for PBC received from "
713 wpa_printf(MSG_DEBUG, "WPS: Invalid Probe Request WPS IE: No "
720 wpa_printf(MSG_DEBUG, "WPS: PBC session overlap detected");
722 wps_pbc_overlap_event(reg->wps);
771 /* Encapsulate WPS IE data with one (or more, if needed) IE headers */
809 wpa_printf(MSG_DEBUG, "WPS: Build Beacon and Probe Response IEs");
821 wps_build_wps_state(reg->wps, beacon) ||
822 wps_build_ap_setup_locked(reg->wps, beacon) ||
827 wps_build_wps_state(reg->wps, probe) ||
828 wps_build_ap_setup_locked(reg->wps, probe) ||
833 wps_build_uuid_e(probe, reg->wps->uuid) ||
834 wps_build_device_attrs(&reg->wps->dev, probe) ||
836 wps_build_rf_bands(&reg->wps->dev, probe)) {
857 * the correct (non-WPS) behavior would be to ask for the
865 0x00 /* no legacy 802.1X or MS WPS */
867 wpa_printf(MSG_DEBUG, "WPS: Add Microsoft Provisioning IE "
881 static int wps_get_dev_password(struct wps_data *wps)
886 os_free(wps->dev_password);
887 wps->dev_password = NULL;
889 if (wps->pbc) {
890 wpa_printf(MSG_DEBUG, "WPS: Use default PIN for PBC");
894 pin = wps_registrar_get_pin(wps->wps->registrar, wps->uuid_e,
898 wpa_printf(MSG_DEBUG, "WPS: No Device Password available for "
900 wps_cb_pin_needed(wps->wps->registrar, wps->uuid_e,
901 &wps->peer_dev);
905 wps->dev_password = os_malloc(pin_len);
906 if (wps->dev_password == NULL)
908 os_memcpy(wps->dev_password, pin, pin_len);
909 wps->dev_password_len = pin_len;
915 static int wps_build_uuid_r(struct wps_data *wps, struct wpabuf *msg)
917 wpa_printf(MSG_DEBUG, "WPS: * UUID-R");
920 wpabuf_put_data(msg, wps->uuid_r, WPS_UUID_LEN);
925 static int wps_build_r_hash(struct wps_data *wps, struct wpabuf *msg)
931 if (os_get_random(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
933 wpa_hexdump(MSG_DEBUG, "WPS: R-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
934 wpa_hexdump(MSG_DEBUG, "WPS: R-S2",
935 wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
937 if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
938 wpa_printf(MSG_DEBUG, "WPS: DH public keys not available for "
943 wpa_printf(MSG_DEBUG, "WPS: * R-Hash1");
948 addr[0] = wps->snonce;
950 addr[1] = wps->psk1;
952 addr[2] = wpabuf_head(wps->dh_pubkey_e);
953 len[2] = wpabuf_len(wps->dh_pubkey_e);
954 addr[3] = wpabuf_head(wps->dh_pubkey_r);
955 len[3] = wpabuf_len(wps->dh_pubkey_r);
956 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
957 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", hash, SHA256_MAC_LEN);
959 wpa_printf(MSG_DEBUG, "WPS: * R-Hash2");
964 addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
965 addr[1] = wps->psk2;
966 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
967 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", hash, SHA256_MAC_LEN);
973 static int wps_build_r_snonce1(struct wps_data *wps, struct wpabuf *msg)
975 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce1");
978 wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
983 static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
985 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce2");
988 wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
997 wpa_printf(MSG_DEBUG, "WPS: * Network Index");
1008 wpa_printf(MSG_DEBUG, "WPS: * SSID");
1019 wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)",
1031 wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)",
1043 wpa_printf(MSG_DEBUG, "WPS: * Network Key");
1054 wpa_printf(MSG_DEBUG, "WPS: * MAC Address (" MACSTR ")",
1077 static int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
1081 if (wps->wps->registrar->skip_cred_build)
1084 wpa_printf(MSG_DEBUG, "WPS: * Credential");
1085 os_memset(&wps->cred, 0, sizeof(wps->cred));
1087 os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
1088 wps->cred.ssid_len = wps->wps->ssid_len;
1091 if (wps->auth_type & WPS_AUTH_WPA2PSK)
1092 wps->auth_type = WPS_AUTH_WPA2PSK;
1093 else if (wps->auth_type & WPS_AUTH_WPAPSK)
1094 wps->auth_type = WPS_AUTH_WPAPSK;
1095 else if (wps->auth_type & WPS_AUTH_OPEN)
1096 wps->auth_type = WPS_AUTH_OPEN;
1097 else if (wps->auth_type & WPS_AUTH_SHARED)
1098 wps->auth_type = WPS_AUTH_SHARED;
1100 wpa_printf(MSG_DEBUG, "WPS: Unsupported auth_type 0x%x",
1101 wps->auth_type);
1104 wps->cred.auth_type = wps->auth_type;
1106 if (wps->auth_type == WPS_AUTH_WPA2PSK ||
1107 wps->auth_type == WPS_AUTH_WPAPSK) {
1108 if (wps->encr_type & WPS_ENCR_AES)
1109 wps->encr_type = WPS_ENCR_AES;
1110 else if (wps->encr_type & WPS_ENCR_TKIP)
1111 wps->encr_type = WPS_ENCR_TKIP;
1113 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1118 if (wps->encr_type & WPS_ENCR_WEP)
1119 wps->encr_type = WPS_ENCR_WEP;
1120 else if (wps->encr_type & WPS_ENCR_NONE)
1121 wps->encr_type = WPS_ENCR_NONE;
1123 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1128 wps->cred.encr_type = wps->encr_type;
1132 os_memcpy(wps->cred.mac_addr, wps->mac_addr_e, ETH_ALEN);
1134 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->wps->ap &&
1135 !wps->wps->registrar->disable_auto_conf) {
1140 os_free(wps->new_psk);
1141 wps->new_psk = base64_encode(r, sizeof(r), &wps->new_psk_len);
1142 if (wps->new_psk == NULL)
1144 wps->new_psk_len--; /* remove newline */
1145 while (wps->new_psk_len &&
1146 wps->new_psk[wps->new_psk_len - 1] == '=')
1147 wps->new_psk_len--;
1148 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Generated passphrase",
1149 wps->new_psk, wps->new_psk_len);
1150 os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
1151 wps->cred.key_len = wps->new_psk_len;
1152 } else if (wps->wps->network_key) {
1153 os_memcpy(wps->cred.key, wps->wps->network_key,
1154 wps->wps->network_key_len);
1155 wps->cred.key_len = wps->wps->network_key_len;
1156 } else if (wps->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
1159 os_free(wps->new_psk);
1160 wps->new_psk_len = 32;
1161 wps->new_psk = os_malloc(wps->new_psk_len);
1162 if (wps->new_psk == NULL)
1164 if (os_get_random(wps->new_psk, wps->new_psk_len) < 0) {
1165 os_free(wps->new_psk);
1166 wps->new_psk = NULL;
1169 wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
1170 wps->new_psk, wps->new_psk_len);
1171 wpa_snprintf_hex(hex, sizeof(hex), wps->new_psk,
1172 wps->new_psk_len);
1173 os_memcpy(wps->cred.key, hex, wps->new_psk_len * 2);
1174 wps->cred.key_len = wps->new_psk_len * 2;
1181 if (wps_build_credential(cred, &wps->cred)) {
1192 if (wps->wps->registrar->extra_cred) {
1193 wpa_printf(MSG_DEBUG, "WPS: * Credential (pre-configured)");
1194 wpabuf_put_buf(msg, wps->wps->registrar->extra_cred);
1201 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
1203 wpa_printf(MSG_DEBUG, "WPS: * AP Settings");
1205 if (wps_build_credential(msg, &wps->cred))
1212 static struct wpabuf * wps_build_m2(struct wps_data *wps)
1216 if (os_get_random(wps->nonce_r, WPS_NONCE_LEN) < 0)
1218 wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
1219 wps->nonce_r, WPS_NONCE_LEN);
1220 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
1222 wpa_printf(MSG_DEBUG, "WPS: Building Message M2");
1229 wps_build_enrollee_nonce(wps, msg) ||
1230 wps_build_registrar_nonce(wps, msg) ||
1231 wps_build_uuid_r(wps, msg) ||
1232 wps_build_public_key(wps, msg) ||
1233 wps_derive_keys(wps) ||
1234 wps_build_auth_type_flags(wps, msg) ||
1235 wps_build_encr_type_flags(wps, msg) ||
1236 wps_build_conn_type_flags(wps, msg) ||
1237 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1238 wps_build_device_attrs(&wps->wps->dev, msg) ||
1239 wps_build_rf_bands(&wps->wps->dev, msg) ||
1240 wps_build_assoc_state(wps, msg) ||
1242 wps_build_dev_password_id(msg, wps->dev_pw_id) ||
1243 wps_build_os_version(&wps->wps->dev, msg) ||
1244 wps_build_authenticator(wps, msg)) {
1249 wps->state = RECV_M3;
1254 static struct wpabuf * wps_build_m2d(struct wps_data *wps)
1257 u16 err = wps->config_error;
1259 wpa_printf(MSG_DEBUG, "WPS: Building Message M2D");
1264 if (wps->wps->ap && wps->wps->ap_setup_locked &&
1270 wps_build_enrollee_nonce(wps, msg) ||
1271 wps_build_registrar_nonce(wps, msg) ||
1272 wps_build_uuid_r(wps, msg) ||
1273 wps_build_auth_type_flags(wps, msg) ||
1274 wps, msg) ||
1275 wps_build_conn_type_flags(wps, msg) ||
1276 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1277 wps_build_device_attrs(&wps->wps->dev, msg) ||
1278 wps_build_rf_bands(&wps->wps->dev, msg) ||
1279 wps_build_assoc_state(wps, msg) ||
1281 wps_build_os_version(&wps->wps->dev, msg)) {
1286 wps->state = RECV_M2D_ACK;
1291 static struct wpabuf * wps_build_m4(struct wps_data *wps)
1295 wpa_printf(MSG_DEBUG, "WPS: Building Message M4");
1297 wps_derive_psk(wps, wps->dev_password, wps->dev_password_len);
1311 wps_build_enrollee_nonce(wps, msg) ||
1312 wps_build_r_hash(wps, msg) ||
1313 wps_build_r_snonce1(wps, plain) ||
1314 wps_build_key_wrap_auth(wps, plain) ||
1315 wps_build_encr_settings(wps, msg, plain) ||
1316 wps_build_authenticator(wps, msg)) {
1323 wps->state = RECV_M5;
1328 static struct wpabuf * wps_build_m6(struct wps_data *wps)
1332 wpa_printf(MSG_DEBUG, "WPS: Building Message M6");
1346 wps_build_enrollee_nonce(wps, msg) ||
1347 wps_build_r_snonce2(wps, plain) ||
1348 wps_build_key_wrap_auth(wps, plain) ||
1349 wps_build_encr_settings(wps, msg, plain) ||
1350 wps_build_authenticator(wps, msg)) {
1357 wps->wps_pin_revealed = 1;
1358 wps->state = RECV_M7;
1363 static struct wpabuf * wps_build_m8(struct wps_data *wps)
1367 wpa_printf(MSG_DEBUG, "WPS: Building Message M8");
1381 wps_build_enrollee_nonce(wps, msg) ||
1382 (wps->wps->ap && wps_build_cred(wps, plain)) ||
1383 (!wps->wps->ap && wps_build_ap_settings(wps, plain)) ||
1384 wps_build_key_wrap_auth(wps, plain) ||
1385 wps_build_encr_settings(wps, msg, plain) ||
1386 wps_build_authenticator(wps, msg)) {
1393 wps->state = RECV_DONE;
1398 static struct wpabuf * wps_build_wsc_ack(struct wps_data *wps)
1402 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_ACK");
1410 wps_build_enrollee_nonce(wps, msg) ||
1411 wps_build_registrar_nonce(wps, msg)) {
1420 static struct wpabuf * wps_build_wsc_nack(struct wps_data *wps)
1424 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_NACK");
1432 wps_build_enrollee_nonce(wps, msg) ||
1433 wps_build_registrar_nonce(wps, msg) ||
1434 wps_build_config_error(msg, wps->config_error)) {
1443 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
1449 if (wps->wps->wps_upnp) {
1451 if (wps->ext_reg > 1)
1452 wps_registrar_free_pending_m2(wps->wps);
1453 p = wps->wps->upnp_msgs;
1460 wpa_printf(MSG_DEBUG, "WPS: Use pending message from "
1465 wps->wps->upnp_msgs = NULL;
1479 if (wps->ext_reg == 0)
1480 wps->ext_reg = 1;
1484 if (wps->ext_reg) {
1485 wpa_printf(MSG_DEBUG, "WPS: Using external Registrar, but no "
1491 switch (wps->state) {
1493 if (wps_get_dev_password(wps) < 0)
1494 msg = wps_build_m2d(wps);
1496 msg = wps_build_m2(wps);
1500 msg = wps_build_m2d(wps);
1504 msg = wps_build_m4(wps);
1508 msg = wps_build_m6(wps);
1512 msg = wps_build_m8(wps);
1516 msg = wps_build_wsc_ack(wps);
1520 msg = wps_build_wsc_nack(wps);
1524 wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
1525 "a message", wps->state);
1533 wpabuf_free(wps->last_msg);
1534 wps->last_msg = wpabuf_dup(msg);
1541 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
1544 wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
1548 os_memcpy(wps->nonce_e, e_nonce, WPS_NONCE_LEN);
1549 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
1550 wps->nonce_e, WPS_NONCE_LEN);
1556 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
1559 wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
1563 if (os_memcmp(wps->nonce_r, r_nonce, WPS_NONCE_LEN) != 0) {
1564 wpa_printf(MSG_DEBUG, "WPS: Invalid Registrar Nonce received");
1572 static int wps_process_uuid_e(struct wps_data *wps, const u8 *uuid_e)
1575 wpa_printf(MSG_DEBUG, "WPS: No UUID-E received");
1579 os_memcpy(wps->uuid_e, uuid_e, WPS_UUID_LEN);
1580 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", wps->uuid_e, WPS_UUID_LEN);
1586 static int wps_process_dev_password_id(struct wps_data *wps, const u8 *pw_id)
1589 wpa_printf(MSG_DEBUG, "WPS: No Device Password ID received");
1593 wps->dev_pw_id = WPA_GET_BE16(pw_id);
1594 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %d", wps->dev_pw_id);
1600 static int wps_process_e_hash1(struct wps_data *wps, const u8 *e_hash1)
1603 wpa_printf(MSG_DEBUG, "WPS: No E-Hash1 received");
1607 os_memcpy(wps->peer_hash1, e_hash1, WPS_HASH_LEN);
1608 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", wps->peer_hash1, WPS_HASH_LEN);
1614 static int wps_process_e_hash2(struct wps_data *wps, const u8 *e_hash2)
1617 wpa_printf(MSG_DEBUG, "WPS: No E-Hash2 received");
1621 os_memcpy(wps->peer_hash2, e_hash2, WPS_HASH_LEN);
1622 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", wps->peer_hash2, WPS_HASH_LEN);
1628 static int wps_process_e_snonce1(struct wps_data *wps, const u8 *e_snonce1)
1635 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce1 received");
1639 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce1", e_snonce1,
1645 addr[1] = wps->psk1;
1647 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1648 len[2] = wpabuf_len(wps->dh_pubkey_e);
1649 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1650 len[3] = wpabuf_len(wps->dh_pubkey_r);
1651 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1653 if (os_memcmp(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
1654 wpa_printf(MSG_DEBUG, "WPS: E-Hash1 derived from E-S1 does "
1656 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1657 wps_pwd_auth_fail_event(wps->wps, 0, 1);
1661 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the first "
1668 static int wps_process_e_snonce2(struct wps_data *wps, const u8 *e_snonce2)
1675 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce2 received");
1679 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce2", e_snonce2,
1685 addr[1] = wps->psk2;
1687 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1688 len[2] = wpabuf_len(wps->dh_pubkey_e);
1689 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1690 len[3] = wpabuf_len(wps->dh_pubkey_r);
1691 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1693 if (os_memcmp(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
1694 wpa_printf(MSG_DEBUG, "WPS: E-Hash2 derived from E-S2 does "
1696 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
1697 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1698 wps_pwd_auth_fail_event(wps->wps, 0, 2);
1702 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the second "
1704 wps->wps_pin_revealed = 0;
1705 wps_registrar_unlock_pin(wps->wps->registrar, wps->uuid_e);
1711 static int wps_process_mac_addr(struct wps_data *wps, const u8 *mac_addr)
1714 wpa_printf(MSG_DEBUG, "WPS: No MAC Address received");
1718 wpa_printf(MSG_DEBUG, "WPS: Enrollee MAC Address " MACSTR,
1720 os_memcpy(wps->mac_addr_e, mac_addr, ETH_ALEN);
1721 os_memcpy(wps->peer_dev.mac_addr, mac_addr, ETH_ALEN);
1727 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
1731 wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
1735 wpabuf_free(wps->dh_pubkey_e);
1736 wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
1737 if (wps->dh_pubkey_e == NULL)
1744 static int wps_process_auth_type_flags(struct wps_data *wps, const u8 *auth)
1749 wpa_printf(MSG_DEBUG, "WPS: No Authentication Type flags "
1756 wpa_printf(MSG_DEBUG, "WPS: Enrollee Authentication Type flags 0x%x",
1758 wps->auth_type = wps->wps->auth_types & auth_types;
1759 if (wps->auth_type == 0) {
1760 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
1762 wps->wps->auth_types, auth_types);
1771 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
1774 wps->auth_type = wps->wps->auth_types;
1784 static int wps_process_encr_type_flags(struct wps_data *wps, const u8 *encr)
1789 wpa_printf(MSG_DEBUG, "WPS: No Encryption Type flags "
1796 wpa_printf(MSG_DEBUG, "WPS: Enrollee Encryption Type flags 0x%x",
1798 wps->encr_type = wps->wps->encr_types & encr_types;
1799 if (wps->encr_type == 0) {
1800 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
1802 wps->wps->encr_types, encr_types);
1811 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
1814 wps->encr_type = wps->wps->encr_types;
1824 static int wps_process_conn_type_flags(struct wps_data *wps, const u8 *conn)
1827 wpa_printf(MSG_DEBUG, "WPS: No Connection Type flags "
1832 wpa_printf(MSG_DEBUG, "WPS: Enrollee Connection Type flags 0x%x",
1839 static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
1844 wpa_printf(MSG_DEBUG, "WPS: No Config Methods received");
1850 wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x", m);
1856 static int wps_process_wps_state(struct wps_data *wps, const u8 *state)
1859 wpa_printf(MSG_DEBUG, "WPS: No Wi-Fi Protected Setup State "
1864 wpa_printf(MSG_DEBUG, "WPS: Enrollee Wi-Fi Protected Setup State %d",
1871 static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc)
1876 wpa_printf(MSG_DEBUG, "WPS: No Association State received");
1881 wpa_printf(MSG_DEBUG, "WPS: Enrollee Association State %d", a);
1887 static int wps_process_config_error(struct wps_data *wps, const u8 *err)
1892 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error received");
1897 wpa_printf(MSG_DEBUG, "WPS: Enrollee Configuration Error %d", e);
1903 static enum wps_process_res wps_process_m1(struct wps_data *wps,
1906 wpa_printf(MSG_DEBUG, "WPS: Received M1");
1908 if (wps->state != RECV_M1) {
1909 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1910 "receiving M1", wps->state);
1914 if (wps_process_uuid_e(wps, attr->uuid_e) ||
1915 wps_process_mac_addr(wps, attr->mac_addr) ||
1916 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1917 wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
1918 wps_process_auth_type_flags(wps, attr->auth_type_flags) ||
1919 wps_process_encr_type_flags(wps, attr->encr_type_flags) ||
1920 wps_process_conn_type_flags(wps, attr->conn_type_flags) ||
1921 wps_process_config_methods(wps, attr->config_methods) ||
1922 wps_process_wps_state(wps, attr->wps_state) ||
1923 wps_process_device_attrs(&wps->peer_dev, attr) ||
1924 wps_process_rf_bands(&wps->peer_dev, attr->rf_bands) ||
1925 wps_process_assoc_state(wps, attr->assoc_state) ||
1926 wps_process_dev_password_id(wps, attr->dev_password_id) ||
1927 wps_process_config_error(wps, attr->config_error) ||
1928 wps_process_os_version(&wps->peer_dev, attr->os_version))
1931 if (wps->dev_pw_id != DEV_PW_DEFAULT &&
1932 wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
1933 wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
1934 wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
1935 (wps->dev_pw_id != DEV_PW_PUSHBUTTON ||
1936 !wps->wps->registrar->pbc)) {
1937 wpa_printf(MSG_DEBUG, "WPS: Unsupported Device Password ID %d",
1938 wps->dev_pw_id);
1939 wps->state = SEND_M2D;
1943 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
1944 if (wps->wps->registrar->force_pbc_overlap ||
1945 wps_registrar_pbc_overlap(wps->wps->registrar,
1946 wps->mac_addr_e, wps->uuid_e)) {
1947 WPS: PBC overlap - deny PBC "
1949 wps->state = SEND_M2D;
1950 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
1951 wps_pbc_overlap_event(wps->wps);
1952 wps->wps->registrar->force_pbc_overlap = 1;
1955 wps_registrar_add_pbc_session(wps->wps->registrar,
1956 wps->mac_addr_e, wps->uuid_e);
1957 wps->pbc = 1;
1960 wps->state = SEND_M2;
1965 static enum wps_process_res wps_process_m3(struct wps_data *wps,
1969 wpa_printf(MSG_DEBUG, "WPS: Received M3");
1971 if (wps->state != RECV_M3) {
1972 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1973 "receiving M3", wps->state);
1974 wps->state = SEND_WSC_NACK;
1978 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
1979 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
1981 wps->state = SEND_WSC_NACK;
1982 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
1986 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
1987 wps_process_authenticator(wps, attr->authenticator, msg) ||
1988 wps_process_e_hash1(wps, attr->e_hash1) ||
1989 wps_process_e_hash2(wps, attr->e_hash2)) {
1990 wps->state = SEND_WSC_NACK;
1994 wps->state = SEND_M4;
1999 static enum wps_process_res wps_process_m5(struct wps_data *wps,
2006 wpa_printf(MSG_DEBUG, "WPS: Received M5");
2008 if (wps->state != RECV_M5) {
2009 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2010 "receiving M5", wps->state);
2011 wps->state = SEND_WSC_NACK;
2015 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2016 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2018 wps->state = SEND_WSC_NACK;
2019 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2023 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2024 wps_process_authenticator(wps, attr->authenticator, msg)) {
2025 wps->state = SEND_WSC_NACK;
2029 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2032 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
2034 wps->state = SEND_WSC_NACK;
2038 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2041 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2042 wps_process_e_snonce1(wps, eattr.e_snonce1)) {
2044 wps->state = SEND_WSC_NACK;
2049 wps->state = SEND_M6;
2054 static void wps_sta_cred_cb(struct wps_data *wps)
2061 if (wps->cred.auth_type & WPS_AUTH_WPA2PSK)
2062 wps->cred.auth_type = WPS_AUTH_WPA2PSK;
2063 else if (wps->cred.auth_type & WPS_AUTH_WPAPSK)
2064 wps->cred.auth_type = WPS_AUTH_WPAPSK;
2065 if (wps->cred.encr_type & WPS_ENCR_AES)
2066 wps->cred.encr_type = WPS_ENCR_AES;
2067 else if (wps->cred.encr_type & WPS_ENCR_TKIP)
2068 wps->cred.encr_type = WPS_ENCR_TKIP;
2069 wpa_printf(MSG_DEBUG, "WPS: Update local configuration based on the "
2071 if (wps->wps->cred_cb)
2072 wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
2076 static int wps_process_ap_settings_r(struct wps_data *wps,
2079 if (wps->wps->ap)
2083 if (wps_process_ap_settings(attr, &wps->cred) < 0)
2086 wpa_printf(MSG_INFO, "WPS: Received old AP configuration from AP");
2100 wps_sta_cred_cb(wps);
2106 static enum wps_process_res wps_process_m7(struct wps_data *wps,
2113 wpa_printf(MSG_DEBUG, "WPS: Received M7");
2115 if (wps->state != RECV_M7) {
2116 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2117 "receiving M7", wps->state);
2118 wps->state = SEND_WSC_NACK;
2122 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2123 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2125 wps->state = SEND_WSC_NACK;
2126 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2130 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2131 wps_process_authenticator(wps, attr->authenticator, msg)) {
2132 wps->state = SEND_WSC_NACK;
2136 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2139 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
2141 wps->state = SEND_WSC_NACK;
2145 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2148 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2149 wps_process_e_snonce2(wps, eattr.e_snonce2) ||
2150 wps_process_ap_settings_r(wps, &eattr)) {
2152 wps->state = SEND_WSC_NACK;
2158 wps->state = SEND_M8;
2163 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
2169 wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
2175 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
2181 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2187 os_memcmp(wps->nonce_r, attr.registrar_nonce,
2189 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2196 if (wps->wps->wps_upnp && attr.mac_addr) {
2198 wps_free_pending_msgs(wps->wps->upnp_msgs);
2199 wps->wps->upnp_msgs = NULL;
2202 wps->wps->wps_upnp, attr.mac_addr,
2206 ret = wps_process_m1(wps, &attr);
2209 ret = wps_process_m3(wps, msg, &attr);
2210 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2211 wps_fail_event(wps->wps, WPS_M3);
2214 ret = wps_process_m5(wps, msg, &attr);
2215 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2216 wps_fail_event(wps->wps, WPS_M5);
2219 ret = wps_process_m7(wps, msg, &attr);
2220 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2221 wps_fail_event(wps->wps, WPS_M7);
2224 wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
2232 wpabuf_free(wps->last_msg);
2233 wps->last_msg = wpabuf_dup(msg);
2240 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
2245 wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
2251 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
2257 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2262 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2268 if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK &&
2269 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2270 if (wps->wps->upnp_msgs)
2272 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2279 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2281 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2286 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2287 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2291 if (wps->state == RECV_M2D_ACK) {
2293 if (wps->wps->wps_upnp &&
2294 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2295 if (wps->wps->upnp_msgs)
2297 if (wps->ext_reg == 0)
2298 wps->ext_reg = 1;
2299 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2305 wpa_printf(MSG_DEBUG, "WPS: No more registrars available - "
2313 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
2319 wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
2321 old_state = wps->state;
2322 wps->state = SEND_WSC_NACK;
2328 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
2334 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2339 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2345 if (wps->wps->wps_upnp && wps->ext_reg) {
2346 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2353 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2355 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2360 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2361 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2366 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
2371 wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
2376 wps_fail_event(wps->wps, WPS_M2);
2379 wps_fail_event(wps->wps, WPS_M4);
2382 wps_fail_event(wps->wps, WPS_M6);
2385 wps_fail_event(wps->wps, WPS_M8);
2395 static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
2400 wpa_printf(MSG_DEBUG, "WPS: Received WSC_Done");
2402 if (wps->state != RECV_DONE &&
2403 (!wps->wps->wps_upnp || !wps->ext_reg)) {
2404 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2405 "receiving WSC_Done", wps->state);
2413 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
2419 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2424 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2430 if (wps->wps->wps_upnp && wps->ext_reg) {
2431 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2438 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2440 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2445 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2446 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2450 wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully");
2452 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
2453 wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
2456 wpa_printf(MSG_DEBUG, "WPS: Moving to Configured state based "
2460 os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
2461 cred.ssid_len = wps->wps->ssid_len;
2464 os_memcpy(cred.key, wps->new_psk, wps->new_psk_len);
2465 cred.key_len = wps->new_psk_len;
2467 wps->wps->wps_state = WPS_STATE_CONFIGURED;
2469 "WPS: Generated random passphrase",
2470 wps->new_psk, wps->new_psk_len);
2471 if (wps->wps->cred_cb)
2472 wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
2474 os_free(wps->new_psk);
2475 wps->new_psk = NULL;
2478 if (!wps->wps->ap)
2479 wps_sta_cred_cb(wps);
2481 if (wps->new_psk) {
2482 if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e,
2483 wps->new_psk, wps->new_psk_len)) {
2484 wpa_printf(MSG_DEBUG, "WPS: Failed to configure the "
2487 os_free(wps->new_psk);
2488 wps->new_psk = NULL;
2491 wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e);
2493 if (wps->pbc) {
2494 wps_registrar_remove_pbc_session(wps->wps->registrar,
2495 wps->mac_addr_e, wps->uuid_e);
2496 wps_registrar_pbc_completed(wps->wps->registrar);
2498 wps_registrar_pin_completed(wps->wps->registrar);
2501 wps_success_event(wps->wps);
2507 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
2513 wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
2518 if (wps->wps->wps_upnp && op_code == WSC_MSG && wps->ext_reg == 1) {
2522 wps->ext_reg = 2; /* past M2/M2D phase */
2524 if (wps->ext_reg > 1)
2525 wps_registrar_free_pending_m2(wps->wps);
2526 if (wps->wps->wps_upnp && wps->ext_reg &&
2527 wps->wps->upnp_msgs == NULL &&
2536 wpa_printf(MSG_DEBUG, "WPS: Sending received message (type %d)"
2538 upnp_wps_device_send_wlan_event(wps->wps->wps_upnp,
2539 wps->mac_addr_e,
2544 } else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) {
2545 wpa_printf(MSG_DEBUG, "WPS: Skip internal processing - using "
2553 return wps_process_wsc_msg(wps, msg);
2555 return wps_process_wsc_ack(wps, msg);
2557 return wps_process_wsc_nack(wps, msg);
2559 ret = wps_process_wsc_done(wps, msg);
2561 wps->state = SEND_WSC_NACK;
2562 wps_fail_event(wps->wps, WPS_WSC_DONE);
2566 wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);
2583 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar timed out - "
2607 wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
2613 wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
2620 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "