[PATCH]: hostapd wired authenticator

Gunter Burchardt gbur at informatik.uni-rostock.de
Tue Sep 21 02:47:38 EDT 2004


Hello,

Here the patch to enable hostapd to work with kernel module i submitted
for some time.

Jouni, i had to include ioctrl specific stuff from a header file of the
kernel module (ieee802_1x_common.h). A aditional include path would be
fine if you found a location for the kernel module.

regards
gunter
-------------- next part --------------
diff -Nur hostap.old/hostapd/driver_wired.c hostap/hostapd/driver_wired.c
--- hostap.old/hostapd/driver_wired.c	2004-09-13 04:59:06.000000000 +0200
+++ hostap/hostapd/driver_wired.c	2004-09-21 08:39:33.000000000 +0200
@@ -21,10 +21,12 @@
 
 #ifdef USE_KERNEL_HEADERS
 #include <asm/types.h>
+#include <linux/if.h>
 #include <linux/if_packet.h>
 #include <linux/if_ether.h>   /* The L2 protocols */
 #include <linux/if_arp.h>
 #else /* USE_KERNEL_HEADERS */
+#include <net/if.h>
 #include <net/if_arp.h>
 #include <netpacket/packet.h>
 #endif /* USE_KERNEL_HEADERS */
@@ -35,6 +37,8 @@
 #include "eloop.h"
 #include "sta_info.h"
 
+#include "../ieee802_1x/modules/ieee802_1x_common.h"
+
 
 static int wired_send_eapol(void *priv, u8 *addr,
 			    u8 *data, size_t data_len, int encrypt)
@@ -73,6 +77,141 @@
 }
 
 
