Remove direct driver calls from vlan_init.c
[libeap.git] / hostapd / accounting.c
index d49c765..12678bc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * hostapd / RADIUS Accounting
- * Copyright (c) 2002-2008, 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
@@ -175,7 +178,6 @@ static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
 
  fail:
        radius_msg_free(msg);
-       os_free(msg);
        return NULL;
 }
 
@@ -184,7 +186,7 @@ static int accounting_sta_update_stats(struct hostapd_data *hapd,
                                       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)
@@ -225,6 +227,11 @@ static void accounting_interim_update(void *eloop_ctx, void *timeout_ctx)
 }
 
 
+/**
+ * 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;
@@ -242,7 +249,7 @@ void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
        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;
@@ -359,10 +366,14 @@ static void accounting_sta_report(struct hostapd_data *hapd,
 
  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)
@@ -370,6 +381,11 @@ void accounting_sta_interim(struct hostapd_data *hapd, struct sta_info *sta)
 }
 
 
+/**
+ * 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) {
@@ -396,12 +412,21 @@ static void accounting_sta_get_id(struct hostapd_data *hapd,
 }
 
 
-/* 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;
        }
@@ -436,7 +461,6 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
        {
                printf("Could not add Acct-Terminate-Cause\n");
                radius_msg_free(msg);
-               os_free(msg);
                return;
        }
 
@@ -444,6 +468,11 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
 }
 
 
+/**
+ * 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
@@ -460,18 +489,11 @@ int accounting_init(struct hostapd_data *hapd)
 }
 
 
+/**
+ * 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);
-}