1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-01 12:22:34 +00:00

legacy: style

This commit is contained in:
Tomas Susanka 2019-11-18 08:52:03 +00:00
parent 8931ac1ef1
commit 3054a56288
7 changed files with 427 additions and 468 deletions

9
legacy/firmware/config.c Executable file → Normal file
View File

@ -828,18 +828,15 @@ bool session_getState(const uint8_t *salt, uint8_t *state,
bool session_isUnlocked(void) { return sectrue == storage_is_unlocked(); } bool session_isUnlocked(void) { return sectrue == storage_is_unlocked(); }
bool session_isUseOnDeviceTextInputCached(void) bool session_isUseOnDeviceTextInputCached(void) {
{
return sectrue == sessionUseOnDeviceTextInputCached; return sectrue == sessionUseOnDeviceTextInputCached;
} }
bool session_isUseOnDeviceTextInput(void) bool session_isUseOnDeviceTextInput(void) {
{
return sectrue == sessionUseOnDeviceTextInput; return sectrue == sessionUseOnDeviceTextInput;
} }
void session_setUseOnDeviceTextInput(bool use) void session_setUseOnDeviceTextInput(bool use) {
{
sessionUseOnDeviceTextInputCached = sectrue; sessionUseOnDeviceTextInputCached = sectrue;
sessionUseOnDeviceTextInput = use ? sectrue : secfalse; sessionUseOnDeviceTextInput = use ? sectrue : secfalse;
} }

56
legacy/firmware/layout2.c Executable file → Normal file
View File

@ -243,16 +243,19 @@ void layoutProgressSwipe(const char *desc, int permil) {
layoutProgress(desc, permil); layoutProgress(desc, permil);
} }
void layoutScrollInput(const char *text, int text_width, int num_total, int num_screen, int current_index, const char entries[], int horizontal_padding, int num_group, const int groups[], int num_skip_in_groups, bool draw_caret) void layoutScrollInput(const char *text, int text_width, int num_total,
{ int num_screen, int current_index, const char entries[],
int horizontal_padding, int num_group,
const int groups[], int num_skip_in_groups,
bool draw_caret) {
layoutLast = layoutScrollInput; layoutLast = layoutScrollInput;
oledClear(); oledClear();
if (num_screen % 2 > 0) if (num_screen % 2 > 0) ++num_screen;
++num_screen;
if (num_total <= 0 || num_screen <= 0 || current_index < 0 || current_index >= num_total || groups[num_group - 1] > num_total) if (num_total <= 0 || num_screen <= 0 || current_index < 0 ||
current_index >= num_total || groups[num_group - 1] > num_total)
return; return;
const int CenterX = OLED_WIDTH / 2; const int CenterX = OLED_WIDTH / 2;
@ -263,8 +266,7 @@ void layoutScrollInput(const char *text, int text_width, int num_total, int num_
int t = (num_screen - 1) / 2; int t = (num_screen - 1) / 2;
char letter[2]; char letter[2];
letter[1] = 0; letter[1] = 0;
for (int i = 0; i < num_screen && i < num_total; ++i) for (int i = 0; i < num_screen && i < num_total; ++i) {
{
int x = CenterX - gap * (t - i); int x = CenterX - gap * (t - i);
int n = (current_index + i - t + num_total) % num_total; int n = (current_index + i - t + num_total) % num_total;
letter[0] = entries[n]; letter[0] = entries[n];
@ -272,7 +274,8 @@ void layoutScrollInput(const char *text, int text_width, int num_total, int num_
} }
int halfgap = gap / 2; int halfgap = gap / 2;
oledInvert(CenterX - halfgap, Y - 2, CenterX + halfgap - 1, Y + FONT_HEIGHT + 1); oledInvert(CenterX - halfgap, Y - 2, CenterX + halfgap - 1,
Y + FONT_HEIGHT + 1);
const int LineY = Y + FONT_HEIGHT * 2 - 2; const int LineY = Y + FONT_HEIGHT * 2 - 2;
@ -280,7 +283,8 @@ void layoutScrollInput(const char *text, int text_width, int num_total, int num_
oledPartialHLine(horizontal_padding, OLED_WIDTH - horizontal_padding, LineY); oledPartialHLine(horizontal_padding, OLED_WIDTH - horizontal_padding, LineY);
for (int i = 0; i < num_group; ++i) for (int i = 0; i < num_group; ++i)
oledPartialVLine(horizontal_padding + width * groups[i] / num_total, LineY - 1, LineY); oledPartialVLine(horizontal_padding + width * groups[i] / num_total,
LineY - 1, LineY);
int x = horizontal_padding + width * current_index / num_total; int x = horizontal_padding + width * current_index / num_total;
oledPartialHLine(x, x + 1, LineY - 1); oledPartialHLine(x, x + 1, LineY - 1);
@ -289,8 +293,7 @@ void layoutScrollInput(const char *text, int text_width, int num_total, int num_
char groupinfo[] = "?-?"; char groupinfo[] = "?-?";
int group; int group;
for (group = 0; group < num_group - 1; ++group) for (group = 0; group < num_group - 1; ++group) {
{
if (current_index >= groups[group] && current_index < groups[group + 1]) if (current_index >= groups[group] && current_index < groups[group + 1])
break; break;
} }
@ -301,16 +304,16 @@ void layoutScrollInput(const char *text, int text_width, int num_total, int num_
oledHLine(OLED_HEIGHT / 2 - 5); oledHLine(OLED_HEIGHT / 2 - 5);
if (text) if (text)
oledDrawStringCenterMultiline(OLED_HEIGHT - FONT_HEIGHT * 2 - 1, text, 1, text_width); oledDrawStringCenterMultiline(OLED_HEIGHT - FONT_HEIGHT * 2 - 1, text, 1,
text_width);
if (draw_caret) if (draw_caret) oledDrawCaret();
oledDrawCaret();
oledRefresh(); oledRefresh();
} }
void layoutCheckPassphrase(const char *passphrase, int text_width, bool enable_edit, bool enable_done_yes) void layoutCheckPassphrase(const char *passphrase, int text_width,
{ bool enable_edit, bool enable_done_yes) {
layoutLast = layoutCheckPassphrase; layoutLast = layoutCheckPassphrase;
layoutSwipe(); layoutSwipe();
@ -325,22 +328,27 @@ void layoutCheckPassphrase(const char *passphrase, int text_width, bool enable_e
oledDrawStringCenterMultiline(OLED_HEIGHT / 2 - 2, passphrase, 1, text_width); oledDrawStringCenterMultiline(OLED_HEIGHT / 2 - 2, passphrase, 1, text_width);
if (enable_edit) if (enable_edit) {
{
const char *btnNo = "Edit"; const char *btnNo = "Edit";
oledDrawString(1, OLED_HEIGHT - 8, "\x15", 0); oledDrawString(1, OLED_HEIGHT - 8, "\x15", 0);
oledDrawString(fontCharWidth(0, '\x15') + 3, OLED_HEIGHT - 8, btnNo, 0); oledDrawString(fontCharWidth(0, '\x15') + 3, OLED_HEIGHT - 8, btnNo, 0);
oledInvert(0, OLED_HEIGHT - 9, fontCharWidth(0, '\x15') + oledStringWidth(btnNo, 0) + 2, OLED_HEIGHT - 1); oledInvert(0, OLED_HEIGHT - 9,
fontCharWidth(0, '\x15') + oledStringWidth(btnNo, 0) + 2,
OLED_HEIGHT - 1);
} }
if (enable_done_yes) if (enable_done_yes) {
{
const char *DONE = "Done"; const char *DONE = "Done";
const char *NEXT = "Next"; const char *NEXT = "Next";
const char *btnYes = enable_edit ? DONE : NEXT; const char *btnYes = enable_edit ? DONE : NEXT;
oledDrawString(OLED_WIDTH - fontCharWidth(0, '\x06') - 1, OLED_HEIGHT - 8, "\x06", 0); oledDrawString(OLED_WIDTH - fontCharWidth(0, '\x06') - 1, OLED_HEIGHT - 8,
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 3, OLED_HEIGHT - 8, btnYes, 0); "\x06", 0);
oledInvert(OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); oledDrawString(
OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 3,
OLED_HEIGHT - 8, btnYes, 0);
oledInvert(
OLED_WIDTH - oledStringWidth(btnYes, 0) - fontCharWidth(0, '\x06') - 4,
OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
} }
oledHLine(OLED_HEIGHT - 13); oledHLine(OLED_HEIGHT - 13);

9
legacy/firmware/layout2.h Executable file → Normal file
View File

@ -44,8 +44,13 @@ void layoutDialogSwipe(const BITMAP *icon, const char *btnNo,
const char *line5, const char *line6); const char *line5, const char *line6);
void layoutProgressSwipe(const char *desc, int permil); void layoutProgressSwipe(const char *desc, int permil);
void layoutScrollInput(const char *text, int text_width, int num_total, int num_screen, int current_index, const char entries[], int horizontal_padding, int num_group, const int groups[], int num_skip_in_groups, bool draw_caret); void layoutScrollInput(const char *text, int text_width, int num_total,
void layoutCheckPassphrase(const char *passphrase, int text_width, bool enable_edit, bool enable_done); int num_screen, int current_index, const char entries[],
int horizontal_padding, int num_group,
const int groups[], int num_skip_in_groups,
bool draw_caret);
void layoutCheckPassphrase(const char *passphrase, int text_width,
bool enable_edit, bool enable_done);
void layoutScreensaver(void); void layoutScreensaver(void);
void layoutHome(void); void layoutHome(void);

248
legacy/firmware/protect.c Executable file → Normal file
View File

@ -30,9 +30,9 @@
#include "messages.pb.h" #include "messages.pb.h"
#include "oled.h" #include "oled.h"
#include "pinmatrix.h" #include "pinmatrix.h"
#include "rng.h"
#include "usb.h" #include "usb.h"
#include "util.h" #include "util.h"
#include "rng.h"
#define MAX_WRONG_PINS 15 #define MAX_WRONG_PINS 15
@ -44,7 +44,8 @@
#define NUM_PASSPHRASE_LINES 3 #define NUM_PASSPHRASE_LINES 3
#define CHAR_AND_SPACE_WIDTH (5 + 1) #define CHAR_AND_SPACE_WIDTH (5 + 1)
#define PASSPHRASE_WIDTH (MAX_PASSPHRASE_LEN / NUM_PASSPHRASE_LINES * CHAR_AND_SPACE_WIDTH) #define PASSPHRASE_WIDTH \
(MAX_PASSPHRASE_LEN / NUM_PASSPHRASE_LINES * CHAR_AND_SPACE_WIDTH)
#define LAST_PASSPHRASE_INDEX (MAX_PASSPHRASE_LEN - 1) #define LAST_PASSPHRASE_INDEX (MAX_PASSPHRASE_LEN - 1)
@ -54,15 +55,14 @@
bool protectAbortedByCancel = false; bool protectAbortedByCancel = false;
bool protectAbortedByInitialize = false; bool protectAbortedByInitialize = false;
void buttonCheckRepeat(bool *yes, bool *no, bool *confirm) void buttonCheckRepeat(bool *yes, bool *no, bool *confirm) {
{
*yes = false; *yes = false;
*no = false; *no = false;
*confirm = false; *confirm = false;
const int Threshold0 = 20; const int Threshold0 = 20;
const int Thresholds[] = { Threshold0, 80, 20, 18, 16, 14, 12, 10, 8, 6, 4 }; const int Thresholds[] = {Threshold0, 80, 20, 18, 16, 14, 12, 10, 8, 6, 4};
const int MaxThresholdLevel = sizeof(Thresholds)/sizeof(Thresholds[0]) - 1; const int MaxThresholdLevel = sizeof(Thresholds) / sizeof(Thresholds[0]) - 1;
static int yesthreshold = Threshold0; static int yesthreshold = Threshold0;
static int nothreshold = Threshold0; static int nothreshold = Threshold0;
@ -75,80 +75,57 @@ void buttonCheckRepeat(bool *yes, bool *no, bool *confirm)
usbSleep(5); usbSleep(5);
buttonUpdate(); buttonUpdate();
if (both) if (both) {
{ if (!button.YesDown && !button.NoDown) {
if (!button.YesDown && !button.NoDown)
{
both = false; both = false;
yeslevel = 0; yeslevel = 0;
nolevel = 0; nolevel = 0;
yesthreshold = Thresholds[0]; yesthreshold = Thresholds[0];
nothreshold = Thresholds[0]; nothreshold = Thresholds[0];
} }
} } else if ((button.YesDown && button.NoDown) ||
else if ((button.YesDown && button.NoDown) (button.YesUp && button.NoDown) ||
|| (button.YesUp && button.NoDown) (button.YesDown && button.NoUp) || (button.YesUp && button.NoUp)) {
|| (button.YesDown && button.NoUp) if (!yeslevel && !nolevel) {
|| (button.YesUp && button.NoUp))
{
if (!yeslevel && !nolevel)
{
both = true; both = true;
*confirm = true; *confirm = true;
} }
} } else {
else if (button.YesUp) {
{ if (!yeslevel) *yes = true;
if (button.YesUp)
{
if (!yeslevel)
*yes = true;
yeslevel = 0; yeslevel = 0;
yesthreshold = Thresholds[0]; yesthreshold = Thresholds[0];
} } else if (button.YesDown >= yesthreshold) {
else if (button.YesDown >= yesthreshold) if (yeslevel < MaxThresholdLevel) yeslevel++;
{
if (yeslevel < MaxThresholdLevel)
yeslevel++;
yesthreshold += Thresholds[yeslevel]; yesthreshold += Thresholds[yeslevel];
*yes = true; *yes = true;
} }
if (button.NoUp) if (button.NoUp) {
{ if (!nolevel) *no = true;
if (!nolevel)
*no = true;
nolevel = 0; nolevel = 0;
nothreshold = Thresholds[0]; nothreshold = Thresholds[0];
} } else if (button.NoDown >= nothreshold) {
else if (button.NoDown >= nothreshold) if (nolevel < MaxThresholdLevel) nolevel++;
{
if (nolevel < MaxThresholdLevel)
nolevel++;
nothreshold += Thresholds[nolevel]; nothreshold += Thresholds[nolevel];
*no = true; *no = true;
} }
} }
} }
void buttonWaitForYesUp(void) void buttonWaitForYesUp(void) {
{
buttonUpdate(); buttonUpdate();
for(;;) for (;;) {
{
usbSleep(5); usbSleep(5);
buttonUpdate(); buttonUpdate();
if (button.YesUp) if (button.YesUp) break;
break;
} }
} }
void buttonWaitForIdle(void) void buttonWaitForIdle(void) {
{
buttonUpdate(); buttonUpdate();
for(;;) for (;;) {
{
usbSleep(5); usbSleep(5);
buttonUpdate(); buttonUpdate();
if (!button.YesDown && !button.YesUp && !button.NoDown && !button.NoUp) if (!button.YesDown && !button.YesUp && !button.NoDown && !button.NoUp)
@ -156,18 +133,17 @@ void buttonWaitForIdle(void)
} }
} }
void requestOnDeviceTextInput(void) void requestOnDeviceTextInput(void) {
{ layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL,
layoutDialog(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you like to use"), _("on-device text input?"), NULL, NULL, NULL, NULL); _("Do you like to use"), _("on-device text input?"), NULL, NULL,
NULL, NULL);
buttonUpdate(); buttonUpdate();
for(;;) for (;;) {
{
usbSleep(5); usbSleep(5);
buttonUpdate(); buttonUpdate();
if (button.YesUp || button.NoUp) if (button.YesUp || button.NoUp) break;
break;
} }
layoutSwipe(); layoutSwipe();
@ -450,33 +426,26 @@ bool protectPassphraseComputer(void) {
return result; return result;
} }
int inputPassphraseScroll(char *passphrase, int *passphrasecharindex, const char entries[], int entryindex, int numtotal, int numscreen, int padding, const int groups[], int numgroup, int skip, int *caret) int inputPassphraseScroll(char *passphrase, int *passphrasecharindex,
{ const char entries[], int entryindex, int numtotal,
for (; ; *caret = (*caret + 1) % CARET_CYCLE) int numscreen, int padding, const int groups[],
{ int numgroup, int skip, int *caret) {
for (;; *caret = (*caret + 1) % CARET_CYCLE) {
bool yes, no, confirm; bool yes, no, confirm;
buttonCheckRepeat(&yes, &no, &confirm); buttonCheckRepeat(&yes, &no, &confirm);
if (confirm) if (confirm) {
{
buttonWaitForIdle(); buttonWaitForIdle();
if (entries[entryindex] == BACKSPACE) if (entries[entryindex] == BACKSPACE) {
{ if (*passphrasecharindex > 0) {
if (*passphrasecharindex > 0)
{
--(*passphrasecharindex); --(*passphrasecharindex);
passphrase[*passphrasecharindex] = 0; passphrase[*passphrasecharindex] = 0;
} }
} } else if (entries[entryindex] == DONE) {
else if (entries[entryindex] == DONE)
{
return INPUT_DONE; return INPUT_DONE;
} } else {
else if (*passphrasecharindex < LAST_PASSPHRASE_INDEX) {
{
if (*passphrasecharindex < LAST_PASSPHRASE_INDEX)
{
passphrase[*passphrasecharindex] = entries[entryindex]; passphrase[*passphrasecharindex] = entries[entryindex];
++(*passphrasecharindex); ++(*passphrasecharindex);
} }
@ -484,47 +453,48 @@ int inputPassphraseScroll(char *passphrase, int *passphrasecharindex, const char
} }
entryindex = random32() % numtotal; entryindex = random32() % numtotal;
} } else {
else if (yes) entryindex = (entryindex + 1) % numtotal;
{ if (no) entryindex = (entryindex - 1 + numtotal) % numtotal;
if (yes)
entryindex = (entryindex + 1) % numtotal;
if (no)
entryindex = (entryindex - 1 + numtotal) % numtotal;
} }
layoutScrollInput(passphrase, PASSPHRASE_WIDTH, numtotal, numscreen, entryindex, entries, padding, numgroup, groups, skip, *caret < CARET_SHOW); layoutScrollInput(passphrase, PASSPHRASE_WIDTH, numtotal, numscreen,
entryindex, entries, padding, numgroup, groups, skip,
*caret < CARET_SHOW);
} }
} }
int findCharIndex(const char entries[], char needle, int numtotal, int startindex, bool forward) int findCharIndex(const char entries[], char needle, int numtotal,
{ int startindex, bool forward) {
int index = startindex; int index = startindex;
int step = forward ? 1 : -1; int step = forward ? 1 : -1;
while (index >= 0 && index < numtotal) while (index >= 0 && index < numtotal) {
{ if (entries[index] == needle) return index;
if (entries[index] == needle)
return index;
index += step; index += step;
} }
return startindex; return startindex;
} }
void inputPassphrase(char *passphrase) void inputPassphrase(char *passphrase) {
{
const char Entries[] = { const char Entries[] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', BACKSPACE, DONE, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', BACKSPACE, DONE, 'h', 'i', BACKSPACE, DONE, 'j', 'k', 'l',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', SPACE, BACKSPACE, DONE, 'm', 'n', 'o', 'p', 'q', 'r', BACKSPACE,
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', BACKSPACE, DONE, DONE, 's', 't', 'u', 'v', 'w', 'x',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', BACKSPACE, DONE, 'y', 'z', SPACE, BACKSPACE, DONE, 'A', 'B',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', SPACE, BACKSPACE, DONE, 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', BACKSPACE, DONE, BACKSPACE, DONE, 'J', 'K', 'L', 'M', 'N',
'!', '@', '#', '$', '\x25', '^', '&', '*', '(', ')', BACKSPACE, DONE, 'O', 'P', 'Q', 'R', BACKSPACE, DONE, 'S',
'`', '-', '=', '[', ']', '\\', ';', '\'', ',', '.', '/', BACKSPACE, DONE, 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'~', '_', '+', '{', '}', '|', ':', '\'', '<', '>', '?', BACKSPACE, DONE SPACE, BACKSPACE, DONE, '1', '2', '3', '4',
}; '5', '6', '7', '8', '9', '0', BACKSPACE,
const int EntriesGroups[] = { 0, 11, 22, 33, 44, 55, 66, 78, 90, 103, 116 }; DONE, '!', '@', '#', '$', '\x25', '^',
'&', '*', '(', ')', BACKSPACE, DONE, '`',
'-', '=', '[', ']', '\\', ';', '\'',
',', '.', '/', BACKSPACE, DONE, '~', '_',
'+', '{', '}', '|', ':', '\'', '<',
'>', '?', BACKSPACE, DONE};
const int EntriesGroups[] = {0, 11, 22, 33, 44, 55, 66, 78, 90, 103, 116};
int numentries = sizeof(Entries) / sizeof(Entries[0]); int numentries = sizeof(Entries) / sizeof(Entries[0]);
int numentriesgroups = sizeof(EntriesGroups) / sizeof(EntriesGroups[0]); int numentriesgroups = sizeof(EntriesGroups) / sizeof(EntriesGroups[0]);
@ -535,88 +505,85 @@ void inputPassphrase(char *passphrase)
int passphrasecharindex = strlen(passphrase); int passphrasecharindex = strlen(passphrase);
int caret = 0; int caret = 0;
for (;;) for (;;) {
{
int entryindex = random32() % numentries; int entryindex = random32() % numentries;
if (passphrasecharindex >= LAST_PASSPHRASE_INDEX) if (passphrasecharindex >= LAST_PASSPHRASE_INDEX)
entryindex = findCharIndex(Entries, DONE, numentries, entryindex, entryindex < numentries / 2); entryindex = findCharIndex(Entries, DONE, numentries, entryindex,
entryindex = inputPassphraseScroll(passphrase, &passphrasecharindex, Entries, entryindex, numentries, 9, 9, EntriesGroups, numentriesgroups, 2, &caret); entryindex < numentries / 2);
if (entryindex == INPUT_DONE) entryindex = inputPassphraseScroll(
return; passphrase, &passphrasecharindex, Entries, entryindex, numentries, 9, 9,
EntriesGroups, numentriesgroups, 2, &caret);
if (entryindex == INPUT_DONE) return;
} }
} }
bool checkPassphrase(const char *passphrase, bool enable_edit, bool enable_done) bool checkPassphrase(const char *passphrase, bool enable_edit,
{ bool enable_done) {
layoutCheckPassphrase(passphrase, PASSPHRASE_WIDTH, enable_edit, enable_done); layoutCheckPassphrase(passphrase, PASSPHRASE_WIDTH, enable_edit, enable_done);
buttonUpdate(); buttonUpdate();
for(;;) for (;;) {
{
usbSleep(5); usbSleep(5);
buttonUpdate(); buttonUpdate();
if (enable_done && button.YesUp) if (enable_done && button.YesUp) return true;
return true; if (enable_edit && button.NoUp) return false;
if (enable_edit && button.NoUp)
return false;
} }
} }
bool protectPassphraseDevice(void) bool protectPassphraseDevice(void) {
{
static char CONFIDENTIAL passphrase[MAX_PASSPHRASE_LEN]; static char CONFIDENTIAL passphrase[MAX_PASSPHRASE_LEN];
memzero(passphrase, sizeof(passphrase)); memzero(passphrase, sizeof(passphrase));
buttonUpdate(); buttonUpdate();
layoutDialog(NULL, NULL, _("Next"), NULL, _("You are about to enter"), _("the passphrase."), _("Select how many times"), _("you'd like to do it."), NULL, NULL); layoutDialog(NULL, NULL, _("Next"), NULL, _("You are about to enter"),
_("the passphrase."), _("Select how many times"),
_("you'd like to do it."), NULL, NULL);
buttonWaitForYesUp(); buttonWaitForYesUp();
layoutSwipe(); layoutSwipe();
layoutDialog(NULL, _("Twice"), _("Once"), NULL, _("If you are creating a new"), _("wallet, it is advised"), _("that you select Twice."), NULL, NULL, NULL); layoutDialog(NULL, _("Twice"), _("Once"), NULL,
for(;;) _("If you are creating a new"), _("wallet, it is advised"),
{ _("that you select Twice."), NULL, NULL, NULL);
for (;;) {
usbSleep(5); usbSleep(5);
buttonUpdate(); buttonUpdate();
if (button.YesUp || button.NoUp) if (button.YesUp || button.NoUp) break;
break;
} }
layoutSwipe(); layoutSwipe();
bool twice = button.NoUp; bool twice = button.NoUp;
layoutDialog(NULL, NULL, _("Next"), NULL, _("Enter the passphrase"), _("on the next screen."), _("- Single button: scroll."), _("- Hold: auto-scroll."), _("- Both buttons: confirm."), NULL); layoutDialog(NULL, NULL, _("Next"), NULL, _("Enter the passphrase"),
_("on the next screen."), _("- Single button: scroll."),
_("- Hold: auto-scroll."), _("- Both buttons: confirm."), NULL);
buttonWaitForYesUp(); buttonWaitForYesUp();
layoutSwipe(); layoutSwipe();
for (;;) for (;;) {
{
inputPassphrase(passphrase); inputPassphrase(passphrase);
if (checkPassphrase(passphrase, true, true)) if (checkPassphrase(passphrase, true, true)) break;
break;
oledSwipeRight(); oledSwipeRight();
} }
if (twice) if (twice) {
{
static char CONFIDENTIAL passphrase2[MAX_PASSPHRASE_LEN]; static char CONFIDENTIAL passphrase2[MAX_PASSPHRASE_LEN];
memzero(passphrase2, sizeof(passphrase2)); memzero(passphrase2, sizeof(passphrase2));
layoutSwipe(); layoutSwipe();
layoutDialog(NULL, NULL, _("Next"), NULL, _("Re-enter the passphrase."), NULL, NULL, NULL, NULL, NULL); layoutDialog(NULL, NULL, _("Next"), NULL, _("Re-enter the passphrase."),
NULL, NULL, NULL, NULL, NULL);
buttonWaitForYesUp(); buttonWaitForYesUp();
layoutSwipe(); layoutSwipe();
for (;;) for (;;) {
{
inputPassphrase(passphrase2); inputPassphrase(passphrase2);
if (strcmp(passphrase, passphrase2) == 0) if (strcmp(passphrase, passphrase2) == 0) break;
break;
checkPassphrase(passphrase2, true, false); checkPassphrase(passphrase2, true, false);
oledSwipeRight(); oledSwipeRight();
@ -628,8 +595,7 @@ bool protectPassphraseDevice(void)
checkPassphrase(passphrase, false, true); checkPassphrase(passphrase, false, true);
for (int i = 0; i < MAX_PASSPHRASE_LEN && passphrase[i]; ++i) for (int i = 0; i < MAX_PASSPHRASE_LEN && passphrase[i]; ++i)
if (passphrase[i] == SPACE) if (passphrase[i] == SPACE) passphrase[i] = ' ';
passphrase[i] = ' ';
session_cachePassphrase(passphrase); session_cachePassphrase(passphrase);
memzero(passphrase, sizeof(passphrase)); memzero(passphrase, sizeof(passphrase));
@ -639,8 +605,7 @@ bool protectPassphraseDevice(void)
return true; return true;
} }
bool protectPassphrase(void) bool protectPassphrase(void) {
{
bool passphrase_protection = false; bool passphrase_protection = false;
config_getPassphraseProtection(&passphrase_protection); config_getPassphraseProtection(&passphrase_protection);
if (!passphrase_protection || session_isPassphraseCached()) { if (!passphrase_protection || session_isPassphraseCached()) {
@ -648,8 +613,7 @@ bool protectPassphrase(void)
} }
bool result; bool result;
if (!session_isUseOnDeviceTextInputCached()) if (!session_isUseOnDeviceTextInputCached()) requestOnDeviceTextInput();
requestOnDeviceTextInput();
if (session_isUseOnDeviceTextInput()) if (session_isUseOnDeviceTextInput())
result = protectPassphraseDevice(); result = protectPassphraseDevice();
else else

View File

@ -16,6 +16,5 @@ int fontCharWidth(uint8_t font, uint8_t c) {
} }
const uint8_t *fontCharData(uint8_t font, uint8_t c) { const uint8_t *fontCharData(uint8_t font, uint8_t c) {
return (c >= 0x80) ? (const uint8_t *)"" return (c >= 0x80) ? (const uint8_t *)"" : font_data[font % FONTS][c] + 1;
: font_data[font % FONTS][c] + 1;
} }

67
legacy/oled.c Executable file → Normal file
View File

@ -244,7 +244,8 @@ void oledSetBuffer(uint8_t *buf) {
memcpy(_oledbuffer, buf, sizeof(_oledbuffer)); memcpy(_oledbuffer, buf, sizeof(_oledbuffer));
} }
void oledDrawCharUpdateCaret(int x, int y, char c, uint8_t font, int zoom, bool update_caret) { void oledDrawCharUpdateCaret(int x, int y, char c, uint8_t font, int zoom,
bool update_caret) {
if (x >= OLED_WIDTH || y >= OLED_HEIGHT || y <= -FONT_HEIGHT) { if (x >= OLED_WIDTH || y >= OLED_HEIGHT || y <= -FONT_HEIGHT) {
return; return;
} }
@ -270,8 +271,7 @@ void oledDrawCharUpdateCaret(int x, int y, char c, uint8_t font, int zoom, bool
} }
} }
if (update_caret) if (update_caret) {
{
caret_x = x + (char_width + 1) * zoom; caret_x = x + (char_width + 1) * zoom;
caret_y = y; caret_y = y;
caret_zoom = zoom; caret_zoom = zoom;
@ -355,8 +355,8 @@ void oledDrawStringRight(int x, int y, const char *text, uint8_t font) {
oledDrawString(x, y, text, font); oledDrawString(x, y, text, font);
} }
void oledDrawPartialStringSize(int x, int y, const char* text, uint8_t font, int size, int num) void oledDrawPartialStringSize(int x, int y, const char *text, uint8_t font,
{ int size, int num) {
if (!text) return; if (!text) return;
int l = 0; int l = 0;
for (; *text && num; text++, num--) { for (; *text && num; text++, num--) {
@ -368,57 +368,47 @@ void oledDrawPartialStringSize(int x, int y, const char* text, uint8_t font, int
} }
} }
void oledDrawPartialString(int x, int y, const char* text, uint8_t font, int num) void oledDrawPartialString(int x, int y, const char *text, uint8_t font,
{ int num) {
oledDrawPartialStringSize(x, y, text, font, 1, num); oledDrawPartialStringSize(x, y, text, font, 1, num);
} }
void oledDrawStringCenterMultiline(int y, const char* text, uint8_t font, int maxwidth) void oledDrawStringCenterMultiline(int y, const char *text, uint8_t font,
{ int maxwidth) {
const int CenterX = OLED_WIDTH / 2; const int CenterX = OLED_WIDTH / 2;
const int Height = FONT_HEIGHT + 1; const int Height = FONT_HEIGHT + 1;
if (!text || !*text) if (!text || !*text) {
{
caret_x = CenterX; caret_x = CenterX;
caret_y = y - Height / 2; caret_y = y - Height / 2;
caret_zoom = 1; caret_zoom = 1;
return; return;
} }
if (maxwidth <= 0 || maxwidth > OLED_WIDTH) if (maxwidth <= 0 || maxwidth > OLED_WIDTH) maxwidth = OLED_WIDTH;
maxwidth = OLED_WIDTH;
const char* end = text + strlen(text); const char *end = text + strlen(text);
int lines = 0; int lines = 0;
int chars[8]; int chars[8];
const char* str; const char *str;
for (str = text; str < end;) for (str = text; str < end;) {
{
int lo = 1; int lo = 1;
int hi = strlen(str); int hi = strlen(str);
int len = lo; int len = lo;
for (;;) for (;;) {
{ if (lo > hi) break;
if (lo > hi)
break;
int mid = (lo + hi) / 2; int mid = (lo + hi) / 2;
int width = oledPartialStringWidth(str, font, mid); int width = oledPartialStringWidth(str, font, mid);
if (width < maxwidth) if (width < maxwidth) {
{
len = mid; len = mid;
lo = mid + 1; lo = mid + 1;
} } else if (width > maxwidth) {
else if (width > maxwidth)
{
if (mid == len + 1) if (mid == len + 1)
break; break;
else else
hi = mid - 1; hi = mid - 1;
} } else {
else
{
len = mid; len = mid;
break; break;
} }
@ -426,17 +416,16 @@ void oledDrawStringCenterMultiline(int y, const char* text, uint8_t font, int ma
str += len; str += len;
chars[lines] = len; chars[lines] = len;
lines++; lines++;
if (lines >= 8) if (lines >= 8) break;
break;
} }
y -= Height * lines / 2; y -= Height * lines / 2;
str = text; str = text;
for (int i = 0; i < lines; i++) for (int i = 0; i < lines; i++) {
{
int len = chars[i]; int len = chars[i];
oledDrawPartialString(CenterX - oledPartialStringWidth(str, font, len) / 2, y, str, font, len); oledDrawPartialString(CenterX - oledPartialStringWidth(str, font, len) / 2,
y, str, font, len);
str += len; str += len;
y += Height; y += Height;
} }
@ -484,8 +473,7 @@ void oledBox(int x1, int y1, int x2, int y2, bool set) {
} }
} }
void oledPartialHLine(int x1, int x2, int y) void oledPartialHLine(int x1, int x2, int y) {
{
if (y < 0 || y >= OLED_HEIGHT || x1 >= x2 || x1 >= OLED_WIDTH || x2 <= 0) { if (y < 0 || y >= OLED_HEIGHT || x1 >= x2 || x1 >= OLED_WIDTH || x2 <= 0) {
return; return;
} }
@ -494,8 +482,7 @@ void oledPartialHLine(int x1, int x2, int y)
} }
} }
void oledPartialVLine(int x, int y1, int y2) void oledPartialVLine(int x, int y1, int y2) {
{
if (x < 0 || x >= OLED_WIDTH || y1 >= y2 || y1 >= OLED_HEIGHT || y2 <= 0) { if (x < 0 || x >= OLED_WIDTH || y1 >= y2 || y1 >= OLED_HEIGHT || y2 <= 0) {
return; return;
} }
@ -504,9 +491,7 @@ void oledPartialVLine(int x, int y1, int y2)
} }
} }
void oledHLine(int y) { void oledHLine(int y) { oledPartialHLine(0, OLED_WIDTH, y); }
oledPartialHLine(0, OLED_WIDTH, y);
}
/* /*
* Draw a rectangle frame. * Draw a rectangle frame.

3
legacy/oled.h Executable file → Normal file
View File

@ -48,7 +48,8 @@ void oledDrawCaret(void);
int oledStringWidth(const char *text, uint8_t font); int oledStringWidth(const char *text, uint8_t font);
void oledDrawString(int x, int y, const char *text, uint8_t font); void oledDrawString(int x, int y, const char *text, uint8_t font);
void oledDrawStringCenter(int x, int y, const char *text, uint8_t font); void oledDrawStringCenter(int x, int y, const char *text, uint8_t font);
void oledDrawStringCenterMultiline(int y, const char* text, uint8_t font, int width); void oledDrawStringCenterMultiline(int y, const char *text, uint8_t font,
int width);
void oledDrawStringRight(int x, int y, const char *text, uint8_t font); void oledDrawStringRight(int x, int y, const char *text, uint8_t font);
void oledDrawBitmap(int x, int y, const BITMAP *bmp); void oledDrawBitmap(int x, int y, const BITMAP *bmp);
void oledInvert(int x1, int y1, int x2, int y2); void oledInvert(int x1, int y1, int x2, int y2);