| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #include "chrome/browser/usb/usb_interface.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/libusb/src/libusb/libusb.h" |
| 9 |
| 10 UsbEndpointDescriptor::UsbEndpointDescriptor( |
| 11 scoped_refptr<const UsbConfigDescriptor> config, |
| 12 PlatformUsbEndpointDescriptor descriptor) |
| 13 : config_(config), descriptor_(descriptor) { |
| 14 } |
| 15 |
| 16 UsbEndpointDescriptor::~UsbEndpointDescriptor() {} |
| 17 |
| 18 int UsbEndpointDescriptor::GetAddress() const { |
| 19 return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; |
| 20 } |
| 21 |
| 22 UsbInterfaceDirection UsbEndpointDescriptor::GetDirection() const { |
| 23 switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) { |
| 24 case LIBUSB_ENDPOINT_IN: |
| 25 return USB_DIRECTION_INBOUND; |
| 26 case LIBUSB_ENDPOINT_OUT: |
| 27 return USB_DIRECTION_OUTBOUND; |
| 28 } |
| 29 NOTREACHED(); |
| 30 return USB_DIRECTION_INBOUND; |
| 31 } |
| 32 |
| 33 int UsbEndpointDescriptor::GetMaximumPacketSize() const { |
| 34 return descriptor_->wMaxPacketSize; |
| 35 } |
| 36 |
| 37 UsbEndpointType UsbEndpointDescriptor::GetEndpointType() const { |
| 38 switch (descriptor_->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) { |
| 39 case LIBUSB_TRANSFER_TYPE_CONTROL: |
| 40 return USB_ENDPOINT_CONTROL; |
| 41 case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS: |
| 42 return USB_ENDPOINT_ISOCHRONOUS; |
| 43 case LIBUSB_TRANSFER_TYPE_BULK: |
| 44 return USB_ENDPOINT_BULK; |
| 45 case LIBUSB_TRANSFER_TYPE_INTERRUPT: |
| 46 return USB_ENDPOINT_INTERRUPT; |
| 47 } |
| 48 NOTREACHED(); |
| 49 return USB_ENDPOINT_CONTROL; |
| 50 } |
| 51 |
| 52 UsbSynchronizationType UsbEndpointDescriptor::GetSynchronizationType() const { |
| 53 switch (descriptor_->bmAttributes & LIBUSB_ISO_SYNC_TYPE_MASK) { |
| 54 case LIBUSB_ISO_SYNC_TYPE_NONE: |
| 55 return USB_SYNCHRONIZATION_NONE; |
| 56 case LIBUSB_ISO_SYNC_TYPE_ASYNC: |
| 57 return USB_SYNCHRONIZATION_ASYNCHRONOUS; |
| 58 case LIBUSB_ISO_SYNC_TYPE_ADAPTIVE: |
| 59 return USB_SYNCHRONIZATION_ADAPTIVE; |
| 60 case LIBUSB_ISO_SYNC_TYPE_SYNC: |
| 61 return USB_SYNCHRONIZATION_SYNCHRONOUS; |
| 62 } |
| 63 NOTREACHED(); |
| 64 return USB_SYNCHRONIZATION_NONE; |
| 65 } |
| 66 |
| 67 UsbUsageType UsbEndpointDescriptor::GetUsageType() const { |
| 68 switch (descriptor_->bmAttributes & LIBUSB_ISO_USAGE_TYPE_MASK) { |
| 69 case LIBUSB_ISO_USAGE_TYPE_DATA: |
| 70 return USB_USAGE_DATA; |
| 71 case LIBUSB_ISO_USAGE_TYPE_FEEDBACK: |
| 72 return USB_USAGE_FEEDBACK; |
| 73 case LIBUSB_ISO_USAGE_TYPE_IMPLICIT: |
| 74 return USB_USAGE_EXPLICIT_FEEDBACK; |
| 75 } |
| 76 NOTREACHED(); |
| 77 return USB_USAGE_DATA; |
| 78 } |
| 79 |
| 80 int UsbEndpointDescriptor::GetPollingInterval() const { |
| 81 return descriptor_->bInterval; |
| 82 } |
| 83 |
| 84 UsbInterfaceDescriptor::UsbInterfaceDescriptor( |
| 85 scoped_refptr<const UsbConfigDescriptor> config, |
| 86 PlatformUsbInterfaceDescriptor descriptor) |
| 87 : config_(config), descriptor_(descriptor) { |
| 88 } |
| 89 |
| 90 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() {} |
| 91 |
| 92 size_t UsbInterfaceDescriptor::numEndpoints() const { |
| 93 return descriptor_->bNumEndpoints; |
| 94 } |
| 95 |
| 96 scoped_refptr<const UsbEndpointDescriptor> |
| 97 UsbInterfaceDescriptor::getEndpoint(size_t index) const { |
| 98 return make_scoped_refptr(new UsbEndpointDescriptor(config_, |
| 99 &descriptor_->endpoint[index])); |
| 100 } |
| 101 |
| 102 int UsbInterfaceDescriptor::GetInterfaceNumber() const { |
| 103 return descriptor_->bInterfaceNumber; |
| 104 } |
| 105 |
| 106 int UsbInterfaceDescriptor::GetAlternateSetting() const { |
| 107 return descriptor_->bAlternateSetting; |
| 108 } |
| 109 |
| 110 int UsbInterfaceDescriptor::GetInterfaceClass() const { |
| 111 return descriptor_->bInterfaceClass; |
| 112 } |
| 113 |
| 114 int UsbInterfaceDescriptor::GetInterfaceSubclass() const { |
| 115 return descriptor_->bInterfaceSubClass; |
| 116 } |
| 117 |
| 118 int UsbInterfaceDescriptor::GetInterfaceProtocol() const { |
| 119 return descriptor_->bInterfaceProtocol; |
| 120 } |
| 121 |
| 122 UsbInterface::UsbInterface(scoped_refptr<const UsbConfigDescriptor> config, |
| 123 PlatformUsbInterface usbInterface) |
| 124 : config_(config), interface_(usbInterface) { |
| 125 } |
| 126 |
| 127 UsbInterface::~UsbInterface() {} |
| 128 |
| 129 size_t UsbInterface::numAltSettings() const { |
| 130 return interface_->num_altsetting; |
| 131 } |
| 132 |
| 133 scoped_refptr<const UsbInterfaceDescriptor> |
| 134 UsbInterface::getAltSetting(size_t index) const { |
| 135 return make_scoped_refptr(new UsbInterfaceDescriptor(config_, |
| 136 &interface_->altsetting[index])); |
| 137 } |
| 138 |
| 139 UsbConfigDescriptor::UsbConfigDescriptor(PlatformUsbConfigDescriptor config) |
| 140 : config_(config) { |
| 141 } |
| 142 |
| 143 UsbConfigDescriptor::~UsbConfigDescriptor() {} |
| 144 |
| 145 size_t UsbConfigDescriptor::numInterfaces() const { |
| 146 return config_->bNumInterfaces; |
| 147 } |
| 148 |
| 149 scoped_refptr<const UsbInterface> |
| 150 UsbConfigDescriptor::getInterface(size_t index) const { |
| 151 return make_scoped_refptr(new UsbInterface(make_scoped_refptr(this), |
| 152 &config_->interface[index])); |
| 153 } |
| OLD | NEW |