dump_state.c 4.8 KB

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