From bb4d4deb4bbb7b094faa16fa41f1f49b062cbf22 Mon Sep 17 00:00:00 2001 From: Masashi Honma Date: Tue, 25 Dec 2012 14:15:07 +0200 Subject: [PATCH] P2P: Allow PSK to be used instead of passphrase for persistent GO This continues optimizations for use of CPU heavy pbkdf2_sha1() in GO setup after the earlier commit 30c371e8a54c3b1bece6366ff0666da15d63e45e by allowing PSK to be used instead of passphrase when creating persistent group information manually for the GO. It should be noted that this would not meet the requirements in the P2P specification (GO shall maintain the passphrase), so this should be used only when there is no need to allow manual configuration of legacy STAs using the passphrase. Signed-hostap: Masashi Honma --- wpa_supplicant/p2p_supplicant.c | 63 +++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 202857b91..303339b4b 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -796,15 +796,28 @@ static void p2p_go_configured(void *ctx, void *data) wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning"); if (wpa_s->global->p2p_group_formation == wpa_s) wpa_s->global->p2p_group_formation = NULL; - wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED - "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" " - "go_dev_addr=" MACSTR "%s", - wpa_s->ifname, - wpa_ssid_txt(ssid->ssid, ssid->ssid_len), - ssid->frequency, - params->passphrase ? params->passphrase : "", - MAC2STR(wpa_s->global->p2p_dev_addr), - params->persistent_group ? " [PERSISTENT]" : ""); + if (os_strlen(params->passphrase) > 0) { + wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED + "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" " + "go_dev_addr=" MACSTR "%s", wpa_s->ifname, + wpa_ssid_txt(ssid->ssid, ssid->ssid_len), + ssid->frequency, params->passphrase, + MAC2STR(wpa_s->global->p2p_dev_addr), + params->persistent_group ? " [PERSISTENT]" : + ""); + } else { + char psk[65]; + wpa_snprintf_hex(psk, sizeof(psk), params->psk, + sizeof(params->psk)); + wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED + "%s GO ssid=\"%s\" freq=%d psk=%s " + "go_dev_addr=" MACSTR "%s", wpa_s->ifname, + wpa_ssid_txt(ssid->ssid, ssid->ssid_len), + ssid->frequency, psk, + MAC2STR(wpa_s->global->p2p_dev_addr), + params->persistent_group ? " [PERSISTENT]" : + ""); + } if (params->persistent_group) network_id = wpas_p2p_store_persistent_group( @@ -874,13 +887,16 @@ static void wpas_start_wps_go(struct wpa_supplicant *wpa_s, ssid->key_mgmt = WPA_KEY_MGMT_PSK; ssid->proto = WPA_PROTO_RSN; ssid->pairwise_cipher = WPA_CIPHER_CCMP; - ssid->passphrase = os_strdup(params->passphrase); - if (ssid->passphrase == NULL) { - wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to copy passphrase for " - "GO"); - wpa_config_remove_network(wpa_s->conf, ssid->id); - return; - } + if (os_strlen(params->passphrase) > 0) { + ssid->passphrase = os_strdup(params->passphrase); + if (ssid->passphrase == NULL) { + wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to copy " + "passphrase for GO"); + wpa_config_remove_network(wpa_s->conf, ssid->id); + return; + } + } else + ssid->passphrase = NULL; ssid->psk_set = params->psk_set; if (ssid->psk_set) os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); @@ -4099,14 +4115,15 @@ int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, params.psk_set = ssid->psk_set; if (params.psk_set) os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); - if (ssid->passphrase == NULL || - os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { - wpa_printf(MSG_DEBUG, "P2P: Invalid passphrase in persistent " - "group"); - return -1; + if (ssid->passphrase) { + if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { + wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in " + "persistent group"); + return -1; + } + os_strlcpy(params.passphrase, ssid->passphrase, + sizeof(params.passphrase)); } - os_strlcpy(params.passphrase, ssid->passphrase, - sizeof(params.passphrase)); os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len); params.ssid_len = ssid->ssid_len; params.persistent_group = 1;