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

📄 rtsnt.c

📁 虚拟网络驱动程序ndis for 数字电视 ip 数据接收
💻 C
📖 第 1 页 / 共 5 页
字号:
/*++

Copyright (c) 1995 Realtek Semiconductor Co.

Module Name:

    interrup.c
    rtsnt.c

Abstract:

    This is the main file for the Realtek RTL8139 Ethernet controller.
    This driver conforms to the NDIS 3.0 miniport interface.

    The overall structure and much of the code is taken from
    the NE2000 driver included in Microsoft NT3.5 DDK.


Environment:

Revision History:

    12/11/96 ----- Vincent

--*/
#include <ndis.h>
#include "Dispatch.h"
#include "rtsnt_sw.h"
#include "bit.h"
#include "pcb.h"
#include "name.h"

//#define POWER_MANAGMENT
#undef POWER_MANAGMENT

//
// On debug builds tell the compiler to keep the symbols for
// internal functions, otw throw them out.
//
#if DBG
#define STATIC
#else
#define STATIC static
#endif

//
// Debugging definitions
//
#if DBG

ULONG           CurrentAdapter = 0;
PRTFAST_ADAPTER dbgAdapter[2];
//
// Default debug mode
//
ULONG RTFast_DebugFlag = RTFast_DEBUG_VERY_LOUD;

//
// Debug tracing defintions
//


#define RTFAST_LOG_SIZE 256


UCHAR RTFast_LogBuffer[RTFAST_LOG_SIZE] = {0};

UINT RTFast_LogLoc = 0;


extern
VOID
RTFast_Log(UCHAR c) {

    RTFast_LogBuffer[RTFast_LogLoc++] = c;

    RTFast_LogBuffer[(RTFast_LogLoc + 4) % RTFAST_LOG_SIZE] = '\0';

    if(RTFast_LogLoc >= RTFAST_LOG_SIZE)
		RTFast_LogLoc = 0;
}

#endif

extern
VOID
RTF8888Log(UCHAR c)
{
}



BOOLEAN g_driverok = FALSE;


//
// This constant is used for places where NdisAllocateMemory
// needs to be called and the HighestAcceptableAddress does
// not matter.
//
NDIS_PHYSICAL_ADDRESS HighestAcceptableMax =
    NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);

//
// The global Miniport driver block.
//

DRIVER_BLOCK RTFast_MiniportBlock = {0};

//
// List of supported OID for this driver.
//
STATIC UINT RTFast_SupportedOids[] =
{
    OID_GEN_SUPPORTED_LIST,
    OID_GEN_HARDWARE_STATUS,
    OID_GEN_MEDIA_SUPPORTED,
    OID_GEN_MEDIA_IN_USE,
    OID_GEN_MAXIMUM_LOOKAHEAD,
    OID_GEN_MAXIMUM_FRAME_SIZE,
    OID_GEN_MAXIMUM_TOTAL_SIZE,
    OID_GEN_MAC_OPTIONS,
    OID_GEN_PROTOCOL_OPTIONS,
    OID_GEN_LINK_SPEED,
    OID_GEN_TRANSMIT_BUFFER_SPACE,
    OID_GEN_RECEIVE_BUFFER_SPACE,
    OID_GEN_TRANSMIT_BLOCK_SIZE,
    OID_GEN_RECEIVE_BLOCK_SIZE,
    OID_GEN_VENDOR_DESCRIPTION,
    OID_GEN_VENDOR_ID,
    OID_GEN_DRIVER_VERSION,
    OID_GEN_CURRENT_PACKET_FILTER,
    OID_GEN_CURRENT_LOOKAHEAD,
    OID_GEN_XMIT_OK,
    OID_GEN_RCV_OK,
    OID_GEN_XMIT_ERROR,
    OID_GEN_RCV_CRC_ERROR,
    OID_GEN_RCV_ERROR,
    OID_GEN_RCV_NO_BUFFER,
    OID_802_3_PERMANENT_ADDRESS,
    OID_802_3_CURRENT_ADDRESS,
    OID_802_3_MULTICAST_LIST,
    OID_802_3_MAXIMUM_LIST_SIZE,
    OID_802_3_RCV_ERROR_ALIGNMENT,
    OID_802_3_XMIT_ONE_COLLISION,
    OID_802_3_XMIT_MORE_COLLISIONS,
    OID_GEN_MAXIMUM_SEND_PACKETS,
    OID_GEN_VENDOR_DRIVER_VERSION,
    OID_GEN_MEDIA_CONNECT_STATUS,
    OID_GEN_DIRECTED_BYTES_XMIT,
    OID_GEN_DIRECTED_BYTES_RCV,

#if NDIS50_MINIPORT
#ifdef POWER_MANAGMENT
    /* powermanagement */
    OID_PNP_CAPABILITIES,
    OID_PNP_SET_POWER,
    OID_PNP_QUERY_POWER,
    OID_PNP_ADD_WAKE_UP_PATTERN,
    OID_PNP_REMOVE_WAKE_UP_PATTERN,
    OID_PNP_ENABLE_WAKE_UP
    /* end powermanagement */
#endif
#endif
};

