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

📄 config.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 3 页
字号:
            }

            MiniportResource = ExAllocatePool(PagedPool, sizeof(MINIPORT_RESOURCE));
            if(!MiniportResource)
            {
                NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
                ExFreePool(KeyInformation);
                ExFreePool(*ParameterValue);
                *ParameterValue = NULL;
                *Status = NDIS_STATUS_RESOURCES;
                return;
            }

            MiniportResource->ResourceType = 0;
            MiniportResource->Resource = *ParameterValue;
            NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
            ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);

            (*ParameterValue)->ParameterType = ParameterType;
            memcpy(&((*ParameterValue)->ParameterData.BinaryData), KeyInformation->Data, KeyInformation->DataLength);

            ExFreePool(KeyInformation);

            *Status = NDIS_STATUS_SUCCESS;

            return;
        }
    }
}


UCHAR UnicodeToHexByte(WCHAR chr)
/*
 * FUNCTION: Converts a unicode hex character to its numerical value
 * ARGUMENTS:
 *     chr: Unicode character to convert
 * RETURNS:
 *     The numerical value of chr
 */
{
    switch(chr)
    {
        case L'0': return 0;
        case L'1': return 1;
        case L'2': return 2;
        case L'3': return 3;
        case L'4': return 4;
        case L'5': return 5;
        case L'6': return 6;
        case L'7': return 7;
        case L'8': return 8;
        case L'9': return 9;
        case L'A':
        case L'a':
            return 10;
        case L'B':
        case L'b':
            return 11;
        case L'C':
        case L'c':
            return 12;
        case L'D':
        case L'd':
            return 13;
        case L'E':
        case L'e':
            return 14;
        case L'F':
        case L'f':
            return 15;
    }
    return -1;
}


/*
 * @implemented
 */
VOID
EXPORT
NdisReadNetworkAddress(
    OUT PNDIS_STATUS    Status,
    OUT PVOID           * NetworkAddress,
    OUT PUINT           NetworkAddressLength,
    IN  NDIS_HANDLE     ConfigurationHandle)
/*
 * FUNCTION: Reads the network address from the registry
 * ARGUMENTS:
 *     Status - variable to receive status
 *     NetworkAddress - pointer to a buffered network address array
 *     NetworkAddressLength - length of the NetworkAddress array
 *     ConfigurationHandle: handle passed back from one of the open routines
 * RETURNS:
 *     NDIS_STATUS_SUCCESS on success
 *     NDIS_STATUS_FAILURE on failure
 *     The network address is placed in the NetworkAddress buffer
 */
{
    PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext = (PMINIPORT_CONFIGURATION_CONTEXT)ConfigurationHandle;
    PMINIPORT_RESOURCE MiniportResource = NULL;
    PNDIS_CONFIGURATION_PARAMETER ParameterValue = NULL;
    NDIS_STRING Keyword;
    UINT *IntArray = 0;
    int i;

    /* FIXME - We don't quite support this yet due to buggy code below */
      {
        *Status = NDIS_STATUS_FAILURE;
        return;
      }

    *NetworkAddress = NULL;
    *NetworkAddressLength = 6;/* XXX magic constant */

    NdisInitUnicodeString(&Keyword, L"NetworkAddress");
    NdisReadConfiguration(Status, &ParameterValue, ConfigurationHandle, &Keyword, NdisParameterString);
    if(*Status != NDIS_STATUS_SUCCESS)
    {
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    /* 6 bytes for ethernet, tokenring, fddi, everything else? */
    IntArray = ExAllocatePool(PagedPool, 6*sizeof(UINT));
    if(!IntArray)
    {
        NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
        *Status = NDIS_STATUS_RESOURCES;
        return;
    }

    MiniportResource = ExAllocatePool(PagedPool, sizeof(MINIPORT_RESOURCE));
    if(!MiniportResource)
    {
        NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    MiniportResource->ResourceType = 0;
    MiniportResource->Resource = IntArray;
    NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
    ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);

    /* convert from string to bytes */
    for(i=0; i<6; i++)
    {
        IntArray[i] = (UnicodeToHexByte((ParameterValue->ParameterData.StringData.Buffer)[2*i]) << 4) +
                UnicodeToHexByte((ParameterValue->ParameterData.StringData.Buffer)[2*i+1]);
    }

    *NetworkAddress = IntArray;

    *Status = NDIS_STATUS_SUCCESS;
}


/*
 * @implemented
 */
VOID
EXPORT
NdisOpenConfigurationKeyByIndex(
    OUT PNDIS_STATUS    Status,
    IN  NDIS_HANDLE     ConfigurationHandle,
    IN  ULONG           Index,
    OUT PNDIS_STRING    KeyName,
    OUT PNDIS_HANDLE    KeyHandle)
/*
 * FUNCTION: Opens a configuration subkey by index number
 * ARGUMENTS:
 *     Status: pointer to an NDIS_STATUS to receive status info
 *     ConfigurationHandle: the handle passed back from a previous open function
 *     Index: the zero-based index of the subkey to open
 *     KeyName: the name of the key that was opened
 *     KeyHandle: a handle to the key that was opened
 * RETURNS:
 *     NDIS_STATUS_SUCCESS on success
 *     NDIS_STATUS_FAILURE on failure
 *     KeyName holds the name of the opened key
 *     KeyHandle holds a handle to the new key
 */
{
    KEY_BASIC_INFORMATION *KeyInformation;
    ULONG KeyInformationLength;
    OBJECT_ATTRIBUTES KeyAttributes;
    NDIS_HANDLE RegKeyHandle;
    PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;

    *Status = ZwEnumerateKey(ConfigurationHandle, Index, KeyBasicInformation, NULL, 0, &KeyInformationLength);
    if(*Status != STATUS_BUFFER_TOO_SMALL && *Status != STATUS_BUFFER_OVERFLOW && *Status != STATUS_SUCCESS)
    {
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    KeyInformation = ExAllocatePool(PagedPool, KeyInformationLength + sizeof(KEY_BASIC_INFORMATION));
    if(!KeyInformation)
    {
        NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    *Status = ZwEnumerateKey(ConfigurationHandle, Index, KeyBasicInformation, KeyInformation,
        KeyInformationLength + sizeof(KEY_BASIC_INFORMATION), &KeyInformationLength);

    if(*Status != STATUS_SUCCESS)
    {
        ExFreePool(KeyInformation);
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    /* should i fail instead if the passed-in string isn't long enough? */
    wcsncpy(KeyName->Buffer, KeyInformation->Name, KeyName->MaximumLength/sizeof(WCHAR));
    KeyName->Length = (USHORT)KeyInformation->NameLength;

    InitializeObjectAttributes(&KeyAttributes, KeyName, OBJ_CASE_INSENSITIVE, ConfigurationHandle, NULL);

    *Status = ZwOpenKey(&RegKeyHandle, KEY_ALL_ACCESS, &KeyAttributes);

    ExFreePool(KeyInformation);

    if(*Status != STATUS_SUCCESS)
    {
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    ConfigurationContext = ExAllocatePool(PagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
    if(!ConfigurationContext)
    {
        NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    KeInitializeSpinLock(&ConfigurationContext->ResourceLock);
    InitializeListHead(&ConfigurationContext->ResourceListHead);

    ConfigurationContext->Handle = RegKeyHandle;

    *KeyHandle = (NDIS_HANDLE)ConfigurationContext;

    *Status = NDIS_STATUS_SUCCESS;
}


/*
 * @implemented
 */
VOID
EXPORT
NdisOpenConfigurationKeyByName(
    OUT PNDIS_STATUS    Status,
    IN  NDIS_HANDLE     ConfigurationHandle,
    IN  PNDIS_STRING    KeyName,
    OUT PNDIS_HANDLE    KeyHandle)
/*
 * FUNCTION: Opens a configuration subkey by name
 * ARGUMENTS:
 *     Status: points to an NDIS_STATUS where status is returned
 *     ConfigurationHandle: handle returned by a previous open call
 *     KeyName: the name of the key to open
 *     KeyHandle: a handle to the opened key
 * RETURNS:
 *     NDIS_STATUS_SUCCESS on success
 *     NDIS_STATUS_FAILURE on failure
 *     KeyHandle holds a handle to the newly-opened key
 * NOTES:
 */
{
    PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext;
    OBJECT_ATTRIBUTES KeyAttributes;
    NDIS_HANDLE RegKeyHandle;

    InitializeObjectAttributes(&KeyAttributes, KeyName, OBJ_CASE_INSENSITIVE, ConfigurationHandle, 0);
    *Status = ZwOpenKey(&RegKeyHandle, KEY_ALL_ACCESS, &KeyAttributes);

    if(*Status != STATUS_SUCCESS)
    {
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    ConfigurationContext = ExAllocatePool(PagedPool, sizeof(MINIPORT_CONFIGURATION_CONTEXT));
    if(!ConfigurationContext)
    {
        NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
        *Status = NDIS_STATUS_FAILURE;
        return;
    }

    KeInitializeSpinLock(&ConfigurationContext->ResourceLock);
    InitializeListHead(&ConfigurationContext->ResourceListHead);

    ConfigurationContext->Handle = RegKeyHandle;

    *KeyHandle = (NDIS_HANDLE)ConfigurationContext;

    *Status = NDIS_STATUS_SUCCESS;
}

⌨️ 快捷键说明

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