📄 main.c
字号:
Routine Description:
Initialize the Ndis wrapper for both the miniport and protocol sections. Since
the name in the registry path is the Protocol key (ImSamp), 'MP' is appended
onto the end to initialize the wrapper for the miniport side of the IM
Arguments:
DriverObject - pointer to NT driver object
RegistryPath - pointer to path to driver params in registry
Return Values:
NDIS_STATUS_SUCCESS
NDIS_STATUS_BAD_VERSION
NDIS_STATUS_FAILURE
--*/
{
NDIS_STATUS Status;
USHORT MPDeviceNameLength;
NDIS_PHYSICAL_ADDRESS HighAddress = NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 );
ULONG i;
NDIS_STRING MPRegistryPath;
PWCHAR RegistryPathBuffer;
#if 1 // BINARY_COMPATIBLE BUG BUG BUG
NdisMInitializeWrapper( &MPWrapperHandle, DriverObject, RegistryPath, NULL );
#else
//
// NT needs the MP name to be different from the protocol name
//
MPDeviceNameLength = RegistryPath->Length + MPNAME_EXTENSION_SIZE;
Status = NdisAllocateMemory(&RegistryPathBuffer,
MPDeviceNameLength,
0,
HighAddress);
if ( RegistryPathBuffer == NULL ) {
ImDbgOut(DBG_CRITICAL_ERROR,
DBG_INIT,
("Can't allocate buffer for MP Device Name\n" ));
return NDIS_STATUS_RESOURCES;
}
//
// max length includes a trailing null, while length is just the string
//
MPRegistryPath.MaximumLength = MPDeviceNameLength;
MPRegistryPath.Length = MPRegistryPath.MaximumLength - sizeof( WCHAR );
MPRegistryPath.Buffer = RegistryPathBuffer;
NdisMoveMemory( MPRegistryPath.Buffer, RegistryPath->Buffer, RegistryPath->Length );
i = RegistryPath->Length / sizeof( WCHAR );
RegistryPathBuffer[ i++ ] = L'M';
RegistryPathBuffer[ i++ ] = L'P';
RegistryPathBuffer[ i ] = L'\0';
NdisMInitializeWrapper( &MPWrapperHandle, DriverObject, &MPRegistryPath, NULL );
NdisFreeMemory( RegistryPathBuffer, MPDeviceNameLength, 0 );
#endif
return NDIS_STATUS_SUCCESS;
} // InitializeNdisWrapper
STATIC NDIS_STATUS
DoMiniportInit(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
/*++
Routine Name:
DoMiniportInit
Routine Description:
This routines registers ImSamp as a Miniport driver with the NDIS wrapper.
Arguments:
None
Return Values:
NDIS_STATUS_SUCCESS
NDIS_STATUS_BAD_VERSION
NDIS_STATUS_FAILURE
--*/
{
NDIS_STATUS Status;
NDIS_MINIPORT_CHARACTERISTICS MiniportChars;
MiniportChars.MajorNdisVersion = 4;
MiniportChars.MinorNdisVersion = 0;
MiniportChars.Reserved = 0;
MiniportChars.HaltHandler = MPHalt;
MiniportChars.InitializeHandler = MPInitialize;
MiniportChars.QueryInformationHandler = MPQueryInformation;
MiniportChars.ResetHandler = MPReset;
MiniportChars.SetInformationHandler = MPSetInformation;
MiniportChars.TransferDataHandler = MPTransferData;
//
// Unused handlers
//
MiniportChars.ReconfigureHandler = NULL;
MiniportChars.DisableInterruptHandler = NULL;
MiniportChars.EnableInterruptHandler = NULL;
MiniportChars.HandleInterruptHandler = NULL;
MiniportChars.ISRHandler = NULL;
MiniportChars.CheckForHangHandler = NULL;
//
// Ndis 4.0 handlers. No regular send routine since we have a
// SendPackets handler.
//
MiniportChars.ReturnPacketHandler = MPReturnPacket;
MiniportChars.SendPacketsHandler = MPSendPackets;
MiniportChars.AllocateCompleteHandler = NULL;
MiniportChars.SendHandler = NULL;
Status = NdisIMRegisterLayeredMiniport(MPWrapperHandle,
&MiniportChars,
sizeof(MiniportChars),
&LMDriverHandle);
return (Status);
} // DoMiniportInit
STATIC NDIS_STATUS
DoProtocolInit(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
/*++
Routine Name:
DoProtocolInit
Routine Description:
This function registers the IM as a protocol
Arguments:
RegistryPath - pointer to our key in the registry
Return Values:
NDIS_STATUS_BAD_CHARACTERISTICS
NDIS_STATUS_BAD_VERSION
NDIS_STATUS_RESOURCES
NDIS_STATUS_SUCCESS
--*/
{
NDIS_PROTOCOL_CHARACTERISTICS ProtocolChars;
NDIS_STATUS Status;
NDIS_STRING IMName = NDIS_STRING_CONST( "IMSamp" );
//
// register the protocol section
//
NdisZeroMemory(&ProtocolChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
ProtocolChars.Name.Length = IMName.Length;
ProtocolChars.Name.Buffer = (PVOID)IMName.Buffer;
ProtocolChars.MajorNdisVersion = 4;
ProtocolChars.MinorNdisVersion = 0;
ProtocolChars.OpenAdapterCompleteHandler = LowerMPOpenAdapterComplete;
ProtocolChars.CloseAdapterCompleteHandler = LowerMPCloseAdapterComplete;
ProtocolChars.SendCompleteHandler = CLSendComplete;
ProtocolChars.TransferDataCompleteHandler = CLTransferDataComplete;
ProtocolChars.ResetCompleteHandler = CLResetComplete;
ProtocolChars.RequestCompleteHandler = CLRequestComplete;
ProtocolChars.ReceiveHandler = CLReceiveIndication;
ProtocolChars.ReceiveCompleteHandler = CLReceiveComplete;
ProtocolChars.StatusHandler = CLStatusIndication;
ProtocolChars.StatusCompleteHandler = CLStatusIndicationComplete;
ProtocolChars.ReceivePacketHandler = CLReceivePacket;
ProtocolChars.BindAdapterHandler = BindToLowerMP;
ProtocolChars.UnbindAdapterHandler = UnbindFromLowerMP;
ProtocolChars.UnloadHandler = CLUnloadProtocol;
NdisRegisterProtocol(&Status,
&ClientProtocolHandle,
&ProtocolChars,
sizeof(NDIS_PROTOCOL_CHARACTERISTICS) + ProtocolChars.Name.Length);
if ( !NT_SUCCESS( Status )) {
ImDbgOut(DBG_CRITICAL_ERROR, DBG_PROTOCOL | DBG_INIT,
("DoProtocolInit: couldn't register client handlers %08X\n", Status ));
}
return Status;
}
STATIC VOID
InitializationCleanup(
ULONG ShutdownMask
)
/*++
Routine Description:
This routine is responsible for cleaning up all allocated resources during
initialization
Arguments:
None
Return Values:
None
--*/
{
NDIS_STATUS Status;
//
// Deregister the protocol; we should have no references that would cause
// this to pend
//
if ( ShutdownMask & SHUTDOWN_DEREGISTER_PROTOCOL ) {
if ( ClientProtocolHandle ) {
NdisDeregisterProtocol( &Status, ClientProtocolHandle );
if ( Status == NDIS_STATUS_PENDING ) {
ImDbgOut(DBG_CRITICAL_ERROR, DBG_INIT, ("Client DeregProto failed - %08X\n", Status));
}
}
}
//
// Terminate the wrapper
//
if ( ShutdownMask & SHUTDOWN_TERMINATE_WRAPPER ) {
NdisTerminateWrapper( MPWrapperHandle, NULL );
}
//
// Delete our IO device and symbolic link
//
WDMCleanup( ShutdownMask );
//
// free the lookaside list resources
//
NdisDeleteNPagedLookasideList( &NdisRequestLL );
//
// Free our global locks
//
NdisFreeSpinLock( &AdapterListLock );
NdisFreeSpinLock( &PSAListLock );
} // InitializationCleanup
/* end main.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -