summaryrefslogtreecommitdiffstats
path: root/device/usb/public/interfaces/device.mojom
blob: de7bd5fb148e87d44187f6becd8dd4a356c42e1a (plain)
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
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module device.usb;

enum OpenDeviceError {
  // Opening the device succeeded.
  OK,

  // The operating system denied access to the device.
  ACCESS_DENIED,

  // The device is already open.
  ALREADY_OPEN,
};

enum TransferDirection {
  INBOUND,
  OUTBOUND,
};

enum ControlTransferType {
  STANDARD,
  CLASS,
  VENDOR,
  RESERVED
};

enum ControlTransferRecipient {
  DEVICE,
  INTERFACE,
  ENDPOINT,
  OTHER
};

enum EndpointType {
  BULK,
  INTERRUPT,
  ISOCHRONOUS,
};

struct EndpointInfo {
  uint8 endpoint_number;
  TransferDirection direction;
  EndpointType type;
  uint32 packet_size;
};

struct AlternateInterfaceInfo {
  uint8 alternate_setting;
  uint8 class_code;
  uint8 subclass_code;
  uint8 protocol_code;
  string? interface_name;
  array<EndpointInfo> endpoints;
};

struct InterfaceInfo {
  uint8 interface_number;
  array<AlternateInterfaceInfo> alternates;
};

struct ConfigurationInfo {
  uint8 configuration_value;
  string? configuration_name;
  array<InterfaceInfo> interfaces;
};

struct WebUsbFunctionSubset {
  uint8 first_interface;
  array<string> origins;
};

struct WebUsbConfigurationSubset {
  uint8 configuration_value;
  array<string> origins;
  array<WebUsbFunctionSubset> functions;
};

struct WebUsbDescriptorSet {
  array<string> origins;
  array<WebUsbConfigurationSubset> configurations;
};

struct DeviceInfo {
  string guid;
  uint8 usb_version_major;
  uint8 usb_version_minor;
  uint8 usb_version_subminor;
  uint8 class_code;
  uint8 subclass_code;
  uint8 protocol_code;
  uint16 vendor_id;
  uint16 product_id;
  uint8 device_version_major;
  uint8 device_version_minor;
  uint8 device_version_subminor;
  string? manufacturer_name;
  string? product_name;
  string? serial_number;
  array<ConfigurationInfo> configurations;
  WebUsbDescriptorSet? webusb_allowed_origins;
};

struct ControlTransferParams {
  ControlTransferType type;
  ControlTransferRecipient recipient;
  uint8 request;
  uint16 value;
  uint16 index;
};

enum TransferStatus {
  // The transfer completed successfully.
  COMPLETED,

  // The transfer failed due to a non-specific error.
  TRANSFER_ERROR,

  // The transfer was not allowed.
  PERMISSION_DENIED,

  // The transfer timed out.
  TIMEOUT,

  // The transfer was cancelled.
  CANCELLED,

  // The transfer stalled.
  STALLED,

  // The transfer failed because the device was disconnected from the host.
  DISCONNECT,

  // The transfer succeeded, but the device sent more data than was requested.
  // This applies only to inbound transfers.
  BABBLE,

  // The transfer succeeded, but the device sent less data than was requested.
  // This applies only to inbound transfers.
  SHORT_PACKET,
};

struct IsochronousPacket {
  uint32 length;
  uint32 transferred_length;
  TransferStatus status;
};

interface Device {
  // Retrieve a DeviceInfo struct containing metadata about the device,
  // including the set of all available device configurations.
  GetDeviceInfo() => (DeviceInfo? info);

  // Retrieves the |configuration_value| of the device's currently active
  // configuration. Will return 0 if the device is unconfigured.
  GetConfiguration() => (uint8 value);

  // Opens the device. Methods below require the device be opened first.
  Open() => (OpenDeviceError error);

  // Closes the device.
  Close() => ();

  // Initiates a device control transfer to set the device's configuration to
  // one with the configuration value |value|.
  SetConfiguration(uint8 value) => (bool success);

  // Claims a single interface in the current device configuration.
  ClaimInterface(uint8 interface_number) => (bool success);

  // Releases a claimed interface in the current device configuration.
  ReleaseInterface(uint8 interface_number) => (bool success);

  // Selects an alternate setting for a given claimed interface.
  SetInterfaceAlternateSetting(uint8 interface_number, uint8 alternate_setting)
      => (bool success);

  // Resets the device.
  Reset() => (bool success);

  // Clear the halt/stall condition for an endpoint.
  ClearHalt(uint8 endpoint) => (bool success);

  // Initiates an inbound control transfer request. |params| determine the
  // details of the request. Transfers to recipients other than DEVICE require a
  // corresponding interface to be claimed.
  //
  // |length| specifies the expected number of bytes to receive for this
  // transfer. The size of |data| will never exceed |length|, and |data| will be
  // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET.
  //
  // |timeout| specifies the request timeout in milliseconds. A timeout of 0
  // indicates no timeout: the request will remain pending indefinitely until
  // completed or otherwise terminated.
  ControlTransferIn(ControlTransferParams params, uint32 length, uint32 timeout)
      => (TransferStatus status, array<uint8>? data);

  // Initiates an inbound control transfer request. |params| determine the
  // details of the request. Transfers to recipients other than DEVICE require a
  // corresponding interface to be claimed.
  //
  // |data| specifies the bytes to send the device in the body of the request.
  //
  // |timeout| specifies the request timeout in milliseconds. A timeout of 0
  // indicates no timeout: the request will remain pending indefinitely until
  // completed or otherwise terminated.
  ControlTransferOut(ControlTransferParams params,
                     array<uint8> data,
                     uint32 timeout)
      => (TransferStatus status);

  // Initiates an inbound generic transfer request on a specific endpoint. The
  // interface to which |endpoint_number| belongs must be claimed, and the
  // appropriate alternate setting must be set on that interface before
  // transfers can be initiated on the endpoint. The endpoint must be of type
  // BULK or INTERRUPT.
  //
  // |length| specifies the expected number of bytes to receive for this
  // transfer. The size of |data| will never exceed |length|, and |data| will be
  // null if |status| is neither COMPLETED, BABBLE, or SHORT_PACKET.
  //
  // |timeout| specifies the request timeout in milliseconds. A timeout of 0
  // indicates no timeout: the request will remain pending indefinitely until
  // completed or otherwise terminated.
  GenericTransferIn(uint8 endpoint_number, uint32 length, uint32 timeout)
      => (TransferStatus status, array<uint8>? data);

  // Initiates an outbound generic transfer request on a specific endpoint. The
  // interface to which |endpoint_number| belongs must be claimed, and the
  // appropriate alternate setting must be set on that interface before
  // transfers can be initiated on the endpoint. The endpoint must be of type
  // BULK or INTERRUPT.
  //
  // |data| specifies the bytes to send the device in the body of the request.
  //
  // |timeout| specifies the request timeout in milliseconds. A timeout of 0
  // indicates no timeout: the request will remain pending indefinitely until
  // completed or otherwise terminated.
  GenericTransferOut(uint8 endpoint_number, array<uint8> data, uint32 timeout)
      => (TransferStatus status);

  // Initiates an inbound isochronous transfer request on a specific endpoint.
  // The interface to which |endpoint_number| belongs must be claimed, and the
  // appropriate alternate setting must be set on that interface before
  // transfers can be initiated on the endpoint. The endpoint must be of type
  // ISOCHRONOUS.
  //
  // |packet_lengths| specifies the maximum expected number of bytes to receive
  // for each packet in this transfer.
  //
  // |timeout| specifies the request timeout in milliseconds. A timeout of 0
  // indicates no timeout: the request will remain pending indefinitely until
  // completed or otherwise terminated.
  //
  // |data| contains the data received from the device, if any. |packets|
  // contains the status of each packet received from the device, in order. The
  // length of the packet indicates its position in |data| while it's
  // transferred length gives the amount of data actually received from the
  // device.
  IsochronousTransferIn(uint8 endpoint_number,
                        array<uint32> packet_lengths,
                        uint32 timeout)
      => (array<uint8>? data, array<IsochronousPacket> packets);

  // Initiates an outbound isochronous transfer request on a specific endpoint.
  // The interface to which |endpoint_number| belongs must be claimed, and the
  // appropriate alternate setting must be set on that interface before
  // transfers can be initiated on the endpoint. The endpoint must be of type
  // ISOCHRONOUS.
  //
  // |data| specifies the bytes to send to the device.
  //
  // |packet_lengths| specifies how |data| should be separated into packets when
  // it is sent to the device.
  //
  // |timeout| specifies the request timeout in milliseconds. A timeout of 0
  // indicates no timeout: the request will remain pending indefinitely until
  // completed or otherwise terminated.

  // |packets| contains the status of each packet sent to the device, in order.
  IsochronousTransferOut(uint8 endpoint_number,
                         array<uint8> data,
                         array<uint32> packet_lengths,
                         uint32 timeout)
      => (array<IsochronousPacket> packets);
};