⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 ndis windows网络驱动程序的范例
💻 C
📖 第 1 页 / 共 2 页
字号:
/*++

Copyright (c) 1996  Microsoft Corporation

Module Name:

    main.c

Abstract:

    This is the initialization file for the sample Ndis 4.0 Intermediate Driver. This sample is
	Designed to layer in between the installed transports and the installed Miniports. Currently.
	this sample doesn't do anything except receive packets, and pass them on.
	The upper edge of this sample is a Miniport interface, the lower edge looks like a transport
Author:

    Jim Mateer 
   
   Environment:

    Kernel Mode

Revision History:

         Based largely on the Packet Scheduler progtam written by  Charlie Wickham
           
--*/

#include "ImSamp.h"

#pragma hdrstop

//
// number of characters that are appended to the RegistryPath when constructing
// the miniport device name
//

#define MPNAME_EXTENSION_SIZE   ( 3 * sizeof(WCHAR))


ULONG NdisRequestTag =  'qerN';
ULONG AdapterTag = 'padA';
ULONG PacketContextTag = 'tkaP';
ULONG ResidualBufferTag = 'bseR';
ULONG LookaheadBufferTag = 'hakL';
ULONG MediaAreaTag = 'taeM';
ULONG ClientVCTag  = 'tcvC';




NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    );

STATIC NDIS_STATUS
InitializeNdisWrapper(
    IN PDRIVER_OBJECT DriverObject,
    IN  PUNICODE_STRING RegistryPath
    );

STATIC NDIS_STATUS
DoMiniportInit(
    IN PDRIVER_OBJECT DriverObject,
    IN  PUNICODE_STRING RegistryPath
    );

STATIC NDIS_STATUS
DoProtocolInit(
    IN PDRIVER_OBJECT DriverObject,
    IN  PUNICODE_STRING RegistryPath
    );

STATIC VOID
InitializationCleanup(
    ULONG ShutdownMask
    );


// Mark the initialization files as pageable
// To conserve system resources 

#pragma NDIS_INIT_FUNCTION(DriverEntry)
#pragma NDIS_INIT_FUNCTION(InitializeNdisWrapper)
#pragma NDIS_INIT_FUNCTION(DoProtocolInit)
#pragma NDIS_INIT_FUNCTION(DoMiniportInit)
#pragma NDIS_INIT_FUNCTION(InitializationCleanup)




NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )

/*++

Routine Description:

    This is the NT OS specific driver entry point.  It kicks off initialization
    for the driver.  Currently, it is not PnP aware. Return from this routine
    only after protocol registration, layered miniport registration, and both
    miniport and higher layer protocol initialization has been done.

Arguments:

    DriverObject - NT OS specific Object
    RegistryPath - NT OS specific pointer to registry location for Psched

Return Values:

    STATUS_SUCCESS
    STATUS_FAILURE

--*/
{
    NDIS_STATUS Status;
    ULONG FuncIndex;
    ULONG ErrorLogData[2];
    ULONG InitShutdownMask;
    PWCHAR EventLogString = IMDriverName.Buffer;
    PVOID DumpData;
    ULONG MaxTimerRes;
    ULONG MinTimerRes;
    ULONG CurrentTimerRes;
    ULONG ActualTimerRes;

#ifdef PACKET_POOL_LOG
    NDIS_PHYSICAL_ADDRESS HighAddress = NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 );
