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

📄 display.c

📁 winddk src目录下的WDM源码压缩!
💻 C
📖 第 1 页 / 共 3 页
字号:
/*++

Copyright (c) 1997-1998 Microsoft Corporation

Module Name:

DISPLAY.C

Abstract:

This source file contains the routines which update the edit control
to display information about the selected USB device.

Environment:

user mode

Revision History:

04-25-97 : created

--*/

//*****************************************************************************
// I N C L U D E S
//*****************************************************************************

#include <windows.h>
#include <basetyps.h>

#include "vndrlist.h"
#include "usbview.h"

//*****************************************************************************
// D E F I N E S
//*****************************************************************************

#define BUFFERALLOCINCREMENT        8192
#define BUFFERMINFREESPACE          1024

//*****************************************************************************
// T Y P E D E F S
//*****************************************************************************

//*****************************************************************************
// G L O B A L S    P R I V A T E    T O    T H I S    F I L E
//*****************************************************************************

// Workspace for text info which is used to update the edit control
//
CHAR *TextBuffer = NULL;
int   TextBufferLen = 0;
int   TextBufferPos = 0;

//*****************************************************************************
// L O C A L    F U N C T I O N    P R O T O T Y P E S
//*****************************************************************************

VOID
DisplayHubInfo (
    PUSB_HUB_INFORMATION HubInfo
);

VOID
DisplayConnectionInfo (
    PUSB_NODE_CONNECTION_INFORMATION_EX    ConnectInfo,
    PSTRING_DESCRIPTOR_NODE             StringDescs
);

VOID
DisplayPipeInfo (
    ULONG           NumPipes,
    USB_PIPE_INFO  *PipeInfo
);

VOID
DisplayConfigDesc (
    PUSB_CONFIGURATION_DESCRIPTOR   ConfigDesc,
    PSTRING_DESCRIPTOR_NODE         StringDescs
);

VOID
DisplayConfigurationDescriptor (
    PUSB_CONFIGURATION_DESCRIPTOR   ConfigDesc,
    PSTRING_DESCRIPTOR_NODE         StringDescs
);

VOID
DisplayInterfaceDescriptor (
    PUSB_INTERFACE_DESCRIPTOR   InterfaceDesc,
    PSTRING_DESCRIPTOR_NODE     StringDescs
);

VOID
DisplayEndpointDescriptor (
    PUSB_ENDPOINT_DESCRIPTOR    EndpointDesc
);

VOID
DisplayHidDescriptor (
    PUSB_HID_DESCRIPTOR         HidDesc
);

VOID
DisplayStringDescriptor (
    UCHAR                       Index,
    PSTRING_DESCRIPTOR_NODE     StringDescs
);

VOID
DisplayUnknownDescriptor (
    PUSB_COMMON_DESCRIPTOR      CommonDesc
);

PCHAR
GetVendorString (
    USHORT     idVendor
);

//*****************************************************************************
// L O C A L    F U N C T I O N S
//*****************************************************************************


//*****************************************************************************
//
// CreateTextBuffer()
//
//*****************************************************************************

BOOL
CreateTextBuffer (
)
{
    // Allocate the buffer
    //
    TextBuffer = ALLOC(BUFFERALLOCINCREMENT);

    if (TextBuffer == NULL)
    {
        OOPS();

        return FALSE;
    }

    TextBufferLen = BUFFERALLOCINCREMENT;

    // Reset the buffer position and terminate the buffer
    //
    *TextBuffer = 0;
    TextBufferPos = 0;

    return TRUE;
}


//*****************************************************************************
//
// DestroyTextBuffer()
//
//*****************************************************************************

VOID
DestroyTextBuffer (
)
{
    if (TextBuffer != NULL)
    {
        FREE(TextBuffer);

        TextBuffer = NULL;
    }
}


//*****************************************************************************
//
// ResetTextBuffer()
//
//*****************************************************************************

BOOL
ResetTextBuffer (
)
{
    // Fail if the text buffer has not been allocated
    //
    if (TextBuffer == NULL)
    {
        OOPS();

        return FALSE;
    }

    // Reset the buffer position and terminate the buffer
    //
    *TextBuffer = 0;
    TextBufferPos = 0;

    return TRUE;
}

//*****************************************************************************
//
// AppendTextBuffer()
//
//*****************************************************************************

VOID __cdecl
AppendTextBuffer (
    LPCTSTR lpFormat,
    ...
)
{
    va_list arglist;

    va_start(arglist, lpFormat);

    // Make sure we have a healthy amount of space free in the buffer,
    // reallocating the buffer if necessary.
    //
    if (TextBufferLen - TextBufferPos < BUFFERMINFREESPACE)
    {
        CHAR *TextBufferTmp;

        TextBufferTmp = REALLOC(TextBuffer, TextBufferLen+BUFFERALLOCINCREMENT);

        if (TextBufferTmp != NULL)
        {
            TextBuffer = TextBufferTmp;
            TextBufferLen += BUFFERALLOCINCREMENT;
        }
        else
        {
            // If GlobalReAlloc fails, the original memory is not freed,
            // and the original handle and pointer are still valid.
            //
            OOPS();

            return;
        }
    }

    // Add the text to the end of the buffer, updating the buffer position.
    //
    TextBufferPos += wvsprintf(TextBuffer + TextBufferPos,
                               lpFormat,
                               arglist);
}


//
// Hardcoded information about specific EHCI controllers
//
typedef struct _EHCI_CONTROLLER_DATA
{
    USHORT  VendorID;
    USHORT  DeviceID;
    UCHAR   DebugPortNumber;
} EHCI_CONTROLLER_DATA, *PEHCI_CONTROLLER_DATA;

EHCI_CONTROLLER_DATA EhciControllerData[] =
{
    {0x8086, 0x24CD, 1},
    {0x8086, 0x24DD, 1},
    {0x10DE, 0x00D8, 1},
    {0,0,0},
};


//*****************************************************************************
//
// UpdateEditControl()
//
// hTreeItem - Handle of selected TreeView item for which information should
// be displayed in the edit control.
//
//*****************************************************************************

VOID
UpdateEditControl (
    HWND      hEditWnd,
    HWND      hTreeWnd,
    HTREEITEM hTreeItem
)
{
    TV_ITEM tvi;
    PVOID   info;
    ULONG   i;

    // Start with an empty text buffer.
    //
    if (!ResetTextBuffer())
    {
        return;
    }

    //
    // Get the name of the TreeView item, along with the a pointer to the
    // info we stored about the item in the item's lParam.
    //

    tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM;
    tvi.hItem = hTreeItem;
    tvi.pszText = (LPSTR)TextBuffer;
    tvi.cchTextMax = TextBufferLen-2;  // leave space for "\r\n'

    TreeView_GetItem(hTreeWnd,
                     &tvi);

    info = (PVOID)tvi.lParam;

    //
    // If we didn't store any info for the item, just display the item's
    // name, else display the info we stored for the item.
    //
    if (info)
    {
        PUSB_NODE_INFORMATION               HubInfo = NULL;
        PCHAR                               HubName = NULL;
        PUSB_NODE_CONNECTION_INFORMATION_EX ConnectionInfo = NULL;
        PUSB_DESCRIPTOR_REQUEST             ConfigDesc = NULL;
        PSTRING_DESCRIPTOR_NODE             StringDescs = NULL;

        switch (*(PUSBDEVICEINFOTYPE)info)
        {
            case HostControllerInfo:
                AppendTextBuffer("DriverKey: %s\r\n",
                                 ((PUSBHOSTCONTROLLERINFO)info)->DriverKey);

                AppendTextBuffer("VendorID: %04X\r\n",
                                 ((PUSBHOSTCONTROLLERINFO)info)->VendorID);

                AppendTextBuffer("DeviceID: %04X\r\n",
                                 ((PUSBHOSTCONTROLLERINFO)info)->DeviceID);

                AppendTextBuffer("SubSysID: %08X\r\n",
                                 ((PUSBHOSTCONTROLLERINFO)info)->SubSysID);

                AppendTextBuffer("Revision: %02X\r\n",
                                 ((PUSBHOSTCONTROLLERINFO)info)->Revision);

                for (i = 0; EhciControllerData[i].VendorID; i++)
                {
                    if (((PUSBHOSTCONTROLLERINFO)info)->VendorID ==
                          EhciControllerData[i].VendorID &&
                        ((PUSBHOSTCONTROLLERINFO)info)->DeviceID ==
                          EhciControllerData[i].DeviceID)
                    {
                        AppendTextBuffer("DebugPort: %d\r\n",
                                         EhciControllerData[i].DebugPortNumber);
                    }
                }

                break;

            case RootHubInfo:
                HubInfo = ((PUSBROOTHUBINFO)info)->HubInfo;
                HubName = ((PUSBROOTHUBINFO)info)->HubName;

                AppendTextBuffer("Root Hub: %s\r\n",
                                 HubName);

                break;

            case ExternalHubInfo:
                HubInfo = ((PUSBEXTERNALHUBINFO)info)->HubInfo;
                HubName = ((PUSBEXTERNALHUBINFO)info)->HubName;
                ConnectionInfo = ((PUSBEXTERNALHUBINFO)info)->ConnectionInfo;
                ConfigDesc = ((PUSBEXTERNALHUBINFO)info)->ConfigDesc;
                StringDescs = ((PUSBEXTERNALHUBINFO)info)->StringDescs;

                AppendTextBuffer("External Hub: %s\r\n",
                                 HubName);

                break;

            case DeviceInfo:
                ConnectionInfo = ((PUSBDEVICEINFO)info)->ConnectionInfo;
                ConfigDesc = ((PUSBDEVICEINFO)info)->ConfigDesc;
                StringDescs = ((PUSBDEVICEINFO)info)->StringDescs;
                break;
        }

        if (HubInfo)
        {
            DisplayHubInfo(&HubInfo->u.HubInformation);
        }

        if (ConnectionInfo)
        {
            DisplayConnectionInfo(ConnectionInfo,
                                  StringDescs);
        }

        if (ConfigDesc)
        {
            DisplayConfigDesc((PUSB_CONFIGURATION_DESCRIPTOR)(ConfigDesc + 1),
                              StringDescs);
        }
    }

    // All done formatting text buffer with info, now update the edit
    // control with the contents of the text buffer
    //
    SetWindowText(hEditWnd, TextBuffer);
}


//*****************************************************************************
//
// DisplayHubInfo()
//
// HubInfo - Info about the hub.
//
//*****************************************************************************

VOID
DisplayHubInfo (
    PUSB_HUB_INFORMATION    HubInfo
)
{

⌨️ 快捷键说明

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