1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "device/usb/usb_descriptors.h"
12 const uint8_t kStringDescriptorType
= 0x03;
15 UsbEndpointDescriptor::UsbEndpointDescriptor()
17 direction(USB_DIRECTION_INBOUND
),
18 maximum_packet_size(0),
19 synchronization_type(USB_SYNCHRONIZATION_NONE
),
20 transfer_type(USB_TRANSFER_CONTROL
),
21 usage_type(USB_USAGE_DATA
),
25 UsbEndpointDescriptor::~UsbEndpointDescriptor() {
28 UsbInterfaceDescriptor::UsbInterfaceDescriptor()
29 : interface_number(0),
32 interface_subclass(0),
33 interface_protocol(0) {
36 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() {
39 UsbConfigDescriptor::UsbConfigDescriptor()
40 : configuration_value(0),
46 UsbConfigDescriptor::~UsbConfigDescriptor() {
49 bool ParseUsbStringDescriptor(const std::vector
<uint8_t>& descriptor
,
50 base::string16
* output
) {
51 if (descriptor
.size() < 2 || descriptor
[1] != kStringDescriptorType
) {
54 // Let the device return a buffer larger than the actual string but prefer the
55 // length reported inside the descriptor.
56 size_t length
= descriptor
[0];
57 length
= std::min(length
, descriptor
.size());
60 } else if (length
== 2) {
61 // Special case to avoid indexing beyond the end of |descriptor|.
62 *output
= base::string16();
64 *output
= base::string16(
65 reinterpret_cast<const base::char16
*>(&descriptor
[2]), length
/ 2 - 1);