#endif



   //
    // announce the version
    //

    KdPrint(( VersionHerald, VersionNumber, VersionTimestamp ));

    //
    // store a copy of our driver object. Used by NdisWriteEventLogEntry
    //

    IMDriverObject = DriverObject;

    //
    // initialize global data and ndis request lookaside list
    //

      InitializeListHead( &AdapterList );
      NdisAllocateSpinLock( &AdapterListLock );
    //
    // init the LLists for NdisRequest.
    // Look at ExInitializeNPagedLookasideList(...) for documentation
    NdisInitializeNPagedLookasideList(&NdisRequestLL,
                                      NULL,
                                      NULL,
                                      0,
                                      sizeof( IM_NDIS_REQUEST ),
                                      NdisRequestTag,
                                      (USHORT)ConfigData.NdisRequestBufferLimit);


    //
    // Lookaside list depth is automatically managed by the executive. The depth arg
    // (as of 1/5/97) is ignored.
    //



    //
    // initialize the wrapper with NDIS
    //

    Status = InitializeNdisWrapper( DriverObject, RegistryPath );

    if ( !NT_SUCCESS( Status )) {

        KdPrint(("InitializeNdisWrapper - Status: 0x%x\n", Status ));

        NdisWriteErrorLogEntry(IMDriverObject,
                               EVENT_TRANSPORT_REGISTER_FAILED,
                               IM_ERROR_INIT_NDIS_WRAPPER,
                               1,
                               &EventLogString,
                               0,
                               NULL);

        goto DriverEntryError;
    }

    InitShutdownMask = SHUTDOWN_TERMINATE_WRAPPER;

    //
    // get driver wide configuration data from the registry
    //

    Status = ConfigureDriver( RegistryPath, &ConfigData ); // in config.c

    if ( !NT_SUCCESS( Status )) {

        KdPrint(("ConfigureDriver - Status: 0x%x\n", Status ));
        goto DriverEntryError;
    }

#if DBG

	// hardcoded for convience. These should relly be read from the registry	
    DbgTraceLevel = ConfigData.DebugLevel;
    DbgTraceMask = ConfigData.DebugMask;
#endif

    //
    // do Protocol initialize first
    //

    Status = DoProtocolInit( DriverObject, RegistryPath );

    if ( !NT_SUCCESS( Status )) {

        ImDbgOut(DBG_CRITICAL_ERROR,
                 DBG_INIT,
                 ("DoProtocolInit Failed! Status: 0x%x\n", Status));

        DumpData = &Status;
        NdisWriteErrorLogEntry(IMDriverObject,
                               EVENT_TRANSPORT_REGISTER_FAILED,
                               IM_ERROR_PROTOCOL_INIT,
                               1,
                               &EventLogString,
                               sizeof( Status ),
                               DumpData);

        goto DriverEntryError;
    }

    InitShutdownMask |= SHUTDOWN_DEREGISTER_PROTOCOL;

    //
    // Initialize as a Miniport driver to the transports. no shutdown mask value
    // since there is no way to dereg a miniport...
    //

    Status = DoMiniportInit( DriverObject, RegistryPath );

    if ( !NT_SUCCESS( Status )) {

        ImDbgOut(DBG_CRITICAL_ERROR,
                 DBG_INIT,
                 ("DoMiniportInit Failed! Status: 0x%x\n", Status));

        DumpData = &Status;
        NdisWriteErrorLogEntry(IMDriverObject,
                               (ULONG)IM_EVENT_MINIPORT_REGISTER_FAILED,
                               0,
                               1,
                               &EventLogString,
                               sizeof( Status ),
                               DumpData);

        goto DriverEntryError;
    }

    Status = WDMInitialize( DriverObject, &InitShutdownMask );

    if ( !NT_SUCCESS( Status )) {

        ImDbgOut(DBG_CRITICAL_ERROR,
                 DBG_INIT,
                 ("WDMInitialize Failed! Status: 0x%x\n", Status));

        goto DriverEntryError;
    }

#ifdef PACKET_POOL_LOG
    NdisAllocateMemory( &PktPoolLog, sizeof(PKTPOOLLOG) * PPLogSize, 0, HighAddress );
#endif


    return (STATUS_SUCCESS);

    //
    // An error occured so we need to cleanup things
    //

DriverEntryError:
    InitializationCleanup( InitShutdownMask );

    return (STATUS_UNSUCCESSFUL);

} // DriverEntry





STATIC NDIS_STATUS
InitializeNdisWrapper(
    IN PDRIVER_OBJECT DriverObject,
    IN  PUNICODE_STRING RegistryPath
    )

/*++

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -