dump_state.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #include "utils/includes.h"
  15. #include <time.h>
  16. #include "utils/common.h"
  17. #include "radius/radius_client.h"
  18. #include "radius/radius_server.h"
  19. #include "eapol_auth/eapol_auth_sm.h"
  20. #include "eapol_auth/eapol_auth_sm_i.h"
  21. #include "eap_server/eap.h"
  22. #include "ap/hostapd.h"
  23. #include "ap/ap_config.h"
  24. #include "ap/sta_info.h"
  25. #include "dump_state.h"
  26. static void fprint_char(FILE *f, char c)
  27. {
  28. if (c >= 32 && c < 127)
  29. fprintf(f, "%c", c);
  30. else
  31. fprintf(f, "<%02x>", c);
  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. fprintf(f, "%sIEEE 802.1X:\n", prefix);
  40. if (sm->identity) {
  41. size_t i;
  42. fprintf(f, "%sidentity=", prefix);
  43. for (i = 0; i < sm->identity_len; i++)
  44. fprint_char(f, sm->identity[i]);
  45. fprintf(f, "\n");
  46. }
  47. fprintf(f, "%slast EAP type: Authentication Server: %d (%s) "
  48. "Supplicant: %d (%s)\n", prefix,
  49. sm->eap_type_authsrv,
  50. eap_server_get_name(0, sm->eap_type_authsrv),
  51. sm->eap_type_supp, eap_server_get_name(0, sm->eap_type_supp));
  52. fprintf(f, "%scached_packets=%s\n", prefix,
  53. sm->last_recv_radius ? "[RX RADIUS]" : "");
  54. eapol_auth_dump_state(f, prefix, sm);
  55. }
  56. /**
  57. * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
  58. */
  59. static void hostapd_dump_state(struct hostapd_data *hapd)
  60. {
  61. FILE *f;
  62. time_t now;
  63. struct sta_info *sta;
  64. int i;
  65. #ifndef CONFIG_NO_RADIUS
  66. char *buf;
  67. #endif /* CONFIG_NO_RADIUS */
  68. if (!hapd->conf->dump_log_name) {
  69. wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
  70. "request");
  71. return;
  72. }
  73. wpa_printf(MSG_DEBUG, "Dumping hostapd state to '%s'",
  74. hapd->conf->dump_log_name);
  75. f = fopen(hapd->conf->dump_log_name, "w");
  76. if (f == NULL) {
  77. wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
  78. "writing.", hapd->conf->dump_log_name);
  79. return;
  80. }
  81. time(&now);
  82. fprintf(f, "hostapd state dump - %s", ctime(&now));
  83. fprintf(f, "num_sta=%d num_sta_non_erp=%d "
  84. "num_sta_no_short_slot_time=%d\n"
  85. "num_sta_no_short_preamble=%d\n",
  86. hapd->num_sta, hapd->iface->num_sta_non_erp,
  87. hapd->iface->num_sta_no_short_slot_time,
  88. hapd->iface->num_sta_no_short_preamble);
  89. for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
  90. fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
  91. fprintf(f,
  92. " AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
  93. "\n"
  94. " capability=0x%x listen_interval=%d\n",
  95. sta->aid,
  96. sta->flags,
  97. (sta->flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
  98. (sta->flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
  99. (sta->flags & WLAN_STA_PS ? "[PS]" : ""),
  100. (sta->flags & WLAN_STA_TIM ? "[TIM]" : ""),
  101. (sta->flags & WLAN_STA_PERM ? "[PERM]" : ""),
  102. (ap_sta_is_authorized(sta) ? "[AUTHORIZED]" : ""),
  103. (sta->flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
  104. ""),
  105. (sta->flags & WLAN_STA_SHORT_PREAMBLE ?
  106. "[SHORT_PREAMBLE]" : ""),
  107. (sta->flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
  108. (sta->flags & WLAN_STA_WMM ? "[WMM]" : ""),
  109. (sta->flags & WLAN_STA_MFP ? "[MFP]" : ""),
  110. (sta->flags & WLAN_STA_WPS ? "[WPS]" : ""),
  111. (sta->flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
  112. (sta->flags & WLAN_STA_WDS ? "[WDS]" : ""),
  113. (sta->flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
  114. (sta->flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
  115. sta->capability,
  116. sta->listen_interval);
  117. fprintf(f, " supported_rates=");
  118. for (i = 0; i < sta->supported_rates_len; i++)
  119. fprintf(f, "%02x ", sta->supported_rates[i]);
  120. fprintf(f, "\n");
  121. fprintf(f,
  122. " timeout_next=%s\n",
  123. (sta->timeout_next == STA_NULLFUNC ? "NULLFUNC POLL" :
  124. (sta->timeout_next == STA_DISASSOC ? "DISASSOC" :
  125. "DEAUTH")));
  126. ieee802_1x_dump_state(f, " ", sta);
  127. }
  128. #ifndef CONFIG_NO_RADIUS
  129. buf = os_malloc(4096);
  130. if (buf) {
  131. int count = radius_client_get_mib(hapd->radius, buf, 4096);
  132. if (count < 0)
  133. count = 0;
  134. else if (count > 4095)
  135. count = 4095;
  136. buf[count] = '\0';
  137. fprintf(f, "%s", buf);
  138. #ifdef RADIUS_SERVER
  139. count = radius_server_get_mib(hapd->radius_srv, buf, 4096);
  140. if (count < 0)
  141. count = 0;
  142. else if (count > 4095)
  143. count = 4095;
  144. buf[count] = '\0';
  145. fprintf(f, "%s", buf);
  146. #endif /* RADIUS_SERVER */
  147. os_free(buf);
  148. }
  149. #endif /* CONFIG_NO_RADIUS */
  150. fclose(f);
  151. }
  152. int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx)
  153. {
  154. size_t i;
  155. for (i = 0; i < iface->num_bss; i++)
  156. hostapd_dump_state(iface->bss[i]);
  157. return 0;
  158. }