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 1401264779 Lines: 86 127 67.7 %
Date: 2014-05-28 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           4 : static inline const char * port_type_txt(PortTypes pt)
      17             : {
      18           4 :         switch (pt) {
      19           0 :         case ForceUnauthorized: return "ForceUnauthorized";
      20           0 :         case ForceAuthorized: return "ForceAuthorized";
      21           4 :         case Auto: return "Auto";
      22           0 :         default: return "Unknown";
      23             :         }
      24             : }
      25             : 
      26             : 
      27           2 : static inline const char * port_state_txt(PortState ps)
      28             : {
      29           2 :         switch (ps) {
      30           0 :         case Unauthorized: return "Unauthorized";
      31           2 :         case Authorized: return "Authorized";
      32           0 :         default: return "Unknown";
      33             :         }
      34             : }
      35             : 
      36             : 
      37           4 : static inline const char * ctrl_dir_txt(ControlledDirection dir)
      38             : {
      39           4 :         switch (dir) {
      40           4 :         case Both: return "Both";
      41           0 :         case In: return "In";
      42           0 :         default: return "Unknown";
      43             :         }
      44             : }
      45             : 
      46             : 
      47           2 : static inline const char * auth_pae_state_txt(int s)
      48             : {
      49           2 :         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           0 :         case AUTH_PAE_AUTHENTICATING: return "AUTHENTICATING";
      54           2 :         case AUTH_PAE_AUTHENTICATED: return "AUTHENTICATED";
      55           0 :         case AUTH_PAE_ABORTING: return "ABORTING";
      56           0 :         case AUTH_PAE_HELD: return "HELD";
      57           0 :         case AUTH_PAE_FORCE_AUTH: return "FORCE_AUTH";
      58           0 :         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           2 : static inline const char * be_auth_state_txt(int s)
      66             : {
      67           2 :         switch (s) {
      68           0 :         case BE_AUTH_REQUEST: return "REQUEST";
      69           0 :         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           2 :         case BE_AUTH_IDLE: return "IDLE";
      74           0 :         case BE_AUTH_INITIALIZE: return "INITIALIZE";
      75           0 :         case BE_AUTH_IGNORE: return "IGNORE";
      76           0 :         default: return "Unknown";
      77             :         }
      78             : }
      79             : 
      80             : 
      81           2 : static inline const char * reauth_timer_state_txt(int s)
      82             : {
      83           2 :         switch (s) {
      84           2 :         case REAUTH_TIMER_INITIALIZE: return "INITIALIZE";
      85           0 :         case REAUTH_TIMER_REAUTHENTICATE: return "REAUTHENTICATE";
      86           0 :         default: return "Unknown";
      87             :         }
      88             : }
      89             : 
      90             : 
      91           2 : static inline const char * auth_key_tx_state_txt(int s)
      92             : {
      93           2 :         switch (s) {
      94           2 :         case AUTH_KEY_TX_NO_KEY_TRANSMIT: return "NO_KEY_TRANSMIT";
      95           0 :         case AUTH_KEY_TX_KEY_TRANSMIT: return "KEY_TRANSMIT";
      96           0 :         default: return "Unknown";
      97             :         }
      98             : }
      99             : 
     100             : 
     101           2 : static inline const char * key_rx_state_txt(int s)
     102             : {
     103           2 :         switch (s) {
     104           2 :         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           2 : static inline const char * ctrl_dir_state_txt(int s)
     112             : {
     113           2 :         switch (s) {
     114           2 :         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           2 : 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           2 :         pos = buf;
     128           2 :         end = pos + buflen;
     129             : 
     130           2 :         ret = os_snprintf(pos, end - pos, "aWhile=%d\nquietWhile=%d\n"
     131             :                           "reAuthWhen=%d\n",
     132             :                           sm->aWhile, sm->quietWhile, sm->reAuthWhen);
     133           2 :         if (ret < 0 || ret >= end - pos)
     134           0 :                 return pos - buf;
     135           2 :         pos += ret;
     136             : 
     137             : #define _SB(b) ((b) ? "TRUE" : "FALSE")
     138          34 :         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           2 :                           _SB(sm->authAbort),
     159           2 :                           _SB(sm->authFail),
     160             :                           port_state_txt(sm->authPortStatus),
     161           2 :                           _SB(sm->authStart),
     162           2 :                           _SB(sm->authTimeout),
     163           2 :                           _SB(sm->authSuccess),
     164           2 :                           _SB(sm->eap_if->eapFail),
     165           2 :                           _SB(sm->eapolEap),
     166           2 :                           _SB(sm->eap_if->eapSuccess),
     167           2 :                           _SB(sm->eap_if->eapTimeout),
     168           2 :                           _SB(sm->initialize),
     169           2 :                           _SB(sm->eap_if->eapKeyAvailable),
     170           4 :                           _SB(sm->keyDone), _SB(sm->keyRun),
     171           2 :                           _SB(sm->keyTxEnabled),
     172             :                           port_type_txt(sm->portControl),
     173           2 :                           _SB(sm->eap_if->portEnabled),
     174           2 :                           _SB(sm->portValid),
     175           2 :                           _SB(sm->reAuthenticate));
     176           2 :         if (ret < 0 || ret >= end - pos)
     177           0 :                 return pos - buf;
     178           2 :         pos += ret;
     179             : 
     180          10 :         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           2 :                           auth_pae_state_txt(sm->auth_pae_state),
     201           2 :                           _SB(sm->eapolLogoff),
     202           2 :                           _SB(sm->eapolStart),
     203           2 :                           _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           2 :         if (ret < 0 || ret >= end - pos)
     219           0 :                 return pos - buf;
     220           2 :         pos += ret;
     221             : 
     222          10 :         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           2 :                           be_auth_state_txt(sm->be_auth_state),
     234           2 :                           _SB(sm->eap_if->eapNoReq),
     235           2 :                           _SB(sm->eap_if->eapReq),
     236           2 :                           _SB(sm->eap_if->eapResp),
     237             :                           sm->serverTimeout,
     238             :                           sm->backendResponses,
     239             :                           sm->backendAccessChallenges,
     240             :                           sm->backendOtherRequestsToSupplicant,
     241             :                           sm->backendAuthSuccesses,
     242             :                           sm->backendAuthFails);
     243           2 :         if (ret < 0 || ret >= end - pos)
     244           0 :                 return pos - buf;
     245           2 :         pos += ret;
     246             : 
     247           4 :         ret = os_snprintf(pos, end - pos,
     248             :                           "reauth_timer_state=%s\n"
     249             :                           "reAuthPeriod=%d\n"
     250             :                           "reAuthEnabled=%s\n",
     251           2 :                           reauth_timer_state_txt(sm->reauth_timer_state),
     252             :                           sm->reAuthPeriod,
     253           2 :                           _SB(sm->reAuthEnabled));
     254           2 :         if (ret < 0 || ret >= end - pos)
     255           0 :                 return pos - buf;
     256           2 :         pos += ret;
     257             : 
     258           2 :         ret = os_snprintf(pos, end - pos,
     259             :                           "auth_key_tx_state=%s\n",
     260           2 :                           auth_key_tx_state_txt(sm->auth_key_tx_state));
     261           2 :         if (ret < 0 || ret >= end - pos)
     262           0 :                 return pos - buf;
     263           2 :         pos += ret;
     264             : 
     265           4 :         ret = os_snprintf(pos, end - pos,
     266             :                           "key_rx_state=%s\n"
     267             :                           "rxKey=%s\n",
     268           2 :                           key_rx_state_txt(sm->key_rx_state),
     269           2 :                           _SB(sm->rxKey));
     270           2 :         if (ret < 0 || ret >= end - pos)
     271           0 :                 return pos - buf;
     272           2 :         pos += ret;
     273             : 
     274           4 :         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           2 :                           ctrl_dir_state_txt(sm->ctrl_dir_state),
     280             :                           ctrl_dir_txt(sm->adminControlledDirections),
     281             :                           ctrl_dir_txt(sm->operControlledDirections),
     282           2 :                           _SB(sm->operEdge));
     283           2 :         if (ret < 0 || ret >= end - pos)
     284           0 :                 return pos - buf;
     285           2 :         pos += ret;
     286             : #undef _SB
     287             : 
     288           2 :         return pos - buf;
     289             : }

Generated by: LCOV version 1.10