3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
12 #include "utils/common.h"
13 #include "radius/radius_client.h"
14 #include "radius/radius_server.h"
15 #include "eapol_auth/eapol_auth_sm.h"
16 #include "eapol_auth/eapol_auth_sm_i.h"
17 #include "eap_server/eap.h"
18 #include "ap/hostapd.h"
19 #include "ap/ap_config.h"
20 #include "ap/sta_info.h"
21 #include "dump_state.h"
24 static void fprint_char(FILE *f
, char c
)
26 if (c
>= 32 && c
< 127)
29 fprintf(f
, "<%02x>", c
);
33 static void ieee802_1x_dump_state(FILE *f
, const char *prefix
,
36 struct eapol_state_machine
*sm
= sta
->eapol_sm
;
40 fprintf(f
, "%sIEEE 802.1X:\n", prefix
);
44 fprintf(f
, "%sidentity=", prefix
);
45 for (i
= 0; i
< sm
->identity_len
; i
++)
46 fprint_char(f
, sm
->identity
[i
]);
50 fprintf(f
, "%slast EAP type: Authentication Server: %d (%s) "
51 "Supplicant: %d (%s)\n", prefix
,
53 eap_server_get_name(0, sm
->eap_type_authsrv
),
54 sm
->eap_type_supp
, eap_server_get_name(0, sm
->eap_type_supp
));
56 fprintf(f
, "%scached_packets=%s\n", prefix
,
57 sm
->last_recv_radius
? "[RX RADIUS]" : "");
59 eapol_auth_dump_state(f
, prefix
, sm
);
64 * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
66 static void hostapd_dump_state(struct hostapd_data
*hapd
)
72 #ifndef CONFIG_NO_RADIUS
74 #endif /* CONFIG_NO_RADIUS */
76 if (!hapd
->conf
->dump_log_name
) {
77 wpa_printf(MSG_DEBUG
, "Dump file not defined - ignoring dump "
82 wpa_printf(MSG_DEBUG
, "Dumping hostapd state to '%s'",
83 hapd
->conf
->dump_log_name
);
84 f
= fopen(hapd
->conf
->dump_log_name
, "w");
86 wpa_printf(MSG_WARNING
, "Could not open dump file '%s' for "
87 "writing.", hapd
->conf
->dump_log_name
);
92 fprintf(f
, "hostapd state dump - %s", ctime(&now
));
93 fprintf(f
, "num_sta=%d num_sta_non_erp=%d "
94 "num_sta_no_short_slot_time=%d\n"
95 "num_sta_no_short_preamble=%d\n",
96 hapd
->num_sta
, hapd
->iface
->num_sta_non_erp
,
97 hapd
->iface
->num_sta_no_short_slot_time
,
98 hapd
->iface
->num_sta_no_short_preamble
);
100 for (sta
= hapd
->sta_list
; sta
!= NULL
; sta
= sta
->next
) {
101 fprintf(f
, "\nSTA=" MACSTR
"\n", MAC2STR(sta
->addr
));
104 " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
106 " capability=0x%x listen_interval=%d\n",
109 (sta
->flags
& WLAN_STA_AUTH
? "[AUTH]" : ""),
110 (sta
->flags
& WLAN_STA_ASSOC
? "[ASSOC]" : ""),
111 (sta
->flags
& WLAN_STA_PS
? "[PS]" : ""),
112 (sta
->flags
& WLAN_STA_TIM
? "[TIM]" : ""),
113 (sta
->flags
& WLAN_STA_PERM
? "[PERM]" : ""),
114 (ap_sta_is_authorized(sta
) ? "[AUTHORIZED]" : ""),
115 (sta
->flags
& WLAN_STA_PENDING_POLL
? "[PENDING_POLL" :
117 (sta
->flags
& WLAN_STA_SHORT_PREAMBLE
?
118 "[SHORT_PREAMBLE]" : ""),
119 (sta
->flags
& WLAN_STA_PREAUTH
? "[PREAUTH]" : ""),
120 (sta
->flags
& WLAN_STA_WMM
? "[WMM]" : ""),
121 (sta
->flags
& WLAN_STA_MFP
? "[MFP]" : ""),
122 (sta
->flags
& WLAN_STA_WPS
? "[WPS]" : ""),
123 (sta
->flags
& WLAN_STA_MAYBE_WPS
? "[MAYBE_WPS]" : ""),
124 (sta
->flags
& WLAN_STA_WDS
? "[WDS]" : ""),
125 (sta
->flags
& WLAN_STA_NONERP
? "[NonERP]" : ""),
126 (sta
->flags
& WLAN_STA_WPS2
? "[WPS2]" : ""),
128 sta
->listen_interval
);
130 fprintf(f
, " supported_rates=");
131 for (i
= 0; i
< sta
->supported_rates_len
; i
++)
132 fprintf(f
, "%02x ", sta
->supported_rates
[i
]);
136 " timeout_next=%s\n",
137 (sta
->timeout_next
== STA_NULLFUNC
? "NULLFUNC POLL" :
138 (sta
->timeout_next
== STA_DISASSOC
? "DISASSOC" :
141 ieee802_1x_dump_state(f
, " ", sta
);
144 #ifndef CONFIG_NO_RADIUS
145 buf
= os_malloc(4096);
147 int count
= radius_client_get_mib(hapd
->radius
, buf
, 4096);
150 else if (count
> 4095)
153 fprintf(f
, "%s", buf
);
156 count
= radius_server_get_mib(hapd
->radius_srv
, buf
, 4096);
159 else if (count
> 4095)
162 fprintf(f
, "%s", buf
);
163 #endif /* RADIUS_SERVER */
167 #endif /* CONFIG_NO_RADIUS */
172 int handle_dump_state_iface(struct hostapd_iface
*iface
, void *ctx
)
176 for (i
= 0; i
< iface
->num_bss
; i
++)
177 hostapd_dump_state(iface
->bss
[i
]);