2 * Copyright 2007-2008, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Michael Lotz <mmlr@mlotz.ch>
15 BUSBEndpoint::BUSBEndpoint(BUSBInterface
*interface
, uint32 index
, int rawFD
)
16 : fInterface(interface
),
20 usb_raw_command command
;
21 command
.endpoint_etc
.descriptor
= &fDescriptor
;
22 command
.endpoint_etc
.config_index
= fInterface
->Configuration()->Index();
23 command
.endpoint_etc
.interface_index
= fInterface
->Index();
24 command
.endpoint_etc
.alternate_index
= fInterface
->AlternateIndex();
25 command
.endpoint_etc
.endpoint_index
= fIndex
;
26 if (ioctl(fRawFD
, B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC
, &command
,
27 sizeof(command
)) || command
.endpoint_etc
.status
!= B_USB_RAW_STATUS_SUCCESS
)
28 memset(&fDescriptor
, 0, sizeof(fDescriptor
));
32 BUSBEndpoint::~BUSBEndpoint()
38 BUSBEndpoint::Index() const
45 BUSBEndpoint::Interface() const
51 const BUSBConfiguration
*
52 BUSBEndpoint::Configuration() const
54 return fInterface
->Configuration();
59 BUSBEndpoint::Device() const
61 return fInterface
->Device();
66 BUSBEndpoint::IsBulk() const
68 return (fDescriptor
.attributes
& USB_ENDPOINT_ATTR_MASK
)
69 == USB_ENDPOINT_ATTR_BULK
;
74 BUSBEndpoint::IsInterrupt() const
76 return (fDescriptor
.attributes
& USB_ENDPOINT_ATTR_MASK
)
77 == USB_ENDPOINT_ATTR_INTERRUPT
;
82 BUSBEndpoint::IsIsochronous() const
84 return (fDescriptor
.attributes
& USB_ENDPOINT_ATTR_MASK
)
85 == USB_ENDPOINT_ATTR_ISOCHRONOUS
;
90 BUSBEndpoint::IsControl() const
92 return (fDescriptor
.attributes
& USB_ENDPOINT_ATTR_MASK
)
93 == USB_ENDPOINT_ATTR_CONTROL
;
98 BUSBEndpoint::IsInput() const
100 return (fDescriptor
.endpoint_address
& USB_ENDPOINT_ADDR_DIR_IN
)
101 == USB_ENDPOINT_ADDR_DIR_IN
;
106 BUSBEndpoint::IsOutput() const
108 return (fDescriptor
.endpoint_address
& USB_ENDPOINT_ADDR_DIR_IN
)
109 == USB_ENDPOINT_ADDR_DIR_OUT
;
114 BUSBEndpoint::MaxPacketSize() const
116 return fDescriptor
.max_packet_size
;
121 BUSBEndpoint::Interval() const
123 return fDescriptor
.interval
;
127 const usb_endpoint_descriptor
*
128 BUSBEndpoint::Descriptor() const
135 BUSBEndpoint::ControlTransfer(uint8 requestType
, uint8 request
, uint16 value
,
136 uint16 index
, uint16 length
, void *data
) const
138 if (length
> 0 && data
== NULL
)
141 usb_raw_command command
;
142 command
.control
.request_type
= requestType
;
143 command
.control
.request
= request
;
144 command
.control
.value
= value
;
145 command
.control
.index
= index
;
146 command
.control
.length
= length
;
147 command
.control
.data
= data
;
149 if (ioctl(fRawFD
, B_USB_RAW_COMMAND_CONTROL_TRANSFER
, &command
,
150 sizeof(command
)) || command
.control
.status
!= B_USB_RAW_STATUS_SUCCESS
)
153 return command
.control
.length
;
158 BUSBEndpoint::InterruptTransfer(void *data
, size_t length
) const
160 if (length
> 0 && data
== NULL
)
163 usb_raw_command command
;
164 command
.transfer
.interface
= fInterface
->Index();
165 command
.transfer
.endpoint
= fIndex
;
166 command
.transfer
.data
= data
;
167 command
.transfer
.length
= length
;
169 if (ioctl(fRawFD
, B_USB_RAW_COMMAND_INTERRUPT_TRANSFER
, &command
,
170 sizeof(command
)) || command
.transfer
.status
!= B_USB_RAW_STATUS_SUCCESS
)
173 return command
.transfer
.length
;
178 BUSBEndpoint::BulkTransfer(void *data
, size_t length
) const
180 if (length
> 0 && data
== NULL
)
183 usb_raw_command command
;
184 command
.transfer
.interface
= fInterface
->Index();
185 command
.transfer
.endpoint
= fIndex
;
186 command
.transfer
.data
= data
;
187 command
.transfer
.length
= length
;
189 if (ioctl(fRawFD
, B_USB_RAW_COMMAND_BULK_TRANSFER
, &command
,
190 sizeof(command
)) || command
.transfer
.status
!= B_USB_RAW_STATUS_SUCCESS
)
193 return command
.transfer
.length
;
198 BUSBEndpoint::IsochronousTransfer(void *data
, size_t length
,
199 usb_iso_packet_descriptor
*packetDescriptors
, uint32 packetCount
) const
201 if (length
> 0 && data
== NULL
)
204 usb_raw_command command
;
205 command
.isochronous
.interface
= fInterface
->Index();
206 command
.isochronous
.endpoint
= fIndex
;
207 command
.isochronous
.data
= data
;
208 command
.isochronous
.length
= length
;
209 command
.isochronous
.packet_descriptors
= packetDescriptors
;
210 command
.isochronous
.packet_count
= packetCount
;
212 if (ioctl(fRawFD
, B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER
, &command
,
213 sizeof(command
)) || command
.isochronous
.status
!= B_USB_RAW_STATUS_SUCCESS
)
216 return command
.isochronous
.length
;
221 BUSBEndpoint::IsStalled() const
224 Device()->ControlTransfer(USB_REQTYPE_ENDPOINT_IN
,
225 USB_REQUEST_GET_STATUS
, USB_FEATURE_ENDPOINT_HALT
,
226 fDescriptor
.endpoint_address
, sizeof(status
), &status
);
232 BUSBEndpoint::ClearStall() const
234 return Device()->ControlTransfer(USB_REQTYPE_ENDPOINT_OUT
,
235 USB_REQUEST_CLEAR_FEATURE
, USB_FEATURE_ENDPOINT_HALT
,
236 fDescriptor
.endpoint_address
, 0, NULL
);