]> git.ipfire.org Git - thirdparty/hostap.git/blob - hostapd/dump_state.c
tests: Verify STA command output and EAPOL state
[thirdparty/hostap.git] / hostapd / dump_state.c
1 /*
2 * hostapd / State dump
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10 #include <time.h>
11
12 #include "utils/common.h"
13 #include "eapol_auth/eapol_auth_sm.h"
14 #include "eapol_auth/eapol_auth_sm_i.h"
15 #include "eap_server/eap.h"
16 #include "ap/hostapd.h"
17 #include "ap/ap_config.h"
18 #include "ap/sta_info.h"
19 #include "dump_state.h"
20 #include "ap/ap_drv_ops.h"
21
22
23 static void ieee802_1x_dump_state(FILE *f, struct sta_info *sta)
24 {
25 struct eapol_state_machine *sm = sta->eapol_sm;
26 char buf[4096];
27 int res;
28
29 if (sm == NULL)
30 return;
31 res = eapol_auth_dump_state(sm, buf, sizeof(buf));
32 if (res > 0)
33 fprintf(f, "%s", buf);
34 }
35
36
37 /**
38 * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
39 */
40 static void hostapd_dump_state(struct hostapd_data *hapd)
41 {
42 FILE *f;
43 time_t now;
44 struct sta_info *sta;
45
46 if (!hapd->conf->dump_log_name) {
47 wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
48 "request");
49 return;
50 }
51
52 wpa_printf(MSG_DEBUG, "Dumping hostapd state to '%s'",
53 hapd->conf->dump_log_name);
54 f = fopen(hapd->conf->dump_log_name, "w");
55 if (f == NULL) {
56 wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
57 "writing.", hapd->conf->dump_log_name);
58 return;
59 }
60
61 time(&now);
62 fprintf(f, "hostapd state dump - %s", ctime(&now));
63
64 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
65 fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
66 ieee802_1x_dump_state(f, sta);
67 }
68
69 fclose(f);
70 }
71
72
73 int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx)
74 {
75 size_t i;
76
77 for (i = 0; i < iface->num_bss; i++)
78 hostapd_dump_state(iface->bss[i]);
79
80 return 0;
81 }