/*
* hostapd / RADIUS Accounting
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include "includes.h"
+#include "common.h"
#include "hostapd.h"
+#include "drivers/driver.h"
#include "radius/radius.h"
#include "radius/radius_client.h"
#include "eloop.h"
#include "accounting.h"
#include "ieee802_1x.h"
-#include "driver.h"
+#include "config.h"
+#include "sta_info.h"
/* Default interval in seconds for polling TX/RX octets from the driver if
* input/output octets and updates Acct-{Input,Output}-Gigawords. */
#define ACCT_DEFAULT_UPDATE_INTERVAL 300
-/* from ieee802_1x.c */
-const char *radius_mode_txt(struct hostapd_data *hapd);
-int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta);
+static void accounting_sta_get_id(struct hostapd_data *hapd,
+ struct sta_info *sta);
static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
fail:
radius_msg_free(msg);
- os_free(msg);
return NULL;
}
struct sta_info *sta,
struct hostap_sta_driver_data *data)
{
- if (hostapd_read_sta_data(hapd, data, sta->addr))
+ if (hapd->drv.read_sta_data(hapd, data, sta->addr))
return -1;
if (sta->last_rx_bytes > data->rx_bytes)
}
+/**
+ * accounting_sta_start - Start STA accounting
+ * @hapd: hostapd BSS data
+ * @sta: The station
+ */
void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
{
struct radius_msg *msg;
if (sta->acct_session_started)
return;
+ accounting_sta_get_id(hapd, sta);
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
+ HOSTAPD_LEVEL_INFO,
+ "starting accounting session %08X-%08X",
+ sta->acct_session_id_hi, sta->acct_session_id_lo);
+
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);
+ hapd->drv.sta_clear_stats(hapd, sta->addr);
if (!hapd->conf->radius->acct_server)
return;
}
-void accounting_sta_report(struct hostapd_data *hapd, struct sta_info *sta,
- int stop)
+static void accounting_sta_report(struct hostapd_data *hapd,
+ struct sta_info *sta, int stop)
{
struct radius_msg *msg;
int cause = sta->acct_terminate_cause;
fail:
radius_msg_free(msg);
- os_free(msg);
}
+/**
+ * accounting_sta_interim - Send a interim STA accounting report
+ * @hapd: hostapd BSS data
+ * @sta: The station
+ */
void accounting_sta_interim(struct hostapd_data *hapd, struct sta_info *sta)
{
if (sta->acct_session_started)
}
+/**
+ * accounting_sta_stop - Stop STA accounting
+ * @hapd: hostapd BSS data
+ * @sta: The station
+ */
void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta)
{
if (sta->acct_session_started) {
accounting_sta_report(hapd, sta, 1);
eloop_cancel_timeout(accounting_interim_update, hapd, sta);
+ hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
+ HOSTAPD_LEVEL_INFO,
+ "stopped accounting session %08X-%08X",
+ sta->acct_session_id_hi,
+ sta->acct_session_id_lo);
sta->acct_session_started = 0;
}
}
-void accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta)
+static void accounting_sta_get_id(struct hostapd_data *hapd,
+ struct sta_info *sta)
{
sta->acct_session_id_lo = hapd->acct_session_id_lo++;
if (hapd->acct_session_id_lo == 0) {
}
-/* Process the RADIUS frames from Accounting Server */
+/**
+ * accounting_receive - Process the RADIUS frames from Accounting Server
+ * @msg: RADIUS response message
+ * @req: RADIUS request message
+ * @shared_secret: RADIUS shared secret
+ * @shared_secret_len: Length of shared_secret in octets
+ * @data: Context data (struct hostapd_data *)
+ * Returns: Processing status
+ */
static RadiusRxResult
accounting_receive(struct radius_msg *msg, struct radius_msg *req,
- u8 *shared_secret, size_t shared_secret_len, void *data)
+ const u8 *shared_secret, size_t shared_secret_len,
+ void *data)
{
- if (msg->hdr->code != RADIUS_CODE_ACCOUNTING_RESPONSE) {
+ if (radius_msg_get_hdr(msg)->code != RADIUS_CODE_ACCOUNTING_RESPONSE) {
printf("Unknown RADIUS message code\n");
return RADIUS_RX_UNKNOWN;
}
{
printf("Could not add Acct-Terminate-Cause\n");
radius_msg_free(msg);
- os_free(msg);
return;
}
}
+/**
+ * accounting_init: Initialize accounting
+ * @hapd: hostapd BSS data
+ * Returns: 0 on success, -1 on failure
+ */
int accounting_init(struct hostapd_data *hapd)
{
/* Acct-Session-Id should be unique over reboots. If reliable clock is
}
+/**
+ * accounting_deinit: Deinitilize accounting
+ * @hapd: hostapd BSS data
+ */
void accounting_deinit(struct hostapd_data *hapd)
{
accounting_report_state(hapd, 0);
}
-
-
-int accounting_reconfig(struct hostapd_data *hapd,
- struct hostapd_config *oldconf)
-{
- if (!hapd->radius_client_reconfigured)
- return 0;
-
- accounting_deinit(hapd);
- return accounting_init(hapd);
-}