Exemple #1
0
NTSTATUS NDIS_API DriverEntry(IN PDRIVER_OBJECT  DriverObject,
                              IN PUNICODE_STRING RegistryPath)

{
  // initialiae the driver

  NDIS_PROTOCOL_CHARACTERISTICS ProtocolChar;
  NDIS_STRING ProtoName = NDIS_STRING_CONST("EPACKET");
  NDIS_STATUS Status;


  // Because the driver can be loaded once for each Netcard on the system,
  // and because DriverEntry is called each time, we must ensure that
  // initialization is performed only once.
  if (GlobalDeviceExtension != NULL)
    return NDIS_STATUS_SUCCESS;
        
  NdisAllocateMemory((PVOID *)&GlobalDeviceExtension, sizeof(DEVICE_EXTENSION), 0, -1 );
  if (GlobalDeviceExtension == NULL)
    return NDIS_STATUS_RESOURCES;

  NdisZeroMemory((UCHAR*)GlobalDeviceExtension, sizeof(DEVICE_EXTENSION));
  NdisZeroMemory((UCHAR*)&ProtocolChar, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
  ProtocolChar.MajorNdisVersion            = 0x03;
  ProtocolChar.MinorNdisVersion            = 0x0a;
  ProtocolChar.Reserved                    = 0;
  ProtocolChar.OpenAdapterCompleteHandler  = PacketBindAdapterComplete;
  ProtocolChar.CloseAdapterCompleteHandler = PacketUnbindAdapterComplete;
  ProtocolChar.SendCompleteHandler         = PacketSendComplete;
  ProtocolChar.TransferDataCompleteHandler = PacketTransferDataComplete;
  ProtocolChar.ResetCompleteHandler        = PacketResetComplete;
  ProtocolChar.RequestCompleteHandler      = PacketRequestComplete;
  ProtocolChar.ReceiveHandler              = PacketReceiveIndicate;
  ProtocolChar.ReceiveCompleteHandler      = PacketReceiveComplete;
  ProtocolChar.StatusHandler               = PacketStatus;
  ProtocolChar.StatusCompleteHandler       = PacketStatusComplete;
  ProtocolChar.BindAdapterHandler          = PacketBindAdapter;
  ProtocolChar.UnbindAdapterHandler        = PacketUnbindAdapter;
  ProtocolChar.UnloadProtocolHandler       = PacketUnload;
  ProtocolChar.Name                        = ProtoName;
  
  NdisRegisterProtocol(&Status,
                       &GlobalDeviceExtension->NdisProtocolHandle,
                       &ProtocolChar,
                       sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
  
  if (Status != NDIS_STATUS_SUCCESS) {
    NdisFreeMemory(GlobalDeviceExtension, sizeof(DEVICE_EXTENSION), 0);
    return Status;
  }
  
  // initialize open list
  InitializeListHead(&GlobalDeviceExtension->OpenList);
  
  // initialize global device extension
  GlobalDeviceExtension->DriverObject = DriverObject;
  
  return Status;
}
Exemple #2
0
NDIS_HANDLE RegisterFakeNDISProtocol ()
/*++

Routine Description:

	Registers a fake NDIS routines.


Arguments:

	None.


Return Value:

	Handle to the fake NDIS protocol if successful, otherwise returns NULL.


Author:

	xiaonie

	2012/07/12


--*/
{
	NTSTATUS status = STATUS_SUCCESS;
	NDIS_HANDLE hFakeProtocol = NULL;
	NDIS_PROTOCOL_CHARACTERISTICS FakeProtocol;
	NDIS_STRING ProtocolName;

	NdisZeroMemory(&FakeProtocol, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
	FakeProtocol.MajorNdisVersion = 0x05;
	FakeProtocol.MinorNdisVersion = 0x00;

	NdisInitUnicodeString(&ProtocolName, L"FakeProtocol");
	FakeProtocol.Name = ProtocolName;
	FakeProtocol.ReceiveHandler = FakeNdisProtocolReceive;
	FakeProtocol.BindAdapterHandler = FakeBind;
	FakeProtocol.UnbindAdapterHandler = FakeUnBind;

	NdisRegisterProtocol(&status, &hFakeProtocol, &FakeProtocol,
		sizeof(NDIS50_PROTOCOL_CHARACTERISTICS));

	if (status == STATUS_SUCCESS) {
		return hFakeProtocol;
	} else {
		DbgPrint("RegisterFakeNDISProtocol failed: 0x%08x!\r\n", status);
		return NULL;
	}
}
Exemple #3
0
NTSTATUS
NTAPI
DriverEntry(PDRIVER_OBJECT DriverObject,
            PUNICODE_STRING RegistryPath)
{
    NDIS_STATUS Status;
    NDIS_PROTOCOL_CHARACTERISTICS Chars;
    UNICODE_STRING NtDeviceName = RTL_CONSTANT_STRING(NDISUIO_DEVICE_NAME_NT);
    UNICODE_STRING DosDeviceName = RTL_CONSTANT_STRING(NDISUIO_DEVICE_NAME_DOS);

    /* Setup dispatch functions */
    DriverObject->MajorFunction[IRP_MJ_CREATE] = NduDispatchCreate;
    DriverObject->MajorFunction[IRP_MJ_CLOSE] = NduDispatchClose;
    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NduDispatchDeviceControl;
    DriverObject->MajorFunction[IRP_MJ_READ] = NduDispatchRead;
    DriverObject->MajorFunction[IRP_MJ_WRITE] = NduDispatchWrite;
    DriverObject->DriverUnload = NduUnload;
    
    /* Setup global state */
    InitializeListHead(&GlobalAdapterList);
    KeInitializeSpinLock(&GlobalAdapterListLock);

    /* Create the NDISUIO device object */
    Status = IoCreateDevice(DriverObject,
                            0,
                            &NtDeviceName,
                            FILE_DEVICE_SECURE_OPEN,
                            0,
                            FALSE,
                            &GlobalDeviceObject);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("Failed to create device object with status 0x%x\n", Status);
        return Status;
    }
    
    /* Create a symbolic link into the DOS devices namespace */
    Status = IoCreateSymbolicLink(&DosDeviceName, &NtDeviceName);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("Failed to create symbolic link with status 0x%x\n", Status);
        IoDeleteDevice(GlobalDeviceObject);
        return Status;
    }

    /* Register the protocol with NDIS */
    RtlZeroMemory(&Chars, sizeof(Chars));
    Chars.MajorNdisVersion = NDIS_MAJOR_VERSION;
    Chars.MinorNdisVersion = NDIS_MINOR_VERSION;
    Chars.OpenAdapterCompleteHandler = NduOpenAdapterComplete;
    Chars.CloseAdapterCompleteHandler = NduCloseAdapterComplete;
    Chars.PnPEventHandler = NduNetPnPEvent;
    Chars.SendCompleteHandler = NduSendComplete;
    Chars.TransferDataCompleteHandler = NduTransferDataComplete;
    Chars.ResetCompleteHandler = NduResetComplete;
    Chars.RequestCompleteHandler = NduRequestComplete;
    Chars.ReceiveHandler = NduReceive;
    Chars.ReceiveCompleteHandler = NduReceiveComplete;
    Chars.StatusHandler = NduStatus;
    Chars.StatusCompleteHandler = NduStatusComplete;
    Chars.Name = ProtocolName;
    Chars.BindAdapterHandler = NduBindAdapter;
    Chars.UnbindAdapterHandler = NduUnbindAdapter;
    
    NdisRegisterProtocol(&Status,
                         &GlobalProtocolHandle,
                         &Chars,
                         sizeof(Chars));
    if (Status != NDIS_STATUS_SUCCESS)
    {
        DPRINT1("Failed to register protocol with status 0x%x\n", Status);
        IoDeleteSymbolicLink(&DosDeviceName);
        IoDeleteDevice(GlobalDeviceObject);
        return Status;
    }

    DPRINT("NDISUIO: Loaded\n");

    return STATUS_SUCCESS;
}
Exemple #4
0
/*
 * This routine initializes the packet driver. The function is called by the 
 * driver manager automatically when RegisterDevice function is called.
 *
 * Arguments
 *		dwContext		-	Specifies a pointer to a string containing the 
 *							registry path to the active key for the stream 
 *							interface driver.
 *
 * Return Value
 *		The function return the device context to be called with other stream
 *		function like _Open, _Close, etc. If the initialization fails then the
 *		function returns NULL. If the function returns 0 then the driver is not 
 *		loaded by the device manager.
 *
 */
DWORD PKT_Init(DWORD dwContext)
{
	NDIS_PROTOCOL_CHARACTERISTICS	ProtocolChar;
	NDIS_STRING						ProtoName = PROTOCOL_NAME;
	NDIS_STATUS						Status;
	
	// Allocate memory for the global device extension
	NdisAllocateMemory ((PVOID*) &g_pDeviceExtension, sizeof (DEVICE_EXTENSION), 
		0, NDIS_ADDR_M1);
	if (g_pDeviceExtension == NULL) {
		return 0;
	}
	
	// reset the global device extension object
	NdisZeroMemory (g_pDeviceExtension, sizeof (DEVICE_EXTENSION));
	
	// reset the protocol characteristics object
	NdisZeroMemory (&ProtocolChar, sizeof (NDIS_PROTOCOL_CHARACTERISTICS));
	
	// Initialize the protocol char structure
	ProtocolChar.MajorNdisVersion            = 0x03;
	ProtocolChar.MinorNdisVersion            = 0x00;
	ProtocolChar.Reserved                    = 0;
	ProtocolChar.Name                        = ProtoName;

	ProtocolChar.BindAdapterHandler			 = PacketBindAdapter;
	ProtocolChar.CloseAdapterCompleteHandler = PacketCloseAdapterComplete;
	ProtocolChar.OpenAdapterCompleteHandler  = PacketOpenAdapterComplete;
	ProtocolChar.ReceiveHandler              = PacketReceive;
	ProtocolChar.ReceiveCompleteHandler      = PacketReceiveComplete;
	ProtocolChar.RequestCompleteHandler      = PacketRequestComplete;
	ProtocolChar.ResetCompleteHandler        = PacketResetComplete;
	ProtocolChar.StatusHandler               = PacketStatus;
	ProtocolChar.StatusCompleteHandler       = PacketStatusComplete;
	ProtocolChar.TransferDataCompleteHandler = PacketTransferDataComplete;
	ProtocolChar.UnbindAdapterHandler        = PacketUnbindAdapter;
	ProtocolChar.SendCompleteHandler         = PacketWriteComplete;
	
	// Registed the protocol handler
	NdisRegisterProtocol (&Status, &g_pDeviceExtension->NdisProtocolHandle,
		&ProtocolChar, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
	
	// Check the return value
	if (Status != NDIS_STATUS_SUCCESS) {
		NdisFreeMemory (g_pDeviceExtension, sizeof (DEVICE_EXTENSION),  0);
		return 0;
	}
	
	// Initialize the list headers
	InitializeListHead (&g_pDeviceExtension->listAdapterNames);

	// Initialize the open instance pointer
	g_pDeviceExtension->pOpenInstance = NULL;
	
	// Check for the available adapters to bind with
	// not reqd for win ce. the os call packet bind adapter for 
	// every adapters installed in the system
	if (PKTBindNames () != NDIS_STATUS_SUCCESS) {
		NdisFreeMemory (g_pDeviceExtension, sizeof (DEVICE_EXTENSION),  0);
		g_pDeviceExtension = NULL;
		return 0;
	}
	
	// Status is generally succes`s over here
	return PKT_DEVICE_CONTEXT;
}
Exemple #5
0
NTSTATUS
LpxRegisterProtocol (
    IN PUNICODE_STRING NameString
    )

/*++

Routine Description:

    This routine introduces this transport to the NDIS interface.

Arguments:

    Irp - Pointer to the request packet representing the I/O request.

Return Value:

    The function value is the status of the operation.
    STATUS_SUCCESS if all goes well,
    Failure status if we tried to register and couldn't,
    STATUS_INSUFFICIENT_RESOURCES if we couldn't even try to register.

--*/

{
    NDIS_STATUS						ndisStatus;
	UNICODE_STRING					functionName;

	PNDIS_PROTOCOL_CHARACTERISTICS	ProtChars;
	UINT							ProtCharsLen;

	ULONG lpxMajorVersion;
	ULONG lpxMinorVersion;

	NTSTATUS (*GetVersion) (PRTL_OSVERSIONINFOW);

	RtlInitUnicodeString( &functionName, L"RtlGetVersion" );
	GetVersion = MmGetSystemRoutineAddress( &functionName );

    if (GetVersion != NULL) {

		NTSTATUS			status;
        RTL_OSVERSIONINFOW	versionInfo;
 
        versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW);

        status = GetVersion(&versionInfo);

		NDAS_ASSERT( NT_SUCCESS(status) );

        lpxMajorVersion = versionInfo.dwMajorVersion;
        lpxMinorVersion = versionInfo.dwMinorVersion;

    } else {

        PsGetVersion( &lpxMajorVersion, &lpxMinorVersion, NULL, NULL );
    }

    // Set up the characteristics of this protocol

	// NDIS 3.0 field

	if (1) {
	//if (lpxMajorVersion == 5 && lpxMinorVersion >= 1 || lpxMajorVersion > 5) {

		ProtChars = (PNDIS_PROTOCOL_CHARACTERISTICS)&Ndis50ProtChars;
		ProtCharsLen = sizeof(Ndis50ProtChars);

		ProtChars->MajorNdisVersion = 4;
		ProtChars->MinorNdisVersion = 0;

	} else {

		ProtChars = (PNDIS_PROTOCOL_CHARACTERISTICS)&Ndis40ProtChars;
		ProtCharsLen = sizeof(Ndis40ProtChars);

		ProtChars->MajorNdisVersion = 4;
		ProtChars->MinorNdisVersion = 0;
	}

	ProtChars->Filler;
	ProtChars->Flags;

	ProtChars->OpenAdapterCompleteHandler	= LpxOpenAdapterComplete;
	ProtChars->CloseAdapterCompleteHandler	= LpxCloseAdapterComplete;

#ifdef LPX_LOCKS
	ProtChars->SendCompleteHandler			= LpxFakeSendCompletionHandler;
	ProtChars->TransferDataCompleteHandler	= LpxFakeTransferDataComplete;
#else
	ProtChars->SendCompleteHandler			= LpxSendCompletionHandler;
	ProtChars->TransferDataCompleteHandler	= LpxTransferDataComplete;
#endif

	ProtChars->ResetCompleteHandler		= LpxResetComplete;
	ProtChars->RequestCompleteHandler	= LpxRequestComplete;

    ProtChars->ReceiveHandler			= LpxReceiveIndication;
    ProtChars->ReceiveCompleteHandler	= LpxReceiveComplete;

	ProtChars->StatusHandler			= LpxStatusIndication;
    ProtChars->StatusCompleteHandler	= LpxStatusComplete;

	ProtChars->Name.Length			= NameString->Length;
	ProtChars->Name.MaximumLength	= NameString->MaximumLength;
	ProtChars->Name.Buffer			= NameString->Buffer;

	// NDIS 4.0 fields

	ProtChars->ReceivePacketHandler	= LpxProtocolReceivePacket;

	ProtChars->BindAdapterHandler	= LpxProtocolBindAdapter;
	ProtChars->UnbindAdapterHandler	= LpxProtocolUnbindAdapter;

	ProtChars->PnPEventHandler		= LpxProtocolPnPEventHandler;

	ProtChars->UnloadHandler;

#if (defined(NDIS50) || defined(NDIS51))

	if (1) {
	//if (ProtChars->MajorNdisVersion == 5) {

		// Start of NDIS 5.0 extensions.

		ProtChars->ReservedHandlers;

		ProtChars->CoSendCompleteHandler		= LpxCoSendCompleteHandler;
		ProtChars->CoStatusHandler				= LpxCoStatusHandler;
		ProtChars->CoReceivePacketHandler		= LpxCoReceivePacketHandler;
		ProtChars->CoAfRegisterNotifyHandler	= LpxCoAfRegisterNotifyHandler;
	}

#endif

	//NDAS_ASSERT( ProtChars->CoSendCompleteHandler == LpxCoSendCompleteHandler );

    NdisRegisterProtocol( &ndisStatus, &LpxNdisProtocolHandle, ProtChars, ProtCharsLen );

    if (ndisStatus != NDIS_STATUS_SUCCESS) {

		NDAS_ASSERT(FALSE);

#if DBG
        IF_LPXDBG (LPX_DEBUG_RESOURCE) {

            LpxPrint1( "LpxInitialize: NdisRegisterProtocol failed: %s\n", LpxGetNdisStatus(ndisStatus) );
        }
#endif

        return (NTSTATUS)ndisStatus;
    }
DWORD	GetProtocolHeaderXP()
{
	NDIS_STATUS                        Status;
	NDIS_PROTOCOL_CHARACTERISTICS      PChars;
	NDIS_HANDLE ProtHandle;
	NDIS_STRING                        Name;
	PKK_NDIS_PROTOCOL_BLOCK			pHeader=NULL;


	//
	// Now register the protocol.
	//
	NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
	PChars.MajorNdisVersion = 4;
	PChars.MinorNdisVersion = 0;

	//
	// Make sure the protocol-name matches the service-name
	// (from the INF) under which this protocol is installed.
	// This is needed to ensure that NDIS can correctly determine
	// the binding and call us to bind to miniports below.
	//
	NdisInitUnicodeString(&Name, L"SUPERCI");    // Protocol name
	PChars.Name = Name;

	// 	PChars.OpenAdapterCompleteHandler = PtOpenAdapterComplete;
	// 	PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete;
	// 	PChars.SendCompleteHandler = PtSendComplete;
	// 	PChars.TransferDataCompleteHandler = PtTransferDataComplete;
	// 
	// 	PChars.ResetCompleteHandler = PtResetComplete;
	// 	PChars.RequestCompleteHandler = PtRequestComplete;
	// 	PChars.ReceiveHandler = PtReceive;
	// 	PChars.ReceiveCompleteHandler = PtReceiveComplete;
	// 	PChars.StatusHandler = PtStatus;
	// 	PChars.StatusCompleteHandler = PtStatusComplete;
	// 	PChars.BindAdapterHandler = PtBindAdapter;
	// 	PChars.UnbindAdapterHandler = PtUnbindAdapter;
	// 	PChars.UnloadHandler = PtUnloadProtocol;
	// 
	// 	PChars.ReceivePacketHandler = PtReceivePacket;

	PChars.BindAdapterHandler = PtBindAdapter;
	PChars.UnbindAdapterHandler = PtUnbindAdapter;

	//GetReal_NdisRegisterProtocol
	//if NdisRegisterProtocol is hook by eat.
	//we can search ff 15 xxxxxx,it means a long call [xxxxxx] instruction
	NdisRegisterProtocol(&Status,
		&ProtHandle,
		&PChars,
		sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
	if (Status != NDIS_STATUS_SUCCESS||ProtHandle==0)
	{
		return 0;
	}

	pHeader	=	(PKK_NDIS_PROTOCOL_BLOCK)ProtHandle;
	ProtHandle	=	(NDIS_HANDLE)pHeader->NextProtocol;
	NdisDeregisterProtocol(&Status, pHeader);
	if (Status != NDIS_STATUS_SUCCESS)
	{
		kprintf("NdisDeregisterProtocol() fail in ReturnProtocolHeader()\n ");
		return 0;
	}
	return (ULONG)ProtHandle;

}
Exemple #7
0
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT   pDriverObject,
    IN PUNICODE_STRING  pRegistryPath
    )
/*++

Routine Description:

    Called on loading. We create a device object to handle user-mode requests
    on, and register ourselves as a protocol with NDIS.

Arguments:

    pDriverObject - Pointer to driver object created by system.

    pRegistryPath - Pointer to the Unicode name of the registry path
        for this driver.

Return Value:

    NT Status code
    
--*/
{
    NDIS_PROTOCOL_CHARACTERISTICS   protocolChar;
    NTSTATUS                        status = STATUS_SUCCESS;
    NDIS_STRING                     protoName = NDIS_STRING_CONST("NdisProt");     
    UNICODE_STRING                  ntDeviceName;
    UNICODE_STRING                  win32DeviceName;
    BOOLEAN                         fSymbolicLink = FALSE;
    PDEVICE_OBJECT                  deviceObject = NULL;

    UNREFERENCED_PARAMETER(pRegistryPath);

    DEBUGP(DL_LOUD, ("DriverEntry\n"));

    Globals.pDriverObject = pDriverObject;
    NPROT_INIT_EVENT(&Globals.BindsComplete);

    do
    {

        //
        // Create our device object using which an application can
        // access NDIS devices.
        //
        RtlInitUnicodeString(&ntDeviceName, NT_DEVICE_NAME);
#ifndef WIN9X
        status = IoCreateDeviceSecure(pDriverObject,
                                 0,
                                 &ntDeviceName,
                                 FILE_DEVICE_NETWORK,
                                 FILE_DEVICE_SECURE_OPEN,
                                 FALSE,
                                 &SDDL_DEVOBJ_SYS_ALL_ADM_ALL,
                                 NULL,
                                 &deviceObject);

#elif     
        status = IoCreateDevice(pDriverObject,
                                 0,
                                 &ntDeviceName,
                                 FILE_DEVICE_NETWORK,
                                 FILE_DEVICE_SECURE_OPEN,
                                 FALSE,
                                 &deviceObject);
#endif
        if (!NT_SUCCESS (status))
        {
            //
            // Either not enough memory to create a deviceobject or another
            // deviceobject with the same name exits. This could happen
            // if you install another instance of this device.
            //
            break;
        }

        RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME);

        status = IoCreateSymbolicLink(&win32DeviceName, &ntDeviceName);

        if (!NT_SUCCESS(status))
        {
            break;
        }

        fSymbolicLink = TRUE;
    
        deviceObject->Flags |= DO_DIRECT_IO;
        Globals.ControlDeviceObject = deviceObject;

        NPROT_INIT_LIST_HEAD(&Globals.OpenList);
        NPROT_INIT_LOCK(&Globals.GlobalLock);

        //
        // Initialize the protocol characterstic structure
        //
    
        NdisZeroMemory(&protocolChar,sizeof(NDIS_PROTOCOL_CHARACTERISTICS));

        protocolChar.MajorNdisVersion            = 5;
        protocolChar.MinorNdisVersion            = 0;
        protocolChar.Name                        = protoName;
        protocolChar.OpenAdapterCompleteHandler  = NdisProtOpenAdapterComplete;
        protocolChar.CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
        protocolChar.SendCompleteHandler         = NdisProtSendComplete;
        protocolChar.TransferDataCompleteHandler = NdisProtTransferDataComplete;
        protocolChar.ResetCompleteHandler        = NdisProtResetComplete;
        protocolChar.RequestCompleteHandler      = NdisProtRequestComplete;
        protocolChar.ReceiveHandler              = NdisProtReceive;
        protocolChar.ReceiveCompleteHandler      = NdisProtReceiveComplete;
        protocolChar.StatusHandler               = NdisProtStatus;
        protocolChar.StatusCompleteHandler       = NdisProtStatusComplete;
        protocolChar.BindAdapterHandler          = NdisProtBindAdapter;
        protocolChar.UnbindAdapterHandler        = NdisProtUnbindAdapter;
        protocolChar.UnloadHandler               = NULL;
        protocolChar.ReceivePacketHandler        = NdisProtReceivePacket;
        protocolChar.PnPEventHandler             = NdisProtPnPEventHandler;

        //
        // Register as a protocol driver
        //
    
        NdisRegisterProtocol(
            (PNDIS_STATUS)&status,
            &Globals.NdisProtocolHandle,
            &protocolChar,
            sizeof(NDIS_PROTOCOL_CHARACTERISTICS));

        if (status != NDIS_STATUS_SUCCESS)
        {
            DEBUGP(DL_WARN, ("Failed to register protocol with NDIS\n"));
            status = STATUS_UNSUCCESSFUL;
            break;
        }

#ifdef NDIS51
        Globals.PartialCancelId = NdisGeneratePartialCancelId();
        Globals.PartialCancelId <<= ((sizeof(PVOID) - 1) * 8);
        DEBUGP(DL_LOUD, ("DriverEntry: CancelId %lx\n", Globals.PartialCancelId));
#endif

        //
        // Now set only the dispatch points we would like to handle.
        //
        pDriverObject->MajorFunction[IRP_MJ_CREATE] = NdisProtOpen;
        pDriverObject->MajorFunction[IRP_MJ_CLOSE]  = NdisProtClose;
        pDriverObject->MajorFunction[IRP_MJ_READ]   = NdisProtRead;
        pDriverObject->MajorFunction[IRP_MJ_WRITE]  = NdisProtWrite;
        pDriverObject->MajorFunction[IRP_MJ_CLEANUP]  = NdisProtCleanup;
        pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]  = NdisProtIoControl;
        pDriverObject->DriverUnload = NdisProtUnload;

        status = STATUS_SUCCESS;
        
    }
    while (FALSE);
       

    if (!NT_SUCCESS(status))
    {
        if (deviceObject)
        {
            IoDeleteDevice(deviceObject);
            Globals.ControlDeviceObject = NULL;
        }

        if (fSymbolicLink)
        {
            IoDeleteSymbolicLink(&win32DeviceName);
        }
        
    }
    
    return status;

}
Exemple #8
0
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT        DriverObject,
    IN PUNICODE_STRING       RegistryPath
    )
/*++

Routine Description:

    First entry point to be called, when this driver is loaded.
    Register with NDIS as an intermediate driver.

Arguments:

    DriverObject - pointer to the system's driver object structure
        for this driver
    
    RegistryPath - system's registry path for this driver
    
Return Value:

    STATUS_SUCCESS if all initialization is successful, STATUS_XXX
    error code if not.

--*/
{
    NDIS_STATUS                        Status;
    NDIS_PROTOCOL_CHARACTERISTICS      PChars;
    NDIS_MINIPORT_CHARACTERISTICS      MChars;
    NDIS_STRING                        Name;

    divert_init();

    Status = NDIS_STATUS_SUCCESS;
    NdisAllocateSpinLock(&GlobalLock);

    NdisMInitializeWrapper(&NdisWrapperHandle, DriverObject, RegistryPath, NULL);

    do
    {
        //
        // 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.
        //

        NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS));

        MChars.MajorNdisVersion = PASSTHRU_MAJOR_NDIS_VERSION;
        MChars.MinorNdisVersion = PASSTHRU_MINOR_NDIS_VERSION;

        MChars.InitializeHandler = MPInitialize;
        MChars.QueryInformationHandler = MPQueryInformation;
        MChars.SetInformationHandler = MPSetInformation;
        MChars.ResetHandler = NULL;
        MChars.TransferDataHandler = MPTransferData;
        MChars.HaltHandler = MPHalt;
