📄 loader.c
字号:
//---------------------------------------------------------------------------
// Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//--------------------------------------------------------------------------
//
// File: loader.c
// Source file for platform specific SDIO WLAN functions
//------------------------------------------------------------------------------
#include "precomp.h"
#define MAX_MINIPORT_NAME_PATH 256
#define MAX_NUMBER_OF_ADAPTERS 8
#define LOADER_INSTANCE_KEY TEXT("Instance")
// miniport instance information
typedef struct _MINIPORT_INSTANCE_INFO {
WCHAR MiniportName[MAX_MINIPORT_NAME_PATH];
WCHAR MiniportInstance[MAX_MINIPORT_NAME_PATH];
WCHAR RegPath[MAX_MINIPORT_NAME_PATH];
WCHAR ActiveKeyPath[MAX_MINIPORT_NAME_PATH];
ULONG InstanceNumber;
} MINIPORT_INSTANCE_INFO, * PMINIPORT_INSTANCE_INFO;
BOOL AllocatedInstance[MAX_NUMBER_OF_ADAPTERS];
CRITICAL_SECTION LoaderCriticalSection;
///////////////////////////////////////////////////////////////////////////////
// LoaderEntry - init loader
// Input: hInstance - the instance that is attaching
// Reason - the reason for attaching
// pReserved - not much
// Output:
// Return: Always returns TRUE
// Notes: this is only used to initialize the zones
///////////////////////////////////////////////////////////////////////////////
BOOL LoaderEntry(HINSTANCE hInstance,
ULONG Reason,
LPVOID pReserved)
{
if ( Reason == DLL_PROCESS_ATTACH ) {
DEBUGREGISTER(hInstance);
InitializeCriticalSection(&LoaderCriticalSection);
memset(&AllocatedInstance, 0, sizeof(AllocatedInstance));
}
if ( Reason == DLL_PROCESS_DETACH ) {
DeleteCriticalSection(&LoaderCriticalSection);
}
return(TRUE);
}
///////////////////////////////////////////////////////////////////////////////
// LoadMiniport - load the miniport for this instance
// Input: pInstance - information for this instance
// Output:
// Return: TRUE if successful
// Notes:
///////////////////////////////////////////////////////////////////////////////
BOOL LoadMiniport(PMINIPORT_INSTANCE_INFO pInstance)
{
HKEY hKey; // registry key
DWORD win32Status; // status
DWORD dataSize; // data size for query
WCHAR stringBuff[128]; // string buffer
WCHAR instanceKey[32]; // instance name
WCHAR instanceNumber[10]; // instance number
WCHAR *token; // tokenizer
NDIS_STATUS NdisStatus; // ndis status
// open the registry path for this instance
if ((win32Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
pInstance->RegPath,
0,
KEY_ALL_ACCESS,
&hKey)) != ERROR_SUCCESS) {
DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR:Failed to open path %s; %d \n"),
pInstance->RegPath, win32Status));
return FALSE;
}
dataSize = sizeof(stringBuff);
// build up the instance key
wcscpy(instanceKey,LOADER_INSTANCE_KEY);
_ultow(pInstance->InstanceNumber, instanceNumber, 10);
wcscat(instanceKey, instanceNumber);
// retrieve the real reg path to the device parameters
if (RegQueryValueEx(hKey,
instanceKey,
0,
NULL,
(PUCHAR)stringBuff,
&dataSize) != ERROR_SUCCESS) {
DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to get the instance key : %d \n"), instanceKey));
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Tokenizing instance information: %s \n"), stringBuff));
// extract the miniport name and instance name, in the form of "<Miniport Name>:<Miniport Instance>
token = wcstok(stringBuff, TEXT(":"));
if (token != NULL) {
wcscpy(pInstance->MiniportName, token);
// search for the next one
token = wcstok( NULL, TEXT(":"));
if (token != NULL) {
wcscpy(pInstance->MiniportInstance, token);
} else {
DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to get miniport instance \n")));
return FALSE;
}
} else {
DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to get miniport name \n")));
return FALSE;
}
// build up the miniport instance path in order to stick in the "ActivePath" key
wcscpy(stringBuff,TEXT("\\Comm\\"));
wcscat(stringBuff,pInstance->MiniportInstance);
wcscat(stringBuff,TEXT("\\Parms"));
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Miniport instance path %s \n"), stringBuff));
if ((win32Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
stringBuff,
0,
KEY_ALL_ACCESS,
&hKey)) != ERROR_SUCCESS) {
DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR:Failed to open path %s; %d \n"),
stringBuff, win32Status));
return FALSE;
}
// make sure the key is deleted first
RegDeleteKey(hKey, TEXT("ActivePath"));
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Storing ActiveKey Path %s \n"), pInstance->ActiveKeyPath));
// save the active ActivePath in the registry path for the miniport.
// The miniport portion will look up this key
if (RegSetValueEx(hKey,
TEXT("ActivePath"),
0,
REG_SZ,
(PUCHAR)pInstance->ActiveKeyPath,
((sizeof(WCHAR))*(wcslen(pInstance->ActiveKeyPath) + 1))) != ERROR_SUCCESS) {
DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to set ActiveKey path \n")));
RegCloseKey(hKey);
return FALSE;
}
// close the key
RegCloseKey(hKey);
// register the adapter
NdisRegisterAdapter(&NdisStatus,
pInstance->MiniportName,
pInstance->MiniportInstance);
if ( NdisStatus != NDIS_STATUS_SUCCESS ) {
return FALSE;
}
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: NdisRegisterAdapter Returned.\n")));
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// UnloadMiniport - unload the miniport
// Input: pInstance - the instance to unload
// Output:
// Return:
// Notes:
///////////////////////////////////////////////////////////////////////////////
VOID UnloadMiniport(PMINIPORT_INSTANCE_INFO pInstance)
{
NDIS_STATUS NdisStatus;
HKEY hKey; // registry key
DWORD win32Status; // status
WCHAR stringBuff[128]; // string buffer
DbgPrintZo(SDCARD_ZONE_INIT,
(TEXT("SDNDISLDR: Unloading Miniport Instance %s \n"),
pInstance->MiniportInstance));
NdisDeregisterAdapter(&NdisStatus, pInstance->MiniportInstance);
DbgPrintZo(SDCARD_ZONE_INIT,
(TEXT("SDNDISLDR: Miniport Unloaded 0x%08X \n"),
NdisStatus));
wcscpy(stringBuff,TEXT("\\Comm\\"));
wcscat(stringBuff,pInstance->MiniportInstance);
wcscat(stringBuff,TEXT("\\Parms"));
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Miniport instance path %s \n"), stringBuff));
if ((win32Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
stringBuff,
0,
KEY_ALL_ACCESS,
&hKey)) != ERROR_SUCCESS) {
DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR:Failed to open path %s; %d \n"),
stringBuff, win32Status));
return;
}
RegDeleteValue(hKey, TEXT("ActivePath"));
DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Storing ActiveKey Path %s \n"), pInstance->ActiveKeyPath));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -