From patchwork Sat Jan 28 20:44:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 138414 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 5250DB6F67 for ; Sun, 29 Jan 2012 07:45:54 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 4A1EF17C066; Sat, 28 Jan 2012 15:45:52 -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 9KAN-N-7okpq; Sat, 28 Jan 2012 15:45:52 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C45849D1E4; Sat, 28 Jan 2012 15:45:46 -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 1BDB79D1E4 for ; Sat, 28 Jan 2012 15:45:45 -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 TJ2g96PW1RL8 for ; Sat, 28 Jan 2012 15:45:41 -0500 (EST) Received: from latitanza.investici.org (latitanza.investici.org [82.94.249.234]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "smtp.autistici.org", Issuer "Autistici/Inventati Certification Authority" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id E4CB49D0D5 for ; Sat, 28 Jan 2012 15:45:40 -0500 (EST) Received: from [82.94.249.234] (latitanza [82.94.249.234]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 64492980B0; Sat, 28 Jan 2012 20:45:39 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 latitanza.investici.org 64492980B0 From: Antonio Quartulli To: hostap Subject: [PATCHv2] ibss_rsn.c: provide ibss_rsn_get_peer() helper function Date: Sat, 28 Jan 2012 21:44:51 +0100 Message-Id: <1327783491-15541-1-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1327783265-12987-1-git-send-email-ordex@autistici.org> References: <1327783265-12987-1-git-send-email-ordex@autistici.org> 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: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com This is a useful function that simplifies some code and can eventually be used somewhere else in future. Signed-hostap: Antonio Quartulli --- wpa_supplicant/ibss_rsn.c | 33 +++++++++++++++++++++------------ 1 files changed, 21 insertions(+), 12 deletions(-) diff --git a/wpa_supplicant/ibss_rsn.c b/wpa_supplicant/ibss_rsn.c index d4fa39d..8655113 100644 --- a/wpa_supplicant/ibss_rsn.c +++ b/wpa_supplicant/ibss_rsn.c @@ -24,6 +24,18 @@ #include "ibss_rsn.h" +static struct ibss_rsn_peer *ibss_rsn_get_peer(struct ibss_rsn *ibss_rsn, + const u8 *addr) +{ + struct ibss_rsn_peer *peer = NULL; + + for (peer = ibss_rsn->peers; peer; peer = peer->next) + if (os_memcmp(addr, peer->addr, ETH_ALEN) == 0) + break; + return peer; +} + + static void ibss_rsn_free(struct ibss_rsn_peer *peer) { wpa_auth_sta_deinit(peer->auth); @@ -383,13 +395,11 @@ int ibss_rsn_start(struct ibss_rsn *ibss_rsn, const u8 *addr) if (ibss_rsn == NULL) return -1; - for (peer = ibss_rsn->peers; peer; peer = peer->next) { - if (os_memcmp(addr, peer->addr, ETH_ALEN) == 0) { - wpa_printf(MSG_DEBUG, "RSN: IBSS Authenticator and " - "Supplicant for peer " MACSTR " already " - "running", MAC2STR(addr)); - return 0; - } + if (ibss_rsn_get_peer(ibss_rsn, addr)) { + wpa_printf(MSG_DEBUG, "RSN: IBSS Authenticator and " + "Supplicant for peer " MACSTR " already " + "running", MAC2STR(addr)); + return 0; } wpa_printf(MSG_DEBUG, "RSN: Starting IBSS Authenticator and " @@ -577,11 +587,10 @@ int ibss_rsn_rx_eapol(struct ibss_rsn *ibss_rsn, const u8 *src_addr, if (ibss_rsn == NULL) return -1; - for (peer = ibss_rsn->peers; peer; peer = peer->next) { - if (os_memcmp(src_addr, peer->addr, ETH_ALEN) == 0) - return ibss_rsn_process_rx_eapol(ibss_rsn, peer, - buf, len); - } + peer = ibss_rsn_get_peer(ibss_rsn, src_addr); + if (peer) + return ibss_rsn_process_rx_eapol(ibss_rsn, peer, + buf, len); if (ibss_rsn_eapol_dst_supp(buf, len) > 0) { /*