How to get descriptors of usb device?

Discussion in 'Windows Vista Drivers' started by RB, Sep 7, 2004.

  1. RB

    RB Guest

    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#{a5dcbf10-6530-11d2-901f-00404fb853ed})
    or what else?

    Thanks in advance
    Rita
    RB, Sep 7, 2004
    #1
    1. Advertising

  2. 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:...
    >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#{a5dcbf10-6530-11d2-901f-00404fb853ed})
    > or what else?
    >
    > Thanks in advance
    > Rita
    Doron Holan [MS], Sep 7, 2004
    #2
    1. Advertising

  3. RB

    RB Guest

    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
    >
    >
    RB, Sep 8, 2004
    #3
  4. 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.
    Robert Marquardt, Sep 8, 2004
    #4
  5. RB

    RB Guest

    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.
    RB, Sep 8, 2004
    #5
  6. RB

    Ray Trent Guest

    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.
    Ray Trent, Sep 8, 2004
    #6
  7. 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.
    Robert Marquardt, Sep 9, 2004
    #7
  8. RB

    Ray Trent Guest

    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.
    Ray Trent, Sep 9, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. claire

    USB audio descriptors

    claire, Jul 9, 2004, in forum: Windows Vista Drivers
    Replies:
    0
    Views:
    184
    claire
    Jul 9, 2004
  2. shahar

    About USB device and interface descriptors

    shahar, Aug 12, 2004, in forum: Windows Vista Drivers
    Replies:
    0
    Views:
    437
    shahar
    Aug 12, 2004
  3. Guest
    Replies:
    0
    Views:
    697
    Guest
    Jul 21, 2006
  4. cancri7
    Replies:
    1
    Views:
    680
    Robert Marquardt
    Jun 7, 2007
  5. Sri
    Replies:
    0
    Views:
    252
Loading...

Share This Page