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

📄 config.c

📁 mx27 f14v2 源代码。包括ADS板上诸多驱动的源码。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************
**
** NAME         boCFGreadArray
**
** PARAMETERS   hRegistryHandle          Handle to open registry key.
**              sKeyword                 NDIS string constant that identifies
**                                       the registry key containing the
**                                       parameter.
**              ulLength                 Length of array.
**              paucValue                Pointer to array.
**
** RETURNS      A boolean indicating whether the parameter was successfully
**              read from the the registry.
**
** DESCRIPTION  This function should be called to read a string parameter from
**              the registry in hex format and convert it to an array of bytes.
**
******************************************************************************/
static BOOLEAN
boCFGreadArray(IN NDIS_HANDLE hRegistryHandle,
               IN CONST NDIS_STRING sKeyword,
               IN ULONG ulLength,
               OUT PUCHAR paucValue)
{
    PNDIS_CONFIGURATION_PARAMETER psParam;
    BOOLEAN boResult = FALSE;

    if (boENDreadValue(hRegistryHandle, &psParam, sKeyword,
                       NdisParameterString))
    {
        boResult = boCFGunicodeToByteArray(psParam->ParameterData.StringData,
                                           paucValue, ulLength);
    }
    return boResult;
}


/*****************************************************************************
**
** NAME         boCFGreadUlong
**
** PARAMETERS   hRegistryHandle          Handle to open registry key.
**              sKeyword                 NDIS string constant that identifies
**                                       the registry key containing the
**                                       parameter.
**              pulValue                 Pointer to ulong.
**
** RETURNS      A boolean indicating whether the parameter was successfully
**              read from the the registry.
**
** DESCRIPTION  This function should be called to read a unsigned long value
**              from the registry.
**
******************************************************************************/
static BOOLEAN
boCFGreadUlong(IN NDIS_HANDLE hRegistryHandle,
               IN CONST NDIS_STRING sKeyword,
               OUT PULONG pulValue)
{
    PNDIS_CONFIGURATION_PARAMETER psParam;
    BOOLEAN boResult = FALSE;

    boResult = boENDreadValue(hRegistryHandle, &psParam, sKeyword,
                              NdisParameterInteger);
    if (boResult)
    {
        *pulValue = psParam->ParameterData.IntegerData;
    }

    return boResult;
}


/*****************************************************************************
**
** NAME         boCFGreadInt
**
** PARAMETERS   hRegistryHandle          Handle to open registry key.
**              sKeyword                 NDIS string constant that identifies
**                                       the registry key containing the
**                                       parameter.
**              pulValue                 Pointer to ulong.
**
** RETURNS      A boolean indicating whether the parameter was successfully
**              read from the the registry.
**
** DESCRIPTION  This function should be called to read a signed int value
**              from the registry.
**
******************************************************************************/
static BOOLEAN
boCFGreadInt(IN NDIS_HANDLE hRegistryHandle,
             IN CONST NDIS_STRING sKeyword,
             OUT PINT piValue)
{
    PNDIS_CONFIGURATION_PARAMETER psParam;
    BOOLEAN boResult = FALSE;

    boResult = boENDreadValue(hRegistryHandle, &psParam, sKeyword,
                              NdisParameterInteger);
    if (boResult)
    {
        *piValue = psParam->ParameterData.IntegerData;
    }

    return boResult;
}

static void 
vConvertNDIS_STRINGtoCharBuffer(PNDIS_STRING psNDISstring, char *pBuffer, unsigned short iMaxLength)
{
    ANSI_STRING sAnsiString;
    sAnsiString.Buffer = pBuffer;
    sAnsiString.Length = 0;
    sAnsiString.MaximumLength = iMaxLength;
    NdisUnicodeStringToAnsiString( &sAnsiString, psNDISstring );
}


/*****************************************************************************
**
** NAME         boENDreadValue
**
** PARAMETERS   hRegistryHandle         Handle to open registry key.
**              ppsParam                Pointer to pointer to structure where
**                                      the parameter read will be placed.
**              sKeyword                Keyword identifying registry entry to
**                                      be read.
**              eParamType              NdisParameterString
**                                      NdisParameterInteger
**
** RETURNS      A boolean indicating whether the value of the keyword was
**              successfully read.
**
** DESCRIPTION  This function wraps access to the read configuration function
**              for reading the values of keywords from the registry.
**
******************************************************************************/
static BOOLEAN
boENDreadValue(IN NDIS_HANDLE hRegistryHandle,
               OUT PNDIS_CONFIGURATION_PARAMETER *ppsParam,
               IN CONST NDIS_STRING sKeyword,
               IN NDIS_PARAMETER_TYPE eParamType)
{
    NDIS_STATUS iStatus;

    NdisReadConfiguration(&iStatus, ppsParam, hRegistryHandle,
                          (PNDIS_STRING)&sKeyword, eParamType);

    // Now let caller handle failure condition; no longer print debug warning

    return (iStatus == NDIS_STATUS_SUCCESS);
}

/*****************************************************************************
**
** NAME         boENDreadValue
**
** PARAMETERS   sKeyword                Keyword identifying registry entry
**                                      that failed to be read.
**
** RETURNS      Nothing
**
** DESCRIPTION  This function converts an NDIS_STRING into a printable string
**				and outputs a warning message indicating a failure to read
**				a configuration value from the register.
**
******************************************************************************/
static VOID
vCFGprintRegReadWarn(IN CONST NDIS_STRING sKeyword)
{
    char buffer[30];
    vConvertNDIS_STRINGtoCharBuffer((PNDIS_STRING)&sKeyword, (char *)buffer,
                                    sizeof(buffer));
    DBG_LEV1(("Couldn't read value \"%s\" from registry. "
              "Using default value.\n", buffer));
}

/*****************************************************************************
**
** NAME         vCFGprintRegReadWarn2
**
** PARAMETERS   sKeyword                Keyword identifying registry entry
**                                      that read back an out of bounds
**                                      value.
**
** RETURNS      Nothing
**
** DESCRIPTION  This function converts an NDIS_STRING into a printable string
**              and outputs a warning message indicating that the
**              configuration value read back from the register is out of
**              bounds.
**
******************************************************************************/
static VOID
vCFGprintRegReadWarn2(IN CONST NDIS_STRING sKeyword)
{
	char buffer[30];
	vConvertNDIS_STRINGtoCharBuffer((PNDIS_STRING)&sKeyword, (char *)buffer,
		                            sizeof(buffer));
	DBG_LEV1(("Value read for \"%s\" from registry is out of bounds. "
				"Using default value.\n", buffer));
}

/*****************************************************************************
**
** NAME         boCFGunicodeToByteArray
**
** PARAMETERS   sString                 String to be converted.
**              paucArray               Byte array where result should be
**                                      stored.
**              uiLength                Length of array where result should be
**                                      stored.
**
** RETURNS      A boolean indicating if the conversion was successful.
**
** DESCRIPTION  This function converts a unicode string to an array of bytes.
**              The string is expected to commence with "0x" and thereafter
**              contain only characters 0 to 9 and A to F.
**
******************************************************************************/
static BOOLEAN
boCFGunicodeToByteArray(IN NDIS_STRING sString,
                        OUT PUCHAR paucArray,
                        IN UINT uiLength)
{
    BOOLEAN boResult = FALSE;
    UINT uiStart, uiEnd, uiNibble, uiIndex;

    /* Convert from bytes to number of digits. */
    uiLength *= 2;

    /* Step past any leading spaces. */
    for (uiStart = 0;
         (uiStart < sString.Length / 2U) && (sString.Buffer[uiStart] == L' ');
         uiStart++);

    /*
    * Verify that the hex number starts with 0x or 0X and is at least
    * three digits.
    */

    if (((sString.Length / 2U) - uiStart <= 2) ||
        (sString.Buffer[uiStart] != L'0') ||
        ((sString.Buffer[uiStart + 1] != L'x') &&
         (sString.Buffer[uiStart + 1] != L'X')))
    {
        DBG_LEV0(("ERROR: Hex string does not start 0xN.\n"));
    }
    else
    {
        uiStart += 2;

        /* Find the end of the number. */
        for (uiEnd = uiStart;
             (uiEnd < (sString.Length / 2U)) && (sString.Buffer[uiEnd] != L' ');
             uiEnd++);

        /* Verify that the number will fit in the array. */
        if (uiEnd - uiStart > uiLength)
        {
            DBG_LEV0(("ERROR: Hex string too big for array: %d, %d.\n",
                      uiEnd - uiStart, uiLength));
        }
        else
        {
            /* We have succeeded unless we find a non-hex digit. */
            boResult = TRUE;

            /*
            * Pad the first nibbles with zero according to the shortfall
            * between of digits required and available.
            */
            for (uiIndex = 0; uiIndex < uiLength - (uiEnd - uiStart); uiIndex++)
            {
                paucArray[uiIndex / 2] = 0;
            }

            for ( ; uiStart < uiEnd; uiStart++, uiIndex++)
            {
                if ((sString.Buffer[uiStart] >= L'0') &&
                    (sString.Buffer[uiStart] <= L'9'))
                {
                    uiNibble = sString.Buffer[uiStart] - L'0';
                }
                else if ((sString.Buffer[uiStart] >= L'A') &&
                         (sString.Buffer[uiStart] <= L'F'))
                {
                    uiNibble = sString.Buffer[uiStart] - L'A' + 0xA;
                }
                else if ((sString.Buffer[uiStart] >= L'a') &&
                         (sString.Buffer[uiStart] <= L'f'))
                {
                    uiNibble = sString.Buffer[uiStart] - L'a' + 0xa;
                }
                else
                {
                    DBG_LEV0(("ERROR: Non-hex digit in string at position %d.\n",
                              uiStart));
                    boResult = FALSE;
                    break;
                }

                /*
                * If this is an even nibble put it in the most significant
                * nibble of the byte and clear the least sig. nibble.
                * Otherwise, or it into the least sig. nibble.
                */
                if ((uiIndex & 1) == 0)
                {
                    paucArray[uiIndex / 2] = (uiNibble << 4);
                }
                else
                {
                    paucArray[uiIndex / 2] |= uiNibble;
                }
            }
        }
    }

    return boResult;
}



/* End of file CFSD_NDconfig.c. */

⌨️ 快捷键说明

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