display.c
上传用户:gzccxsp
上传日期:2015-07-14
资源大小:182k
文件大小:32k
源码类别:

MacOS编程

开发平台:

Visual C++

  1. /*++
  2. Copyright (c) 1997-1998 Microsoft Corporation
  3. Module Name:
  4. DISPLAY.C
  5. Abstract:
  6. This source file contains the routines which update the edit control
  7. to display information about the selected USB device.
  8. Environment:
  9. user mode
  10. Revision History:
  11. 04-25-97 : created
  12. --*/
  13. //*****************************************************************************
  14. // I N C L U D E S
  15. //*****************************************************************************
  16. #include <windows.h>
  17. #include <basetyps.h>
  18. #include "vndrlist.h"
  19. #include "usbview.h"
  20. #include "usb100.h"
  21. //*****************************************************************************
  22. // D E F I N E S
  23. //*****************************************************************************
  24. #define BUFFERALLOCINCREMENT        8192
  25. #define BUFFERMINFREESPACE          1024
  26. //*****************************************************************************
  27. // T Y P E D E F S
  28. //*****************************************************************************
  29. //*****************************************************************************
  30. // G L O B A L S    P R I V A T E    T O    T H I S    F I L E
  31. //*****************************************************************************
  32. // Workspace for text info which is used to update the edit control
  33. //
  34. CHAR *TextBuffer = NULL;
  35. int   TextBufferLen = 0;
  36. int   TextBufferPos = 0;
  37. //*****************************************************************************
  38. // L O C A L    F U N C T I O N    P R O T O T Y P E S
  39. //*****************************************************************************
  40. VOID
  41. DisplayHubInfo (
  42.     PUSB_HUB_INFORMATION HubInfo
  43. );
  44. VOID
  45. DisplayConnectionInfo (
  46.     PUSB_NODE_CONNECTION_INFORMATION    ConnectInfo,
  47.     PSTRING_DESCRIPTOR_NODE             StringDescs
  48. );
  49. VOID
  50. DisplayPipeInfo (
  51.     ULONG           NumPipes,
  52.     USB_PIPE_INFO  *PipeInfo
  53. );
  54. VOID
  55. DisplayConfigDesc (
  56.     PUSB_CONFIGURATION_DESCRIPTOR   ConfigDesc,
  57.     PSTRING_DESCRIPTOR_NODE         StringDescs
  58. );
  59. VOID
  60. DisplayConfigurationDescriptor (
  61.     PUSB_CONFIGURATION_DESCRIPTOR   ConfigDesc,
  62.     PSTRING_DESCRIPTOR_NODE         StringDescs
  63. );
  64. VOID
  65. DisplayInterfaceDescriptor (
  66.     PUSB_INTERFACE_DESCRIPTOR   InterfaceDesc,
  67.     PSTRING_DESCRIPTOR_NODE     StringDescs
  68. );
  69. VOID
  70. DisplayEndpointDescriptor (
  71.     PUSB_ENDPOINT_DESCRIPTOR    EndpointDesc
  72. );
  73. VOID
  74. DisplayHidDescriptor (
  75.     PUSB_HID_DESCRIPTOR         HidDesc
  76. );
  77. VOID
  78. DisplayStringDescriptor (
  79.     UCHAR                       Index,
  80.     PSTRING_DESCRIPTOR_NODE     StringDescs
  81. );
  82. VOID
  83. DisplayUnknownDescriptor (
  84.     PUSB_COMMON_DESCRIPTOR      CommonDesc
  85. );
  86. PCHAR
  87. GetVendorString (
  88.     USHORT     idVendor
  89. );
  90. //*****************************************************************************
  91. // L O C A L    F U N C T I O N S
  92. //*****************************************************************************
  93. //*****************************************************************************
  94. //
  95. // CreateTextBuffer()
  96. //
  97. //*****************************************************************************
  98. BOOL
  99. CreateTextBuffer (
  100. )
  101. {
  102.     // Allocate the buffer
  103.     //
  104.     TextBuffer = ALLOC(BUFFERALLOCINCREMENT);
  105.     if (TextBuffer == NULL)
  106.     {
  107.         OOPS();
  108.         return FALSE;
  109.     }
  110.     TextBufferLen = BUFFERALLOCINCREMENT;
  111.     // Reset the buffer position and terminate the buffer
  112.     //
  113.     *TextBuffer = 0;
  114.     TextBufferPos = 0;
  115.     return TRUE;
  116. }
  117. //*****************************************************************************
  118. //
  119. // DestroyTextBuffer()
  120. //
  121. //*****************************************************************************
  122. VOID
  123. DestroyTextBuffer (
  124. )
  125. {
  126.     if (TextBuffer != NULL)
  127.     {
  128.         FREE(TextBuffer);
  129.         TextBuffer = NULL;
  130.     }
  131. }
  132. //*****************************************************************************
  133. //
  134. // ResetTextBuffer()
  135. //
  136. //*****************************************************************************
  137. BOOL
  138. ResetTextBuffer (
  139. )
  140. {
  141.     // Fail if the text buffer has not been allocated
  142.     //
  143.     if (TextBuffer == NULL)
  144.     {
  145.         OOPS();
  146.         return FALSE;
  147.     }
  148.     // Reset the buffer position and terminate the buffer
  149.     //
  150.     *TextBuffer = 0;
  151.     TextBufferPos = 0;
  152.     return TRUE;
  153. }
  154. //*****************************************************************************
  155. //
  156. // AppendTextBuffer()
  157. //
  158. //*****************************************************************************
  159. VOID __cdecl
  160. AppendTextBuffer (
  161.     LPCTSTR lpFormat,
  162.     ...
  163. )
  164. {
  165.     va_list arglist;
  166.     va_start(arglist, lpFormat);
  167.     // Make sure we have a healthy amount of space free in the buffer,
  168.     // reallocating the buffer if necessary.
  169.     //
  170.     if (TextBufferLen - TextBufferPos < BUFFERMINFREESPACE)
  171.     {
  172.         CHAR *TextBufferTmp;
  173.         TextBufferTmp = REALLOC(TextBuffer, TextBufferLen+BUFFERALLOCINCREMENT);
  174.         if (TextBufferTmp != NULL)
  175.         {
  176.             TextBuffer = TextBufferTmp;
  177.             TextBufferLen += BUFFERALLOCINCREMENT;
  178.         }
  179.         else
  180.         {
  181.             // If GlobalReAlloc fails, the original memory is not freed,
  182.             // and the original handle and pointer are still valid.
  183.             //
  184.             OOPS();
  185.             return;
  186.         }
  187.     }
  188.     // Add the text to the end of the buffer, updating the buffer position.
  189.     //
  190.     TextBufferPos += wvsprintf(TextBuffer + TextBufferPos,
  191.                                lpFormat,
  192.                                arglist);
  193. }
  194. //*****************************************************************************
  195. //
  196. // UpdateEditControl()
  197. //
  198. // hTreeItem - Handle of selected TreeView item for which information should
  199. // be displayed in the edit control.
  200. //
  201. //*****************************************************************************
  202. VOID
  203. UpdateEditControl (
  204.     HWND      hEditWnd,
  205.     HWND      hTreeWnd,
  206.     HTREEITEM hTreeItem
  207. )
  208. {
  209.     TV_ITEM         tvi;
  210.     PUSBDEVICEINFO  info;
  211.     // Start with an empty text buffer.
  212.     //
  213.     if (!ResetTextBuffer())
  214.     {
  215.         return;
  216.     }
  217.     //
  218.     // Get the name of the TreeView item, along with the a pointer to the
  219.     // info we stored about the item in the item's lParam.
  220.     //
  221.     tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM;
  222.     tvi.hItem = hTreeItem;
  223.     tvi.pszText = (LPSTR)TextBuffer;
  224.     tvi.cchTextMax = TextBufferLen-2;  // leave space for "rn'
  225.     TreeView_GetItem(hTreeWnd,
  226.                      &tvi);
  227.     info = (PUSBDEVICEINFO)tvi.lParam;
  228.     //
  229.     // If we didn't store any info for the item, just display the item's
  230.     // name, else display the info we stored for the item.
  231.     //
  232.     if (info != NULL)
  233.     {
  234.         if (info->ConnectionInfo == NULL)
  235.         {
  236.             // Must be Root HUB, external devices have Connection Info
  237.             //
  238.             AppendTextBuffer("Root Hub: %srn",
  239.                              info->HubName);
  240.             DisplayHubInfo(&info->HubInfo->u.HubInformation);
  241.         }
  242.         else
  243.         {
  244.             if (info->HubInfo != NULL)
  245.             {
  246.                 // Must be external HUB external
  247.                 //
  248.                 AppendTextBuffer("External Hub: %srn",
  249.                                  info->HubName);
  250.                 DisplayHubInfo(&info->HubInfo->u.HubInformation);
  251.             }
  252.             else
  253.             {
  254.                 // Must be external non-HUB device.  Nothing special to
  255.                 // display here that isn't displayed in connection info
  256.                 // below.
  257.             }
  258.             // Display info common to any external device
  259.             //
  260.             DisplayConnectionInfo(info->ConnectionInfo, /////////////////////////
  261.                                   info->StringDescs);
  262.             if (info->ConfigDesc)
  263.             {
  264.                 DisplayConfigDesc((PUSB_CONFIGURATION_DESCRIPTOR)(info->ConfigDesc + 1),
  265.                                   info->StringDescs);
  266.             }
  267.         }
  268.     }
  269.     // All done formatting text buffer with info, now update the edit
  270.     // control with the contents of the text buffer
  271.     //
  272.     SetWindowText(hEditWnd, TextBuffer);
  273. }
  274. //*****************************************************************************
  275. //
  276. // DisplayHubInfo()
  277. //
  278. // HubInfo - Info about the hub.
  279. //
  280. //*****************************************************************************
  281. VOID
  282. DisplayHubInfo (
  283.     PUSB_HUB_INFORMATION    HubInfo
  284. )
  285. {
  286.     USHORT wHubChar;
  287.     AppendTextBuffer("Hub Power:               %srn",
  288.                      HubInfo->HubIsBusPowered ?
  289.                      "Bus Power" : "Self Power");
  290.     AppendTextBuffer("Number of Ports:         %drn",
  291.                      HubInfo->HubDescriptor.bNumberOfPorts);
  292.     wHubChar = HubInfo->HubDescriptor.wHubCharacteristics;
  293.     switch (wHubChar & 0x0003)
  294.     {
  295.         case 0x0000:
  296.             AppendTextBuffer("Power switching:         Gangedrn");
  297.             break;
  298.         case 0x0001:
  299.             AppendTextBuffer("Power switching:         Individualrn");
  300.             break;
  301.         case 0x0002:
  302.         case 0x0003:
  303.             AppendTextBuffer("Power switching:         Nonern");
  304.             break;
  305.     }
  306.     switch (wHubChar & 0x0004)
  307.     {
  308.         case 0x0000:
  309.             AppendTextBuffer("Compound device:         Norn");
  310.             break;
  311.         case 0x0004:
  312.             AppendTextBuffer("Compound device:         Yesrn");
  313.             break;
  314.     }
  315.     switch (wHubChar & 0x0018)
  316.     {
  317.         case 0x0000:
  318.             AppendTextBuffer("Over-current Protection: Globalrn");
  319.             break;
  320.         case 0x0008:
  321.             AppendTextBuffer("Over-current Protection: Individualrn");
  322.             break;
  323.         case 0x0010:
  324.         case 0x0018:
  325.             AppendTextBuffer("No Over-current Protection (Bus Power Only)rn");
  326.             break;
  327.     }
  328.     AppendTextBuffer("rn");
  329. }
  330. //*****************************************************************************
  331. //
  332. // DisplayConnectionInfo()
  333. //
  334. // ConnectInfo - Info about the connection.
  335. //
  336. //*****************************************************************************
  337. VOID
  338. DisplayConnectionInfo (
  339.     PUSB_NODE_CONNECTION_INFORMATION    ConnectInfo,
  340.     PSTRING_DESCRIPTOR_NODE             StringDescs
  341. )
  342. {
  343.     if (ConnectInfo->ConnectionStatus == NoDeviceConnected)
  344.     {
  345.         AppendTextBuffer("ConnectionStatus: NoDeviceConnectedrn");
  346.     }
  347.     else
  348.     {
  349.         PCHAR VendorString;
  350.         AppendTextBuffer("Device Descriptor:rn");
  351.         AppendTextBuffer("bcdUSB:             0x%04Xrn",
  352.                          ConnectInfo->DeviceDescriptor.bcdUSB);
  353.         AppendTextBuffer("bDeviceClass:         0x%02Xrn",
  354.                          ConnectInfo->DeviceDescriptor.bDeviceClass);
  355.         AppendTextBuffer("bDeviceSubClass:      0x%02Xrn",
  356.                          ConnectInfo->DeviceDescriptor.bDeviceSubClass);
  357.         AppendTextBuffer("bDeviceProtocol:      0x%02Xrn",
  358.                          ConnectInfo->DeviceDescriptor.bDeviceProtocol);
  359.         AppendTextBuffer("bMaxPacketSize0:      0x%02X (%d)rn",
  360.                          ConnectInfo->DeviceDescriptor.bMaxPacketSize0,
  361.                          ConnectInfo->DeviceDescriptor.bMaxPacketSize0);
  362.         VendorString = GetVendorString(ConnectInfo->DeviceDescriptor.idVendor);
  363.         if (VendorString != NULL)
  364.         {
  365.             AppendTextBuffer("idVendor:           0x%04X (%s)rn",
  366.                              ConnectInfo->DeviceDescriptor.idVendor,
  367.                              VendorString);
  368.         }
  369.         else
  370.         {
  371.             AppendTextBuffer("idVendor:           0x%04Xrn",
  372.                              ConnectInfo->DeviceDescriptor.idVendor);
  373.         }
  374.         AppendTextBuffer("idProduct:          0x%04Xrn",
  375.                          ConnectInfo->DeviceDescriptor.idProduct);
  376.         AppendTextBuffer("bcdDevice:          0x%04Xrn",
  377.                          ConnectInfo->DeviceDescriptor.bcdDevice);
  378.         AppendTextBuffer("iManufacturer:        0x%02Xrn",
  379.                          ConnectInfo->DeviceDescriptor.iManufacturer);
  380.         if (ConnectInfo->DeviceDescriptor.iManufacturer)
  381.         {
  382.             DisplayStringDescriptor(ConnectInfo->DeviceDescriptor.iManufacturer,
  383.                                     StringDescs);
  384.         }
  385.         AppendTextBuffer("iProduct:             0x%02Xrn",
  386.                          ConnectInfo->DeviceDescriptor.iProduct);
  387.         if (ConnectInfo->DeviceDescriptor.iProduct)
  388.         {
  389.             DisplayStringDescriptor(ConnectInfo->DeviceDescriptor.iProduct,
  390.                                     StringDescs);
  391.         }
  392.         AppendTextBuffer("iSerialNumber:        0x%02Xrn",
  393.                          ConnectInfo->DeviceDescriptor.iSerialNumber);
  394.         if (ConnectInfo->DeviceDescriptor.iSerialNumber)
  395.         {
  396.             DisplayStringDescriptor(ConnectInfo->DeviceDescriptor.iSerialNumber,
  397.                                     StringDescs);
  398.         }
  399.         AppendTextBuffer("bNumConfigurations:   0x%02Xrn",
  400.                          ConnectInfo->DeviceDescriptor.bNumConfigurations);
  401.         AppendTextBuffer("rnConnectionStatus: %srn",
  402.                          ConnectionStatuses[ConnectInfo->ConnectionStatus]);
  403.         AppendTextBuffer("Current Config Value: 0x%02Xrn",
  404.                          ConnectInfo->CurrentConfigurationValue);
  405.         if (ConnectInfo->LowSpeed)
  406.         {
  407.             AppendTextBuffer("Device Bus Speed:      Lowrn");
  408.         }
  409.         else
  410.         {
  411.             AppendTextBuffer("Device Bus Speed:     Fullrn");
  412.         }
  413.         AppendTextBuffer("Device Address:       0x%02Xrn",
  414.                          ConnectInfo->DeviceAddress);
  415.         AppendTextBuffer("Open Pipes:             %2drn",
  416.                          ConnectInfo->NumberOfOpenPipes);
  417.         if (ConnectInfo->NumberOfOpenPipes)
  418.         {
  419.             DisplayPipeInfo(ConnectInfo->NumberOfOpenPipes,
  420.                             ConnectInfo->PipeList);
  421.         }
  422.     }
  423. }
  424. //*****************************************************************************
  425. //
  426. // DisplayPipeInfo()
  427. //
  428. // NumPipes - Number of pipe for we info should be displayed.
  429. //
  430. // PipeInfo - Info about the pipes.
  431. //
  432. //*****************************************************************************
  433. VOID
  434. DisplayPipeInfo (
  435.     ULONG           NumPipes,
  436.     USB_PIPE_INFO  *PipeInfo
  437. )
  438. {
  439.     ULONG i;
  440.     for (i=0; i<NumPipes; i++)
  441.     {
  442.         DisplayEndpointDescriptor(&PipeInfo[i].EndpointDescriptor);
  443.     }
  444. }
  445. //*****************************************************************************
  446. //
  447. // DisplayConfigDesc()
  448. //
  449. // ConfigDesc - The Configuration Descriptor, and associated Interface and
  450. // EndpointDescriptors
  451. //
  452. //*****************************************************************************
  453. VOID
  454. DisplayConfigDesc (
  455.     PUSB_CONFIGURATION_DESCRIPTOR   ConfigDesc,
  456.     PSTRING_DESCRIPTOR_NODE         StringDescs
  457. )
  458. {
  459.     PUCHAR                  descEnd;
  460.     PUSB_COMMON_DESCRIPTOR  commonDesc;
  461.     UCHAR                   bInterfaceClass;
  462.     UCHAR                   bInterfaceSubClass;
  463.     BOOL                    displayUnknown;
  464.     bInterfaceClass = 0;
  465.     descEnd = (PUCHAR)ConfigDesc + ConfigDesc->wTotalLength;
  466.     commonDesc = (PUSB_COMMON_DESCRIPTOR)ConfigDesc;
  467.     while ((PUCHAR)commonDesc + sizeof(USB_COMMON_DESCRIPTOR) < descEnd &&
  468.            (PUCHAR)commonDesc + commonDesc->bLength <= descEnd)
  469.     {
  470.         displayUnknown = FALSE;
  471.         switch (commonDesc->bDescriptorType)
  472.         {
  473.             case USB_CONFIGURATION_DESCRIPTOR_TYPE:
  474.                 if (commonDesc->bLength != sizeof(USB_CONFIGURATION_DESCRIPTOR))
  475.                 {
  476.                     OOPS();
  477.                     displayUnknown = TRUE;
  478.                     break;
  479.                 }
  480.                 DisplayConfigurationDescriptor((PUSB_CONFIGURATION_DESCRIPTOR)commonDesc,
  481.                                                StringDescs);
  482.                 break;
  483.             case USB_INTERFACE_DESCRIPTOR_TYPE:
  484.                 if ((commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR)) &&
  485.                     (commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR2)))
  486.                 {
  487.                     OOPS();
  488.                     displayUnknown = TRUE;
  489.                     break;
  490.                 }
  491.                 bInterfaceClass = ((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->bInterfaceClass;
  492.                 bInterfaceSubClass = ((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->bInterfaceSubClass;
  493.                 DisplayInterfaceDescriptor((PUSB_INTERFACE_DESCRIPTOR)commonDesc,
  494.                                            StringDescs);
  495.                 break;
  496.             case USB_ENDPOINT_DESCRIPTOR_TYPE:
  497.                 if ((commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR)) &&
  498.                     (commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR2)))
  499.                 {
  500.                     OOPS();
  501.                     displayUnknown = TRUE;
  502.                     break;
  503.                 }
  504.                 DisplayEndpointDescriptor((PUSB_ENDPOINT_DESCRIPTOR)commonDesc);
  505.                 break;
  506.             case USB_HID_DESCRIPTOR_TYPE:
  507.                 if (commonDesc->bLength < sizeof(USB_HID_DESCRIPTOR))
  508.                 {
  509.                     OOPS();
  510.                     displayUnknown = TRUE;
  511.                     break;
  512.                 }
  513.                 DisplayHidDescriptor((PUSB_HID_DESCRIPTOR)commonDesc);
  514.                 break;
  515.             default:
  516.                 switch (bInterfaceClass)
  517.                 {
  518.                     case USB_DEVICE_CLASS_AUDIO:
  519.                         displayUnknown = !DisplayAudioDescriptor(
  520.                                               (PUSB_AUDIO_COMMON_DESCRIPTOR)commonDesc,
  521.                                               bInterfaceSubClass);
  522.                         break;
  523.                     default:
  524.                         displayUnknown = TRUE;
  525.                         break;
  526.                 }
  527.                 break;
  528.         }
  529.         if (displayUnknown)
  530.         {
  531.             DisplayUnknownDescriptor(commonDesc);
  532.         }
  533.         (PUCHAR)commonDesc += commonDesc->bLength;
  534.     }
  535. }
  536. //*****************************************************************************
  537. //
  538. // DisplayConfigurationDescriptor()
  539. //
  540. //*****************************************************************************
  541. VOID
  542. DisplayConfigurationDescriptor (
  543.     PUSB_CONFIGURATION_DESCRIPTOR   ConfigDesc,
  544.     PSTRING_DESCRIPTOR_NODE         StringDescs
  545. )
  546. {
  547.     AppendTextBuffer("rnConfiguration Descriptor:rn");
  548.     AppendTextBuffer("wTotalLength:       0x%04Xrn",
  549.                      ConfigDesc->wTotalLength);
  550.     AppendTextBuffer("bNumInterfaces:       0x%02Xrn",
  551.                      ConfigDesc->bNumInterfaces);
  552.     AppendTextBuffer("bConfigurationValue:  0x%02Xrn",
  553.                      ConfigDesc->bConfigurationValue);
  554.     AppendTextBuffer("iConfiguration:       0x%02Xrn",
  555.                      ConfigDesc->iConfiguration);
  556.     if (ConfigDesc->iConfiguration)
  557.     {
  558.         DisplayStringDescriptor(ConfigDesc->iConfiguration,
  559.                                 StringDescs);
  560.     }
  561.     AppendTextBuffer("bmAttributes:         0x%02X (",
  562.                      ConfigDesc->bmAttributes);
  563.     if (ConfigDesc->bmAttributes & 0x80)
  564.     {
  565.         AppendTextBuffer("Bus Powered ");
  566.     }
  567.     if (ConfigDesc->bmAttributes & 0x40)
  568.     {
  569.         AppendTextBuffer("Self Powered ");
  570.     }
  571.     if (ConfigDesc->bmAttributes & 0x20)
  572.     {
  573.         AppendTextBuffer("Remote Wakeup");
  574.     }
  575.     AppendTextBuffer(")rn");
  576.     AppendTextBuffer("MaxPower:             0x%02X (%d Ma)rn",
  577.                      ConfigDesc->MaxPower,
  578.                      ConfigDesc->MaxPower * 2);
  579. }
  580. //*****************************************************************************
  581. //
  582. // DisplayInterfaceDescriptor()
  583. //
  584. //*****************************************************************************
  585. VOID
  586. DisplayInterfaceDescriptor (
  587.     PUSB_INTERFACE_DESCRIPTOR   InterfaceDesc,
  588.     PSTRING_DESCRIPTOR_NODE     StringDescs
  589. )
  590. {
  591.     PCHAR pStr;
  592.     AppendTextBuffer("rnInterface Descriptor:rn");
  593.     AppendTextBuffer("bInterfaceNumber:     0x%02Xrn",
  594.                      InterfaceDesc->bInterfaceNumber);
  595.     AppendTextBuffer("bAlternateSetting:    0x%02Xrn",
  596.                      InterfaceDesc->bAlternateSetting);
  597.     AppendTextBuffer("bNumEndpoints:        0x%02Xrn",
  598.                      InterfaceDesc->bNumEndpoints);
  599.     AppendTextBuffer("bInterfaceClass:      0x%02X",
  600.                      InterfaceDesc->bInterfaceClass);
  601.     pStr = "rn";
  602.     switch (InterfaceDesc->bInterfaceClass)
  603.     {
  604.         case USB_DEVICE_CLASS_AUDIO:
  605.             pStr = " (Audio)rn";
  606.             break;
  607.         case USB_DEVICE_CLASS_HUMAN_INTERFACE:
  608.             pStr = " (HID)rn";
  609.             break;
  610.         case USB_DEVICE_CLASS_HUB:
  611.             pStr = " (Hub)rn";
  612.             break;
  613.         default:
  614.             break;
  615.     }
  616.     AppendTextBuffer(pStr);
  617.     AppendTextBuffer("bInterfaceSubClass:   0x%02X",
  618.                      InterfaceDesc->bInterfaceSubClass);
  619.     pStr = "rn";
  620.     switch (InterfaceDesc->bInterfaceClass)
  621.     {
  622.         case USB_DEVICE_CLASS_AUDIO:
  623.             switch (InterfaceDesc->bInterfaceSubClass)
  624.             {
  625.                 case USB_AUDIO_SUBCLASS_AUDIOCONTROL:
  626.                     pStr = " (Audio Control)rn";
  627.                     break;
  628.                 case USB_AUDIO_SUBCLASS_AUDIOSTREAMING:
  629.                     pStr = " (Audio Streaming)rn";
  630.                     break;
  631.                 case USB_AUDIO_SUBCLASS_MIDISTREAMING:
  632.                     pStr = " (MIDI Streaming)rn";
  633.                     break;
  634.                 default:
  635.                     break;
  636.             }
  637.             break;
  638.         default:
  639.             break;
  640.     }
  641.     AppendTextBuffer(pStr);
  642.     AppendTextBuffer("bInterfaceProtocol:   0x%02Xrn",
  643.                      InterfaceDesc->bInterfaceProtocol);
  644.     AppendTextBuffer("iInterface:           0x%02Xrn",
  645.                      InterfaceDesc->iInterface);
  646.     if (InterfaceDesc->iInterface)
  647.     {
  648.         DisplayStringDescriptor(InterfaceDesc->iInterface,
  649.                                 StringDescs);
  650.     }
  651.     if (InterfaceDesc->bLength == sizeof(USB_INTERFACE_DESCRIPTOR2))
  652.     {
  653.         PUSB_INTERFACE_DESCRIPTOR2 interfaceDesc2;
  654.         interfaceDesc2 = (PUSB_INTERFACE_DESCRIPTOR2)InterfaceDesc;
  655.         AppendTextBuffer("wNumClasses:        0x%04Xrn",
  656.                          interfaceDesc2->wNumClasses);
  657.     }
  658. }
  659. //*****************************************************************************
  660. //
  661. // DisplayEndpointDescriptor()
  662. //
  663. //*****************************************************************************
  664. VOID
  665. DisplayEndpointDescriptor (
  666.     PUSB_ENDPOINT_DESCRIPTOR    EndpointDesc
  667. )
  668. {
  669.     AppendTextBuffer("rnEndpoint Descriptor:rn");
  670.     AppendTextBuffer("bEndpointAddress:     0x%02Xrn",
  671.                      EndpointDesc->bEndpointAddress);
  672.     switch (EndpointDesc->bmAttributes & 0x03)
  673.     {
  674.         case 0x00:
  675.             AppendTextBuffer("Transfer Type:     Controlrn");
  676.             break;
  677.         case 0x01:
  678.             AppendTextBuffer("Transfer Type: Isochronousrn");
  679.             break;
  680.         case 0x02:
  681.             AppendTextBuffer("Transfer Type:        Bulkrn");
  682.             break;
  683.         case 0x03:
  684.             AppendTextBuffer("Transfer Type:   Interruptrn");
  685.             break;
  686.     }
  687.     AppendTextBuffer("wMaxPacketSize:     0x%04X (%d)rn",
  688.                      EndpointDesc->wMaxPacketSize,
  689.                      EndpointDesc->wMaxPacketSize);
  690.     if (EndpointDesc->bLength == sizeof(USB_ENDPOINT_DESCRIPTOR))
  691.     {
  692.         AppendTextBuffer("bInterval:            0x%02Xrn",
  693.                          EndpointDesc->bInterval);
  694.     }
  695.     else
  696.     {
  697.         PUSB_ENDPOINT_DESCRIPTOR2 endpointDesc2;
  698.         endpointDesc2 = (PUSB_ENDPOINT_DESCRIPTOR2)EndpointDesc;
  699.         AppendTextBuffer("wInterval:          0x%04Xrn",
  700.                          endpointDesc2->wInterval);
  701.         AppendTextBuffer("bSyncAddress:         0x%02Xrn",
  702.                          endpointDesc2->bSyncAddress);
  703.     }
  704. }
  705. //*****************************************************************************
  706. //
  707. // DisplayHidDescriptor()
  708. //
  709. //*****************************************************************************
  710. VOID
  711. DisplayHidDescriptor (
  712.     PUSB_HID_DESCRIPTOR         HidDesc
  713. )
  714. {
  715.     UCHAR i;
  716.     AppendTextBuffer("rnHID Descriptor:rn");
  717.     AppendTextBuffer("bcdHID:             0x%04Xrn",
  718.     HidDesc->bcdHID);
  719.     AppendTextBuffer("bCountryCode:         0x%02Xrn",
  720.                      HidDesc->bCountryCode);
  721.     AppendTextBuffer("bNumDescriptors:      0x%02Xrn",
  722.                      HidDesc->bNumDescriptors);
  723.     for (i=0; i<HidDesc->bNumDescriptors; i++)
  724.     {
  725.         AppendTextBuffer("bDescriptorType:      0x%02Xrn",
  726.                          HidDesc->OptionalDescriptors[i].bDescriptorType);
  727.         AppendTextBuffer("wDescriptorLength:  0x%04Xrn",
  728.                          HidDesc->OptionalDescriptors[i].wDescriptorLength);
  729.     }
  730. }
  731. #if 0
  732. //*****************************************************************************
  733. //
  734. // DisplayPowerDescriptor()
  735. //
  736. //*****************************************************************************
  737. PCHAR PowerUnits[] =
  738. {
  739.     "0.001 mW",
  740.     "0.01 mW",
  741.     "0.1 mW",
  742.     "1 mW",
  743.     "10 mW",
  744.     "100 mW",
  745.     "1 W"
  746. };
  747. VOID
  748. DisplayPowerDescriptor (
  749.     PUSB_POWER_DESCRIPTOR       PowerDesc
  750. )
  751. {
  752.     UCHAR i;
  753.     AppendTextBuffer("rnPower Descriptor:rn");
  754.     AppendTextBuffer("bCapabilitiesFlags:   0x%02X (",
  755.                      PowerDesc->bCapabilitiesFlags);
  756.     if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D2_WAKEUP)
  757.     {
  758.         AppendTextBuffer("WakeD2 ");
  759.     }
  760.     if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D1_WAKEUP)
  761.     {
  762.         AppendTextBuffer("WakeD1 ");
  763.     }
  764.     if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D3_COMMAND)
  765.     {
  766.         AppendTextBuffer("D3 ");
  767.     }
  768.     if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D2_COMMAND)
  769.     {
  770.         AppendTextBuffer("D2 ");
  771.     }
  772.     if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D1_COMMAND)
  773.     {
  774.         AppendTextBuffer("D1 ");
  775.     }
  776.     if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D0_COMMAND)
  777.     {
  778.         AppendTextBuffer("D0 ");
  779.     }
  780.     AppendTextBuffer(")rn");
  781.     AppendTextBuffer("EventNotification:  0x%04Xrn",
  782.                      PowerDesc->EventNotification);
  783.     AppendTextBuffer("D1LatencyTime:      0x%04Xrn",
  784.                      PowerDesc->D1LatencyTime);
  785.     AppendTextBuffer("D2LatencyTime:      0x%04Xrn",
  786.                      PowerDesc->D2LatencyTime);
  787.     AppendTextBuffer("D3LatencyTime:      0x%04Xrn",
  788.                      PowerDesc->D3LatencyTime);
  789.     AppendTextBuffer("PowerUnit:            0x%02X (%s)rn",
  790.                      PowerDesc->PowerUnit,
  791.                      PowerDesc->PowerUnit < sizeof(PowerUnits)/sizeof(PowerUnits[0])
  792.                      ? PowerUnits[PowerDesc->PowerUnit]
  793.                      : "?");
  794.     AppendTextBuffer("D0PowerConsumption: 0x%04X (%5d)rn",
  795.                      PowerDesc->D0PowerConsumption,
  796.                      PowerDesc->D0PowerConsumption);
  797.     AppendTextBuffer("D1PowerConsumption: 0x%04X (%5d)rn",
  798.                      PowerDesc->D1PowerConsumption,
  799.                      PowerDesc->D1PowerConsumption);
  800.     AppendTextBuffer("D2PowerConsumption: 0x%04X (%5d)rn",
  801.                      PowerDesc->D2PowerConsumption,
  802.                      PowerDesc->D2PowerConsumption);
  803. }
  804. #endif
  805. //*****************************************************************************
  806. //
  807. // DisplayStringDescriptor()
  808. //
  809. //*****************************************************************************
  810. #if 1
  811. VOID
  812. DisplayStringDescriptor (
  813.     UCHAR                       Index,
  814.     PSTRING_DESCRIPTOR_NODE     StringDescs
  815. )
  816. {
  817.     ULONG nBytes;
  818.     while (StringDescs)
  819.     {
  820.         if (StringDescs->DescriptorIndex == Index)
  821.         {
  822.             AppendTextBuffer("0x%04X: "",
  823.                              StringDescs->LanguageID);
  824.             nBytes = WideCharToMultiByte(
  825.                          CP_ACP,     // CodePage
  826.                          0,          // CodePage
  827.                          StringDescs->StringDescriptor->bString,
  828.                          (StringDescs->StringDescriptor->bLength - 2) / 2,
  829.                          TextBuffer + TextBufferPos,
  830.                          TextBufferLen - TextBufferPos,
  831.                          NULL,       // lpDefaultChar
  832.                          NULL);      // pUsedDefaultChar
  833.             TextBufferPos += nBytes;
  834.             AppendTextBuffer(""rn");
  835.         }
  836.         StringDescs = StringDescs->Next;
  837.     }
  838. }
  839. #else
  840. VOID
  841. DisplayStringDescriptor (
  842.     UCHAR                       Index,
  843.     PSTRING_DESCRIPTOR_NODE     StringDescs
  844. )
  845. {
  846.     UCHAR i;
  847.     while (StringDescs)
  848.     {
  849.         if (StringDescs->DescriptorIndex == Index)
  850.         {
  851.             AppendTextBuffer("String Descriptor:rn");
  852.             AppendTextBuffer("LanguageID:         0x%04Xrn",
  853.                              StringDescs->LanguageID);
  854.             AppendTextBuffer("bLength:              0x%02Xrn",
  855.                              StringDescs->StringDescriptor->bLength);
  856.             for (i = 0; i < StringDescs->StringDescriptor->bLength-2; i++)
  857.             {
  858.                 AppendTextBuffer("%02X ",
  859.                                  ((PUCHAR)StringDescs->StringDescriptor->bString)[i]);
  860.                 if (i % 16 == 15)
  861.                 {
  862.                     AppendTextBuffer("rn");
  863.                 }
  864.             }
  865.             if (i % 16 != 0)
  866.             {
  867.                 AppendTextBuffer("rn");
  868.             }
  869.         }
  870.         StringDescs = StringDescs->Next;
  871.     }
  872. }
  873. #endif
  874. //*****************************************************************************
  875. //
  876. // DisplayUnknownDescriptor()
  877. //
  878. //*****************************************************************************
  879. VOID
  880. DisplayUnknownDescriptor (
  881.     PUSB_COMMON_DESCRIPTOR      CommonDesc
  882. )
  883. {
  884.     UCHAR   i;
  885.     AppendTextBuffer("rnUnknown Descriptor:rn");
  886.     AppendTextBuffer("bDescriptorType:      0x%02Xrn",
  887.                      CommonDesc->bDescriptorType);
  888.     AppendTextBuffer("bLength:              0x%02Xrn",
  889.                      CommonDesc->bLength);
  890.     for (i = 0; i < CommonDesc->bLength; i++)
  891.     {
  892.         AppendTextBuffer("%02X ",
  893.                          ((PUCHAR)CommonDesc)[i]);
  894.         if (i % 16 == 15)
  895.         {
  896.             AppendTextBuffer("rn");
  897.         }
  898.     }
  899.     if (i % 16 != 0)
  900.     {
  901.         AppendTextBuffer("rn");
  902.     }
  903. }
  904. //*****************************************************************************
  905. //
  906. // GetVendorString()
  907. //
  908. // idVendor - USB Vendor ID
  909. //
  910. // Return Value - Vendor name string associated with idVendor, or NULL if
  911. // no vendor name string is found which is associated with idVendor.
  912. //
  913. //*****************************************************************************
  914. PCHAR
  915. GetVendorString (
  916.     USHORT     idVendor
  917. )
  918. {
  919.     PUSBVENDORID vendorID;
  920.     if (idVendor != 0x0000)
  921.     {
  922.         vendorID = USBVendorIDs;
  923.         while (vendorID->usVendorID != 0x0000)
  924.         {
  925.             if (vendorID->usVendorID == idVendor)
  926.             {
  927.                 return (vendorID->szVendor);
  928.             }
  929.             vendorID++;
  930.         }
  931.     }
  932.     return NULL;
  933. }