📄 usbdebug.cpp
字号:
}
//------------------------------------------------------------------------
//
//
int DumpInterfaceDescriptor (PCUSB_INTERFACE_DESCRIPTOR lpDes)
{
__try
{
if (lpDes->bLength != sizeof(USB_INTERFACE_DESCRIPTOR))
DEBUGMSG (1, (TEXT("\t Unexpected bLength: %02xh ***********\r\n"), lpDes->bLength));
if (lpDes->bDescriptorType != USB_INTERFACE_DESCRIPTOR_TYPE)
DEBUGMSG (1, (TEXT("\t Unexpected DescriptorType! %02xh \r\n"), lpDes->bDescriptorType));
DEBUGMSG (1, (TEXT("\t bInterfaceNumber: %02xh \r\n"), lpDes->bInterfaceNumber));
DEBUGMSG (1, (TEXT("\t bAlternateSetting: %02xh \r\n"), lpDes->bAlternateSetting));
DEBUGMSG (1, (TEXT("\t bNumEndpoints: %02xh \r\n"), lpDes->bNumEndpoints));
DEBUGMSG (1, (TEXT("\t bInterfaceClass: %02xh (%s)\r\n"), lpDes->bInterfaceClass, GetIFName(lpDes->bInterfaceClass)));
if (lpDes->bInterfaceClass == 0xe)
DEBUGMSG (1, (TEXT("\t bInterfaceSubClass: %02xh (%s)\r\n"), lpDes->bInterfaceSubClass, GetVideoStreamingSubclassName(lpDes->bInterfaceSubClass)));
else
DEBUGMSG (1, (TEXT("\t bInterfaceSubClass: %02xh \r\n"), lpDes->bInterfaceSubClass));
DEBUGMSG (1, (TEXT("\t bInterfaceProtocol: %02xh \r\n"), lpDes->bInterfaceProtocol));
DEBUGMSG (1, (TEXT("\t iInterface: %02xh \r\n"), lpDes->iInterface));
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG (1, (TEXT("Exception dumping interface descriptor\r\n")));
return -1;
}
return 0;
}
//------------------------------------------------------------------------
// DumpByteStream
//
int DumpByteStream (LPBYTE lpb, int nCnt, LPTSTR psz, int sMax)
{
*psz = TEXT('\0');
for (int i = 0; i < nCnt; i++)
{
wsprintf (&psz[lstrlen(psz)], TEXT(" %02x"), *(lpb+i));
if (i && ((i % 16) == 0))
lstrcat (psz, TEXT("\r\n"));
}
return 0;
}
//------------------------------------------------------------------------
// DumpExtendedConfigurationDescriptor
//
int DumpExtendedInterfaceDescriptor (LPBYTE lpex)
{
if (lpex == 0)
return -1;
TCHAR sz[256];
PUSBVIDSTDDESCHDR pStd = (PUSBVIDSTDDESCHDR)lpex;
__try
{
DEBUGMSG (1, (TEXT("Extended Interface Descriptor\r\n")));
DEBUGMSG (1, (TEXT("\t Descriptor Length: %02xh\r\n"), pStd->bLen));
DEBUGMSG (1, (TEXT("\t I/F Descriptor Type: %02xh\r\n"), pStd->bType));
DEBUGMSG (1, (TEXT("\t I/F Descriptor Subtype: %02xh\r\n"), pStd->bSubtype));
lstrcpy (sz, TEXT(" "));
DumpByteStream (lpex+3, pStd->bLen - 3, &sz[lstrlen (sz)], dim (sz) - lstrlen (sz));
DEBUGMSG (1, (TEXT("%s\r\n"), sz));
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG (1, (TEXT("Exception dumping extended descriptor\r\n")));
return -1;
}
return 0;
}
//------------------------------------------------------------------------
// DumpExtendedConfigurationDescriptor
//
LPTSTR LabelBitmap (LPBYTE lpbm, int len, LPTSTR *pLbls, int cLbls, LPTSTR sz, int nStrSize)
{
int index;
BYTE bm;
sz[0] = TEXT('\0');
if (nStrSize < 6)
return sz;
for (index = 0; index < cLbls; index++)
{
// Do we need another byte?
if ((index % 8) == 0)
{
// if no more bytes, leave
if (len == 0) return sz;
bm = *lpbm++;
len--;
}
if (bm & 0x01)
{
if (lstrlen (sz) + lstrlen (pLbls[index]) < (DWORD)nStrSize)
{
lstrcat (sz, pLbls[index]);
lstrcat (sz, TEXT(", "));
}
else
{
lstrcpy (sz, TEXT("<***>\r\n"));
return sz;
}
}
bm = bm >> 1;
}
return sz;
}
LPTSTR DumpConfigBitmap (LPBYTE lpbm, int len, LPTSTR sz, int nStrSize)
{
LPTSTR szLbls[] = {
TEXT("Scanning Mode"),
TEXT("Auto-Exposure Mode"),
TEXT("Auto-Exposure Priority"),
TEXT("Exposure Time (Abs)"),
TEXT("Exposure Time (Rel)"),
TEXT("Focus (Abs)"),
TEXT("Focus (Rel)"),
TEXT("Iris (Abs)"),
TEXT("Iris (Rel)"),
TEXT("Zoom (Abs)"),
TEXT("Zoom (Rel)"),
TEXT("PanTilt (Abs)"),
TEXT("PanTilt (Rel)"),
TEXT("Roll (Abs)"),
TEXT("Roll (Rel)"),
TEXT("Reserved"),
TEXT("Reserved"),
TEXT("Focus, Auto"),
TEXT("Privacy"),
};
return LabelBitmap (lpbm, len, szLbls, dim(szLbls), sz, nStrSize);
}
//------------------------------------------------------------------------
// DumpExtendedVideoControlInterfaceDescriptor
//
int DumpExtendedVideoControlInterfaceDescriptor (LPBYTE lpex)
{
if (lpex == 0)
return -1;
LPTSTR szpuLbls[] = {
TEXT("Brightness"),
TEXT("Contrast"),
TEXT("Hue"),
TEXT("Saturation"),
TEXT("Sharpness"),
TEXT("Gamma"),
TEXT("White Balance Temp"),
TEXT("White Balance Component"),
TEXT("Backlight Compensation"),
TEXT("Gain"),
TEXT("Power Line Frequency"),
TEXT("Hue-Auto"),
TEXT("White Balance Temp-Auto"),
TEXT("White Balance Component-Auto"),
TEXT("Digital Multiplier"),
TEXT("Digital Multiplier Limit"),
TEXT("Analog Video Standard"),
TEXT("Analog Video Lock Status"),
TEXT("Reserved"),
};
TCHAR sz[256];
PUSBVIDCTLIFDESCRIPTOR pDes = (PUSBVIDCTLIFDESCRIPTOR) lpex;
int i;
__try {
if ((pDes->bType != 0x24) || (pDes->bSubtype != 1))
return DumpExtendedInterfaceDescriptor(lpex);
PBYTE pEnd = lpex + pDes->wTotalLen;
DEBUGMSG (1, (TEXT("Video Control Interface Descriptor Header\r\n")));
if (pDes->bLen >= 0x0d)
{
DEBUGMSG (1, (TEXT("\t Subtype: %02xh\r\n"), pDes->bSubtype));
DEBUGMSG (1, (TEXT("\t Interface Ver %d.%02d\r\n"), pDes->wIFVersion>>8, pDes->wIFVersion & 0xff));
DEBUGMSG (1, (TEXT("\t Total Length: %04xh\r\n"), pDes->wTotalLen));
DEBUGMSG (1, (TEXT("\t InCollection: %02xh\r\n"), pDes->bInCollection));
for (i = 0; i < pDes->bInCollection; i++)
{
DEBUGMSG (1, (TEXT("\t baInterface(%d): %02xh\r\n"), i, pDes->bInterface[i]));
}
}
PUSBVIDSTDDESCHDR pStd = (PUSBVIDSTDDESCHDR)lpex;
while (lpex + pStd->bLen < pEnd)
{
lpex += pStd->bLen;
pStd = (PUSBVIDSTDDESCHDR)lpex;
if (pStd->bType != 0x24)
{
DEBUGMSG (1, (TEXT("Unexpected header type %xh\r\n"), pStd->bType));
break;
}
switch (pStd->bSubtype)
{
case 0x1:
DEBUGMSG (1, (TEXT("Video Control Interface Descriptor Header in list????\r\n")));
break;
case USB_VIDEO_VC_INPUT_TERMINAL:
if (pStd->bLen >= 0x8)
{
WORD wType = *(LPWORD)(lpex+4);
switch (wType)
{
case 0x0101: lstrcpy (sz, TEXT("Stream")); break;
case 0x0201: lstrcpy (sz, TEXT("Camera")); break;
case 0x0202: lstrcpy (sz, TEXT("Media Transport")); break;
case 0x0401: lstrcpy (sz, TEXT("Composite Connector")); break;
case 0x0402: lstrcpy (sz, TEXT("S-Video Connector")); break;
case 0x0403: lstrcpy (sz, TEXT("Component Connector")); break;
default: lstrcpy (sz, TEXT("")); break;
}
DEBUGMSG (1, (TEXT("Input Terminal Descriptor (%s)\r\n"), sz));
DEBUGMSG (1, (TEXT("\t Terminal ID: %02xh\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Terminal Type: %04xh\r\n"), wType));
DEBUGMSG (1, (TEXT("\t Assoc Terminal: %02xh\r\n"), *(lpex+6)));
DEBUGMSG (1, (TEXT("\t iTerminal: %02xh\r\n"), *(lpex+7)));
} else
DEBUGMSG (1, (TEXT("Input Terminal Descriptor\r\n")));
if (pStd->bLen >= 0x11)
{
DEBUGMSG (1, (TEXT("\t Obj Focal Len (min) %d\r\n"), *(LPWORD)(lpex+8)));
DEBUGMSG (1, (TEXT("\t Obj Focal Len (max) %d\r\n"), *(LPWORD)(lpex+10)));
DEBUGMSG (1, (TEXT("\t Ocular Focal Len %d\r\n"), *(LPWORD)(lpex+12)));
DEBUGMSG (1, (TEXT("\t Control Size: %02xh\r\n"), *(lpex+14)));
DEBUGMSG (1, (TEXT("\t bmControls: %02xh\r\n"), *(lpex+15)));
DumpByteStream (lpex+15, *(lpex+14), sz, dim (sz));
DEBUGMSG (1, (TEXT("\t bmControls: >%s<\r\n"), sz));
DumpConfigBitmap (lpex+15, *(lpex+14), sz, dim (sz));
DEBUGMSG (1, (TEXT("\t bmControls: >%s<\r\n"), sz));
}
break;
case USB_VIDEO_VC_OUTPUT_TERMINAL:
if (pStd->bLen >= 9)
{
WORD wType = *(LPWORD)(lpex+4);
switch (wType)
{
case 0x0101: lstrcpy (sz, TEXT("Stream")); break;
case 0x0300: lstrcpy (sz, TEXT("Vendor")); break;
case 0x0301: lstrcpy (sz, TEXT("Display")); break;
case 0x0302: lstrcpy (sz, TEXT("Seq Media")); break;
default: lstrcpy (sz, TEXT("")); break;
}
DEBUGMSG (1, (TEXT("Output Terminal Descriptor (%s)\r\n"), sz));
DEBUGMSG (1, (TEXT("\t Terminal ID: %02xh\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Terminal Type: %04xh\r\n"), wType));
DEBUGMSG (1, (TEXT("\t Assoc Terminal: %02xh\r\n"), *(lpex+6)));
DEBUGMSG (1, (TEXT("\t SourceID %02xh\r\n"), *(lpex+7)));
DEBUGMSG (1, (TEXT("\t iTerminal: %02xh\r\n"), *(lpex+8)));
} else
DEBUGMSG (1, (TEXT("Output Terminal Descriptor\r\n")));
break;
case USB_VIDEO_VC_SELECTOR_UNIT:
DEBUGMSG (1, (TEXT("Selector Unit Descriptor\r\n")));
if (pStd->bLen >= 6)
{
DEBUGMSG (1, (TEXT("\t Unit ID: %02xh\r\n"), *(lpex+3)));
}
break;
case USB_VIDEO_VC_PROCESSING_UNIT:
DEBUGMSG (1, (TEXT("Processing Unit Descriptor\r\n")));
if (pStd->bLen >= 10)
{
int nbmCnt = Num(lpex+7,1);
DEBUGMSG (1, (TEXT("\t Unit ID: %02xh\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Source ID: %02xh\r\n"), *(lpex+4)));
DEBUGMSG (1, (TEXT("\t Max Multiplier: %d.%02d"), Num(lpex+5,2)/100, Num(lpex+5,2)%100));
DEBUGMSG (1, (TEXT("\t Control size: %d\r\n"), nbmCnt));
DumpByteStream (lpex+8, nbmCnt, sz, dim (sz));
DEBUGMSG (1, (TEXT("\t bmControls: >%s<\r\n"), sz));
LabelBitmap (lpex+8, nbmCnt, szpuLbls, dim(szpuLbls), sz, dim(sz));
DEBUGMSG (1, (TEXT("\t bmControls: >%s<\r\n"), sz));
DEBUGMSG (1, (TEXT("\t iProcessing: %d\r\n"), *(lpex+8+nbmCnt)));
DEBUGMSG (1, (TEXT("\t bmVideoStds: %d\r\n"), *(lpex+9+nbmCnt)));
}
break;
case USB_VIDEO_VC_EXTENSION_UNIT:
DEBUGMSG (1, (TEXT("Extension Unit Descriptor\r\n")));
if (pStd->bLen >= 24)
{
DEBUGMSG (1, (TEXT("\t Unit ID: %02xh\r\n"), *(lpex+3)));
DumpGUID (lpex+4);
DEBUGMSG (1, (TEXT("\t Num Ctls: %02xh\r\n"), *(lpex+20)));
DEBUGMSG (1, (TEXT("\t Num In Pins: %02xh\r\n"), *(lpex+21)));
DEBUGMSG (1, (TEXT("\t Source ID(I) %02xh\r\n"), *(lpex+22)));
// there is more on this one...
}
break;
default:
DEBUGMSG (1, (TEXT("Unknown Interface Descriptor subtype %xh\r\n"), pStd->bSubtype));
lstrcpy (sz, TEXT(" "));
for (i = 3; i < pStd->bLen; i++)
{
wsprintf (&sz[lstrlen(sz)], TEXT(" %02x"), *(lpex+i));
if ((i % 16) == 0)
{
DEBUGMSG (1, (TEXT("%s\r\n"), sz));
sz[0] = TEXT('\0');
}
}
DEBUGMSG (1, (TEXT("%s\r\n"), sz));
break;
}
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG (1, (TEXT("Exception dumping extended descriptor\r\n")));
return -1;
}
return 0;
}
//------------------------------------------------------------------------
// Num
//
DWORD Num (PBYTE p, int nCntBytes)
{
int c = 0;
DWORD b;
DWORD num = 0;
while (nCntBytes)
{
b = *p++;
b = b << (c * 8);
num += b;
nCntBytes--;
c++;
}
return num;
}
//------------------------------------------------------------------------
// DumpGUID
//
void DumpGUID (PBYTE pData)
{
if (pData == 0)
return;
__try
{
DEBUGMSG (1, (TEXT(" GUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\r\n"),
Num (pData, 4), Num (pData+4, 2),Num (pData+6, 2), *(pData+8), *(pData+9),
*(pData+10), *(pData+11), *(pData+12), *(pData+13), *(pData+14), *(pData+15)));
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG (1, (TEXT("Exception dumping GUID\r\n")));
return;
}
return;
}
//------------------------------------------------------------------------
// DumpExtendedVideoStreamInterfaceDescriptor
//
int DumpExtendedVideoStreamInterfaceDescriptor (LPBYTE lpex)
{
if (lpex == 0)
return -1;
TCHAR sz[256];
int i;
PUSBVIDSTREAMIFDESCRIPTOR pDes = (PUSBVIDSTREAMIFDESCRIPTOR) lpex;
// Test access
__try {
if ((pDes->bType != 0x24) || (pDes->bSubtype != 1))
return DumpExtendedInterfaceDescriptor(lpex);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -