LCOV - code coverage report
Current view: top level - hostapd - dump_state.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1388338050 Lines: 0 78 0.0 %
Date: 2013-12-29 Functions: 0 4 0.0 %
Branches: 0 38 0.0 %

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

Generated by: LCOV version 1.9