
#include "stdafx.h"
#include "WiFiEvents.h"
#include "WiFiEventsDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

void ShowResult(const int Res)
{
	if (Res != WCL_E_SUCCESS)
	{
		CString s;
		s.Format(_T("Error: 0x%.8X"), Res);
		AfxMessageBox(s);
	}
}

CString IntToHex(const int Res)
{
	CString Str;
	Str.Format(_T("0x%.8X"), Res);
	return Str;
}

CString GetEnumName(const wclWiFiAdHocNetworkState Enum)
{
	switch (Enum)
	{
		case asFormed:
			return _T("asFormed");
		case asConnected:
			return _T("asConnected");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiBssType Enum)
{
	switch (Enum)
	{
		case bssInfrastructure:
			return _T("bssInfrastructure");
		case bssIndependent:
			return _T("bssIndependent");
		case bssAny:
			return _T("bssAny");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiConnectionMode Enum)
{
	switch (Enum)
	{
		case cmProfile:
			return _T("cmProfile");
		case cmTemporaryProfile:
			return _T("cmTemporaryProfile");
		case cmDiscoverySecure:
			return _T("cmDiscoverySecure");
		case cmDiscoveryUnsecure:
			return _T("cmDiscoveryUnsecure");
		case cmAuto:
			return _T("cmAuto");
		case cmInvalid:
			return _T("cmInvalid");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiPowerSetting Enum)
{
	switch (Enum)
	{
		case psNo:
			return _T("psNo");
		case psLow:
			return _T("psLow");
		case psMedium:
			return _T("psMedium");
		case psMaximum:
			return _T("psMaximum");
		case psInvalid:
			return _T("psInvalid");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiHostedNetworkPeerAuthState Enum)
{
	switch (Enum)
	{
		case asAuthenticated:
			return _T("asAuthenticated");
		case asInvalid:
			return _T("asInvalid");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiRadioState Enum)
{
	switch (Enum)
	{
		case rsOn:
			return _T("rsOn");
		case rsOff:
			return _T("rsOff");
		case rsUnknown:
			return _T("rsUnknown");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiHostedNetworkState Enum)
{
	switch (Enum)
	{
		case hnIdle:
			return _T("hnIdle");
		case hnActive:
			return _T("hnActive");
		case hnUnavailable:
			return _T("hnUnavailable");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiOperationMode Enum)
{
	switch (Enum)
	{
		case omStation:
			return _T("omStation");
		case omAccessPoint:
			return _T("omAccessPoint");
		case omExtensibleStation:
			return _T("omExtensibleStation");
		case omExtensibleAccessPoint:
			return _T("omExtensibleAccessPoint");
		case omWiFiDirectDevice:
			return _T("omWiFiDirectDevice");
		case omWiFiDirectGroupOwner:
			return _T("omWiFiDirectGroupOwner");
		case omWiFiDirectClient:
			return _T("omWiFiDirectClient");
		case omManufacturing:
			return _T("omManufacturing");
		case omNetworkMonitor:
			return _T("omNetworkMonitor");
		case omUnknown:
			return _T("omUnknown");
		default:
			return _T("UNKNOWN");
	}
}

CString GetEnumName(const wclWiFiPhy Enum)
{
	switch (Enum)
	{
		case phyAny:
			return _T("phyAny");
		case phyFhss:
			return _T("phyFhss");
		case phyDsss:
			return _T("phyDsss");
		case phyIr:
			return _T("phyIr");
		case phyOfdm:
			return _T("phyOfdm");
		case phyHrDsss:
			return _T("phyHrDsss");
		case phyErp:
			return _T("phyErp");
		case phyHt:
			return _T("phyHt");
		case phyVht:
			return _T("phyVht");
		case phyUnknown:
			return _T("phyUnknown");
		default:
			return _T("UNKNOWN");
	}
}

CString BoolToStr(const bool Val)
{
	if (Val)
		return _T("True");
	else
		return _T("False");
}

CString IntToStr(const int Val)
{
	CString s;
	s.Format(_T("%d"), Val);
	return s;
}

CString GuidToString(const GUID& Guid)
{
	LPOLESTR lpszClsID;
	StringFromCLSID(Guid, &lpszClsID);
	CString Res = CString(lpszClsID);
	CoTaskMemFree(lpszClsID);
	return Res;
}


// CWiFiEventsDlg dialog




CWiFiEventsDlg::CWiFiEventsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWiFiEventsDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWiFiEventsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_EVENTS, lvEvents);
}

BEGIN_MESSAGE_MAP(CWiFiEventsDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON_EVENTS_OPEN, &CWiFiEventsDlg::OnBnClickedButtonEventsOpen)
	ON_BN_CLICKED(IDC_BUTTON_EVENTS_CLOSE, &CWiFiEventsDlg::OnBnClickedButtonEventsClose)
	ON_BN_CLICKED(IDC_BUTTON_EVENTS_CLEAR, &CWiFiEventsDlg::OnBnClickedButtonEventsClear)
	ON_WM_DESTROY()
END_MESSAGE_MAP()


// CWiFiEventsDlg message handlers

BOOL CWiFiEventsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application"s main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	lvEvents.InsertColumn(0, _T("Interface ID"), 0, 200);
	lvEvents.InsertColumn(1, _T("Event name"), 0, 200);
	lvEvents.InsertColumn(2, _T("Parameter name"), 0, 200);
	lvEvents.InsertColumn(3, _T("Parameter value"), 0, 200);
	lvEvents.SetExtendedStyle(lvEvents.GetExtendedStyle() | LVS_EX_FULLROWSELECT);

	__hook(&CwclWiFiEvents::AfterOpen, &wclWiFiEvents, &CWiFiEventsDlg::EventsAfterOpen);
	__hook(&CwclWiFiEvents::BeforeClose, &wclWiFiEvents, &CWiFiEventsDlg::EventsBeforeClose);

	__hook(&CwclWiFiEvents::OnAcmAdHocNetworkStateChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmAdHocNetworkStateChange);
	__hook(&CwclWiFiEvents::OnAcmAutoconfDisabled, &wclWiFiEvents, &CWiFiEventsDlg::AcmAutoconfDisabled);
	__hook(&CwclWiFiEvents::OnAcmAutoconfEnabled, &wclWiFiEvents, &CWiFiEventsDlg::AcmAutoconfEnabled);
	__hook(&CwclWiFiEvents::OnAcmBackgroundScanDisabled, &wclWiFiEvents, &CWiFiEventsDlg::AcmBackgroundScanDisabled);
	__hook(&CwclWiFiEvents::OnAcmBackgroundScanEnabled, &wclWiFiEvents, &CWiFiEventsDlg::AcmBackgroundScanEnabled);
	__hook(&CwclWiFiEvents::OnAcmConnectionAttemptFail, &wclWiFiEvents, &CWiFiEventsDlg::AcmConnectionAttemptFail);
	__hook(&CwclWiFiEvents::OnAcmBssTypeChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmBssTypeChange);
	__hook(&CwclWiFiEvents::OnAcmConnectionComplete, &wclWiFiEvents, &CWiFiEventsDlg::AcmConnectionComplete);
	__hook(&CwclWiFiEvents::OnAcmConnectionStart, &wclWiFiEvents, &CWiFiEventsDlg::AcmConnectionStart);
	__hook(&CwclWiFiEvents::OnAcmDisconnected, &wclWiFiEvents, &CWiFiEventsDlg::AcmDisconnected);
	__hook(&CwclWiFiEvents::OnAcmDisconnecting, &wclWiFiEvents, &CWiFiEventsDlg::AcmDisconnecting);
	__hook(&CwclWiFiEvents::OnAcmFilterListChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmFilterListChange);
	__hook(&CwclWiFiEvents::OnAcmInterfaceArrival, &wclWiFiEvents, &CWiFiEventsDlg::AcmInterfaceArrival);
	__hook(&CwclWiFiEvents::OnAcmInterfaceRemoval, &wclWiFiEvents, &CWiFiEventsDlg::AcmInterfaceRemoval);
	__hook(&CwclWiFiEvents::OnAcmNetworkAvailable, &wclWiFiEvents, &CWiFiEventsDlg::AcmNetworkAvailable);
	__hook(&CwclWiFiEvents::OnAcmNetworkNotAvailable, &wclWiFiEvents, &CWiFiEventsDlg::AcmNetworkNotAvailable);
	__hook(&CwclWiFiEvents::OnAcmOperationalStateChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmOperationalStateChange);
	__hook(&CwclWiFiEvents::OnAcmPowerSettingChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmPowerSettingChange);
	__hook(&CwclWiFiEvents::OnAcmProfileBlocked, &wclWiFiEvents, &CWiFiEventsDlg::AcmProfileBlocked);
	__hook(&CwclWiFiEvents::OnAcmProfileChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmProfileChange);
	__hook(&CwclWiFiEvents::OnAcmProfileNameChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmProfileNameChange);
	__hook(&CwclWiFiEvents::OnAcmProfilesExhausted, &wclWiFiEvents, &CWiFiEventsDlg::AcmProfilesExhausted);
	__hook(&CwclWiFiEvents::OnAcmProfileUnblocked, &wclWiFiEvents, &CWiFiEventsDlg::AcmProfileUnblocked);
	__hook(&CwclWiFiEvents::OnAcmScanComplete, &wclWiFiEvents, &CWiFiEventsDlg::AcmScanComplete);
	__hook(&CwclWiFiEvents::OnAcmScanFail, &wclWiFiEvents, &CWiFiEventsDlg::AcmScanFail);
	__hook(&CwclWiFiEvents::OnAcmScanListRefresh, &wclWiFiEvents, &CWiFiEventsDlg::AcmScanListRefresh);
	__hook(&CwclWiFiEvents::OnAcmScreenPowerChange, &wclWiFiEvents, &CWiFiEventsDlg::AcmScreenPowerChange);

	__hook(&CwclWiFiEvents::OnHostedNetworkPeerStateChange, &wclWiFiEvents, &CWiFiEventsDlg::HostedNetworkPeerStateChange);
	__hook(&CwclWiFiEvents::OnHostedNetworkRadioStateChange, &wclWiFiEvents, &CWiFiEventsDlg::HostedNetworkRadioStateChange);
	__hook(&CwclWiFiEvents::OnHostedNetworkStateChange, &wclWiFiEvents, &CWiFiEventsDlg::HostedNetworkStateChange);

	__hook(&CwclWiFiEvents::OnMsmAdapterOperationModeChange, &wclWiFiEvents, &CWiFiEventsDlg::MsmAdapterOperationModeChange);
	__hook(&CwclWiFiEvents::OnMsmAdapterRemoval, &wclWiFiEvents, &CWiFiEventsDlg::MsmAdapterRemoval);
	__hook(&CwclWiFiEvents::OnMsmAssociated, &wclWiFiEvents, &CWiFiEventsDlg::MsmAssociated);
	__hook(&CwclWiFiEvents::OnMsmAssociating, &wclWiFiEvents, &CWiFiEventsDlg::MsmAssociating);
	__hook(&CwclWiFiEvents::OnMsmAuthenticating, &wclWiFiEvents, &CWiFiEventsDlg::MsmAuthenticating);
	__hook(&CwclWiFiEvents::OnMsmConnected, &wclWiFiEvents, &CWiFiEventsDlg::MsmConnected);
	__hook(&CwclWiFiEvents::OnMsmDisassociating, &wclWiFiEvents, &CWiFiEventsDlg::MsmDisassociating);
	__hook(&CwclWiFiEvents::OnMsmDisconnected, &wclWiFiEvents, &CWiFiEventsDlg::MsmDisconnected);
	__hook(&CwclWiFiEvents::OnMsmPeerJoin, &wclWiFiEvents, &CWiFiEventsDlg::MsmPeerJoin);
	__hook(&CwclWiFiEvents::OnMsmPeerLeave, &wclWiFiEvents, &CWiFiEventsDlg::MsmPeerLeave);
	__hook(&CwclWiFiEvents::OnMsmRadioStateChange, &wclWiFiEvents, &CWiFiEventsDlg::MsmRadioStateChange);
	__hook(&CwclWiFiEvents::OnMsmRoamingEnd, &wclWiFiEvents, &CWiFiEventsDlg::MsmRoamingEnd);
	__hook(&CwclWiFiEvents::OnMsmRoamingStart, &wclWiFiEvents, &CWiFiEventsDlg::MsmRoamingStart);
	__hook(&CwclWiFiEvents::OnMsmSignalQualityChange, &wclWiFiEvents, &CWiFiEventsDlg::MsmSignalQualityChange);
	__hook(&CwclWiFiEvents::OnMsmLinkDegraded, &wclWiFiEvents, &CWiFiEventsDlg::MsmLinkDegraded);
	__hook(&CwclWiFiEvents::OnMsmLinkImproved, &wclWiFiEvents, &CWiFiEventsDlg::MsmLinkImproved);

	__hook(&CwclWiFiEvents::OnOneXAuthRestarted, &wclWiFiEvents, &CWiFiEventsDlg::OneXAuthRestarted);
	__hook(&CwclWiFiEvents::OnOneXAuthUpdate, &wclWiFiEvents, &CWiFiEventsDlg::OneXAuthUpdate);

	__hook(&CwclWiFiEvents::OnIpChanged, &wclWiFiEvents, &CWiFiEventsDlg::IpChanged);

	__hook(&CwclPowerEventsMonitor::OnPowerStateChanged, &FPowerMonitor, &CWiFiEventsDlg::PowerStateChanged);
	
	FPowerMonitor.Open();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CWiFiEventsDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CWiFiEventsDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CWiFiEventsDlg::OnBnClickedButtonEventsOpen()
{
	ShowResult(wclWiFiEvents.Open());
}

void CWiFiEventsDlg::OnBnClickedButtonEventsClose()
{
	ShowResult(wclWiFiEvents.Close());
}

void CWiFiEventsDlg::OnBnClickedButtonEventsClear()
{
	lvEvents.DeleteAllItems();
}

void CWiFiEventsDlg::EventsAfterOpen(void* Sender)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(NULL, _T("AfterOpen"), _T(""), _T(""));
}

void CWiFiEventsDlg::EventsBeforeClose(void* Sender)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(NULL, _T("BeforeClose"), _T(""), _T(""));
}

void CWiFiEventsDlg::TraceEvent(const GUID* const Iface, const CString& EventName, 
	const CString& ParamName, const CString& ParamValue)
{
	CString Id;
	if (Iface == NULL)
		Id = _T("");
	else
		Id = GuidToString(*Iface);
	
	int i = lvEvents.GetItemCount();
	lvEvents.InsertItem(i, Id);
	lvEvents.SetItemText(i, 1, EventName);
	lvEvents.SetItemText(i, 2, ParamName);
	lvEvents.SetItemText(i, 3, ParamValue);
}

void CWiFiEventsDlg::AcmAdHocNetworkStateChange(void* Sender, const GUID& IfaceId, 
	const wclWiFiAdHocNetworkState State)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmAdHocNetworkStateChange"), _T("State"),
		GetEnumName(State));
}

void CWiFiEventsDlg::AcmAutoconfDisabled(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmAutoconfDisabled"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmAutoconfEnabled(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmAutoconfEnabled"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmBackgroundScanDisabled(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmBackgroundScanDisabled"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmBackgroundScanEnabled(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmBackgroundScanEnabled"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmBssTypeChange(void* Sender, const GUID& IfaceId, 
	const wclWiFiBssType BssType)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmBssTypeChange"), _T("BSS type"), GetEnumName(BssType));
}

void CWiFiEventsDlg::AcmConnectionAttemptFail(void* Sender, const GUID& IfaceId,
	const wclWiFiAcmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceAcmConnectionEvent(IfaceId, _T("AcmConnectionAttemptFail"), Data);
}

void CWiFiEventsDlg::TraceAcmConnectionEvent(const GUID& IfaceId, const CString& EventName,
	const wclWiFiAcmConnectionEventData& Data)
{
	TraceEvent(&IfaceId, EventName, _T("ConnectionMode"), GetEnumName(Data.ConnectionMode));
	TraceEvent(NULL, _T(""), _T("Profile name"), Data.ProfileName.c_str());
	TraceEvent(NULL, _T(""), _T("SSID"), Data.Ssid.c_str());
	TraceEvent(NULL, _T(""), _T("BSS type"), GetEnumName(Data.BssType));
	TraceEvent(NULL, _T(""), _T("Security enabled"), BoolToStr(Data.SecurityEnabled));
	
	CString Str  = IntToHex(Data.Reason);
	TraceEvent(NULL, _T(""), _T("Reason"), Str);

	Str = _T("");
	if (Data.Flags.find(cfAdHocNetworkFormed) != Data.Flags.end())
		Str += _T("cfAdHocNetworkFormed ");
	if (Data.Flags.find(cfConsoleUserProfile) != Data.Flags.end())
		Str += _T("cfAdHocNetworkFormed ");
	TraceEvent(NULL, _T(""), _T("Flags"), Str);
	
	TraceEvent(NULL, _T(""), _T("Profile XML"), Data.ProfileXml.c_str());
}

void CWiFiEventsDlg::AcmConnectionComplete(void* Sender, const GUID& IfaceId,
	const wclWiFiAcmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceAcmConnectionEvent(IfaceId, _T("AcmConnectionComplete"), Data);
}

void CWiFiEventsDlg::AcmConnectionStart(void* Sender, const GUID& IfaceId,
	const wclWiFiAcmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceAcmConnectionEvent(IfaceId, _T("AcmConnectionStart"), Data);
}

void CWiFiEventsDlg::AcmDisconnected(void* Sender, const GUID& IfaceId,
	const wclWiFiAcmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceAcmConnectionEvent(IfaceId, _T("AcmDisconnected"), Data);
}

void CWiFiEventsDlg::AcmDisconnecting(void* Sender, const GUID& IfaceId,
	const wclWiFiAcmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceAcmConnectionEvent(IfaceId, _T("AcmDisconnecting"), Data);
}

void CWiFiEventsDlg::AcmFilterListChange(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmFilterListChange"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmInterfaceArrival(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);
	
	TraceEvent(&IfaceId, _T("AcmInterfaceArrival"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmInterfaceRemoval(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmInterfaceRemoval"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmNetworkAvailable(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmNetworkAvailable"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmNetworkNotAvailable(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmNetworkNotAvailable"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmOperationalStateChange(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmOperationalStateChange"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmPowerSettingChange(void* Sender, const GUID& IfaceId,
	const wclWiFiPowerSetting Setting)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmOperationalStateChange"), _T("Setting"),
		GetEnumName(Setting));
}

void CWiFiEventsDlg::AcmProfileBlocked(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmProfileBlocked"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmProfileChange(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmProfileChange"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmProfileNameChange(void* Sender, const GUID& IfaceId, 
	const tstring& OldName, const tstring& NewName)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmProfileNameChange"), _T("OldName"), OldName.c_str());
	TraceEvent(NULL, _T(""), _T("NewName"), NewName.c_str());
}

void CWiFiEventsDlg::AcmProfilesExhausted(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmProfilesExhausted"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmProfileUnblocked(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmProfileUnblocked"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmScanComplete(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmScanComplete"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmScanFail(void* Sender, const GUID& IfaceId, 
	const int Reason)
{
	UNREFERENCED_PARAMETER(Sender);

	CString Str = IntToHex(Reason);
	TraceEvent(&IfaceId, _T("AcmScanFail"), _T("Reason"), Str);
}

void CWiFiEventsDlg::AcmScanListRefresh(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmScanListRefresh"), _T(""), _T(""));
}

void CWiFiEventsDlg::AcmScreenPowerChange(void* Sender, const GUID& IfaceId, 
	const bool SwitchedOn)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("AcmScreenPowerChange"), _T("SwitchedOn"), BoolToStr(SwitchedOn));
}

void CWiFiEventsDlg::HostedNetworkPeerStateChange(void* Sender, const GUID& IfaceId,
	const wclWiFiHostedNetworkPeerState& OldState, 
	const wclWiFiHostedNetworkPeerState& NewState, const int Reason)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("HostedNetworkPeerStateChange"), _T("Old MAC"), OldState.Mac.c_str());
	TraceEvent(NULL, _T(""), _T("Old authentication state"), GetEnumName(OldState.AuthState));
	TraceEvent(NULL, _T(""), _T("New MAC"), NewState.Mac.c_str());
	TraceEvent(NULL, _T(""), _T("New authentication state"), GetEnumName(NewState.AuthState));

	CString Str = IntToHex(Reason);
	TraceEvent(NULL, _T(""), _T("Reason"), Str);
}

void CWiFiEventsDlg::HostedNetworkRadioStateChange(void* Sender, const GUID& IfaceId,
	const wclWiFiRadioState SoftwareState, const wclWiFiRadioState HardwareState)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("HostedNetworkRadioStateChange"), _T("Software state"),
		GetEnumName(SoftwareState));
	TraceEvent(NULL, _T(""), _T("Hardware state"), GetEnumName(HardwareState));
}

void CWiFiEventsDlg::HostedNetworkStateChange(void* Sender, const GUID& IfaceId,
	const wclWiFiHostedNetworkState OldState, const wclWiFiHostedNetworkState NewState, 
	const int Reason)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("HostedNetworkStateChange"), _T("Old state"), GetEnumName(OldState));
	TraceEvent(NULL, _T(""), _T("New state"), GetEnumName(NewState));

	CString Str = IntToHex(Reason);
	TraceEvent(NULL, _T(""), _T("Reason"), Str);
}

void CWiFiEventsDlg::MsmAdapterOperationModeChange(void* Sender, const GUID& IfaceId,
	const wclWiFiOperationMode Mode)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("MsmAdapterOperationModeChange"), _T("Mode"), GetEnumName(Mode));
}

void CWiFiEventsDlg::MsmAdapterRemoval(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData &Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmAdapterRemoval"), Data);
}

void CWiFiEventsDlg::MsmAssociated(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmAssociated"), Data);
}

void CWiFiEventsDlg::MsmAssociating(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmAssociating"), Data);
}

void CWiFiEventsDlg::MsmAuthenticating(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmAuthenticating"), Data);
}

void CWiFiEventsDlg::MsmConnected(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmConnected"), Data);
}

void CWiFiEventsDlg::MsmDisassociating(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmDisassociating"), Data);
}

void CWiFiEventsDlg::MsmDisconnected(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmDisconnected"), Data);
}

void CWiFiEventsDlg::MsmPeerJoin(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmPeerJoin"), Data);
}

void CWiFiEventsDlg::MsmPeerLeave(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmPeerLeave"), Data);
}

void CWiFiEventsDlg::MsmRadioStateChange(void* Sender, const GUID& IfaceId,
	const wclWiFiPhyRadioState& State)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("MsmRadioStateChange"), _T("PHY"), GetEnumName(State.Phy));
	TraceEvent(NULL, _T(""), _T("Software state"), GetEnumName(State.SoftwareState));
	TraceEvent(NULL, _T(""), _T("Hardware state"), GetEnumName(State.HardwareState));
}

void CWiFiEventsDlg::MsmRoamingEnd(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmRoamingEnd"), Data);
}

void CWiFiEventsDlg::MsmRoamingStart(void* Sender, const GUID& IfaceId,
	const wclWiFiMsmConnectionEventData& Data)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceMsmConnectionEvent(IfaceId, _T("MsmRoamingStart"), Data);
}

void CWiFiEventsDlg::MsmSignalQualityChange(void* Sender, const GUID& IfaceId, 
	const unsigned long Quality)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("MsmSignalQualityChange"), _T("Quality"), IntToStr(Quality));
}

void CWiFiEventsDlg::TraceMsmConnectionEvent(const GUID& IfaceId, const CString& EventName,
	const wclWiFiMsmConnectionEventData& Data)
{
	TraceEvent(&IfaceId, EventName, _T("ConnectionMode"), GetEnumName(Data.ConnectionMode));
	TraceEvent(NULL, _T(""), _T("Profile name"), Data.ProfileName.c_str());
	TraceEvent(NULL, _T(""), _T("SSID"), Data.Ssid.c_str());
	TraceEvent(NULL, _T(""), _T("BSS type"), GetEnumName(Data.BssType));
	TraceEvent(NULL, _T(""), _T("MAC"), Data.Mac.c_str());
	TraceEvent(NULL, _T(""), _T("Security enabled"), BoolToStr(Data.SecurityEnabled));
	TraceEvent(NULL, _T(""), _T("First peer"), BoolToStr(Data.FirstPeer));
	TraceEvent(NULL, _T(""), _T("Last peer"), BoolToStr(Data.LastPeer));

	CString Str = IntToHex(Data.Reason);
	TraceEvent(NULL, _T(""), _T("Reason"), Str);
}

void CWiFiEventsDlg::OneXAuthRestarted(void* Sender, const GUID& IfaceId, 
	const int Reason)
{
	UNREFERENCED_PARAMETER(Sender);

	CString Str = IntToHex(Reason);
	TraceEvent(&IfaceId, _T("OneXAuthRestarted"), _T("Reason"), Str);
}

void CWiFiEventsDlg::OnDestroy()
{
	CDialog::OnDestroy();

	wclWiFiEvents.Close();

	FPowerMonitor.Close();

	__unhook(&wclWiFiEvents);
	__unhook(&FPowerMonitor);
}

void CWiFiEventsDlg::PowerStateChanged(void* Sender, const wclPowerState State)
{
	UNREFERENCED_PARAMETER(Sender);

	switch (State)
	{
		case psResumeAutomatic:
			TraceEvent(NULL, _T("Power"), _T("State"), _T("psResumeAutomatic"));
			break;

		case psResume:
			TraceEvent(NULL, _T("Power"), _T("State"), _T("psResume"));
			break;

		case psSuspend:
			TraceEvent(NULL, _T("Power"), _T("State"), _T("psSuspend"));
			break;

		case psPowerStatusChanged:
			TraceEvent(NULL, _T("Power"), _T("State"), _T("psPowerStatusChanged"));
			break;

		case psUnknown:
			TraceEvent(NULL, _T("Power"), _T("State"), _T("psUnknown"));
			break;
	}
}

void CWiFiEventsDlg::IpChanged(void* Sender, const GUID& IfaceId, 
	const wclWiFiIpSettings& Old, const wclWiFiIpSettings& New)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("IP changed"), _T("Old address"), Old.Address.c_str());
	TraceEvent(NULL, _T("IP changed"), _T("New address"), New.Address.c_str());
}

