Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > How to get descriptors of usb device?

Reply
Thread Tools Display Modes

How to get descriptors of usb device?

 
 
RB
Guest
Posts: n/a

 
      09-07-2004
I want to get descriptors (device, string, etc.) of the usb storage
device.
Actually, I need to know the following device properties:
vid, pid, manufacturer, product name, serial number, device bus speed,
maxpacketsize (from endpoint descriptors) and maxpower (from config.
descriptor).

This is the part of my code.

HDEVINFO DeviceInfo ;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData ;
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceDetailData ;
ULONG index ;
ULONG RequiredLength ;
BOOL IsMoreDeviceInterfaces ;
SP_DEVINFO_DATA DeviceInfoData ;


DeviceInfo = SetupDiGetClassDevs ((LPGUID)&GUID_CLASS_USB_DEVICE,
NULL,
NULL,
(DIGCF_PRESENT |
IGCF_DEVICEINTERFACE)) ;

DeviceInterfaceData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA) ;

index = 0 ;
while (TRUE == SetupDiEnumDeviceInterfaces (DeviceInfo,
0,

(LPGUID)&GUID_CLASS_USB_DEVICE,
index,
&DeviceInterfaceData
))
{
SetupDiGetDeviceInterfaceDetail ( DeviceInfo,
&DeviceInterfaceData,
NULL,
0,
&RequiredLength,
NULL ) ;

DeviceDetailData =
(PSP_DEVICE_INTERFACE_DETAIL_DATA)GlobalAlloc (GPTR, RequiredLength) ;
DeviceDetailData->cbSize = sizeof
(SP_DEVICE_INTERFACE_DETAIL_DATA) ;
DeviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA) ;

SetupDiGetDeviceInterfaceDetail ( DeviceInfo,
&DeviceInterfaceData,
DeviceDetailData,
RequiredLength,
&RequiredLength,
&DeviceInfoData );

/////////////////////////////////////////////////////////////////
// THE QUESTION IS: //
// HERE I WANT TO OBTAIN THE DEVICE DESCRIPTORS. HOW TO DO IT? //
/////////////////////////////////////////////////////////////////

index++ ;
}

================================================== ===============
Additional questions:
What is the handle returned in DeviceInfoData.DevInst? Is it the same
that returned from CreateFile by drive letter path (\\.\E or by
symbolic name (\\?\usb#vid_0fc5&pid_1222#0123456789abcdef#{a5dcb f10-6530-11d2-901f-00404fb853ed})
or what else?

Thanks in advance
Rita
 
Reply With Quote
 
 
 
 
Doron Holan [MS]
Guest
Posts: n/a

 
      09-07-2004
look at usbview in the ddk.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"RB" <> wrote in message
news: om...
>I want to get descriptors (device, string, etc.) of the usb storage
> device.
> Actually, I need to know the following device properties:
> vid, pid, manufacturer, product name, serial number, device bus speed,
> maxpacketsize (from endpoint descriptors) and maxpower (from config.
> descriptor).
>
> This is the part of my code.
>
> HDEVINFO DeviceInfo ;
> SP_DEVICE_INTERFACE_DATA DeviceInterfaceData ;
> PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceDetailData ;
> ULONG index ;
> ULONG RequiredLength ;
> BOOL IsMoreDeviceInterfaces ;
> SP_DEVINFO_DATA DeviceInfoData ;
>
>
> DeviceInfo = SetupDiGetClassDevs ((LPGUID)&GUID_CLASS_USB_DEVICE,
> NULL,
> NULL,
> (DIGCF_PRESENT |
> IGCF_DEVICEINTERFACE)) ;
>
> DeviceInterfaceData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA) ;
>
> index = 0 ;
> while (TRUE == SetupDiEnumDeviceInterfaces (DeviceInfo,
> 0,
>
> (LPGUID)&GUID_CLASS_USB_DEVICE,
> index,
> &DeviceInterfaceData
> ))
> {
> SetupDiGetDeviceInterfaceDetail ( DeviceInfo,
> &DeviceInterfaceData,
> NULL,
> 0,
> &RequiredLength,
> NULL ) ;
>
> DeviceDetailData =
> (PSP_DEVICE_INTERFACE_DETAIL_DATA)GlobalAlloc (GPTR, RequiredLength) ;
> DeviceDetailData->cbSize = sizeof
> (SP_DEVICE_INTERFACE_DETAIL_DATA) ;
> DeviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA) ;
>
> SetupDiGetDeviceInterfaceDetail ( DeviceInfo,
> &DeviceInterfaceData,
> DeviceDetailData,
> RequiredLength,
> &RequiredLength,
> &DeviceInfoData );
>
> /////////////////////////////////////////////////////////////////
> // THE QUESTION IS: //
> // HERE I WANT TO OBTAIN THE DEVICE DESCRIPTORS. HOW TO DO IT? //
> /////////////////////////////////////////////////////////////////
>
> index++ ;
> }
>
> ================================================== ===============
> Additional questions:
> What is the handle returned in DeviceInfoData.DevInst? Is it the same
> that returned from CreateFile by drive letter path (\\.\E or by
> symbolic name
> (\\?\usb#vid_0fc5&pid_1222#0123456789abcdef#{a5dcb f10-6530-11d2-901f-00404fb853ed})
> or what else?
>
> Thanks in advance
> Rita



 
Reply With Quote
 
 
 
 
RB
Guest
Posts: n/a

 
      09-08-2004
Thank you, Doron, but USBVIEW way isn't it.
In USBVIEW this done by enumeration controllers, hubs and ports and
descriptors obtained from DeviceIoControl() with
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, hub handle and port
number.

SetupDixxx functions makes the devices enumeration process easier and
shorter.

So, is there any way to get descriptors directly after retrieving
information about device from SetupDixxx?

If not, how to retrieve the Hub name or handle and port number that
the device connected to them in order to use
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION (like in USBVIEW)?

Thanks,
Rita


"Doron Holan [MS]" <> wrote in message news:<>...
> look at usbview in the ddk.
>
> d
>
>

 
Reply With Quote
 
Robert Marquardt
Guest
Posts: n/a

 
      09-08-2004
RB wrote:

> So, is there any way to get descriptors directly after retrieving
> information about device from SetupDixxx?


AFAIK no.
Another idiot design by MS.
 
Reply With Quote
 
RB
Guest
Posts: n/a

 
      09-08-2004
Too bad! ;-(

Robert Marquardt <> wrote in message news:<#zy$>...
> RB wrote:
>
> > So, is there any way to get descriptors directly after retrieving
> > information about device from SetupDixxx?

>
> AFAIK no.
> Another idiot design by MS.

 
Reply With Quote
 
Ray Trent
Guest
Posts: n/a

 
      09-08-2004
Geez... MS gets bashed for including too many incompatible interfaces,
and also when they don't.

Think about the motivation for spending valuable development time to
make this easy:

There are 3 cases:

1) It's a HID device, and you can get all the info you really ought to
care about using the HID functions.

2) It's an MS controlled device, in which case you really shouldn't be
messing with it without already knowing what you're doing and what
device you're attached to.

3) It's another kind of USB device, in which case you have to have a
driver for it, and that driver can contain whatever interface you want.

The only case that's not covered is the 2 people that want to write
usbview or an enhanced version of that... Ok, so it's a pain...

RB wrote:

> Too bad! ;-(
>
> Robert Marquardt <> wrote in message news:<#zy$>...
>
>>RB wrote:
>>
>>
>>>So, is there any way to get descriptors directly after retrieving
>>>information about device from SetupDixxx?

>>
>>AFAIK no.
>>Another idiot design by MS.


--
.../ray\..

Please remove ".spamblock" from my email address if you need to contact
me outside the newsgroup.
 
Reply With Quote
 
Robert Marquardt
Guest
Posts: n/a

 
      09-09-2004
Ray Trent wrote:

> 1) It's a HID device, and you can get all the info you really ought to
> care about using the HID functions.


Denying developers the complete information is always a bad idea.

> 2) It's an MS controlled device, in which case you really shouldn't be
> messing with it without already knowing what you're doing and what
> device you're attached to.


THe HID API is specifically designed to allow to handle an unknown HID
device.

> 3) It's another kind of USB device, in which case you have to have a
> driver for it, and that driver can contain whatever interface you want.


Sorry, USBVIEW itself shows that the complete information about the
device is stored in the OS, but the interface to access it (aka Usbview
way to ask the hub driver) is unsupported and does not allow to match
the devices as enumerated through the official API.
Worse there was a statement in this newsgroup that the Usbview API may
be removed from future OS versions.

> The only case that's not covered is the 2 people that want to write
> usbview or an enhanced version of that... Ok, so it's a pain...


Sorry, there are more programmers out there who think that the Windows
USB API sucks.
 
Reply With Quote
 
Ray Trent
Guest
Posts: n/a

 
      09-09-2004
Robert Marquardt wrote:
>
>> 1) It's a HID device, and you can get all the info you really ought to
>> care about using the HID functions.

> Denying developers the complete information is always a bad idea.


I don't even agree with this in general. Abstraction is a good thing,
among other things. Exposing data structures, for example, is a recipe
for a non-forward compatible operating system. And the complaint here is
that you can get all the information, you just can't do it they way the
OP wants to.

>> 2) It's an MS controlled device, in which case you really shouldn't be
>> messing with it without already knowing what you're doing and what
>> device you're attached to.

> THe HID API is specifically designed to allow to handle an unknown HID
> device.


Yes, well, that would be case one. I'm more talking about things like
USB flash drives. The only reason you would want descriptors is a)
you're trying to do something that you probably shouldn't be doing, or
b) you're writing usbview or an enhanced version. In either case, having
the API be somewhat difficult doesn't seem like an insurmountable problem.

> Sorry, USBVIEW itself shows that the complete information about the
> device is stored in the OS, but the interface to access it (aka Usbview
> way to ask the hub driver) is unsupported and does not allow to match


Ok, this at least is a reasonable objection. I would expect, though,
that if they remove this interface, it will be replaced with another one
(hopefully better... I'm not going to argue that the Windows USB API is
wonderful). Why borrow trouble?

> the devices as enumerated through the official API.


Ummm, bet you a dollar there's a way to do this. Might require parsing
registry key names, though... not pleasant, I admit, but the need for
this capability is pretty obscure anyway.

> Worse there was a statement in this newsgroup that the Usbview API may
> be removed from future OS versions.


Don't believe everything you hear here. Including this :-).

My main objection to this was that the OP asked a question, got a
(correct) answer, and then said something akin to "I don't like that
answer, that's too hard.".
--
.../ray\..

Please remove ".spamblock" from my email address if you need to contact
me outside the newsgroup.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
USB string descriptors and Vista Leo Havm°ller Windows Vista Drivers 9 12-16-2006 12:38 PM
USB HID Report descriptors for Windows Media Player lptguy Windows Vista Drivers 2 06-08-2006 01:19 AM
About USB device and interface descriptors shahar Windows Vista Drivers 0 08-12-2004 01:17 AM
USB audio descriptors claire Windows Vista Drivers 0 07-09-2004 03:40 PM
USB Configuration Descriptors Andrew Windows Vista Drivers 0 12-01-2003 04:04 PM