File: usb.webidl

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (454 lines) | stat: -rw-r--r-- 16,096 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Direction, Recipient, RequestType, and TransferType all map to their
// namesakes within the USB specification.
enum Direction {
  "in",
  "out"
};

enum Recipient {
  "device",
  "interface",
  "endpoint",
  "other"
};

enum RequestType {
  "standard",
  "class",
  "vendor",
  "reserved"
};

enum TransferType {
  "control",
  "interrupt",
  "isochronous",
  "bulk"
};

// For interrupt and isochronous modes, SynchronizationType and UsageType map
// to their namesakes within the USB specification.
enum SynchronizationType {
  "asynchronous",
  "adaptive",
  "synchronous"
};

enum UsageType {
  "data",
  "feedback",
  "explicitFeedback",
  "periodic",
  "notification"
};

dictionary Device {
  // An opaque ID for the USB device. It remains unchanged until the device is
  // unplugged.
  required long device;
  // The device vendor ID.
  required long vendorId;
  // The product ID.
  required long productId;
  // The device version (bcdDevice field).
  required long version;
  // The iProduct string read from the device, if available.
  required DOMString productName;
  // The iManufacturer string read from the device, if available.
  required DOMString manufacturerName;
  // The iSerialNumber string read from the device, if available.
  required DOMString serialNumber;
};

dictionary ConnectionHandle {
  // An opaque handle representing this connection to the USB device and all
  // associated claimed interfaces and pending transfers. A new handle is
  // created each time the device is opened. The connection handle is
  // different from $(ref:Device.device).
  required long handle;
  // The device vendor ID.
  required long vendorId;
  // The product ID.
  required long productId;
};

dictionary EndpointDescriptor {
  // Endpoint address.
  required long address;
  // Transfer type.
  required TransferType type;
  // Transfer direction.
  required Direction direction;
  // Maximum packet size.
  required long maximumPacketSize;
  // Transfer synchronization mode (isochronous only).
  SynchronizationType synchronization;
  // Endpoint usage hint.
  UsageType usage;
  // Polling interval (interrupt and isochronous only).
  long pollingInterval;
  // Extra descriptor data associated with this endpoint.
  required ArrayBuffer extra_data;
};

dictionary InterfaceDescriptor {
  // The interface number.
  required long interfaceNumber;
  // The interface alternate setting number (defaults to <code>0</code).
  required long alternateSetting;
  // The USB interface class.
  required long interfaceClass;
  // The USB interface sub-class.
  required long interfaceSubclass;
  // The USB interface protocol.
  required long interfaceProtocol;
  // Description of the interface.
  DOMString description;
  // Available endpoints.
  required sequence<EndpointDescriptor> endpoints;
  // Extra descriptor data associated with this interface.
  required ArrayBuffer extra_data;
};

dictionary ConfigDescriptor {
  // Is this the active configuration?
  required boolean active;
  // The configuration number.
  required long configurationValue;
  // Description of the configuration.
  DOMString description;
  // The device is self-powered.
  required boolean selfPowered;
  // The device supports remote wakeup.
  required boolean remoteWakeup;
  // The maximum power needed by this device in milliamps (mA).
  required long maxPower;
  // Available interfaces.
  required sequence<InterfaceDescriptor> interfaces;
  // Extra descriptor data associated with this configuration.
  required ArrayBuffer extra_data;
};

dictionary ControlTransferInfo {
  // The transfer direction (<code>"in"</code> or <code>"out"</code>).
  required Direction direction;

  // The transfer target. The target given by <code>index</code> must be
  // claimed if <code>"interface"</code> or <code>"endpoint"</code>.
  required Recipient recipient;

  // The request type.
  required RequestType requestType;

  // The <code>bRequest</code> field, see <i>Universal Serial Bus
  // Specification Revision 1.1</i> &sect; 9.3.
  required long request;
  // The <code>wValue</code> field, see <i>Ibid</i>.
  required long value;
  // The <code>wIndex</code> field, see <i>Ibid</i>.
  required long index;

  // The maximum number of bytes to receive (required only by input
  // transfers).
  long length;

  // The data to transmit (required only by output transfers).
  ArrayBuffer data;

  // Request timeout (in milliseconds). The default value <code>0</code>
  // indicates no timeout.
  long timeout;
};

dictionary GenericTransferInfo {
  // The transfer direction (<code>"in"</code> or <code>"out"</code>).
  required Direction direction;

  // The target endpoint address. The interface containing this endpoint must
  // be claimed.
  required long endpoint;

  // The maximum number of bytes to receive (required only by input
  // transfers).
  long length;

  // The data to transmit (required only by output transfers).
  ArrayBuffer data;

  // Request timeout (in milliseconds). The default value <code>0</code>
  // indicates no timeout.
  long timeout;
};

dictionary IsochronousTransferInfo {
  // Transfer parameters. The transfer length or data buffer specified in this
  // parameter block is split along <code>packetLength</code> boundaries to
  // form the individual packets of the transfer.
  required GenericTransferInfo transferInfo;

  // The total number of packets in this transfer.
  required long packets;

  // The length of each of the packets in this transfer.
  required long packetLength;
};

dictionary TransferResultInfo {
  // A value of <code>0</code> indicates that the transfer was a success.
  // Other values indicate failure.
  long resultCode;

  // The data returned by an input transfer. <code>undefined</code> for output
  // transfers.
  ArrayBuffer data;
};

dictionary DeviceFilter {
  // Device vendor ID.
  long vendorId;
  // Device product ID, checked only if the vendor ID matches.
  long productId;
  // USB interface class, matches any interface on the device.
  long interfaceClass;
  // USB interface sub-class, checked only if the interface class matches.
  long interfaceSubclass;
  // USB interface protocol, checked only if the interface sub-class matches.
  long interfaceProtocol;
};

dictionary EnumerateDevicesOptions {
  [deprecated="Equivalent to setting $(ref:DeviceFilter.vendorId)."]
  long vendorId;
  [deprecated="Equivalent to setting $(ref:DeviceFilter.productId)."]
  long productId;
  // A device matching any given filter will be returned. An empty filter list
  // will return all devices the app has permission for.
  sequence<DeviceFilter> filters;
};

dictionary EnumerateDevicesAndRequestAccessOptions {
  // The device vendor ID.
  required long vendorId;
  // The product ID.
  required long productId;
  // The interface ID to request access to.
  // Only available on Chrome OS. It has no effect on other platforms.
  long interfaceId;
};

dictionary DevicePromptOptions {
  // Allow the user to select multiple devices.
  boolean multiple;
  // Filter the list of devices presented to the user. If multiple filters are
  // provided devices matching any filter will be displayed.
  sequence<DeviceFilter> filters;
};

callback OnDeviceAddedListener = undefined (Device device);

interface OnDeviceAddedEvent : ExtensionEvent {
  static undefined addListener(OnDeviceAddedListener listener);
  static undefined removeListener(OnDeviceAddedListener listener);
  static boolean hasListener(OnDeviceAddedListener listener);
};

callback OnDeviceRemovedListener = undefined (Device device);

interface OnDeviceRemovedEvent : ExtensionEvent {
  static undefined addListener(OnDeviceRemovedListener listener);
  static undefined removeListener(OnDeviceRemovedListener listener);
  static boolean hasListener(OnDeviceRemovedListener listener);
};

// Use the <code>chrome.usb</code> API to interact with connected USB
// devices. This API provides access to USB operations from within the context
// of an app. Using this API, apps can function as drivers for hardware devices.
// Errors generated by this API are reported by setting
// $(ref:runtime.lastError) and executing the function's regular callback. The
// callback's regular parameters will be undefined in this case.
interface Usb {
  // Enumerates connected USB devices.
  // |options|: The properties to search for on target devices.
  // |PromiseValue|: devices
  [requiredCallback] static Promise<sequence<Device>> getDevices(
      EnumerateDevicesOptions options);

  // Presents a device picker to the user and returns the $(ref:Device)s
  // selected.
  // If the user cancels the picker devices will be empty. A user gesture
  // is required for the dialog to display. Without a user gesture, the
  // callback will run as though the user cancelled.
  // |options|: Configuration of the device picker dialog box.
  // |Returns|: Invoked with a list of chosen $(ref:Device)s.
  // |PromiseValue|: devices
  [requiredCallback] static Promise<sequence<Device>> getUserSelectedDevices(
      DevicePromptOptions options);

  // Returns the full set of device configuration descriptors.
  // |device|: The $(ref:Device) to fetch descriptors from.
  // |PromiseValue|: configs
  [requiredCallback]
  static Promise<sequence<ConfigDescriptor>> getConfigurations(
      Device device);

  // Requests access from the permission broker to a device claimed by
  // Chrome OS if the given interface on the device is not claimed.
  //
  // |device|: The $(ref:Device) to request access to.
  // |interfaceId|: The particular interface requested.
  // |PromiseValue|: success
  [deprecated="This function was Chrome OS specific and calling it on other
    platforms would fail. This operation is now implicitly performed as part of
    $(ref:openDevice) and this function will return <code>true</code> on all
    platforms.", requiredCallback]
  static Promise<boolean> requestAccess(Device device,
                            long interfaceId);

  // Opens a USB device returned by $(ref:getDevices).
  // |device|: The $(ref:Device) to open.
  // |PromiseValue|: handle
  [requiredCallback] static Promise<ConnectionHandle> openDevice(
      Device device);

  // Finds USB devices specified by the vendor, product and (optionally)
  // interface IDs and if permissions allow opens them for use.
  //
  // If the access request is rejected or the device fails to be opened a
  // connection handle will not be created or returned.
  //
  // Calling this method is equivalent to calling $(ref:getDevices) followed
  // by $(ref:openDevice) for each device.
  //
  // |options|: The properties to search for on target devices.
  // |PromiseValue|: handles
  [requiredCallback] static Promise<sequence<ConnectionHandle>> findDevices(
      EnumerateDevicesAndRequestAccessOptions options);

  // Closes a connection handle. Invoking operations on a handle after it
  // has been closed is a safe operation but causes no action to be taken.
  // |handle|: The $(ref:ConnectionHandle) to close.
  static Promise<undefined> closeDevice(
      ConnectionHandle handle);

  // Select a device configuration.
  //
  // This function effectively resets the device by selecting one of the
  // device's available configurations. Only configuration values greater
  // than <code>0</code> are valid however some buggy devices have a working
  // configuration <code>0</code> and so this value is allowed.
  // |handle|: An open connection to the device.
  [requiredCallback] static Promise<undefined> setConfiguration(
      ConnectionHandle handle,
      long configurationValue);

  // Gets the configuration descriptor for the currently selected
  // configuration.
  // |handle|: An open connection to the device.
  // |PromiseValue|: config
  [requiredCallback] static Promise<ConfigDescriptor> getConfiguration(
      ConnectionHandle handle);

  // Lists all interfaces on a USB device.
  // |handle|: An open connection to the device.
  // |PromiseValue|: descriptors
  [requiredCallback]
  static Promise<sequence<InterfaceDescriptor>> listInterfaces(
      ConnectionHandle handle);

  // Claims an interface on a USB device.
  // Before data can be transfered to an interface or associated endpoints the
  // interface must be claimed. Only one connection handle can claim an
  // interface at any given time. If the interface is already claimed, this
  // call will fail.
  //
  // $(ref:releaseInterface) should be called when the interface is no longer
  // needed.
  //
  // |handle|: An open connection to the device.
  // |interfaceNumber|: The interface to be claimed.
  [requiredCallback] static Promise<undefined> claimInterface(
      ConnectionHandle handle,
      long interfaceNumber);

  // Releases a claimed interface.
  // |handle|: An open connection to the device.
  // |interfaceNumber|: The interface to be released.
  [requiredCallback] static Promise<undefined> releaseInterface(
      ConnectionHandle handle,
      long interfaceNumber);

  // Selects an alternate setting on a previously claimed interface.
  // |handle|: An open connection to the device where this interface has been
  //     claimed.
  // |interfaceNumber|: The interface to configure.
  // |alternateSetting|: The alternate setting to configure.
  [requiredCallback] static Promise<undefined> setInterfaceAlternateSetting(
      ConnectionHandle handle,
      long interfaceNumber,
      long alternateSetting);

  // Performs a control transfer on the specified device.
  //
  // Control transfers refer to either the device, an interface or an
  // endpoint. Transfers to an interface or endpoint require the interface to
  // be claimed.
  //
  // |handle|: An open connection to the device.
  // |PromiseValue|: info
  [requiredCallback] static Promise<TransferResultInfo> controlTransfer(
      ConnectionHandle handle,
      ControlTransferInfo transferInfo);

  // Performs a bulk transfer on the specified device.
  // |handle|: An open connection to the device.
  // |transferInfo|: The transfer parameters.
  // |PromiseValue|: info
  [requiredCallback] static Promise<TransferResultInfo> bulkTransfer(
      ConnectionHandle handle,
      GenericTransferInfo transferInfo);

  // Performs an interrupt transfer on the specified device.
  // |handle|: An open connection to the device.
  // |transferInfo|: The transfer parameters.
  // |PromiseValue|: info
  [requiredCallback] static Promise<TransferResultInfo> interruptTransfer(
      ConnectionHandle handle,
      GenericTransferInfo transferInfo);

  // Performs an isochronous transfer on the specific device.
  // |handle|: An open connection to the device.
  // |PromiseValue|: info
  [requiredCallback] static Promise<TransferResultInfo> isochronousTransfer(
      ConnectionHandle handle,
      IsochronousTransferInfo transferInfo);

  // Tries to reset the USB device.
  // If the reset fails, the given connection handle will be closed and the
  // USB device will appear to be disconnected then reconnected.
  // In this case $(ref:getDevices) or $(ref:findDevices) must be called again
  // to acquire the device.
  //
  // |handle|: A connection handle to reset.
  // |PromiseValue|: success
  [requiredCallback] static Promise<boolean> resetDevice(
      ConnectionHandle handle);

  // Event generated when a device is added to the system. Events are only
  // broadcast to apps and extensions that have permission to access the
  // device. Permission may have been granted at install time, when the user
  // accepted an optional permission (see $(ref:permissions.request)), or
  // through $(ref:getUserSelectedDevices).
  static attribute OnDeviceAddedEvent onDeviceAdded;

  // Event generated when a device is removed from the system. See
  // $(ref:onDeviceAdded) for which events are delivered.
  static attribute OnDeviceRemovedEvent onDeviceRemoved;
};

partial interface Browser {
  static attribute Usb usb;
};