From patchwork Wed Nov 16 09:15:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 125963 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 A3D77B6FA0 for ; Wed, 16 Nov 2011 20:16:12 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 7B2009C132; Wed, 16 Nov 2011 04:16:09 -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 g5pATfELLV03; Wed, 16 Nov 2011 04:16:09 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 61BA29C133; Wed, 16 Nov 2011 04:16:05 -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 297F69C133 for ; Wed, 16 Nov 2011 04:16:04 -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 Qbok8uJpc6pW for ; Wed, 16 Nov 2011 04:15:59 -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 47CC79C132 for ; Wed, 16 Nov 2011 04:15:59 -0500 (EST) Received: by sipsolutions.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.77) (envelope-from ) id 1RQbb2-0000tD-7K; Wed, 16 Nov 2011 10:15:56 +0100 Subject: [PATCH] P2P: deal with a peer associating while connected From: Johannes Berg To: "hostap@lists.shmoo.com" Date: Wed, 16 Nov 2011 10:15:55 +0100 Message-ID: <1321434955.4773.12.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 If a P2P client associates with the group while it is already associated, two member entries may be added to the group which also confuses num_members counting. Deal with this by removing the existing entry first before adding a new one. I think the way Reinette ran into this was due to our tx_sync implementation in iwlagn, mac80211 might have queued two association frames thinking the first one just failed, but both only went out after the sync was really successful (which tx_sync doesn't wait for). Reported-by: Reinette Chatre Signed-hostap: Johannes Berg --- src/p2p/p2p_group.c | 54 +++++++++++++++++++++++++++++++------------------- 1 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/p2p/p2p_group.c b/src/p2p/p2p_group.c index 58b24c5..c34a92f 100644 --- a/src/p2p/p2p_group.c +++ b/src/p2p/p2p_group.c @@ -313,6 +313,36 @@ static struct wpabuf * p2p_build_client_info(const u8 *addr, } +static int p2p_group_remove_member(struct p2p_group *group, const u8 *addr) +{ + struct p2p_group_member *m, *prev; + + if (group == NULL) + return 0; + + m = group->members; + prev = NULL; + while (m) { + if (os_memcmp(m->addr, addr, ETH_ALEN) == 0) + break; + prev = m; + m = m->next; + } + + if (m == NULL) + return 0; + + if (prev) + prev->next = m->next; + else + group->members = m->next; + p2p_group_free_member(m); + group->num_members--; + + return 1; +} + + int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr, const u8 *ie, size_t len) { @@ -332,6 +362,8 @@ int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr, m->dev_addr); } + p2p_group_remove_member(group, addr); + m->next = group->members; group->members = m; group->num_members++; @@ -374,27 +406,7 @@ struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status) void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr) { - struct p2p_group_member *m, *prev; - - if (group == NULL) - return; - - m = group->members; - prev = NULL; - while (m) { - if (os_memcmp(m->addr, addr, ETH_ALEN) == 0) - break; - prev = m; - m = m->next; - } - - if (m) { - if (prev) - prev->next = m->next; - else - group->members = m->next; - p2p_group_free_member(m); - group->num_members--; + if (p2p_group_remove_member(group, addr)) { wpa_msg(group->p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Remove " "client " MACSTR " from group; num_members=%u/%u", MAC2STR(addr), group->num_members,