dump_state.c 4.5 KB

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