1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-20 21:38:26 +00:00
trezor-firmware/embed/trezorhal/usb_webusb-defs.h

56 lines
2.3 KiB
C
Raw Normal View History

/*
* Copyright (c) Jan Pochyla, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
2018-01-23 00:34:47 +00:00
#define USB_WEBUSB_VENDOR_CODE 0x01 // arbitrary
#define USB_WEBUSB_LANDING_PAGE 0x01 // arbitrary
typedef struct __attribute__((packed)) {
usb_interface_descriptor_t iface;
usb_endpoint_descriptor_t ep_in;
usb_endpoint_descriptor_t ep_out;
} usb_webusb_descriptor_block_t;
/* usb_webusb_info_t contains all information for setting up a WebUSB interface. All
* passed pointers need to live at least until the interface is disabled
* (usb_stop is called). */
typedef struct {
uint8_t *rx_buffer; // With length of max_packet_len bytes
uint8_t iface_num; // Address of this WebUSB interface
uint8_t ep_in; // Address of IN endpoint (with the highest bit set)
uint8_t ep_out; // Address of OUT endpoint
uint8_t subclass; // usb_iface_subclass_t
uint8_t protocol; // usb_iface_protocol_t
uint8_t polling_interval; // In units of 1ms
uint8_t max_packet_len; // Length of the biggest report and of rx_buffer
} usb_webusb_info_t;
/* usb_webusb_state_t encapsulates all state used by enabled WebUSB interface. It
* needs to be completely initialized in usb_webusb_add and reset in
* usb_webusb_class_init. See usb_webusb_info_t for details of the configuration
* fields. */
typedef struct {
const usb_webusb_descriptor_block_t *desc_block;
uint8_t *rx_buffer;
uint8_t ep_in;
uint8_t ep_out;
uint8_t max_packet_len;
uint8_t alt_setting; // For SET_INTERFACE/GET_INTERFACE setup reqs
uint8_t last_read_len; // Length of data read into rx_buffer
uint8_t ep_in_is_idle; // Set to 1 after IN endpoint gets idle
} usb_webusb_state_t;
secbool __wur usb_webusb_add(const usb_webusb_info_t *webusb_info);
secbool __wur usb_webusb_can_read(uint8_t iface_num);
secbool __wur usb_webusb_can_write(uint8_t iface_num);
int __wur usb_webusb_read(uint8_t iface_num, uint8_t *buf, uint32_t len);
int __wur usb_webusb_write(uint8_t iface_num, const uint8_t *buf, uint32_t len);
int __wur usb_webusb_read_select(uint32_t timeout);
int __wur usb_webusb_read_blocking(uint8_t iface_num, uint8_t *buf, uint32_t len, int timeout);
int __wur usb_webusb_write_blocking(uint8_t iface_num, const uint8_t *buf, uint32_t len, int timeout);