깔끔히 정리된 USB 장치를 열거하는 코드입니다.
// DisplayUSB.cpp: Defines the entry point for the console application. // // Copyright (C) 2001, Intel Corporation // All rights reserved. // Permission is hereby granted to merge this program code with other program // material to create a derivative work. This derivative work may be distributed // in compiled object form only. Any other publication of this program, in any form, // without the explicit permission of the copyright holder is prohibited. // // Send questions and comments to [email protected] #include "stdafx.h" #include "objbase.h" #include "winioctl.h" #include "usbioctl.h" #include "stdio.h" #include "stdlib.h" bool DEBUG; // Set to true to enable DEBUG messages SECURITY_ATTRIBUTES SA; // Needed for Win2000 const char ClassName[] [20] = { "Reserved", "Audio", "Communications", "Human Interface", "Monitor", "Physical Interface", "Power", "Printer", "Storage", "Hub", "Vendor Specific", "*ILLEGAL VALUE*" }; const char ConnectionStatus[] [30] = { "No device connected", "Device connected", "Device FAILED enumeration", "Device general FAILURE", "Device caused overcurrent", "Not enough power for device" }; // Define all stuctures using UCHAR or BOOLEAN so that the variables are not 'aligned' by the compiler typedef struct DESCRIPTOR_REQUEST { ULONG ConnectionIndex; struct {UCHAR bmRequest; UCHAR bRequest; UCHAR wValue[2]; UCHAR wIndex[2]; UCHAR wLength[2];} SetupPacket; UCHAR Data[2048]; }; typedef struct DEVICE_DESCRIPTOR { UCHAR bLength; UCHAR bDescriptorType; UCHAR bcdUSB[2]; UCHAR bDeviceClass; UCHAR bDeviceSubClass; UCHAR bDeviceProtocol; UCHAR bMaxPacketSize0; UCHAR idVendor[2]; UCHAR idProduct[2]; UCHAR bcdDevice[2]; UCHAR iManufacturer; UCHAR iProduct; UCHAR iSerialNumber; UCHAR bNumConfigurations; }; typedef struct HUB_DESCRIPTOR { UCHAR bDescriptorLength; UCHAR bDescriptorType; UCHAR bNumberOfPorts; UCHAR wHubCharacteristics[2]; UCHAR bPowerOnToPowerGood; UCHAR bHubControlCurrent; UCHAR bRemoveAndPowerMask[64]; }; typedef struct NODE_INFORMATION { USB_HUB_NODE NodeType; HUB_DESCRIPTOR HubDescriptor; BOOLEAN HubIsBusPowered; }; typedef struct NODE_CONNECTION_INFORMATION { ULONG ConnectionIndex; DEVICE_DESCRIPTOR DeviceDescriptor; UCHAR CurrentConfigurationValue; BOOLEAN LowSpeed; BOOLEAN DeviceIsHub; UCHAR DeviceAddress[2]; UCHAR NumberOfOpenPipes[4]; UCHAR ConnectionStatus[4]; USB_PIPE_INFO PipeList[32]; }; USHORT DisplayStringDescriptor (HANDLE HubHandle, ULONG PortIndex, USHORT LanguageID, UCHAR Index) { if (DEBUG) printf("\nIn DisplayStringDescriptor with HubHandle = %x, PortIndex = %x, LanguageID = %x, Index = %x\n", HubHandle, PortIndex, LanguageID, Index); DESCRIPTOR_REQUEST Packet; DWORD BytesReturned; bool Success; if (LanguageID == 0) { // Get the language ID memset(&Packet, 0, sizeof(Packet)); Packet.ConnectionIndex = PortIndex; Packet.SetupPacket.bmRequest = 0x80; Packet.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR; Packet.SetupPacket.wValue[1] = USB_STRING_DESCRIPTOR_TYPE; Packet.SetupPacket.wLength[0] = 4; Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, &Packet, sizeof(Packet), &Packet, sizeof(Packet), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** String Descriptor 0 not returned, ErrorCode = %d\n", GetLastError()); LanguageID = Packet.Data[2] + (Packet.Data[3] << 8); } memset(&Packet, 0, sizeof(Packet)); Packet.ConnectionIndex = PortIndex; Packet.SetupPacket.bmRequest = 0x80; Packet.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR; Packet.SetupPacket.wValue[1] = USB_STRING_DESCRIPTOR_TYPE; Packet.SetupPacket.wValue[0] = Index; Packet.SetupPacket.wIndex[0] = LanguageID & 0xFF; Packet.SetupPacket.wIndex[1] = (LanguageID >> 8) & 0xFF; Packet.SetupPacket.wLength[0] = 255; Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, &Packet, sizeof(Packet), &Packet, sizeof(Packet), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** String Descriptor %d not returned. ErrorCode = %d\n", Index, GetLastError()); printf(" = %ws", &Packet.Data[2]); return LanguageID; } USHORT DisplayDeviceDescriptor (HANDLE HubHandle, ULONG PortIndex, USHORT LanguageID, PUCHAR BufferPtr) { if (DEBUG) printf("In DisplayDeviceDescriptor with HubHandle = %x, PortIndex = %x, LanguageID = %x\n", HubHandle, PortIndex, LanguageID); UCHAR LowByte; printf("Device Descriptor"); BufferPtr--; // Backup pointer to prepare for pre-increment printf("\n bLength %2.2x", *++BufferPtr); printf("\n bDescriptorType %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n bcdUSB %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bDeviceClass %2.2x", *++BufferPtr); printf("\n bDeviceSubClass %2.2x", *++BufferPtr); printf("\n bDeviceProtocol %2.2x", *++BufferPtr); printf("\n bMaxEP0Size %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n wVendorID %4.4x", LowByte + (*++BufferPtr << 8)); LowByte = *++BufferPtr; printf("\n wProductID %4.4x", LowByte + (*++BufferPtr << 8)); LowByte = *++BufferPtr; printf("\n wDeviceID %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n iManufacturer %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n iProduct %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n iSerialNumber %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n bNumConfigurations %2.2x\n", *++BufferPtr); return LanguageID; } USHORT DisplayConfigurationDescriptor(HANDLE HubHandle, ULONG PortIndex, USHORT LanguageID) { if (DEBUG) printf("In DisplayConfigurationDescriptor with HubHandle = %x, PortIndex = %x, LanguageID = %x\n", HubHandle, PortIndex, LanguageID); DWORD BytesReturned; bool Success; UCHAR LowByte; DESCRIPTOR_REQUEST Packet; int i; printf("\nConfiguration Descriptor"); // First need to get the configuration descriptor memset(&Packet, 0, sizeof(Packet)); Packet.ConnectionIndex = PortIndex; Packet.SetupPacket.bmRequest = 0x80; Packet.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR; Packet.SetupPacket.wValue[1] = USB_CONFIGURATION_DESCRIPTOR_TYPE; Packet.SetupPacket.wLength[1] = 1; // Using a 2K buffer Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, &Packet, sizeof(Packet), &Packet, sizeof(Packet), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** Configuration Descriptor not returned. ErrorCode = %d\n", GetLastError()); PUCHAR BufferPtr = &Packet.Data[0]; UCHAR Length = *BufferPtr; while (Length != 0) { UCHAR Type = *++BufferPtr; switch (Type) { case 2: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = Configuration Header", Type); LowByte = *++BufferPtr; printf("\n wTotalLength %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bNumInterfaces %2.2x", *++BufferPtr); printf("\n bConfigValue %2.2x", *++BufferPtr); printf("\n iConfiguration %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n bmAttributes %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n bMaxPower %2.2x = %d mA", LowByte, (LowByte << 1)); break; case 4: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = Interface Descriptor", Type); printf("\n bInterfaceNum %2.2x", *++BufferPtr); printf("\n bAlternateSetting %2.2x", *++BufferPtr); printf("\n bNumEndpoints %2.2x", *++BufferPtr); LowByte = *++BufferPtr; if ((LowByte > 9) & (LowByte < 255)) LowByte = 11; if (LowByte == 255) LowByte = 10; printf("\n bInterfaceClass %2.2x = %s", *BufferPtr, ClassName[LowByte]); printf("\n bSubClass %2.2x", *++BufferPtr); printf("\n bProtocol %2.2x", *++BufferPtr); printf("\n iInterface %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); break; case 5: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = Endpoint Descriptor", Type); printf("\n bEndpointAddress %2.2x", *++BufferPtr); printf("\n bmAttributes %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n wMaxPacketSize %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bInterval %2.2x", *++BufferPtr); break; case 0x21: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = HID Descriptor", Type); LowByte = *++BufferPtr; printf("\n wHIDversion %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bCountryCode %2.2x", *++BufferPtr); printf("\n bHIDDescriptorCount %2.2x", *++BufferPtr); printf("\n bHIDReportType %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n wHIDReportLength %4.4x", LowByte + (*++BufferPtr << 8)); break; default: printf("\nUnknown descriptor with Length = %2.2xH and Type = %2.2xH", Length, Type); BufferPtr-=2; // Back up to start of descriptor for (i = 0; i < Length; i++) { if ((i % 16) == 0) printf("\n"); printf("%2.2x ", *++BufferPtr); } break; } Length = *++BufferPtr; printf("\n"); } return LanguageID; } void GetPortData(HANDLE HubHandle, UCHAR PortCount, int HubDepth) { if (DEBUG) printf("In GetPortData with HubHandle = %x, PortCount = %x, HubDepth = %x\n", HubHandle, PortCount, HubDepth); DWORD BytesReturned; bool Success; int i; ULONG PortIndex; USHORT LanguageID; UCHAR ThisDevice, PortStatus; char ConnectedHubName[256] = "\\\\.\\"; HANDLE ConnectedHubHandle; NODE_INFORMATION NodeInformation; NODE_CONNECTION_INFORMATION ConnectionInformation; struct {ULONG ConnectionIndex; ULONG ActualLength; WCHAR Name[256];} ConnectedHub; // Iterate over the ports to discover what is connected to each one for (PortIndex = 1; PortIndex < (ULONG)PortCount + 1; PortIndex++) { LanguageID = 0; // Reset for each port ConnectionInformation.ConnectionIndex = PortIndex; Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION, &ConnectionInformation, sizeof(ConnectionInformation), &ConnectionInformation, sizeof(ConnectionInformation), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** Node connection information not returned\n"); PortStatus = ConnectionInformation.ConnectionStatus[0]; // Save some typing! ThisDevice = (PortStatus == DeviceConnected) ? ConnectionInformation.DeviceAddress[0] : 0; // Create an indented display so that hubs and their connections are more easily seen // First the common header // printf("%2.2x", ThisDevice); for (i=0; i
출처는 아래와 같습니다.
PDF 자료를 긁어다 붙입니다.
*. 게시와 관련하여 문제가 있을 경우 연락 부탁드립니다.^^
http://www.intel.com/intelpress/usb/examples/DUSBVC.PDF
// DisplayUSB.cpp: Defines the entry point for the console application. // // Copyright (C) 2001, Intel Corporation // All rights reserved. // Permission is hereby granted to merge this program code with other program // material to create a derivative work. This derivative work may be distributed // in compiled object form only. Any other publication of this program, in any form, // without the explicit permission of the copyright holder is prohibited. // // Send questions and comments to [email protected] #include "stdafx.h" #include "objbase.h" #include "winioctl.h" #include "usbioctl.h" #include "stdio.h" #include "stdlib.h" bool DEBUG; // Set to true to enable DEBUG messages SECURITY_ATTRIBUTES SA; // Needed for Win2000 const char ClassName[] [20] = { "Reserved", "Audio", "Communications", "Human Interface", "Monitor", "Physical Interface", "Power", "Printer", "Storage", "Hub", "Vendor Specific", "*ILLEGAL VALUE*" }; const char ConnectionStatus[] [30] = { "No device connected", "Device connected", "Device FAILED enumeration", "Device general FAILURE", "Device caused overcurrent", "Not enough power for device" }; // Define all stuctures using UCHAR or BOOLEAN so that the variables are not 'aligned' by the compiler typedef struct DESCRIPTOR_REQUEST { ULONG ConnectionIndex; struct {UCHAR bmRequest; UCHAR bRequest; UCHAR wValue[2]; UCHAR wIndex[2]; UCHAR wLength[2];} SetupPacket; UCHAR Data[2048]; }; typedef struct DEVICE_DESCRIPTOR { UCHAR bLength; UCHAR bDescriptorType; UCHAR bcdUSB[2]; UCHAR bDeviceClass; UCHAR bDeviceSubClass; UCHAR bDeviceProtocol; UCHAR bMaxPacketSize0; UCHAR idVendor[2]; UCHAR idProduct[2]; UCHAR bcdDevice[2]; UCHAR iManufacturer; UCHAR iProduct; UCHAR iSerialNumber; UCHAR bNumConfigurations; }; typedef struct HUB_DESCRIPTOR { UCHAR bDescriptorLength; UCHAR bDescriptorType; UCHAR bNumberOfPorts; UCHAR wHubCharacteristics[2]; UCHAR bPowerOnToPowerGood; UCHAR bHubControlCurrent; UCHAR bRemoveAndPowerMask[64]; }; typedef struct NODE_INFORMATION { USB_HUB_NODE NodeType; HUB_DESCRIPTOR HubDescriptor; BOOLEAN HubIsBusPowered; }; typedef struct NODE_CONNECTION_INFORMATION { ULONG ConnectionIndex; DEVICE_DESCRIPTOR DeviceDescriptor; UCHAR CurrentConfigurationValue; BOOLEAN LowSpeed; BOOLEAN DeviceIsHub; UCHAR DeviceAddress[2]; UCHAR NumberOfOpenPipes[4]; UCHAR ConnectionStatus[4]; USB_PIPE_INFO PipeList[32]; }; USHORT DisplayStringDescriptor (HANDLE HubHandle, ULONG PortIndex, USHORT LanguageID, UCHAR Index) { if (DEBUG) printf("\nIn DisplayStringDescriptor with HubHandle = %x, PortIndex = %x, LanguageID = %x, Index = %x\n", HubHandle, PortIndex, LanguageID, Index); DESCRIPTOR_REQUEST Packet; DWORD BytesReturned; bool Success; if (LanguageID == 0) { // Get the language ID memset(&Packet, 0, sizeof(Packet)); Packet.ConnectionIndex = PortIndex; Packet.SetupPacket.bmRequest = 0x80; Packet.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR; Packet.SetupPacket.wValue[1] = USB_STRING_DESCRIPTOR_TYPE; Packet.SetupPacket.wLength[0] = 4; Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, &Packet, sizeof(Packet), &Packet, sizeof(Packet), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** String Descriptor 0 not returned, ErrorCode = %d\n", GetLastError()); LanguageID = Packet.Data[2] + (Packet.Data[3] << 8); } memset(&Packet, 0, sizeof(Packet)); Packet.ConnectionIndex = PortIndex; Packet.SetupPacket.bmRequest = 0x80; Packet.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR; Packet.SetupPacket.wValue[1] = USB_STRING_DESCRIPTOR_TYPE; Packet.SetupPacket.wValue[0] = Index; Packet.SetupPacket.wIndex[0] = LanguageID & 0xFF; Packet.SetupPacket.wIndex[1] = (LanguageID >> 8) & 0xFF; Packet.SetupPacket.wLength[0] = 255; Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, &Packet, sizeof(Packet), &Packet, sizeof(Packet), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** String Descriptor %d not returned. ErrorCode = %d\n", Index, GetLastError()); printf(" = %ws", &Packet.Data[2]); return LanguageID; } USHORT DisplayDeviceDescriptor (HANDLE HubHandle, ULONG PortIndex, USHORT LanguageID, PUCHAR BufferPtr) { if (DEBUG) printf("In DisplayDeviceDescriptor with HubHandle = %x, PortIndex = %x, LanguageID = %x\n", HubHandle, PortIndex, LanguageID); UCHAR LowByte; printf("Device Descriptor"); BufferPtr--; // Backup pointer to prepare for pre-increment printf("\n bLength %2.2x", *++BufferPtr); printf("\n bDescriptorType %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n bcdUSB %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bDeviceClass %2.2x", *++BufferPtr); printf("\n bDeviceSubClass %2.2x", *++BufferPtr); printf("\n bDeviceProtocol %2.2x", *++BufferPtr); printf("\n bMaxEP0Size %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n wVendorID %4.4x", LowByte + (*++BufferPtr << 8)); LowByte = *++BufferPtr; printf("\n wProductID %4.4x", LowByte + (*++BufferPtr << 8)); LowByte = *++BufferPtr; printf("\n wDeviceID %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n iManufacturer %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n iProduct %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n iSerialNumber %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n bNumConfigurations %2.2x\n", *++BufferPtr); return LanguageID; } USHORT DisplayConfigurationDescriptor(HANDLE HubHandle, ULONG PortIndex, USHORT LanguageID) { if (DEBUG) printf("In DisplayConfigurationDescriptor with HubHandle = %x, PortIndex = %x, LanguageID = %x\n", HubHandle, PortIndex, LanguageID); DWORD BytesReturned; bool Success; UCHAR LowByte; DESCRIPTOR_REQUEST Packet; int i; printf("\nConfiguration Descriptor"); // First need to get the configuration descriptor memset(&Packet, 0, sizeof(Packet)); Packet.ConnectionIndex = PortIndex; Packet.SetupPacket.bmRequest = 0x80; Packet.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR; Packet.SetupPacket.wValue[1] = USB_CONFIGURATION_DESCRIPTOR_TYPE; Packet.SetupPacket.wLength[1] = 1; // Using a 2K buffer Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, &Packet, sizeof(Packet), &Packet, sizeof(Packet), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** Configuration Descriptor not returned. ErrorCode = %d\n", GetLastError()); PUCHAR BufferPtr = &Packet.Data[0]; UCHAR Length = *BufferPtr; while (Length != 0) { UCHAR Type = *++BufferPtr; switch (Type) { case 2: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = Configuration Header", Type); LowByte = *++BufferPtr; printf("\n wTotalLength %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bNumInterfaces %2.2x", *++BufferPtr); printf("\n bConfigValue %2.2x", *++BufferPtr); printf("\n iConfiguration %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); printf("\n bmAttributes %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n bMaxPower %2.2x = %d mA", LowByte, (LowByte << 1)); break; case 4: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = Interface Descriptor", Type); printf("\n bInterfaceNum %2.2x", *++BufferPtr); printf("\n bAlternateSetting %2.2x", *++BufferPtr); printf("\n bNumEndpoints %2.2x", *++BufferPtr); LowByte = *++BufferPtr; if ((LowByte > 9) & (LowByte < 255)) LowByte = 11; if (LowByte == 255) LowByte = 10; printf("\n bInterfaceClass %2.2x = %s", *BufferPtr, ClassName[LowByte]); printf("\n bSubClass %2.2x", *++BufferPtr); printf("\n bProtocol %2.2x", *++BufferPtr); printf("\n iInterface %2.2x", *++BufferPtr); if (*BufferPtr != 0) LanguageID = DisplayStringDescriptor(HubHandle, PortIndex, LanguageID, *BufferPtr); break; case 5: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = Endpoint Descriptor", Type); printf("\n bEndpointAddress %2.2x", *++BufferPtr); printf("\n bmAttributes %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n wMaxPacketSize %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bInterval %2.2x", *++BufferPtr); break; case 0x21: printf("\n bLength %2.2x", Length); printf("\n bDescriptorType %2.2x = HID Descriptor", Type); LowByte = *++BufferPtr; printf("\n wHIDversion %4.4x", LowByte + (*++BufferPtr << 8)); printf("\n bCountryCode %2.2x", *++BufferPtr); printf("\n bHIDDescriptorCount %2.2x", *++BufferPtr); printf("\n bHIDReportType %2.2x", *++BufferPtr); LowByte = *++BufferPtr; printf("\n wHIDReportLength %4.4x", LowByte + (*++BufferPtr << 8)); break; default: printf("\nUnknown descriptor with Length = %2.2xH and Type = %2.2xH", Length, Type); BufferPtr-=2; // Back up to start of descriptor for (i = 0; i < Length; i++) { if ((i % 16) == 0) printf("\n"); printf("%2.2x ", *++BufferPtr); } break; } Length = *++BufferPtr; printf("\n"); } return LanguageID; } void GetPortData(HANDLE HubHandle, UCHAR PortCount, int HubDepth) { if (DEBUG) printf("In GetPortData with HubHandle = %x, PortCount = %x, HubDepth = %x\n", HubHandle, PortCount, HubDepth); DWORD BytesReturned; bool Success; int i; ULONG PortIndex; USHORT LanguageID; UCHAR ThisDevice, PortStatus; char ConnectedHubName[256] = "\\\\.\\"; HANDLE ConnectedHubHandle; NODE_INFORMATION NodeInformation; NODE_CONNECTION_INFORMATION ConnectionInformation; struct {ULONG ConnectionIndex; ULONG ActualLength; WCHAR Name[256];} ConnectedHub; // Iterate over the ports to discover what is connected to each one for (PortIndex = 1; PortIndex < (ULONG)PortCount + 1; PortIndex++) { LanguageID = 0; // Reset for each port ConnectionInformation.ConnectionIndex = PortIndex; Success = DeviceIoControl(HubHandle, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION, &ConnectionInformation, sizeof(ConnectionInformation), &ConnectionInformation, sizeof(ConnectionInformation), &BytesReturned, NULL); if (!Success) printf(" *** ERROR *** Node connection information not returned\n"); PortStatus = ConnectionInformation.ConnectionStatus[0]; // Save some typing! ThisDevice = (PortStatus == DeviceConnected) ? ConnectionInformation.DeviceAddress[0] : 0; // Create an indented display so that hubs and their connections are more easily seen // First the common header // printf("%2.2x", ThisDevice); for (i=0; i