Skip to content

Commit 94f000c

Browse files
authored
feat(legacy): enable USB HID in bitcoin-only firmware for factory mode (#187)
* feat(legacy): enable FIDO2/U2F in bitcoin-only firmware for factory mode * chore(legacy): bump firmware version to 3.17.2.
1 parent f3cbdfa commit 94f000c

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

legacy/Makefile.include

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,13 @@ endif
171171

172172
ifeq ($(BITCOIN_ONLY), 1)
173173
CFLAGS += -DBITCOIN_ONLY=1
174-
CFLAGS += -DU2F_ENABLED=0
175174
else
176175
CFLAGS += -DBITCOIN_ONLY=0
177-
CFLAGS += -DU2F_ENABLED=1
178176
endif
179177

178+
# U2F_ENABLED always enabled to support factory mode
179+
CFLAGS += -DU2F_ENABLED=1
180+
180181
ifeq ($(PRODUCTION), 0)
181182
CFLAGS += -DPRODUCTION=0
182183
CPUFLAGS += -DPRODUCTION=0

legacy/firmware/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ OBJS += se_chip.o
9191
OBJS += psbt/psbt.o
9292
OBJS += bip322_simple/bip322_simple.o
9393

94-
ifneq ($(BITCOIN_ONLY),1)
94+
# FIDO2 support (always compiled for factory mode)
9595
OBJS += fido2/ctap_trans.o
9696
OBJS += fido2/ctap.o
9797
OBJS += fido2/ctap_parse.o
9898
OBJS += fido2/resident_credential.o
99+
100+
ifneq ($(BITCOIN_ONLY),1)
99101
OBJS += ethereum.o
100102
OBJS += ethereum_definitions.o
101103
OBJS += ethereum_networks.o

legacy/firmware/usb.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ uint16_t s_usOffset;
9797
static const char *usb_strings[] = {USB_STRINGS};
9898
#undef X
9999

100+
static bool usb_fido_switch = true;
101+
100102
static struct usb_device_descriptor dev_descr = {
101103
.bLength = USB_DT_DEVICE_SIZE,
102104
.bDescriptorType = USB_DT_DEVICE,
@@ -277,9 +279,17 @@ static struct usb_config_descriptor config = {
277279
};
278280

279281
static void usb_init_ifaces(void) {
280-
bool fido_switch = true;
281-
config_getFidoSwitch(&fido_switch);
282+
#if BITCOIN_ONLY
282283

284+
if (se_isFactoryMode()) {
285+
usb_fido_switch = true;
286+
} else {
287+
usb_fido_switch = false;
288+
}
289+
290+
#else
291+
config_getFidoSwitch(&usb_fido_switch);
292+
#endif
283293
int idx = 0;
284294
ifaces[idx].num_altsetting = 1;
285295
ifaces[idx].altsetting = webusb_iface_main;
@@ -292,7 +302,7 @@ static void usb_init_ifaces(void) {
292302
#endif
293303

294304
#if U2F_ENABLED
295-
if (fido_switch) {
305+
if (usb_fido_switch) {
296306
ifaces[idx].num_altsetting = 1;
297307
ifaces[idx].altsetting = hid_iface_u2f;
298308
idx++;
@@ -394,9 +404,7 @@ static void set_config(usbd_device *dev, uint16_t wValue) {
394404
USB_PACKET_SIZE, main_rx_callback);
395405
#if U2F_ENABLED
396406

397-
bool fido_switch = false;
398-
config_getFidoSwitch(&fido_switch);
399-
if (fido_switch) {
407+
if (usb_fido_switch) {
400408
usbd_ep_setup(dev, ENDPOINT_ADDRESS_U2F_IN, USB_ENDPOINT_ATTR_INTERRUPT,
401409
USB_PACKET_SIZE, 0);
402410
usbd_ep_setup(dev, ENDPOINT_ADDRESS_U2F_OUT, USB_ENDPOINT_ATTR_INTERRUPT,
@@ -410,7 +418,7 @@ static void set_config(usbd_device *dev, uint16_t wValue) {
410418
USB_PACKET_SIZE, debug_rx_callback);
411419
#endif
412420
#if U2F_ENABLED
413-
if (fido_switch) {
421+
if (usb_fido_switch) {
414422
usbd_register_control_callback(
415423
dev, USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
416424
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, hid_control_request);
@@ -594,7 +602,6 @@ void usbPoll(void) {
594602
#endif
595603
}
596604

597-
#if !BITCOIN_ONLY
598605
void usb_u2f_data_send(void) {
599606
static const uint8_t *data;
600607
while (1) {
@@ -608,7 +615,7 @@ void usb_u2f_data_send(void) {
608615
}
609616
}
610617
}
611-
#endif
618+
612619
void usbReconnect(void) {
613620
if (usbd_dev != NULL) {
614621
usbd_disconnect(usbd_dev, 1);

legacy/firmware/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#define ONEKEY_VER_MAJOR 3
1010
#define ONEKEY_VER_MINOR 17
11-
#define ONEKEY_VER_PATCH 1
11+
#define ONEKEY_VER_PATCH 2
1212

13-
#define ONEKEY_VERSION "3.17.1"
13+
#define ONEKEY_VERSION "3.17.2"
1414
// Deprecated
1515
#define ONEKEY_VERSION_HEX 0x3F00
1616

legacy/script/cibuild

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ set -e
77

88
cd "$(dirname "$0")/.."
99

10-
if [ "$BITCOIN_ONLY" != 1 ]; then
11-
vendor/trezor-common/tools/cointool.py render firmware/fido2
12-
fi
10+
vendor/trezor-common/tools/cointool.py render firmware/fido2
1311

1412
if [ "$EMULATOR" = 1 ]; then
1513
make -C emulator

0 commit comments

Comments
 (0)