//
// Determines whether failing the initial card test will prevent
// the adapter from being registered.
//
//?????

#if CARD_TEST
BOOLEAN InitialCardTest = TRUE;
#else  // CARD_TEST
BOOLEAN InitialCardTest = FALSE;
#endif // CARD_TEST

VOID
LinkHandler(
    IN PVOID            SystemSpecific1,
    IN PRTFAST_ADAPTER  Adapter,
    IN PVOID            SystemSpecific2,
    IN PVOID            SystemSpecific3
    );

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

#pragma NDIS_INIT_FUNCTION(DriverEntry)

#define NT_DEVICE_NAME  L"\\Device\\2830S"
#define SYM_LINK_NAME   L"\\DosDevices\\2830S"


/*++

Routine Description:

    This is the primary initialization routine for the RTL8139 driver.
    It is simply responsible for the intializing the wrapper and registering
    the Miniport driver.  It then calls a system and architecture specific
    routine that will initialize and register each adapter.

Arguments:

    DriverObject - Pointer to driver object created by the system.

    RegistryPath - Path to the parameters for this driver in the registry.

Return Value:

    The status of the operation.

--*/

NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
    //
    // Receives the status of the NdisMRegisterMiniport operation.
    //
    NDIS_STATUS Status;
    //
    // Characteristics table for this driver.
    //
    NDIS_MINIPORT_CHARACTERISTICS RTFast_Char;
    //
    // Pointer to the global information for this driver
    //
    PDRIVER_BLOCK NewDriver = &RTFast_MiniportBlock;
    // static const UCHAR test[] = "Realtek rtl8139A WOL ndis5 driver POWERM\0\0\0\0\0\0\0\0\1\1 ";

    //
    // Handle for referring to the wrapper about this driver.
    //
    NDIS_HANDLE NdisWrapperHandle;
    PDRIVER_DISPATCH  MajorFunctions [IRP_MJ_MAXIMUM_FUNCTION];
    UINT  ii;
    PDEVICE_OBJECT  pTsDevice;
    NDIS_HANDLE NdisDeviceHandle;
    NDIS_STRING DeviceName;
    NDIS_STRING SymLinkName;

    DbgPrint ("DVB NIC adapter Build at %s %s\n",__DATE__,__TIME__);

#if DBG
    //DebugPrintInit("RTL8139 miniport");
    DbgPrint(" NDIS50_MINIPORT = %x\n", NDIS50_MINIPORT);
    DbgPrint(" NDIS_WDM = %x\n", NDIS_WDM);
#endif

	

    //
    // Initialize the wrapper.
    //
    NdisMInitializeWrapper(
                &NdisWrapperHandle,
                DriverObject,
                RegistryPath,
                NULL
                );
    
    //
    // Save the global information about this driver.
    //
    NewDriver->NdisWrapperHandle = NdisWrapperHandle;
    NewDriver->AdapterQueue = (PRTFAST_ADAPTER)NULL;

#if CREATE_MY_NEWDEVICE
    NewDriver->NdisDeviceHandle = NULL;
    NewDriver->pTsDevice = NULL;
#endif
    //
    // Initialize the Miniport characteristics for the call to
    // NdisMRegisterMiniport.
    //

	
    RTFast_Char.MajorNdisVersion = RTFAST_NDIS_MAJOR_VERSION;
    RTFast_Char.MinorNdisVersion = RTFAST_NDIS_MINOR_VERSION;

    RTFast_Char.CheckForHangHandler = RTFast_CheckForHang;
    RTFast_Char.DisableInterruptHandler = RTFast_DisableInterrupt;
    RTFast_Char.EnableInterruptHandler = RTFast_EnableInterrupt;
    RTFast_Char.HaltHandler = RTFast_Halt;
    RTFast_Char.HandleInterruptHandler = RTFast_HandleInterrupt;
    RTFast_Char.InitializeHandler = RTFast_Initialize;
    RTFast_Char.ISRHandler = RTFast_Isr;
    RTFast_Char.QueryInformationHandler = RTFast_QueryInformation;
    RTFast_Char.ReconfigureHandler = NULL;
    RTFast_Char.ResetHandler = RTFast_Reset;
    RTFast_Char.SendHandler = RTFast_Send;
    RTFast_Char.SetInformationHandler = RTFast_SetInformation;
    RTFast_Char.TransferDataHandler = RTFast_TransferData;
 
#if NDIS40_MINIPORT
    RTFast_Char.SendPacketsHandler = RTFast_Sends;
    RTFast_Char.ReturnPacketHandler = NULL;
    RTFast_Char.AllocateCompleteHandler = NULL;
#endif

#if NDIS50_MINIPORT
    RTFast_Char.SendPacketsHandler = NULL; 
    RTFast_Char.ReturnPacketHandler = NULL;  
    RTFast_Char.AllocateCompleteHandler = NULL;
    RTFast_Char.CoCreateVcHandler = NULL;
    RTFast_Char.CoDeleteVcHandler = NULL;
    RTFast_Char.CoActivateVcHandler = NULL;
    RTFast_Char.CoDeactivateVcHandler = NULL;
    RTFast_Char.CoSendPacketsHandler = NULL;
    RTFast_Char.CoRequestHandler = NULL;
