blob: d5a1e0fcdff74a96e098d89560452a9b66934289 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/usb/usb_interface.h"
#include "base/logging.h"
#include "third_party/libusb/src/libusb/libusb.h"
UsbEndpointDescriptor::UsbEndpointDescriptor(
scoped_refptr<const UsbConfigDescriptor> config,
PlatformUsbEndpointDescriptor descriptor)
: config_(config), descriptor_(descriptor) {
}
UsbEndpointDescriptor::~UsbEndpointDescriptor() {}
int UsbEndpointDescriptor::GetAddress() const {
return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK;
}
UsbEndpointDirection UsbEndpointDescriptor::GetDirection() const {
switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) {
case LIBUSB_ENDPOINT_IN:
return USB_DIRECTION_INBOUND;
case LIBUSB_ENDPOINT_OUT:
return USB_DIRECTION_OUTBOUND;
default:
NOTREACHED();
return USB_DIRECTION_INBOUND;
}
}
int UsbEndpointDescriptor::GetMaximumPacketSize() const {
return descriptor_->wMaxPacketSize;
}
UsbSynchronizationType UsbEndpointDescriptor::GetSynchronizationType() const {
switch (descriptor_->bmAttributes & LIBUSB_ISO_SYNC_TYPE_MASK) {
case LIBUSB_ISO_SYNC_TYPE_NONE:
return USB_SYNCHRONIZATION_NONE;
case LIBUSB_ISO_SYNC_TYPE_ASYNC:
return USB_SYNCHRONIZATION_ASYNCHRONOUS;
case LIBUSB_ISO_SYNC_TYPE_ADAPTIVE:
return USB_SYNCHRONIZATION_ADAPTIVE;
case LIBUSB_ISO_SYNC_TYPE_SYNC:
return USB_SYNCHRONIZATION_SYNCHRONOUS;
default:
NOTREACHED();
return USB_SYNCHRONIZATION_NONE;
}
}
UsbTransferType UsbEndpointDescriptor::GetTransferType() const {
switch (descriptor_->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
return USB_TRANSFER_CONTROL;
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
return USB_TRANSFER_ISOCHRONOUS;
case LIBUSB_TRANSFER_TYPE_BULK:
return USB_TRANSFER_BULK;
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
return USB_TRANSFER_INTERRUPT;
default:
NOTREACHED();
return USB_TRANSFER_CONTROL;
}
}
UsbUsageType UsbEndpointDescriptor::GetUsageType() const {
switch (descriptor_->bmAttributes & LIBUSB_ISO_USAGE_TYPE_MASK) {
case LIBUSB_ISO_USAGE_TYPE_DATA:
return USB_USAGE_DATA;
case LIBUSB_ISO_USAGE_TYPE_FEEDBACK:
return USB_USAGE_FEEDBACK;
case LIBUSB_ISO_USAGE_TYPE_IMPLICIT:
return USB_USAGE_EXPLICIT_FEEDBACK;
default:
NOTREACHED();
return USB_USAGE_DATA;
}
}
int UsbEndpointDescriptor::GetPollingInterval() const {
return descriptor_->bInterval;
}
UsbInterfaceAltSettingDescriptor::UsbInterfaceAltSettingDescriptor(
scoped_refptr<const UsbConfigDescriptor> config,
PlatformUsbInterfaceDescriptor descriptor)
: config_(config), descriptor_(descriptor) {
}
UsbInterfaceAltSettingDescriptor::~UsbInterfaceAltSettingDescriptor() {}
size_t UsbInterfaceAltSettingDescriptor::GetNumEndpoints() const {
return descriptor_->bNumEndpoints;
}
scoped_refptr<const UsbEndpointDescriptor>
UsbInterfaceAltSettingDescriptor::GetEndpoint(size_t index) const {
return new UsbEndpointDescriptor(config_, &descriptor_->endpoint[index]);
}
int UsbInterfaceAltSettingDescriptor::GetInterfaceNumber() const {
return descriptor_->bInterfaceNumber;
}
int UsbInterfaceAltSettingDescriptor::GetAlternateSetting() const {
return descriptor_->bAlternateSetting;
}
int UsbInterfaceAltSettingDescriptor::GetInterfaceClass() const {
return descriptor_->bInterfaceClass;
}
int UsbInterfaceAltSettingDescriptor::GetInterfaceSubclass() const {
return descriptor_->bInterfaceSubClass;
}
int UsbInterfaceAltSettingDescriptor::GetInterfaceProtocol() const {
return descriptor_->bInterfaceProtocol;
}
UsbInterfaceDescriptor::UsbInterfaceDescriptor(
scoped_refptr<const UsbConfigDescriptor> config,
PlatformUsbInterface usbInterface)
: config_(config), interface_(usbInterface) {
}
UsbInterfaceDescriptor::~UsbInterfaceDescriptor() {}
size_t UsbInterfaceDescriptor::GetNumAltSettings() const {
return interface_->num_altsetting;
}
scoped_refptr<const UsbInterfaceAltSettingDescriptor>
UsbInterfaceDescriptor::GetAltSetting(size_t index) const {
return new UsbInterfaceAltSettingDescriptor(config_,
&interface_->altsetting[index]);
}
UsbConfigDescriptor::UsbConfigDescriptor(PlatformUsbConfigDescriptor config)
: config_(config) {
}
UsbConfigDescriptor::~UsbConfigDescriptor() {
if (config_ != NULL) {
libusb_free_config_descriptor(config_);
config_ = NULL;
}
}
size_t UsbConfigDescriptor::GetNumInterfaces() const {
return config_->bNumInterfaces;
}
scoped_refptr<const UsbInterfaceDescriptor>
UsbConfigDescriptor::GetInterface(size_t index) const {
return new UsbInterfaceDescriptor(this, &config_->interface[index]);
}
|