OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 module device.usb; | 5 module device.mojom; |
6 | 6 |
7 enum OpenDeviceError { | 7 enum UsbOpenDeviceError { |
8 // Opening the device succeeded. | 8 // Opening the device succeeded. |
9 OK, | 9 OK, |
10 | 10 |
11 // The operating system denied access to the device. | 11 // The operating system denied access to the device. |
12 ACCESS_DENIED, | 12 ACCESS_DENIED, |
13 | 13 |
14 // The device is already open. | 14 // The device is already open. |
15 ALREADY_OPEN, | 15 ALREADY_OPEN, |
16 }; | 16 }; |
17 | 17 |
18 enum TransferDirection { | 18 enum UsbTransferDirection { |
19 INBOUND, | 19 INBOUND, |
20 OUTBOUND, | 20 OUTBOUND, |
21 }; | 21 }; |
22 | 22 |
23 enum ControlTransferType { | 23 enum UsbControlTransferType { |
24 STANDARD, | 24 STANDARD, |
25 CLASS, | 25 CLASS, |
26 VENDOR, | 26 VENDOR, |
27 RESERVED | 27 RESERVED |
28 }; | 28 }; |
29 | 29 |
30 enum ControlTransferRecipient { | 30 enum UsbControlTransferRecipient { |
31 DEVICE, | 31 DEVICE, |
32 INTERFACE, | 32 INTERFACE, |
33 ENDPOINT, | 33 ENDPOINT, |
34 OTHER | 34 OTHER |
35 }; | 35 }; |
36 | 36 |
37 enum EndpointType { | 37 enum UsbEndpointType { |
38 BULK, | 38 BULK, |
39 INTERRUPT, | 39 INTERRUPT, |
40 ISOCHRONOUS, | 40 ISOCHRONOUS, |
41 }; | 41 }; |
42 | 42 |
43 struct EndpointInfo { | 43 struct UsbEndpointInfo { |
44 uint8 endpoint_number; | 44 uint8 endpoint_number; |
45 TransferDirection direction; | 45 UsbTransferDirection direction; |
46 EndpointType type; | 46 UsbEndpointType type; |
47 uint32 packet_size; | 47 uint32 packet_size; |
48 }; | 48 }; |
49 | 49 |
50 struct AlternateInterfaceInfo { | 50 struct UsbAlternateInterfaceInfo { |
51 uint8 alternate_setting; | 51 uint8 alternate_setting; |
52 uint8 class_code; | 52 uint8 class_code; |
53 uint8 subclass_code; | 53 uint8 subclass_code; |
54 uint8 protocol_code; | 54 uint8 protocol_code; |
55 string? interface_name; | 55 string? interface_name; |
56 array<EndpointInfo> endpoints; | 56 array<UsbEndpointInfo> endpoints; |
57 }; | 57 }; |
58 | 58 |
59 struct InterfaceInfo { | 59 struct UsbInterfaceInfo { |
60 uint8 interface_number; | 60 uint8 interface_number; |
61 array<AlternateInterfaceInfo> alternates; | 61 array<UsbAlternateInterfaceInfo> alternates; |
62 }; | 62 }; |
63 | 63 |
64 struct ConfigurationInfo { | 64 struct UsbConfigurationInfo { |
65 uint8 configuration_value; | 65 uint8 configuration_value; |
66 string? configuration_name; | 66 string? configuration_name; |
67 array<InterfaceInfo> interfaces; | 67 array<UsbInterfaceInfo> interfaces; |
68 }; | 68 }; |
69 | 69 |
70 struct DeviceInfo { | 70 struct UsbDeviceInfo { |
71 string guid; | 71 string guid; |
72 uint8 usb_version_major; | 72 uint8 usb_version_major; |
73 uint8 usb_version_minor; | 73 uint8 usb_version_minor; |
74 uint8 usb_version_subminor; | 74 uint8 usb_version_subminor; |
75 uint8 class_code; | 75 uint8 class_code; |
76 uint8 subclass_code; | 76 uint8 subclass_code; |
77 uint8 protocol_code; | 77 uint8 protocol_code; |
78 uint16 vendor_id; | 78 uint16 vendor_id; |
79 uint16 product_id; | 79 uint16 product_id; |
80 uint8 device_version_major; | 80 uint8 device_version_major; |
81 uint8 device_version_minor; | 81 uint8 device_version_minor; |
82 uint8 device_version_subminor; | 82 uint8 device_version_subminor; |
83 string? manufacturer_name; | 83 string? manufacturer_name; |
84 string? product_name; | 84 string? product_name; |
85 string? serial_number; | 85 string? serial_number; |
86 uint8 active_configuration; | 86 uint8 active_configuration; |
87 array<ConfigurationInfo> configurations; | 87 array<UsbConfigurationInfo> configurations; |
88 }; | 88 }; |
89 | 89 |
90 struct ControlTransferParams { | 90 struct UsbControlTransferParams { |
91 ControlTransferType type; | 91 UsbControlTransferType type; |
92 ControlTransferRecipient recipient; | 92 UsbControlTransferRecipient recipient; |
93 uint8 request; | 93 uint8 request; |
94 uint16 value; | 94 uint16 value; |
95 uint16 index; | 95 uint16 index; |
96 }; | 96 }; |
97 | 97 |
98 enum TransferStatus { | 98 enum UsbTransferStatus { |
99 // The transfer completed successfully. | 99 // The transfer completed successfully. |
100 COMPLETED, | 100 COMPLETED, |
101 | 101 |
102 // The transfer failed due to a non-specific error. | 102 // The transfer failed due to a non-specific error. |
103 TRANSFER_ERROR, | 103 TRANSFER_ERROR, |
104 | 104 |
105 // The transfer was not allowed. | 105 // The transfer was not allowed. |
106 PERMISSION_DENIED, | 106 PERMISSION_DENIED, |
107 | 107 |
108 // The transfer timed out. | 108 // The transfer timed out. |
(...skipping 10 matching lines...) Expand all Loading... |
119 | 119 |
120 // The transfer succeeded, but the device sent more data than was requested. | 120 // The transfer succeeded, but the device sent more data than was requested. |
121 // This applies only to inbound transfers. | 121 // This applies only to inbound transfers. |
122 BABBLE, | 122 BABBLE, |
123 | 123 |
124 // The transfer succeeded, but the device sent less data than was requested. | 124 // The transfer succeeded, but the device sent less data than was requested. |
125 // This applies only to inbound transfers. | 125 // This applies only to inbound transfers. |
126 SHORT_PACKET, | 126 SHORT_PACKET, |
127 }; | 127 }; |
128 | 128 |
129 struct IsochronousPacket { | 129 struct UsbIsochronousPacket { |
130 uint32 length; | 130 uint32 length; |
131 uint32 transferred_length; | 131 uint32 transferred_length; |
132 TransferStatus status; | 132 UsbTransferStatus status; |
133 }; | 133 }; |
134 | 134 |
135 interface Device { | 135 interface UsbDevice { |
136 // Opens the device. Methods below require the device be opened first. | 136 // Opens the device. Methods below require the device be opened first. |
137 Open() => (OpenDeviceError error); | 137 Open() => (UsbOpenDeviceError error); |
138 | 138 |
139 // Closes the device. | 139 // Closes the device. |
140 Close() => (); | 140 Close() => (); |
141 | 141 |
142 // Initiates a device control transfer to set the device's configuration to | 142 // Initiates a device control transfer to set the device's configuration to |
143 // one with the configuration value |value|. | 143 // one with the configuration value |value|. |
144 SetConfiguration(uint8 value) => (bool success); | 144 SetConfiguration(uint8 value) => (bool success); |
145 | 145 |
146 // Claims a single interface in the current device configuration. | 146 // Claims a single interface in the current device configuration. |
147 ClaimInterface(uint8 interface_number) => (bool success); | 147 ClaimInterface(uint8 interface_number) => (bool success); |
(...skipping 15 matching lines...) Expand all Loading... |
163 // details of the request. Transfers to recipients other than DEVICE require a | 163 // details of the request. Transfers to recipients other than DEVICE require a |
164 // corresponding interface to be claimed. | 164 // corresponding interface to be claimed. |
165 // | 165 // |
166 // |length| specifies the expected number of bytes to receive for this | 166 // |length| specifies the expected number of bytes to receive for this |
167 // transfer. The size of |data| will never exceed |length|, and |data| will be | 167 // transfer. The size of |data| will never exceed |length|, and |data| will be |
168 // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET. | 168 // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET. |
169 // | 169 // |
170 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | 170 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 |
171 // indicates no timeout: the request will remain pending indefinitely until | 171 // indicates no timeout: the request will remain pending indefinitely until |
172 // completed or otherwise terminated. | 172 // completed or otherwise terminated. |
173 ControlTransferIn(ControlTransferParams params, uint32 length, uint32 timeout) | 173 ControlTransferIn(UsbControlTransferParams params, |
174 => (TransferStatus status, array<uint8>? data); | 174 uint32 length, |
| 175 uint32 timeout) |
| 176 => (UsbTransferStatus status, array<uint8>? data); |
175 | 177 |
176 // Initiates an inbound control transfer request. |params| determine the | 178 // Initiates an inbound control transfer request. |params| determine the |
177 // details of the request. Transfers to recipients other than DEVICE require a | 179 // details of the request. Transfers to recipients other than DEVICE require a |
178 // corresponding interface to be claimed. | 180 // corresponding interface to be claimed. |
179 // | 181 // |
180 // |data| specifies the bytes to send the device in the body of the request. | 182 // |data| specifies the bytes to send the device in the body of the request. |
181 // | 183 // |
182 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | 184 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 |
183 // indicates no timeout: the request will remain pending indefinitely until | 185 // indicates no timeout: the request will remain pending indefinitely until |
184 // completed or otherwise terminated. | 186 // completed or otherwise terminated. |
185 ControlTransferOut(ControlTransferParams params, | 187 ControlTransferOut(UsbControlTransferParams params, |
186 array<uint8> data, | 188 array<uint8> data, |
187 uint32 timeout) | 189 uint32 timeout) |
188 => (TransferStatus status); | 190 => (UsbTransferStatus status); |
189 | 191 |
190 // Initiates an inbound generic transfer request on a specific endpoint. The | 192 // Initiates an inbound generic transfer request on a specific endpoint. The |
191 // interface to which |endpoint_number| belongs must be claimed, and the | 193 // interface to which |endpoint_number| belongs must be claimed, and the |
192 // appropriate alternate setting must be set on that interface before | 194 // appropriate alternate setting must be set on that interface before |
193 // transfers can be initiated on the endpoint. The endpoint must be of type | 195 // transfers can be initiated on the endpoint. The endpoint must be of type |
194 // BULK or INTERRUPT. | 196 // BULK or INTERRUPT. |
195 // | 197 // |
196 // |length| specifies the expected number of bytes to receive for this | 198 // |length| specifies the expected number of bytes to receive for this |
197 // transfer. The size of |data| will never exceed |length|, and |data| will be | 199 // transfer. The size of |data| will never exceed |length|, and |data| will be |
198 // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET. | 200 // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET. |
199 // | 201 // |
200 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | 202 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 |
201 // indicates no timeout: the request will remain pending indefinitely until | 203 // indicates no timeout: the request will remain pending indefinitely until |
202 // completed or otherwise terminated. | 204 // completed or otherwise terminated. |
203 GenericTransferIn(uint8 endpoint_number, uint32 length, uint32 timeout) | 205 GenericTransferIn(uint8 endpoint_number, uint32 length, uint32 timeout) |
204 => (TransferStatus status, array<uint8>? data); | 206 => (UsbTransferStatus status, array<uint8>? data); |
205 | 207 |
206 // Initiates an outbound generic transfer request on a specific endpoint. The | 208 // Initiates an outbound generic transfer request on a specific endpoint. The |
207 // interface to which |endpoint_number| belongs must be claimed, and the | 209 // interface to which |endpoint_number| belongs must be claimed, and the |
208 // appropriate alternate setting must be set on that interface before | 210 // appropriate alternate setting must be set on that interface before |
209 // transfers can be initiated on the endpoint. The endpoint must be of type | 211 // transfers can be initiated on the endpoint. The endpoint must be of type |
210 // BULK or INTERRUPT. | 212 // BULK or INTERRUPT. |
211 // | 213 // |
212 // |data| specifies the bytes to send the device in the body of the request. | 214 // |data| specifies the bytes to send the device in the body of the request. |
213 // | 215 // |
214 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | 216 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 |
215 // indicates no timeout: the request will remain pending indefinitely until | 217 // indicates no timeout: the request will remain pending indefinitely until |
216 // completed or otherwise terminated. | 218 // completed or otherwise terminated. |
217 GenericTransferOut(uint8 endpoint_number, array<uint8> data, uint32 timeout) | 219 GenericTransferOut(uint8 endpoint_number, array<uint8> data, uint32 timeout) |
218 => (TransferStatus status); | 220 => (UsbTransferStatus status); |
219 | 221 |
220 // Initiates an inbound isochronous transfer request on a specific endpoint. | 222 // Initiates an inbound isochronous transfer request on a specific endpoint. |
221 // The interface to which |endpoint_number| belongs must be claimed, and the | 223 // The interface to which |endpoint_number| belongs must be claimed, and the |
222 // appropriate alternate setting must be set on that interface before | 224 // appropriate alternate setting must be set on that interface before |
223 // transfers can be initiated on the endpoint. The endpoint must be of type | 225 // transfers can be initiated on the endpoint. The endpoint must be of type |
224 // ISOCHRONOUS. | 226 // ISOCHRONOUS. |
225 // | 227 // |
226 // |packet_lengths| specifies the maximum expected number of bytes to receive | 228 // |packet_lengths| specifies the maximum expected number of bytes to receive |
227 // for each packet in this transfer. | 229 // for each packet in this transfer. |
228 // | 230 // |
229 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | 231 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 |
230 // indicates no timeout: the request will remain pending indefinitely until | 232 // indicates no timeout: the request will remain pending indefinitely until |
231 // completed or otherwise terminated. | 233 // completed or otherwise terminated. |
232 // | 234 // |
233 // |data| contains the data received from the device, if any. |packets| | 235 // |data| contains the data received from the device, if any. |packets| |
234 // contains the status of each packet received from the device, in order. The | 236 // contains the status of each packet received from the device, in order. The |
235 // length of the packet indicates its position in |data| while it's | 237 // length of the packet indicates its position in |data| while it's |
236 // transferred length gives the amount of data actually received from the | 238 // transferred length gives the amount of data actually received from the |
237 // device. | 239 // device. |
238 IsochronousTransferIn(uint8 endpoint_number, | 240 IsochronousTransferIn(uint8 endpoint_number, |
239 array<uint32> packet_lengths, | 241 array<uint32> packet_lengths, |
240 uint32 timeout) | 242 uint32 timeout) |
241 => (array<uint8>? data, array<IsochronousPacket> packets); | 243 => (array<uint8>? data, array<UsbIsochronousPacket> packets); |
242 | 244 |
243 // Initiates an outbound isochronous transfer request on a specific endpoint. | 245 // Initiates an outbound isochronous transfer request on a specific endpoint. |
244 // The interface to which |endpoint_number| belongs must be claimed, and the | 246 // The interface to which |endpoint_number| belongs must be claimed, and the |
245 // appropriate alternate setting must be set on that interface before | 247 // appropriate alternate setting must be set on that interface before |
246 // transfers can be initiated on the endpoint. The endpoint must be of type | 248 // transfers can be initiated on the endpoint. The endpoint must be of type |
247 // ISOCHRONOUS. | 249 // ISOCHRONOUS. |
248 // | 250 // |
249 // |data| specifies the bytes to send to the device. | 251 // |data| specifies the bytes to send to the device. |
250 // | 252 // |
251 // |packet_lengths| specifies how |data| should be separated into packets when | 253 // |packet_lengths| specifies how |data| should be separated into packets when |
252 // it is sent to the device. | 254 // it is sent to the device. |
253 // | 255 // |
254 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 | 256 // |timeout| specifies the request timeout in milliseconds. A timeout of 0 |
255 // indicates no timeout: the request will remain pending indefinitely until | 257 // indicates no timeout: the request will remain pending indefinitely until |
256 // completed or otherwise terminated. | 258 // completed or otherwise terminated. |
257 | 259 |
258 // |packets| contains the status of each packet sent to the device, in order. | 260 // |packets| contains the status of each packet sent to the device, in order. |
259 IsochronousTransferOut(uint8 endpoint_number, | 261 IsochronousTransferOut(uint8 endpoint_number, |
260 array<uint8> data, | 262 array<uint8> data, |
261 array<uint32> packet_lengths, | 263 array<uint32> packet_lengths, |
262 uint32 timeout) | 264 uint32 timeout) |
263 => (array<IsochronousPacket> packets); | 265 => (array<UsbIsochronousPacket> packets); |
264 }; | 266 }; |
OLD | NEW |