blob: 9357a467e7a79ca07183c132632d9bb906a1e727 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / RADIUS Accounting
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003 * Copyright (c) 2002-2009, 2012-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080013#include "eapol_auth/eapol_auth_sm.h"
14#include "eapol_auth/eapol_auth_sm_i.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070015#include "radius/radius.h"
16#include "radius/radius_client.h"
17#include "hostapd.h"
18#include "ieee802_1x.h"
19#include "ap_config.h"
20#include "sta_info.h"
21#include "ap_drv_ops.h"
22#include "accounting.h"
23
24
25/* Default interval in seconds for polling TX/RX octets from the driver if
26 * STA is not using interim accounting. This detects wrap arounds for
27 * input/output octets and updates Acct-{Input,Output}-Gigawords. */
28#define ACCT_DEFAULT_UPDATE_INTERVAL 300
29
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070030static void accounting_sta_interim(struct hostapd_data *hapd,
31 struct sta_info *sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032
33
34static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
35 struct sta_info *sta,
36 int status_type)
37{
38 struct radius_msg *msg;
39 char buf[128];
40 u8 *val;
41 size_t len;
42 int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -070043 struct wpabuf *b;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -080044 struct os_time now;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045
46 msg = radius_msg_new(RADIUS_CODE_ACCOUNTING_REQUEST,
47 radius_client_get_id(hapd->radius));
48 if (msg == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -080049 wpa_printf(MSG_INFO, "Could not create new RADIUS packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070050 return NULL;
51 }
52
Dmitry Shmidtb97e4282016-02-08 10:16:07 -080053 if (radius_msg_make_authenticator(msg) < 0) {
54 wpa_printf(MSG_INFO, "Could not make Request Authenticator");
55 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070056 }
57
58 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_STATUS_TYPE,
59 status_type)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -080060 wpa_printf(MSG_INFO, "Could not add Acct-Status-Type");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070061 goto fail;
62 }
63
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064 if (sta) {
Dmitry Shmidtb97e4282016-02-08 10:16:07 -080065 if (!hostapd_config_get_radius_attr(
66 hapd->conf->radius_acct_req_attr,
67 RADIUS_ATTR_ACCT_AUTHENTIC) &&
68 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_AUTHENTIC,
69 hapd->conf->ieee802_1x ?
70 RADIUS_ACCT_AUTHENTIC_RADIUS :
71 RADIUS_ACCT_AUTHENTIC_LOCAL)) {
72 wpa_printf(MSG_INFO, "Could not add Acct-Authentic");
73 goto fail;
74 }
75
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070076 /* Use 802.1X identity if available */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077 val = ieee802_1x_get_identity(sta->eapol_sm, &len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070078
79 /* Use RADIUS ACL identity if 802.1X provides no identity */
80 if (!val && sta->identity) {
81 val = (u8 *) sta->identity;
82 len = os_strlen(sta->identity);
83 }
84
85 /* Use STA MAC if neither 802.1X nor RADIUS ACL provided
86 * identity */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087 if (!val) {
88 os_snprintf(buf, sizeof(buf), RADIUS_ADDR_FORMAT,
89 MAC2STR(sta->addr));
90 val = (u8 *) buf;
91 len = os_strlen(buf);
92 }
93
94 if (!radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME, val,
95 len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -080096 wpa_printf(MSG_INFO, "Could not add User-Name");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 goto fail;
98 }
99 }
100
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700101 if (add_common_radius_attr(hapd, hapd->conf->radius_acct_req_attr, sta,
102 msg) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104
105 if (sta) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106 for (i = 0; ; i++) {
107 val = ieee802_1x_get_radius_class(sta->eapol_sm, &len,
108 i);
109 if (val == NULL)
110 break;
111
112 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CLASS,
113 val, len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800114 wpa_printf(MSG_INFO, "Could not add Class");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700115 goto fail;
116 }
117 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700118
119 b = ieee802_1x_get_radius_cui(sta->eapol_sm);
120 if (b &&
121 !radius_msg_add_attr(msg,
122 RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
123 wpabuf_head(b), wpabuf_len(b))) {
124 wpa_printf(MSG_ERROR, "Could not add CUI");
125 goto fail;
126 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700127
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700128 if (!b && sta->radius_cui &&
129 !radius_msg_add_attr(msg,
130 RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
131 (u8 *) sta->radius_cui,
132 os_strlen(sta->radius_cui))) {
133 wpa_printf(MSG_ERROR, "Could not add CUI from ACL");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700134 goto fail;
135 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800136
137 if (sta->ipaddr &&
138 !radius_msg_add_attr_int32(msg,
139 RADIUS_ATTR_FRAMED_IP_ADDRESS,
140 be_to_host32(sta->ipaddr))) {
141 wpa_printf(MSG_ERROR,
142 "Could not add Framed-IP-Address");
143 goto fail;
144 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145 }
146
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800147 os_get_time(&now);
148 if (now.sec > 1000000000 &&
149 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_EVENT_TIMESTAMP,
150 now.sec)) {
151 wpa_printf(MSG_INFO, "Could not add Event-Timestamp");
152 goto fail;
153 }
154
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700155 return msg;
156
157 fail:
158 radius_msg_free(msg);
159 return NULL;
160}
161
162
163static int accounting_sta_update_stats(struct hostapd_data *hapd,
164 struct sta_info *sta,
165 struct hostap_sta_driver_data *data)
166{
167 if (hostapd_drv_read_sta_data(hapd, data, sta->addr))
168 return -1;
169
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800170 if (!data->bytes_64bit) {
171 /* Extend 32-bit counters from the driver to 64-bit counters */
172 if (sta->last_rx_bytes_lo > data->rx_bytes)
173 sta->last_rx_bytes_hi++;
174 sta->last_rx_bytes_lo = data->rx_bytes;
175
176 if (sta->last_tx_bytes_lo > data->tx_bytes)
177 sta->last_tx_bytes_hi++;
178 sta->last_tx_bytes_lo = data->tx_bytes;
179 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180
181 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800182 HOSTAPD_LEVEL_DEBUG,
183 "updated TX/RX stats: rx_bytes=%llu [%u:%u] tx_bytes=%llu [%u:%u] bytes_64bit=%d",
184 data->rx_bytes, sta->last_rx_bytes_hi,
185 sta->last_rx_bytes_lo,
186 data->tx_bytes, sta->last_tx_bytes_hi,
187 sta->last_tx_bytes_lo,
188 data->bytes_64bit);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189
190 return 0;
191}
192
193
194static void accounting_interim_update(void *eloop_ctx, void *timeout_ctx)
195{
196 struct hostapd_data *hapd = eloop_ctx;
197 struct sta_info *sta = timeout_ctx;
198 int interval;
199
200 if (sta->acct_interim_interval) {
201 accounting_sta_interim(hapd, sta);
202 interval = sta->acct_interim_interval;
203 } else {
204 struct hostap_sta_driver_data data;
205 accounting_sta_update_stats(hapd, sta, &data);
206 interval = ACCT_DEFAULT_UPDATE_INTERVAL;
207 }
208
209 eloop_register_timeout(interval, 0, accounting_interim_update,
210 hapd, sta);
211}
212
213
214/**
215 * accounting_sta_start - Start STA accounting
216 * @hapd: hostapd BSS data
217 * @sta: The station
218 */
219void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
220{
221 struct radius_msg *msg;
222 int interval;
223
224 if (sta->acct_session_started)
225 return;
226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
228 HOSTAPD_LEVEL_INFO,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800229 "starting accounting session %016llX",
230 (unsigned long long) sta->acct_session_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700231
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800232 os_get_reltime(&sta->acct_session_start);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800233 sta->last_rx_bytes_hi = 0;
234 sta->last_rx_bytes_lo = 0;
235 sta->last_tx_bytes_hi = 0;
236 sta->last_tx_bytes_lo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237 hostapd_drv_sta_clear_stats(hapd, sta->addr);
238
239 if (!hapd->conf->radius->acct_server)
240 return;
241
242 if (sta->acct_interim_interval)
243 interval = sta->acct_interim_interval;
244 else
245 interval = ACCT_DEFAULT_UPDATE_INTERVAL;
246 eloop_register_timeout(interval, 0, accounting_interim_update,
247 hapd, sta);
248
249 msg = accounting_msg(hapd, sta, RADIUS_ACCT_STATUS_TYPE_START);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700250 if (msg &&
251 radius_client_send(hapd->radius, msg, RADIUS_ACCT, sta->addr) < 0)
252 radius_msg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253
254 sta->acct_session_started = 1;
255}
256
257
258static void accounting_sta_report(struct hostapd_data *hapd,
259 struct sta_info *sta, int stop)
260{
261 struct radius_msg *msg;
262 int cause = sta->acct_terminate_cause;
263 struct hostap_sta_driver_data data;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800264 struct os_reltime now_r, diff;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800265 u64 bytes;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700266
267 if (!hapd->conf->radius->acct_server)
268 return;
269
270 msg = accounting_msg(hapd, sta,
271 stop ? RADIUS_ACCT_STATUS_TYPE_STOP :
272 RADIUS_ACCT_STATUS_TYPE_INTERIM_UPDATE);
273 if (!msg) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800274 wpa_printf(MSG_INFO, "Could not create RADIUS Accounting message");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275 return;
276 }
277
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800278 os_get_reltime(&now_r);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800279 os_reltime_sub(&now_r, &sta->acct_session_start, &diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_SESSION_TIME,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800281 diff.sec)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800282 wpa_printf(MSG_INFO, "Could not add Acct-Session-Time");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283 goto fail;
284 }
285
286 if (accounting_sta_update_stats(hapd, sta, &data) == 0) {
287 if (!radius_msg_add_attr_int32(msg,
288 RADIUS_ATTR_ACCT_INPUT_PACKETS,
289 data.rx_packets)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800290 wpa_printf(MSG_INFO, "Could not add Acct-Input-Packets");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291 goto fail;
292 }
293 if (!radius_msg_add_attr_int32(msg,
294 RADIUS_ATTR_ACCT_OUTPUT_PACKETS,
295 data.tx_packets)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800296 wpa_printf(MSG_INFO, "Could not add Acct-Output-Packets");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297 goto fail;
298 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800299 if (data.bytes_64bit)
300 bytes = data.rx_bytes;
301 else
302 bytes = ((u64) sta->last_rx_bytes_hi << 32) |
303 sta->last_rx_bytes_lo;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 if (!radius_msg_add_attr_int32(msg,
305 RADIUS_ATTR_ACCT_INPUT_OCTETS,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800306 (u32) bytes)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800307 wpa_printf(MSG_INFO, "Could not add Acct-Input-Octets");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308 goto fail;
309 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800310 if (!radius_msg_add_attr_int32(msg,
311 RADIUS_ATTR_ACCT_INPUT_GIGAWORDS,
312 (u32) (bytes >> 32))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800313 wpa_printf(MSG_INFO, "Could not add Acct-Input-Gigawords");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314 goto fail;
315 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800316 if (data.bytes_64bit)
317 bytes = data.tx_bytes;
318 else
319 bytes = ((u64) sta->last_tx_bytes_hi << 32) |
320 sta->last_tx_bytes_lo;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 if (!radius_msg_add_attr_int32(msg,
322 RADIUS_ATTR_ACCT_OUTPUT_OCTETS,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800323 (u32) bytes)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800324 wpa_printf(MSG_INFO, "Could not add Acct-Output-Octets");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325 goto fail;
326 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800327 if (!radius_msg_add_attr_int32(msg,
328 RADIUS_ATTR_ACCT_OUTPUT_GIGAWORDS,
329 (u32) (bytes >> 32))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800330 wpa_printf(MSG_INFO, "Could not add Acct-Output-Gigawords");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331 goto fail;
332 }
333 }
334
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 if (eloop_terminated())
336 cause = RADIUS_ACCT_TERMINATE_CAUSE_ADMIN_REBOOT;
337
338 if (stop && cause &&
339 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_TERMINATE_CAUSE,
340 cause)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800341 wpa_printf(MSG_INFO, "Could not add Acct-Terminate-Cause");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342 goto fail;
343 }
344
Dmitry Shmidt04949592012-07-19 12:16:46 -0700345 if (radius_client_send(hapd->radius, msg,
346 stop ? RADIUS_ACCT : RADIUS_ACCT_INTERIM,
347 sta->addr) < 0)
348 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700349 return;
350
351 fail:
352 radius_msg_free(msg);
353}
354
355
356/**
357 * accounting_sta_interim - Send a interim STA accounting report
358 * @hapd: hostapd BSS data
359 * @sta: The station
360 */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700361static void accounting_sta_interim(struct hostapd_data *hapd,
362 struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363{
364 if (sta->acct_session_started)
365 accounting_sta_report(hapd, sta, 0);
366}
367
368
369/**
370 * accounting_sta_stop - Stop STA accounting
371 * @hapd: hostapd BSS data
372 * @sta: The station
373 */
374void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta)
375{
376 if (sta->acct_session_started) {
377 accounting_sta_report(hapd, sta, 1);
378 eloop_cancel_timeout(accounting_interim_update, hapd, sta);
379 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
380 HOSTAPD_LEVEL_INFO,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800381 "stopped accounting session %016llX",
382 (unsigned long long) sta->acct_session_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700383 sta->acct_session_started = 0;
384 }
385}
386
387
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800388int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700389{
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800390 return radius_gen_session_id((u8 *) &sta->acct_session_id,
391 sizeof(sta->acct_session_id));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392}
393
394
395/**
396 * accounting_receive - Process the RADIUS frames from Accounting Server
397 * @msg: RADIUS response message
398 * @req: RADIUS request message
399 * @shared_secret: RADIUS shared secret
400 * @shared_secret_len: Length of shared_secret in octets
401 * @data: Context data (struct hostapd_data *)
402 * Returns: Processing status
403 */
404static RadiusRxResult
405accounting_receive(struct radius_msg *msg, struct radius_msg *req,
406 const u8 *shared_secret, size_t shared_secret_len,
407 void *data)
408{
409 if (radius_msg_get_hdr(msg)->code != RADIUS_CODE_ACCOUNTING_RESPONSE) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800410 wpa_printf(MSG_INFO, "Unknown RADIUS message code");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 return RADIUS_RX_UNKNOWN;
412 }
413
414 if (radius_msg_verify(msg, shared_secret, shared_secret_len, req, 0)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800415 wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have correct Authenticator - dropped");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 return RADIUS_RX_INVALID_AUTHENTICATOR;
417 }
418
419 return RADIUS_RX_PROCESSED;
420}
421
422
423static void accounting_report_state(struct hostapd_data *hapd, int on)
424{
425 struct radius_msg *msg;
426
427 if (!hapd->conf->radius->acct_server || hapd->radius == NULL)
428 return;
429
430 /* Inform RADIUS server that accounting will start/stop so that the
431 * server can close old accounting sessions. */
432 msg = accounting_msg(hapd, NULL,
433 on ? RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_ON :
434 RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF);
435 if (!msg)
436 return;
437
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800438 if (hapd->acct_session_id) {
439 char buf[20];
440
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800441 os_snprintf(buf, sizeof(buf), "%016llX",
442 (unsigned long long) hapd->acct_session_id);
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800443 if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
444 (u8 *) buf, os_strlen(buf)))
445 wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 }
447
Dmitry Shmidt04949592012-07-19 12:16:46 -0700448 if (radius_client_send(hapd->radius, msg, RADIUS_ACCT, NULL) < 0)
449 radius_msg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700450}
451
452
453/**
454 * accounting_init: Initialize accounting
455 * @hapd: hostapd BSS data
456 * Returns: 0 on success, -1 on failure
457 */
458int accounting_init(struct hostapd_data *hapd)
459{
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800460 if (radius_gen_session_id((u8 *) &hapd->acct_session_id,
461 sizeof(hapd->acct_session_id)) < 0)
462 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463
464 if (radius_client_register(hapd->radius, RADIUS_ACCT,
465 accounting_receive, hapd))
466 return -1;
467
468 accounting_report_state(hapd, 1);
469
470 return 0;
471}
472
473
474/**
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700475 * accounting_deinit: Deinitialize accounting
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476 * @hapd: hostapd BSS data
477 */
478void accounting_deinit(struct hostapd_data *hapd)
479{
480 accounting_report_state(hapd, 0);
481}