#endif 

    Status = NdisMRegisterMiniport(
                 NdisWrapperHandle,
                 (PNDIS_MINIPORT_CHARACTERISTICS)&RTFast_Char,
                 sizeof(RTFast_Char));

    if(Status != NDIS_STATUS_SUCCESS)
    {
#if DBG
        DbgPrint("*** NDIS register failed status = %x %x\n", Status, NDIS_STATUS_SUCCESS);
#endif
        return (STATUS_UNSUCCESSFUL);
    }
	else
	{
		 DbgPrint("*** NDIS register success status\n");
	}
	
	
#if CREATE_MY_NEWDEVICE
	////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
	DriverObject->DriverUnload = Wdm1Unload;
	////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

    //Create our device interface
    for(ii = 0; ii < IRP_MJ_MAXIMUM_FUNCTION; ii++)
        MajorFunctions[ii] = NULL;
  
    MajorFunctions[IRP_MJ_CREATE] = TsCreate;
    MajorFunctions[IRP_MJ_CLOSE] = TsClose;
    MajorFunctions[IRP_MJ_READ] = TsRead;
    MajorFunctions[IRP_MJ_WRITE] = TsWrite;
    MajorFunctions[IRP_MJ_DEVICE_CONTROL] = TsDeviceControl;
    MajorFunctions[IRP_MJ_CLEANUP] = TsCleanup;
    //MajorFunctions[IRP_MJ_POWER] = TsPower;

    NdisInitUnicodeString(&DeviceName, NT_DEVICE_NAME);
    NdisInitUnicodeString(&SymLinkName, SYM_LINK_NAME);

    Status = NdisMRegisterDevice(
                   NdisWrapperHandle,
                   &DeviceName,
                   &SymLinkName,
                   MajorFunctions,
                   &pTsDevice,
                   &NdisDeviceHandle
                   );
#if DBG
    DbgPrint("*** NdisMRegisterDevice status = %8x\n", Status);
#endif

    if(Status == NDIS_STATUS_SUCCESS)
    {
#if DBG
        DbgPrint("*** Create device success\n");
#endif

        pTsDevice->Flags |= DO_DIRECT_IO;
        pTsDevice->Flags &= ~DO_DEVICE_INITIALIZING;
        NewDriver->NdisDeviceHandle = NdisDeviceHandle;
        NewDriver->pTsDevice = pTsDevice;
    }
    else
    {
        DbgPrint("*** Create device fail ");
#if DBG
        DbgPrint(" NdisMRegisterDevice status = %8x\n", Status);
        DbgBreakPoint();
#endif
        return (STATUS_UNSUCCESSFUL);
    }
#endif  // #if CREATE_MY_NEWDEVICE

	
    if(Status == NDIS_STATUS_SUCCESS)
        DbgPrint(" Found PCI Fast Modem NIC device\n");

	return (Status);


/*
#if 0
Status = NDIS_STATUS_SUCCESS;
	// Export other driver entry points...
	DriverObject->DriverExtension->AddDevice = Wdm1AddDevice;
	DriverObject->DriverUnload = Wdm1Unload;

	DriverObject->MajorFunction[IRP_MJ_CREATE] = TsCreate;
	DriverObject->MajorFunction[IRP_MJ_CLOSE] = TsClose;

	DriverObject->MajorFunction[IRP_MJ_PNP] = Wdm1Pnp;
	DriverObject->MajorFunction[IRP_MJ_POWER] = TsPower;

	DriverObject->MajorFunction[IRP_MJ_READ] = TsRead;
	DriverObject->MajorFunction[IRP_MJ_WRITE] = TsWrite;
	DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = TsDeviceControl;

	DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = Wdm1SystemControl;

    return (Status); 
#endif  */
}



#pragma code_seg("PAGE") // start PAGE section

VOID Wdm1Unload(IN PDRIVER_OBJECT DriverObject)
{
	// Free buffer (do not need to acquire spin lock)
//	if( Buffer!=NULL)
//		ExFreePool(Buffer);
	NDIS_STATUS Status;

#if CREATE_MY_NEWDEVICE
    if(RTFast_MiniportBlock.NdisDeviceHandle)
	{
		Status=NdisMDeregisterDevice(RTFast_MiniportBlock.NdisDeviceHandle);
		DbgPrint("NdisMDeregisterDevice!\n");
	}
#endif

	DbgPrint("****************Wdm1Unload");
}

//////////////////////////////////////////////////////////////////////////////
#pragma code_seg() // end PAGE section





#pragma NDIS_PAGEABLE_FUNCTION(RTFast_Initialize)


/*++

Routine Description:

    Rtl8139Initialize starts an adapter and registers resources with the
    wrapper.

Arguments:

⌨️ 快捷键说明

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