#ifdef NDIS51_MINIPORT
        MChars.CancelSendPacketsHandler = MPCancelSendPackets;
        MChars.PnPEventNotifyHandler = MPDevicePnPEvent;
        MChars.AdapterShutdownHandler = MPAdapterShutdown;
#endif // NDIS51_MINIPORT

        //
        // We will disable the check for hang timeout so we do not
        // need a check for hang handler!
        //
        MChars.CheckForHangHandler = NULL;
        MChars.ReturnPacketHandler = MPReturnPacket;

        //
        // Either the Send or the SendPackets handler should be specified.
        // If SendPackets handler is specified, SendHandler is ignored
        //
        MChars.SendHandler = NULL;    // MPSend;
        MChars.SendPacketsHandler = MPSendPackets;

        Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle,
                                                  &MChars,
                                                  sizeof(MChars),
                                                  &DriverHandle);
        if (Status != NDIS_STATUS_SUCCESS)
        {
            break;
        }

#ifndef WIN9X
        NdisMRegisterUnloadHandler(NdisWrapperHandle, PtUnload);
#endif

        //
        // Now register the protocol.
        //
        NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
        PChars.MajorNdisVersion = PASSTHRU_PROT_MAJOR_NDIS_VERSION;
        PChars.MinorNdisVersion = PASSTHRU_PROT_MINOR_NDIS_VERSION;

        //
        // Make sure the protocol-name matches the service-name
        // (from the INF) under which this protocol is installed.
        // This is needed to ensure that NDIS can correctly determine
        // the binding and call us to bind to miniports below.
        //
        NdisInitUnicodeString(&Name, L"Passthru");    // Protocol name
        PChars.Name = Name;
        PChars.OpenAdapterCompleteHandler = PtOpenAdapterComplete;
        PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete;
        PChars.SendCompleteHandler = PtSendComplete;
        PChars.TransferDataCompleteHandler = PtTransferDataComplete;
    
        PChars.ResetCompleteHandler = PtResetComplete;
        PChars.RequestCompleteHandler = PtRequestComplete;
        PChars.ReceiveHandler = PtReceive;
        PChars.ReceiveCompleteHandler = PtReceiveComplete;
        PChars.StatusHandler = PtStatus;
        PChars.StatusCompleteHandler = PtStatusComplete;
        PChars.BindAdapterHandler = PtBindAdapter;
        PChars.UnbindAdapterHandler = PtUnbindAdapter;
        PChars.UnloadHandler = PtUnloadProtocol;

        PChars.ReceivePacketHandler = PtReceivePacket;
        PChars.PnPEventHandler= PtPNPHandler;

        NdisRegisterProtocol(&Status,
                             &ProtHandle,
                             &PChars,
                             sizeof(NDIS_PROTOCOL_CHARACTERISTICS));

        if (Status != NDIS_STATUS_SUCCESS)
        {
            NdisIMDeregisterLayeredMiniport(DriverHandle);
            break;
        }

        NdisIMAssociateMiniport(DriverHandle, ProtHandle);
    }
    while (FALSE);

    if (Status != NDIS_STATUS_SUCCESS)
    {
        NdisTerminateWrapper(NdisWrapperHandle, NULL);
    }

    return(Status);
}
Exemple #9
0
NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING str)
{
	DbgBreakPoint();
	NTSTATUS sta;
	global.contextnum = 0;
	global.mininum = 0;
	globalinfopool.count = 0;
	global.controlobj = NULL;
	NDIS_STATUS ndissta;
	NDIS_HANDLE wraphandle=NULL;
	NDIS_MINIPORT_CHARACTERISTICS minicha;
	NDIS_PROTOCOL_CHARACTERISTICS pc;
	NDIS_STRING ns = NDIS_STRING_CONST("zlzpass");
	NdisZeroMemory(&global, sizeof(GLOBAL));
	NdisInitializeWrapper(&wraphandle, driver, str, NULL);
	if (wraphandle == NULL)
	{
		return STATUS_UNSUCCESSFUL;
	}
	NdisZeroMemory(&minicha, sizeof(NDIS_MINIPORT_CHARACTERISTICS));
	minicha.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
	minicha.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
	minicha.InitializeHandler = MPInitialize;
	minicha.HaltHandler = MPHalt;
	minicha.SetInformationHandler = MPSetInformation;
	minicha.QueryInformationHandler = MPQueryInformation;
	minicha.ReturnPacketHandler = MPReturnPacket;
	minicha.ResetHandler = NULL;
	minicha.CheckForHangHandler = NULL;
	minicha.TransferDataHandler = MPTransferData;
	minicha.SendHandler = MPSend;
	ndissta=NdisIMRegisterLayeredMiniport(wraphandle, &minicha, sizeof(NDIS_MINIPORT_CHARACTERISTICS), &global.driverhandle);
	if (ndissta!=NDIS_STATUS_SUCCESS)
	{
		return STATUS_UNSUCCESSFUL;
	}
	sysadddevfunc = driver->DriverExtension->AddDevice;

	driver->DriverExtension->AddDevice = myAddDevice;

	pc.MajorNdisVersion = 5;
	pc.MinorNdisVersion = 0;
	pc.Name = ns;
	pc.CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
	pc.SendCompleteHandler = NdisProtSendComplete;
	pc.TransferDataCompleteHandler = NdisProtTransferDataComplete;
	pc.ResetCompleteHandler = NdisProtResetComplete;
	pc.RequestCompleteHandler = NdisProtRequestComplete;
	pc.ReceiveHandler = NdisProtReceive;
	pc.ReceiveCompleteHandler = NdisProtReceiveComplete;
	pc.StatusHandler = NdisProtStatus;
	pc.StatusCompleteHandler = NdisProtStatusComplete;
	pc.BindAdapterHandler = NdisProtBindAdapter;
	pc.OpenAdapterCompleteHandler = NdisOpenAdapterComplete;
	pc.UnbindAdapterHandler = NdisProtUnbindAdapter;
	pc.UnloadHandler = NULL;
	pc.ReceivePacketHandler = NdisProtReceivePacket;
	pc.PnPEventHandler = NdisProtPnPEventHandler;
	pc.CoAfRegisterNotifyHandler = NdisProtRegisterAf;
	NdisRegisterProtocol(&ndissta,&global.protocolhandle, &pc, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
	if (ndissta != NDIS_STATUS_SUCCESS)
	{
		return STATUS_UNSUCCESSFUL;
	}
	NdisIMAssociateMiniport(global.driverhandle, global.protocolhandle);

	sta = ZlzCreateDevice(driver,wraphandle);
	if (!NT_SUCCESS(sta))
	{
		return STATUS_UNSUCCESSFUL;
	}

	NdisMRegisterUnloadHandler(wraphandle, unload);
    return STATUS_SUCCESS;
}
Exemple #10
0
// 初始化协议驱动
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObj, PUNICODE_STRING pRegistryString)
{
	NTSTATUS status = STATUS_SUCCESS;
	PDEVICE_OBJECT pDeviceObj = NULL;
	NDIS_STRING protoName = NDIS_STRING_CONST("Packet");
	// 给用户使用的符号连接名称
	UNICODE_STRING ustrSymbolicLink;
	BOOLEAN bSymbolicLink = FALSE;

	DbgPrint(" ProtoDrv: DriverEntry...  \n");

	// 保存驱动对象指针。这里,g_data是GLOBAL类型的全局变量
	g_data.pDriverObj = pDriverObj;

	do
	{
			// 为此驱动创建一个控制设备对象。用户程序向这个设备发送IOCTL代码,
			// 以便获取绑定的适配器信息
		UNICODE_STRING ustrDevName;
		RtlInitUnicodeString(&ustrDevName, DEVICE_NAME);
		status = IoCreateDevice(pDriverObj, 
			0,
			&ustrDevName, 
			FILE_DEVICE_UNKNOWN,
			0,
			FALSE,
			&pDeviceObj);
		if(!NT_SUCCESS(status))
		{
			DbgPrint(" ProtoDrv: CreateDevice failed \n");
			break;
		}
		// 为上面的设备创建符号连接
		RtlInitUnicodeString(&ustrSymbolicLink, LINK_NAME);
		status = IoCreateSymbolicLink(&ustrSymbolicLink, &ustrDevName);  
		if(!NT_SUCCESS(status))
		{
			DbgPrint(" ProtoDrv: CreateSymbolicLink failed \n");
			break;
		}
		bSymbolicLink = TRUE;
		// 设置为缓冲区I/O方式
		pDeviceObj->Flags |= DO_BUFFERED_IO;

			// 初始化全局变量
		g_data.pControlDevice = pDeviceObj;
		InitializeListHead(&g_data.AdapterList);
		KeInitializeSpinLock(&g_data.GlobalLock);

			// 初始化协议特征结构
		NDIS_PROTOCOL_CHARACTERISTICS protocolChar;
		NdisZeroMemory(&protocolChar, sizeof(protocolChar));
		protocolChar.Ndis40Chars.Ndis30Chars.MajorNdisVersion = 5;
		protocolChar.Ndis40Chars.Ndis30Chars.MinorNdisVersion = 0;

		protocolChar.Ndis40Chars.Ndis30Chars.Name = protoName;

		protocolChar.Ndis40Chars.BindAdapterHandler = ProtocolBindAdapter;
		protocolChar.Ndis40Chars.UnbindAdapterHandler = ProtocolUnbindAdapter;
		
		protocolChar.Ndis40Chars.Ndis30Chars.OpenAdapterCompleteHandler  = ProtocolOpenAdapterComplete;
		protocolChar.Ndis40Chars.Ndis30Chars.CloseAdapterCompleteHandler = ProtocolCloseAdapterComplete;

		protocolChar.Ndis40Chars.Ndis30Chars.ReceiveHandler              = ProtocolReceive;
//		protocolChar.Ndis40Chars.ReceivePacketHandler					= ProtocolReceivePacket;
		protocolChar.Ndis40Chars.Ndis30Chars.TransferDataCompleteHandler = ProtocolTransferDataComplete;

		protocolChar.Ndis40Chars.Ndis30Chars.SendCompleteHandler         = ProtocolSendComplete;

		
		protocolChar.Ndis40Chars.Ndis30Chars.ResetCompleteHandler        = ProtocolResetComplete;
		protocolChar.Ndis40Chars.Ndis30Chars.RequestCompleteHandler      = ProtocolRequestComplete;
		
		protocolChar.Ndis40Chars.Ndis30Chars.ReceiveCompleteHandler      = ProtocolReceiveComplete;
		
		protocolChar.Ndis40Chars.Ndis30Chars.StatusHandler               = ProtocolStatus;
		protocolChar.Ndis40Chars.Ndis30Chars.StatusCompleteHandler       = ProtocolStatusComplete;
		protocolChar.Ndis40Chars.PnPEventHandler						= ProtocolPNPHandler; 
		
			// 注册为协议驱动
		NdisRegisterProtocol((PNDIS_STATUS)&status, 
			&g_data.hNdisProtocol, &protocolChar, sizeof(protocolChar));
		if(status != NDIS_STATUS_SUCCESS)
		{
			status = STATUS_UNSUCCESSFUL;
			break;
		}
		DbgPrint(" ProtoDrv: NdisRegisterProtocol success \n");

			// 现在,设置我们要处理的派遣例程
		pDriverObj->MajorFunction[IRP_MJ_CREATE] = DispatchCreate;
		pDriverObj->MajorFunction[IRP_MJ_CLOSE] = DispatchClose;
		pDriverObj->MajorFunction[IRP_MJ_READ]  = DispatchRead;
		pDriverObj->MajorFunction[IRP_MJ_WRITE]  = DispatchWrite;
		pDriverObj->MajorFunction[IRP_MJ_CLEANUP]  = DispatchCleanup;

		pDriverObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchIoctl;
		pDriverObj->DriverUnload = DriverUnload;	
		status = STATUS_SUCCESS;
	}while(FALSE);
	
	if(!NT_SUCCESS(status))		// 错误处理
	{
		if(pDeviceObj != NULL)
		{
			// 删除设备对象
			IoDeleteDevice(pDeviceObj); 
			g_data.pControlDevice = NULL;
		}
		if(bSymbolicLink)
		{
			// 删除符号连接
			IoDeleteSymbolicLink(&ustrSymbolicLink);
		}
	}
	return status;
}
NTSTATUS GingkoNdisDriverEntry(
    IN PDRIVER_OBJECT        DriverObject,
    IN PUNICODE_STRING       RegistryPath
    )
{
	NDIS_STATUS                        Status;
    NDIS_PROTOCOL_CHARACTERISTICS      PChars;
    NDIS_MINIPORT_CHARACTERISTICS      MChars;
    NDIS_STRING                        Name;

    Status = NDIS_STATUS_SUCCESS;
    NdisAllocateSpinLock(&GlobalLock);
    NdisMInitializeWrapper(&NdisWrapperHandle, DriverObject, RegistryPath, NULL);
	KdPrint(("Calling NdisMInitializeWrapper Before\n"));

    do
    {
        //
        // 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.
        //

        NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS));

        MChars.MajorNdisVersion = PASSTHRU_MAJOR_NDIS_VERSION;
        MChars.MinorNdisVersion = PASSTHRU_MINOR_NDIS_VERSION;

        MChars.InitializeHandler = GingkoNdisInitialize;
        MChars.QueryInformationHandler = GingkoNdisQueryInformation;
        MChars.SetInformationHandler = GingkoNdisSetInformation;
        MChars.ResetHandler = NULL;
        MChars.TransferDataHandler = GingkoNdisTransferData;
        MChars.HaltHandler = GingkoNdisHalt;
#ifdef NDIS51_MINIPORT
        MChars.CancelSendPacketsHandler = GingkoNdisCancelSendPackets;
        MChars.PnPEventNotifyHandler = GingkoNdisDevicePnPEvent;
        MChars.AdapterShutdownHandler = GingkoNdisAdapterShutdown;
#endif // NDIS51_MINIPORT

        //
        // We will disable the check for hang timeout so we do not
        // need a check for hang handler!
        //
        MChars.CheckForHangHandler = NULL;
        MChars.ReturnPacketHandler = GingkoNdisReturnPacket;

        //
        // Either the Send or the SendPackets handler should be specified.
        // If SendPackets handler is specified, SendHandler is ignored
        //
        MChars.SendHandler = NULL;    // MPSend;
        MChars.SendPacketsHandler = GingkoNdisSendPackets;

        Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle,
                                                  &MChars,
                                                  sizeof(MChars),
                                                  &DriverHandle);

		KdPrint(("Calling NdisIMRegisterLayeredMiniport After\n"));
		///return 0;
        if (Status != NDIS_STATUS_SUCCESS)
        {
            break;
        }


#ifndef WIN9X
        NdisMRegisterUnloadHandler(NdisWrapperHandle, GingkoNdisUnload);
#endif

        //
        // Now register the protocol.
        //
        NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
        PChars.MajorNdisVersion = PASSTHRU_PROT_MAJOR_NDIS_VERSION;
        PChars.MinorNdisVersion = PASSTHRU_PROT_MINOR_NDIS_VERSION;

        //
        // Make sure the protocol-name matches the service-name
        // (from the INF) under which this protocol is installed.
        // This is needed to ensure that NDIS can correctly determine
        // the binding and call us to bind to miniports below.
        //
        NdisInitUnicodeString(&Name, L"GingkoFilter");    // Protocol name
        PChars.Name = Name;
        PChars.OpenAdapterCompleteHandler = GingkoNdisOpenAdapterComplete;
        PChars.CloseAdapterCompleteHandler = GingkoNdisCloseAdapterComplete;
        PChars.SendCompleteHandler = GingkoNdisSendComplete;
        PChars.TransferDataCompleteHandler = GingkoNdisTransferDataComplete;
    
        PChars.ResetCompleteHandler = GingkoNdisResetComplete;
        PChars.RequestCompleteHandler = GingkoNdisRequestComplete;
        PChars.ReceiveHandler = GingkoNdisReceive;
        PChars.ReceiveCompleteHandler = GingkoNdisReceiveComplete;
        PChars.StatusHandler = GingkoNdisStatus;
        PChars.StatusCompleteHandler = GingkoNdisStatusComplete;
        PChars.BindAdapterHandler = GingkoNdisBindAdapter;
        PChars.UnbindAdapterHandler = GingkoNdisUnbindAdapter;
        PChars.UnloadHandler = GingkoNdisUnloadProtocol;

        PChars.ReceivePacketHandler = GingkoNdisReceivePacket;
        PChars.PnPEventHandler= GingkoNdisPNPHandler;

        NdisRegisterProtocol(&Status,
                             &ProtHandle,
                             &PChars,
                             sizeof(NDIS_PROTOCOL_CHARACTERISTICS));

		KdPrint(("Calling NdisRegisterProtocol After\n"));
        if (Status != NDIS_STATUS_SUCCESS)
        {
            NdisIMDeregisterLayeredMiniport(DriverHandle);
            break;
        }

        NdisIMAssociateMiniport(DriverHandle, ProtHandle);

		KdPrint(("Calling NdisIMAssociateMiniport After\n"));
    }
    while (FALSE);

    if (Status != NDIS_STATUS_SUCCESS)
    {
        NdisTerminateWrapper(NdisWrapperHandle, NULL);
    }

    return(Status);
}
Exemple #12
0
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT        DriverObject,
    IN PUNICODE_STRING       RegistryPath
    )
{
    NDIS_STATUS                        Status;
    NDIS40_PROTOCOL_CHARACTERISTICS    PChars40;
    NDIS40_MINIPORT_CHARACTERISTICS    MChars40;
    NDIS50_PROTOCOL_CHARACTERISTICS    PChars50;
    NDIS51_MINIPORT_CHARACTERISTICS    MChars51;
    NDIS_STRING                        Name;

    Status = NDIS_STATUS_SUCCESS;

	g_ArpFw_ShareMem = NULL;

    NdisAllocateSpinLock(&GlobalLock);

	g_CurrentDriver = DriverObject;

	LoadDynamicFunction();  //识别版本并加载额外函数

//	Status = InitPacketList();

//	if( Status != STATUS_SUCCESS)
//	{
//		return Status;
//	}

    NdisMInitializeWrapper(&NdisWrapperHandle, DriverObject, RegistryPath, NULL);

	if(IS_NDIS51())
	{
	    do
	    {
        	//
        	// 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.
        	//
        	NdisZeroMemory(&MChars51, sizeof(NDIS51_MINIPORT_CHARACTERISTICS));

        	MChars51.MajorNdisVersion = 5;
        	MChars51.MinorNdisVersion = 1;

        	MChars51.InitializeHandler 			= MiniportInitialize5;
        	MChars51.QueryInformationHandler 	= MiniportQueryInformation5;
        	MChars51.SetInformationHandler 		= MiniportSetInformation5;
        	MChars51.ResetHandler 				= NULL;
        	MChars51.TransferDataHandler 		= MiniportTransferData5;
        	MChars51.HaltHandler 				= MiniportHalt5;

			//NDIS51++
        	MChars51.CancelSendPacketsHandler 	= MiniportCancelSendPackets5;
        	MChars51.PnPEventNotifyHandler 		= MiniportDevicePnPEvent5;
        	MChars51.AdapterShutdownHandler 	= MiniportAdapterShutdown5;
			//--NDIS51

        	//
        	// We will disable the check for hang timeout so we do not
        	// need a check for hang handler!
        	//
        	MChars51.CheckForHangHandler 		= MiniportCheckForHang5;
        	MChars51.ReturnPacketHandler 		= MiniportReturnPacket5;

        	//
        	// Either the Send or the SendPackets handler should be specified.
        	// If SendPackets handler is specified, SendHandler is ignored
        	//
        	MChars51.SendHandler 				= NULL;
        	MChars51.SendPacketsHandler 		= MiniportSendPackets5;

        	Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle,
                                                  (PVOID)&MChars51,
                                                  sizeof(NDIS51_MINIPORT_CHARACTERISTICS),
                                                  &DriverHandle);
        	if (Status != NDIS_STATUS_SUCCESS)
        	{
            	break;
        	}

        	NdisMRegisterUnloadHandler(NdisWrapperHandle, ProtocolUnload);


        	//
        	// Now register the protocol.
        	//
        	NdisZeroMemory(&PChars50, sizeof(NDIS50_PROTOCOL_CHARACTERISTICS));
        	PChars50.MajorNdisVersion = 5;
        	PChars50.MinorNdisVersion = 0;

        	//
        	// Make sure the protocol-name matches the service-name
        	// (from the INF) under which this protocol is installed.
        	// This is needed to ensure that NDIS can correctly determine
        	// the binding and call us to bind to miniports below.
        	//
        	NdisInitUnicodeString(&Name, PROTOCOL_NAME);    // Protocol name
        	PChars50.Name 							= Name;
        	PChars50.OpenAdapterCompleteHandler 	= ProtocolOpenAdapterComplete5;
        	PChars50.CloseAdapterCompleteHandler 	= ProtocolCloseAdapterComplete5;
        	PChars50.SendCompleteHandler 			= ProtocolSendComplete5;
        	PChars50.TransferDataCompleteHandler 	= ProtocolTransferDataComplete5;
    
        	PChars50.ResetCompleteHandler 			= ProtocolResetComplete5;
        	PChars50.RequestCompleteHandler 		= ProtocolRequestComplete5;
        	PChars50.ReceiveHandler 				= ProtocolReceive5;
        	PChars50.ReceiveCompleteHandler 		= ProtocolReceiveComplete5;
        	PChars50.StatusHandler 					= ProtocolStatus5;
        	PChars50.StatusCompleteHandler 			= ProtocolStatusComplete5;
        	PChars50.BindAdapterHandler 			= ProtocolBindAdapter5;
        	PChars50.UnbindAdapterHandler 			= ProtocolUnbindAdapter5;
        	PChars50.UnloadHandler 					= ProtocolUnloadProtocol5;

        	PChars50.ReceivePacketHandler 			= ProtocolReceivePacket5;
        	PChars50.PnPEventHandler				= ProtocolPNPHandler5;

        	NdisRegisterProtocol(&Status,
                             &ProtHandle,
                             (PVOID)&PChars50,
                             sizeof(NDIS50_PROTOCOL_CHARACTERISTICS));

        	if (Status != NDIS_STATUS_SUCCESS)
        	{
            	NdisIMDeregisterLayeredMiniport(DriverHandle);
            	break;
        	}

        	NdisIMAssociateMiniport(DriverHandle, ProtHandle);
    	}
    	while (FALSE);

	}
	else
	{
		do
		{
			//注册 Miniport
			NdisZeroMemory(&MChars40, sizeof(NDIS40_MINIPORT_CHARACTERISTICS));

			MChars40.MajorNdisVersion = 4;
			MChars40.MinorNdisVersion = 0;

			MChars40.InitializeHandler 			= MiniportInitialize4;
			MChars40.QueryInformationHandler 	= MiniportQueryInformation4;
			MChars40.SetInformationHandler 		= MiniportSetInformation4;
			MChars40.ResetHandler 				= NULL;
			MChars40.TransferDataHandler 		= MiniportTransferData4;
			MChars40.HaltHandler 				= MiniportHalt4;

			MChars40.CheckForHangHandler 		= MiniportCheckForHang4;
			MChars40.ReturnPacketHandler 		= MiniportReturnPacket4;

			MChars40.SendHandler 				= NULL;
			MChars40.SendPacketsHandler 		= MiniportSendPackets4;

			Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle,
													  (PVOID)&MChars40,
													  sizeof(MChars40),
													  &DriverHandle);
			if (Status != NDIS_STATUS_SUCCESS)
			{
				break;
			}

			NdisMRegisterUnloadHandler(NdisWrapperHandle, ProtocolUnload);

			//
			// Now register the protocol.
			//
			NdisZeroMemory(&PChars40, sizeof(NDIS40_PROTOCOL_CHARACTERISTICS));
			PChars40.MajorNdisVersion = 4;
			PChars40.MinorNdisVersion = 0;

			NdisInitUnicodeString(&Name, PROTOCOL_NAME);    // Protocol name
			PChars40.Name 							= Name;
			PChars40.OpenAdapterCompleteHandler 	= ProtocolOpenAdapterComplete4;
			PChars40.CloseAdapterCompleteHandler 	= ProtocolCloseAdapterComplete4;
			PChars40.SendCompleteHandler 			= ProtocolSendComplete4;
			PChars40.TransferDataCompleteHandler 	= ProtocolTransferDataComplete4;
    
			PChars40.ResetCompleteHandler 			= ProtocolResetComplete4;
			PChars40.RequestCompleteHandler 		= ProtocolRequestComplete4;
			PChars40.ReceiveHandler 				= ProtocolReceive4;
			PChars40.ReceiveCompleteHandler 		= ProtocolReceiveComplete4;
			PChars40.StatusHandler 					= ProtocolStatus4;
			PChars40.StatusCompleteHandler 			= ProtocolStatusComplete4;
			PChars40.BindAdapterHandler 			= ProtocolBindAdapter4;
			PChars40.UnbindAdapterHandler 			= ProtocolUnbindAdapter4;
			PChars40.UnloadHandler 					= ProtocolUnloadProtocol4;

			PChars40.ReceivePacketHandler 			= ProtocolReceivePacket4;
			PChars40.PnPEventHandler				= ProtocolPNPHandler4;

			NdisRegisterProtocol(&Status,
								 &ProtHandle,
								 (PVOID)&PChars40,
								 sizeof(NDIS40_PROTOCOL_CHARACTERISTICS));
			if (Status != NDIS_STATUS_SUCCESS)
			{
				NdisIMDeregisterLayeredMiniport(DriverHandle);
				break;
			}

			NdisIMAssociateMiniport(DriverHandle, ProtHandle);

		}
		while (FALSE);
	}

    if (Status != NDIS_STATUS_SUCCESS)
    {
        NdisTerminateWrapper(NdisWrapperHandle, NULL);
		NdisFreeSpinLock(&GlobalLock);
    }

    return(Status);
}
Exemple #13
-1
DLC_STATUS
LlcInitialize(
    VOID
    )

