Poll USB during BIP39 derivation.

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.
pull/25/head
Jochen Hoenicke 8 years ago committed by Pavol Rusnak
parent 4ce4cc5605
commit 9287dd7e04
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -39,6 +39,7 @@
#include "debug.h"
#include "protect.h"
#include "layout2.h"
#include "usb.h"
Storage storage;
@ -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);
}
@ -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;

@ -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)

@ -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

Loading…
Cancel
Save