void CWiFiEventsDlg::OneXAuthUpdate(void* Sender, const GUID& IfaceId, 
	const wclWiFiOneXStatusUpdate& State)
{
	UNREFERENCED_PARAMETER(Sender);

	CString Str;
	switch (State.Status.Status)
	{
		case oxAuthNotStarted:
			Str = _T("oxAuthNotStarted");
			break;
		case oxAuthInProgress:
			Str = _T("oxAuthInProgress");
			break;
		case oxAuthNoAuthenticatorFound:
			Str = _T("oxAuthNoAuthenticatorFound");
			break;
		case oxAuthSuccess:
			Str = _T("oxAuthSuccess");
			break;
		case oxAuthFailure:
			Str = _T("oxAuthFailure");
			break;
		case oxAuthInvalid:
			Str = _T("oxAuthInvalid");
			break;
		default:
			Str = _T("");
			break;
	}
	TraceEvent(&IfaceId, _T("OneXAuthUpdate"), _T("Status"), Str);
	TraceEvent(NULL, _T(""), _T("Status.Reason"), _T("0x") + IntToHex(State.Status.Reason));
	TraceEvent(NULL, _T(""), _T("Status.Error"), _T("0x") + IntToHex(State.Status.Error));
	
	switch (State.BackendSupport)
	{
		case oxEapMethodBackendSupportUnknown:
			Str = _T("oxEapMethodBackendSupportUnknown");
			break;
		case oxEapMethodBackendSupported:
			Str = _T("oxEapMethodBackendSupported");
			break;
		case oxEapMethodBackendUnsupported:
			Str = _T("oxEapMethodBackendUnsupported");
			break;
		default:
			Str = _T("");
			break;
	}
	TraceEvent(NULL, _T(""), _T("BackendSupport"), Str);
	
	if (State.BackendEngaged)
		TraceEvent(NULL, _T(""), _T("BackendEngaged"), _T("True"));
	else
		TraceEvent(NULL, _T(""), _T("BackendEngaged"), _T("False"));
	
	if (State.AuthParams.UpdatePending)
		TraceEvent(NULL, _T(""), _T("AuthParams.UpdatePending"), _T("True"));
	else
		TraceEvent(NULL, _T(""), _T("AuthParams.UpdatePending"), _T("False"));
	
	switch (State.AuthParams.Profile.SupplicantMode)
	{
		case oxSupplicantModeInhibitTransmission:
			Str = _T("oxSupplicantModeInhibitTransmission");
			break;
		case oxSupplicantModeLearn:
			Str = _T("oxSupplicantModeLearn");
			break;
		case oxSupplicantModeCompliant:
			Str = _T("oxSupplicantModeCompliant");
			break;
		case oxSupplicantModeInvalid:
			Str = _T("oxSupplicantModeInvalid");
			break;
		default:
			Str = _T("");
			break;
	}
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.SupplicantMode"), Str);
	
	switch (State.AuthParams.Profile.AuthMode)
	{
		case oxAuthModeMachineOrUser:
			Str = _T("oxAuthModeMachineOrUser");
			break;
		case oxAuthModeMachineOnly:
			Str = _T("oxAuthModeMachineOnly");
			break;
		case oxAuthModeUserOnly:
			Str = _T("oxAuthModeUserOnly");
			break;
		case oxAuthModeGuest:
			Str = _T("oxAuthModeGuest");
			break;
		case oxAuthModeUnspecified:
			Str = _T("oxAuthModeUnspecified");
			break;
		case oxAuthModeInvalid:
			Str = _T("oxAuthModeInvalid");
			break;
		default:
			Str = _T("");
			break;
	}
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.AuthMode"), Str);
	
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.HeldPeriod"), IntToStr(State.AuthParams.Profile.HeldPeriod));
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.AuthPeriod"), IntToStr(State.AuthParams.Profile.AuthPeriod));
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.StartPeriod"), IntToStr(State.AuthParams.Profile.StartPeriod));
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.MaxStart"), IntToStr(State.AuthParams.Profile.MaxStart));
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.MaxAuthFailures"), IntToStr(State.AuthParams.Profile.MaxAuthFailures));
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.NetworkAuthTimeout"), IntToStr(State.AuthParams.Profile.NetworkAuthTimeout));
	TraceEvent(NULL, _T(""), _T("AuthParams.Profile.NetworkAuthWithUITimeout"), IntToStr(State.AuthParams.Profile.NetworkAuthWithUITimeout));
	
	if (State.AuthParams.Profile.AllowLogonDialogs)
		TraceEvent(NULL, _T(""), _T("AuthParams.Profile.AllowLogonDialogs"), _T("True"));
	else
		TraceEvent(NULL, _T(""), _T("AuthParams.Profile.AllowLogonDialogs"), _T("False"));
	
	if (State.AuthParams.Profile.UserBasedVLan)
		TraceEvent(NULL, _T(""), _T("AuthParams.Profile.UserBasedVLan"), _T("True"));
	else
		TraceEvent(NULL, _T(""), _T("AuthParams.Profile.UserBasedVLan"), _T("False"));
	
	switch (State.AuthParams.AuthIdentity)
	{
		case oxAuthIdentityNone:
			Str = _T("");
			break;
		case oxAuthIdentityMachine:
			Str = _T("");
			break;
		case oxAuthIdentityUser:
			Str = _T("");
			break;
		case oxAuthIdentityExplicitUser:
			Str = _T("");
			break;
		case oxAuthIdentityGuest:
			Str = _T("");
			break;
		case oxAuthIdentityInvalid:
			Str = _T("");
			break;
		case oxAuthIdentityUnknown:
			Str = _T("");
			break;
		default:
			Str = _T("");
			break;
	}
	TraceEvent(NULL, _T(""), _T("AuthParams.AuthIdentity"), Str);
	
	switch (State.AuthParams.QuarantineState)
	{
		case isUnknonw:
			Str = _T("isUnknonw");
			break;
		case isNotRestricted:
			Str = _T("isNotRestricted");
			break;
		case isInProbation:
			Str = _T("isInProbation");
			break;
		case isRestrictedAccess:
			Str = _T("isRestrictedAccess");
		case isInvalid:
			Str = _T("isInvalid");
			break;
		default:
			Str = _T("");
			break;
	}
	TraceEvent(NULL, _T(""), _T("AuthParams.QuarantineState"), Str);
	
	TraceEvent(NULL, _T(""), _T("AuthParams.SessiondId"), IntToStr(State.AuthParams.SessiondId));
	TraceEvent(NULL, _T(""), _T("AuthParams.Identity"), CString(State.AuthParams.Identity.c_str()));
	TraceEvent(NULL, _T(""), _T("AuthParams.UserName"), CString(State.AuthParams.UserName.c_str()));
	TraceEvent(NULL, _T(""), _T("AuthParams.Domain"), CString(State.AuthParams.Domain.c_str()));
	
	TraceEvent(NULL, _T(""), _T("EapError.Error"), _T("0x") + IntToHex(State.EapError.Error));
	
	TraceEvent(NULL, _T(""), _T("EapError.MethodType.EapType.EapType"), IntToStr(State.EapError.MethodType.EapType.EapType));
	TraceEvent(NULL, _T(""), _T("EapError.MethodType.EapType.VendorId"), IntToStr(State.EapError.MethodType.EapType.VendorId));
	TraceEvent(NULL, _T(""), _T("EapError.MethodType.EapType.VendorType"), IntToStr(State.EapError.MethodType.EapType.VendorType));
	
	TraceEvent(NULL, _T(""), _T("EapError.MethodType.AuthorId"), IntToStr(State.EapError.MethodType.AuthorId));
	
	TraceEvent(NULL, _T(""), _T("EapError.Reason"), _T("0x") + IntToHex(State.EapError.Reason));
	TraceEvent(NULL, _T(""), _T("EapError.RootCauseGuid"), GuidToString(State.EapError.RootCauseGuid));
	TraceEvent(NULL, _T(""), _T("EapError.RepairGuid"), GuidToString(State.EapError.RepairGuid));
	TraceEvent(NULL, _T(""), _T("EapError.HelpLinkGuid"), GuidToString(State.EapError.HelpLinkGuid));
	TraceEvent(NULL, _T(""), _T("EapError.RootCauseString"), CString(State.EapError.RootCauseString.c_str()));
	TraceEvent(NULL, _T(""), _T("EapError.RepairString"), CString(State.EapError.RepairString.c_str()));
}

void CWiFiEventsDlg::MsmLinkDegraded(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);
	
	TraceEvent(&IfaceId, _T("MsmLinkDegraded"), _T(""), _T(""));
}

void CWiFiEventsDlg::MsmLinkImproved(void* Sender, const GUID& IfaceId)
{
	UNREFERENCED_PARAMETER(Sender);

	TraceEvent(&IfaceId, _T("MsmLinkImproved"), _T(""), _T(""));
}