From patchwork Thu Sep 24 17:37:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilan Peer X-Patchwork-Id: 522456 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]) by ozlabs.org (Postfix) with ESMTP id 5DAFA1401CD for ; Fri, 25 Sep 2015 03:40:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 2569E17C578; Thu, 24 Sep 2015 13:40:03 -0400 (EDT) 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 0sZ+rwGHmN2n; Thu, 24 Sep 2015 13:40:02 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id D2F5F17C57A; Thu, 24 Sep 2015 13:38:51 -0400 (EDT) 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 0112417C542 for ; Thu, 24 Sep 2015 13:38:49 -0400 (EDT) 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 qX5JkpG1CtCQ for ; Thu, 24 Sep 2015 13:38:47 -0400 (EDT) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 3608D17C531 for ; Thu, 24 Sep 2015 13:38:28 -0400 (EDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 24 Sep 2015 10:38:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,582,1437462000"; d="scan'208";a="812502883" Received: from unknown (HELO JEL00311.ger.corp.intel.com) ([10.12.217.137]) by orsmga002.jf.intel.com with ESMTP; 24 Sep 2015 10:38:26 -0700 From: Ilan Peer To: hostap@lists.shmoo.com Subject: [PATCH 07/23] P2PS: Re-factor p2ps_group_capability() Date: Thu, 24 Sep 2015 20:37:57 +0300 Message-Id: <1443116293-9323-8-git-send-email-ilan.peer@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1443116293-9323-1-git-send-email-ilan.peer@intel.com> References: <1443116293-9323-1-git-send-email-ilan.peer@intel.com> X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com The code was iterating all the interfaces, and for each interface iterated all the network blocks to count active P2P GO and P2P client interfaces. Change the code to reuse wpas_p2p_get_go_group() to get a P2P GO interface and add wpas_p2p_get_cli_group() and use it to find a P2P Client interface, and use these objects when evaluating the group capability. Signed-off-by: Ilan Peer --- wpa_supplicant/p2p_supplicant.c | 75 +++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 024ed9b..d87122e 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -582,6 +582,28 @@ wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s) } +static unsigned int p2p_is_active_persistent_cli(struct wpa_supplicant *wpa_s) +{ + if (p2p_is_active_persistent_group(wpa_s) && + wpa_s->current_ssid->mode == WPAS_MODE_INFRA) + return 1; + return 0; +} + + +/* Find an interface for a P2P group where we are the Client */ +static struct wpa_supplicant * +wpas_p2p_get_cli_group(struct wpa_supplicant *wpa_s) +{ + for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { + if (p2p_is_active_persistent_cli(wpa_s)) + return wpa_s; + } + + return NULL; +} + + /* Find an active P2P group where we are the GO */ static struct wpa_ssid * wpas_p2p_group_go_ssid(struct wpa_supplicant *wpa_s, u8 *bssid) @@ -613,13 +635,11 @@ wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s) static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role) { - struct wpa_supplicant *wpa_s = ctx, *tmp_wpa_s; + struct wpa_supplicant *wpa_s = ctx; struct wpa_ssid *s; u8 conncap = P2PS_SETUP_NONE; unsigned int owned_members = 0; - unsigned int owner = 0; - unsigned int client = 0; - struct wpa_supplicant *go_wpa_s; + struct wpa_supplicant *go_wpa_s, *cli_wpa_s; struct wpa_ssid *persistent_go; int p2p_no_group_iface; @@ -632,36 +652,22 @@ static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role) * If client, then no GO. */ go_wpa_s = wpas_p2p_get_go_group(wpa_s); - persistent_go = wpas_p2p_get_persistent_go(wpa_s); - p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s); + if (go_wpa_s) + owned_members = p2p_get_group_num_members(go_wpa_s->p2p_group); + cli_wpa_s = wpas_p2p_get_cli_group(wpa_s); - wpa_printf(MSG_DEBUG, "P2P: GO(iface)=%p persistent(ssid)=%p", - go_wpa_s, persistent_go); + p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s); + persistent_go = wpas_p2p_get_persistent_go(wpa_s); - for (tmp_wpa_s = wpa_s->global->ifaces; tmp_wpa_s; - tmp_wpa_s = tmp_wpa_s->next) { - for (s = tmp_wpa_s->conf->ssid; s; s = s->next) { - wpa_printf(MSG_DEBUG, - "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d", - tmp_wpa_s, s, s->disabled, - s->p2p_group, s->mode); - if (!s->disabled && s->p2p_group) { - if (s->mode == WPAS_MODE_P2P_GO) { - owned_members += - p2p_get_group_num_members( - tmp_wpa_s->p2p_group); - owner++; - } else - client++; - } - } - } + wpa_printf(MSG_DEBUG, + "P2P: GO(iface)=%p members=%d CLI(iface)=%p persistent(ssid)=%p", + go_wpa_s, owned_members, cli_wpa_s, persistent_go); /* If not concurrent, restrict our choices */ if (p2p_no_group_iface) { wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface"); - if (client) + if (cli_wpa_s) return P2PS_SETUP_NONE; if (go_wpa_s) { @@ -705,7 +711,7 @@ static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role) * Must be a complimentary role - cannot be a client to * more than one peer. */ - if (incoming == role || client) + if (incoming == role || cli_wpa_s) return P2PS_SETUP_NONE; return P2PS_SETUP_CLIENT; @@ -731,7 +737,7 @@ static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role) switch (incoming) { case P2PS_SETUP_NONE: case P2PS_SETUP_NEW: - if (client) + if (cli_wpa_s) conncap = P2PS_SETUP_GROUP_OWNER; else if (!owned_members) conncap = P2PS_SETUP_NEW; @@ -746,13 +752,13 @@ static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role) break; case P2PS_SETUP_GROUP_OWNER: - if (!client) + if (!cli_wpa_s) conncap = P2PS_SETUP_CLIENT; break; case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: - if (client) + if (cli_wpa_s) conncap = P2PS_SETUP_GROUP_OWNER; else { u8 r; @@ -774,15 +780,12 @@ grp_owner: (!incoming && (conncap & P2PS_SETUP_NEW))) { if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group)) conncap &= ~P2PS_SETUP_GROUP_OWNER; - wpa_printf(MSG_DEBUG, "P2P: GOs:%d members:%d conncap:%d", - owner, owned_members, conncap); s = wpas_p2p_get_persistent_go(wpa_s); - - if (!s && !owner && p2p_no_group_iface) { + if (!s && !go_wpa_s && p2p_no_group_iface) { p2p_set_intended_addr(wpa_s->global->p2p, wpa_s->own_addr); - } else if (!s && !owner) { + } else if (!s && !go_wpa_s) { if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0) { wpa_printf(MSG_ERROR,