/*++

Routine Description:

    The routines initializes the protocol module and
    does the minimal stuff, that must be done in the
    serialized initialization routine.

Arguments:

    None.

Return Value:

    NDIS_STATUS

--*/

{
    NDIS_STATUS Status;

    ASSUME_IRQL(PASSIVE_LEVEL);

    //
    // We must build a MDL for the XID information used
    // when the link level takes care of XID handling.
    //

    pXidMdl = IoAllocateMdl(&Ieee802Xid,
                            sizeof(Ieee802Xid),
                            FALSE,
                            FALSE,
                            NULL
                            );
    if (pXidMdl == NULL) {
        return DLC_STATUS_NO_MEMORY;
    }

#if LLC_DBG

    ALLOCATE_SPIN_LOCK(&MemCheckLock);

#endif

    MmBuildMdlForNonPagedPool(pXidMdl);
    LlcInitializeTimerSystem();
    NdisRegisterProtocol(&Status,
                         &LlcProtocolHandle,
                         &LlcCharacteristics,
                         sizeof(LlcCharacteristics)
                         );

    KeInitializeSpinLock(&LlcSpinLock);

    ASSUME_IRQL(PASSIVE_LEVEL);

    KeInitializeMutex(&NdisAccessMutex, 1);

    //
    // We use the OpenAdapterSemaphore in the LlcOpenAdapter function. We really
    // want a mutex, but a mutex causes us problems on a checked build if we
    // make a call into NTOS. In either case, we just need a mechanism to ensure
    // only one thread is creating the ADAPTER_CONTEXT & opening the adapter at
    // NDIS level
    //

    KeInitializeSemaphore(&OpenAdapterSemaphore, 1, 1);

    if (Status != STATUS_SUCCESS) {
        IoFreeMdl(pXidMdl);
    }
    return Status;
}