Patchwork ibss_rsn.c: provide ibss_rsn_get_peer() helper function

login
register
mail settings
Submitter Antonio Quartulli
Date Jan. 28, 2012, 8:41 p.m.
Message ID <1327783265-12987-1-git-send-email-ordex@autistici.org>
Download mbox | patch
Permalink /patch/138413/
State Superseded
Headers show

Comments

Antonio Quartulli - Jan. 28, 2012, 8:41 p.m.
This is a useful function that simplifies some code and can eventually be used
somewhere else in future.

Signed-hostap: Antonio Quartulli <ordex@autistici.org>
---
 wpa_supplicant/ibss_rsn.c |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)
Antonio Quartulli - Jan. 28, 2012, 8:42 p.m.
On Sat, Jan 28, 2012 at 09:41:05PM +0100, Antonio Quartulli wrote:
> This is a useful function that simplifies some code and can eventually be used
> somewhere else in future.
> 
> Signed-hostap: Antonio Quartulli <ordex@autistici.org>

Please, forgot this patch. I'm probably tired...

I'll send v2

Patch

diff --git a/wpa_supplicant/ibss_rsn.c b/wpa_supplicant/ibss_rsn.c
index 40fc7e0..dccb1af 100644
--- a/wpa_supplicant/ibss_rsn.c
+++ b/wpa_supplicant/ibss_rsn.c
@@ -25,6 +25,17 @@ 
 #include "ibss_rsn.h"
 
 
+static ibss_rsn_peer *ibss_rsn_get_peer(struct ibss_rsn *ibss_rsn, u8 *addr)
+{
+	struct ibss_rsn_peer *peer = NULL;
+
+	for (peer = ibss_rsn->peers; peer; peer = peer->next)
+		if (os_memcmp(src_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);
@@ -384,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 "
@@ -593,11 +602,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) {
 		/*