// 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, }; 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 endpoints; }; struct InterfaceInfo { uint8 interface_number; array alternates; }; struct ConfigurationInfo { uint8 configuration_value; string? configuration_name; array interfaces; }; struct WebUsbFunctionSubset { uint8 first_interface; array origins; }; struct WebUsbConfigurationSubset { uint8 configuration_value; array origins; array functions; }; struct WebUsbDescriptorSet { array origins; array 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 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? 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 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? 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 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 packet_lengths, uint32 timeout) => (array? data, array 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 data, array packet_lengths, uint32 timeout) => (array packets); };