[PATCH]: clear station statistic on accounting start

Gunter Burchardt gbur
Thu Dec 2 05:22:53 PST 2004


Hi Jouni,

>    * new session id for the new session. */
>   accounting_sta_stop(hapd, sta);
>   accounting_sta_get_id(hapd, sta);
> 
> Generating a new sessionid is a great idea (i had a not submitted patch
> for my own doing this) but you missid one thing. You have to reset the
> accounting data in driver! At the moment it is only possible to do this
> by deleting the station from driver and readd the station. A new IOCTRL
> only reseting the stats would be fine. I have such an IOCTRL in
> PAE-module.

I have written a patch for clearing station stats on an accounting
start. This guaranties that no already accounted data will be send to
radius server. This patch is only a suggestion. I know your objections
against (new) IOCTRLs, but i think this is a usefull extension. 

regards
gunter
-------------- next part --------------
diff -Nur hostap.old/driver/modules/hostap_ap.c hostap/driver/modules/hostap_ap.c
--- hostap.old/driver/modules/hostap_ap.c	2004-07-18 01:34:23.000000000 +0200
+++ hostap/driver/modules/hostap_ap.c	2004-12-02 07:36:05.000000000 +0100
@@ -2587,6 +2587,31 @@
 }
 
 
+static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
+					  struct prism2_hostapd_param *param)
+{
+	struct sta_info *sta;
+	int rate;
+
+	spin_lock_bh(&ap->sta_table_lock);
+	sta = ap_get_sta(ap, param->sta_addr);
+	if (sta) {
+		sta->rx_packets = sta->tx_packets = 0;
+		sta->rx_bytes = sta->tx_bytes = 0;
+		for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
+			sta->tx_count[rate] = 0;
+			sta->rx_count[rate] = 0;
+		}
+	}
+	spin_unlock_bh(&ap->sta_table_lock);
+
+	if (!sta)
+		return -ENOENT;
+
+	return 0;
+}
+
+
 static int prism2_hostapd(struct ap_data *ap,
 			  struct prism2_hostapd_param *param)
 {
@@ -2602,6 +2627,8 @@
 		return prism2_hostapd_get_info_sta(ap, param);
 	case PRISM2_HOSTAPD_SET_FLAGS_STA:
 		return prism2_hostapd_set_flags_sta(ap, param);
+	case PRISM2_HOSTAPD_STA_CLEAR_STATS:
+		return prism2_hostapd_sta_clear_stats(ap, param);
 	default:
 		printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
 		       param->cmd);
diff -Nur hostap.old/driver/modules/hostap_common.h hostap/driver/modules/hostap_common.h
--- hostap.old/driver/modules/hostap_common.h	2004-04-04 06:37:39.000000000 +0200
+++ hostap/driver/modules/hostap_common.h	2004-12-02 06:18:28.000000000 +0100
@@ -482,6 +482,7 @@
 	PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
 	PRISM2_HOSTAPD_MLME = 13,
 	PRISM2_HOSTAPD_SCAN_REQ = 14,
+	PRISM2_HOSTAPD_STA_CLEAR_STATS = 15,
 };
 
 #define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
diff -Nur hostap.old/hostapd/accounting.c hostap/hostapd/accounting.c
--- hostap.old/hostapd/accounting.c	2004-11-30 08:45:21.000000000 +0100
+++ hostap/hostapd/accounting.c	2004-12-02 07:25:32.000000000 +0100
@@ -223,6 +223,7 @@
 	time(&sta->acct_session_start);
 	sta->last_rx_bytes = sta->last_tx_bytes = 0;
 	sta->acct_input_gigawords = sta->acct_output_gigawords = 0;
+	hostapd_sta_clear_stats(hapd, sta->addr);
 
 	if (!hapd->conf->acct_server)
 		return;
diff -Nur hostap.old/hostapd/driver.c hostap/hostapd/driver.c
--- hostap.old/hostapd/driver.c	2004-09-26 20:54:36.000000000 +0200
+++ hostap/hostapd/driver.c	2004-12-02 07:32:48.000000000 +0100
@@ -713,6 +713,21 @@
 }
 
 
+static int hostap_sta_clear_stats(void *priv, u8 *addr)
+{
+	struct hostap_driver_data *drv = priv;
+	struct prism2_hostapd_param param;
+
+	memset(&param, 0, sizeof(param));
+	param.cmd = PRISM2_HOSTAPD_STA_CLEAR_STATS;
+	memcpy(param.sta_addr, addr, ETH_ALEN);
+	if (hostapd_ioctl(drv, &param, sizeof(param))){
+		return -1;
+	}
+
+	return 0;
+}
+
 static int hostap_set_assoc_ap(void *priv, u8 *addr)
 {
 	struct hostap_driver_data *drv = priv;
@@ -1064,4 +1079,5 @@
 	.set_assoc_ap = hostap_set_assoc_ap,
 	.sta_add = hostap_sta_add,
 	.get_inact_sec = hostap_get_inact_sec,
+	.sta_clear_stats = hostap_sta_clear_stats,
 };
diff -Nur hostap.old/hostapd/driver.h hostap/hostapd/driver.h
--- hostap.old/hostapd/driver.h	2004-09-21 05:37:27.000000000 +0200
+++ hostap/hostapd/driver.h	2004-12-02 06:14:44.000000000 +0100
@@ -51,6 +51,7 @@
 	int (*sta_add)(void *priv, u8 *addr, u16 aid, u16 capability,
 		       u8 tx_supp_rates);
 	int (*get_inact_sec)(void *priv, u8 *addr);
+	int (*sta_clear_stats)(void *priv, u8 *addr);
 };
 
 static inline void
@@ -225,4 +226,12 @@
 	return hapd->driver->get_inact_sec(hapd->driver, addr);
 }
 
+static inline int
+hostapd_sta_clear_stats(struct hostapd_data *hapd, u8 *addr)
+{
+	if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
+		return 0;
+	return hapd->driver->sta_clear_stats(hapd->driver, addr);
+}
+
 #endif /* DRIVER_H */



More information about the Hostap mailing list