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

📄 htdsu.c

📁 这是一个56K MODEM的驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
        (InterruptNumber != HTDSU_PARAM_IRQ15))
    {
        DBG_DISPLAY(("ERROR: Invalid InterruptNumber=%d)\n",InterruptNumber));
        /*
        // Log error message and exit.
        */
        NdisWriteErrorLogEntry(
                MiniportAdapterHandle,
                NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION,
                3,
                InterruptNumber,
                __FILEID__,
                __LINE__
                );
        NdisCloseConfiguration(ConfigHandle);
        return NDIS_STATUS_FAILURE;
    }

    /********************************************************************
    // Get RambaseAddress for this adapter.
    */
    NdisReadConfiguration(
            &Status,
            &ReturnedValue,
            ConfigHandle,
            &RamBaseString,
            NdisParameterHexInteger
            );

    if (Status == NDIS_STATUS_SUCCESS)
    {
        RamBaseAddress = (ULONG)(ReturnedValue->ParameterData.IntegerData);
    }
    else
    {
        DBG_DISPLAY(("ERROR: NdisReadConfiguration(RamBaseAddress) 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 RambaseAddress is valid.
    */
    if ((RamBaseAddress != HTDSU_PARAM_RAMBASE1) &&
        (RamBaseAddress != HTDSU_PARAM_RAMBASE2) &&
        (RamBaseAddress != HTDSU_PARAM_RAMBASE3) &&
        (RamBaseAddress != HTDSU_PARAM_RAMBASE4))
    {
        DBG_DISPLAY(("ERROR: Invalid RamBaseAddress=%Xh\n",RamBaseAddress));
        /*
        // Log error message and exit.
        */
        NdisWriteErrorLogEntry(
                MiniportAdapterHandle,
                NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION,
                3,
                RamBaseAddress,
                __FILEID__,
                __LINE__
                );
        NdisCloseConfiguration(ConfigHandle);
        return NDIS_STATUS_FAILURE;
    }

    /********************************************************************
    // Get MediaType for this adapter.
    // The MediaType and DeviceName values are used to construct the
    // ProviderInfo strings required by HtTapiGetDevCaps.
    */
    NdisReadConfiguration(
            &Status,
            &ReturnedValue,
            ConfigHandle,
            &MediaTypeString,
            NdisParameterString
            );

    if (Status == NDIS_STATUS_SUCCESS)
    {
        RtlUnicodeStringToAnsiString(
                &MediaType,
                &(ReturnedValue->ParameterData.StringData),
                TRUE
                );
    }
    else
    {
        DBG_DISPLAY(("ERROR: NdisReadConfiguration(MediaType) 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;
    }

    /********************************************************************
    // Get DeviceName for this adapter.
    // The MediaType and DeviceName values are used to construct the
    // ProviderInfo strings required by HtTapiGetDevCaps.
    */
    NdisReadConfiguration(
            &Status,
            &ReturnedValue,
            ConfigHandle,
            &DeviceNameString,
            NdisParameterString
            );

    if (Status == NDIS_STATUS_SUCCESS)
    {
        RtlUnicodeStringToAnsiString(
                &DeviceName,
                &(ReturnedValue->ParameterData.StringData),
                TRUE
                );
    }
    else
    {
        DBG_DISPLAY(("ERROR: NdisReadConfiguration(DeviceName) 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;
    }

    /********************************************************************
    // Get AddressList for this adapter.
    */
    NdisReadConfiguration(
            &Status,
            &ReturnedValue,
            ConfigHandle,
            &AddressListString,
            NdisParameterString
            );

    if (Status == NDIS_STATUS_SUCCESS)
    {
        RtlUnicodeStringToAnsiString(
                &AddressList,
                &(ReturnedValue->ParameterData.StringData),
                TRUE
                );
    }
    else
    {
        DBG_DISPLAY(("ERROR: NdisReadConfiguration(AddressList) 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;
    }

#ifdef USE_LEASED_LINE
    /********************************************************************
    // Get LineType for this adapter.
    */
    NdisReadConfiguration(
            &Status,
            &ReturnedValue,
            ConfigHandle,
            &LineTypeString,
            NdisParameterInteger
            );

    if (Status == NDIS_STATUS_SUCCESS)
    {
        LineType = (CCHAR)(ReturnedValue->ParameterData.IntegerData);
    }
    else
    {
        DBG_DISPLAY(("ERROR: NdisReadConfiguration(LineType) 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 LineType is valid.
    */
    if ((LineType != HTDSU_LINEMODE_LEASED) &&
        (LineType != HTDSU_LINEMODE_DIALUP))
    {
        DBG_DISPLAY(("ERROR: Invalid LineType=%d\n",LineType));
        /*
        // Log error message and exit.
        */
        NdisWriteErrorLogEntry(
                MiniportAdapterHandle,
                NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION,
                3,
                LineType,
                __FILEID__,
                __LINE__
                );
        NdisCloseConfiguration(ConfigHandle);
        return NDIS_STATUS_FAILURE;
    }
#else
    LineType = HTDSU_LINEMODE_DIALUP;
#endif // USE_LEASED_LINE

#if DBG
    /********************************************************************
    // Get DbgFlags for this adapter.
    */
    NdisReadConfiguration(
            &Status,
            &ReturnedValue,
            ConfigHandle,
            &DbgFlagsString,
            NdisParameterHexInteger
            );

    if (Status == NDIS_STATUS_SUCCESS)
    {
        DbgFlags = (ULONG)(ReturnedValue->ParameterData.IntegerData);
    }
    else
    {
        DbgFlags = 0;
    }
#endif

    /*
    // Close the configuration registry - we're done with it.
    */
    NdisCloseConfiguration(ConfigHandle);

    /*
    // Allocate memory for the adapter information structure.
    */
    Status = NdisAllocateMemory(
                    (PVOID *)&Adapter,
                    sizeof(*Adapter),
                    0,
                    HighestAcceptableAddress
                    );

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

    /*
    // Init the adapter structure values to NULL.
    */
    NdisZeroMemory (Adapter, sizeof(*Adapter));

    /*
    // Assign a unique ID to this adapter instance.
    */
    Adapter->InstanceNumber = ++HtDsuAdapterCount;

    /*
    // We use the adapter id number in debug messages to help when debugging
    // with multiple adapters.
    */
#if DBG
    Adapter->DbgID[0] = (0x0F & HtDsuAdapterCount) + '0';
    Adapter->DbgID[1] = 0;
    Adapter->DbgFlags = DbgFlags;
#endif

    DBG_DISPLAY(("HTDSU41(Adap=%08Xh,Ram=%05lXh,RamSiz=%04Xh,BufSiz=%04Xh,IRQ=%d)\n",
               Adapter, RamBaseAddress, HTDSU_MEMORY_SIZE,
               sizeof(HTDSU_BUFFER), InterruptNumber));

    /*
    // Make sure the adapter memory structure is sized properly.
    */
    ASSERT(sizeof(HTDSU_BUFFER) == 2016);
    ASSERT(HTDSU_MEMORY_SIZE == 4096);

    /*
    // Save the config parameters in the adapter structure.
    */
    Adapter->MiniportAdapterHandle = MiniportAdapterHandle;
    Adapter->InterruptNumber = InterruptNumber;
    Adapter->MemorySize = HTDSU_MEMORY_SIZE;
    NdisSetPhysicalAddressLow(Adapter->PhysicalAddress, RamBaseAddress);
    NdisSetPhysicalAddressHigh(Adapter->PhysicalAddress, 0);

    /*
    // Construct the "MediaType\0DeviceName" string for use by TAPI.
    */
    strcpy(Adapter->ProviderInfo, MediaType.Buffer);
    strcpy(Adapter->ProviderInfo + MediaType.Length + 1, DeviceName.Buffer);
    DBG_NOTICE(Adapter, ("Media=%s Device=%s\n",
            Adapter->ProviderInfo,
            &Adapter->ProviderInfo[MediaType.Length + 1]
            ));
    Adapter->ProviderInfoSize = MediaType.Length + 1 + DeviceName.Length + 1;

    /*
    // Now it's time to initialize the hardware resources.
    */
    Status = HtDsuRegisterAdapter(Adapter, &AddressList);

    if (Status != NDIS_STATUS_SUCCESS)
    {
        HtDsuHalt(Adapter);
    }

    DBG_DISPLAY(("RETURN: Status=%Xh\n",Status));

    return Status;
}


NDIS_STATUS
HtDsuRegisterAdapter(
    IN PHTDSU_ADAPTER Adapter,
    IN PSTRING AddressList
    )

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

Functional Description:

    This function is called when a new adapter is being registered. It
    initializes the adapter information structure, allocate any resources
    needed by the adapter/driver, registers with the wrapper, and initializes
    the physical adapter.

Parameters:

    Adapter _ A pointer ot our adapter information structure.

    AddressList _ This is a list of MULTI_SZ strings which are to be assigned
                  to each link for use by TAPI HtTapiGetAddressCaps.

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("HtDsuRegisterAdapter")

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

    DBG_ENTER(Adapter);

    /*
    // Initialize the WAN information structure to match the capabilities of
    // the adapter.
    */
    Adapter->WanInfo.MaxFrameSize   = HTDSU_MAX_FRAME_SIZE;
    Adapter->WanInfo.MaxTransmit    = HTDSU_MAX_TRANSMITS;

    /*
    // Since we copy the packets to/from adapter RAM, no padding information is
    // needed in the WAN packets we get.  We can just use adapter RAM as needed.
    */
    Adapter->WanInfo.HeaderPadding  = 0;
    Adapter->WanInfo.TailPadding    = 0;

    /*
    // This value indicates how many point to point connections are allowed
    // per WAN link.  Currently, the WAN wrapper only supports 1 line per link.
    */
    Adapter->WanInfo.Endpoints      = 1;

    /*
    // Transmits and received are copied to/from adapter RAM so cached memory
    // can be used for packet allocation and we don't really care if it's
    // physically contiguous or not, as long as it's virtually contiguous.
    */
    Adapter->WanInfo.MemoryFlags    = 0;
    Adapter->WanInfo.HighestAcceptableAddress = HighestAcceptableAddress;

⌨️ 快捷键说明

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