OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 module device.usb; | |
6 | |
7 enum OpenDeviceError { | |
8 // Opening the device succeeded. | |
9 OK, | |
10 | |
11 // The operating system denied access to the device. | |
12 ACCESS_DENIED, | |
13 }; | |
14 | |
15 enum TransferDirection { | |
16 INBOUND, | |
17 OUTBOUND, | |
18 }; | |
19 | |
20 enum ControlTransferType { | |
21 STANDARD, | |
22 CLASS, | |
23 VENDOR, | |
24 RESERVED | |
25 }; | |
26 | |
27 enum ControlTransferRecipient { | |
28 DEVICE, | |
29 INTERFACE, | |
30 ENDPOINT, | |
31 OTHER | |
32 }; | |
33 | |
34 enum EndpointType { | |
35 BULK, | |
36 INTERRUPT, | |
37 ISOCHRONOUS, | |
38 }; | |
39 | |
40 struct EndpointInfo { | |
41 uint8 endpoint_number; | |
42 TransferDirection direction; | |
43 EndpointType type; | |
44 uint32 packet_size; | |
45 }; | |
46 | |
47 struct AlternateInterfaceInfo { | |
48 uint8 alternate_setting; | |
49 uint8 class_code; | |
50 uint8 subclass_code; | |
51 uint8 protocol_code; | |
52 string? interface_name; | |
53 array<EndpointInfo> endpoints; | |
54 }; | |
55 | |
56 struct InterfaceInfo { | |
57 uint8 interface_number; | |
58 array<AlternateInterfaceInfo> alternates; | |
59 }; | |
60 | |
61 struct ConfigurationInfo { | |
62 uint8 configuration_value; | |
63 string? configuration_name; | |
64 array<InterfaceInfo> interfaces; | |
65 }; | |
66 | |
67 struct WebUsbFunctionSubset { | |
68 uint8 first_interface; | |
69 array<string> origins; | |
70 }; | |
71 | |
72 struct WebUsbConfigurationSubset { | |
73 uint8 configuration_value; | |
74 array<string> origins; | |
75 array<WebUsbFunctionSubset> functions; | |
76 }; | |
77 | |
78 struct WebUsbDescriptorSet { | |
79 array<string> origins; | |
80 array<WebUsbConfigurationSubset> configurations; | |
81 }; | |
82 | |
83 struct DeviceInfo { | |
84 string guid; | |
85 uint8 usb_version_major; | |
86 uint8 usb_version_minor; | |
87 uint8 usb_version_subminor; | |
88 uint8 class_code; | |
89 uint8 subclass_code; | |
90 uint8 protocol_code; | |
91 uint16 vendor_id; | |
92 uint16 product_id; | |
93 uint8 device_version_major; | |
94 uint8 device_version_minor; | |
95 uint8 device_version_subminor; | |
96 string? manufacturer_name; | |
97 string? product_name; | |
98 string? serial_number; | |
99 array<ConfigurationInfo> configurations; | |
100 WebUsbDescriptorSet? webusb_allowed_origins; | |
101 }; | |
102 | |
103 struct ControlTransferParams { | |
104 ControlTransferType type; | |
105 ControlTransferRecipient recipient; | |
106 uint8 request; | |
107 uint16 value; | |
108 uint16 index; | |
109 }; | |
110 | |
111 enum TransferStatus { | |
112 // The transfer completed successfully. | |
113 COMPLETED, | |
114 | |
115 // The transfer failed due to a non-specific error. | |
116 TRANSFER_ERROR, | |
117 | |
118 // The transfer was not allowed. | |
119 PERMISSION_DENIED, | |
120 | |
121 // The transfer timed out. | |
122 TIMEOUT, | |
123 | |
124 // The transfer was cancelled. | |
125 CANCELLED, | |
126 | |
127 // The transfer stalled. | |
128 STALLED, | |
129 | |
130 // The transfer failed because the device was disconnected from the host. | |
131 DISCONNECT, | |
132 | |
133 // The transfer succeeded, but the device sent more data than was requested. | |
134 // This applies only to inbound transfers. | |
135 BABBLE, | |
136 | |
137 // The transfer succeeded, but the device sent less data than was requested. | |
138 // This applies only to inbound transfers. | |
139 SHORT_PACKET, | |
140 }; | |
141 | |
142 struct IsochronousPacket { | |
143 uint32 length; | |
144 uint32 transferred_length; | |
145 TransferStatus status; | |
146 }; | |
147 | |
148 interface Device { | |
149 // Retrieve a DeviceInfo struct containing metadata about the device, | |
150 // including the set of all available device configurations. | |
151 GetDeviceInfo() => (DeviceInfo? info); | |
152 | |
153 // Retrieves the |configuration_value| of the device's currently active | |
154 // configuration. Will return 0 if the device is unconfigured. | |
155 GetConfiguration() => (uint8 value); | |
156 | |
157 // Opens the device. Methods below require the device be opened first. | |
158 Open() => (OpenDeviceError error); | |
159 | |
160 // Closes the device. | |
161 Close() => (); | |
162 | |
163 // Initiates a device control transfer to set the device's configuration to | |
164 // one with the configuration value |value|. | |
165 SetConfiguration(uint8 value) => (bool success); | |
166 | |
167 // Claims a single interface in the current device configuration. | |
168 ClaimInterface(uint8 interface_number) => (bool success); | |
169 | |
170 // Releases a claimed interface in the current device configuration. | |
171 ReleaseInterface(uint8 interface_number) => (bool success); | |
172 | |
173 // Selects an alternate setting for a given claimed interface. | |
174 SetInterfaceAlternateSetting(uint8 interface_number, uint8 alternate_setting) | |
175 => (bool success); | |
176 | |
177 // Resets the device. | |
178 Reset() => (bool success); | |
179 | |
180 // Clear the halt/stall condition for an endpoint. | |
181 ClearHalt(uint8 endpoint) => (bool success); | |
182 | |
183 // Initiates an inbound control transfer request. |params| determine the | |
184 // details of the request. Transfers to recipients other than DEVICE require a | |
185 // corresponding interface to be claimed. | |
186 // | |
187 // |length| specifies the expected number of bytes to receive for this | |
188 // transfer. The size of |data| will never exceed |length|, and |data| will be | |
189 // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET. | |
190 // | |
191 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | |
192 // indicates no timeout: the request will remain pending indefinitely until | |
193 // completed or otherwise terminated. | |
194 ControlTransferIn(ControlTransferParams params, uint32 length, uint32 timeout) | |
195 => (TransferStatus status, array<uint8>? data); | |
196 | |
197 // Initiates an inbound control transfer request. |params| determine the | |
198 // details of the request. Transfers to recipients other than DEVICE require a | |
199 // corresponding interface to be claimed. | |
200 // | |
201 // |data| specifies the bytes to send the device in the body of the request. | |
202 // | |
203 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | |
204 // indicates no timeout: the request will remain pending indefinitely until | |
205 // completed or otherwise terminated. | |
206 ControlTransferOut(ControlTransferParams params, | |
207 array<uint8> data, | |
208 uint32 timeout) | |
209 => (TransferStatus status); | |
210 | |
211 // Initiates an inbound generic transfer request on a specific endpoint. The | |
212 // interface to which |endpoint_number| belongs must be claimed, and the | |
213 // appropriate alternate setting must be set on that interface before | |
214 // transfers can be initiated on the endpoint. The endpoint must be of type | |
215 // BULK or INTERRUPT. | |
216 // | |
217 // |length| specifies the expected number of bytes to receive for this | |
218 // transfer. The size of |data| will never exceed |length|, and |data| will be | |
219 // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET. | |
220 // | |
221 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | |
222 // indicates no timeout: the request will remain pending indefinitely until | |
223 // completed or otherwise terminated. | |
224 GenericTransferIn(uint8 endpoint_number, uint32 length, uint32 timeout) | |
225 => (TransferStatus status, array<uint8>? data); | |
226 | |
227 // Initiates an outbound generic transfer request on a specific endpoint. The | |
228 // interface to which |endpoint_number| belongs must be claimed, and the | |
229 // appropriate alternate setting must be set on that interface before | |
230 // transfers can be initiated on the endpoint. The endpoint must be of type | |
231 // BULK or INTERRUPT. | |
232 // | |
233 // |data| specifies the bytes to send the device in the body of the request. | |
234 // | |
235 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | |
236 // indicates no timeout: the request will remain pending indefinitely until | |
237 // completed or otherwise terminated. | |
238 GenericTransferOut(uint8 endpoint_number, array<uint8> data, uint32 timeout) | |
239 => (TransferStatus status); | |
240 | |
241 // Initiates an inbound isochronous transfer request on a specific endpoint. | |
242 // The interface to which |endpoint_number| belongs must be claimed, and the | |
243 // appropriate alternate setting must be set on that interface before | |
244 // transfers can be initiated on the endpoint. The endpoint must be of type | |
245 // ISOCHRONOUS. | |
246 // | |
247 // |packet_lengths| specifies the maximum expected number of bytes to receive | |
248 // for each packet in this transfer. | |
249 // | |
250 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | |
251 // indicates no timeout: the request will remain pending indefinitely until | |
252 // completed or otherwise terminated. | |
253 // | |
254 // |data| contains the data received from the device, if any. |packets| | |
255 // contains the status of each packet received from the device, in order. The | |
256 // length of the packet indicates its position in |data| while it's | |
257 // transferred length gives the amount of data actually received from the | |
258 // device. | |
259 IsochronousTransferIn(uint8 endpoint_number, | |
260 array<uint32> packet_lengths, | |
261 uint32 timeout) | |
262 => (array<uint8>? data, array<IsochronousPacket> packets); | |
263 | |
264 // Initiates an outbound isochronous transfer request on a specific endpoint. | |
265 // The interface to which |endpoint_number| belongs must be claimed, and the | |
266 // appropriate alternate setting must be set on that interface before | |
267 // transfers can be initiated on the endpoint. The endpoint must be of type | |
268 // ISOCHRONOUS. | |
269 // | |
270 // |data| specifies the bytes to send to the device. | |
271 // | |
272 // |packet_lengths| specifies how |data| should be separated into packets when | |
273 // it is sent to the device. | |
274 // | |
275 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | |
276 // indicates no timeout: the request will remain pending indefinitely until | |
277 // completed or otherwise terminated. | |
278 | |
279 // |packets| contains the status of each packet sent to the device, in order. | |
280 IsochronousTransferOut(uint8 endpoint_number, | |
281 array<uint8> data, | |
282 array<uint32> packet_lengths, | |
283 uint32 timeout) | |
284 => (array<IsochronousPacket> packets); | |
285 }; | |
OLD | NEW |