display.c
资源名称:VC++USB.rar [点击查看]
上传用户:hnzyys
上传日期:2015-09-10
资源大小:423k
文件大小:32k
源码类别:
通讯编程
开发平台:
Visual C++
- /*++
- 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"
- #include "usb100.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 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);
- }
- //*****************************************************************************
- //
- // 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;
- PUSBDEVICEINFO info;
- // 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 "rn'
- TreeView_GetItem(hTreeWnd,
- &tvi);
- info = (PUSBDEVICEINFO)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 != NULL)
- {
- if (info->ConnectionInfo == NULL)
- {
- // Must be Root HUB, external devices have Connection Info
- //
- AppendTextBuffer("Root Hub: %srn",
- info->HubName);
- DisplayHubInfo(&info->HubInfo->u.HubInformation);
- }
- else
- {
- if (info->HubInfo != NULL)
- {
- // Must be external HUB external
- //
- AppendTextBuffer("External Hub: %srn",
- info->HubName);
- DisplayHubInfo(&info->HubInfo->u.HubInformation);
- }
- else
- {
- // Must be external non-HUB device. Nothing special to
- // display here that isn't displayed in connection info
- // below.
- }
- // Display info common to any external device
- //
- DisplayConnectionInfo(info->ConnectionInfo,
- info->StringDescs);
- if (info->ConfigDesc)
- {
- DisplayConfigDesc((PUSB_CONFIGURATION_DESCRIPTOR)(info->ConfigDesc + 1),
- info->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
- )
- {
- USHORT wHubChar;
- AppendTextBuffer("Hub Power: %srn",
- HubInfo->HubIsBusPowered ?
- "Bus Power" : "Self Power");
- AppendTextBuffer("Number of Ports: %drn",
- HubInfo->HubDescriptor.bNumberOfPorts);
- wHubChar = HubInfo->HubDescriptor.wHubCharacteristics;
- switch (wHubChar & 0x0003)
- {
- case 0x0000:
- AppendTextBuffer("Power switching: Gangedrn");
- break;
- case 0x0001:
- AppendTextBuffer("Power switching: Individualrn");
- break;
- case 0x0002:
- case 0x0003:
- AppendTextBuffer("Power switching: Nonern");
- break;
- }
- switch (wHubChar & 0x0004)
- {
- case 0x0000:
- AppendTextBuffer("Compound device: Norn");
- break;
- case 0x0004:
- AppendTextBuffer("Compound device: Yesrn");
- break;
- }
- switch (wHubChar & 0x0018)
- {
- case 0x0000:
- AppendTextBuffer("Over-current Protection: Globalrn");
- break;
- case 0x0008:
- AppendTextBuffer("Over-current Protection: Individualrn");
- break;
- case 0x0010:
- case 0x0018:
- AppendTextBuffer("No Over-current Protection (Bus Power Only)rn");
- break;
- }
- AppendTextBuffer("rn");
- }
- //*****************************************************************************
- //
- // DisplayConnectionInfo()
- //
- // ConnectInfo - Info about the connection.
- //
- //*****************************************************************************
- VOID
- DisplayConnectionInfo (
- PUSB_NODE_CONNECTION_INFORMATION ConnectInfo,
- PSTRING_DESCRIPTOR_NODE StringDescs
- )
- {
- if (ConnectInfo->ConnectionStatus == NoDeviceConnected)
- {
- AppendTextBuffer("ConnectionStatus: NoDeviceConnectedrn");
- }
- else
- {
- PCHAR VendorString;
- AppendTextBuffer("Device Descriptor:rn");
- AppendTextBuffer("bcdUSB: 0x%04Xrn",
- ConnectInfo->DeviceDescriptor.bcdUSB);
- AppendTextBuffer("bDeviceClass: 0x%02Xrn",
- ConnectInfo->DeviceDescriptor.bDeviceClass);
- AppendTextBuffer("bDeviceSubClass: 0x%02Xrn",
- ConnectInfo->DeviceDescriptor.bDeviceSubClass);
- AppendTextBuffer("bDeviceProtocol: 0x%02Xrn",
- ConnectInfo->DeviceDescriptor.bDeviceProtocol);
- AppendTextBuffer("bMaxPacketSize0: 0x%02X (%d)rn",
- ConnectInfo->DeviceDescriptor.bMaxPacketSize0,
- ConnectInfo->DeviceDescriptor.bMaxPacketSize0);
- VendorString = GetVendorString(ConnectInfo->DeviceDescriptor.idVendor);
- if (VendorString != NULL)
- {
- AppendTextBuffer("idVendor: 0x%04X (%s)rn",
- ConnectInfo->DeviceDescriptor.idVendor,
- VendorString);
- }
- else
- {
- AppendTextBuffer("idVendor: 0x%04Xrn",
- ConnectInfo->DeviceDescriptor.idVendor);
- }
- AppendTextBuffer("idProduct: 0x%04Xrn",
- ConnectInfo->DeviceDescriptor.idProduct);
- AppendTextBuffer("bcdDevice: 0x%04Xrn",
- ConnectInfo->DeviceDescriptor.bcdDevice);
- AppendTextBuffer("iManufacturer: 0x%02Xrn",
- ConnectInfo->DeviceDescriptor.iManufacturer);
- if (ConnectInfo->DeviceDescriptor.iManufacturer)
- {
- DisplayStringDescriptor(ConnectInfo->DeviceDescriptor.iManufacturer,
- StringDescs);
- }
- AppendTextBuffer("iProduct: 0x%02Xrn",
- ConnectInfo->DeviceDescriptor.iProduct);
- if (ConnectInfo->DeviceDescriptor.iProduct)
- {
- DisplayStringDescriptor(ConnectInfo->DeviceDescriptor.iProduct,
- StringDescs);
- }
- AppendTextBuffer("iSerialNumber: 0x%02Xrn",
- ConnectInfo->DeviceDescriptor.iSerialNumber);
- if (ConnectInfo->DeviceDescriptor.iSerialNumber)
- {
- DisplayStringDescriptor(ConnectInfo->DeviceDescriptor.iSerialNumber,
- StringDescs);
- }
- AppendTextBuffer("bNumConfigurations: 0x%02Xrn",
- ConnectInfo->DeviceDescriptor.bNumConfigurations);
- AppendTextBuffer("rnConnectionStatus: %srn",
- ConnectionStatuses[ConnectInfo->ConnectionStatus]);
- AppendTextBuffer("Current Config Value: 0x%02Xrn",
- ConnectInfo->CurrentConfigurationValue);
- if (ConnectInfo->LowSpeed)
- {
- AppendTextBuffer("Device Bus Speed: Lowrn");
- }
- else
- {
- AppendTextBuffer("Device Bus Speed: Fullrn");
- }
- AppendTextBuffer("Device Address: 0x%02Xrn",
- ConnectInfo->DeviceAddress);
- AppendTextBuffer("Open Pipes: %2drn",
- ConnectInfo->NumberOfOpenPipes);
- if (ConnectInfo->NumberOfOpenPipes)
- {
- DisplayPipeInfo(ConnectInfo->NumberOfOpenPipes,
- ConnectInfo->PipeList);
- }
- }
- }
- //*****************************************************************************
- //
- // DisplayPipeInfo()
- //
- // NumPipes - Number of pipe for we info should be displayed.
- //
- // PipeInfo - Info about the pipes.
- //
- //*****************************************************************************
- VOID
- DisplayPipeInfo (
- ULONG NumPipes,
- USB_PIPE_INFO *PipeInfo
- )
- {
- ULONG i;
- for (i=0; i<NumPipes; i++)
- {
- DisplayEndpointDescriptor(&PipeInfo[i].EndpointDescriptor);
- }
- }
- //*****************************************************************************
- //
- // DisplayConfigDesc()
- //
- // ConfigDesc - The Configuration Descriptor, and associated Interface and
- // EndpointDescriptors
- //
- //*****************************************************************************
- VOID
- DisplayConfigDesc (
- PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc,
- PSTRING_DESCRIPTOR_NODE StringDescs
- )
- {
- PUCHAR descEnd;
- PUSB_COMMON_DESCRIPTOR commonDesc;
- UCHAR bInterfaceClass;
- UCHAR bInterfaceSubClass;
- BOOL displayUnknown;
- bInterfaceClass = 0;
- descEnd = (PUCHAR)ConfigDesc + ConfigDesc->wTotalLength;
- commonDesc = (PUSB_COMMON_DESCRIPTOR)ConfigDesc;
- while ((PUCHAR)commonDesc + sizeof(USB_COMMON_DESCRIPTOR) < descEnd &&
- (PUCHAR)commonDesc + commonDesc->bLength <= descEnd)
- {
- displayUnknown = FALSE;
- switch (commonDesc->bDescriptorType)
- {
- case USB_CONFIGURATION_DESCRIPTOR_TYPE:
- if (commonDesc->bLength != sizeof(USB_CONFIGURATION_DESCRIPTOR))
- {
- OOPS();
- displayUnknown = TRUE;
- break;
- }
- DisplayConfigurationDescriptor((PUSB_CONFIGURATION_DESCRIPTOR)commonDesc,
- StringDescs);
- break;
- case USB_INTERFACE_DESCRIPTOR_TYPE:
- if ((commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR)) &&
- (commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR2)))
- {
- OOPS();
- displayUnknown = TRUE;
- break;
- }
- bInterfaceClass = ((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->bInterfaceClass;
- bInterfaceSubClass = ((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->bInterfaceSubClass;
- DisplayInterfaceDescriptor((PUSB_INTERFACE_DESCRIPTOR)commonDesc,
- StringDescs);
- break;
- case USB_ENDPOINT_DESCRIPTOR_TYPE:
- if ((commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR)) &&
- (commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR2)))
- {
- OOPS();
- displayUnknown = TRUE;
- break;
- }
- DisplayEndpointDescriptor((PUSB_ENDPOINT_DESCRIPTOR)commonDesc);
- break;
- case USB_HID_DESCRIPTOR_TYPE:
- if (commonDesc->bLength < sizeof(USB_HID_DESCRIPTOR))
- {
- OOPS();
- displayUnknown = TRUE;
- break;
- }
- DisplayHidDescriptor((PUSB_HID_DESCRIPTOR)commonDesc);
- break;
- default:
- switch (bInterfaceClass)
- {
- case USB_DEVICE_CLASS_AUDIO:
- displayUnknown = !DisplayAudioDescriptor(
- (PUSB_AUDIO_COMMON_DESCRIPTOR)commonDesc,
- bInterfaceSubClass);
- break;
- default:
- displayUnknown = TRUE;
- break;
- }
- break;
- }
- if (displayUnknown)
- {
- DisplayUnknownDescriptor(commonDesc);
- }
- (PUCHAR)commonDesc += commonDesc->bLength;
- }
- }
- //*****************************************************************************
- //
- // DisplayConfigurationDescriptor()
- //
- //*****************************************************************************
- VOID
- DisplayConfigurationDescriptor (
- PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc,
- PSTRING_DESCRIPTOR_NODE StringDescs
- )
- {
- AppendTextBuffer("rnConfiguration Descriptor:rn");
- AppendTextBuffer("wTotalLength: 0x%04Xrn",
- ConfigDesc->wTotalLength);
- AppendTextBuffer("bNumInterfaces: 0x%02Xrn",
- ConfigDesc->bNumInterfaces);
- AppendTextBuffer("bConfigurationValue: 0x%02Xrn",
- ConfigDesc->bConfigurationValue);
- AppendTextBuffer("iConfiguration: 0x%02Xrn",
- ConfigDesc->iConfiguration);
- if (ConfigDesc->iConfiguration)
- {
- DisplayStringDescriptor(ConfigDesc->iConfiguration,
- StringDescs);
- }
- AppendTextBuffer("bmAttributes: 0x%02X (",
- ConfigDesc->bmAttributes);
- if (ConfigDesc->bmAttributes & 0x80)
- {
- AppendTextBuffer("Bus Powered ");
- }
- if (ConfigDesc->bmAttributes & 0x40)
- {
- AppendTextBuffer("Self Powered ");
- }
- if (ConfigDesc->bmAttributes & 0x20)
- {
- AppendTextBuffer("Remote Wakeup");
- }
- AppendTextBuffer(")rn");
- AppendTextBuffer("MaxPower: 0x%02X (%d Ma)rn",
- ConfigDesc->MaxPower,
- ConfigDesc->MaxPower * 2);
- }
- //*****************************************************************************
- //
- // DisplayInterfaceDescriptor()
- //
- //*****************************************************************************
- VOID
- DisplayInterfaceDescriptor (
- PUSB_INTERFACE_DESCRIPTOR InterfaceDesc,
- PSTRING_DESCRIPTOR_NODE StringDescs
- )
- {
- PCHAR pStr;
- AppendTextBuffer("rnInterface Descriptor:rn");
- AppendTextBuffer("bInterfaceNumber: 0x%02Xrn",
- InterfaceDesc->bInterfaceNumber);
- AppendTextBuffer("bAlternateSetting: 0x%02Xrn",
- InterfaceDesc->bAlternateSetting);
- AppendTextBuffer("bNumEndpoints: 0x%02Xrn",
- InterfaceDesc->bNumEndpoints);
- AppendTextBuffer("bInterfaceClass: 0x%02X",
- InterfaceDesc->bInterfaceClass);
- pStr = "rn";
- switch (InterfaceDesc->bInterfaceClass)
- {
- case USB_DEVICE_CLASS_AUDIO:
- pStr = " (Audio)rn";
- break;
- case USB_DEVICE_CLASS_HUMAN_INTERFACE:
- pStr = " (HID)rn";
- break;
- case USB_DEVICE_CLASS_HUB:
- pStr = " (Hub)rn";
- break;
- default:
- break;
- }
- AppendTextBuffer(pStr);
- AppendTextBuffer("bInterfaceSubClass: 0x%02X",
- InterfaceDesc->bInterfaceSubClass);
- pStr = "rn";
- switch (InterfaceDesc->bInterfaceClass)
- {
- case USB_DEVICE_CLASS_AUDIO:
- switch (InterfaceDesc->bInterfaceSubClass)
- {
- case USB_AUDIO_SUBCLASS_AUDIOCONTROL:
- pStr = " (Audio Control)rn";
- break;
- case USB_AUDIO_SUBCLASS_AUDIOSTREAMING:
- pStr = " (Audio Streaming)rn";
- break;
- case USB_AUDIO_SUBCLASS_MIDISTREAMING:
- pStr = " (MIDI Streaming)rn";
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- AppendTextBuffer(pStr);
- AppendTextBuffer("bInterfaceProtocol: 0x%02Xrn",
- InterfaceDesc->bInterfaceProtocol);
- AppendTextBuffer("iInterface: 0x%02Xrn",
- InterfaceDesc->iInterface);
- if (InterfaceDesc->iInterface)
- {
- DisplayStringDescriptor(InterfaceDesc->iInterface,
- StringDescs);
- }
- if (InterfaceDesc->bLength == sizeof(USB_INTERFACE_DESCRIPTOR2))
- {
- PUSB_INTERFACE_DESCRIPTOR2 interfaceDesc2;
- interfaceDesc2 = (PUSB_INTERFACE_DESCRIPTOR2)InterfaceDesc;
- AppendTextBuffer("wNumClasses: 0x%04Xrn",
- interfaceDesc2->wNumClasses);
- }
- }
- //*****************************************************************************
- //
- // DisplayEndpointDescriptor()
- //
- //*****************************************************************************
- VOID
- DisplayEndpointDescriptor (
- PUSB_ENDPOINT_DESCRIPTOR EndpointDesc
- )
- {
- AppendTextBuffer("rnEndpoint Descriptor:rn");
- AppendTextBuffer("bEndpointAddress: 0x%02Xrn",
- EndpointDesc->bEndpointAddress);
- switch (EndpointDesc->bmAttributes & 0x03)
- {
- case 0x00:
- AppendTextBuffer("Transfer Type: Controlrn");
- break;
- case 0x01:
- AppendTextBuffer("Transfer Type: Isochronousrn");
- break;
- case 0x02:
- AppendTextBuffer("Transfer Type: Bulkrn");
- break;
- case 0x03:
- AppendTextBuffer("Transfer Type: Interruptrn");
- break;
- }
- AppendTextBuffer("wMaxPacketSize: 0x%04X (%d)rn",
- EndpointDesc->wMaxPacketSize,
- EndpointDesc->wMaxPacketSize);
- if (EndpointDesc->bLength == sizeof(USB_ENDPOINT_DESCRIPTOR))
- {
- AppendTextBuffer("bInterval: 0x%02Xrn",
- EndpointDesc->bInterval);
- }
- else
- {
- PUSB_ENDPOINT_DESCRIPTOR2 endpointDesc2;
- endpointDesc2 = (PUSB_ENDPOINT_DESCRIPTOR2)EndpointDesc;
- AppendTextBuffer("wInterval: 0x%04Xrn",
- endpointDesc2->wInterval);
- AppendTextBuffer("bSyncAddress: 0x%02Xrn",
- endpointDesc2->bSyncAddress);
- }
- }
- //*****************************************************************************
- //
- // DisplayHidDescriptor()
- //
- //*****************************************************************************
- VOID
- DisplayHidDescriptor (
- PUSB_HID_DESCRIPTOR HidDesc
- )
- {
- UCHAR i;
- AppendTextBuffer("rnHID Descriptor:rn");
- AppendTextBuffer("bcdHID: 0x%04Xrn",
- HidDesc->bcdHID);
- AppendTextBuffer("bCountryCode: 0x%02Xrn",
- HidDesc->bCountryCode);
- AppendTextBuffer("bNumDescriptors: 0x%02Xrn",
- HidDesc->bNumDescriptors);
- for (i=0; i<HidDesc->bNumDescriptors; i++)
- {
- AppendTextBuffer("bDescriptorType: 0x%02Xrn",
- HidDesc->OptionalDescriptors[i].bDescriptorType);
- AppendTextBuffer("wDescriptorLength: 0x%04Xrn",
- HidDesc->OptionalDescriptors[i].wDescriptorLength);
- }
- }
- #if 0
- //*****************************************************************************
- //
- // DisplayPowerDescriptor()
- //
- //*****************************************************************************
- PCHAR PowerUnits[] =
- {
- "0.001 mW",
- "0.01 mW",
- "0.1 mW",
- "1 mW",
- "10 mW",
- "100 mW",
- "1 W"
- };
- VOID
- DisplayPowerDescriptor (
- PUSB_POWER_DESCRIPTOR PowerDesc
- )
- {
- UCHAR i;
- AppendTextBuffer("rnPower Descriptor:rn");
- AppendTextBuffer("bCapabilitiesFlags: 0x%02X (",
- PowerDesc->bCapabilitiesFlags);
- if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D2_WAKEUP)
- {
- AppendTextBuffer("WakeD2 ");
- }
- if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D1_WAKEUP)
- {
- AppendTextBuffer("WakeD1 ");
- }
- if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D3_COMMAND)
- {
- AppendTextBuffer("D3 ");
- }
- if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D2_COMMAND)
- {
- AppendTextBuffer("D2 ");
- }
- if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D1_COMMAND)
- {
- AppendTextBuffer("D1 ");
- }
- if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D0_COMMAND)
- {
- AppendTextBuffer("D0 ");
- }
- AppendTextBuffer(")rn");
- AppendTextBuffer("EventNotification: 0x%04Xrn",
- PowerDesc->EventNotification);
- AppendTextBuffer("D1LatencyTime: 0x%04Xrn",
- PowerDesc->D1LatencyTime);
- AppendTextBuffer("D2LatencyTime: 0x%04Xrn",
- PowerDesc->D2LatencyTime);
- AppendTextBuffer("D3LatencyTime: 0x%04Xrn",
- PowerDesc->D3LatencyTime);
- AppendTextBuffer("PowerUnit: 0x%02X (%s)rn",
- PowerDesc->PowerUnit,
- PowerDesc->PowerUnit < sizeof(PowerUnits)/sizeof(PowerUnits[0])
- ? PowerUnits[PowerDesc->PowerUnit]
- : "?");
- AppendTextBuffer("D0PowerConsumption: 0x%04X (%5d)rn",
- PowerDesc->D0PowerConsumption,
- PowerDesc->D0PowerConsumption);
- AppendTextBuffer("D1PowerConsumption: 0x%04X (%5d)rn",
- PowerDesc->D1PowerConsumption,
- PowerDesc->D1PowerConsumption);
- AppendTextBuffer("D2PowerConsumption: 0x%04X (%5d)rn",
- PowerDesc->D2PowerConsumption,
- PowerDesc->D2PowerConsumption);
- }
- #endif
- //*****************************************************************************
- //
- // DisplayStringDescriptor()
- //
- //*****************************************************************************
- #if 1
- VOID
- DisplayStringDescriptor (
- UCHAR Index,
- PSTRING_DESCRIPTOR_NODE StringDescs
- )
- {
- ULONG nBytes;
- while (StringDescs)
- {
- if (StringDescs->DescriptorIndex == Index)
- {
- AppendTextBuffer("0x%04X: "",
- StringDescs->LanguageID);
- nBytes = WideCharToMultiByte(
- CP_ACP, // CodePage
- 0, // CodePage
- StringDescs->StringDescriptor->bString,
- (StringDescs->StringDescriptor->bLength - 2) / 2,
- TextBuffer + TextBufferPos,
- TextBufferLen - TextBufferPos,
- NULL, // lpDefaultChar
- NULL); // pUsedDefaultChar
- TextBufferPos += nBytes;
- AppendTextBuffer(""rn");
- }
- StringDescs = StringDescs->Next;
- }
- }
- #else
- VOID
- DisplayStringDescriptor (
- UCHAR Index,
- PSTRING_DESCRIPTOR_NODE StringDescs
- )
- {
- UCHAR i;
- while (StringDescs)
- {
- if (StringDescs->DescriptorIndex == Index)
- {
- AppendTextBuffer("String Descriptor:rn");
- AppendTextBuffer("LanguageID: 0x%04Xrn",
- StringDescs->LanguageID);
- AppendTextBuffer("bLength: 0x%02Xrn",
- StringDescs->StringDescriptor->bLength);
- for (i = 0; i < StringDescs->StringDescriptor->bLength-2; i++)
- {
- AppendTextBuffer("%02X ",
- ((PUCHAR)StringDescs->StringDescriptor->bString)[i]);
- if (i % 16 == 15)
- {
- AppendTextBuffer("rn");
- }
- }
- if (i % 16 != 0)
- {
- AppendTextBuffer("rn");
- }
- }
- StringDescs = StringDescs->Next;
- }
- }
- #endif
- //*****************************************************************************
- //
- // DisplayUnknownDescriptor()
- //
- //*****************************************************************************
- VOID
- DisplayUnknownDescriptor (
- PUSB_COMMON_DESCRIPTOR CommonDesc
- )
- {
- UCHAR i;
- AppendTextBuffer("rnUnknown Descriptor:rn");
- AppendTextBuffer("bDescriptorType: 0x%02Xrn",
- CommonDesc->bDescriptorType);
- AppendTextBuffer("bLength: 0x%02Xrn",
- CommonDesc->bLength);
- for (i = 0; i < CommonDesc->bLength; i++)
- {
- AppendTextBuffer("%02X ",
- ((PUCHAR)CommonDesc)[i]);
- if (i % 16 == 15)
- {
- AppendTextBuffer("rn");
- }
- }
- if (i % 16 != 0)
- {
- AppendTextBuffer("rn");
- }
- }
- //*****************************************************************************
- //
- // GetVendorString()
- //
- // idVendor - USB Vendor ID
- //
- // Return Value - Vendor name string associated with idVendor, or NULL if
- // no vendor name string is found which is associated with idVendor.
- //
- //*****************************************************************************
- PCHAR
- GetVendorString (
- USHORT idVendor
- )
- {
- PUSBVENDORID vendorID;
- if (idVendor != 0x0000)
- {
- vendorID = USBVendorIDs;
- while (vendorID->usVendorID != 0x0000)
- {
- if (vendorID->usVendorID == idVendor)
- {
- return (vendorID->szVendor);
- }
- vendorID++;
- }
- }
- return NULL;
- }