-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusb_endpoint_descriptor.cc
82 lines (65 loc) · 2.37 KB
/
usb_endpoint_descriptor.cc
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
// Copyright (c) 2013 The Chromium OS 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 "mist/usb_endpoint_descriptor.h"
#include <libusb.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
namespace mist {
UsbEndpointDescriptor::UsbEndpointDescriptor(
const libusb_endpoint_descriptor* endpoint_descriptor)
: endpoint_descriptor_(endpoint_descriptor) {
CHECK(endpoint_descriptor_);
}
uint8_t UsbEndpointDescriptor::GetLength() const {
return endpoint_descriptor_->bLength;
}
uint8_t UsbEndpointDescriptor::GetDescriptorType() const {
return endpoint_descriptor_->bDescriptorType;
}
uint8_t UsbEndpointDescriptor::GetEndpointAddress() const {
return endpoint_descriptor_->bEndpointAddress;
}
uint8_t UsbEndpointDescriptor::GetEndpointNumber() const {
return GetEndpointAddress() & LIBUSB_ENDPOINT_ADDRESS_MASK;
}
uint8_t UsbEndpointDescriptor::GetAttributes() const {
return endpoint_descriptor_->bmAttributes;
}
uint16_t UsbEndpointDescriptor::GetMaxPacketSize() const {
return endpoint_descriptor_->wMaxPacketSize;
}
uint8_t UsbEndpointDescriptor::GetInterval() const {
return endpoint_descriptor_->bInterval;
}
UsbDirection UsbEndpointDescriptor::GetDirection() const {
uint8_t direction = GetEndpointAddress() & LIBUSB_ENDPOINT_DIR_MASK;
return (direction == LIBUSB_ENDPOINT_IN) ? kUsbDirectionIn : kUsbDirectionOut;
}
UsbTransferType UsbEndpointDescriptor::GetTransferType() const {
return static_cast<UsbTransferType>(GetAttributes() &
LIBUSB_TRANSFER_TYPE_MASK);
}
std::string UsbEndpointDescriptor::ToString() const {
return base::StringPrintf(
"Endpoint (Length=%u, "
"DescriptorType=%u, "
"EndpointAddress=0x%02x, "
"EndpointNumber=%u, "
"Attributes=0x%02x, "
"MaxPacketSize=%u, "
"Interval=%u, "
"Direction=%s, "
"TransferType=%s)",
GetLength(), GetDescriptorType(), GetEndpointAddress(),
GetEndpointNumber(), GetAttributes(), GetMaxPacketSize(), GetInterval(),
UsbDirectionToString(GetDirection()),
UsbTransferTypeToString(GetTransferType()));
}
} // namespace mist
std::ostream& operator<<(
std::ostream& stream,
const mist::UsbEndpointDescriptor& endpoint_descriptor) {
stream << endpoint_descriptor.ToString();
return stream;
}