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

📄 ndisdriver.c

📁 MICREL 网卡驱动 FOR CE 5.0
💻 C
📖 第 1 页 / 共 3 页
字号:
VOID MiniportShutdown (
    IN  NDIS_HANDLE hContext )
{
    PNDIS_ADAPTER pAdapter = ( PNDIS_ADAPTER ) hContext;

#if DBG
    DbgPrint( "MiniportShutdown"NEWLINE );
#endif

    ShutdownAdapter( pAdapter );
}  // MiniportShutdown


/*
    MiniportInitialize

    Description:
        This function initializes the adapter and registers resources with the
        NDIS wrapper.

    Parameters:
        PNDIS_STATUS pnsOpenErrorStatus
            Extra status bytes for opening token ring adapters.

        PUINT puiSelectedMediumIndex
            Index of the media type chosen by the driver.

        PNDIS_MEDIUM pnmMediumArray
            Array of media types for the driver to choose from.

        UINT uiMediumArraySize
            Number of entries in the array.

        NDIS_HANDLE hAdapter
            Handle to adapter to pass to the NDIS wrapper.

        NDIS_HANDLE hConfiguration
            Handle of configuration to pass to NdisOpenConfiguration.

    Return (NDIS_STATUS):
        NDIS_STATUS_SUCCESS if successful; otherwise an error code indicating
        failure.
*/

NDIS_STATUS MiniportInitialize (
    OUT PNDIS_STATUS pnsOpenErrorStatus,
    OUT PUINT        puiSelectedMediumIndex,
    IN  PNDIS_MEDIUM pnmMediumArray,
    IN  UINT         uiMediumArraySize,
    IN  NDIS_HANDLE  hAdapter,
    IN  NDIS_HANDLE  hConfiguration )
{
    PNDIS_ADAPTER pAdapter;
    NDIS_STATUS   nsStatus;
    UINT          i;
    UCHAR         bInterrupt = FALSE;

#if (NDISVER < 50)
    NDIS_PHYSICAL_ADDRESS HighestAcceptableMax =
        NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 );
#endif

    for ( i = 0; i < uiMediumArraySize; i++ )
    {
        if ( pnmMediumArray[ i ] == NdisMedium802_3 )
            break;
    }
    if ( i == uiMediumArraySize )
    {
        return NDIS_STATUS_UNSUPPORTED_MEDIA;
    }
    *puiSelectedMediumIndex = i;

    // Allocate memory for the adapter block now.

#if (NDISVER >= 50)
    nsStatus = NdisAllocateMemoryWithTag(( PVOID* ) &pAdapter,
        sizeof( NDIS_ADAPTER ), 'rciM' );
#else
    nsStatus = NdisAllocateMemory(( PVOID* ) &pAdapter, sizeof( NDIS_ADAPTER ),
        0, HighestAcceptableMax );
#endif
    if ( nsStatus != NDIS_STATUS_SUCCESS )
    {
        return( nsStatus );
    }

    // Clear out the adapter block, which sets all default values to FALSE
    // or NULL.

    NdisZeroMemory( pAdapter, sizeof( NDIS_ADAPTER ));

    pAdapter->m_Hardware.m_hwfn = ks8842_fn;

    // Allocate the spin locks.
    NdisAllocateSpinLock( &pAdapter->m_lockAdapter );
    NdisAllocateSpinLock( &pAdapter->m_lockReceive );
    NdisAllocateSpinLock( &pAdapter->m_lockHardware );

    // Process the configuration parameters.
    nsStatus = InitAdapter( pAdapter, hAdapter, hConfiguration );
    if ( nsStatus != NDIS_STATUS_SUCCESS )
    {
        goto MiniportInitializeMemoryError;
    }

    // Register the adapter.
    nsStatus = RegisterAdapter( pAdapter );
    if ( nsStatus != NDIS_STATUS_SUCCESS )
    {
        goto MiniportInitializeError;
    }

    nsStatus = NdisMRegisterInterrupt( &pAdapter->m_Interrupt,
        pAdapter->m_hAdapter, pAdapter->m_ulInterruptNumber,
        pAdapter->m_ulInterruptNumber, TRUE, TRUE,
        NdisInterruptLevelSensitive );
    if ( nsStatus != NDIS_STATUS_SUCCESS )
    {
#if 0
        NdisWriteErrorLogEntry( pAdapter->m_hAdapter,
            NDIS_ERROR_TRILOG_NO_INTERRUPT_ROUTE, 3, 0x1056000C, TRUE,
            pAdapter->m_ulInterruptNumber );
#endif
        goto MiniportInitializeError;
    }
    bInterrupt = TRUE;

    nsStatus = SetupAdapter( pAdapter );
    if ( nsStatus != NDIS_STATUS_SUCCESS )
    {
        goto MiniportInitializeError;
    }

#if 0
    // initialize reset timer.
    NdisMInitializeTimer( pAdapter->ResetTimer,
        pAdapter->hMiniportAdapterHandle, ResetCompleteTimerDpc, pAdapter );
#endif

    // initialize period timer
    NdisMInitializeTimer( &pAdapter->m_PeriodTimer, pAdapter->m_hAdapter,
        PeriodTimerDpc, pAdapter );

    //
    // Fire off Dpc to execute after 1 seconds if
    //
    NdisMSetPeriodicTimer( &pAdapter->m_PeriodTimer, 1000 );

    // Register shutdown handler.  Note: NDIS 5.1 registers the handler in
    // NDIS_MINIPORT_CHARACTERISTICS
    if ( ExplicitRegisterShutdownHandler )
    {
        NdisMRegisterAdapterShutdownHandler( hAdapter, pAdapter,
            MiniportShutdown );
    }

    return NDIS_STATUS_SUCCESS;

MiniportInitializeError:
    if ( bInterrupt )
        NdisMDeregisterInterrupt( &pAdapter->m_Interrupt );
    DeRegisterAdapter( pAdapter );

#if UNDER_CE
    NdisTerminateWrapper( pAdapter->m_hAdapter, NULL );
#endif

MiniportInitializeMemoryError:
    FreeMemory( pAdapter );

    NdisFreeSpinLock( &pAdapter->m_lockAdapter );
    NdisFreeSpinLock( &pAdapter->m_lockReceive );
    NdisFreeSpinLock( &pAdapter->m_lockHardware );
    NdisFreeMemory( pAdapter, sizeof( NDIS_ADAPTER ), 0 );
    return( nsStatus );
}  // MiniportInitialize

/* -------------------------------------------------------------------------- */

VOID DriverUnload (
    IN  PDRIVER_OBJECT DriverObject )
{
#if DBG
    DBG_PRINT( "DriverUnload"NEWLINE );
#endif
    if ( ks8842_fn )
    {
        NdisFreeMemory( ks8842_fn, sizeof( struct hw_fn ), 0 );
        ks8842_fn = NULL;
    }
}  /* DriverUnload */


/*
    DriverEntry

    Description:
        This function is the main entry point of the driver.

    Parameters:
        PDRIVER_OBJECT pDriverObject
            Pointer to driver object.

        PUNICODE_STRING RegistryPath
            Pointer to unicode string containing the register path that stores
            the configuration of the driver.

    Return (NTSTATUS):
        STATUS_SUCCESS if successful; otherwise STATUS_UNSUCCESSFUL.
*/

