Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Poll USB during BIP39 derivation.
Browse files Browse the repository at this point in the history
This patch adds calls to usbPoll in the progress callback.  This
should address #98.

We call usbDelay instead of Poll, to call usbd_poll several times.
Otherwise it would only handle one event instead of handling all
events that were pending so far.  The ugly magic number 5 is a guess.

Note that we also need to set usbTiny, so that we don't recursively
process messages.  Since we don't know whether usbTiny is set, we
need to store the old value (especially true for u2f).

This fix also relies on another fix in libopencm3.
  • Loading branch information
jhoenicke authored and prusnak committed Nov 9, 2016
1 parent 4ce4cc5 commit 9287dd7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions firmware/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "debug.h"
#include "protect.h"
#include "layout2.h"
#include "usb.h"

Storage storage;

Expand Down Expand Up @@ -337,6 +338,7 @@ void storage_setHomescreen(const uint8_t *data, uint32_t size)

void get_root_node_callback(uint32_t iter, uint32_t total)
{
usbDelay(10); // handle up to ten usb interrupts.
layoutProgress("Waking up", 1000 * iter / total);
}

Expand All @@ -361,7 +363,9 @@ const uint8_t *storage_getSeed(bool usePassphrase)
storage_show_error();
}
}
char oldTiny = usbTiny(1);
mnemonic_to_seed(storage.mnemonic, usePassphrase ? sessionPassphrase : "", sessionSeed, get_root_node_callback); // BIP-0039
usbTiny(oldTiny);
sessionSeedCached = true;
sessionSeedUsesPassphrase = usePassphrase;
return sessionSeed;
Expand Down
4 changes: 3 additions & 1 deletion firmware/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,11 @@ void usbReconnect(void)
usbd_disconnect(usbd_dev, 0);
}

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

void usbDelay(int cycles)
Expand Down
2 changes: 1 addition & 1 deletion firmware/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
void usbInit(void);
void usbPoll(void);
void usbReconnect(void);
void usbTiny(char set);
char usbTiny(char set);
void usbDelay(int cycles);

#endif

0 comments on commit 9287dd7

Please sign in to comment.