[PATCH] driver_bsd.c: Clean up EAPOL frame transmission code

Masashi Honma honma at ictec.co.jp
Tue Jan 26 21:18:10 EST 2010


(2010/01/18 9:10), Masashi Honma wrote:
>
> Thank you for your advices. I'll try it.

The bsd_send_eapol() add Ethernet header by itself. This patch changes it
to use l2_packet functionality.

I have tested on NetBSD 5.0.1 with WPA-PSK(TKIP).


diff --git a/src/drivers/driver_bsd.c b/src/drivers/driver_bsd.c
index 9744570..8290ae0 100644
--- a/src/drivers/driver_bsd.c
+++ b/src/drivers/driver_bsd.c
@@ -696,44 +696,18 @@ bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
  	       int encrypt, const u8 *own_addr)
  {
  	struct bsd_driver_data *drv = priv;
-	unsigned char *bp;
-	struct l2_ethhdr *eth;
-	size_t len;
-	int status;
  
-	/*
-	 * Prepend the Ethernet header.  If the caller left us
-	 * space at the front we could just insert it but since
-	 * we don't know we copy to a local buffer.  Given the frequency
-	 * and size of frames this probably doesn't matter.
-	 */
-	len = data_len + sizeof(struct l2_ethhdr);
-	bp = os_zalloc(len);
-	if (bp == NULL) {
-		wpa_printf(MSG_ERROR, "malloc() failed for bsd_send_eapol"
-			   "(len=%lu)", (unsigned long) len);
-		return -1;
-	}
-	eth = (struct l2_ethhdr *) bp;
-	os_memcpy(eth->h_dest, addr, ETH_ALEN);
-	os_memcpy(eth->h_source, own_addr, ETH_ALEN);
-	eth->h_proto = htons(ETH_P_EAPOL);
-	os_memcpy(eth + 1, data, data_len);
-
-	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
-
-	status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
+	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", data, data_len);
  
-	os_free(bp);
-	return status;
+	return l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, data,
+			      data_len);
  }
  
  static void
  handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
  {
  	struct bsd_driver_data *drv = ctx;
-	drv_event_eapol_rx(drv->hapd, src_addr, buf + sizeof(struct l2_ethhdr),
-			   len - sizeof(struct l2_ethhdr));
+	drv_event_eapol_rx(drv->hapd, src_addr, buf, len);
  }
  
  static int
@@ -778,7 +752,7 @@ bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params)
  	memcpy(drv->iface, params->ifname, sizeof(drv->iface));
  
  	drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
-					handle_read, drv, 1);
+					handle_read, drv, 0);
  	if (drv->sock_xmit == NULL)
  		goto bad;
  	if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))


Regards,
Masashi Honma.


More information about the HostAP mailing list