dump_state.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "eapol_auth/eapol_auth_sm.h"
  12. #include "eapol_auth/eapol_auth_sm_i.h"
  13. #include "eap_server/eap.h"
  14. #include "ap/hostapd.h"
  15. #include "ap/ap_config.h"
  16. #include "ap/sta_info.h"
  17. #include "dump_state.h"
  18. #include "ap/ap_drv_ops.h"
  19. static void ieee802_1x_dump_state(FILE *f, const char *prefix,
  20. struct sta_info *sta)
  21. {
  22. struct eapol_state_machine *sm = sta->eapol_sm;
  23. if (sm == NULL)
  24. return;
  25. eapol_auth_dump_state(f, prefix, sm);
  26. }
  27. /**
  28. * hostapd_dump_state - SIGUSR1 handler to dump hostapd state to a text file
  29. */
  30. static void hostapd_dump_state(struct hostapd_data *hapd)
  31. {
  32. FILE *f;
  33. time_t now;
  34. struct sta_info *sta;
  35. if (!hapd->conf->dump_log_name) {
  36. wpa_printf(MSG_DEBUG, "Dump file not defined - ignoring dump "
  37. "request");
  38. return;
  39. }
  40. wpa_printf(MSG_DEBUG, "Dumping hostapd state to '%s'",
  41. hapd->conf->dump_log_name);
  42. f = fopen(hapd->conf->dump_log_name, "w");
  43. if (f == NULL) {
  44. wpa_printf(MSG_WARNING, "Could not open dump file '%s' for "
  45. "writing.", hapd->conf->dump_log_name);
  46. return;
  47. }
  48. time(&now);
  49. fprintf(f, "hostapd state dump - %s", ctime(&now));
  50. for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
  51. fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
  52. ieee802_1x_dump_state(f, " ", sta);
  53. }
  54. fclose(f);
  55. }
  56. int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx)
  57. {
  58. size_t i;
  59. for (i = 0; i < iface->num_bss; i++)
  60. hostapd_dump_state(iface->bss[i]);
  61. return 0;
  62. }