diff --git a/embed/bootloader/main.c b/embed/bootloader/main.c index 29bad0bc7..d9c337f31 100644 --- a/embed/bootloader/main.c +++ b/embed/bootloader/main.c @@ -64,6 +64,7 @@ static void usb_init_all(void) { .serial_number = "000000000000000000000000", .interface = "TREZOR Interface", .usb21_enabled = sectrue, + .usb21_landing = sectrue, }; static uint8_t rx_buffer[USB_PACKET_SIZE]; diff --git a/embed/extmod/modtrezorio/modtrezorio-usb.h b/embed/extmod/modtrezorio/modtrezorio-usb.h index d7285c27d..e6045bab4 100644 --- a/embed/extmod/modtrezorio/modtrezorio-usb.h +++ b/embed/extmod/modtrezorio/modtrezorio-usb.h @@ -60,7 +60,8 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) { /// product: str='', /// serial_number: str='', /// interface: str='', -/// usb21_enabled: bool=True) -> None: +/// usb21_enabled: bool=True, +/// usb21_landing: bool=True) -> None: /// ''' /// ''' STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -77,6 +78,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar { MP_QSTR_serial_number, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} }, { MP_QSTR_interface, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} }, { MP_QSTR_usb21_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, + { MP_QSTR_usb21_landing, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, }; mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals); @@ -92,6 +94,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar const char *serial_number = get_0str(vals[8].u_obj, 0, 32); const char *interface = get_0str(vals[9].u_obj, 0, 32); const secbool usb21_enabled = vals[10].u_bool ? sectrue : secfalse; + const secbool usb21_landing = vals[11].u_bool ? sectrue : secfalse; CHECK_PARAM_RANGE(device_class, 0, 255) CHECK_PARAM_RANGE(device_subclass, 0, 255) @@ -128,6 +131,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar o->info.serial_number = serial_number; o->info.interface = interface; o->info.usb21_enabled = usb21_enabled; + o->info.usb21_landing = usb21_landing; mp_obj_list_init(&o->ifaces, 0); diff --git a/embed/prodtest/main.c b/embed/prodtest/main.c index f5d12309a..e96a67a92 100644 --- a/embed/prodtest/main.c +++ b/embed/prodtest/main.c @@ -109,6 +109,7 @@ static void usb_init_all(void) .serial_number = "000000000000", .interface = "TREZOR Interface", .usb21_enabled = secfalse, + .usb21_landing = secfalse, }; static uint8_t tx_packet[VCP_PACKET_LEN]; diff --git a/embed/trezorhal/usb.c b/embed/trezorhal/usb.c index 695efde13..57dff2b0f 100644 --- a/embed/trezorhal/usb.c +++ b/embed/trezorhal/usb.c @@ -61,6 +61,7 @@ static const USBD_DescriptorsTypeDef usb_descriptors; static const USBD_ClassTypeDef usb_class; static secbool usb21_enabled = secfalse; +static secbool usb21_landing = secfalse; static secbool __wur check_desc_str(const char *s) { if (NULL == s) return secfalse; @@ -72,6 +73,7 @@ void usb_init(const usb_dev_info_t *dev_info) { // enable/disable USB 2.1 features usb21_enabled = dev_info->usb21_enabled; + usb21_landing = dev_info->usb21_landing; // Device descriptor usb_dev_desc.bLength = sizeof(usb_device_descriptor_t); @@ -226,7 +228,7 @@ static uint8_t *usb_get_interface_str_descriptor(USBD_SpeedTypeDef speed, uint16 static uint8_t *usb_get_bos_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) { if (sectrue == usb21_enabled) { - static const uint8_t bos[] = { + static uint8_t bos[] = { // usb_bos_descriptor { 0x05, // uint8_t bLength USB_DESC_TYPE_BOS, // uint8_t bDescriptorType @@ -244,6 +246,7 @@ static uint8_t *usb_get_bos_descriptor(USBD_SpeedTypeDef speed, uint16_t *length USB_WEBUSB_LANDING_PAGE, // uint8_t iLandingPage // } }; + bos[28] = (sectrue == usb21_landing) ? USB_WEBUSB_LANDING_PAGE : 0; *length = sizeof(bos); return UNCONST(bos); } else { diff --git a/embed/trezorhal/usb.h b/embed/trezorhal/usb.h index ef83a4386..35fcc9258 100644 --- a/embed/trezorhal/usb.h +++ b/embed/trezorhal/usb.h @@ -116,6 +116,7 @@ typedef struct { const char *serial_number; const char *interface; secbool usb21_enabled; + secbool usb21_landing; } usb_dev_info_t; typedef enum { diff --git a/src/usb.py b/src/usb.py index 9be51ce5d..65597ec0e 100644 --- a/src/usb.py +++ b/src/usb.py @@ -60,6 +60,7 @@ bus = io.USB( product="TREZOR", interface="TREZOR Interface", serial_number=get_device_id(), + usb21_landing=False, ) bus.add(iface_wire) if __debug__: