Patchwork [v2,1/2] Included session transfer stats (rx/tx packets/bytes) and duration into the station's "deauthentiation"-log message.

login
register
mail settings
Submitter Jan Vales
Date Jan. 2, 2013, 1:57 p.m.
Message ID <1357135026-8147-2-git-send-email-jan@jvales.net>
Download mbox | patch
Permalink /patch/209050/
State Under Review
Headers show

Comments

Jan Vales - Jan. 2, 2013, 1:57 p.m.
Signed-hostap: Jan Vales <jan@jvales.net>
---
 src/ap/ieee802_11.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
Jouni Malinen - Jan. 6, 2013, 6:35 p.m.
On Wed, Jan 02, 2013 at 02:57:05PM +0100, Jan Vales wrote:
> diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
> @@ -1374,8 +1376,21 @@ static void handle_deauth(struct hostapd_data *hapd,
>  	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
>  			WLAN_STA_ASSOC_REQ_OK);
>  	wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
> -	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
> -		       HOSTAPD_LEVEL_DEBUG, "deauthenticated");
> +
> +	if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) == 0) {

This does not look like the correct place to do this. This function is
called only if the station send Deauthentication frame to the AP. This
may not happen, i.e., the station may use Disassociation frame or just
go out of range from the AP without sending any frame. If this type of
log information is desired, I would assume it would be desired for all
different ways of a station getting disconnected. In other words, this
would need to be done in the same place as account_sta_stop().

I know you mentioned that you did not want to modify the RADIUS
accounting code for this, but that would likely be the best place for
doing this. This takes care of the counter wrapping and there is already
a hostapd_logger() call in accounting_sta_update_stats() for that
matter.

Patch

diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index 51c8d28..7809cc6 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -1351,6 +1351,8 @@  static void handle_deauth(struct hostapd_data *hapd,
 			  const struct ieee80211_mgmt *mgmt, size_t len)
 {
 	struct sta_info *sta;
+	struct hostap_sta_driver_data data;
+	struct os_time now;
 
 	if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
 		wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
@@ -1374,8 +1376,21 @@  static void handle_deauth(struct hostapd_data *hapd,
 	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
 			WLAN_STA_ASSOC_REQ_OK);
 	wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
-	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
-		       HOSTAPD_LEVEL_DEBUG, "deauthenticated");
+
+	if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) == 0) {
+		os_get_time(&now);
+		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+			HOSTAPD_LEVEL_INFO,
+			"deauthenticated. Stats: session=%08X-%08X; duration=%ld;"
+			"rx_pkt=%lu; tx_pkt=%lu; rx_byte=%lu; tx_byte=%lu;",
+			sta->acct_session_id_hi, sta->acct_session_id_lo,
+			(now.sec - sta->acct_session_start), data.rx_packets,
+			data.tx_packets, data.rx_bytes, data.tx_bytes);
+	} else {
+		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+			HOSTAPD_LEVEL_DEBUG, "deauthenticated");
+	}
+
 	mlme_deauthenticate_indication(
 		hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
 	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;