PATCH: remove hostapd_ioctl() from driver independent part (part 1)

Gunter Burchardt gbur at informatik.uni-rostock.de
Fri Jul 30 05:12:09 EDT 2004


Hello,

This is the next part to seperate driver from hostapd functionality.
Goal of this patch is to remove hostapd_ioctl() from all driver
independent parts of hostapd. There are 2 new function (pointer) to
driver part:

 * add_sta - adds a station to the kernel
 * get_inact_sec - gets the inactivity time of a station

To finish this part i will add one function to driver:

 * set_assoc_ap - sets the associated ap address of hostapd if it is
   used in station mode (WDS)

regards
gunter
-------------- next part --------------
diff -Nur hostap.old/hostapd/driver.c hostap/hostapd/driver.c
--- hostap.old/hostapd/driver.c	2004-07-30 05:56:20.000000000 +0200
+++ hostap/hostapd/driver.c	2004-07-30 10:09:34.000000000 +0200
@@ -340,6 +340,26 @@
 }
 
 
+static int hostapd_add_sta(void *priv, u8 *addr, u16 aid, u16 capability,
+			    u8 tx_supp_rates)
+{
+	struct hostap_driver_data *drv = priv;
+	struct prism2_hostapd_param param;
+
+	memset(&param, 0, sizeof(param));
+	param.cmd = PRISM2_HOSTAPD_ADD_STA;
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+	param.u.add_sta.aid = aid;
+	param.u.add_sta.capability = capability;
+	param.u.add_sta.tx_supp_rates = tx_supp_rates;
+	if (hostapd_ioctl(drv, &param, sizeof(param))) {
+		return -1;
+	}
+
+	return 0;
+}
+
+
 static void hostapd_remove_sta(void *priv, u8 *addr)
 {
 	struct hostap_driver_data *drv = priv;
@@ -356,6 +376,22 @@
 }
 
 
+static int hostapd_get_inact_sec(void *priv, u8 *addr)
+{
+	struct hostap_driver_data *drv = priv;
+	struct prism2_hostapd_param param;
+
+	memset(&param, 0, sizeof(param));
+	param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+	if (hostapd_ioctl(drv, &param, sizeof(param))) {
+		return -1;
+	}
+
+	return param.u.get_info_sta.inactive_sec;
+}
+
+
 int hostapd_set_generic_elem(void *priv,
 			     const char *elem, size_t elem_len)
 {
@@ -619,6 +655,8 @@
 	hapd->driver.send_mgmt_frame = hostapd_send_mgmt_frame;
 	hapd->driver.read_sta_data = hostapd_read_sta_driver_data;
 	hapd->driver.remove_sta = hostapd_remove_sta;
+	hapd->driver.add_sta = hostapd_add_sta;
+	hapd->driver.get_inact_sec = hostapd_get_inact_sec;
 
 	return 0;
 }
@@ -633,6 +671,8 @@
 	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;
 
 	(void) hostapd_set_iface_flags(drv, 0);
 	(void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
diff -Nur hostap.old/hostapd/hostapd.h hostap/hostapd/hostapd.h
--- hostap.old/hostapd/hostapd.h	2004-07-30 05:56:20.000000000 +0200
+++ hostap/hostapd/hostapd.h	2004-07-30 10:07:55.000000000 +0200
@@ -53,6 +53,9 @@
 struct driver_info {
 	void *data; /* driver specific data - each driver can store data for
 		     * its own use in this pointer */
+	int (*get_inact_sec)(void *priv, u8 *addr);
+	int (*add_sta)(void *priv, u8 *addr, u16 aid, u16 capability,
+		       u8 tx_supp_rates);
 	void (*remove_sta)(void *priv, u8 *addr);
 	int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
 			     u8 *addr);
diff -Nur hostap.old/hostapd/ieee802_11.c hostap/hostapd/ieee802_11.c
--- hostap.old/hostapd/ieee802_11.c	2004-07-30 05:56:20.000000000 +0200
+++ hostap/hostapd/ieee802_11.c	2004-07-30 09:30:25.000000000 +0200
@@ -1096,7 +1096,6 @@
 			    size_t len, int reassoc, int ok)
 {
 	u16 status;
-	struct prism2_hostapd_param param;
 	struct sta_info *sta;
 	int new_assoc = 1;
 
@@ -1135,13 +1134,9 @@
 		new_assoc = 0;
 	sta->flags |= WLAN_STA_ASSOC;
 
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_ADD_STA;
-	memcpy(param.sta_addr, sta->addr, ETH_ALEN);
-	param.u.add_sta.aid = sta->aid;
-	param.u.add_sta.capability = sta->capability;
-	param.u.add_sta.tx_supp_rates = sta->tx_supp_rates;
-	if (hostapd_ioctl(hapd->driver.data, &param, sizeof(param))) {
+	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");
 	}
 
diff -Nur hostap.old/hostapd/sta_info.c hostap/hostapd/sta_info.c
--- hostap.old/hostapd/sta_info.c	2004-07-30 05:56:20.000000000 +0200
+++ hostap/hostapd/sta_info.c	2004-07-30 10:07:28.000000000 +0200
@@ -153,7 +153,7 @@
 	hostapd *hapd = eloop_ctx;
 	struct sta_info *sta = timeout_ctx;
 	unsigned long next_time = 0;
-	struct prism2_hostapd_param param;
+	int inactive_sec = 0;
 
 	if (sta->timeout_next == STA_REMOVE) {
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
@@ -166,22 +166,22 @@
 	HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
 		      "Checking STA " MACSTR " inactivity:\n",
 		      MAC2STR(sta->addr));
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
-	memcpy(param.sta_addr, sta->addr, ETH_ALEN);
-	if (hostapd_ioctl(hapd->driver.data, &param, sizeof(param))) {
+	if (hapd->driver.get_inact_sec)
+		inactive_sec =
+			hapd->driver.get_inact_sec(hapd->driver.data, sta->addr);
+
+	if (inactive_sec == -1) {
 		printf("  Could not get station info from kernel driver.\n");
 		/* assume the station has expired */
-		param.u.get_info_sta.inactive_sec = AP_MAX_INACTIVITY + 1;
+		inactive_sec = AP_MAX_INACTIVITY + 1;
 	}
 
-	if (param.u.get_info_sta.inactive_sec < AP_MAX_INACTIVITY) {
+	if (inactive_sec < AP_MAX_INACTIVITY) {
 		/* station activity detected; reset timeout state */
 		HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
 			      "  Station has been active\n");
 		sta->timeout_next = STA_NULLFUNC;
-		next_time = AP_MAX_INACTIVITY -
-			param.u.get_info_sta.inactive_sec;
+		next_time = AP_MAX_INACTIVITY - inactive_sec;
 	} else if (sta->timeout_next == STA_DISASSOC &&
 		   !(sta->flags & WLAN_STA_PENDING_POLL)) {
 		HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,


More information about the HostAP mailing list