📄 wince.c
字号:
//
// Copyright (c) Renesas Technology Corp. 1999-2003 All Rights Reserved.
//
// LAN91C111 network hardware driver
//
//----------------------------------------------------------------------------
//
// FILE : WINCE.C
// CREATED : 1998. 4.18 (for NE2000 driver)
// MODIFIED : 2003.08.06
// AUTHOR : Renesas Technology Corp.
// HARDWARE : RENESAS HS7751RSTC01H (S1-E, ITS-DS5)
// TARGET OS : Microsoft(R) Windows(R) CE .NET 4.2
// FUNCTION : WinCE OS specific part of LAN driver
// HISTORY :
// 1999.04.26
// - Released as SMSC LAN91C94 driver for PFM-DS6x by modifying
// NE2000 driver in PB2.12 reference drivers.
// (Detailed history for PFM-DS6x are omitted.)
// 2002.04.??
// - Diverted to LAN91C111 driver for HS7751RSTC01H without
// modification.
// 2002.09.05
// - Header style is changed and file informations are added.
/*++
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.
Copyright (c) 1995-1998 Microsoft Corporation. All rights reserved.
--*/
#include <windows.h>
#include <ndis.h>
#include <cardserv.h>
#include <cardapi.h>
#include <tuple.h>
#include "celanhw.h"
#include "celansw.h"
LPWSTR FindDetectKey(VOID);
#ifdef DEBUG
//
// These defines must match the ZONE_* defines in CELANSW.H
//
#define DBG_ERROR 1
#define DBG_WARN 2
#define DBG_FUNCTION 4
#define DBG_INIT 8
#define DBG_INTR 16
#define DBG_RCV 32
#define DBG_XMIT 64
#define DBG_COV1 128
DBGPARAM dpCurSettings = {
TEXT("CELAN"), {
TEXT("Errors"),TEXT("Warnings"),TEXT("Functions"),TEXT("Init"),
TEXT("Interrupts"),TEXT("Receives"),TEXT("Transmits"),TEXT("DBG_COV1"),
TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),
TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined") },
DBG_ERROR | DBG_WARN | DBG_FUNCTION| DBG_INIT /*0xffff*/
};
#endif // DEBUG
typedef struct _REG_VALUE_DESCR {
LPWSTR val_name;
DWORD val_type;
PBYTE val_data;
} REG_VALUE_DESCR, * PREG_VALUE_DESCR;
// Values for [HKEY_LOCAL_MACHINE\Drivers\PCMCIA\Detect\40]
REG_VALUE_DESCR DetectKeyValues[] = {
(TEXT("Dll")), REG_SZ, (PBYTE)(TEXT("CELAN.DLL")),
(TEXT("Entry")), REG_SZ, (PBYTE)(TEXT("DetectCELAN")),
NULL, 0, NULL
};
// Values for [HKEY_LOCAL_MACHINE\Drivers\PCMCIA\CELAN]
REG_VALUE_DESCR PcmKeyValues[] = {
(TEXT("Dll")), REG_SZ, (PBYTE)(TEXT("ndis.dll")),
(TEXT("Prefix")), REG_SZ, (PBYTE)(TEXT("NDS")),
(TEXT("Miniport")), REG_SZ, (PBYTE)(TEXT("CELAN")),
NULL, 0, NULL
};
// Values for [HKEY_LOCAL_MACHINE\Comm\CELAN]
// and [HKEY_LOCAL_MACHINE\Comm\CELAN1]
REG_VALUE_DESCR CommKeyValues[] = {
(TEXT("DisplayName")), REG_SZ, (PBYTE)(TEXT("CELAN Compatible Ethernet Driver")),
(TEXT("Group")), REG_SZ, (PBYTE)(TEXT("NDIS")),
(TEXT("ImagePath")), REG_SZ, (PBYTE)(TEXT("celan.dll")),
NULL, 0, NULL
};
// Values for [HKEY_LOCAL_MACHINE\Comm\CELAN1\Parms]
REG_VALUE_DESCR ParmKeyValues[] = {
(TEXT("BusNumber")), REG_DWORD, (PBYTE)0,
(TEXT("BusType")), REG_DWORD, (PBYTE)8,
(TEXT("InterruptNumber")), REG_DWORD, (PBYTE)03,
(TEXT("IoBaseAddress")), REG_DWORD, (PBYTE)768, // 0x0300
(TEXT("Transceiver")), REG_DWORD, (PBYTE)3,
(TEXT("CardType")), REG_DWORD, (PBYTE)1,
NULL, 0, NULL
};
// Values for [HKEY_LOCAL_MACHINE\Comm\CELAN1]
REG_VALUE_DESCR LinkageKeyValues[] = {
(TEXT("Route")), REG_MULTI_SZ, (PBYTE)(TEXT("CELAN1")),
NULL, 0, NULL
};
PREG_VALUE_DESCR Values[] = {
PcmKeyValues,
CommKeyValues,
CommKeyValues,
ParmKeyValues,
LinkageKeyValues
};
LPWSTR KeyNames[] = {
(TEXT("Drivers\\PCMCIA\\CELAN")),
(TEXT("Comm\\CELAN")),
(TEXT("Comm\\CELAN1")),
(TEXT("Comm\\CELAN1\\Parms")),
(TEXT("Comm\\CELAN\\Linkage"))
};
//
// Standard Windows DLL entrypoint.
// Since Windows CE NDIS miniports are implemented as DLLs, a DLL entrypoint is
// needed.
//
BOOL __stdcall
DllEntry(
HANDLE hDLL,
DWORD dwReason,
LPVOID lpReserved
)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
DEBUGREGISTER(hDLL);
DEBUGMSG(ZONE_INIT, (TEXT("CELAN: DLL_PROCESS_ATTACH\n")));
break;
case DLL_PROCESS_DETACH:
DEBUGMSG(ZONE_INIT, (TEXT("CELAN: DLL_PROCESS_DETACH\n")));
break;
}
return TRUE;
}
//
// Add the specified key and its values to the registry under HKEY_LOCAL_MACHINE
//
// NOTE: This function only supports REG_MULTI_SZ strings with one item.
//
BOOL
AddKeyValues(
LPWSTR KeyName,
PREG_VALUE_DESCR Vals
)
{
DWORD Status;
DWORD dwDisp;
HKEY hKey;
PREG_VALUE_DESCR pValue;
DWORD ValLen;
PBYTE pVal;
DWORD dwVal;
LPWSTR pStr;
Status = RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
KeyName,
0,
NULL,
REG_OPTION_NON_VOLATILE,
0,
NULL,
&hKey,
&dwDisp);
if (Status != ERROR_SUCCESS) {
return FALSE;
}
pValue = Vals;
while (pValue->val_name) {
switch (pValue->val_type) {
case REG_DWORD:
pVal = (PBYTE)&dwVal;
dwVal = (DWORD)pValue->val_data;
ValLen = sizeof(DWORD);
break;
case REG_SZ:
pVal = (PBYTE)pValue->val_data;
ValLen = (wcslen((LPWSTR)pVal) + 1)*sizeof(WCHAR);
break;
case REG_MULTI_SZ:
dwVal = wcslen((LPWSTR)pValue->val_data);
ValLen = (dwVal+2)*sizeof(WCHAR);
pVal = LocalAlloc(LPTR, ValLen);
if (pVal == NULL) {
goto akv_fail;
}
wcscpy((LPWSTR)pVal, (LPWSTR)pValue->val_data);
pStr = (LPWSTR)pVal + dwVal;
pStr[1] = 0;
break;
}
Status = RegSetValueEx(
hKey,
pValue->val_name,
0,
pValue->val_type,
pVal,
ValLen
);
if (pValue->val_type == REG_MULTI_SZ) {
LocalFree(pVal);
}
akv_fail:
if (Status != ERROR_SUCCESS) {
RegCloseKey(hKey);
return FALSE;
}
pValue++;
}
RegCloseKey(hKey);
return TRUE;
} // AddKeyValues
//
// Install_Driver function for the CELAN NDIS miniport driver.
//
// This function sets up the registry keys and values required to install this
// DLL as a Windows CE plug and play driver.
//
// Input:
//
// LPWSTR lpPnpId - The device's plug and play identifier string. An install
// function can use lpPnpId to set up a key
// HKEY_LOCAL_MACHINE\Drivers\PCMCIA\<lpPnpId> under the assumption that the
// user will continue to use the same device that generates the same plug and
// play id string. If there is a general detection method for the card, then lpPnpId can
// be ignored and a detection function can be registered under HKEY_LOCAL_MACHINE\
// Drivers\PCMCIA\Detect.
//
// LPWSTR lpRegPath - Buffer to contain the newly installed driver's device key
// under HKEY_LOCAL_MACHINE in the registry. Windows CE will attempt to load the
// the newly installed device driver upon completion of its
// Install_Driver function.
//
// DWORD cRegPathSize - Number of bytes in lpRegPath.
//
// Returns lpRegPath if successful, NULL for failure.
//
LPWSTR
Install_Driver(
LPWSTR lpPnpId,
LPWSTR lpRegPath,
DWORD cRegPathSize
)
{
/*
A driver does not need to install a detect function if its associated device
has a unique Plug and Play identifier. Since the CELAN driver can work with
many CELAN compatible cards which would have many plug and play ids, it
supplies a detection function and installs a PCMCIA\Detect\nn key.
The following registry keys and values will be installed:
[HKEY_LOCAL_MACHINE\Drivers\PCMCIA\Detect\40]
"Dll"="CELAN.DLL"
"Entry"="DetectCELAN"
[HKEY_LOCAL_MACHINE\Drivers\PCMCIA\CELAN]
"Dll"="ndis.dll"
"Prefix"="NDS"
"Miniport"="CELAN"
[HKEY_LOCAL_MACHINE\Comm\CELAN]
"DisplayName"="CELAN Compatible Ethernet Driver"
"Group"="NDIS"
"ImagePath"="celan.dll"
[HKEY_LOCAL_MACHINE\Comm\CELAN\Linkage]
"Route"=multi_sz:"CELAN1"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -