Browse Source

Add drv_event_eapol_rx() helper

Jouni Malinen 15 years ago
parent
commit
baac649094

+ 11 - 0
src/drivers/driver.h

@@ -2305,4 +2305,15 @@ static inline void drv_event_disassoc(void *ctx, const u8 *addr)
 	wpa_supplicant_event(ctx, EVENT_DISASSOC, &event);
 }
 
+static inline void drv_event_eapol_rx(void *ctx, const u8 *src, const u8 *data,
+				      size_t data_len)
+{
+	union wpa_event_data event;
+	os_memset(&event, 0, sizeof(event));
+	event.eapol_rx.src = src;
+	event.eapol_rx.data = data;
+	event.eapol_rx.data_len = data_len;
+	wpa_supplicant_event(ctx, EVENT_EAPOL_RX, &event);
+}
+
 #endif /* DRIVER_H */

+ 2 - 6
src/drivers/driver_atheros.c

@@ -1071,12 +1071,8 @@ static void
 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
 {
 	struct madwifi_driver_data *drv = ctx;
-	union wpa_event_data event;
-	os_memset(&event, 0, sizeof(event));
-	event.eapol_rx.src = src_addr;
-	event.eapol_rx.data = buf + sizeof(struct l2_ethhdr);
-	event.eapol_rx.data_len = len - sizeof(struct l2_ethhdr);
-	wpa_supplicant_event(drv->hapd, EVENT_EAPOL_RX, &event);
+	drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
+			   len - sizeof(struct l2_ethhdr));
 }
 
 static void *

+ 2 - 6
src/drivers/driver_bsd.c

@@ -736,12 +736,8 @@ static void
 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
 {
 	struct bsd_driver_data *drv = ctx;
-	union wpa_event_data event;
-	os_memset(&event, 0, sizeof(event));
-	event.eapol_rx.src = src_addr;
-	event.eapol_rx.data = buf + sizeof(struct l2_ethhdr);
-	event.eapol_rx.data_len = len - sizeof(struct l2_ethhdr);
-	wpa_supplicant_event(drv->hapd, EVENT_EAPOL_RX, &event);
+	drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
+			   len - sizeof(struct l2_ethhdr));
 }
 
 static int

+ 1 - 5
src/drivers/driver_hostap.c

@@ -112,11 +112,7 @@ static void handle_data(struct hostap_driver_data *drv, u8 *buf, size_t len,
 	left -= 2;
 	switch (ethertype) {
 	case ETH_P_PAE:
-		os_memset(&event, 0, sizeof(event));
-		event.eapol_rx.src = sa;
-		event.eapol_rx.data = pos;
-		event.eapol_rx.data_len = left;
-		wpa_supplicant_event(drv->hapd, EVENT_EAPOL_RX, &event);
+		drv_event_eapol_rx(drv->hapd, sa, pos, left);
 		break;
 
 	default:

+ 2 - 6
src/drivers/driver_madwifi.c

@@ -1141,12 +1141,8 @@ static void
 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
 {
 	struct madwifi_driver_data *drv = ctx;
-	union wpa_event_data event;
-	os_memset(&event, 0, sizeof(event));
-	event.eapol_rx.src = src_addr;
-	event.eapol_rx.data = buf + sizeof(struct l2_ethhdr);
-	event.eapol_rx.data_len = len - sizeof(struct l2_ethhdr);
-	wpa_supplicant_event(drv->hapd, EVENT_EAPOL_RX, &event);
+	drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
+			   len - sizeof(struct l2_ethhdr));
 }
 
 static void *

+ 2 - 8
src/drivers/driver_nl80211.c

@@ -4233,14 +4233,8 @@ static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
 		return;
 	}
 
-	if (have_ifidx(drv, lladdr.sll_ifindex)) {
-		union wpa_event_data event;
-		os_memset(&event, 0, sizeof(event));
-		event.eapol_rx.src = lladdr.sll_addr;
-		event.eapol_rx.data = buf;
-		event.eapol_rx.data_len = len;
-		wpa_supplicant_event(drv->ctx, EVENT_EAPOL_RX, &event);
-	}
+	if (have_ifidx(drv, lladdr.sll_ifindex))
+		drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
 }
 
 

+ 1 - 8
src/drivers/driver_privsep.c

@@ -432,16 +432,9 @@ static void wpa_driver_privsep_event_ft_response(void *ctx, u8 *buf,
 
 static void wpa_driver_privsep_event_rx_eapol(void *ctx, u8 *buf, size_t len)
 {
-	union wpa_event_data event;
-
 	if (len < ETH_ALEN)
 		return;
-
-	os_memset(&event, 0, sizeof(event));
-	event.eapol_rx.src = buf;
-	event.eapol_rx.data = buf + ETH_ALEN;
-	event.eapol_rx.data_len = len - ETH_ALEN;
-	wpa_supplicant_event(ctx, EVENT_EAPOL_RX, &event);
+	drv_event_eapol_rx(ctx, buf, buf + ETH_ALEN, len - ETH_ALEN);
 }
 
 

+ 2 - 8
src/drivers/driver_roboswitch.c

@@ -179,14 +179,8 @@ static void wpa_driver_roboswitch_receive(void *priv, const u8 *src_addr,
 	struct wpa_driver_roboswitch_data *drv = priv;
 
 	if (len > 14 && WPA_GET_BE16(buf + 12) == ETH_P_EAPOL &&
-	    os_memcmp(buf, drv->own_addr, ETH_ALEN) == 0) {
-		union wpa_event_data event;
-		os_memset(&event, 0, sizeof(event));
-		event.eapol_rx.src = src_addr;
-		event.eapol_rx.data = buf + 14;
-		event.eapol_rx.data_len = len - 14;
-		wpa_supplicant_event(drv->ctx, EVENT_EAPOL_RX, &event);
-	}
+	    os_memcmp(buf, drv->own_addr, ETH_ALEN) == 0)
+		drv_event_eapol_rx(drv->ctx, src_addr, buf + 14, len - 14);
 }
 
 

+ 5 - 22
src/drivers/driver_test.c

@@ -647,8 +647,6 @@ static void test_driver_eapol(struct wpa_driver_test_data *drv,
 	struct test_client_socket *cli;
 #endif /* HOSTAPD */
 	const u8 *src = NULL;
-	union wpa_event_data event;
-	void *ctx;
 
 	if (datalen > 14) {
 		/* Skip Ethernet header */
@@ -661,29 +659,19 @@ static void test_driver_eapol(struct wpa_driver_test_data *drv,
 		datalen -= 14;
 	}
 
-	os_memset(&event, 0, sizeof(event));
-	event.eapol_rx.data = data;
-	event.eapol_rx.data_len = datalen;
-
 #ifdef HOSTAPD
 	cli = test_driver_get_cli(drv, from, fromlen);
 	if (cli) {
-		event.eapol_rx.src = cli->addr;
-		ctx = cli->bss->bss_ctx;
+		drv_event_eapol_rx(cli->bss->bss_ctx, cli->addr, data,
+				   datalen);
 	} else {
 		wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
 			   "client");
-		return;
 	}
 #else /* HOSTAPD */
-	if (src) {
-		event.eapol_rx.src = src;
-		ctx = drv->ctx;
-	} else
-		return;
+	if (src)
+		drv_event_eapol_rx(drv->ctx, src, data, datalen);
 #endif /* HOSTAPD */
-
-	wpa_supplicant_event(ctx, EVENT_EAPOL_RX, &event);
 }
 
 
@@ -1811,7 +1799,6 @@ static void wpa_driver_test_eapol(struct wpa_driver_test_data *drv,
 				  const u8 *data, size_t data_len)
 {
 	const u8 *src = drv->bssid;
-	union wpa_event_data event;
 
 	if (data_len > 14) {
 		/* Skip Ethernet header */
@@ -1820,11 +1807,7 @@ static void wpa_driver_test_eapol(struct wpa_driver_test_data *drv,
 		data_len -= 14;
 	}
 
-	os_memset(&event, 0, sizeof(event));
-	event.eapol_rx.src = src;
-	event.eapol_rx.data = data;
-	event.eapol_rx.data_len = data_len;
-	wpa_supplicant_event(drv->ctx, EVENT_EAPOL_RX, &event);
+	drv_event_eapol_rx(drv->ctx, src, data, data_len);
 }
 
 

+ 1 - 6
src/drivers/driver_wired.c

@@ -140,12 +140,7 @@ static void handle_data(void *ctx, unsigned char *buf, size_t len)
 
 			pos = (u8 *) (hdr + 1);
 			left = len - sizeof(*hdr);
-
-			os_memset(&event, 0, sizeof(event));
-			event.eapol_rx.src = sa;
-			event.eapol_rx.data = pos;
-			event.eapol_rx.data_len = left;
-			wpa_supplicant_event(ctx, EVENT_EAPOL_RX, &event);
+			drv_event_eapol_rx(ctx, sa, pos, left);
 		break;
 
 	default: