1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

Merge pull request #845 from trezor/prusnak/webusb-popup

Don't show WebUSB popup in firmware, in bootloader only if no firmware present
This commit is contained in:
Pavol Rusnak 2020-02-19 18:18:01 +01:00 committed by GitHub
commit 581e46ff87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 23 deletions

View File

@ -50,8 +50,8 @@ static const uint8_t * const BOOTLOADER_KEYS[] = {
#define USB_IFACE_NUM 0 #define USB_IFACE_NUM 0
static void usb_init_all(void) { static void usb_init_all(secbool usb21_landing) {
static const usb_dev_info_t dev_info = { usb_dev_info_t dev_info = {
.device_class = 0x00, .device_class = 0x00,
.device_subclass = 0x00, .device_subclass = 0x00,
.device_protocol = 0x00, .device_protocol = 0x00,
@ -63,7 +63,7 @@ static void usb_init_all(void) {
.serial_number = "000000000000000000000000", .serial_number = "000000000000000000000000",
.interface = "TREZOR Interface", .interface = "TREZOR Interface",
.usb21_enabled = sectrue, .usb21_enabled = sectrue,
.usb21_landing = sectrue, .usb21_landing = usb21_landing,
}; };
static uint8_t rx_buffer[USB_PACKET_SIZE]; static uint8_t rx_buffer[USB_PACKET_SIZE];
@ -88,7 +88,9 @@ static void usb_init_all(void) {
static secbool bootloader_usb_loop(const vendor_header *const vhdr, static secbool bootloader_usb_loop(const vendor_header *const vhdr,
const image_header *const hdr) { const image_header *const hdr) {
usb_init_all(); // if both are NULL, we don't have a firmware installed
// let's show a webusb landing page in this case
usb_init_all((vhdr == NULL && hdr == NULL) ? sectrue : secfalse);
uint8_t buf[USB_PACKET_SIZE]; uint8_t buf[USB_PACKET_SIZE];

View File

@ -59,6 +59,7 @@ bus = io.USB(
product="TREZOR", product="TREZOR",
interface="TREZOR Interface", interface="TREZOR Interface",
serial_number=get_device_id(), serial_number=get_device_id(),
usb21_landing=False,
) )
bus.add(iface_wire) bus.add(iface_wire)
if __debug__: if __debug__:

View File

@ -18,6 +18,7 @@ usb = io.USB(
manufacturer="SatoshiLabs", manufacturer="SatoshiLabs",
product="TREZOR", product="TREZOR",
serial_number="000000000000000000000000", serial_number="000000000000000000000000",
usb21_landing=False,
) )
usb.add(usb_vcp) usb.add(usb_vcp)

View File

@ -440,23 +440,38 @@ static void set_config(usbd_device *dev, uint16_t wValue) {
static usbd_device *usbd_dev; static usbd_device *usbd_dev;
static uint8_t usbd_control_buffer[256] __attribute__((aligned(2))); static uint8_t usbd_control_buffer[256] __attribute__((aligned(2)));
static const struct usb_device_capability_descriptor *capabilities[] = { static const struct usb_device_capability_descriptor *capabilities_landing[] = {
(const struct usb_device_capability_descriptor (const struct usb_device_capability_descriptor
*)&webusb_platform_capability_descriptor, *)&webusb_platform_capability_descriptor_landing,
}; };
static const struct usb_bos_descriptor bos_descriptor = { static const struct usb_device_capability_descriptor
*capabilities_no_landing[] = {
(const struct usb_device_capability_descriptor
*)&webusb_platform_capability_descriptor_no_landing,
};
static const struct usb_bos_descriptor bos_descriptor_landing = {
.bLength = USB_DT_BOS_SIZE, .bLength = USB_DT_BOS_SIZE,
.bDescriptorType = USB_DT_BOS, .bDescriptorType = USB_DT_BOS,
.bNumDeviceCaps = sizeof(capabilities) / sizeof(capabilities[0]), .bNumDeviceCaps =
.capabilities = capabilities}; sizeof(capabilities_landing) / sizeof(capabilities_landing[0]),
.capabilities = capabilities_landing};
static void usbInit(void) { static const struct usb_bos_descriptor bos_descriptor_no_landing = {
.bLength = USB_DT_BOS_SIZE,
.bDescriptorType = USB_DT_BOS,
.bNumDeviceCaps =
sizeof(capabilities_no_landing) / sizeof(capabilities_no_landing[0]),
.capabilities = capabilities_no_landing};
static void usbInit(bool firmware_present) {
usbd_dev = usbd_init(&otgfs_usb_driver, &dev_descr, &config, usb_strings, usbd_dev = usbd_init(&otgfs_usb_driver, &dev_descr, &config, usb_strings,
sizeof(usb_strings) / sizeof(const char *), sizeof(usb_strings) / sizeof(const char *),
usbd_control_buffer, sizeof(usbd_control_buffer)); usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_register_set_config_callback(usbd_dev, set_config); usbd_register_set_config_callback(usbd_dev, set_config);
usb21_setup(usbd_dev, &bos_descriptor); usb21_setup(usbd_dev, firmware_present ? &bos_descriptor_no_landing
: &bos_descriptor_landing);
webusb_setup(usbd_dev, "trezor.io/start"); webusb_setup(usbd_dev, "trezor.io/start");
winusb_setup(usbd_dev, USB_INTERFACE_INDEX_MAIN); winusb_setup(usbd_dev, USB_INTERFACE_INDEX_MAIN);
} }
@ -491,7 +506,7 @@ static void checkButtons(void) {
void usbLoop(void) { void usbLoop(void) {
bool firmware_present = firmware_present_new(); bool firmware_present = firmware_present_new();
usbInit(); usbInit(firmware_present);
for (;;) { for (;;) {
usbd_poll(usbd_dev); usbd_poll(usbd_dev);
if (!firmware_present && if (!firmware_present &&

View File

@ -373,7 +373,7 @@ static uint8_t usbd_control_buffer[256] __attribute__((aligned(2)));
static const struct usb_device_capability_descriptor *capabilities[] = { static const struct usb_device_capability_descriptor *capabilities[] = {
(const struct usb_device_capability_descriptor (const struct usb_device_capability_descriptor
*)&webusb_platform_capability_descriptor, *)&webusb_platform_capability_descriptor_no_landing,
}; };
static const struct usb_bos_descriptor bos_descriptor = { static const struct usb_bos_descriptor bos_descriptor = {

View File

@ -23,15 +23,27 @@
#include "util.h" #include "util.h"
#include "webusb.h" #include "webusb.h"
const struct webusb_platform_descriptor webusb_platform_capability_descriptor = const struct webusb_platform_descriptor
{.bLength = WEBUSB_PLATFORM_DESCRIPTOR_SIZE, webusb_platform_capability_descriptor_landing = {
.bDescriptorType = USB_DT_DEVICE_CAPABILITY, .bLength = WEBUSB_PLATFORM_DESCRIPTOR_SIZE,
.bDevCapabilityType = USB_DC_PLATFORM, .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
.bReserved = 0, .bDevCapabilityType = USB_DC_PLATFORM,
.platformCapabilityUUID = WEBUSB_UUID, .bReserved = 0,
.bcdVersion = 0x0100, .platformCapabilityUUID = WEBUSB_UUID,
.bVendorCode = WEBUSB_VENDOR_CODE, .bcdVersion = 0x0100,
.iLandingPage = 1}; .bVendorCode = WEBUSB_VENDOR_CODE,
.iLandingPage = 1};
const struct webusb_platform_descriptor
webusb_platform_capability_descriptor_no_landing = {
.bLength = WEBUSB_PLATFORM_DESCRIPTOR_SIZE,
.bDescriptorType = USB_DT_DEVICE_CAPABILITY,
.bDevCapabilityType = USB_DC_PLATFORM,
.bReserved = 0,
.platformCapabilityUUID = WEBUSB_UUID,
.bcdVersion = 0x0100,
.bVendorCode = WEBUSB_VENDOR_CODE,
.iLandingPage = 0};
static const char* webusb_https_url; static const char* webusb_https_url;

View File

@ -26,7 +26,9 @@
#define WEBUSB_VENDOR_CODE 0x01 #define WEBUSB_VENDOR_CODE 0x01
extern const struct webusb_platform_descriptor extern const struct webusb_platform_descriptor
webusb_platform_capability_descriptor; webusb_platform_capability_descriptor_landing;
extern const struct webusb_platform_descriptor
webusb_platform_capability_descriptor_no_landing;
extern void webusb_setup(usbd_device* usbd_dev, const char* https_url); extern void webusb_setup(usbd_device* usbd_dev, const char* https_url);