次の方法で共有


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. 特定のデバイスのハードウェア ID を表示するには:

  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 を送信するという 2 つの方法のいずれかで転送を開始できます。

デバイス記述子の取得

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 Driver Model (WDM) に基づいている場合を除き、クライアント ドライバーはこの種類の要求に対して URB を送信する必要はありません。 Such a driver must allocate an URB structure and then call the UsbBuildGetDescriptorRequest macro to specify format the URB for the request. ドライバーは、USB ドライバー スタックに URB を送信することによって要求を送信できます。 詳細については、「URB の送信方法」に関する記事を参照してください。

このコード例は、pURB が指すバッファを適切な URB でフォーマットする UsbBuildGetDescriptorRequest 呼び出しを示しています。

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
);

サンプル デバイス記述子

USBView アプリケーションを使用して取得した USB Web カメラ デバイスのデバイス記述子 (「USB デバイス レイアウト」を参照) の例を次に示します。

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. これらの値は、機能ごとに複数のインターフェイスをグループ化するために使用できる 1 つ以上の 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. このデバイスは 1 つの構成をサポートします。 USB 構成に関する情報を取得するには、ドライバーが USB 構成記述子を取得する必要があります。