PATCH: moved send_eapol to driver.c

Gunter Burchardt gbur
Thu Jun 17 02:19:30 PDT 2004


Hello Jouni

Ok the last patch was a bit to large. So i split my issue in to steps.
Here is the part which moved ieee802_1x_send_data to driver.c . I hope
indentation is ok now.

The part which moved hapd->sock to driver->sock comes in next patch. I
will wrap all send(hapd->sock,...) calls to a function in driver.c eg.
hostapd_send_mgmt_frame and make a function pointer to
hapd->driver.send_mgmt_frame . I think setup packets should remain in
ieee802_11.c .

regards
gunter
-------------- next part --------------
diff -Nur hostap/hostapd/driver.c hostap.new/hostapd/driver.c
--- hostap/hostapd/driver.c	2004-06-17 06:45:25.000000000 +0200
+++ hostap.new/hostapd/driver.c	2004-06-17 10:02:02.000000000 +0200
@@ -38,6 +38,53 @@
 #include "ieee802_11.h"
 
 
+static int hostapd_send_eapol(void *priv, u8 *addr,
+    		 u8 *data, size_t data_len, int encrypt)
+{
+	struct hostap_driver_data *drv = priv;
+	struct ieee80211_hdr *hdr;
+	size_t len;
+	u8 *pos;
+	int res;
+
+	len = sizeof(*hdr) + sizeof(rfc1042_header) + 2 + data_len;
+	hdr = malloc(len);
+	if (hdr == NULL) {
+		printf("malloc() failed for hostapd_send_data(len=%d)\n", len);
+		return -1;
+	}
+
+	memset(hdr, 0, len);
+	hdr->frame_control =
+		IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
+	hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
+	/* Request TX callback */
+	hdr->frame_control |= host_to_le16(BIT(1));
+	if (encrypt)
+		hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
+	memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
+	memcpy(hdr->IEEE80211_BSSID_FROMDS, drv->hapd->own_addr, ETH_ALEN);
+	memcpy(hdr->IEEE80211_SA_FROMDS, drv->hapd->own_addr, ETH_ALEN);
+
+	pos = (u8 *) (hdr + 1);
+	memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
+	pos += sizeof(rfc1042_header);
+	*((u16 *) pos) = htons(ETH_P_PAE);
+	pos += 2;
+	memcpy(pos, data, data_len);
+
+	res = send(drv->hapd->sock, (u8 *) hdr, len, 0);
+	free(hdr);
+
+	if (res < 0) {
+		perror("hostapd_send_data: send");
+		printf("hostapd_data_send - packet len: %d - failed\n", len);
+	}
+
+	return res;
+}
+
+
 static void hostapd_set_sta_authorized(void *priv, u8 *addr, int authorized)
 {
 	struct hostap_driver_data *drv = priv;
@@ -556,6 +603,7 @@
 
 	/* register callback functions */
 	hapd->driver.set_sta_authorized = hostapd_set_sta_authorized;
+	hapd->driver.send_eapol = hostapd_send_eapol;
 
 	return 0;
 }
@@ -566,6 +614,7 @@
 	struct hostap_driver_data *drv = hapd->driver.data;
 
 	hapd->driver.set_sta_authorized = NULL;
