📄 wps_registrar.c
字号:
wpabuf_free(decrypted); wps->state = SEND_WSC_NACK; return WPS_CONTINUE; } wpabuf_free(decrypted); wps->state = SEND_M8; return WPS_CONTINUE;}static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps, const struct wpabuf *msg){ struct wps_parse_attr attr; enum wps_process_res ret = WPS_CONTINUE; wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG"); if (wps_parse_msg(msg, &attr) < 0) return WPS_FAILURE; if (!wps_version_supported(attr.version)) { wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x", attr.version ? *attr.version : 0); return WPS_FAILURE; } if (attr.msg_type == NULL) { wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute"); return WPS_FAILURE; } if (*attr.msg_type != WPS_M1 && (attr.registrar_nonce == NULL || os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))) { wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce"); return WPS_FAILURE; } switch (*attr.msg_type) { case WPS_M1:#ifdef CONFIG_WPS_UPNP if (wps->wps->wps_upnp && attr.mac_addr) { /* Remove old pending messages when starting new run */ wps_free_pending_msgs(wps->wps->upnp_msgs); wps->wps->upnp_msgs = NULL; upnp_wps_device_send_wlan_event( wps->wps->wps_upnp, attr.mac_addr, UPNP_WPS_WLANEVENT_TYPE_EAP, msg); }#endif /* CONFIG_WPS_UPNP */ ret = wps_process_m1(wps, &attr); break; case WPS_M3: ret = wps_process_m3(wps, msg, &attr); if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK) wps_fail_event(wps->wps, WPS_M3); break; case WPS_M5: ret = wps_process_m5(wps, msg, &attr); if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK) wps_fail_event(wps->wps, WPS_M5); break; case WPS_M7: ret = wps_process_m7(wps, msg, &attr); if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK) wps_fail_event(wps->wps, WPS_M7); break; default: wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d", *attr.msg_type); return WPS_FAILURE; } if (ret == WPS_CONTINUE) { /* Save a copy of the last message for Authenticator derivation */ wpabuf_free(wps->last_msg); wps->last_msg = wpabuf_dup(msg); } return ret;}static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps, const struct wpabuf *msg){ struct wps_parse_attr attr; wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK"); if (wps_parse_msg(msg, &attr) < 0) return WPS_FAILURE; if (!wps_version_supported(attr.version)) { wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x", attr.version ? *attr.version : 0); return WPS_FAILURE; } if (attr.msg_type == NULL) { wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute"); return WPS_FAILURE; } if (*attr.msg_type != WPS_WSC_ACK) { wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d", *attr.msg_type); return WPS_FAILURE; }#ifdef CONFIG_WPS_UPNP if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK && upnp_wps_subscribers(wps->wps->wps_upnp)) { if (wps->wps->upnp_msgs) return WPS_CONTINUE; wpa_printf(MSG_DEBUG, "WPS: Wait for response from an " "external Registrar"); return WPS_PENDING; }#endif /* CONFIG_WPS_UPNP */ if (attr.registrar_nonce == NULL || os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0)) { wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce"); return WPS_FAILURE; } if (attr.enrollee_nonce == NULL || os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) { wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce"); return WPS_FAILURE; } if (wps->state == RECV_M2D_ACK) {#ifdef CONFIG_WPS_UPNP if (wps->wps->wps_upnp && upnp_wps_subscribers(wps->wps->wps_upnp)) { if (wps->wps->upnp_msgs) return WPS_CONTINUE; if (wps->ext_reg == 0) wps->ext_reg = 1; wpa_printf(MSG_DEBUG, "WPS: Wait for response from an " "external Registrar"); return WPS_PENDING; }#endif /* CONFIG_WPS_UPNP */ wpa_printf(MSG_DEBUG, "WPS: No more registrars available - " "terminate negotiation"); } return WPS_FAILURE;}static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps, const struct wpabuf *msg){ struct wps_parse_attr attr; int old_state; wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK"); old_state = wps->state; wps->state = SEND_WSC_NACK; if (wps_parse_msg(msg, &attr) < 0) return WPS_FAILURE; if (!wps_version_supported(attr.version)) { wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x", attr.version ? *attr.version : 0); return WPS_FAILURE; } if (attr.msg_type == NULL) { wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute"); return WPS_FAILURE; } if (*attr.msg_type != WPS_WSC_NACK) { wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d", *attr.msg_type); return WPS_FAILURE; }#ifdef CONFIG_WPS_UPNP if (wps->wps->wps_upnp && wps->ext_reg) { wpa_printf(MSG_DEBUG, "WPS: Negotiation using external " "Registrar terminated by the Enrollee"); return WPS_FAILURE; }#endif /* CONFIG_WPS_UPNP */ if (attr.registrar_nonce == NULL || os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0)) { wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce"); return WPS_FAILURE; } if (attr.enrollee_nonce == NULL || os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) { wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce"); return WPS_FAILURE; } if (attr.config_error == NULL) { wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute " "in WSC_NACK"); return WPS_FAILURE; } wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with " "Configuration Error %d", WPA_GET_BE16(attr.config_error)); switch (old_state) { case RECV_M3: wps_fail_event(wps->wps, WPS_M2); break; case RECV_M5: wps_fail_event(wps->wps, WPS_M4); break; case RECV_M7: wps_fail_event(wps->wps, WPS_M6); break; case RECV_DONE: wps_fail_event(wps->wps, WPS_M8); break; default: break; } return WPS_FAILURE;}static enum wps_process_res wps_process_wsc_done(struct wps_data *wps, const struct wpabuf *msg){ struct wps_parse_attr attr; wpa_printf(MSG_DEBUG, "WPS: Received WSC_Done"); if (wps->state != RECV_DONE && (!wps->wps->wps_upnp || !wps->ext_reg)) { wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for " "receiving WSC_Done", wps->state); return WPS_FAILURE; } if (wps_parse_msg(msg, &attr) < 0) return WPS_FAILURE; if (!wps_version_supported(attr.version)) { wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x", attr.version ? *attr.version : 0); return WPS_FAILURE; } if (attr.msg_type == NULL) { wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute"); return WPS_FAILURE; } if (*attr.msg_type != WPS_WSC_DONE) { wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d", *attr.msg_type); return WPS_FAILURE; }#ifdef CONFIG_WPS_UPNP if (wps->wps->wps_upnp && wps->ext_reg) { wpa_printf(MSG_DEBUG, "WPS: Negotiation using external " "Registrar completed successfully"); return WPS_DONE; }#endif /* CONFIG_WPS_UPNP */ if (attr.registrar_nonce == NULL || os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0)) { wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce"); return WPS_FAILURE; } if (attr.enrollee_nonce == NULL || os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) { wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce"); return WPS_FAILURE; } wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully"); if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk && wps->wps->ap && !wps->wps->registrar->disable_auto_conf) { struct wps_credential cred; wpa_printf(MSG_DEBUG, "WPS: Moving to Configured state based " "on first Enrollee connection"); os_memset(&cred, 0, sizeof(cred)); os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len); cred.ssid_len = wps->wps->ssid_len; cred.auth_type = WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK; cred.encr_type = WPS_ENCR_TKIP | WPS_ENCR_AES; os_memcpy(cred.key, wps->new_psk, wps->new_psk_len); cred.key_len = wps->new_psk_len; wps->wps->wps_state = WPS_STATE_CONFIGURED; wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Generated random passphrase", wps->new_psk, wps->new_psk_len); if (wps->wps->cred_cb) wps->wps->cred_cb(wps->wps->cb_ctx, &cred); os_free(wps->new_psk); wps->new_psk = NULL; } if (!wps->wps->ap) { wpa_printf(MSG_DEBUG, "WPS: Update local configuration based " "on the modified AP configuration"); if (wps->wps->cred_cb) wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred); } if (wps->new_psk) { if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e, wps->new_psk, wps->new_psk_len)) { wpa_printf(MSG_DEBUG, "WPS: Failed to configure the " "new PSK"); } os_free(wps->new_psk); wps->new_psk = NULL; } wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e); if (wps->pbc) { wps_registrar_remove_pbc_session(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e); wps_registrar_pbc_completed(wps->wps->registrar); } wps_success_event(wps->wps); return WPS_DONE;}enum wps_process_res wps_registrar_process_msg(struct wps_data *wps, enum wsc_op_code op_code, const struct wpabuf *msg){ enum wps_process_res ret; wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu " "op_code=%d)", (unsigned long) wpabuf_len(msg), op_code);#ifdef CONFIG_WPS_UPNP if (wps->wps->wps_upnp && op_code == WSC_MSG && wps->ext_reg == 1) { struct wps_parse_attr attr; if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type && *attr.msg_type == WPS_M3) wps->ext_reg = 2; /* past M2/M2D phase */ } if (wps->ext_reg > 1) wps_registrar_free_pending_m2(wps->wps); if (wps->wps->wps_upnp && wps->ext_reg && wps->wps->upnp_msgs == NULL && (op_code == WSC_MSG || op_code == WSC_Done)) { struct wps_parse_attr attr; int type; if (wps_parse_msg(msg, &attr) < 0 || attr.msg_type == NULL) type = -1; else type = *attr.msg_type; wpa_printf(MSG_DEBUG, "WPS: Sending received message (type %d)" " to external Registrar for processing", type); upnp_wps_device_send_wlan_event(wps->wps->wps_upnp, wps->mac_addr_e, UPNP_WPS_WLANEVENT_TYPE_EAP, msg); if (op_code == WSC_MSG) return WPS_PENDING; } else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) { wpa_printf(MSG_DEBUG, "WPS: Skip internal processing - using " "external Registrar"); return WPS_CONTINUE; }#endif /* CONFIG_WPS_UPNP */ switch (op_code) { case WSC_MSG: return wps_process_wsc_msg(wps, msg); case WSC_ACK: return wps_process_wsc_ack(wps, msg); case WSC_NACK: return wps_process_wsc_nack(wps, msg); case WSC_Done: ret = wps_process_wsc_done(wps, msg); if (ret == WPS_FAILURE) { wps->state = SEND_WSC_NACK; wps_fail_event(wps->wps, WPS_WSC_DONE); } return ret; default: wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code); return WPS_FAILURE; }}int wps_registrar_update_ie(struct wps_registrar *reg){ return wps_set_ie(reg);}static void wps_registrar_set_selected_timeout(void *eloop_ctx, void *timeout_ctx){ struct wps_registrar *reg = eloop_ctx; wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar timed out - " "unselect Registrar"); reg->selected_registrar = 0; reg->pbc = 0; reg->sel_reg_dev_password_id_override = -1; reg->sel_reg_config_methods_override = -1; wps_set_ie(reg);}/** * wps_registrar_set_selected_registrar - Notification of SetSelectedRegistrar * @reg: Registrar data from wps_registrar_init() * @msg: Received message from SetSelectedRegistrar * Returns: 0 on success, -1 on failure * * This function is called when an AP receives a SetSelectedRegistrar UPnP * message. */int wps_registrar_set_selected_registrar(struct wps_registrar *reg, const struct wpabuf *msg){ struct wps_parse_attr attr; wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes", msg); if (wps_parse_msg(msg, &attr) < 0) return -1; if (!wps_version_supported(attr.version)) { wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar " "version 0x%x", attr.version ? *attr.version : 0); return -1; } if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) { wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable " "Selected Registrar"); eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL); wps_registrar_set_selected_timeout(reg, NULL); return 0; } reg->selected_registrar = 1; reg->sel_reg_dev_password_id_override = attr.dev_password_id ? WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT; reg->sel_reg_config_methods_override = attr.sel_reg_config_methods ? WPA_GET_BE16(attr.sel_reg_config_methods) : -1; wps_set_ie(reg); eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL); eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_set_selected_timeout, reg, NULL); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -