?? enum.c
字號:
commonDesc = (PUSB_COMMON_DESCRIPTOR)ConfigDesc;
while ((PUCHAR)commonDesc + sizeof(USB_COMMON_DESCRIPTOR) < descEnd &&
(PUCHAR)commonDesc + commonDesc->bLength <= descEnd)
{
switch (commonDesc->bDescriptorType)
{
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
if (commonDesc->bLength != sizeof(USB_CONFIGURATION_DESCRIPTOR))
{
OOPS();
break;
}
if (((PUSB_CONFIGURATION_DESCRIPTOR)commonDesc)->iConfiguration)
{
return TRUE;
}
(PUCHAR)commonDesc += commonDesc->bLength;
continue;
case USB_INTERFACE_DESCRIPTOR_TYPE:
if (commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR) &&
commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR2))
{
OOPS();
break;
}
if (((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->iInterface)
{
return TRUE;
}
(PUCHAR)commonDesc += commonDesc->bLength;
continue;
default:
(PUCHAR)commonDesc += commonDesc->bLength;
continue;
}
break;
}
return FALSE;
}
//*****************************************************************************
//
// GetAllStringDescriptors()
//
// hHubDevice - Handle of the hub device containing the port from which the
// String Descriptors will be requested.
//
// ConnectionIndex - Identifies the port on the hub to which a device is
// attached from which the String Descriptors will be requested.
//
// DeviceDesc - Device Descriptor for which String Descriptors should be
// requested.
//
// ConfigDesc - Configuration Descriptor (also containing Interface Descriptor)
// for which String Descriptors should be requested.
//
//*****************************************************************************
PSTRING_DESCRIPTOR_NODE
GetAllStringDescriptors (
HANDLE hHubDevice,
ULONG ConnectionIndex,
PUSB_DEVICE_DESCRIPTOR DeviceDesc,
PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc
)
{
PSTRING_DESCRIPTOR_NODE supportedLanguagesString;
PSTRING_DESCRIPTOR_NODE stringDescNodeTail;
ULONG numLanguageIDs;
USHORT *languageIDs;
PUCHAR descEnd;
PUSB_COMMON_DESCRIPTOR commonDesc;
//
// Get the array of supported Language IDs, which is returned
// in String Descriptor 0
//
supportedLanguagesString = GetStringDescriptor(hHubDevice,
ConnectionIndex,
0,
0);
if (supportedLanguagesString == NULL)
{
return NULL;
}
numLanguageIDs = (supportedLanguagesString->StringDescriptor->bLength - 2) / 2;
languageIDs = &supportedLanguagesString->StringDescriptor->bString[0];
stringDescNodeTail = supportedLanguagesString;
//
// Get the Device Descriptor strings
//
if (DeviceDesc->iManufacturer)
{
stringDescNodeTail = GetStringDescriptors(hHubDevice,
ConnectionIndex,
DeviceDesc->iManufacturer,
numLanguageIDs,
languageIDs,
stringDescNodeTail);
}
if (DeviceDesc->iProduct)
{
stringDescNodeTail = GetStringDescriptors(hHubDevice,
ConnectionIndex,
DeviceDesc->iProduct,
numLanguageIDs,
languageIDs,
stringDescNodeTail);
}
if (DeviceDesc->iSerialNumber)
{
stringDescNodeTail = GetStringDescriptors(hHubDevice,
ConnectionIndex,
DeviceDesc->iSerialNumber,
numLanguageIDs,
languageIDs,
stringDescNodeTail);
}
//
// Get the Configuration and Interface Descriptor strings
//
descEnd = (PUCHAR)ConfigDesc + ConfigDesc->wTotalLength;
commonDesc = (PUSB_COMMON_DESCRIPTOR)ConfigDesc;
while ((PUCHAR)commonDesc + sizeof(USB_COMMON_DESCRIPTOR) < descEnd &&
(PUCHAR)commonDesc + commonDesc->bLength <= descEnd)
{
switch (commonDesc->bDescriptorType)
{
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
if (commonDesc->bLength != sizeof(USB_CONFIGURATION_DESCRIPTOR))
{
OOPS();
break;
}
if (((PUSB_CONFIGURATION_DESCRIPTOR)commonDesc)->iConfiguration)
{
stringDescNodeTail = GetStringDescriptors(
hHubDevice,
ConnectionIndex,
((PUSB_CONFIGURATION_DESCRIPTOR)commonDesc)->iConfiguration,
numLanguageIDs,
languageIDs,
stringDescNodeTail);
}
(PUCHAR)commonDesc += commonDesc->bLength;
continue;
case USB_INTERFACE_DESCRIPTOR_TYPE:
if (commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR) &&
commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR2))
{
OOPS();
break;
}
if (((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->iInterface)
{
stringDescNodeTail = GetStringDescriptors(
hHubDevice,
ConnectionIndex,
((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->iInterface,
numLanguageIDs,
languageIDs,
stringDescNodeTail);
}
(PUCHAR)commonDesc += commonDesc->bLength;
continue;
default:
(PUCHAR)commonDesc += commonDesc->bLength;
continue;
}
break;
}
return supportedLanguagesString;
}
//*****************************************************************************
//
// GetStringDescriptor()
//
// hHubDevice - Handle of the hub device containing the port from which the
// String Descriptor will be requested.
//
// ConnectionIndex - Identifies the port on the hub to which a device is
// attached from which the String Descriptor will be requested.
//
// DescriptorIndex - String Descriptor index.
//
// LanguageID - Language in which the string should be requested.
//
//*****************************************************************************
PSTRING_DESCRIPTOR_NODE
GetStringDescriptor (
HANDLE hHubDevice,
ULONG ConnectionIndex,
UCHAR DescriptorIndex,
USHORT LanguageID
)
{
BOOL success;
ULONG nBytes;
ULONG nBytesReturned;
UCHAR stringDescReqBuf[sizeof(USB_DESCRIPTOR_REQUEST) +
MAXIMUM_USB_STRING_LENGTH];
PUSB_DESCRIPTOR_REQUEST stringDescReq;
PUSB_STRING_DESCRIPTOR stringDesc;
PSTRING_DESCRIPTOR_NODE stringDescNode;
nBytes = sizeof(stringDescReqBuf);
stringDescReq = (PUSB_DESCRIPTOR_REQUEST)stringDescReqBuf;
stringDesc = (PUSB_STRING_DESCRIPTOR)(stringDescReq+1);
// Zero fill the entire request structure
//
memset(stringDescReq, 0, nBytes);
// Indicate the port from which the descriptor will be requested
//
stringDescReq->ConnectionIndex = ConnectionIndex;
//
// USBHUB uses URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE to process this
// IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION request.
//
// USBD will automatically initialize these fields:
// bmRequest = 0x80
// bRequest = 0x06
//
// We must inititialize these fields:
// wValue = Descriptor Type (high) and Descriptor Index (low byte)
// wIndex = Zero (or Language ID for String Descriptors)
// wLength = Length of descriptor buffer
//
stringDescReq->SetupPacket.wValue = (USB_STRING_DESCRIPTOR_TYPE << 8)
| DescriptorIndex;
stringDescReq->SetupPacket.wIndex = LanguageID;
stringDescReq->SetupPacket.wLength = (USHORT)(nBytes - sizeof(USB_DESCRIPTOR_REQUEST));
// Now issue the get descriptor request.
//
success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION,
stringDescReq,
nBytes,
stringDescReq,
nBytes,
&nBytesReturned,
NULL);
//
// Do some sanity checks on the return from the get descriptor request.
//
if (!success)
{
OOPS();
return NULL;
}
if (nBytesReturned < 2)
{
OOPS();
return NULL;
}
if (stringDesc->bDescriptorType != USB_STRING_DESCRIPTOR_TYPE)
{
OOPS();
return NULL;
}
if (stringDesc->bLength != nBytesReturned - sizeof(USB_DESCRIPTOR_REQUEST))
{
OOPS();
return NULL;
}
if (stringDesc->bLength % 2 != 0)
{
OOPS();
return NULL;
}
//
// Looks good, allocate some (zero filled) space for the string descriptor
// node and copy the string descriptor to it.
//
stringDescNode = (PSTRING_DESCRIPTOR_NODE)ALLOC(sizeof(STRING_DESCRIPTOR_NODE) +
stringDesc->bLength);
if (stringDescNode == NULL)
{
OOPS();
return NULL;
}
stringDescNode->DescriptorIndex = DescriptorIndex;
stringDescNode->LanguageID = LanguageID;
memcpy(stringDescNode->StringDescriptor,
stringDesc,
stringDesc->bLength);
return stringDescNode;
}
//*****************************************************************************
//
// GetStringDescriptors()
//
// hHubDevice - Handle of the hub device containing the port from which the
// String Descriptor will be requested.
//
// ConnectionIndex - Identifies the port on the hub to which a device is
// attached from which the String Descriptor will be requested.
//
// DescriptorIndex - String Descriptor index.
//
// NumLanguageIDs - Number of languages in which the string should be
// requested.
//
// LanguageIDs - Languages in which the string should be requested.
//
//*****************************************************************************
PSTRING_DESCRIPTOR_NODE
GetStringDescriptors (
HANDLE hHubDevice,
ULONG ConnectionIndex,
UCHAR DescriptorIndex,
ULONG NumLanguageIDs,
USHORT *LanguageIDs,
PSTRING_DESCRIPTOR_NODE StringDescNodeTail
)
{
ULONG i;
for (i=0; i<NumLanguageIDs; i++)
{
StringDescNodeTail->Next = GetStringDescriptor(hHubDevice,
ConnectionIndex,
DescriptorIndex,
*LanguageIDs);
if (StringDescNodeTail->Next)
{
StringDescNodeTail = StringDescNodeTail->Next;
}
LanguageIDs++;
}
return StringDescNodeTail;
}
//*****************************************************************************
//
// CleanupItem()
//
//*****************************************************************************
VOID
CleanupItem (
HWND hTreeWnd,
HTREEITEM hTreeItem
)
{
TV_ITEM tvi;
PUSBDEVICEINFO info;
tvi.mask = TVIF_HANDLE | TVIF_PARAM;
tvi.hItem = hTreeItem;
TreeView_GetItem(hTreeWnd,
&tvi);
info = (PUSBDEVICEINFO)tvi.lParam;
if (info)
{
if (info->HubInfo != NULL)
{
FREE(info->HubInfo);
info->HubInfo = NULL;
}
if (info->HubName != NULL)
{
FREE(info->HubName);
info->HubName = NULL;
}
if (info->ConfigDesc != NULL)
{
FREE(info->ConfigDesc);
info->ConfigDesc = NULL;
}
if (info->StringDescs != NULL)
{
PSTRING_DESCRIPTOR_NODE Next;
do {
Next = info->StringDescs->Next;
FREE(info->StringDescs);
info->StringDescs = Next;
} while (info->StringDescs != NULL);
}
if (info->ConnectionInfo != NULL)
{
FREE(info->ConnectionInfo);
info->ConnectionInfo = NULL;
}
FREE(info);
info = NULL;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -