Example #1
0
/*****************************************************************************
 * DriverEntry()
 *
 *   この関数のは System がこのドライバをロードするときに呼ばれ、ドライバを
 *   NDIS と関連付け、エントリポイントを登録する。
 * 
 * 引数:
 *     DriverObject :  ドライバーオブジェクトのポインタ
 *     RegistryPath :  ドライバーのレジストリのパス 関連付け
 *  
 * 返り値:
 * 
 *     NDIS_STATUS 
 * 
 ********************************************************************************/
NDIS_STATUS
DriverEntry(
    IN PVOID DriverObject,
    IN PVOID RegistryPath)
{
    NDIS_MINIPORT_CHARACTERISTICS  MiniportCharacteristics;
    NDIS_STATUS                    Status;

    DEBUG_PRINT0(3, "DriverEntry called\n");        

    NdisZeroMemory(&MiniportCharacteristics, sizeof(NDIS_MINIPORT_CHARACTERISTICS));

    /*
     * ミニポートドライバを NDIS に関連付けし、NdisWrapperHandle を得る。
     */
    NdisMInitializeWrapper(
        &NdisWrapperHandle, // OUT PNDIS_HANDLE  
        DriverObject,       // IN ドライバーオブジェクト
        RegistryPath,       // IN レジストリパス
        NULL                // IN 必ず NULL
        );

    if(NdisWrapperHandle == NULL){
        DEBUG_PRINT0(1, "NdisInitializeWrapper failed\n");
        return(STATUS_INVALID_HANDLE);
    }

    MiniportCharacteristics.MajorNdisVersion         = STE_NDIS_MAJOR_VERSION; // Major Version 
    MiniportCharacteristics.MinorNdisVersion         = STE_NDIS_MINOR_VERSION; // Minor Version 
    MiniportCharacteristics.CheckForHangHandler      = SteMiniportCheckForHang;     
    MiniportCharacteristics.HaltHandler              = SteMiniportHalt;             
    MiniportCharacteristics.InitializeHandler        = SteMiniportInitialize;       
    MiniportCharacteristics.QueryInformationHandler  = SteMiniportQueryInformation; 
    MiniportCharacteristics.ResetHandler             = SteMiniportReset ;            
    MiniportCharacteristics.SetInformationHandler    = SteMiniportSetInformation;   
    MiniportCharacteristics.ReturnPacketHandler      = SteMiniportReturnPacket;    
    MiniportCharacteristics.SendPacketsHandler       = SteMiniportSendPackets; 

    Status = NdisMRegisterMiniport(     
        NdisWrapperHandle,                    // IN NDIS_HANDLE                     
        &MiniportCharacteristics,             // IN PNDIS_MINIPORT_CHARACTERISTICS  
        sizeof(NDIS_MINIPORT_CHARACTERISTICS) // IN UINT                            
        );

    if( Status != NDIS_STATUS_SUCCESS){
        DEBUG_PRINT1(1, "NdisMRegisterMiniport failed(Status = 0x%x)\n", Status);
        NdisTerminateWrapper(
            NdisWrapperHandle, // IN NDIS_HANDLE  
            NULL               
            );        
        return(Status);
    }

    // グローバルロックを初期化
    NdisAllocateSpinLock(&SteGlobalSpinLock);

    NdisMRegisterUnloadHandler(NdisWrapperHandle, SteMiniportUnload);    
    
    return(NDIS_STATUS_SUCCESS);
}
Example #2
0
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
	NTSTATUS result = STATUS_SUCCESS, stat;
	NDIS_HANDLE wrapperHandle;
	NDIS40_MINIPORT_CHARACTERISTICS info;

	DBGOUT(("==> IRMINI_Entry()"));

	NdisMInitializeWrapper(	(PNDIS_HANDLE)&wrapperHandle,
							DriverObject,
							RegistryPath,
							NULL
							);
	DBGOUT(("Wrapper handle is %xh", (UINT)wrapperHandle));

	info.MajorNdisVersion			=	(UCHAR)NDIS_MAJOR_VERSION;		
	info.MinorNdisVersion			=	(UCHAR)NDIS_MINOR_VERSION;	
//	info.Flags						=	0; 
	info.CheckForHangHandler		=	MiniportCheckForHang; 	
	info.HaltHandler				=	MiniportHalt; 	
	info.InitializeHandler			=	MiniportInitialize;  
	info.QueryInformationHandler	=	MiniportQueryInformation; 
	info.ReconfigureHandler			=	MiniportReconfigure;  
	info.ResetHandler				=	MiniportReset; 
	info.SendHandler				=	MiniportSend;  
	info.SetInformationHandler		=	MiniportSetInformation; 
	info.TransferDataHandler		=	MiniportTransferData; 

	info.HandleInterruptHandler		=	MiniportHandleInterrupt;
	info.ISRHandler					=	MiniportISR;  
	info.DisableInterruptHandler	=	MiniportDisableInterrupt;
	info.EnableInterruptHandler		=	MiniportEnableInterrupt; 

	
	/*
	 *  New NDIS 4.0 fields
	 */
	info.ReturnPacketHandler		=	ReturnPacketHandler;   
    info.SendPacketsHandler			=	SendPacketsHandler;	
	info.AllocateCompleteHandler	=	AllocateCompleteHandler;


	stat = NdisMRegisterMiniport(	wrapperHandle,
									(PNDIS_MINIPORT_CHARACTERISTICS)&info,
									sizeof(NDIS_MINIPORT_CHARACTERISTICS));
	if (stat != NDIS_STATUS_SUCCESS){
		DBGERR(("NdisMRegisterMiniport failed in DriverEntry"));
		result = STATUS_UNSUCCESSFUL;
		goto _entryDone;
	}

 _entryDone:	
	DBGOUT(("<== IRMINI_Entry %s", (PUCHAR)((result == NDIS_STATUS_SUCCESS) ? "succeeded" : "failed")));
	return result;

}
Example #3
0
// Win32 driver entry point
NDIS_STATUS DriverEntry(DRIVER_OBJECT *DriverObject, UNICODE_STRING *RegistryPath)
{
	NDIS_MINIPORT_CHARACTERISTICS miniport;
	ULONG os_major_ver = 0, os_minor_ver = 0;

	// Initialize the Neo library
	if (NeoInit() == FALSE)
	{
		// Initialization Failed
		return STATUS_UNSUCCESSFUL;
	}

	g_is_win8 = false;

#ifndef	NDIS30_MINIPORT
	// Get the OS version
	PsGetVersion(&os_major_ver, &os_minor_ver, NULL, NULL);

	if (os_major_ver >= 7 || (os_major_ver == 6 && os_minor_ver >= 2))
	{
		// Windows 8
		g_is_win8 = true;
	}
#endif	// NDIS30_MINIPORT

	// Initialize the NDIS wrapper
	NdisMInitializeWrapper(&ctx->NdisWrapper, DriverObject, RegistryPath, NULL);
	ndis_wrapper_handle = ctx->NdisWrapper;

	// Register a NDIS miniport driver
	NeoZero(&miniport, sizeof(NDIS_MINIPORT_CHARACTERISTICS));
	miniport.MajorNdisVersion = NEO_NDIS_MAJOR_VERSION;
	miniport.MinorNdisVersion = NEO_NDIS_MINOR_VERSION;

	// Register the handler
	miniport.InitializeHandler = NeoNdisInit;
	miniport.HaltHandler = NeoNdisHalt;
	miniport.QueryInformationHandler = NeoNdisQuery;
	miniport.ResetHandler = NeoNdisReset;
	miniport.SetInformationHandler = NeoNdisSet;

#ifndef	NDIS30_MINIPORT
	miniport.SendPacketsHandler = NeoNdisSendPackets;
#else	// NDIS30_MINIPORT
	miniport.SendHandler = NULL;
#endif	// NDIS30_MINIPORT

	if (NG(NdisMRegisterMiniport(ctx->NdisWrapper, &miniport, sizeof(NDIS_MINIPORT_CHARACTERISTICS))))
	{
		// Registration failure
		return STATUS_UNSUCCESSFUL;
	}

	// Initialization success
	return STATUS_SUCCESS;
}
Example #4
0
extern "C" NTSTATUS DriverEntry(
        IN PDRIVER_OBJECT pDriverObject,
        IN PUNICODE_STRING pRegistryPath)
{
    NDIS_STATUS  status;
    NDIS_HANDLE  hwrapper;
    
    NDIS40_MINIPORT_CHARACTERISTICS ndischar;
    
    PUTS(("<Davicom DM9000x / DM900x driver v3.7.0 for WinCE 4.2/5.0/6.0> \r\n"));
    PUTS(("(netbook/smartbook default(a.x.w))\r\n"));
    
    NdisMInitializeWrapper(
        &hwrapper,
        pDriverObject,
        pRegistryPath,
        NULL);
        
    memset((void*)&ndischar, 0, sizeof(ndischar));
    
    ndischar.Ndis30Chars.MajorNdisVersion = PRJ_NDIS_MAJOR_VERSION;
    ndischar.Ndis30Chars.MinorNdisVersion = PRJ_NDIS_MINOR_VERSION;
    
    ndischar.Ndis30Chars.CheckForHangHandler = MiniportCheckForHang;
    
    ndischar.Ndis30Chars.HaltHandler = MiniportHalt;
    ndischar.Ndis30Chars.HandleInterruptHandler = MiniportInterruptHandler;
    ndischar.Ndis30Chars.InitializeHandler = MiniportInitialize;
    ndischar.Ndis30Chars.ISRHandler = MiniportISRHandler;
    ndischar.Ndis30Chars.QueryInformationHandler = MiniportQueryInformation;
    
    ndischar.Ndis30Chars.ResetHandler = MiniportReset;
    ndischar.Ndis30Chars.SendHandler = MiniportSend;
    ndischar.Ndis30Chars.SetInformationHandler = MiniportSetInformation;
    
    if ((status = NdisMRegisterMiniport(
                      hwrapper,
                      (PNDIS_MINIPORT_CHARACTERISTICS) & ndischar,
                      sizeof(ndischar)) != NDIS_STATUS_SUCCESS))
    {
        NdisTerminateWrapper(hwrapper, NULL);
        return status;
    }
    
    
#ifndef IMPL_DLL_ENTRY
    INIT_EXCEPTION();
#endif
    
    return NDIS_STATUS_SUCCESS;
    
}
Example #5
0
NTSTATUS
NTAPI
DriverEntry (
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
    NDIS_HANDLE wrapperHandle;
    NDIS_MINIPORT_CHARACTERISTICS characteristics;
    NDIS_STATUS status;

    RtlZeroMemory(&characteristics, sizeof(characteristics));
    characteristics.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
    characteristics.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
    characteristics.CheckForHangHandler = NULL;
    characteristics.DisableInterruptHandler = NULL;
    characteristics.EnableInterruptHandler = NULL;
    characteristics.HaltHandler = MiniportHalt;
    characteristics.HandleInterruptHandler = MiniportHandleInterrupt;
    characteristics.InitializeHandler = MiniportInitialize;
    characteristics.ISRHandler = MiniportISR;
    characteristics.QueryInformationHandler = MiniportQueryInformation;
    characteristics.ReconfigureHandler = NULL;
    characteristics.ResetHandler = MiniportReset;
    characteristics.SendHandler = MiniportSend;
    characteristics.SetInformationHandler = MiniportSetInformation;
    characteristics.TransferDataHandler = NULL;
    characteristics.ReturnPacketHandler = NULL;
    characteristics.SendPacketsHandler = NULL;
    characteristics.AllocateCompleteHandler = NULL;

    NdisMInitializeWrapper(&wrapperHandle, DriverObject, RegistryPath, NULL);
    if (!wrapperHandle)
    {
        return NDIS_STATUS_FAILURE;
    }

    status = NdisMRegisterMiniport(wrapperHandle, &characteristics, sizeof(characteristics));
    if (status != NDIS_STATUS_SUCCESS)
    {
        NdisTerminateWrapper(wrapperHandle, 0);
        return NDIS_STATUS_FAILURE;
    }

    return NDIS_STATUS_SUCCESS;
}
/*************************************************************
Driver's entry point
Parameters:
	as usual
Return value:
	SUCCESS or error code
*************************************************************/
NDIS_STATUS DriverEntry(PVOID DriverObject,PVOID RegistryPath)
{
	NDIS_STATUS status;
	NDIS_MINIPORT_CHARACTERISTICS chars;
	ParaNdis_DebugInitialize(DriverObject, RegistryPath);

	status = NDIS_STATUS_FAILURE;

	DEBUG_ENTRY(0);
	_LogOutString(0, __DATE__ " " __TIME__);

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

	if (DriverHandle)
	{
		NdisZeroMemory(&chars, sizeof(chars));
		//NDIS version of the miniport
		chars.MajorNdisVersion			= NDIS_MINIPORT_MAJOR_VERSION;
		chars.MinorNdisVersion			= NDIS_MINIPORT_MINOR_VERSION;
		//Init and destruction
		chars.InitializeHandler			= ParaNdis5_Initialize;
		chars.HaltHandler				= ParaNdis5_Halt;

		//Interrupt and DPC handling
		chars.HandleInterruptHandler	= ParaNdis5_HandleDPC;
		chars.ISRHandler				= ParaNdis5_MiniportISR;

		//Packet transfer - send path and notification on the send packet
		chars.SendPacketsHandler		= ParaNdis5_SendPackets;
		chars.ReturnPacketHandler		= ParaNdis5_ReturnPacket;

		//OID set\get
		chars.SetInformationHandler		= ParaNdis5_SetOID;
		chars.QueryInformationHandler	= ParaNdis5_QueryOID;

		//Reset
		chars.ResetHandler				= ParaNdis5_Reset;
		chars.CheckForHangHandler		= ParaNdis5_CheckForHang; //optional

#ifdef NDIS51_MINIPORT
		chars.CancelSendPacketsHandler	= ParaNdis5_CancelSendPackets;
		chars.PnPEventNotifyHandler		= ParaNdis5_PnPEventNotify;
		chars.AdapterShutdownHandler	= ParaNdis5_Shutdown;
#endif
		status = NdisMRegisterMiniport(
			DriverHandle,
			&chars,
			sizeof(chars));
	}

	if (status == NDIS_STATUS_SUCCESS)
	{
		NdisMRegisterUnloadHandler(DriverHandle, ParaVirtualNICUnload);
	}
	else if (DriverHandle)
	{
		DPrintf(0, ("NdisMRegisterMiniport failed"));
		NdisTerminateWrapper(DriverHandle, NULL);
	}
	else
	{
		DPrintf(0, ("NdisMInitializeWrapper failed"));
	}

	DEBUG_EXIT_STATUS(status ? 0 : 4, status);
	return status;
}
Example #7
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);
}
Example #8
0
NTSTATUS
DriverEntry(
  PDRIVER_OBJECT DriverObject,
  PUNICODE_STRING RegistryPath
  )
{
  NTSTATUS status;  
  NDIS_HANDLE ndis_wrapper_handle = NULL;
  NDIS_MINIPORT_CHARACTERISTICS mini_chars;

  FUNCTION_ENTER();

  KdPrint((__DRIVER_NAME "     DriverObject = %p, RegistryPath = %p\n", DriverObject, RegistryPath));
  
  NdisZeroMemory(&mini_chars, sizeof(mini_chars));

  KdPrint((__DRIVER_NAME "     NdisGetVersion = %x\n", NdisGetVersion()));

  KdPrint((__DRIVER_NAME "     ndis_wrapper_handle = %p\n", ndis_wrapper_handle));
  NdisMInitializeWrapper(&ndis_wrapper_handle, DriverObject, RegistryPath, NULL);
  KdPrint((__DRIVER_NAME "     ndis_wrapper_handle = %p\n", ndis_wrapper_handle));
  if (!ndis_wrapper_handle)
  {
    KdPrint((__DRIVER_NAME "     NdisMInitializeWrapper failed\n"));
    return NDIS_STATUS_FAILURE;
  }
  KdPrint((__DRIVER_NAME "     NdisMInitializeWrapper succeeded\n"));

  /* NDIS 5.1 driver */
  mini_chars.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
  mini_chars.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;

  KdPrint((__DRIVER_NAME "     MajorNdisVersion = %d,  MinorNdisVersion = %d\n", NDIS_MINIPORT_MAJOR_VERSION, NDIS_MINIPORT_MINOR_VERSION));

  mini_chars.HaltHandler = XenNet_Halt;
  mini_chars.InitializeHandler = XenNet_Init;
  //mini_chars.ISRHandler = XenNet_InterruptIsr;
  //mini_chars.HandleInterruptHandler = XenNet_InterruptDpc;
  mini_chars.QueryInformationHandler = XenNet_QueryInformation;
  mini_chars.ResetHandler = XenNet_Reset;
  mini_chars.SetInformationHandler = XenNet_SetInformation;
  /* added in v.4 -- use multiple pkts interface */
  mini_chars.ReturnPacketHandler = XenNet_ReturnPacket;
  mini_chars.SendPacketsHandler = XenNet_SendPackets;
  /* don't support cancel - no point as packets are never queued for long */
  //mini_chars.CancelSendPacketsHandler = XenNet_CancelSendPackets;

#ifdef NDIS51_MINIPORT
  /* added in v.5.1 */
  mini_chars.PnPEventNotifyHandler = XenNet_PnPEventNotify;
  mini_chars.AdapterShutdownHandler = XenNet_Shutdown;
#else
  // something else here
#endif

  /* set up upper-edge interface */
  KdPrint((__DRIVER_NAME "     about to call NdisMRegisterMiniport\n"));
  status = NdisMRegisterMiniport(ndis_wrapper_handle, &mini_chars, sizeof(mini_chars));
  KdPrint((__DRIVER_NAME "     called NdisMRegisterMiniport\n"));
  if (!NT_SUCCESS(status))
  {
    KdPrint((__DRIVER_NAME "     NdisMRegisterMiniport failed, status = 0x%x\n", status));
    NdisTerminateWrapper(ndis_wrapper_handle, NULL);
    return status;
  }

  FUNCTION_EXIT();

  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);
}
Example #10
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);
}
Example #11
0
NDIS_STATUS 
DriverEntry(
            PVOID DriverObject,
            PVOID RegistryPath)
{
    HRESULT                         hr;
    NDIS_STATUS                        status;
    NDIS_MINIPORT_CHARACTERISTICS    mpChar;
    
    DEBUGP(MP_TRACE, ("[HT_STARTUP]---> DriverEntry built on "__DATE__" at "__TIME__ 
        "MP_NDIS_MAJOR_VERSION=%d, MP_NDIS_MINOR_VERSION=%d\n", 
        MP_NDIS_MAJOR_VERSION, MP_NDIS_MINOR_VERSION));

    //Associate miniport driver with NDIS
    NdisMInitializeWrapper(
            &NdisWrapperHandle,
            DriverObject,
            RegistryPath,
            NULL
            );
    
    if(!NdisWrapperHandle){
        DEBUGP(MP_ERROR, ("NdisMInitializeWrapper failed\n"));
        return NDIS_STATUS_FAILURE;
    }

    NdisZeroMemory(&mpChar, sizeof(mpChar));
    mpChar.MajorNdisVersion          = MP_NDIS_MAJOR_VERSION;
    mpChar.MinorNdisVersion          = MP_NDIS_MINOR_VERSION;
    mpChar.InitializeHandler         = MPInitialize;
    mpChar.HaltHandler               = MPHalt;
    
    mpChar.SetInformationHandler     = MPSetInformation;
    mpChar.QueryInformationHandler   = MPQueryInformation;
    
    mpChar.SendPacketsHandler        = MPSendPackets;
    mpChar.ReturnPacketHandler       = MPReturnPacket;

#ifdef NDIS51_MINIPORT
    mpChar.CancelSendPacketsHandler = MPCancelSendPackets;
    mpChar.PnPEventNotifyHandler    = MPPnPEventNotify;
    mpChar.AdapterShutdownHandler   = MPShutdown;
#endif

    DEBUGP(MP_LOUD, ("[HT_STARTUP] Calling NdisMRegisterMiniport...\n"));
    status = NdisMRegisterMiniport(
                    NdisWrapperHandle,
                    &mpChar,
                    sizeof(NDIS_MINIPORT_CHARACTERISTICS));
    if (status != NDIS_STATUS_SUCCESS) {
        
        DEBUGP(MP_ERROR, ("Status = 0x%08x\n", status));
        NdisTerminateWrapper(NdisWrapperHandle, NULL);
        
    }
    else
    {
        NdisAllocateSpinLock(&GlobalData.Lock);
        NdisInitializeListHead(&GlobalData.AdapterList);  
        NdisMRegisterUnloadHandler(NdisWrapperHandle, MPUnload);
    }
    DEBUGP(MP_TRACE, ("[HT_STARTUP]<--- DriverEntry, Status=0x%08x\n", status));

    return status;
}
Example #12
0
NDIS_STATUS    
DriverEntry(
    PVOID  DriverObject, 
    PVOID  RegistryPath
    )
{
    NDIS_STATUS                   Status;
    NDIS_HANDLE                   NdisWrapperHandle;
    NDIS_MINIPORT_CHARACTERISTICS EmacChar;

    DEBUGMSG(DBG_FUNC, (L"---> DriverEntry\r\n"));

    /*  Notify the  NDIS library that driver is about to register itself as
     *  a miniport. NDIS sets up the state it needs to track the driver and
     *  returns an NDISWrapperHandle which driver uses for subsequent calls.
     */
    
     NdisMInitializeWrapper(
        &NdisWrapperHandle,
        DriverObject,
        RegistryPath,
        NULL);

    if (NdisWrapperHandle == NULL)
    {
        Status = NDIS_STATUS_FAILURE;

        DEBUGMSG(Status, (L"<--- DriverEntry failed to InitWrapper, Status=%x \r\n", Status));
        return Status;
    }

    /* Fill in the Miniport characteristics structure with the version numbers 
     * and the entry points for driver-supplied MiniportXxx 
     */
     
    NdisZeroMemory(&EmacChar, sizeof(EmacChar));

    EmacChar.MajorNdisVersion         = EMAC_NDIS_MAJOR_VERSION;
    EmacChar.MinorNdisVersion         = EMAC_NDIS_MINOR_VERSION;

    EmacChar.CheckForHangHandler      = Emac_MiniportCheckForHang;
    EmacChar.DisableInterruptHandler  = Emac_MiniportDisableInterrupt;
    EmacChar.EnableInterruptHandler   = NULL;
    EmacChar.HaltHandler              = Emac_MiniportHalt;
    EmacChar.HandleInterruptHandler   = Emac_MiniportHandleInterrupt;  
    EmacChar.InitializeHandler        = Emac_MiniportInitialize;
    EmacChar.ISRHandler               = Emac_MiniportIsr;  
    EmacChar.QueryInformationHandler  = Emac_MiniportQueryInformation;
    EmacChar.ReconfigureHandler       = NULL;  
    EmacChar.ResetHandler             = Emac_MiniportReset;
    EmacChar.SendHandler              = NULL;
    EmacChar.SetInformationHandler    = Emac_MiniportSetInformation;
    EmacChar.TransferDataHandler      = NULL;  
    EmacChar.ReturnPacketHandler      = Emac_MiniportReturnPacket;
    EmacChar.SendPacketsHandler       = Emac_MiniportSendPacketsHandler;
    EmacChar.AllocateCompleteHandler  = NULL;
    
    DEBUGMSG(TRUE, (L"Calling NdisMRegisterMiniport with NDIS_MINIPORT_MAJOR_VERSION %d" \
                     L"& NDIS_MINIPORT_MINOR_VERSION %d\r\n",
                      NDIS_MINIPORT_MAJOR_VERSION,NDIS_MINIPORT_MINOR_VERSION));
    
    /* Calling NdisMRegisterMiniport causes driver's MiniportInitialise
     * function to run in the context of NdisMRegisterMiniport.
     */
     
    
    Status = NdisMRegisterMiniport(
                 NdisWrapperHandle,
                 &EmacChar,
                 sizeof(NDIS_MINIPORT_CHARACTERISTICS));
    
    if(Status != NDIS_STATUS_SUCCESS)
    {
        /* Call NdisTerminateWrapper, and return the error code to the OS. */
        NdisTerminateWrapper(
            NdisWrapperHandle, 
            NULL);          /* Ignored */            
    }
        
    DEBUGMSG(DBG_INFO, (L"<--- DriverEntry, Status= %x\r\n", Status));

    return Status;
    
}