#ifdef OPENR_ETHERSTAT
#include "EtherStat.h"
#include <OPENR/OSyslog.h>

void EtherStat::PrintEtherStatistics(const EtherDriverGetStatisticsMsg& msg){
  OSYSPRINT(("[Ether Statistics]\n"));
  OSYSPRINT(("  carrierSenseErrorCount  : %d\n",
	     msg.statistics.carrierSenseErrorCount));
  OSYSPRINT(("  lateCollisionCount      : %d\n",
	     msg.statistics.lateCollisionCount));
  OSYSPRINT(("  excessiveCollisionCount : %d\n",
	     msg.statistics.excessiveCollisionCount));
  OSYSPRINT(("  singleCollisionCount    : %d\n",
	     msg.statistics.singleCollisionCount));
  OSYSPRINT(("  multipleCollisionCount  : %d\n",
	     msg.statistics.multipleCollisionCount));
  OSYSPRINT(("  deferredCount           : %d\n",
	     msg.statistics.deferredCount));
  OSYSPRINT(("  alignmentErrorCount     : %d\n",
	     msg.statistics.alignmentErrorCount));
  OSYSPRINT(("  fcsErrorCount           : %d\n",
	     msg.statistics.fcsErrorCount));
  OSYSPRINT(("  frameTooLongCount       : %d\n",
	     msg.statistics.frameTooLongCount));
}

void EtherStat::PrintWLANSettings(const EtherDriverGetWLANSettingsMsg& msg){
  OSYSPRINT(("[WLAN Settings]\n"));
  OSYSPRINT(("  port          : %d\n", msg.port));
  OSYSPRINT(("  mode          : "));

  switch (msg.mode) {
  case ETHER_WLAN_MODE_AP:
    OSYSPRINT(("ETHER_WLAN_MODE_AP\n"));
    break;
  case ETHER_WLAN_MODE_ADHOC: 
    OSYSPRINT(("ETHER_WLAN_MODE_ADHOC\n"));
    break;
  default: 
    OSYSPRINT(("invalid value\n")); 
  }

  OSYSPRINT(("  essid         : %s\n", msg.essid));
  OSYSPRINT(("  channel       : %d\n", msg.channel));
  OSYSPRINT(("  encryption    : ", msg.encryption));

  switch (msg.encryption) {
  case ETHER_WLAN_ENC_OFF:
    OSYSPRINT(("ETHER_WLAN_ENC_OFF\n"));
    break;
  case ETHER_WLAN_ENC_WEP:
    OSYSPRINT(("ETHER_WLAN_ENC_WEP\n"));
    break;
  default:
    OSYSPRINT(("invalid value\n"));
  }

  OSYSPRINT(("  rate          : "));

  switch (msg.rate) {
  case ETHER_WLAN_RATE_1MB:
    OSYSPRINT(("ETHER_WLAN_RATE_1MB\n"));
    break;
  case ETHER_WLAN_RATE_2MB:
    OSYSPRINT(("ETHER_WLAN_RATE_2MB\n"));
    break;
  case ETHER_WLAN_RATE_5_5MB: 
    OSYSPRINT(("ETHER_WLAN_RATE_5_5MB\n"));
    break;
  case ETHER_WLAN_RATE_11MB:
    OSYSPRINT(("ETHER_WLAN_RATE_11MB\n"));
    break;
  case ETHER_WLAN_RATE_AUTO:
    OSYSPRINT(("ETHER_WLAN_RATE_AUTO\n"));
    break;
  default:
    OSYSPRINT(("invalid value\n"));
  }

  OSYSPRINT(("  rts           : %d\n", msg.rts));
  OSYSPRINT(("  fragmentation : %d\n", msg.fragmentation));
  OSYSPRINT(("  sensitivity   : "));

  switch (msg.sensitivity) {
  case ETHER_WLAN_DENSITY_LOW:
    OSYSPRINT(("ETHER_WLAN_DENSITY_LOW\n"));
    break;
  case ETHER_WLAN_DENSITY_MED: 
    OSYSPRINT(("ETHER_WLAN_DENSITY_MED\n"));
    break;
  case ETHER_WLAN_DENSITY_HIGH:
    OSYSPRINT(("ETHER_WLAN_DENSITY_HIGH\n"));
    break;
  default:
    OSYSPRINT(("invalid value\n"));
  }
}

void EtherStat::PrintWLANStatistics(const EtherDriverGetWLANStatisticsMsg& msg){
  OSYSPRINT(("[WLAN Statistics]\n"));
  OSYSPRINT(("  link             : %d\n", msg.statistics.link));
  OSYSPRINT(("  signal           : %d\n", msg.statistics.signal));
  OSYSPRINT(("  noise            : %d\n", msg.statistics.noise));
  OSYSPRINT(("  invalidIDCount   : %d\n", msg.statistics.invalidIDCount));
  OSYSPRINT(("  invalidEncCount  : %d\n", msg.statistics.invalidEncCount));
  OSYSPRINT(("  invalidMiscCount : %d\n", msg.statistics.invalidMiscCount));
}

void EtherStat::printStat(){
  OSYSDEBUG(("EtherStat::EtherStat()\n"));
  
  EtherStatus status;
  EtherStat eth=EtherStat();
  
  EtherDriverGetStatisticsMsg etherStatMsg;
  status = ERA201D1_GetEtherStatistics(&etherStatMsg);
  if (status == ETHER_OK) 
    eth.PrintEtherStatistics(etherStatMsg);
  else 
    OSYSLOG1((osyslogERROR, "ERA201D1_GetEtherStatistics() FAILED %d", status));
  EtherDriverGetWLANSettingsMsg wlanSettingsMsg;
  status = ERA201D1_GetWLANSettings(&wlanSettingsMsg);
  if (status == ETHER_OK)
    eth.PrintWLANSettings(wlanSettingsMsg);
  else 
    OSYSLOG1((osyslogERROR, "ERA201D1_GetWLANSettings() FAILED %d", status));
  
  EtherDriverGetWLANStatisticsMsg wlanStatMsg;
  status = ERA201D1_GetWLANStatistics(&wlanStatMsg);
  if (status == ETHER_OK)
    eth.PrintWLANStatistics(wlanStatMsg);
  else
    OSYSLOG1((osyslogERROR, "ERA201D1_GetWLANStatistics() FAILED %d", status));
}
#endif
