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

📄 vmini.c

📁 三星2410的BSP开发包
💻 C
📖 第 1 页 / 共 4 页
字号:
		LeaveCriticalSection(&g_csSend);
        return NDIS_STATUS_SUCCESS;        
    }


    CopyFromNdisPacket(
        Packet,
        pVA,
        &dwTotalLength);

	//
	//	No longer need this, Kernel will use UNCACHED region so do we..
	//
    //	CacheSync(CACHE_SYNC_DISCARD);
	//

    RETAILMSG (0, (TEXT("Sending: %x-%x-%x-%x-%x-%x   %x-%x-%x-%x-%x-%x\r\n"),
        pVA[0],
        pVA[1],
        pVA[2],
        pVA[3],
        pVA[4],
        pVA[5],
        pVA[6],
        pVA[7],
        pVA[8],
        pVA[9],
        pVA[10],
        pVA[11]));


	if (bConvert)
		BufferAddress |= 0x20000000;	

    KernelIoControl(
        IOCTL_VBRIDGE_GET_TX_PACKET_COMPLETE,
        (LPVOID)BufferAddress,
        dwTotalLength,
        NULL,
        0x00,
        &dwReturnedBytes);

	LeaveCriticalSection(&g_csSend);

#if EDBG_USE_NAME_EVENT

    //
    //  Trigger the send via RETAILMSG() if we don't have the EdbgIntEvent.
    //

    if (VMini.vm_EdbgIntHandle == NULL) 
        RETAILMSG (1, (TEXT("")));
    else        
    {
        SetEvent(VMini.vm_EdbgIntHandle);       
    }
#else

    RETAILMSG (1, (TEXT("")));

#endif   
    
    return NDIS_STATUS_SUCCESS; 

}   //  VMiniMSend()



////////////////////////////////////////////////////////////////////////////////
//	VMiniMHalt()
//
//	Routine description:
//
//		Required function to deallocates resources that we allocate in 
//		VMiniMInitialize()
//
//	Arguments:
//
//		Look at MSDN MiniportHalt() description.
//
//	return values:
//	
//		None.
//

VOID
VMiniMHalt(
    IN NDIS_HANDLE Context
    )
{
	PSTRUCT_VMINI	Adapter = (PSTRUCT_VMINI) Context;

    DEBUGMSG (ZONE_MISC, (TEXT("VMini:: VMiniMHalt()...\r\n")));

	//
	//	Mark that the adapter is shutting down..
	//	

	Adapter->vm_bHalt = TRUE;

	//
	//	Signal the RX thread to quit..
	//

	SetEvent(Adapter->vm_hInterruptEvent);

	if (Adapter->vm_hRxThread != NULL)		
	{
		WaitForSingleObject(Adapter->vm_hRxThread, INFINITE);
		CloseHandle(Adapter->vm_hRxThread);
		Adapter->vm_hRxThread = NULL;
	}

	RETAILMSG (1,
		(TEXT("VMini:: RX Thread exited.. VMini shutting down..\r\n")));
	
	
	//
	//	Release all resources used, we are about to be unloaded..
	//

	DeleteCriticalSection(&g_csSend);

	NdisFreePacket(Adapter->pNdisPacket);
	NdisFreePacketPool(Adapter->NdisPacketPool);
	NdisFreeBufferPool(Adapter->NdisBufferPool);
	
	VMini.pNdisPacket			= NULL;
	VMini.NdisPacketPool		= NULL;
	VMini.NdisBufferPool		= NULL;
	VMini.vm_VMiniportHandle	= NULL;

	VirtualFree(
		(LPVOID)dwTxVA, 
		VIRTUAL_MEMORY_TO_ALLOC + dwTxOffset,
		MEM_RELEASE);

	VirtualFree(
		(LPVOID)dwRxVA,
		VIRTUAL_MEMORY_TO_ALLOC + dwRxOffset,
		MEM_RELEASE);

	CloseHandle(Adapter->vm_hInterruptEvent);
	    
}   //  VMiniMHalt()



////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//  
//  Miniport_XXX functions that are not implemented
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////
//  VMiniMShutdownHandler()
//

VOID
VMiniMShutdownHandler(
    IN PVOID Context
    )
{
    DEBUGMSG (ZONE_MISC, (TEXT("VMini:: VMiniShutDownHandler()...\r\n")));

    
}   //  VMiniShutdownHandler()



////////////////////////////////////////////////////////////////////////////////
//  VMiniMDisableInterrupt()    
//  

VOID        
VMiniMDisableInterrupt(
    IN NDIS_HANDLE MiniportAdapterContext
    )
{
    DEBUGMSG (ZONE_MISC, (TEXT("VMini:: VMiniMDisableInterrupt()...\r\n")));
    
    
}   //  VMiniMDisableInterrupt()



////////////////////////////////////////////////////////////////////////////////
//  VMiniMEnableInterrupt() 
//  

VOID        
VMiniMEnableInterrupt(
    IN NDIS_HANDLE MiniportAdapterContext
    )
{
    DEBUGMSG (ZONE_MISC, (TEXT("VMini:: VMiniMEnableInterrupt()...\r\n")));


}   //  VMiniMEnableInterrupt()


////////////////////////////////////////////////////////////////////////////////
//  VMiniMHandleInterrupt()
//

VOID
VMiniMHandleInterrupt(
    IN  PVOID               Context
    )
{
    DEBUGMSG (ZONE_MISC, (TEXT("VMini:: VMiniMHandleInterrupt()...\r\n")));

}   //  VMiniMHandleInterrupt()



////////////////////////////////////////////////////////////////////////////////
//  VMiniMISR()
//

VOID
VMiniMISR(
    OUT PBOOLEAN    InterruptRecognized,
    OUT PBOOLEAN    QueueDpc,
    IN  PVOID       Context
    )
{

    DEBUGMSG (ZONE_MISC, (TEXT("VMini:: VMiniMISR()...\r\n")));

}   //  VMiniMISR()



////////////////////////////////////////////////////////////////////////////////
//  VMiniMReset()
//

NDIS_STATUS
VMiniMReset(
    OUT PBOOLEAN    AddressingReset,
    IN NDIS_HANDLE  MiniportAdapterContext
    )
{
	//
	//	We don't have hardware to reset, so just return OK..
	//	And we keep the addressing information, so no need to set that 
	//	again..
	//

    DEBUGMSG (ZONE_MISC, (TEXT("VMiniMReset():: \r\n")));

	*AddressingReset = FALSE;

    return NDIS_STATUS_SUCCESS;

}   //  VMiniMReset()


////////////////////////////////////////////////////////////////////////////////
//  VMiniMTransferData()
//

NDIS_STATUS
VMiniMTransferData(
    OUT PNDIS_PACKET Packet,
    OUT PUINT BytesTransferred,
    IN NDIS_HANDLE MiniportAdapterContext,
    IN NDIS_HANDLE MiniportReceiveContext,
    IN UINT ByteOffset,
    IN UINT BytesToTransfer
    )
{
    DEBUGMSG (ZONE_MISC, (TEXT("VMiniMTransferData():: \r\n")));

    return NDIS_STATUS_FAILURE;

}   //  VMiniMTransferData()



////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//  Driver related functions..
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
//  DriverEntry()
//

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

    NDIS_STATUS                     Status;                     // Receives the status of NdisRegisterMac Operation...  
    NDIS_MINIPORT_CHARACTERISTICS   VMiniCharacteristics;       // Allocate memory for the data structure...            
	DWORD							bVBridgeInitialized;

    DEBUGMSG (ZONE_INIT, (TEXT("DriverEntry()... VMini.dll\r\n")));
    
    memset (&VMini, 0x00, sizeof(STRUCT_VMINI));

    //
    //  If there is no KernelIoCtl() to support us, bail out now.
    //

    if (!KernelIoControl(
            IOCTL_VBRIDGE_SHARED_ETHERNET,
            NULL,
            0x00,
            NULL,
            0x00,
            NULL))
    {
        RETAILMSG (1, (TEXT("VMini:: Kernel does not support ethernet sharing!\r\n")));
        return NDIS_STATUS_FAILURE;
    }

	//
	//	Now, IOCTL may there but apparently this no guarantee..
	//	Now call and ask vbridge directly..
	//

	KernelIoControl(
		IOCTL_VBRIDGE_WILD_CARD,
        (PVOID)IOCTL_VBRIDGE_WILD_CARD_VB_INITIALIZED,
        0x00,
        &bVBridgeInitialized,
        sizeof(DWORD),
        NULL);

	if (!bVBridgeInitialized)
	{
        RETAILMSG (1, (TEXT("VMini:: VBridge is not initialized!   Bail out..\r\n")));
        return NDIS_STATUS_FAILURE;
    }


    DEBUGMSG (ZONE_INIT, (TEXT("VMini:: Successfully detected shared ether mode kernel.\r\n")));    	

	//
    //  Get hook up with the EDBG interrupt event for our TX.
    //

    if ((VMini.vm_EdbgIntHandle = CreateEvent(0, FALSE, FALSE, EDBG_INTERRUPT_EVENT)) == NULL) 
    {
        RETAILMSG (1, (TEXT("VMini:: failed to create edbg interrupt event: [%s]\r\n"),
            EDBG_INTERRUPT_EVENT));
        VMini.vm_EdbgIntHandle = NULL;       
    }
    else
    {
        RETAILMSG (1, (TEXT("VMini:: Successfully created Edbg event: [%s]\r\n"),
            EDBG_INTERRUPT_EVENT));
    }

	//
	//	Until we get the first instance initialized..
	//

	VMini.vm_bHalt = TRUE;


	//
    //  Initialize the wrapper.
    //

    NdisInitializeWrapper(
        &VMini.vm_VMiniWrapperHandle,
        DriverObject,
        RegistryPath,
        NULL
        );

    memset (&VMiniCharacteristics, 0x00, sizeof(VMiniCharacteristics));

    
	//
    //  Initialize the MAC characteristics for the call to
    //  NdisMRegisterMiniport()
    //

    VMiniCharacteristics.MajorNdisVersion           = 4;
    VMiniCharacteristics.MinorNdisVersion           = 0;
    VMiniCharacteristics.CheckForHangHandler        = NULL; 
    VMiniCharacteristics.DisableInterruptHandler    = VMiniMDisableInterrupt;
    VMiniCharacteristics.EnableInterruptHandler     = VMiniMEnableInterrupt;
    VMiniCharacteristics.HaltHandler                = VMiniMHalt;
    VMiniCharacteristics.HandleInterruptHandler     = VMiniMHandleInterrupt;
    VMiniCharacteristics.InitializeHandler          = VMiniMInitialize;
    VMiniCharacteristics.ISRHandler                 = VMiniMISR;
    VMiniCharacteristics.QueryInformationHandler    = VMiniMQueryInformation;
    VMiniCharacteristics.ReconfigureHandler         = NULL;
    VMiniCharacteristics.ResetHandler               = VMiniMReset;
    VMiniCharacteristics.SetInformationHandler      = VMiniMSetInformation;
    VMiniCharacteristics.TransferDataHandler        = VMiniMTransferData;
    VMiniCharacteristics.ReturnPacketHandler        = NULL; 
    VMiniCharacteristics.AllocateCompleteHandler    = NULL;
    VMiniCharacteristics.SendHandler                = VMiniMSend;
    VMiniCharacteristics.SendPacketsHandler         = NULL;


    //
    //  Register the miniport driver
    //

    Status = NdisMRegisterMiniport(
                        VMini.vm_VMiniWrapperHandle,
                        &VMiniCharacteristics,
                        sizeof(VMiniCharacteristics));


	//
    //  If ok, done
    //

    if (Status == NDIS_STATUS_SUCCESS)
    {
        DEBUGMSG (ZONE_INIT, (TEXT("VMini:: registered successfully!\r\n")));

		//
		//  Okay, we are not the typical miniport driver.
		//  We have our own thread to do the fake SYSINTR_XXX to receive the
		//  interrupt from kernel.
		//		

        return NDIS_STATUS_SUCCESS;
    }

    DEBUGMSG (ZONE_ERROR, (TEXT("VMini:: Error! failed to register.\r\n")));

	//
	//	Release resources allocated earlier..
	//

	CloseHandle(&VMini.vm_EdbgIntHandle);
	VMini.vm_EdbgIntHandle = NULL;

    
	//
    //  We can only get here if something went wrong with registering
    //  the miniport driver or *all* of the adapters.
    //

    NdisTerminateWrapper(
        VMini.vm_VMiniWrapperHandle, 
        NULL);      


    return NDIS_STATUS_FAILURE;

}   //  DriverEntry()



////////////////////////////////////////////////////////////////////////////////
//  DllEntry()
//

DllEntry(
  HANDLE hDLL,
  DWORD dwReason,
  LPVOID lpReserved
)
{ 
    switch (dwReason) 
    {
        /////////////////////////////////////////////////////////////////////////
        //  DLL Process Attach...
        //  
        case DLL_PROCESS_ATTACH:            
            DEBUGMSG(ZONE_INIT, (TEXT("VMini:: DLL_PROCESS_ATTACH\n")));
            #if DEBUG   
                RegisterDbgZones(hDLL, &dpCurSettings);                         
            #endif
	    DisableThreadLibraryCalls((HMODULE) hDLL);
            break;      


        /////////////////////////////////////////////////////////////////////////
        //  DLL Process Detach...
        //      
        case DLL_PROCESS_DETACH:            
            DEBUGMSG(ZONE_INIT, (TEXT("VMini: DLL_PROCESS_DETACH\n")));         
            break;
    }
    return TRUE;

}	//	DllEntry()

⌨️ 快捷键说明

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