예제 #1
0
파일: ste.c 프로젝트: kaizawa/vpn-ste-win
/*****************************************************************************
 * 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);
}
예제 #2
0
/*--------------------------------------------------------------------------
  ssh_interceptor_register_upper_edge()
  
  Registers(Deregisters) the upper-edge (miniport) handlers of driver with 
  NDIS. After registration is done, NDIS can use these handlers for 
  communication with upper layer device (protocol) driver.
  
  Arguments:
  interceptor - SshInterceptor object,
  enable - Register/Deregister flag.
 
  Returns:
  NDIS_STATUS_SUCCESS - operation succeeded
  NDIS_STATUS_FAILURE - otherwise
  
  Notes:
  --------------------------------------------------------------------------*/
NDIS_STATUS
ssh_interceptor_register_upper_edge(SshNdisIMInterceptor interceptor,
                                    BOOLEAN enable)
{
  NDIS_STATUS status = NDIS_STATUS_SUCCESS;
  NDIS_MINIPORT_CHARACTERISTICS mp_chars;

  SSH_ASSERT(interceptor != NULL);

  SSH_DEBUG(SSH_D_NICETOKNOW, ("ssh_interceptor_register_upper_edge()"));

  if (enable == TRUE && interceptor->miniport_handle == NULL)
    {
      NdisZeroMemory(&mp_chars,sizeof(mp_chars));

      mp_chars.MajorNdisVersion = SSH_MAJOR_NDIS_VERSION;
      mp_chars.MinorNdisVersion = SSH_MINOR_NDIS_VERSION;

      mp_chars.CheckForHangHandler = ssh_driver_check_for_hang;
      mp_chars.HaltHandler = ssh_driver_deinitialize;
      mp_chars.InitializeHandler = ssh_driver_initialize;
      mp_chars.ResetHandler = ssh_driver_reset;
      mp_chars.SendHandler = NULL;
#ifdef _WIN32_WCE
      mp_chars.WanSendHandler = ssh_driver_send_wan_packet;
#endif /* _WIN32_WCE */
      mp_chars.SendPacketsHandler = ssh_driver_send_packets;
      mp_chars.TransferDataHandler = ssh_driver_transfer_data;
      mp_chars.ReturnPacketHandler = ssh_driver_return_packet;
      mp_chars.QueryInformationHandler = ssh_driver_query_information;
      mp_chars.SetInformationHandler = ssh_driver_set_information;

      status = NdisIMRegisterLayeredMiniport(interceptor->wrapper_handle,
                                             &mp_chars,
                                             sizeof(mp_chars),
                                             &interceptor->miniport_handle);

      if (status != NDIS_STATUS_SUCCESS)
        {
          interceptor->miniport_handle = NULL;
          SSH_DEBUG(SSH_D_ERROR, ("  - failed!"));
        }

      NdisMRegisterUnloadHandler(interceptor->wrapper_handle, DriverUnload); 
    }

  if (enable == FALSE && interceptor->miniport_handle != NULL)
    {
      /* Deregister upper edge API */
      NdisIMDeregisterLayeredMiniport(interceptor->miniport_handle);
      interceptor->miniport_handle = NULL;
      status = NDIS_STATUS_SUCCESS;
    }

  return (status);
}
/*************************************************************
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;
}
예제 #4
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);
}
예제 #5
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;
}
예제 #6
0
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);
}
예제 #7
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);
}
예제 #8
0
파일: mp_main_5x.c 프로젝트: PaulJing/Sora
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;
}