//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name:
Wzcui.c
Abstract:
Code for Wireless Zero Config dialogs. This allows user to set
the preferred SSID list for 802.11 networks, and configure various
parameters such as WEP key.
Functions:
Notes:
The zero config service is implemented in two parts -- the wzcsvc.dll which
runs in device.exe and communicates with wireless miniports, and wczsapi.dll
which is loaded into the application context and provides APIs to communicate
with wzcsvc.
--*/
#include "stdafx.h"
#include "wzcuip.h"
// Dynamically load function pointers, as WZC may not be available in all configs.
BOOL g_fWZCInit = FALSE;
PFN_WZCQueryInterface pfnWZCQueryInterface;
PFN_WZCSetInterface pfnWZCSetInterface;
PFN_WZCRefreshInterface pfnWZCRefreshInterface;
PFN_WZCEnumEapExtensions pfnWZCEnumEapExtensions;
PFN_WZCDeleteIntfObj pfnWZCDeleteIntfObj;
PFN_WZCQueryContext pfnWZCQueryContext;
PFN_WZCSetContext pfnWZCSetContext;
PFN_WZCPassword2Key pfnWZCPassword2Key;
PFN_WZCEnumInterfaces pfnWZCEnumInterfaces;
WCHAR g_WirelessCard1[MAX_PATH] = L""; // 1st wireless card found by WZC query
INTF_ENTRY gIntfEntry = {0};
#define wszGuidConstStr L"JAGUARGSP1"
//#define wszGuidConstStr L"SDIO86861"
#define WIFI_AP_MAX_COUNT 50
#define SCAN_BUF_SIZE (sizeof(WZC_WLAN_CONFIG)*WIFI_AP_MAX_COUNT + sizeof(ULONG) + sizeof(ULONG))
PUCHAR m_pScanQueryBuf = NULL;
WZC_802_11_CONFIG_LIST *m_pScanList = NULL;
PUCHAR m_pPreferListBuf = NULL;
WZC_802_11_CONFIG_LIST *m_pPreferList = NULL;
CRITICAL_SECTION g_csLock;
#define WZCQCFG_LOCK EnterCriticalSection(&g_csLock)
#define WZCQCFG_UNLOCK LeaveCriticalSection(&g_csLock)
void
InterpretEncryptionKeyValue
// interpret key value then fill wzcConfig1.KeyLength and KeyMaterial[]
// wzcConfig1.Privacy should be initialized before calling.
// key is interpreted differently based on the wzcConfig1.Privacy
// wzcConfig1.Privacy could be one of these
// Ndis802_11WEPEnabled = WEP key
// Ndis802_11Encryption2Enabled = TKIP/WPA key
(
IN OUT WZC_WLAN_CONFIG& wzcConfig1,
IN WCHAR *szEncryptionKey,
IN BOOL& bNeed8021X // this becomes TRUE if szEncryptionKey is "auto"
);
void
AddToPreferredNetworkListOrg
// adding to the [Preferred Networks]
// [Preferred Networks] is a list of SSIDs in preference order.
// WZC continuously scans available SSIDs and attempt to connect to the most preferable SSID.
(
IN WCHAR *szWiFiCard,
IN WZC_WLAN_CONFIG& wzcConfig1,
IN WCHAR *szSsidToConnect
);
DWORD GetWZCRescanTime();
BOOL
InitZeroConfig(void)
{
HINSTANCE hWZCLib = NULL;
if (g_fWZCInit) {
return TRUE; // Already initialized
}
// See if zero config API present in system
if ((hWZCLib = LoadLibrary(L"wzcsapi.dll")) == NULL) {
DEBUGMSG(ZONE_WARN,(TEXT("!WZCUI: WZCAPI.DLL not present in system\r\n")));
return FALSE;
}
pfnWZCQueryInterface = (PFN_WZCQueryInterface)GetProcAddress(hWZCLib,L"WZCQueryInterface");
pfnWZCSetInterface = (PFN_WZCSetInterface)GetProcAddress(hWZCLib,L"WZCSetInterface");
pfnWZCRefreshInterface = (PFN_WZCRefreshInterface)GetProcAddress(hWZCLib,L"WZCRefreshInterface");
pfnWZCEnumEapExtensions = (PFN_WZCEnumEapExtensions)GetProcAddress(hWZCLib,L"WZCEnumEapExtensions");
pfnWZCDeleteIntfObj = (PFN_WZCDeleteIntfObj)GetProcAddress(hWZCLib,L"WZCDeleteIntfObj");
pfnWZCQueryContext = (PFN_WZCQueryContext)GetProcAddress(hWZCLib,L"WZCQueryContext");
pfnWZCSetContext = (PFN_WZCSetContext)GetProcAddress(hWZCLib,L"WZCSetContext");
pfnWZCPassword2Key = (PFN_WZCPassword2Key)GetProcAddress(hWZCLib,L"WZCPassword2Key");
pfnWZCEnumInterfaces = (PFN_WZCEnumInterfaces)GetProcAddress(hWZCLib,L"WZCEnumInterfaces");
if ((pfnWZCQueryInterface == NULL) ||
(pfnWZCSetInterface == NULL) ||
(pfnWZCRefreshInterface == NULL) ||
(pfnWZCEnumEapExtensions == NULL)||
(pfnWZCDeleteIntfObj == NULL) ||
(pfnWZCPassword2Key == NULL)||
(pfnWZCEnumInterfaces == NULL) ||
(pfnWZCSetContext == NULL) ||
(pfnWZCQueryContext == NULL)) {
DEBUGMSG(ZONE_ERROR,(TEXT("!WZCUI: WZC APis not present in system\r\n")));
FreeLibrary(hWZCLib);
return FALSE;
}
g_fWZCInit = TRUE;
return TRUE;
}
//PWLAN_CONFIG_LISTENT
//AllocAndInitConfigListEnt(DWORD dwFlags, PWZC_WLAN_CONFIG pwzcConfig)
//{
// PWLAN_CONFIG_LISTENT pListEnt;
// if ((pListEnt = (PWLAN_CONFIG_LISTENT)LocalAlloc(LPTR,sizeof(WLAN_CONFIG_LISTENT))) == NULL)
// return NULL;
// pListEnt->dwFlags = dwFlags;
// memcpy(&pListEnt->wzcConfig,pwzcConfig,sizeof(WZC_WLAN_CONFIG));
// pListEnt->pPrev = pListEnt->pNext = pListEnt;
// pListEnt->nListIndex = -1;
// return pListEnt;
//}
//
//void
//FreeConfigListEnt(PWLAN_CONFIG_LISTENT pListEnt)
//{
// pListEnt->pPrev->pNext = pListEnt->pNext;
// pListEnt->pNext->pPrev = pListEnt->pPrev;
//
// #ifdef DEBUG
// pListEnt->pNext = NULL;
// pListEnt->pPrev = NULL;
// #endif // DEBUG
//
// LocalFree(pListEnt);
//}
BOOL
ConfigMatch(PWZC_WLAN_CONFIG pCfg1, PWZC_WLAN_CONFIG pCfg2)
{
BOOL bMatch;
// check whether the InfrastructureMode matches
bMatch = (pCfg1->InfrastructureMode == pCfg2->InfrastructureMode);
// check whether the SSIDs are of the same length
bMatch = bMatch && (pCfg1->Ssid.SsidLength == pCfg2->Ssid.SsidLength);
if (bMatch && pCfg1->Ssid.SsidLength != 0)
{
// in case of Non empty SSIDs, check if they're the same
bMatch = (memcmp(pCfg1->Ssid.Ssid,
pCfg2->Ssid.Ssid,
pCfg1->Ssid.SsidLength)) == 0;
}
return bMatch;
}
BOOL
IsConfigInList(WLAN_CONFIG_LISTENT *pHdList, PWZC_WLAN_CONFIG pwzcConfig, WLAN_CONFIG_LISTENT **ppMatchingConfig)
{
BOOL bYes = FALSE;
if (pHdList != NULL)
{
WLAN_CONFIG_LISTENT *pConfig;
pConfig = pHdList;
do
{
if (ConfigMatch(&pConfig->wzcConfig, pwzcConfig))
{
if (ppMatchingConfig != NULL)
*ppMatchingConfig = pConfig;
bYes = TRUE;
break;
}
pConfig = pConfig->pNext;
} while(pConfig != pHdList);
}
return bYes;
}
/*++
Routine Name:
RefreshZeroConfigThread
Routine Description:
This thread refreshes ZeroConfig and queries it for updated networks.
Arguments:
pv: HWND of the wireless dialog whose adapter should be queried
--*/
//DWORD WINAPI RefreshZeroConfigThread(LPVOID pv)
//DWORD RefreshZeroConfig()
//{
// //HWND hwndDlg = (HWND) pv;
// HRESULT hr = S_OK;
// DWORD dwOutFlags = 0;
// //INT i = 0;
// //SystrayIcon* pSysIcon = NULL;
// //BOOL fAssociated = FALSE;
// //WLAN_CONFIG_LISTENT *pConfig = NULL;
// //DWORD dwWait;
// //HANDLE h;
//
// WZCQCFG_LOCK;
//
// //DEBUGMSG(ZONE_MISC, (TEXT("NETUIQC: --- Refresh Zero Config ---")));
//
// //// Get the systray icon for the given window
// //hr = GetDeviceSystrayIcon(GetParen
- 1
- 2
前往页