+	hapd->driver.send_eapol = NULL;
 
 	(void) hostapd_set_iface_flags(drv, 0);
 	(void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
diff -Nur hostap/hostapd/hostapd.h hostap.new/hostapd/hostapd.h
--- hostap/hostapd/hostapd.h	2004-06-17 06:37:40.000000000 +0200
+++ hostap.new/hostapd/hostapd.h	2004-06-17 10:13:49.000000000 +0200
@@ -49,6 +49,8 @@
 struct driver_info {
 	void *data; /* driver specific data - each driver can store data for
 		     * its own use in this pointer */
+	int (*send_eapol)(void *driver, u8 *addr, u8 *data, size_t
+			  data_len, int encrypt);
 	void (*set_sta_authorized)(void *driver, u8 *addr, int authorized);
 };
 
diff -Nur hostap/hostapd/ieee802_1x.c hostap.new/hostapd/ieee802_1x.c
--- hostap/hostapd/ieee802_1x.c	2004-06-17 06:37:40.000000000 +0200
+++ hostap.new/hostapd/ieee802_1x.c	2004-06-17 10:15:37.000000000 +0200
@@ -36,52 +36,6 @@
 #include "wpa.h"
 
 
-int ieee802_1x_send_data(struct hostapd_data *hapd, struct sta_info *sta,
-			 u8 *data, size_t data_len, int encrypt)
-{
-	struct ieee80211_hdr *hdr;
-	size_t len;
-	u8 *pos;
-	int res;
-
-	len = sizeof(*hdr) + sizeof(rfc1042_header) + 2 + data_len;
-	hdr = malloc(len);
-	if (hdr == NULL) {
-		printf("malloc() failed for hostapd_send_data(len=%d)\n", len);
-		return -1;
-	}
-
-	memset(hdr, 0, len);
-	hdr->frame_control =
-		IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
-	hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
-	/* Request TX callback */
-	hdr->frame_control |= host_to_le16(BIT(1));
-	if (encrypt)
-		hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
-	memcpy(hdr->IEEE80211_DA_FROMDS, sta->addr, ETH_ALEN);
-	memcpy(hdr->IEEE80211_BSSID_FROMDS, hapd->own_addr, ETH_ALEN);
-	memcpy(hdr->IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN);
-
-	pos = (u8 *) (hdr + 1);
-	memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
-	pos += sizeof(rfc1042_header);
-	*((u16 *) pos) = htons(ETH_P_PAE);
-	pos += 2;
-	memcpy(pos, data, data_len);
-
-	res = send(hapd->sock, (u8 *) hdr, len, 0);
-	free(hdr);
-
-	if (res < 0) {
-		perror("hostapd_send_data: send");
-		printf("hostapd_data_send - packet len: %d - failed\n", len);
-	}
-
-	return res;
-}
-
-
 static void ieee802_1x_send(hostapd *hapd, struct sta_info *sta, u8 type,
 			    u8 *data, size_t datalen)
 {
@@ -123,7 +77,9 @@
 	if (sta->flags & WLAN_STA_PREAUTH)
 		rsn_preauth_send(hapd, sta, buf, len);
 	else
-		ieee802_1x_send_data(hapd, sta, buf, len, encrypt);
+		if (hapd->driver.send_eapol)
+			hapd->driver.send_eapol(hapd->driver.data, sta->addr, buf,
+						len, encrypt);
 
 	free(buf);
 }
diff -Nur hostap/hostapd/ieee802_1x.h hostap.new/hostapd/ieee802_1x.h
--- hostap/hostapd/ieee802_1x.h	2004-06-04 06:20:46.000000000 +0200
+++ hostap.new/hostapd/ieee802_1x.h	2004-06-17 10:10:52.000000000 +0200
@@ -95,8 +95,6 @@
 void ieee802_1x_new_auth_session(hostapd *hapd, struct sta_info *sta);
 int ieee802_1x_tx_status(hostapd *hapd, struct sta_info *sta, u8 *buf,
 			 size_t len, int ack);
-int ieee802_1x_send_data(struct hostapd_data *hapd, struct sta_info *sta,
-			 u8 *data, size_t data_len, int encrypt);
 u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len);
 u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len);
 u8 * ieee802_1x_get_key_crypt(struct eapol_state_machine *sm, size_t *len);
diff -Nur hostap/hostapd/wpa.c hostap.new/hostapd/wpa.c
--- hostap/hostapd/wpa.c	2004-06-17 06:45:25.000000000 +0200
+++ hostap.new/hostapd/wpa.c	2004-06-17 10:15:59.000000000 +0200
@@ -1800,7 +1802,9 @@
 				       key->key_mic);
 	}
 
-	ieee802_1x_send_data(hapd, sta, (u8 *) hdr, len, sm->pairwise_set);
+	if (hapd->driver.send_eapol)
+		hapd->driver.send_eapol(hapd->driver.data, sta->addr, (u8 *) hdr,
+					len, sm->pairwise_set);
 	free(hdr);
 
 	timeout_ms = pairwise ? dot11RSNAConfigPairwiseUpdateTimeOut :



More information about the Hostap mailing list