Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / extensions / common / api / usb.idl
blob77163e7912bd8f017f2db77287d9cf46617e4fa7
1 // Copyright 2014 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.
5 // Use the <code>chrome.usb</code> API to interact with connected USB
6 // devices. This API provides access to USB operations from within the context
7 // of an app. Using this API, apps can function as drivers for hardware devices.
8 //
9 // Errors generated by this API are reported by setting
10 // $(ref:runtime.lastError) and executing the function's regular callback. The
11 // callback's regular parameters will be undefined in this case.
12 namespace usb {
14 // Direction, Recipient, RequestType, and TransferType all map to their
15 // namesakes within the USB specification.
16 enum Direction {in, out};
17 enum Recipient {device, _interface, endpoint, other};
18 enum RequestType {standard, class, vendor, reserved};
19 enum TransferType {control, interrupt, isochronous, bulk};
21 // For isochronous mode, SynchronizationType and UsageType map to their
22 // namesakes within the USB specification.
23 enum SynchronizationType {asynchronous, adaptive, synchronous};
24 enum UsageType {data, feedback, explicitFeedback};
26 dictionary Device {
27 // An opaque ID for the USB device. It remains unchanged until the device is
28 // unplugged.
29 long device;
30 // The device vendor ID.
31 long vendorId;
32 // The product ID.
33 long productId;
34 // The iProduct string read from the device, if available.
35 DOMString productName;
36 // The iManufacturer string read from the device, if available.
37 DOMString manufacturerName;
38 // The iSerialNumber string read from the device, if available.
39 DOMString serialNumber;
42 dictionary ConnectionHandle {
43 // An opaque handle representing this connection to the USB device and all
44 // associated claimed interfaces and pending transfers. A new handle is
45 // created each time the device is opened. The connection handle is
46 // different from $(ref:Device.device).
47 long handle;
48 // The device vendor ID.
49 long vendorId;
50 // The product ID.
51 long productId;
54 [noinline_doc] dictionary EndpointDescriptor {
55 // Endpoint address.
56 long address;
57 // Transfer type.
58 TransferType type;
59 // Transfer direction.
60 Direction direction;
61 // Maximum packet size.
62 long maximumPacketSize;
63 // Transfer synchronization mode (isochronous only).
64 SynchronizationType? synchronization;
65 // Endpoint usage hint.
66 UsageType? usage;
67 // Polling interval (interrupt and isochronous only).
68 long? pollingInterval;
69 // Extra descriptor data associated with this endpoint.
70 ArrayBuffer extra_data;
73 [noinline_doc] dictionary InterfaceDescriptor {
74 // The interface number.
75 long interfaceNumber;
76 // The interface alternate setting number (defaults to <code>0</code).
77 long alternateSetting;
78 // The USB interface class.
79 long interfaceClass;
80 // The USB interface sub-class.
81 long interfaceSubclass;
82 // The USB interface protocol.
83 long interfaceProtocol;
84 // Description of the interface.
85 DOMString? description;
86 // Available endpoints.
87 EndpointDescriptor[] endpoints;
88 // Extra descriptor data associated with this interface.
89 ArrayBuffer extra_data;
92 [noinline_doc] dictionary ConfigDescriptor {
93 // Is this the active configuration?
94 boolean active;
95 // The configuration number.
96 long configurationValue;
97 // Description of the configuration.
98 DOMString? description;
99 // The device is self-powered.
100 boolean selfPowered;
101 // The device supports remote wakeup.
102 boolean remoteWakeup;
103 // The maximum power needed by this device in milliamps (mA).
104 long maxPower;
105 // Available interfaces.
106 InterfaceDescriptor[] interfaces;
107 // Extra descriptor data associated with this configuration.
108 ArrayBuffer extra_data;
111 dictionary ControlTransferInfo {
112 // The transfer direction (<code>"in"</code> or <code>"out"</code>).
113 Direction direction;
115 // The transfer target. The target given by <code>index</code> must be
116 // claimed if <code>"interface"</code> or <code>"endpoint"</code>.
117 Recipient recipient;
119 // The request type.
120 RequestType requestType;
122 // The <code>bRequest</code> field, see <i>Universal Serial Bus Specification
123 // Revision 1.1</i> &sect; 9.3.
124 long request;
125 // The <code>wValue</code> field, see <i>Ibid</i>.
126 long value;
127 // The <code>wIndex</code> field, see <i>Ibid</i>.
128 long index;
130 // The amount of data to receive (required only by input transfers).
131 long? length;
133 // The data to transmit (required only by output transfers).
134 ArrayBuffer? data;
136 // Request timeout (in milliseconds). The default value <code>0</code>
137 // indicates no timeout.
138 long? timeout;
141 dictionary GenericTransferInfo {
142 // The transfer direction (<code>"in"</code> or <code>"out"</code>).
143 Direction direction;
145 // The target endpoint address. The interface containing this endpoint must
146 // be claimed.
147 long endpoint;
149 // The amount of data to receive (required only by input transfers).
150 long? length;
152 // The data to transmit (required only by output transfers).
153 ArrayBuffer? data;
155 // Request timeout (in milliseconds). The default value <code>0</code>
156 // indicates no timeout.
157 long? timeout;
160 dictionary IsochronousTransferInfo {
161 // Transfer parameters. The transfer length or data buffer specified in this
162 // parameter block is split along <code>packetLength</code> boundaries to
163 // form the individual packets of the transfer.
164 GenericTransferInfo transferInfo;
166 // The total number of packets in this transfer.
167 long packets;
169 // The length of each of the packets in this transfer.
170 long packetLength;
173 dictionary TransferResultInfo {
174 // A value of <code>0</code> indicates that the transfer was a success.
175 // Other values indicate failure.
176 long? resultCode;
178 // The data returned by an input transfer. <code>undefined</code> for output
179 // transfers.
180 ArrayBuffer? data;
183 [noinline_doc] dictionary DeviceFilter {
184 // Device vendor ID.
185 long? vendorId;
186 // Device product ID, checked only if the vendor ID matches.
187 long? productId;
188 // USB interface class, matches any interface on the device.
189 long? interfaceClass;
190 // USB interface sub-class, checked only if the interface class matches.
191 long? interfaceSubclass;
192 // USB interface protocol, checked only if the interface sub-class matches.
193 long? interfaceProtocol;
196 dictionary EnumerateDevicesOptions {
197 [deprecated="Equivalent to setting $(ref:DeviceFilter.vendorId)."]
198 long? vendorId;
199 [deprecated="Equivalent to setting $(ref:DeviceFilter.productId)."]
200 long? productId;
201 // A device matching any given filter will be returned. An empty filter list
202 // will return all devices the app has permission for.
203 DeviceFilter[]? filters;
206 dictionary EnumerateDevicesAndRequestAccessOptions {
207 // The device vendor ID.
208 long vendorId;
209 // The product ID.
210 long productId;
211 // The interface ID to request access to.
212 // Only available on Chrome OS. It has no effect on other platforms.
213 long? interfaceId;
216 dictionary DevicePromptOptions {
217 // Allow the user to select multiple devices.
218 boolean? multiple;
219 // Filter the list of devices presented to the user. If multiple filters are
220 // provided devices matching any filter will be displayed.
221 DeviceFilter[]? filters;
224 callback VoidCallback = void ();
225 callback GetDevicesCallback = void (Device[] devices);
226 callback GetConfigurationsCallback = void (ConfigDescriptor[] configs);
227 callback RequestAccessCallback = void (boolean success);
228 callback OpenDeviceCallback = void (ConnectionHandle handle);
229 callback FindDevicesCallback = void (ConnectionHandle[] handles);
230 callback GetConfigurationCallback = void (ConfigDescriptor config);
231 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors);
232 callback CloseDeviceCallback = void ();
233 callback TransferCallback = void (TransferResultInfo info);
234 callback ResetDeviceCallback = void(boolean success);
236 interface Functions {
237 // Enumerates connected USB devices.
238 // |options|: The properties to search for on target devices.
239 static void getDevices(EnumerateDevicesOptions options,
240 GetDevicesCallback callback);
242 // Presents a device picker to the user and returns the $(ref:Device)s
243 // selected.
244 // If the user cancels the picker devices will be empty. A user gesture
245 // is required for the dialog to display. Without a user gesture, the
246 // callback will run as though the user cancelled.
247 // |options|: Configuration of the device picker dialog box.
248 // |callback|: Invoked with a list of chosen $(ref:Device)s.
249 static void getUserSelectedDevices(DevicePromptOptions options,
250 GetDevicesCallback callback);
252 // Returns the full set of device configuration descriptors.
253 // |device|: The $(ref:Device) to fetch descriptors from.
254 static void getConfigurations(Device device,
255 GetConfigurationsCallback callback);
257 // Requests access from the permission broker to a device claimed by
258 // Chrome OS if the given interface on the device is not claimed.
260 // |device|: The $(ref:Device) to request access to.
261 // |interfaceId|: The particular interface requested.
262 [deprecated="This function was Chrome OS specific and calling it on other
263 platforms would fail. This operation is now implicitly performed as part of
264 $(ref:openDevice) and this function will return <code>true</code> on all
265 platforms."]
266 static void requestAccess(Device device,
267 long interfaceId,
268 RequestAccessCallback callback);
270 // Opens a USB device returned by $(ref:getDevices).
271 // |device|: The $(ref:Device) to open.
272 static void openDevice(Device device, OpenDeviceCallback callback);
274 // Finds USB devices specified by the vendor, product and (optionally)
275 // interface IDs and if permissions allow opens them for use.
277 // If the access request is rejected or the device fails to be opened a
278 // connection handle will not be created or returned.
280 // Calling this method is equivalent to calling $(ref:getDevices) followed
281 // by $(ref:openDevice) for each device.
283 // |options|: The properties to search for on target devices.
284 static void findDevices(EnumerateDevicesAndRequestAccessOptions options,
285 FindDevicesCallback callback);
287 // Closes a connection handle. Invoking operations on a handle after it
288 // has been closed is a safe operation but causes no action to be taken.
289 // |handle|: The $(ref:ConnectionHandle) to close.
290 static void closeDevice(ConnectionHandle handle,
291 optional CloseDeviceCallback callback);
293 // Select a device configuration.
295 // This function effectively resets the device by selecting one of the
296 // device's available configurations. Only configuration values greater
297 // than <code>0</code> are valid however some buggy devices have a working
298 // configuration <code>0</code> and so this value is allowed.
299 // |handle|: An open connection to the device.
300 static void setConfiguration(ConnectionHandle handle,
301 long configurationValue,
302 VoidCallback callback);
304 // Gets the configuration descriptor for the currently selected
305 // configuration.
306 // |handle|: An open connection to the device.
307 static void getConfiguration(ConnectionHandle handle,
308 GetConfigurationCallback callback);
310 // Lists all interfaces on a USB device.
311 // |handle|: An open connection to the device.
312 static void listInterfaces(ConnectionHandle handle,
313 ListInterfacesCallback callback);
315 // Claims an interface on a USB device.
316 // Before data can be transfered to an interface or associated endpoints the
317 // interface must be claimed. Only one connection handle can claim an
318 // interface at any given time. If the interface is already claimed, this
319 // call will fail.
321 // $(ref:releaseInterface) should be called when the interface is no longer
322 // needed.
324 // |handle|: An open connection to the device.
325 // |interfaceNumber|: The interface to be claimed.
326 static void claimInterface(ConnectionHandle handle, long interfaceNumber,
327 VoidCallback callback);
329 // Releases a claimed interface.
330 // |handle|: An open connection to the device.
331 // |interfaceNumber|: The interface to be released.
332 static void releaseInterface(ConnectionHandle handle, long interfaceNumber,
333 VoidCallback callback);
335 // Selects an alternate setting on a previously claimed interface.
336 // |handle|: An open connection to the device where this interface has been
337 // claimed.
338 // |interfaceNumber|: The interface to configure.
339 // |alternateSetting|: The alternate setting to configure.
340 static void setInterfaceAlternateSetting(ConnectionHandle handle,
341 long interfaceNumber,
342 long alternateSetting,
343 VoidCallback callback);
345 // Performs a control transfer on the specified device.
347 // Control transfers refer to either the device, an interface or an
348 // endpoint. Transfers to an interface or endpoint require the interface to
349 // be claimed.
351 // |handle|: An open connection to the device.
352 static void controlTransfer(ConnectionHandle handle,
353 ControlTransferInfo transferInfo,
354 TransferCallback callback);
356 // Performs a bulk transfer on the specified device.
357 // |handle|: An open connection to the device.
358 // |transferInfo|: The transfer parameters.
359 static void bulkTransfer(ConnectionHandle handle,
360 GenericTransferInfo transferInfo,
361 TransferCallback callback);
363 // Performs an interrupt transfer on the specified device.
364 // |handle|: An open connection to the device.
365 // |transferInfo|: The transfer parameters.
366 static void interruptTransfer(ConnectionHandle handle,
367 GenericTransferInfo transferInfo,
368 TransferCallback callback);
370 // Performs an isochronous transfer on the specific device.
371 // |handle|: An open connection to the device.
372 static void isochronousTransfer(ConnectionHandle handle,
373 IsochronousTransferInfo transferInfo,
374 TransferCallback callback);
376 // Tries to reset the USB device.
377 // If the reset fails, the given connection handle will be closed and the
378 // USB device will appear to be disconnected then reconnected.
379 // In this case $(ref:getDevices) or $(ref:findDevices) must be called again
380 // to acquire the device.
382 // |handle|: A connection handle to reset.
383 static void resetDevice(ConnectionHandle handle,
384 ResetDeviceCallback callback);
387 interface Events {
388 // Event generated when a device is added to the system. Events are only
389 // broadcast to apps and extensions that have permission to access the
390 // device. Permission may have been granted at install time, when the user
391 // accepted an optional permission (see $(ref:permissions.request)), or
392 // through $(ref:getUserSelectedDevices).
393 static void onDeviceAdded(Device device);
395 // Event generated when a device is removed from the system. See
396 // $(ref:onDeviceAdded) for which events are delivered.
397 static void onDeviceRemoved(Device device);