#ifdef __cplusplus
extern "C"
#endif
NTSTATUS DriverEntry (
    IN  PDRIVER_OBJECT  DriverObject,
    IN  PUNICODE_STRING RegistryPath )
{
    // Characteristics table for this driver.
    NDIS_MINIPORT_CHARACTERISTICS DriverStruct;
    NDIS_HANDLE                   NdisWrapperHandle;
    NDIS_STATUS                   nsStatus;

#ifdef DBG
    DBG_PRINT( "%s"NEWLINE, version );
#endif

    // Initialize the wrapper.
    NdisMInitializeWrapper( &NdisWrapperHandle, DriverObject, RegistryPath,
        NULL );

    // Clear the characteristics table to ensure there's no bogus data passed
    // to NDIS.
    NdisZeroMemory( &DriverStruct, sizeof( DriverStruct ));

    // Initialize the Miniport characteristics for the call to
    // NdisMRegisterMiniport.
    DriverStruct3.MajorNdisVersion          = NDIS_MAJOR_VERSION;
    DriverStruct3.MinorNdisVersion          = NDIS_MINOR_VERSION;
    DriverStruct3.CheckForHangHandler       = MiniportCheckForHang;
    DriverStruct3.CheckForHangHandler       = NULL;
    DriverStruct3.DisableInterruptHandler   = MiniportDisableInterrupt;
    DriverStruct3.EnableInterruptHandler    = MiniportEnableInterrupt;
    DriverStruct3.HaltHandler               = MiniportHalt;
    DriverStruct3.HandleInterruptHandler    = MiniportHandleInterrupt;
    DriverStruct3.InitializeHandler         = MiniportInitialize;
    DriverStruct3.ISRHandler                = MiniportISR;
    DriverStruct3.QueryInformationHandler   = MiniportQueryInformation;
    DriverStruct3.ReconfigureHandler        = NULL;
    DriverStruct3.ResetHandler              = MiniportReset;
    DriverStruct3.SendHandler               = MiniportSend;
    DriverStruct3.SetInformationHandler     = MiniportSetInformation;
    DriverStruct3.TransferDataHandler       = NULL;

    // NDIS 4.0 extensions...
    //
    // If you want to support NDIS 3.1 then don't support these functions and
    // change the NDIS_MAJOR_VERSION & NDIS_MINOR_VERSION and change the compile
    // and link parameters to reflect 3.1.  NDIS 3.1 uses SendHandler to send
    // packets (and its implemented).
    //
    // NDIS 4.0 does give a speed boost because the SendPacketsHandler will
    // handle multiple packets at a time.

#if (NDISVER >= 40)
    // Specific to NDIS 4
    DriverStruct4.ReturnPacketHandler       = MiniportReturnPacket;
    DriverStruct4.SendPacketsHandler        = MiniportSendPackets;
    DriverStruct4.AllocateCompleteHandler   = NULL;
#endif

#if (NDISVER >= 50)
#endif

#if (NDISVER >= 51)
    // Specific to NDIS 5.1
    DriverStruct.AdapterShutdownHandler     = MiniportAdapterShutdown;
    DriverStruct.CancelSendPacketsHandler   = NULL;
    DriverStruct.PnPEventNotifyHandler      = MiniportPnPEventNotify;
#endif

    nsStatus = NdisMRegisterMiniport( NdisWrapperHandle, &DriverStruct,
        sizeof( DriverStruct ));

#if (NDISVER >= 51)
    // Fall back to NDIS 5.0 support if necessary.
    if ( nsStatus != NDIS_STATUS_SUCCESS )
    {

#if DBG
        DbgPrint( "DriverEntry falling back to NDIS 5.0..."NEWLINE );
#endif
        DriverStruct3.MajorNdisVersion = 5;
        DriverStruct3.MinorNdisVersion = 0;
        nsStatus = NdisMRegisterMiniport( NdisWrapperHandle, &DriverStruct,
            sizeof( DriverStruct5 ));
    }
    else
    {
        // Don't need to explicitly register shutdown handler -- already done in
        // NDIS_MINIPORT_CHARACTERISTICS.
        ExplicitRegisterShutdownHandler = FALSE;
    }
#endif

    if ( NDIS_STATUS_SUCCESS == nsStatus )
    {

#if (NDISVER >= 50)
        NdisAllocateMemoryWithTag(( PVOID* ) &ks8842_fn,
            sizeof( struct hw_fn ), 'rciM' );
#else
        NDIS_PHYSICAL_ADDRESS HighestAcceptableMax =
            NDIS_PHYSICAL_ADDRESS_CONST( -1, -1 );

        NdisAllocateMemory(( PVOID* ) &ks8842_fn,
            sizeof( struct hw_fn ),
            0, HighestAcceptableMax );
#endif
        HardwareSetupFunc( ks8842_fn );

        NdisMRegisterUnloadHandler( NdisWrapperHandle, DriverUnload );
    }

#if DBG
#ifdef UNDER_CE
    DEBUGMSG( ZONE_INIT, ( TEXT( "KS884X: DriverEntry:%x\r\n" ), nsStatus ));

#else
    DbgPrint( "%p = ", DriverObject );
    switch ( nsStatus )
    {
        case NDIS_STATUS_BAD_CHARACTERISTICS:
            DbgPrint( "NDIS_STATUS_BAD_CHARACTERISTICS\n" );
            break;
        case NDIS_STATUS_BAD_VERSION:
            DbgPrint( "NDIS_STATUS_BAD_VERSION\n" );
            break;
        case NDIS_STATUS_RESOURCES:
            DbgPrint( "NDIS_STATUS_RESOURCES\n" );
            break;
        case NDIS_STATUS_FAILURE:
            DbgPrint( "NDIS_STATUS_FAILURE\n" );
            break;
        case NDIS_STATUS_SUCCESS:
            DbgPrint( "NDIS_STATUS_SUCCESS\n" );
            break;
        default:
            DbgPrint( "NDIS Unknown:%08x\n", nsStatus );
            break;
    }
#endif
#endif

    return( nsStatus == NDIS_STATUS_SUCCESS ? STATUS_SUCCESS :
        STATUS_UNSUCCESSFUL );
}  // DriverEntry

⌨️ 快捷键说明

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