From 361cdf34009c7407ddf22dee6f5e6ce82e81bcae Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 13 Apr 2012 17:01:15 +0300 Subject: [PATCH] P2P: Extend use of group formation timeout until end of 4-way handshake Instead of relying on the P2P group idle timeout before the group connection has been fully established, re-start the group formation timeout in the end of the WPS provisioning step and clear it at the successful completion of the initial 4-way handshake. This allows the P2P group idle timeout to be set to a small value without triggering it during the initial scan and connection attempt. Signed-hostap: Jouni Malinen --- wpa_supplicant/p2p_supplicant.c | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index e4f9d9b85..0b1801eb3 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -47,6 +47,14 @@ #define P2P_MAX_CLIENT_IDLE 10 #endif /* P2P_MAX_CLIENT_IDLE */ +#ifndef P2P_MAX_INITIAL_CONN_WAIT +/* + * How many seconds to wait for initial 4-way handshake to get completed after + * WPS provisioning step. + */ +#define P2P_MAX_INITIAL_CONN_WAIT 10 +#endif /* P2P_MAX_INITIAL_CONN_WAIT */ + static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx); static struct wpa_supplicant * @@ -3617,6 +3625,17 @@ void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent, NULL); + if (ssid && ssid->mode == WPAS_MODE_INFRA) { + /* + * Use a separate timeout for initial data connection to + * complete to allow the group to be removed automatically if + * something goes wrong in this step before the P2P group idle + * timeout mechanism is taken into use. + */ + eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, + wpas_p2p_group_formation_timeout, + wpa_s, NULL); + } if (wpa_s->global->p2p) p2p_wps_success_cb(wpa_s->global->p2p, peer_addr); else if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) @@ -3997,6 +4016,9 @@ void wpas_p2p_completed(struct wpa_supplicant *wpa_s) int persistent; int freq; + eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent, + NULL); + if (!wpa_s->show_group_started || !ssid) return; @@ -4129,6 +4151,19 @@ static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s) return; } + if (wpa_s->show_group_started) { + /* + * Use the normal group formation timeout between the end of + * the provisioning phase and completion of 4-way handshake to + * avoid terminating this process too early due to group idle + * timeout. + */ + wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " + "while waiting for initial 4-way handshake to " + "complete"); + return; + } + wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds", timeout); eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout,