You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dump_state.c 4.7KB

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