📄 usbdebug.cpp
字号:
PBYTE pEnd = lpex + pDes->wTotalLen;
int nNumFmts = *(lpex+3);
DEBUGMSG (1, (TEXT("Video Stream interface Descriptor Header\r\n")));
if (pDes->bLen >= 0x0d)
{
DEBUGMSG (1, (TEXT("\t Subtype: %02xh\r\n"), pDes->bSubtype));
DEBUGMSG (1, (TEXT("\t Num Formats: %d\r\n"), pDes->bNumFormats));
DEBUGMSG (1, (TEXT("\t Total Length: %04xh\r\n"), pDes->wTotalLen));
DEBUGMSG (1, (TEXT("\t EndPoint Addr: %02xh\r\n"), pDes->bEndpointAddress));
DEBUGMSG (1, (TEXT("\t bmInfo: %02xh\r\n"), pDes->bmInfo));
DEBUGMSG (1, (TEXT("\t Terminal Link: %02xh\r\n"), pDes->bTerminalLink));
DEBUGMSG (1, (TEXT("\t Still Capture Method %02xh\r\n"), pDes->bStillCapMethod));
DEBUGMSG (1, (TEXT("\t Trigger Support %02xh\r\n"), pDes->bTriggerSupport));
DEBUGMSG (1, (TEXT("\t Trigger Usage %02xh\r\n"), pDes->bTriggerUsage));
int z;
DEBUGMSG (1, (TEXT("\t Control Size %02xh\r\n"), pDes->bControlSize));
PBYTE p = pDes->bmaControls;
for (z = 0; z < pDes->bNumFormats; z++, p += pDes->bControlSize)
{
DumpByteStream (p, pDes->bControlSize, sz, dim (sz));
DEBUGMSG (1, (TEXT("\t bmControls: %d >%s<\r\n"), z, sz));
}
}
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 USB_VIDEO_VS_STILL_IMAGE_FRAME:
DEBUGMSG (1, (TEXT("Still Image Frame\r\n")));
{
DEBUGMSG (1, (TEXT("\t Endpoint Address: %02xh\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Num Image Sizes: %d\r\n"), *(lpex+4)));
PBYTE p = lpex+5;
int k;
for (k = 0; k < *(lpex+4); k++) {
int x = Num (p, 2);
int y = Num (p+2, 2);
DEBUGMSG (1, (TEXT("\t Img %2d %3d x %3d\r\n"), k, x, y));
p += 4;
}
// Get compression values
int m = *p++;
DEBUGMSG (1, (TEXT("\t Compression cnt %d\r\n"), m));
for (k = 0; k < m; k++)
{
DEBUGMSG (1, (TEXT("\t Cmp %2d %d\r\n"), k, *p++));
}
}
break;
case USB_VIDEO_VS_FORMAT_UNCOMPRESSED:
DEBUGMSG (1, (TEXT("Format Uncompressed\r\n")));
if (pStd->bLen >= 27)
{
DEBUGMSG (1, (TEXT("\t Format Index: %d\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Num Descriptors: %d\r\n"), *(lpex+4)));
DumpGUID (lpex+5);
DEBUGMSG (1, (TEXT("\t BitsPerPixel %02xh\r\n"), *(lpex+21)));
DEBUGMSG (1, (TEXT("\t Default Frame Index %d\r\n"), *(lpex+22)));
DEBUGMSG (1, (TEXT("\t Aspect Ratio X: %d\r\n"), *(lpex+23)));
DEBUGMSG (1, (TEXT("\t Aspect Ratio Y: %d\r\n"), *(lpex+24)));
DEBUGMSG (1, (TEXT("\t Interlace Flags: %02xh\r\n"), *(lpex+25)));
DEBUGMSG (1, (TEXT("\t CopyProtect Flag: %02xh\r\n"), *(lpex+26)));
}
break;
case USB_VIDEO_VS_FRAME_UNCOMPRESSED:
DEBUGMSG (1, (TEXT("Frame Uncompressed\r\n")));
if (pStd->bLen >= 30)
{
DEBUGMSG (1, (TEXT("\t Frame Index: %d\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Capabilities: %02xh\r\n"), *(lpex+4)));
DEBUGMSG (1, (TEXT("\t Width: %d\r\n"), Num(lpex+5, 2)));
DEBUGMSG (1, (TEXT("\t Height: %d\r\n"), Num(lpex+7, 2)));
DEBUGMSG (1, (TEXT("\t Min Bit Rate: %d\r\n"), Num(lpex+9, 4)));
DEBUGMSG (1, (TEXT("\t Max Bit Rate: %d\r\n"), Num(lpex+13, 4)));
DEBUGMSG (1, (TEXT("\t Max Framebuff Size: %d\r\n"), Num(lpex+17, 4)));
DEBUGMSG (1, (TEXT("\t Def Interval: %d\r\n"), Num(lpex+21, 4)));
int k;
k = Num (lpex+25, 1);
if (k == 0)
{
DEBUGMSG (1, (TEXT("\t Min Frame Interval: %d\r\n"), Num (lpex+26, 4)));
DEBUGMSG (1, (TEXT("\t Max Frame Interval: %d\r\n"), Num (lpex+30, 4)));
DEBUGMSG (1, (TEXT("\t Frame Interval Step: %d\r\n"), Num (lpex+34, 4)));
} else
{
DEBUGMSG (1, (TEXT("\t Frame interval Cnt: %d\r\n"), *(lpex+25)));
PBYTE p = lpex+26;
for (k = 0; k < *(lpex+25); k++)
{
int t = Num (p, 4);
if (t <= 10000)
DEBUGMSG (1, (TEXT("\t Frame Interval: %d %7d %3d.%03d mS (%2d fps)\r\n"),
k, t, t/10000, (t/10)%1000, 1000/(t/10000)));
else
DEBUGMSG (1, (TEXT("\t Frame Interval: %d %7d\r\n"), k, t));
p += 4;
}
}
}
break;
case USB_VIDEO_VS_FORMAT_MJPEG:
DEBUGMSG (1, (TEXT("Format MJPEG\r\n")));
if (pStd->bLen >= 11)
{
DEBUGMSG (1, (TEXT("\t Format Index: %d\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Num Descriptors: %d\r\n"), *(lpex+4)));
DEBUGMSG (1, (TEXT("\t bmFlags %02xh\r\n"), *(lpex+5)));
DEBUGMSG (1, (TEXT("\t Default Frame Index %d\r\n"), *(lpex+6)));
DEBUGMSG (1, (TEXT("\t Aspect Ratio X: %d\r\n"), *(lpex+7)));
DEBUGMSG (1, (TEXT("\t Aspect Ratio Y: %d\r\n"), *(lpex+8)));
DEBUGMSG (1, (TEXT("\t Interlace Flags: %02xh\r\n"), *(lpex+9)));
DEBUGMSG (1, (TEXT("\t CopyProtect Flag: %02xh\r\n"), *(lpex+10)));
}
break;
case USB_VIDEO_VS_FRAME_MJPEG:
DEBUGMSG (1, (TEXT("Frame MJPEG\r\n")));
if (pStd->bLen >= 30)
{
DEBUGMSG (1, (TEXT("\t Frame Index: %d\r\n"), *(lpex+3)));
DEBUGMSG (1, (TEXT("\t Capabilities: %02xh\r\n"), *(lpex+4)));
DEBUGMSG (1, (TEXT("\t Width: %d\r\n"), Num(lpex+5, 2)));
DEBUGMSG (1, (TEXT("\t Height: %d\r\n"), Num(lpex+7, 2)));
DEBUGMSG (1, (TEXT("\t Min Bit Rate: %d\r\n"), Num(lpex+9, 4)));
DEBUGMSG (1, (TEXT("\t Max Bit Rate: %d\r\n"), Num(lpex+13, 4)));
DEBUGMSG (1, (TEXT("\t Max Framebuff Size: %d\r\n"), Num(lpex+17, 4)));
DEBUGMSG (1, (TEXT("\t Def Interval: %d\r\n"), Num(lpex+21, 4)));
int k;
k = Num (lpex+25, 1);
if (k == 0)
{
DEBUGMSG (1, (TEXT("\t Min Frame Interval: %d\r\n"), Num (lpex+26, 4)));
DEBUGMSG (1, (TEXT("\t Max Frame Interval: %d\r\n"), Num (lpex+30, 4)));
DEBUGMSG (1, (TEXT("\t Frame Interval Step: %d\r\n"), Num (lpex+34, 4)));
} else
{
DEBUGMSG (1, (TEXT("\t Frame interval Cnt: %d\r\n"), *(lpex+25)));
PBYTE p = lpex+26;
for (k = 0; k < *(lpex+25); k++)
{
int t = Num (p, 4);
if (t <= 10000)
DEBUGMSG (1, (TEXT("\t Frame Interval: %d %7d %3d.%03d mS (%2d fps)\r\n"),
k, t, t/10000, (t/10)%1000, 1000/(t/10000)));
else
DEBUGMSG (1, (TEXT("\t Frame Interval: %d %7d\r\n"), k, t));
p += 4;
}
}
}
break;
case 0x8:
case 0x9:
case 0x0b:
case 0x0e:
case 0x0f:
DEBUGMSG (1, (TEXT(" ***** Reserved\r\n")));
break;
case USB_VIDEO_VS_FORMAT_MPEG2TS:
DEBUGMSG (1, (TEXT(" ***** Format MPEG2TS\r\n")));
break;
case USB_VIDEO_VS_COLORFORMAT:
DEBUGMSG (1, (TEXT("Color Format\r\n")));
if (pStd->bLen >= 6)
{
PUSBVIDCOLORIFDESCRIPTOR p = (PUSBVIDCOLORIFDESCRIPTOR)lpex;
DEBUGMSG (1, (TEXT("\t bColorPrimaries: %02x\r\n"), p->bColorPrimaries));
DEBUGMSG (1, (TEXT("\t bTransferCharacteristics: %02x\r\n"), p->bTransferCharacteristics));
DEBUGMSG (1, (TEXT("\t bMatrixCoefficients %02xh\r\n"), p->bMatrixCoefficients));
}
break;
case USB_VIDEO_VS_FORMAT_FRAME_BASED:
DEBUGMSG (1, (TEXT(" ***** Format Frame Based\r\n")));
break;
case USB_VIDEO_VS_FRAME_FRAME_BASED:
DEBUGMSG (1, (TEXT(" ***** Frame Frame Based\r\n")));
break;
case USB_VIDEO_VS_FORMAT_STREAM_BASED:
DEBUGMSG (1, (TEXT(" ***** Format Stream Based\r\n")));
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;
}
//------------------------------------------------------------------------
//
//
int DumpUsbInterface (LPCUSB_INTERFACE lpif)
{
DEBUGMSG (1, (TEXT("================================\r\n")));
DEBUGMSG (1, (TEXT("USB Interface\r\n")));
if (lpif->dwCount != sizeof (USB_INTERFACE))
DEBUGMSG (1, (TEXT("Unexpected USB_INTERFACE size dwCount: %d ***********\r\n"), lpif->dwCount));
DumpInterfaceDescriptor (&lpif->Descriptor);
if (lpif->lpvExtended)
{
// if (lpif->Descriptor.bInterfaceClass == 0x0e) //video
// {
__try
{
if (lpif->Descriptor.bInterfaceSubClass == 0x01) //Control
DumpExtendedVideoControlInterfaceDescriptor ((LPBYTE) lpif->lpvExtended);
else if (lpif->Descriptor.bInterfaceSubClass == 0x02) //Stream
DumpExtendedVideoStreamInterfaceDescriptor ((LPBYTE) lpif->lpvExtended);
else
DumpExtendedInterfaceDescriptor ((LPBYTE) lpif->lpvExtended);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG (1, (TEXT("Exception dumping endpoints\r\n")));
return -1;
}
// }
// else
// DumpExtendedInterfaceDescriptor ((LPBYTE) lpif->lpvExtended);
}
int i;
if (lpif->lpEndpoints)
{
__try
{
LPCUSB_ENDPOINT ep = lpif->lpEndpoints;
for (i = 0; i < lpif->Descriptor.bNumEndpoints; i++)
{
DumpUsbEndpoint(ep, i);
ep = (LPCUSB_ENDPOINT)((DWORD) ep + ep->dwCount);
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG (1, (TEXT("Exception dumping endpoints\r\n")));
return -1;
}
}
return 0;
}
//------------------------------------------------------------------------
// Retrieves the requested string descriptor and validates it.
//
DWORD GetStringDescriptor (USB_HANDLE hDevice, LPCUSB_FUNCS lpUsbFuncs,
BYTE bIdx, WORD wLangId, PBYTE pbBuffer, WORD cbBuffer, PDWORD pbTransferred)
{
PUSB_STRING_DESCRIPTOR pStringDesc = (PUSB_STRING_DESCRIPTOR) pbBuffer;
USB_ERROR usbErr;
USB_TRANSFER hTransfer;
DWORD dwErr;
DEBUGCHK(cbBuffer >= sizeof(USB_STRING_DESCRIPTOR));
DEBUGCHK(pbTransferred != NULL);
hTransfer = lpUsbFuncs->lpGetDescriptor (hDevice, NULL, NULL,
USB_SHORT_TRANSFER_OK, USB_STRING_DESCRIPTOR_TYPE, bIdx,
wLangId, cbBuffer, pbBuffer);
if (hTransfer != NULL) {
GetTransferStatus (lpUsbFuncs, hTransfer, pbTransferred, &usbErr);
CloseTransferHandle(lpUsbFuncs, hTransfer);
if (usbErr != USB_NO_ERROR) {
if (usbErr == USB_STALL_ERROR) {
dwErr = ERROR_NOT_SUPPORTED;
}
else {
dwErr = ERROR_GEN_FAILURE;
}
goto EXIT;
}
}
else {
dwErr = GetLastError();
goto EXIT;
}
// We've got a descriptor. Is it valid?
if ( (*pbTransferred < (sizeof(USB_STRING_DESCRIPTOR) - sizeof(pStringDesc->bString))) ||
(pStringDesc->bDescriptorType != USB_STRING_DESCRIPTOR_TYPE) ) {
DEBUGCHK(FALSE); // The device returned something strange.
dwErr = ERROR_GEN_FAILURE;
goto EXIT;
}
dwErr = ERROR_SUCCESS;
EXIT:
if (dwErr != ERROR_SUCCESS) {
DEBUGMSG(1, (_T("%s: Error getting string descriptor Err=%u\r\n"),
dwErr));
}
return dwErr;
}
//-----------------------------------------------------------------------------
// Get a device string. For predefined types see hiddi.h.
//
DWORD GetUsbString (USB_HANDLE hDevice, LPCUSB_FUNCS lpUsbFuncs, UCHAR id, LPTSTR sz, int nSize)
{
PCUSB_DEVICE pDeviceInfo = NULL;
DWORD dwErr;
WORD wLangId;
DWORD dwBytesTransferred;
const DWORD CB_STRING_DESCRIPTOR_MAX = 0xff;
union {
BYTE rgbBuffer[CB_STRING_DESCRIPTOR_MAX];
USB_STRING_DESCRIPTOR StringDesc;
} StringDescriptor;
// Get the Zero string descriptor to determine which LANGID to use.
// We just use the first LANGID listed.
dwErr = GetStringDescriptor (hDevice, lpUsbFuncs, 0, 0, (PBYTE) &StringDescriptor,
sizeof(StringDescriptor), &dwBytesTransferred);
if (dwErr != ERROR_SUCCESS) {
goto EXIT;
}
DEBUGCHK(StringDescriptor.StringDesc.bLength >= sizeof(USB_STRING_DESCRIPTOR));
DEBUGCHK(StringDescriptor.StringDesc.bDescriptorType == USB_STRING_DESCRIPTOR_TYPE);
wLangId = StringDescriptor.StringDesc.bString[0];
// Get the string descriptor for the first LANGID
dwErr = GetStringDescriptor(hDevice, lpUsbFuncs, id, wLangId, (PBYTE) &StringDescriptor,
sizeof(StringDescriptor), &dwBytesTransferred);
if (dwErr != ERROR_SUCCESS) {
goto EXIT;
}
__try {
// Copy the character count and string into the user's buffer
int cchActual = (StringDescriptor.StringDesc.bLength - 2) / sizeof(WCHAR); // Does not include NULL
if (sz != NULL) {
StringCchCopyN(sz, nSize,
StringDescriptor.StringDesc.bString, cchActual);
}
}
__except (EXCEPTION_EXECUTE_HANDLER) {
DEBUGMSG(1, (_T("GetUSBString: Exception writing to user buffer\r\n")));
dwErr = ERROR_INVALID_PARAMETER;
}
EXIT:
return dwErr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -