Dela via


USB-enhetsbeskrivningar

Enhetsbeskrivningen innehåller information om en USB-enhet som helhet. This article describes the USB_DEVICE_DESCRIPTOR structure and includes information about how a client driver can send a get-descriptor request to obtain the device descriptor.

Varje USB-enhet (Universal Serial Bus) måste kunna tillhandahålla en enda enhetsbeskrivning som innehåller relevant information om enheten. The USB_DEVICE_DESCRIPTOR structure describes a device descriptor. Windows använder den informationen för att härleda olika typer av information. For example, the idVendor and idProduct fields specify vendor and product identifiers, respectively. Windows uses those field values to construct a hardware ID for the device. Så här visar du maskinvaru-ID för en viss enhet:

  1. Open Device Manager.
  2. Right-click on the USB device and select Properties.
  3. Select the Details tab in the properties dialog box.
  4. Drop down the Property list.
  5. Select the Hardware Ids property

The values indicate the hardware IDs ("USB\XXX") that Windows generates.

The bcdUSB field of the USB_DEVICE_DESCRIPTOR structure indicates the version of the USB specification to which the device conforms. Till exempel anger 0x0200 att enheten är utformad enligt USB 2.0-specifikationen. The bcdDevice value indicates the device-defined revision number.

The USB driver stack uses bcdDevice, along with idVendor and idProduct, to generate hardware and compatible IDs for the device. You can view those identifiers in Device Manager. Enhetsbeskrivningen anger också det totala antalet konfigurationer som enheten stöder.

En enhet kan rapportera annan information i sin enhetsbeskrivning när enheten ansluter till värddatorn i en hög hastighetskapacitet än när den ansluter i en kapacitet med full hastighet. En enhet får inte ändra informationen i enhetsbeskrivningen under en anslutning, inklusive vid ändringar i energitillståndet.

Värden hämtar enhetsbeskrivningen via en kontrollöverföring. I överföringen är begärandetypen GET DESCRIPTOR och mottagaren är enheten. Klientdrivrutinen kan initiera överföringen på något av två sätt: genom att använda ramverkets USB-målenhetsobjekt eller genom att skicka en URB med begärandeinformationen.

Hämta enhetsbeskrivningen

En WDF-klientdrivrutin (Windows Driver Frameworks) kan hämta enhetsbeskrivningen först när ramverkets USB-målenhetsobjekt har skapats.

A Kernel-Mode Driver Framework (KMDF) driver must obtain a WDFUSBDEVICE handle to the USB target device object by calling WdfUsbTargetDeviceCreate. Typically, a client driver calls WdfUsbTargetDeviceCreate in the driver's EvtDevicePrepareHardware callback implementation. After that, the client driver must call the WdfUsbTargetDeviceGetDeviceDescriptor method. After the call completes, the device descriptor is received in the caller-allocated USB_DEVICE_DESCRIPTOR structure.

A User-Mode Driver Framework (UMDF) driver must query the framework device object for an IWDFUsbTargetDevice pointer and then call the IWDFUsbTargetDevice::RetrieveDescriptor method and specify USB_DEVICE_DESCRIPTOR_TYPE as the descriptor type.

Värden kan också hämta enhetsbeskrivningen genom att skicka en URB. Den här metoden gäller endast för drivrutiner i kernelläge. En klientdrivrutin ska dock aldrig behöva skicka en URB för den här typen av begäran såvida inte drivrutinen baseras på Windows Driver Model (WDM). Such a driver must allocate an URB structure and then call the UsbBuildGetDescriptorRequest macro to specify format the URB for the request. Drivrutinen kan sedan skicka begäran genom att skicka URB till USB-drivrutinsstacken. För mer information, se Hur man skickar in en URB.

Det här kodexemplet visar ett UsbBuildGetDescriptorRequest-anrop som formaterar bufferten som pekas på av pURB med lämplig URB:

UsbBuildGetDescriptorRequest(
    pURB,                                                 // Points to the URB to be formatted
    sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
    USB_DEVICE_DESCRIPTOR_TYPE,
    0,                                                    // Not used for device descriptors
    0,                                                    // Not used for device descriptors
    pDescriptor,                                          // Points to a USB_DEVICE_DESCRIPTOR structure
    NULL,
    sizeof(USB_DEVICE_DESCRIPTOR),
    NULL
);

Exempel på enhetsbeskrivning

Det här exemplet visar enhetsbeskrivningen för en USB-webbkameraenhet (se USB-enhetslayout) som hämtas med hjälp av USBView-programmet:

Device Descriptor:
bcdUSB:             0x0200
bDeviceClass:         0xEF
bDeviceSubClass:      0x02
bDeviceProtocol:      0x01
bMaxPacketSize0:      0x40 (64)
idVendor:           0x045E (Microsoft Corporation)
idProduct:          0x0728
bcdDevice:          0x0100
iManufacturer:        0x01
0x0409: "Microsoft"
iProduct:             0x02
0x0409: "Microsoft LifeCam VX-5000"
0x0409: "Microsoft LifeCam VX-5000"
iSerialNumber:        0x00
bNumConfigurations:   0x01

I föregående exempel utvecklades enheten enligt USB-specifikation, version 2.0. Note the bDeviceClass, bDeviceSubClass, and bDeviceProtocol values. Dessa värden anger att enheten innehåller en eller flera USB-gränssnittsassociationer som kan användas för att gruppera flera gränssnitt per funktion. Mer information finns i USB Interface Association Descriptor.

Next, see the value of bMaxPacketSize0. Det här värdet anger den maximala paketstorleken för standardslutpunkten. Den här exempelenheten kan överföra upp till 64 byte data via standardslutpunkten.

För att konfigurera enheten hämtar klientdrivrutinen vanligtvis information om de konfigurationer som stöds på enheten när enhetsbeskrivningen har hämtats. To determine the number of configurations that the device supports, inspect the bNumConfigurations member of the returned structure. Den här enheten stöder en konfiguration. För att få information om en USB-konfiguration måste drivrutinen hämta USB-konfigurationsbeskrivningar.