Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 16 | #include <time.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 17 | |
| 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" |
| 28 | |
| 29 | |
| 30 | static void fprint_char(FILE *f, char c) |
| 31 | { |
| 32 | if (c >= 32 && c < 127) |
| 33 | fprintf(f, "%c", c); |
| 34 | else |
| 35 | fprintf(f, "<%02x>", c); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | static void ieee802_1x_dump_state(FILE *f, const char *prefix, |
| 40 | struct sta_info *sta) |
| 41 | { |
| 42 | struct eapol_state_machine *sm = sta->eapol_sm; |
| 43 | if (sm == NULL) |
| 44 | return; |
| 45 | |
| 46 | fprintf(f, "%sIEEE 802.1X:\n", prefix); |
| 47 | |
| 48 | if (sm->identity) { |
| 49 | size_t i; |
| 50 | fprintf(f, "%sidentity=", prefix); |
| 51 | for (i = 0; i < sm->identity_len; i++) |
| 52 | fprint_char(f, sm->identity[i]); |
| 53 | fprintf(f, "\n"); |
| 54 | } |
| 55 | |
| 56 | fprintf(f, "%slast EAP type: Authentication Server: %d (%s) " |
| 57 | "Supplicant: %d (%s)\n", prefix, |
| 58 | sm->eap_type_authsrv, |
| 59 | eap_server_get_name(0, sm->eap_type_authsrv), |
| 60 | sm->eap_type_supp, eap_server_get_name(0, sm->eap_type_supp)); |
| 61 | |
| 62 | fprintf(f, "%scached_packets=%s\n", prefix, |
| 63 | sm->last_recv_radius ? "[RX RADIUS]" : ""); |
| 64 | |
| 65 | eapol_auth_dump_state(f, prefix, sm); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file |
| 71 | */ |
| 72 | static void hostapd_dump_state(struct hostapd_data *hapd) |
| 73 | { |
| 74 | FILE *f; |
| 75 | time_t now; |
| 76 | struct sta_info *sta; |
| 77 | int i; |
| 78 | #ifndef CONFIG_NO_RADIUS |
| 79 | char *buf; |
| 80 | #endif /* CONFIG_NO_RADIUS */ |
| 81 | |
| 82 | if (!hapd->conf->dump_log_name) { |
| 83 | wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump " |
| 84 | "request"); |
| 85 | return; |
| 86 | } |
| 87 | |
| 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"); |
| 91 | if (f == NULL) { |
| 92 | wpa_printf(MSG_WARNING, "Could not open dump file '%s' for " |
| 93 | "writing.", hapd->conf->dump_log_name); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | time(&now); |
| 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); |
| 105 | |
| 106 | for (sta = hapd->sta_list; sta != NULL; sta = sta->next) { |
| 107 | fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr)); |
| 108 | |
| 109 | fprintf(f, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 110 | " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" |
| 111 | "\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 112 | " capability=0x%x listen_interval=%d\n", |
| 113 | sta->aid, |
| 114 | sta->flags, |
| 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" : |
| 122 | ""), |
| 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]" : ""), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 132 | (sta->flags & WLAN_STA_WPS2 ? "[WPS2]" : ""), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 133 | sta->capability, |
| 134 | sta->listen_interval); |
| 135 | |
| 136 | fprintf(f, " supported_rates="); |
| 137 | for (i = 0; i < sta->supported_rates_len; i++) |
| 138 | fprintf(f, "%02x ", sta->supported_rates[i]); |
| 139 | fprintf(f, "\n"); |
| 140 | |
| 141 | fprintf(f, |
| 142 | " timeout_next=%s\n", |
| 143 | (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" : |
| 144 | (sta->timeout_next == STA_DISASSOC ? "DISASSOC" : |
| 145 | "DEAUTH"))); |
| 146 | |
| 147 | ieee802_1x_dump_state(f, " ", sta); |
| 148 | } |
| 149 | |
| 150 | #ifndef CONFIG_NO_RADIUS |
| 151 | buf = os_malloc(4096); |
| 152 | if (buf) { |
| 153 | int count = radius_client_get_mib(hapd->radius, buf, 4096); |
| 154 | if (count < 0) |
| 155 | count = 0; |
| 156 | else if (count > 4095) |
| 157 | count = 4095; |
| 158 | buf[count] = '\0'; |
| 159 | fprintf(f, "%s", buf); |
| 160 | |
| 161 | #ifdef RADIUS_SERVER |
| 162 | count = radius_server_get_mib(hapd->radius_srv, buf, 4096); |
| 163 | if (count < 0) |
| 164 | count = 0; |
| 165 | else if (count > 4095) |
| 166 | count = 4095; |
| 167 | buf[count] = '\0'; |
| 168 | fprintf(f, "%s", buf); |
| 169 | #endif /* RADIUS_SERVER */ |
| 170 | |
| 171 | os_free(buf); |
| 172 | } |
| 173 | #endif /* CONFIG_NO_RADIUS */ |
| 174 | fclose(f); |
| 175 | } |
| 176 | |
| 177 | |
| 178 | int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx) |
| 179 | { |
| 180 | size_t i; |
| 181 | |
| 182 | for (i = 0; i < iface->num_bss; i++) |
| 183 | hostapd_dump_state(iface->bss[i]); |
| 184 | |
| 185 | return 0; |
| 186 | } |