📄 rwiso.c
字号:
return h;
}
BOOL
compare_buffs(char *buff1,
char *buff2,
int length)
/*++
Routine Description:
Called to verify read and write buffers match for loopback test
Arguments:
buffers to compare and length
Return Value:
TRUE if buffers match, else FALSE
--*/
{
int ok = 1;
if (memcmp(buff1, buff2, length))
{
ok = 0;
}
return ok;
}
#define NPERLN 8
void
dump(
UCHAR *b,
int len
)
/*++
Routine Description:
Called to do formatted ascii dump to console of the io buffer
Arguments:
buffer and length
Return Value:
none
--*/
{
ULONG i;
ULONG longLen = (ULONG)len / sizeof(ULONG);
PULONG pBuf = (PULONG) b;
// dump an ordinal ULONG for each sizeof(ULONG)'th byte
printf("\n****** BEGIN DUMP LEN decimal %d, 0x%x\n", len,len);
for (i=0; i<longLen; i++)
{
printf("%04X ", *pBuf++);
if (i % NPERLN == (NPERLN - 1))
{
printf("\n");
}
}
if (i % NPERLN != 0)
{
printf("\n");
}
printf("\n****** END DUMP LEN decimal %d, 0x%x\n", len,len);
}
// Begin, routines for USB configuration dump (Cmdline "rwiso -u" )
//
VOID
ShowEndpointDescriptor (
PUSB_ENDPOINT_DESCRIPTOR EndpointDesc
)
/*++
Routine Description:
Called to do formatted ascii dump to console of a USB endpoint descriptor
Arguments:
ptr to USB endpoint descriptor,
Return Value:
none
--*/
{
printf("--------------------\n");
printf("Endpoint Descriptor:\n");
if (USB_ENDPOINT_DIRECTION_IN(EndpointDesc->bEndpointAddress))
{
printf("bEndpointAddress: 0x%02X IN\n",
EndpointDesc->bEndpointAddress);
}
else
{
printf("bEndpointAddress: 0x%02X OUT\n",
EndpointDesc->bEndpointAddress);
}
switch (EndpointDesc->bmAttributes & 0x03)
{
case 0x00:
printf("Transfer Type: Control\n");
break;
case 0x01:
printf("Transfer Type: Isochronous\n");
break;
case 0x02:
printf("Transfer Type: Bulk\n");
break;
case 0x03:
printf("Transfer Type: Interrupt\n");
break;
}
printf("wMaxPacketSize: 0x%04X (%d)\n",
EndpointDesc->wMaxPacketSize,
EndpointDesc->wMaxPacketSize);
printf("bInterval: 0x%02X\n",
EndpointDesc->bInterval);
}
VOID
ShowInterfaceDescriptor (
PUSB_INTERFACE_DESCRIPTOR InterfaceDesc
)
/*++
Routine Description:
Called to do formatted ascii dump to console of a USB interface descriptor
Arguments:
ptr to USB interface descriptor
Return Value:
none
--*/
{
printf("\n---------------------\n");
printf("Interface Descriptor:\n");
printf("bInterfaceNumber: 0x%02X\n",
InterfaceDesc->bInterfaceNumber);
printf("bAlternateSetting: 0x%02X\n",
InterfaceDesc->bAlternateSetting);
printf("bNumEndpoints: 0x%02X\n",
InterfaceDesc->bNumEndpoints);
printf("bInterfaceClass: 0x%02X\n",
InterfaceDesc->bInterfaceClass);
printf("bInterfaceSubClass: 0x%02X\n",
InterfaceDesc->bInterfaceSubClass);
printf("bInterfaceProtocol: 0x%02X\n",
InterfaceDesc->bInterfaceProtocol);
printf("iInterface: 0x%02X\n",
InterfaceDesc->iInterface);
}
VOID
ShowConfigurationDescriptor (
PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc
)
/*++
Routine Description:
Called to do formatted ascii dump to console of a USB config descriptor
Arguments:
ptr to USB configuration descriptor
Return Value:
none
--*/
{
printf("=========================\n");
printf("Configuration Descriptor:\n");
printf("wTotalLength: 0x%04X\n",
ConfigDesc->wTotalLength);
printf("bNumInterfaces: 0x%02X\n",
ConfigDesc->bNumInterfaces);
printf("bConfigurationValue: 0x%02X\n",
ConfigDesc->bConfigurationValue);
printf("iConfiguration: 0x%02X\n",
ConfigDesc->iConfiguration);
printf("bmAttributes: 0x%02X\n",
ConfigDesc->bmAttributes);
if (ConfigDesc->bmAttributes & 0x80)
{
printf(" Bus Powered\n");
}
if (ConfigDesc->bmAttributes & 0x40)
{
printf(" Self Powered\n");
}
if (ConfigDesc->bmAttributes & 0x20)
{
printf(" Remote Wakeup\n");
}
printf("MaxPower: 0x%02X (%d Ma)\n",
ConfigDesc->MaxPower,
ConfigDesc->MaxPower * 2);
}
VOID
ShowConfigDesc (
PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc
)
{
PUCHAR descEnd;
PUSB_COMMON_DESCRIPTOR commonDesc;
BOOLEAN ShowUnknown;
descEnd = (PUCHAR)ConfigDesc + ConfigDesc->wTotalLength;
commonDesc = (PUSB_COMMON_DESCRIPTOR)ConfigDesc;
while ((PUCHAR)commonDesc + sizeof(USB_COMMON_DESCRIPTOR) < descEnd &&
(PUCHAR)commonDesc + commonDesc->bLength <= descEnd)
{
ShowUnknown = FALSE;
switch (commonDesc->bDescriptorType)
{
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
if (commonDesc->bLength != sizeof(USB_CONFIGURATION_DESCRIPTOR))
{
ShowUnknown = TRUE;
break;
}
ShowConfigurationDescriptor((PUSB_CONFIGURATION_DESCRIPTOR)commonDesc);
break;
case USB_INTERFACE_DESCRIPTOR_TYPE:
if (commonDesc->bLength != sizeof(USB_INTERFACE_DESCRIPTOR))
{
ShowUnknown = TRUE;
break;
}
ShowInterfaceDescriptor((PUSB_INTERFACE_DESCRIPTOR)commonDesc);
break;
case USB_ENDPOINT_DESCRIPTOR_TYPE:
if (commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR))
{
ShowUnknown = TRUE;
break;
}
ShowEndpointDescriptor((PUSB_ENDPOINT_DESCRIPTOR)commonDesc);
break;
default:
ShowUnknown = TRUE;
break;
}
if (ShowUnknown)
{
// ShowUnknownDescriptor(commonDesc);
}
(PUCHAR)commonDesc += commonDesc->bLength;
}
}
void dumpUsbConfig()
/*++
Routine Description:
Called to do formatted ascii dump to console of USB
configuration, interface, and endpoint descriptors
(Cmdline "rwiso -u" )
Arguments:
none
Return Value:
none
--*/
{
HANDLE hDEV;
ULONG success;
int siz;
int nBytes;
char buf[4096];
PUSB_CONFIGURATION_DESCRIPTOR configDesc;
hDEV = open_dev();
if (hDEV && hDEV != INVALID_HANDLE_VALUE)
{
siz = sizeof(buf);
nBytes = 0;
success = DeviceIoControl(hDEV,
IOCTL_ISOUSB_GET_CONFIG_DESCRIPTOR,
buf,
siz,
buf,
siz,
&nBytes,
NULL);
NOISY(("request complete, success = %d nBytes = %d\n", success, nBytes));
configDesc = (PUSB_CONFIGURATION_DESCRIPTOR)buf;
if (success && configDesc->wTotalLength == nBytes)
{
ShowConfigDesc(configDesc);
}
CloseHandle(hDEV);
}
}
//
// End, routines for USB configuration and pipe info dump (Cmdline "rwiso -u" )
// Begin, routines for Iso Streaming
//
void
IsoStream( HANDLE hDEV, BOOL fStop )
/*++
Routine Description:
Called to start or stop an iso stream
(Cmdline "RwIso -g" )
Arguments:
handle to device
Return Value:
none
--*/
{
ULONG success;
int nBytes;
DWORD ioctl;
char i;
if (fStop)
{
ioctl = IOCTL_ISOUSB_STOP_ISO_STREAM;
for (i = 0; i < sizeof(gbuf); i++)
{
gbuf[ i ] = 0; // init outbuf to 0's to make sure read was good
}
success = DeviceIoControl(hDEV,
ioctl,
&gpStreamObj, //pointer to stream object initted when stream was started
sizeof( PVOID),
gbuf, // output buffer gets back from kernel mode
sizeof(gbuf),
&nBytes,
NULL);
NOISY(("DeviceIoControl STOP_ISO_STREAM complete, success = %d\n", success));
}
else
{
ioctl = IOCTL_ISOUSB_START_ISO_STREAM;
//input is our 256-byte buffer, binary char 0-255
for (i = 0; i < sizeof(gbuf); i++)
{
gbuf[i] = i;
}
success = DeviceIoControl(hDEV,
ioctl,
gbuf,
sizeof(gbuf),
&gpStreamObj, // will receive pointer to stream object
sizeof( PVOID),
&nBytes,
NULL);
NOISY(("DeviceIoControl START_ISO_STREAM complete, success = %d\n", success));
}
if (hDEV == INVALID_HANDLE_VALUE)
{
NOISY(("DEV not open"));
return;
}
}
void StartIsoStream( void )
{
if (!ghStreamDev)
{
ghStreamDev = open_dev();
if (ghStreamDev != INVALID_HANDLE_VALUE )
{
IsoStream(ghStreamDev, FALSE);
Sleep(gMS);
StopIsoStream();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -