3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
18 #include "utils/common.h"
19 #include "radius/radius_client.h"
20 #include "radius/radius_server.h"
21 #include "eapol_auth/eapol_auth_sm.h"
22 #include "eapol_auth/eapol_auth_sm_i.h"
23 #include "eap_server/eap.h"
24 #include "ap/hostapd.h"
25 #include "ap/ap_config.h"
26 #include "ap/sta_info.h"
27 #include "dump_state.h"
30 static void fprint_char(FILE *f, char c)
32 if (c >= 32 && c < 127)
35 fprintf(f, "<%02x>", c);
39 static void ieee802_1x_dump_state(FILE *f, const char *prefix,
42 struct eapol_state_machine *sm = sta->eapol_sm;
46 fprintf(f, "%sIEEE 802.1X:\n", prefix);
50 fprintf(f, "%sidentity=", prefix);
51 for (i = 0; i < sm->identity_len; i++)
52 fprint_char(f, sm->identity[i]);
56 fprintf(f, "%slast EAP type: Authentication Server: %d (%s) "
57 "Supplicant: %d (%s)\n", prefix,
59 eap_server_get_name(0, sm->eap_type_authsrv),
60 sm->eap_type_supp, eap_server_get_name(0, sm->eap_type_supp));
62 fprintf(f, "%scached_packets=%s\n", prefix,
63 sm->last_recv_radius ? "[RX RADIUS]" : "");
65 eapol_auth_dump_state(f, prefix, sm);
70 * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
72 static void hostapd_dump_state(struct hostapd_data *hapd)
78 #ifndef CONFIG_NO_RADIUS
80 #endif /* CONFIG_NO_RADIUS */
82 if (!hapd->conf->dump_log_name) {
83 wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
88 wpa_printf(MSG_DEBUG, "Dumping hostapd state to '%s'",
89 hapd->conf->dump_log_name);
90 f = fopen(hapd->conf->dump_log_name, "w");
92 wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
93 "writing.", hapd->conf->dump_log_name);
98 fprintf(f, "hostapd state dump - %s", ctime(&now));
99 fprintf(f, "num_sta=%d num_sta_non_erp=%d "
100 "num_sta_no_short_slot_time=%d\n"
101 "num_sta_no_short_preamble=%d\n",
102 hapd->num_sta, hapd->iface->num_sta_non_erp,
103 hapd->iface->num_sta_no_short_slot_time,
104 hapd->iface->num_sta_no_short_preamble);
106 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
107 fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
110 " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
112 " capability=0x%x listen_interval=%d\n",
115 (sta->flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
116 (sta->flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
117 (sta->flags & WLAN_STA_PS ? "[PS]" : ""),
118 (sta->flags & WLAN_STA_TIM ? "[TIM]" : ""),
119 (sta->flags & WLAN_STA_PERM ? "[PERM]" : ""),
120 (ap_sta_is_authorized(sta) ? "[AUTHORIZED]" : ""),
121 (sta->flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
123 (sta->flags & WLAN_STA_SHORT_PREAMBLE ?
124 "[SHORT_PREAMBLE]" : ""),
125 (sta->flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
126 (sta->flags & WLAN_STA_WMM ? "[WMM]" : ""),
127 (sta->flags & WLAN_STA_MFP ? "[MFP]" : ""),
128 (sta->flags & WLAN_STA_WPS ? "[WPS]" : ""),
129 (sta->flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
130 (sta->flags & WLAN_STA_WDS ? "[WDS]" : ""),
131 (sta->flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
132 (sta->flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
134 sta->listen_interval);
136 fprintf(f, " supported_rates=");
137 for (i = 0; i < sta->supported_rates_len; i++)
138 fprintf(f, "%02x ", sta->supported_rates[i]);
142 " timeout_next=%s\n",
143 (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" :
144 (sta->timeout_next == STA_DISASSOC ? "DISASSOC" :
147 ieee802_1x_dump_state(f, " ", sta);
150 #ifndef CONFIG_NO_RADIUS
151 buf = os_malloc(4096);
153 int count = radius_client_get_mib(hapd->radius, buf, 4096);
156 else if (count > 4095)
159 fprintf(f, "%s", buf);
162 count = radius_server_get_mib(hapd->radius_srv, buf, 4096);
165 else if (count > 4095)
168 fprintf(f, "%s", buf);
169 #endif /* RADIUS_SERVER */
173 #endif /* CONFIG_NO_RADIUS */
178 int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx)
182 for (i = 0; i < iface->num_bss; i++)
183 hostapd_dump_state(iface->bss[i]);