+static int drv_dev_ioctl(struct wired_driver_data *drv, 
+			 struct ieee802_1x_dev_param *param)
+{
+	struct ifreq req;
+
+	param->ifindex = drv->ifindex;
+	strcpy(req.ifr_name,IEEE802_1X_DEV_NAME);
+	req.ifr_data = (caddr_t)param;
+
+	if( ioctl(drv->sock, IEEE802_1X_DEV, &req ) < 0) {
+		printf("ioctl(IEEE802_1X_DEV)\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+
+static int drv_sta_ioctl(struct wired_driver_data *drv,
+			 struct ieee802_1x_sta_param *param)
+{
+	struct ifreq req;
+
+	param->ifindex = drv->ifindex;
+	strcpy(req.ifr_name,IEEE802_1X_DEV_NAME);
+	req.ifr_data = (caddr_t)param;
+
+	if( ioctl(drv->sock, IEEE802_1X_STA, &req ) < 0) {
+		printf("ioctl(IEEE802_1X_STA)\n");
+		return -1;
+	}
+	return 0;
+}
+
+
+static int wired_flush(void *priv) {
+	struct wired_driver_data *drv = priv;
+	struct ieee802_1x_dev_param param;
+
+	param.command = IEEE802_1X_DEV_FLUSH;
+
+	return drv_dev_ioctl(drv, &param);
+}
+
+
+static int wired_init_1x(void *priv) {
+	struct wired_driver_data *drv = priv;
+	struct ieee802_1x_dev_param param;
+
+	param.command = IEEE802_1X_DEV_ADD;
+
+	return drv_dev_ioctl(drv, &param);
+}
+
+static int wired_deinit_1x(struct wired_driver_data *drv) {
+	struct ieee802_1x_dev_param param;
+
+	param.command = IEEE802_1X_DEV_DEL;
+
+	return drv_dev_ioctl(drv, &param); 
+}
+
+
+static int wired_add_sta(void *priv, u8 *addr, u16 aid, u16 capability,
+			 u8 tx_supp_rates) {
+	struct wired_driver_data *drv = priv;
+	struct ieee802_1x_sta_param param;
+
+	param.command = IEEE802_1X_STA_ADD;
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+	
+	return drv_sta_ioctl(drv, &param);
+}
+ 
+
+static void wired_remove_sta(void *priv, u8 *addr) {
+	struct wired_driver_data *drv = priv;
+	struct ieee802_1x_sta_param param;
+
+	param.command = IEEE802_1X_STA_REMOVE;
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+
+	drv_sta_ioctl(drv, &param);
+}
+
+
+static int wired_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
+			       u8 *addr) {
+	struct wired_driver_data *drv = priv;
+	struct ieee802_1x_sta_param param;
+
+	param.command = IEEE802_1X_STA_GET_INFO;
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+
+	if (drv_sta_ioctl(drv, &param))
+		return -1;
+
+	data->rx_packets = param.u.get_info.rx_packets;
+	data->tx_packets = param.u.get_info.tx_packets;
+	data->rx_bytes = param.u.get_info.rx_bytes;
+	data->tx_bytes = param.u.get_info.tx_bytes;
+
+	return 0;
+}
+
+
+static int wired_get_inact_sec(void *priv, u8 *addr) {
+	struct wired_driver_data *drv = priv;
+	struct ieee802_1x_sta_param param;
+
+	param.command = IEEE802_1X_STA_GET_INFO;
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+
+	if (drv_sta_ioctl(drv, &param))
+		return -1;
+
+	return param.u.get_info.inactive_sec;
+}
+
+
+static void wired_set_sta_authorized(void *priv, u8 *addr, int authorized) {
+	struct wired_driver_data *drv = priv;
+	struct ieee802_1x_sta_param param;
+
+	if (authorized)
+		param.command = IEEE802_1X_STA_AUTHORIZE;
+	else
+		param.command = IEEE802_1X_STA_DEAUTHORIZE;
+
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+
+	drv_sta_ioctl(drv, &param);
+}
+
+
 int wired_driver_init(struct hostapd_data *hapd)
 {
 	struct wired_driver_data *drv;
@@ -90,18 +229,18 @@
 		return -1;
 
 	/* register callback functions */
-	hapd->driver.set_sta_authorized = NULL;
+	hapd->driver.set_sta_authorized = wired_set_sta_authorized;
 	hapd->driver.send_eapol = wired_send_eapol;
 	hapd->driver.send_mgmt_frame = NULL;
-	hapd->driver.read_sta_data = NULL;
-	hapd->driver.remove_sta = NULL;
-	hapd->driver.add_sta = NULL;
-	hapd->driver.get_inact_sec = NULL;
+	hapd->driver.read_sta_data = wired_read_sta_data;
+	hapd->driver.remove_sta = wired_remove_sta;
+	hapd->driver.add_sta = wired_add_sta;
+	hapd->driver.get_inact_sec = wired_get_inact_sec;
 	hapd->driver.set_assoc_ap = NULL;
-	hapd->driver.init_1x = NULL;
+	hapd->driver.init_1x = wired_init_1x;
 	hapd->driver.set_privacy_invoked = NULL;
 	hapd->driver.set_encryption = NULL;
-	hapd->driver.flush = NULL;
+	hapd->driver.flush = wired_flush;
 
 	return 0;
 }
@@ -124,6 +263,8 @@
 	hapd->driver.set_encryption = NULL;
 	hapd->driver.flush = NULL;
 
+	wired_deinit_1x(drv);
+	
 	if (drv->sock >= 0)
 		close(drv->sock);
 	
diff -Nur hostap.old/hostapd/driver_wired.h hostap/hostapd/driver_wired.h
--- hostap.old/hostapd/driver_wired.h	2004-09-13 04:59:06.000000000 +0200
+++ hostap/hostapd/driver_wired.h	2004-09-17 14:21:52.000000000 +0200
@@ -4,8 +4,11 @@
 int wired_driver_init(struct hostapd_data *hapd);
 void wired_driver_deinit(struct hostapd_data *hapd);
 
+#define IEEE802_1X_DEV_NAME "ieee802_1x"
+
 struct wired_driver_data {
 	struct hostapd_data *hapd;
+	int ifindex; /* index of device stas can associate */
 
 	int sock; /* raw packet socket for driver access */
 	int dhcp_sock; /* socket for dhcp packets */
diff -Nur hostap.old/hostapd/hostapd.c hostap/hostapd/hostapd.c
--- hostap.old/hostapd/hostapd.c	2004-09-13 04:59:06.000000000 +0200
+++ hostap/hostapd/hostapd.c	2004-09-20 09:14:51.000000000 +0200
@@ -366,6 +366,16 @@
 
 static void hostapd_cleanup_driver_wired(struct hostapd_data *hapd)
 {
+	accounting_deinit(hapd);
+	ieee802_1x_deinit(hapd);
+	radius_client_deinit(hapd);
+
+	wired_driver_deinit(hapd);
+
+	hostapd_config_free(hapd->conf);
+	hapd->conf = NULL;
+	
+	free(hapd->config_fname);
 }
 
 
diff -Nur hostap.old/hostapd/receive_wired.c hostap/hostapd/receive_wired.c
--- hostap.old/hostapd/receive_wired.c	2004-09-13 05:28:30.000000000 +0200
+++ hostap/hostapd/receive_wired.c	2004-09-20 09:31:40.000000000 +0200
@@ -72,6 +72,12 @@
 		      MACSTR " - adding a new STA\n", MAC2STR(addr));
 	sta = ap_sta_add(hapd, addr);
 	if (sta) {
+		if (hapd->driver.add_sta &&
+		    hapd->driver.add_sta(hapd->driver.data, sta->addr,
+					 sta->aid, sta->capability,
+					 sta->tx_supp_rates)) {
+			printf("Could not add station to kernel driver.\n");
+		}
 		hostapd_new_assoc_sta(hapd, sta);
 	} else {
 		HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "Failed to add STA entry "
@@ -195,6 +201,7 @@
 		return -1;
 	}
 
+	drv->ifindex = ifr.ifr_ifindex;
 	
 	memset(&addr, 0, sizeof(addr));
 	addr.sll_family = AF_PACKET;


More information about the HostAP mailing list