From patchwork Fri Nov 18 11:59:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 126397 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 3158CB724F for ; Fri, 18 Nov 2011 22:59:50 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id E15319C17C; Fri, 18 Nov 2011 06:59:46 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PujDvpgcF241; Fri, 18 Nov 2011 06:59:46 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id D878F9C240; Fri, 18 Nov 2011 06:59:35 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id B53C49C240 for ; Fri, 18 Nov 2011 06:59:34 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x4d4jEhMaByG for ; Fri, 18 Nov 2011 06:59:31 -0500 (EST) Received: from sipsolutions.net (he.sipsolutions.net [78.46.109.217]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id D7A169C17C for ; Fri, 18 Nov 2011 06:59:30 -0500 (EST) Received: by sipsolutions.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.77) (envelope-from ) id 1RRN6P-0007Py-Ey for hostap@lists.shmoo.com; Fri, 18 Nov 2011 12:59:29 +0100 Subject: [PATCH] P2P: simplify code in wpas_p2p_connect From: Johannes Berg To: hostap@lists.shmoo.com Date: Fri, 18 Nov 2011 12:59:27 +0100 Message-ID: <1321617567.10266.49.camel@jlt3.sipsolutions.net> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Johannes Berg There's some duplicated code there that can be simplified with just a single new variable. Signed-hostap: Johannes Berg --- wpa_supplicant/p2p_supplicant.c | 49 ++++++++++++++++----------------------- 1 files changed, 20 insertions(+), 29 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index d2668be..78bb344 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -2670,6 +2670,7 @@ int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, u8 bssid[ETH_ALEN]; int ret = 0; enum wpa_driver_if_type iftype; + const u8 *iface_addr; if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) return -1; @@ -2765,44 +2766,34 @@ int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); - if (!wpa_s->create_p2p_iface) { - if (auth) { - if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, - go_intent, wpa_s->own_addr, - force_freq, persistent_group) - < 0) - return -1; - return ret; - } - if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, - go_intent, wpa_s->own_addr, - force_freq, persistent_group) < 0) + if (wpa_s->create_p2p_iface) { + /* Prepare to add a new interface for the group */ + iftype = WPA_IF_P2P_GROUP; + if (go_intent == 15) + iftype = WPA_IF_P2P_GO; + if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { + wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " + "interface for the group"); return -1; - return ret; - } + } - /* Prepare to add a new interface for the group */ - iftype = WPA_IF_P2P_GROUP; - if (go_intent == 15) - iftype = WPA_IF_P2P_GO; - if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { - wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " - "interface for the group"); - return -1; - } + iface_addr = wpa_s->pending_interface_addr; + } else + iface_addr = wpa_s->own_addr; if (auth) { if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, - go_intent, - wpa_s->pending_interface_addr, + go_intent, iface_addr, force_freq, persistent_group) < 0) return -1; return ret; } - if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, go_intent, - wpa_s->pending_interface_addr, - force_freq, persistent_group) < 0) { - wpas_p2p_remove_pending_group_interface(wpa_s); + + if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, + go_intent, iface_addr, force_freq, + persistent_group) < 0) { + if (wpa_s->create_p2p_iface) + wpas_p2p_remove_pending_group_interface(wpa_s); return -1; } return ret;