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"
17 #include "utils/common.h"
18 #include "radius/radius_client.h"
19 #include "radius/radius_server.h"
20 #include "eapol_auth/eapol_auth_sm.h"
21 #include "eapol_auth/eapol_auth_sm_i.h"
22 #include "eap_server/eap.h"
23 #include "ap/hostapd.h"
24 #include "ap/ap_config.h"
25 #include "ap/sta_info.h"
26 #include "dump_state.h"
29 static void fprint_char(FILE *f
, char c
)
31 if (c
>= 32 && c
< 127)
34 fprintf(f
, "<%02x>", c
);
38 static void ieee802_1x_dump_state(FILE *f
, const char *prefix
,
41 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
45 fprintf(f
, "%sIEEE 802.1X:\n", prefix
);
49 fprintf(f
, "%sidentity=", prefix
);
50 for (i
= 0; i
< sm
->identity_len
; i
++)
51 fprint_char(f
, sm
->identity
[i
]);
55 fprintf(f
, "%slast EAP type: Authentication Server: %d (%s) "
56 "Supplicant: %d (%s)\n", prefix
,
58 eap_server_get_name(0, sm
->eap_type_authsrv
),
59 sm
->eap_type_supp
, eap_server_get_name(0, sm
->eap_type_supp
));
61 fprintf(f
, "%scached_packets=%s\n", prefix
,
62 sm
->last_recv_radius
? "[RX RADIUS]" : "");
64 eapol_auth_dump_state(f
, prefix
, sm
);
69 * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
71 static void hostapd_dump_state(struct hostapd_data
*hapd
)
77 #ifndef CONFIG_NO_RADIUS
79 #endif /* CONFIG_NO_RADIUS */
81 if (!hapd
->conf
->dump_log_name
) {
82 wpa_printf(MSG_DEBUG
, "Dump file not defined - ignoring dump "
87 wpa_printf(MSG_DEBUG
, "Dumping hostapd state to '%s'",
88 hapd
->conf
->dump_log_name
);
89 f
= fopen(hapd
->conf
->dump_log_name
, "w");
91 wpa_printf(MSG_WARNING
, "Could not open dump file '%s' for "
92 "writing.", hapd
->conf
->dump_log_name
);
97 fprintf(f
, "hostapd state dump - %s", ctime(&now
));
98 fprintf(f
, "num_sta=%d num_sta_non_erp=%d "
99 "num_sta_no_short_slot_time=%d\n"
100 "num_sta_no_short_preamble=%d\n",
101 hapd
->num_sta
, hapd
->iface
->num_sta_non_erp
,
102 hapd
->iface
->num_sta_no_short_slot_time
,
103 hapd
->iface
->num_sta_no_short_preamble
);
105 for (sta
= hapd
->sta_list
; sta
!= NULL
; sta
= sta
->next
) {
106 fprintf(f
, "\nSTA=" MACSTR
"\n", MAC2STR(sta
->addr
));
109 " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n"
110 " capability=0x%x listen_interval=%d\n",
113 (sta
->flags
& WLAN_STA_AUTH
? "[AUTH]" : ""),
114 (sta
->flags
& WLAN_STA_ASSOC
? "[ASSOC]" : ""),
115 (sta
->flags
& WLAN_STA_PS
? "[PS]" : ""),
116 (sta
->flags
& WLAN_STA_TIM
? "[TIM]" : ""),
117 (sta
->flags
& WLAN_STA_PERM
? "[PERM]" : ""),
118 (sta
->flags
& WLAN_STA_AUTHORIZED
? "[AUTHORIZED]" :
120 (sta
->flags
& WLAN_STA_PENDING_POLL
? "[PENDING_POLL" :
122 (sta
->flags
& WLAN_STA_SHORT_PREAMBLE
?
123 "[SHORT_PREAMBLE]" : ""),
124 (sta
->flags
& WLAN_STA_PREAUTH
? "[PREAUTH]" : ""),
125 (sta
->flags
& WLAN_STA_WMM
? "[WMM]" : ""),
126 (sta
->flags
& WLAN_STA_MFP
? "[MFP]" : ""),
127 (sta
->flags
& WLAN_STA_WPS
? "[WPS]" : ""),
128 (sta
->flags
& WLAN_STA_MAYBE_WPS
? "[MAYBE_WPS]" : ""),
129 (sta
->flags
& WLAN_STA_WDS
? "[WDS]" : ""),
130 (sta
->flags
& WLAN_STA_NONERP
? "[NonERP]" : ""),
132 sta
->listen_interval
);
134 fprintf(f
, " supported_rates=");
135 for (i
= 0; i
< sta
->supported_rates_len
; i
++)
136 fprintf(f
, "%02x ", sta
->supported_rates
[i
]);
140 " timeout_next=%s\n",
141 (sta
->timeout_next
== STA_NULLFUNC
? "NULLFUNC POLL" :
142 (sta
->timeout_next
== STA_DISASSOC
? "DISASSOC" :
145 ieee802_1x_dump_state(f
, " ", sta
);
148 #ifndef CONFIG_NO_RADIUS
149 buf
= os_malloc(4096);
151 int count
= radius_client_get_mib(hapd
->radius
, buf
, 4096);
154 else if (count
> 4095)
157 fprintf(f
, "%s", buf
);
160 count
= radius_server_get_mib(hapd
->radius_srv
, buf
, 4096);
163 else if (count
> 4095)
166 fprintf(f
, "%s", buf
);
167 #endif /* RADIUS_SERVER */
171 #endif /* CONFIG_NO_RADIUS */
176 int handle_dump_state_iface(struct hostapd_iface
*iface
, void *ctx
)
180 for (i
= 0; i
< iface
->num_bss
; i
++)
181 hostapd_dump_state(iface
->bss
[i
]);