分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
#include "precomp.h"
#pragma hdrstop
#pragma NDIS_INIT_FUNCTION(DriverEntry)
NDIS_PHYSICAL_ADDRESS HighestAcceptableMax = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);
NDIS_MEDIUM MediumArray[3] =
{
NdisMedium802_3, // Ethernet
NdisMedium802_5, // Token-ring
NdisMediumFddi // Fddi
};
//
// g_GlobalLock - Protects resources
//
NDIS_SPIN_LOCK g_GlobalLock;
//
// g_ProtocolHandle - handle returned by NDIS when registering the protocol portion of the IM
//
NDIS_HANDLE g_ProtocolHandle = NULL;
//
// g_MiniportHandle - handle returned by NDIS when MP portion registers as LM
//
NDIS_HANDLE g_MiniportHandle = NULL;
//
// g_AdapterList - List of adapters to which the NetWall is bound
//
PADAPT g_AdapterList = NULL;
//
// g_DriverObject - pointer to NT driver and device objects
//
PDRIVER_OBJECT g_DriverObject = NULL;
/**
* Routine Description:
*
* This is the primary initialization routine for the NetWall IM driver.
* It is simply responsible for the intializing the wrapper and registering
* the Miniport and Protocol driver.
*
* Arguments:
*
* IN DriverObject - Pointer to driver object created by the system.
* IN RegistryPath - Registry path string for driver service key
*
* Return Value:
*
* The status of the operation.
*/
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
NDIS_STATUS Status;
NDIS_PROTOCOL_CHARACTERISTICS PChars;
NDIS_MINIPORT_CHARACTERISTICS MChars;
NDIS_STRING protoName;
UNICODE_STRING ntDeviceName;
UNICODE_STRING win32DeviceName;
NDIS_HANDLE WrapperHandle;
UINT FuncIndex = 0;
DBGPRINT("===> NetWall - DriverEntry/n");
DbgPrint("=== RegistryPath is : %ws ===/n", RegistryPath->Buffer);
g_DriverObject = DriverObject;
//
// Initialize Global Lock
//
NdisAllocateSpinLock(&g_GlobalLock);
do
{
//
// 1. Register the miniport with NDIS. Note that it is the miniport
// which was started as a driver and not the protocol. Also the miniport
// must be registered prior to the protocol since the protocol's BindAdapter
// handler can be initiated anytime and when it is, it must be ready to
// start driver instances.
//
NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, NULL);
//
// 2. Perform IM Driver's Miniport Initialization
//
NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS));
MChars.MajorNdisVersion = 4;
MChars.MinorNdisVersion = 0;
MChars.InitializeHandler = MPInitialize;
MChars.QueryInformationHandler = MPQueryInformation;
MChars.SetInformationHandler = MPSetInformation;
MChars.ResetHandler = MPReset;
MChars.TransferDataHandler = MPTransferData;
MChars.HaltHandler = MPHalt;
//
// We will disable the check for hang timeout so we do not
// need a check for hang handler!
//
MChars.CheckForHangHandler = NULL;
MChars.SendHandler = MPSend;
MChars.ReturnPacketHandler = MPReturnPacket;
//
// Either the Send or the SendPackets handler should be specified.
// If SendPackets handler is specified, SendHandler is ignored
//
MChars.SendPacketsHandler = NULL;//MPSendPackets;
Status = NdisIMRegisterLayeredMiniport(WrapperHandle,
&MChars,
sizeof(MChars),
&g_MiniportHandle);
if (! NT_SUCCESS(Status))
{
DbgPrint("MPRegisterAsMiniport Failed! Status: 0x%x/n", Status);
NdisWriteErrorLogEntry(
DriverObject,
(ULONG)IM_ERROR_IM_REGISTER_FAILED,
0,
1,
(ULONG )Status);
break;
}
//
// 3. Perform initialization supported by WDM
//
// Create a control device object for this driver.
// Application can send an IOCTL to this device to get
// bound adapter information.
//
//
DBGPRINT("===> NetWall - NdisWDMInitialize/n");
NdisAcquireSpinLock(&g_GlobalLock); // sync
++g_MiniportCount;
if (1 == g_MiniportCount)
{
ASSERT(g_DeviceState != PS_DEVICE_STATE_CREATING); //
while (g_DeviceState != PS_DEVICE_STATE_READY)
{
NdisReleaseSpinLock(&g_GlobalLock);
NdisMSleep(1); // Waiting
NdisAcquireSpinLock(&g_GlobalLock);
}
g_DeviceState