blob: 10cf30d764fa2894cc1d79753568a3b8a8ae56db [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library fuchsia.hardware.usb.peripheral;
using zx;
struct FunctionDescriptor {
uint8 interface_class;
uint8 interface_subclass;
uint8 interface_protocol;
// The fields in DeviceDescriptor match those in usb_descriptor_t in the USB specification.
struct DeviceDescriptor {
uint16 bcdUSB;
uint8 bDeviceClass;
uint8 bDeviceSubClass;
uint8 bDeviceProtocol;
uint8 bMaxPacketSize0;
uint16 idVendor;
uint16 idProduct;
uint16 bcdDevice;
uint8 iManufacturer;
uint8 iProduct;
uint8 iSerialNumber;
uint8 bNumConfigurations;
const uint32 MAX_STRING_LENGTH = 127;
// Events protocol that is used as a callback to inform the client
// of the completion of various server-side events.
// This callback interface can be registered using the SetStateChangeListener
// method on the Device protocol.
[Layout = "Simple"]
protocol Events {
// Invoked when a function registers
FunctionRegistered() -> ();
[Layout = "Simple"]
protocol Device {
// Sets the device's USB device descriptor.
SetDeviceDescriptor(DeviceDescriptor desc) -> (zx.status s);
// Sets a string descriptor a string in the USB device descriptor.
AllocStringDesc(string:MAX_STRING_LENGTH name) -> (zx.status s, uint8 index);
// Adds a new function to the USB current configuration.
// Must be called before BindFunctions or after ClearFunctions.
AddFunction(FunctionDescriptor desc) -> (zx.status s);
// Tells the device to create child devices for the configuration's interfaces.
BindFunctions() -> (zx.status s);
// Tells the device to remove the child devices for the configuration's interfaces
// and reset the list of functions to empty.
ClearFunctions() -> (zx.status s);
// Returns the current USB mode.
GetMode() -> (zx.status s, uint32 mode);
// Sets the current USB mode.
SetMode(uint32 mode) -> (zx.status s);
// Adds a state change listener that is invoked when a state change completes.
SetStateChangeListener(request<Events> listener);