共用方式為


USB 裝置描述元

裝置描述項包含整體 USB 裝置的相關信息。 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.

每個通用序列總線 (USB) 裝置都必須能夠提供包含裝置相關信息的單一裝置描述元。 The USB_DEVICE_DESCRIPTOR structure describes a device descriptor. Windows 會使用該資訊來衍生各種資訊集。 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. 若要檢視特定裝置的硬體識別碼:

  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. 例如,0x0200表示裝置是根據USB 2.0規格所設計。 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. 裝置描述元也表示裝置支援的組態總數。

當裝置以高速容量連線到主計算機時,裝置可能會報告其裝置描述元中的不同資訊,而不是以完整速度容量連接時。 裝置不得在連線存留期間變更裝置描述元中包含的資訊,包括在電源狀態變更期間。

主機會透過控制項傳輸取得裝置描述項。 在傳輸中,要求類型為 GET DESCRIPTOR,而收件者是裝置。 用戶端驅動程式可以透過下列兩種方式之一起始該傳輸:使用架構 USB 目標裝置物件,或使用要求資訊傳送 URB。

取得裝置描述元

Windows Driver Frameworks (WDF) 客戶端驅動程式只能在建立架構 USB 目標裝置物件之後取得裝置描述元。

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.

主機也可以藉由傳送 URB 來取得裝置描述元。 這個方法只適用於內核模式驅動程式。 不過,除非驅動程式是以 Windows 驅動程式模型 (WDM) 為基礎,否則客戶端驅動程式不應該傳送此類型要求的 URB。 Such a driver must allocate an URB structure and then call the UsbBuildGetDescriptorRequest macro to specify format the URB for the request. 然後,驅動程式可以將 URB 提交至 USB 驅動程式堆疊,以傳送要求。 如需詳細資訊,請參閱 如何提交 URB

此程式代碼範例顯示UsbBuildGetDescriptorRequest呼叫,其會將 pURB 所指向的緩衝區格式化為適當的 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
);

範例裝置描述元

此範例顯示 USB 網路攝影機裝置的裝置描述元(請參閱 USB 裝置配置),使用 USBView 應用程式取得:

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

在上述範例中,裝置已根據USB規格2.0版進行開發。 Note the bDeviceClass, bDeviceSubClass, and bDeviceProtocol values. 這些值表示裝置包含一或多個USB介面關聯描述元,可用來將每個函式的多個介面分組。 如需詳細資訊,請參閱 USB介面關聯描述元

Next, see the value of bMaxPacketSize0. 此值表示預設端點的封包大小上限。 此範例裝置可以透過預設端點傳輸最多64個字節的數據。

一般而言,若要設定裝置,用戶端驅動程式會在取得裝置描述元之後,取得裝置中支援設定的相關信息。 To determine the number of configurations that the device supports, inspect the bNumConfigurations member of the returned structure. 此裝置支援一個設定。 若要取得 USB 設定的相關信息,驅動程式必須取得 USB 設定描述元