Skip to content

Commit

Permalink
Merge pull request #2 from shapeshift/fix-u2f-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnerdhair authored Apr 14, 2022
2 parents 65eddf2 + 06b089b commit 70064d7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/keepkey/board/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ typedef enum {
RAW_MESSAGE_ERROR
} RawMessageState;

extern bool msg_tiny_flag;

typedef void (*raw_msg_handler_t)(RawMessage *msg, uint32_t frame_length);

const pb_field_t *message_fields(MessageMapType type, MessageType msg_id,
Expand Down
2 changes: 1 addition & 1 deletion lib/board/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void usb_rx_helper(const uint8_t *buf, size_t length, MessageMapType type) {
}

/* Tiny messages */
static bool msg_tiny_flag = false;
bool msg_tiny_flag = false;
static CONFIDENTIAL uint8_t msg_tiny[MSG_TINY_BFR_SZ];
static uint16_t msg_tiny_id = MSG_TINY_TYPE_ERROR; /* Default to error type */

Expand Down
9 changes: 4 additions & 5 deletions lib/board/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifdef EMULATOR

#include "keepkey/board/usb.h"
#include "keepkey/board/messages.h"
#include "keepkey/board/timer.h"
#include "keepkey/emulator/emulator.h"

Expand All @@ -32,8 +33,6 @@ extern usb_rx_callback_t user_rx_callback;
extern usb_rx_callback_t user_debug_rx_callback;
#endif

static volatile char tiny = 0;

void usbInit(const char *origin_url) {
(void)origin_url;
emulatorSocketInit();
Expand All @@ -47,7 +46,7 @@ void usbPoll(void) {

int iface = 0;
if (0 < (len = emulatorSocketRead(&iface, buf, sizeof(buf)))) {
if (!tiny) {
if (!msg_tiny_flag) {
if (iface == 0) {
user_rx_callback(&buf, len);
} else if (iface == 1) {
Expand Down Expand Up @@ -75,8 +74,8 @@ bool usb_debug_tx(uint8_t *msg, uint32_t len) {
#endif

char usbTiny(char set) {
char old = tiny;
tiny = set;
char old = msg_tiny_flag;
msg_tiny_flag = set;
return old;
}

Expand Down
8 changes: 3 additions & 5 deletions lib/board/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ static enum usbd_request_return_codes hid_control_request(
return 1;
}

static volatile char tiny = 0;

static void main_rx_callback(usbd_device *dev, uint8_t ep) {
(void)ep;
static CONFIDENTIAL uint8_t buf[64] __attribute__((aligned(4)));
Expand All @@ -335,7 +333,7 @@ static void u2f_rx_callback(usbd_device *dev, uint8_t ep) {
if (usbd_ep_read_packet(dev, ENDPOINT_ADDRESS_U2F_OUT, buf, 64) != 64) return;

if (user_u2f_rx_callback) {
user_u2f_rx_callback(tiny, (const U2FHID_FRAME *)(void *)buf);
user_u2f_rx_callback(msg_tiny_flag, (const U2FHID_FRAME *)(void *)buf);
}
}

Expand Down Expand Up @@ -423,8 +421,8 @@ void usbReconnect(void) {
}

char usbTiny(char set) {
char old = tiny;
tiny = set;
char old = msg_tiny_flag;
msg_tiny_flag = set;
return old;
}

Expand Down

0 comments on commit 70064d7

Please sign in to comment.