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

📄 htdsu.c

📁 这是一个56K MODEM的驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************\
|* Copyright (c) 1994  Microsoft Corporation                               *|
|* Developed for Microsoft by TriplePoint, Inc. Beaverton, Oregon          *|
|*                                                                         *|
|* This file is part of the HT Communications DSU41 WAN Miniport Driver.   *|
\***************************************************************************/
#include "version.h"
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Module Name:

    htdsu.c

Abstract:

    This module contains the DriverEntry() routine, which is the first
    routine called when the driver is loaded into memory.  The Miniport
    initialization and termination routines are also implemented here:
        MiniportInitialize()
        MiniportHalt()

    This driver conforms to the NDIS 3.0 Miniport interface.

Author:

    Larry Hattery - TriplePoint, Inc. (larryh@tpi.com) Jun-94

Environment:

    Windows NT 3.5 kernel mode Miniport driver or equivalent.

Revision History:

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

#define  __FILEID__     1       // Unique file ID for error logging

#include "htdsu.h"

/*
// This is defined here to avoid including all of ntddk.h which cannot
// normally be included by a miniport driver.
*/
extern NTSTATUS
RtlUnicodeStringToAnsiString(
        PANSI_STRING out,
        PUNICODE_STRING in,
        BOOLEAN allocate
        );

/*
// Receives the context value representing the Miniport wrapper
// as returned from NdisMInitializeWrapper.
*/
static NDIS_HANDLE
NdisWrapperHandle = NULL;

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

/*
// This is used to assign a unique instance number to each adapter.
*/
static UCHAR
HtDsuAdapterCount = 0;

/*
// Tell the compiler which routines can be unloaded after initialization.
*/
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    );
#pragma NDIS_INIT_FUNCTION(DriverEntry)

/*
// Tell the compiler which routines can be paged out.
// These can never be called from interrupt or DPC level!
*/
NDIS_STATUS
HtDsuInitialize(
    OUT PNDIS_STATUS OpenErrorStatus,
    OUT PUINT SelectedMediumIndex,
    IN PNDIS_MEDIUM MediumArray,
    IN UINT MediumArraySize,
    IN NDIS_HANDLE MiniportAdapterHandle,
    IN NDIS_HANDLE WrapperConfigurationContext
    );
#pragma NDIS_PAGABLE_FUNCTION(HtDsuInitialize)

NDIS_STATUS
HtDsuRegisterAdapter(
    IN PHTDSU_ADAPTER Adapter,
    IN PSTRING AddressList
    );
#pragma NDIS_PAGABLE_FUNCTION(HtDsuRegisterAdapter)

VOID
HtDsuHalt(
    IN PHTDSU_ADAPTER Adapter
    );
#pragma NDIS_PAGABLE_FUNCTION(HtDsuHalt)


NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Functional Description:

    The DriverEntry routine is the main entry point for the driver.
    It is responsible for the initializing the Miniport wrapper and
    registering the driver with the Miniport wrapper.

Parameters:

    DriverObject _ Pointer to driver object created by the system.

    RegistryPath _ Pointer to registery path name used to read registry
                   parameters.

Return Values:

    STATUS_SUCCESS
    STATUS_UNSUCCESSFUL

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

{
    DBG_FUNC("HtDsuDriverEntry")

    /*
    // Receives the status of the NdisMWanRegisterMiniport operation.
    */
    NDIS_STATUS Status;

    /*
    // Characteristics table passed to NdisMWanRegisterMiniport.
    */
    NDIS_WAN_MINIPORT_CHARACTERISTICS HtDsuChar;

#if DBG
    DbgPrint("?>>>%s: Build Date:"__DATE__" Time:"__TIME__"\n",__FUNC__);
#endif

    /*
    // Initialize the Miniport wrapper - THIS MUST BE THE FIRST NDIS CALL.
    */
    NdisMInitializeWrapper(
            &NdisWrapperHandle,
            DriverObject,
            RegistryPath,
            NULL
            );

    /*
    // Initialize the characteristics table, exporting the Miniport's entry
    // points to the Miniport wrapper.
    */
    HtDsuChar.MajorNdisVersion        = NDIS_MAJOR_VERSION;
    HtDsuChar.MinorNdisVersion        = NDIS_MINOR_VERSION;
    HtDsuChar.Reserved                = NDIS_USE_WAN_WRAPPER;

    HtDsuChar.CheckForHangHandler     = HtDsuCheckForHang;
    HtDsuChar.DisableInterruptHandler = HtDsuDisableInterrupt;
    HtDsuChar.EnableInterruptHandler  = HtDsuEnableInterrupt;
    HtDsuChar.HaltHandler             = HtDsuHalt;
    HtDsuChar.HandleInterruptHandler  = HtDsuHandleInterrupt;
    HtDsuChar.InitializeHandler       = HtDsuInitialize;
    HtDsuChar.ISRHandler              = HtDsuISR;
    HtDsuChar.QueryInformationHandler = HtDsuQueryInformation;
    HtDsuChar.ReconfigureHandler      = NULL;   // Hardware not reconfigurable
    HtDsuChar.ResetHandler            = HtDsuReset;
    HtDsuChar.SendHandler             = HtDsuWanSend;
    HtDsuChar.SetInformationHandler   = HtDsuSetInformation;
    HtDsuChar.TransferDataHandler     = NULL;   // Not used by WAN drivers

    /*
    // Register the driver with the Miniport wrapper.
    */
    Status = NdisMRegisterMiniport(
                    NdisWrapperHandle,
                    (PNDIS_MINIPORT_CHARACTERISTICS) &HtDsuChar,
                    sizeof(HtDsuChar)
                    );

    /*
    // The driver will not load if this call fails.
    // The system will log the error for us.
    */
    if (Status != NDIS_STATUS_SUCCESS)
    {
        DBG_DISPLAY(("ERROR: NdisMRegisterMiniport Status=%Xh\n",Status));
        return STATUS_UNSUCCESSFUL;
    }

    return STATUS_SUCCESS;
}



NDIS_STATUS
HtDsuInitialize(
    OUT PNDIS_STATUS OpenErrorStatus,
    OUT PUINT SelectedMediumIndex,
    IN PNDIS_MEDIUM MediumArray,
    IN UINT MediumArraySize,
    IN NDIS_HANDLE MiniportAdapterHandle,
    IN NDIS_HANDLE WrapperConfigurationContext
    )

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Functional Description:

    The MiniportInitialize request is called to have the Miniport driver
    initialize the adapter.

    No other request will be outstanding on the Miniport when this routine
    is called.  No other request will be submitted to the Miniport until
    the operation is completed.

    The wrapper will supply an array containing a list of the media types
    that it supports.  The Miniport driver reads this array and returns
    the index of the media type that the wrapper should treat her as.
    If the Miniport driver is impersonating a media type that is different
    from the true media type, this must be done completely transparently to
    the wrapper.

    If the Miniport driver cannot find a media type supported by both it
    and the wrapper, it returns NDIS_STATUS_UNSUPPORTED_MEDIA.

    The status value NDIS_STATUS_OPEN_ERROR has a special meaning.  It
    indicates that the OpenErrorStatus parameter has returned a valid status
    which the wrapper can examine to obtain more information about the error.

    This routine is called with interrupts enabled, and a call to MiniportISR
    will occur if the adapter generates any interrupts.  During this routine
    MiniportDisableInterrupt and MiniportEnableInterrupt will not be called,
    so it is the responsibility of the Miniport driver to acknowledge and
    clear any interrupts generated.

Parameters:

    OpenErrorStatus _ Returns more information about the reason for the
                      failure. Currently, the only values defined match those
                      specified as Open Error Codes in Appendix B of the IBM
                      Local Area Network Technical Reference.

    SelectedMediumIndex _ Returns the index in MediumArray of the medium type
                          that the Miniport driver wishes to be viewed as.
                          Note that even though the NDIS interface may complete
                          this request asynchronously, it must return this
                          index on completion of this function.

    MediumArray _ An array of medium types which the wrapper supports.

    MediumArraySize _ The number of elements in MediumArray.

    MiniportAdapterHandle _ A handle identifying the Miniport.  The Miniport
                            driver must supply this handle in future requests
                            that refer to the Miniport.

    WrapperConfigurationContext _ The handle used for calls to NdisOpenConfiguration,
                                  and the routines in section 4 of this document.

Return Values:

    NDIS_STATUS_ADAPTER_NOT_FOUND
    NDIS_STATUS_FAILURE
    NDIS_STATUS_NOT_ACCEPTED
    NDIS_STATUS_OPEN_ERROR
    NDIS_STATUS_RESOURCES
    NDIS_STATUS_SUCCESS
    NDIS_STATUS_UNSUPPORTED_MEDIA

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

{
    DBG_FUNC("HtDsuInitialize")

    /*
    // Holds the status result returned from an NDIS function call.
    */
    NDIS_STATUS Status;

    /*
    // Pointer to our newly allocated adapter.
    */
    PHTDSU_ADAPTER Adapter;

    /*
    // The handle for reading from the registry.
    */
    NDIS_HANDLE ConfigHandle;

    /*
    // The value read from the registry.
    */
    PNDIS_CONFIGURATION_PARAMETER ReturnedValue;

    UINT index;

    /*
    // Define all the parameters that will be read.
    */
    NDIS_STRING RamBaseString = HTDSU_PARAM_RAMBASE_STRING;
    ULONG RamBaseAddress      = 0;

    NDIS_STRING InterruptString = HTDSU_PARAM_INTERRUPT_STRING;
    CCHAR InterruptNumber       = 0;

    NDIS_STRING LineTypeString = HTDSU_PARAM_LINETYPE_STRING;
    CCHAR LineType             = 0;

    NDIS_STRING MediaTypeString = HTDSU_PARAM_MEDIATYPE_STRING;
    ANSI_STRING MediaType;

    NDIS_STRING DeviceNameString = HTDSU_PARAM_DEVICENAME_STRING;
    ANSI_STRING DeviceName;

    NDIS_STRING AddressListString = HTDSU_PARAM_ADDRLIST_STRING;
    ANSI_STRING AddressList;

#if DBG
    NDIS_STRING DbgFlagsString = HTDSU_PARAM_DBGFLAGS_STRING;
    ULONG DbgFlags             = 0;
#endif

    /*
    // Search the MediumArray for the WAN media type.
    */
    for (index = 0; index < MediumArraySize; index++)
    {
        if (MediumArray[index] == NdisMediumWan)
        {
            break;
        }
    }

    /*
    // Return if no supported medium is found.
    */
    if (index >= MediumArraySize)
    {
        DBG_DISPLAY(("ERROR: No medium found (array=%X,size=%d)\n",
                    MediumArray, MediumArraySize));
        /*
        // Log error message and exit.
        */
        NdisWriteErrorLogEntry(
                MiniportAdapterHandle,
                NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION,
                3,
                index,
                __FILEID__,
                __LINE__
                );
        return NDIS_STATUS_UNSUPPORTED_MEDIA;
    }

    /*
    // Save the selected medium type.
    */
    *SelectedMediumIndex = index;

    /*
    // Open the configuration registry so we can get our config values.
    */
    NdisOpenConfiguration(
            &Status,
            &ConfigHandle,
            WrapperConfigurationContext
            );

    if (Status != NDIS_STATUS_SUCCESS)
    {
        DBG_DISPLAY(("ERROR: NdisOpenConfiguration failed (Status=%X)\n",Status));
        /*
        // Log error message and exit.
        */
        NdisWriteErrorLogEntry(
                MiniportAdapterHandle,
                NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION,
                3,
                Status,
                __FILEID__,
                __LINE__
                );
        return NDIS_STATUS_FAILURE;
    }

    /********************************************************************
    // Get InterruptNumber for this adapter.
    */
    NdisReadConfiguration(
            &Status,
            &ReturnedValue,
            ConfigHandle,
            &InterruptString,
            NdisParameterInteger
            );

    if (Status == NDIS_STATUS_SUCCESS)
    {
        InterruptNumber = (CCHAR)(ReturnedValue->ParameterData.IntegerData);
    }
    else
    {
        DBG_DISPLAY(("ERROR: NdisReadConfiguration(InterruptNumber) failed (Status=%X)\n",Status));
        /*
        // Log error message and exit.
        */
        NdisWriteErrorLogEntry(
                MiniportAdapterHandle,
                NDIS_ERROR_CODE_MISSING_CONFIGURATION_PARAMETER,
                3,
                Status,
                __FILEID__,
                __LINE__
                );
        NdisCloseConfiguration(ConfigHandle);
        return NDIS_STATUS_FAILURE;
    }

    /*
    // Make sure the interrupt IRQ is valid.
    */
    if ((InterruptNumber != HTDSU_PARAM_IRQ03) &&
        (InterruptNumber != HTDSU_PARAM_IRQ04) &&
        (InterruptNumber != HTDSU_PARAM_IRQ10) &&
        (InterruptNumber != HTDSU_PARAM_IRQ11) &&
        (InterruptNumber != HTDSU_PARAM_IRQ12) &&

⌨️ 快捷键说明

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