remove @EAP_LDFLAGS@, no longer exists
[mech_eap.orig] / libeap / hostapd / dump_state.c
1 /*
2  * hostapd / State dump
3  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4  *
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.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "utils/includes.h"
16
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"
27
28
29 static void fprint_char(FILE *f, char c)
30 {
31         if (c >= 32 && c < 127)
32                 fprintf(f, "%c", c);
33         else
34                 fprintf(f, "<%02x>", c);
35 }
36
37
38 static void ieee802_1x_dump_state(FILE *f, const char *prefix,
39                                   struct sta_info *sta)
40 {
41         struct eapol_state_machine *sm = sta->eapol_sm;
42         if (sm == NULL)
43                 return;
44
45         fprintf(f, "%sIEEE 802.1X:\n", prefix);
46
47         if (sm->identity) {
48                 size_t i;
49                 fprintf(f, "%sidentity=", prefix);
50                 for (i = 0; i < sm->identity_len; i++)
51                         fprint_char(f, sm->identity[i]);
52                 fprintf(f, "\n");
53         }
54
55         fprintf(f, "%slast EAP type: Authentication Server: %d (%s) "
56                 "Supplicant: %d (%s)\n", prefix,
57                 sm->eap_type_authsrv,
58                 eap_server_get_name(0, sm->eap_type_authsrv),
59                 sm->eap_type_supp, eap_server_get_name(0, sm->eap_type_supp));
60
61         fprintf(f, "%scached_packets=%s\n", prefix,
62                 sm->last_recv_radius ? "[RX RADIUS]" : "");
63
64         eapol_auth_dump_state(f, prefix, sm);
65 }
66
67
68 /**
69  * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
70  */
71 static void hostapd_dump_state(struct hostapd_data *hapd)
72 {
73         FILE *f;
74         time_t now;
75         struct sta_info *sta;
76         int i;
77 #ifndef CONFIG_NO_RADIUS
78         char *buf;
79 #endif /* CONFIG_NO_RADIUS */
80
81         if (!hapd->conf->dump_log_name) {
82                 wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
83                            "request");
84                 return;
85         }
86
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");
90         if (f == NULL) {
91                 wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
92                            "writing.", hapd->conf->dump_log_name);
93                 return;
94         }
95
96         time(&now);
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);
104
105         for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
106                 fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
107
108                 fprintf(f,
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",
111                         sta->aid,
112                         sta->flags,
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]" :
119                          ""),
120                         (sta->flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
121                          ""),
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]" : ""),
131                         sta->capability,
132                         sta->listen_interval);
133
134                 fprintf(f, "  supported_rates=");
135                 for (i = 0; i < sta->supported_rates_len; i++)
136                         fprintf(f, "%02x ", sta->supported_rates[i]);
137                 fprintf(f, "\n");
138
139                 fprintf(f,
140                         "  timeout_next=%s\n",
141                         (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" :
142                          (sta->timeout_next == STA_DISASSOC ? "DISASSOC" :
143                           "DEAUTH")));
144
145                 ieee802_1x_dump_state(f, "  ", sta);
146         }
147
148 #ifndef CONFIG_NO_RADIUS
149         buf = os_malloc(4096);
150         if (buf) {
151                 int count = radius_client_get_mib(hapd->radius, buf, 4096);
152                 if (count < 0)
153                         count = 0;
154                 else if (count > 4095)
155                         count = 4095;
156                 buf[count] = '\0';
157                 fprintf(f, "%s", buf);
158
159 #ifdef RADIUS_SERVER
160                 count = radius_server_get_mib(hapd->radius_srv, buf, 4096);
161                 if (count < 0)
162                         count = 0;
163                 else if (count > 4095)
164                         count = 4095;
165                 buf[count] = '\0';
166                 fprintf(f, "%s", buf);
167 #endif /* RADIUS_SERVER */
168
169                 os_free(buf);
170         }
171 #endif /* CONFIG_NO_RADIUS */
172         fclose(f);
173 }
174
175
176 int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx)
177 {
178         size_t i;
179
180         for (i = 0; i < iface->num_bss; i++)
181                 hostapd_dump_state(iface->bss[i]);
182
183         return 0;
184 }