LCOV - code coverage report
Current view: top level - src/eapol_auth - eapol_auth_dump.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 97 127 76.4 %
Date: 2015-09-27 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /*
       2             :  * IEEE 802.1X-2004 Authenticator - State dump
       3             :  * Copyright (c) 2002-2013, 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 "includes.h"
      10             : 
      11             : #include "common.h"
      12             : #include "eap_server/eap.h"
      13             : #include "eapol_auth_sm.h"
      14             : #include "eapol_auth_sm_i.h"
      15             : 
      16          36 : static inline const char * port_type_txt(PortTypes pt)
      17             : {
      18          36 :         switch (pt) {
      19           2 :         case ForceUnauthorized: return "ForceUnauthorized";
      20           2 :         case ForceAuthorized: return "ForceAuthorized";
      21          32 :         case Auto: return "Auto";
      22           0 :         default: return "Unknown";
      23             :         }
      24             : }
      25             : 
      26             : 
      27          18 : static inline const char * port_state_txt(PortState ps)
      28             : {
      29          18 :         switch (ps) {
      30           3 :         case Unauthorized: return "Unauthorized";
      31          15 :         case Authorized: return "Authorized";
      32           0 :         default: return "Unknown";
      33             :         }
      34             : }
      35             : 
      36             : 
      37          36 : static inline const char * ctrl_dir_txt(ControlledDirection dir)
      38             : {
      39          36 :         switch (dir) {
      40          35 :         case Both: return "Both";
      41           1 :         case In: return "In";
      42           0 :         default: return "Unknown";
      43             :         }
      44             : }
      45             : 
      46             : 
      47          18 : static inline const char * auth_pae_state_txt(int s)
      48             : {
      49          18 :         switch (s) {
      50           0 :         case AUTH_PAE_INITIALIZE: return "INITIALIZE";
      51           0 :         case AUTH_PAE_DISCONNECTED: return "DISCONNECTED";
      52           0 :         case AUTH_PAE_CONNECTING: return "CONNECTING";
      53           5 :         case AUTH_PAE_AUTHENTICATING: return "AUTHENTICATING";
      54          11 :         case AUTH_PAE_AUTHENTICATED: return "AUTHENTICATED";
      55           0 :         case AUTH_PAE_ABORTING: return "ABORTING";
      56           0 :         case AUTH_PAE_HELD: return "HELD";
      57           1 :         case AUTH_PAE_FORCE_AUTH: return "FORCE_AUTH";
      58           1 :         case AUTH_PAE_FORCE_UNAUTH: return "FORCE_UNAUTH";
      59           0 :         case AUTH_PAE_RESTART: return "RESTART";
      60           0 :         default: return "Unknown";
      61             :         }
      62             : }
      63             : 
      64             : 
      65          18 : static inline const char * be_auth_state_txt(int s)
      66             : {
      67          18 :         switch (s) {
      68           4 :         case BE_AUTH_REQUEST: return "REQUEST";
      69           1 :         case BE_AUTH_RESPONSE: return "RESPONSE";
      70           0 :         case BE_AUTH_SUCCESS: return "SUCCESS";
      71           0 :         case BE_AUTH_FAIL: return "FAIL";
      72           0 :         case BE_AUTH_TIMEOUT: return "TIMEOUT";
      73          11 :         case BE_AUTH_IDLE: return "IDLE";
      74           2 :         case BE_AUTH_INITIALIZE: return "INITIALIZE";
      75           0 :         case BE_AUTH_IGNORE: return "IGNORE";
      76           0 :         default: return "Unknown";
      77             :         }
      78             : }
      79             : 
      80             : 
      81          18 : static inline const char * reauth_timer_state_txt(int s)
      82             : {
      83          18 :         switch (s) {
      84          18 :         case REAUTH_TIMER_INITIALIZE: return "INITIALIZE";
      85           0 :         case REAUTH_TIMER_REAUTHENTICATE: return "REAUTHENTICATE";
      86           0 :         default: return "Unknown";
      87             :         }
      88             : }
      89             : 
      90             : 
      91          18 : static inline const char * auth_key_tx_state_txt(int s)
      92             : {
      93          18 :         switch (s) {
      94          17 :         case AUTH_KEY_TX_NO_KEY_TRANSMIT: return "NO_KEY_TRANSMIT";
      95           1 :         case AUTH_KEY_TX_KEY_TRANSMIT: return "KEY_TRANSMIT";
      96           0 :         default: return "Unknown";
      97             :         }
      98             : }
      99             : 
     100             : 
     101          18 : static inline const char * key_rx_state_txt(int s)
     102             : {
     103          18 :         switch (s) {
     104          18 :         case KEY_RX_NO_KEY_RECEIVE: return "NO_KEY_RECEIVE";
     105           0 :         case KEY_RX_KEY_RECEIVE: return "KEY_RECEIVE";
     106           0 :         default: return "Unknown";
     107             :         }
     108             : }
     109             : 
     110             : 
     111          18 : static inline const char * ctrl_dir_state_txt(int s)
     112             : {
     113          18 :         switch (s) {
     114          18 :         case CTRL_DIR_FORCE_BOTH: return "FORCE_BOTH";
     115           0 :         case CTRL_DIR_IN_OR_BOTH: return "IN_OR_BOTH";
     116           0 :         default: return "Unknown";
     117             :         }
     118             : }
     119             : 
     120             : 
     121          18 : int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
     122             :                           size_t buflen)
     123             : {
     124             :         char *pos, *end;
     125             :         int ret;
     126             : 
     127          18 :         pos = buf;
     128          18 :         end = pos + buflen;
     129             : 
     130          18 :         ret = os_snprintf(pos, end - pos, "aWhile=%d\nquietWhile=%d\n"
     131             :                           "reAuthWhen=%d\n",
     132             :                           sm->aWhile, sm->quietWhile, sm->reAuthWhen);
     133          18 :         if (os_snprintf_error(end - pos, ret))
     134           0 :                 return pos - buf;
     135          18 :         pos += ret;
     136             : 
     137             : #define _SB(b) ((b) ? "TRUE" : "FALSE")
     138         306 :         ret = os_snprintf(pos, end - pos,
     139             :                           "authAbort=%s\n"
     140             :                           "authFail=%s\n"
     141             :                           "authPortStatus=%s\n"
     142             :                           "authStart=%s\n"
     143             :                           "authTimeout=%s\n"
     144             :                           "authSuccess=%s\n"
     145             :                           "eapFail=%s\n"
     146             :                           "eapolEap=%s\n"
     147             :                           "eapSuccess=%s\n"
     148             :                           "eapTimeout=%s\n"
     149             :                           "initialize=%s\n"
     150             :                           "keyAvailable=%s\n"
     151             :                           "keyDone=%s\n"
     152             :                           "keyRun=%s\n"
     153             :                           "keyTxEnabled=%s\n"
     154             :                           "portControl=%s\n"
     155             :                           "portEnabled=%s\n"
     156             :                           "portValid=%s\n"
     157             :                           "reAuthenticate=%s\n",
     158          18 :                           _SB(sm->authAbort),
     159          18 :                           _SB(sm->authFail),
     160             :                           port_state_txt(sm->authPortStatus),
     161          18 :                           _SB(sm->authStart),
     162          18 :                           _SB(sm->authTimeout),
     163          18 :                           _SB(sm->authSuccess),
     164          18 :                           _SB(sm->eap_if->eapFail),
     165          18 :                           _SB(sm->eapolEap),
     166          18 :                           _SB(sm->eap_if->eapSuccess),
     167          18 :                           _SB(sm->eap_if->eapTimeout),
     168          18 :                           _SB(sm->initialize),
     169          18 :                           _SB(sm->eap_if->eapKeyAvailable),
     170          36 :                           _SB(sm->keyDone), _SB(sm->keyRun),
     171          18 :                           _SB(sm->keyTxEnabled),
     172             :                           port_type_txt(sm->portControl),
     173          18 :                           _SB(sm->eap_if->portEnabled),
     174          18 :                           _SB(sm->portValid),
     175          18 :                           _SB(sm->reAuthenticate));
     176          18 :         if (os_snprintf_error(end - pos, ret))
     177           0 :                 return pos - buf;
     178          18 :         pos += ret;
     179             : 
     180          90 :         ret = os_snprintf(pos, end - pos,
     181             :                           "auth_pae_state=%s\n"
     182             :                           "eapolLogoff=%s\n"
     183             :                           "eapolStart=%s\n"
     184             :                           "eapRestart=%s\n"
     185             :                           "portMode=%s\n"
     186             :                           "reAuthCount=%d\n"
     187             :                           "quietPeriod=%d\n"
     188             :                           "reAuthMax=%d\n"
     189             :                           "authEntersConnecting=%d\n"
     190             :                           "authEapLogoffsWhileConnecting=%d\n"
     191             :                           "authEntersAuthenticating=%d\n"
     192             :                           "authAuthSuccessesWhileAuthenticating=%d\n"
     193             :                           "authAuthTimeoutsWhileAuthenticating=%d\n"
     194             :                           "authAuthFailWhileAuthenticating=%d\n"
     195             :                           "authAuthEapStartsWhileAuthenticating=%d\n"
     196             :                           "authAuthEapLogoffWhileAuthenticating=%d\n"
     197             :                           "authAuthReauthsWhileAuthenticated=%d\n"
     198             :                           "authAuthEapStartsWhileAuthenticated=%d\n"
     199             :                           "authAuthEapLogoffWhileAuthenticated=%d\n",
     200          18 :                           auth_pae_state_txt(sm->auth_pae_state),
     201          18 :                           _SB(sm->eapolLogoff),
     202          18 :                           _SB(sm->eapolStart),
     203          18 :                           _SB(sm->eap_if->eapRestart),
     204             :                           port_type_txt(sm->portMode),
     205             :                           sm->reAuthCount,
     206             :                           sm->quietPeriod, sm->reAuthMax,
     207             :                           sm->authEntersConnecting,
     208             :                           sm->authEapLogoffsWhileConnecting,
     209             :                           sm->authEntersAuthenticating,
     210             :                           sm->authAuthSuccessesWhileAuthenticating,
     211             :                           sm->authAuthTimeoutsWhileAuthenticating,
     212             :                           sm->authAuthFailWhileAuthenticating,
     213             :                           sm->authAuthEapStartsWhileAuthenticating,
     214             :                           sm->authAuthEapLogoffWhileAuthenticating,
     215             :                           sm->authAuthReauthsWhileAuthenticated,
     216             :                           sm->authAuthEapStartsWhileAuthenticated,
     217             :                           sm->authAuthEapLogoffWhileAuthenticated);
     218          18 :         if (os_snprintf_error(end - pos, ret))
     219           0 :                 return pos - buf;
     220          18 :         pos += ret;
     221             : 
     222          90 :         ret = os_snprintf(pos, end - pos,
     223             :                           "be_auth_state=%s\n"
     224             :                           "eapNoReq=%s\n"
     225             :                           "eapReq=%s\n"
     226             :                           "eapResp=%s\n"
     227             :                           "serverTimeout=%d\n"
     228             :                           "backendResponses=%d\n"
     229             :                           "backendAccessChallenges=%d\n"
     230             :                           "backendOtherRequestsToSupplicant=%d\n"
     231             :                           "backendAuthSuccesses=%d\n"
     232             :                           "backendAuthFails=%d\n",
     233          18 :                           be_auth_state_txt(sm->be_auth_state),
     234          18 :                           _SB(sm->eap_if->eapNoReq),
     235          18 :                           _SB(sm->eap_if->eapReq),
     236          18 :                           _SB(sm->eap_if->eapResp),
     237             :                           sm->serverTimeout,
     238             :                           sm->backendResponses,
     239             :                           sm->backendAccessChallenges,
     240             :                           sm->backendOtherRequestsToSupplicant,
     241             :                           sm->backendAuthSuccesses,
     242             :                           sm->backendAuthFails);
     243          18 :         if (os_snprintf_error(end - pos, ret))
     244           0 :                 return pos - buf;
     245          18 :         pos += ret;
     246             : 
     247          36 :         ret = os_snprintf(pos, end - pos,
     248             :                           "reauth_timer_state=%s\n"
     249             :                           "reAuthPeriod=%d\n"
     250             :                           "reAuthEnabled=%s\n",
     251          18 :                           reauth_timer_state_txt(sm->reauth_timer_state),
     252             :                           sm->reAuthPeriod,
     253          18 :                           _SB(sm->reAuthEnabled));
     254          18 :         if (os_snprintf_error(end - pos, ret))
     255           0 :                 return pos - buf;
     256          18 :         pos += ret;
     257             : 
     258          18 :         ret = os_snprintf(pos, end - pos,
     259             :                           "auth_key_tx_state=%s\n",
     260          18 :                           auth_key_tx_state_txt(sm->auth_key_tx_state));
     261          18 :         if (os_snprintf_error(end - pos, ret))
     262           0 :                 return pos - buf;
     263          18 :         pos += ret;
     264             : 
     265          36 :         ret = os_snprintf(pos, end - pos,
     266             :                           "key_rx_state=%s\n"
     267             :                           "rxKey=%s\n",
     268          18 :                           key_rx_state_txt(sm->key_rx_state),
     269          18 :                           _SB(sm->rxKey));
     270          18 :         if (os_snprintf_error(end - pos, ret))
     271           0 :                 return pos - buf;
     272          18 :         pos += ret;
     273             : 
     274          36 :         ret = os_snprintf(pos, end - pos,
     275             :                           "ctrl_dir_state=%s\n"
     276             :                           "adminControlledDirections=%s\n"
     277             :                           "operControlledDirections=%s\n"
     278             :                           "operEdge=%s\n",
     279          18 :                           ctrl_dir_state_txt(sm->ctrl_dir_state),
     280             :                           ctrl_dir_txt(sm->adminControlledDirections),
     281             :                           ctrl_dir_txt(sm->operControlledDirections),
     282          18 :                           _SB(sm->operEdge));
     283          18 :         if (os_snprintf_error(end - pos, ret))
     284           0 :                 return pos - buf;
     285          18 :         pos += ret;
     286             : #undef _SB
     287             : 
     288          18 :         return pos - buf;
     289             : }

Generated by: LCOV version 1.10