WinUSB Control Transfer

Hi All,

I am developing an application to control USB device using WinUSB.

Application is able to open USB device using WInUSB and able to retrieve
data correctly with APIs

WinUsb_QueryDeviceInformation
WinUsb_QueryInterfaceSettings

and able to reset Bulk in & Out Pipe as well.

But when I am initiating any control transfer request using
WinUsb_ControlTransfer it is failing with ERROR 31( A device attached to the
system is not functioning)

Can anyone tell what could be the reason?

Thanks in advance!!

Thanks and Regards
Sunil

On 02/07/2011 08:06 AM, Sunil Kumar wrote:

But when I am initiating any control transfer request using
WinUsb_ControlTransfer it is failing with ERROR 31( A device attached to
the system is not functioning)

Can anyone tell what could be the reason?

Erm… maybe the control transfer is not handled properly by the device?

http://www.catb.org/~esr/faqs/smart-questions.html

I am working with Standard USB Mass Storage device which is working fine
with windows!!

So this could nt be the case!!

More over I am able to establish the Bulk In and Bulk Out Transfer with
winUSB.

Is it required to reset the Control Pipe before making any request?? if yes
what parameter should i give while restting WinUsb_ResetPipe

WinUsb_ResetPipe(devInfo.winUSBHandle, ??);

Thanks and Regards
Sunil
On Mon, Feb 7, 2011 at 5:58 PM, Hagen Patzke wrote:

> On 02/07/2011 08:06 AM, Sunil Kumar wrote:
> > But when I am initiating any control transfer request using
> > WinUsb_ControlTransfer it is failing with ERROR 31( A device attached to
> > the system is not functioning)
> >
> > Can anyone tell what could be the reason?
>
> Erm… maybe the control transfer is not handled properly by the device?
>
>
> http://www.catb.org/~esr/faqs/smart-questions.html
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Sunil Kumar wrote:

I am working with Standard USB Mass Storage device which is working
fine with windows!!

So this could nt be the case!!

Of course it could, depending on what control requests you are sending.
Perhaps you should post the code.

Is it required to reset the Control Pipe before making any
request?? if yes what parameter should i give while restting
WinUsb_ResetPipe

Under ordinary conditions, you should never have to reset a pipe. The
control pipe, in particular, although it can stall if it is sent a
request it does not handle, resets the stall automatically.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks Tim for Reply,

Here is the code, I am trying to read Descriptor using get descriptor
command!!

WINUSB_SETUP_PACKET SetupPacket;

ZeroMemory(&SetupPacket, sizeof(WINUSB_SETUP_PACKET));

ULONG cbSent = 0;

UCHAR ucResult[1024] = {0,};

/*

//Create the setup packet

SetupPacket.RequestType = 0x80;

SetupPacket.Request = 0x06;

SetupPacket.Value = 1;

SetupPacket.Index = 0;

SetupPacket.Length = 0x12;

bResult = WinUsb_ControlTransfer(devInfo.winUSBHandle, SetupPacket,
ucResult, 1024, &cbSent, 0);

if(!bResult)

{

dErr = GetLastError();

}

it is giving dErr = 31 (A device attached to the system is not functioning.
)

Thanks and Regards
Sunil

On Tue, Feb 8, 2011 at 12:16 AM, Tim Roberts wrote:

> Sunil Kumar wrote:
> > I am working with Standard USB Mass Storage device which is working
> > fine with windows!!
> >
> > So this could nt be the case!!
>
> Of course it could, depending on what control requests you are sending.
> Perhaps you should post the code.
>
> > Is it required to reset the Control Pipe before making any
> > request?? if yes what parameter should i give while restting
> > WinUsb_ResetPipe
>
> Under ordinary conditions, you should never have to reset a pipe. The
> control pipe, in particular, although it can stall if it is sent a
> request it does not handle, resets the stall automatically.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Sunil Kumar wrote:

Here is the code, I am trying to read Descriptor using get descriptor
command!!

WINUSB_SETUP_PACKET SetupPacket;

ZeroMemory(&SetupPacket, sizeof(WINUSB_SETUP_PACKET));

ULONG cbSent = 0;

UCHAR ucResult[1024] = {0,};

/*

//Create the setup packet

SetupPacket.RequestType = 0x80;

SetupPacket.Request = 0x06;

SetupPacket.Value = 1;

SetupPacket.Index = 0;

SetupPacket.Length = 0x12;

bResult = WinUsb_ControlTransfer(devInfo.winUSBHandle, SetupPacket,
ucResult, 1024, &cbSent, 0);

In a GET_DESCRIPTOR request, the descriptor type goes in the high-order
byte, and the descriptor index in the low order byte. So, you would
want SetupPacket.Value = 0x0100 to get your device descriptor.

Better yet would be to use the symbols:
SetupPacket.Request = USB_REQUEST_GET_DESCRIPTOR;
SetupPacket.Value = USB_DEVICE_DESCRIPTOR_TYPE << 8;
SetupPacket.Length = sizeof(USB_DEVICE_DESCRIPTOR);

Even better yet would be to throw all of that code away and actually use
the API that was designed for this:

USB_DEVICE_DESCRIPTOR device;

WinUsb_GetDescriptor(
devInfo.winUSBHandle,
USB_DEVICE_DESCRIPTOR_TYPE,
0, 0,
(PUCHAR)&device,
sizeof(USB_DEVICE_DESCRIPTOR),
&cbSent );


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Yeah Tim!!

Thanks for your reply. It started working now, I was having wrong
SetupPacket.Value!!

Regards
Sunil
On Tue, Feb 8, 2011 at 11:27 PM, Tim Roberts wrote:

> Sunil Kumar wrote:
> >
> >
> > Here is the code, I am trying to read Descriptor using get descriptor
> > command!!
> >
> > WINUSB_SETUP_PACKET SetupPacket;
> >
> > ZeroMemory(&SetupPacket, sizeof(WINUSB_SETUP_PACKET));
> >
> > ULONG cbSent = 0;
> >
> > UCHAR ucResult[1024] = {0,};
> >
> > /*
> >
> > //Create the setup packet
> >
> > SetupPacket.RequestType = 0x80;
> >
> > SetupPacket.Request = 0x06;
> >
> > SetupPacket.Value = 1;
> >
> > SetupPacket.Index = 0;
> >
> > SetupPacket.Length = 0x12;
> >
> > bResult = WinUsb_ControlTransfer(devInfo.winUSBHandle, SetupPacket,
> > ucResult, 1024, &cbSent, 0);
> >
>
> In a GET_DESCRIPTOR request, the descriptor type goes in the high-order
> byte, and the descriptor index in the low order byte. So, you would
> want SetupPacket.Value = 0x0100 to get your device descriptor.
>
> Better yet would be to use the symbols:
> SetupPacket.Request = USB_REQUEST_GET_DESCRIPTOR;
> SetupPacket.Value = USB_DEVICE_DESCRIPTOR_TYPE << 8;
> SetupPacket.Length = sizeof(USB_DEVICE_DESCRIPTOR);
>
> Even better yet would be to throw all of that code away and actually use
> the API that was designed for this:
>
> USB_DEVICE_DESCRIPTOR device;
>
> WinUsb_GetDescriptor(
> devInfo.winUSBHandle,
> USB_DEVICE_DESCRIPTOR_TYPE,
> 0, 0,
> (PUCHAR)&device,
> sizeof(USB_DEVICE_DESCRIPTOR),
> &cbSent );
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>