]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/wpa/hostapd/dump_state.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / wpa / 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 "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"
22
23
24 static void fprint_char(FILE *f, char c)
25 {
26         if (c >= 32 && c < 127)
27                 fprintf(f, "%c", c);
28         else
29                 fprintf(f, "<%02x>", c);
30 }
31
32
33 static void ieee802_1x_dump_state(FILE *f, const char *prefix,
34                                   struct sta_info *sta)
35 {
36         struct eapol_state_machine *sm = sta->eapol_sm;
37         if (sm == NULL)
38                 return;
39
40         fprintf(f, "%sIEEE 802.1X:\n", prefix);
41
42         if (sm->identity) {
43                 size_t i;
44                 fprintf(f, "%sidentity=", prefix);
45                 for (i = 0; i < sm->identity_len; i++)
46                         fprint_char(f, sm->identity[i]);
47                 fprintf(f, "\n");
48         }
49
50         fprintf(f, "%slast EAP type: Authentication Server: %d (%s) "
51                 "Supplicant: %d (%s)\n", prefix,
52                 sm->eap_type_authsrv,
53                 eap_server_get_name(0, sm->eap_type_authsrv),
54                 sm->eap_type_supp, eap_server_get_name(0, sm->eap_type_supp));
55
56         fprintf(f, "%scached_packets=%s\n", prefix,
57                 sm->last_recv_radius ? "[RX RADIUS]" : "");
58
59         eapol_auth_dump_state(f, prefix, sm);
60 }
61
62
63 /**
64  * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
65  */
66 static void hostapd_dump_state(struct hostapd_data *hapd)
67 {
68         FILE *f;
69         time_t now;
70         struct sta_info *sta;
71         int i;
72 #ifndef CONFIG_NO_RADIUS
73         char *buf;
74 #endif /* CONFIG_NO_RADIUS */
75
76         if (!hapd->conf->dump_log_name) {
77                 wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
78                            "request");
79                 return;
80         }
81
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");
85         if (f == NULL) {
86                 wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
87                            "writing.", hapd->conf->dump_log_name);
88                 return;
89         }
90
91         time(&now);
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);
99
100         for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
101                 fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
102
103                 fprintf(f,
104                         "  AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
105                         "\n"
106                         "  capability=0x%x listen_interval=%d\n",
107                         sta->aid,
108                         sta->flags,
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" :
116                          ""),
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]" : ""),
127                         sta->capability,
128                         sta->listen_interval);
129
130                 fprintf(f, "  supported_rates=");
131                 for (i = 0; i < sta->supported_rates_len; i++)
132                         fprintf(f, "%02x ", sta->supported_rates[i]);
133                 fprintf(f, "\n");
134
135                 fprintf(f,
136                         "  timeout_next=%s\n",
137                         (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" :
138                          (sta->timeout_next == STA_DISASSOC ? "DISASSOC" :
139                           "DEAUTH")));
140
141                 ieee802_1x_dump_state(f, "  ", sta);
142         }
143
144 #ifndef CONFIG_NO_RADIUS
145         buf = os_malloc(4096);
146         if (buf) {
147                 int count = radius_client_get_mib(hapd->radius, buf, 4096);
148                 if (count < 0)
149                         count = 0;
150                 else if (count > 4095)
151                         count = 4095;
152                 buf[count] = '\0';
153                 fprintf(f, "%s", buf);
154
155 #ifdef RADIUS_SERVER
156                 count = radius_server_get_mib(hapd->radius_srv, buf, 4096);
157                 if (count < 0)
158                         count = 0;
159                 else if (count > 4095)
160                         count = 4095;
161                 buf[count] = '\0';
162                 fprintf(f, "%s", buf);
163 #endif /* RADIUS_SERVER */
164
165                 os_free(buf);
166         }
167 #endif /* CONFIG_NO_RADIUS */
168         fclose(f);
169 }
170
171
172 int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx)
173 {
174         size_t i;
175
176         for (i = 0; i < iface->num_bss; i++)
177                 hostapd_dump_state(iface->bss[i]);
178
179         return 0;
180 }