2014-04-29 12:26:51 +00:00
|
|
|
/*
|
2017-11-05 16:46:34 +00:00
|
|
|
* This file is part of the TREZOR project, https://trezor.io/
|
2014-04-29 12:26:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "trezor.h"
|
|
|
|
#include "oled.h"
|
|
|
|
#include "bitmaps.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "usb.h"
|
|
|
|
#include "setup.h"
|
|
|
|
#include "storage.h"
|
2014-07-30 18:34:28 +00:00
|
|
|
#include "layout.h"
|
2014-04-29 12:26:51 +00:00
|
|
|
#include "layout2.h"
|
2014-07-30 18:34:28 +00:00
|
|
|
#include "rng.h"
|
2016-11-17 19:07:41 +00:00
|
|
|
#include "timer.h"
|
2016-08-26 16:50:10 +00:00
|
|
|
#include "buttons.h"
|
2017-07-31 00:31:30 +00:00
|
|
|
#include "gettext.h"
|
2017-06-10 18:42:10 +00:00
|
|
|
#include "fastflash.h"
|
2014-07-30 18:34:28 +00:00
|
|
|
|
2017-12-13 18:38:51 +00:00
|
|
|
/* Screen timeout */
|
|
|
|
uint32_t system_millis_lock_start;
|
|
|
|
|
2016-08-26 16:50:10 +00:00
|
|
|
void check_lock_screen(void)
|
|
|
|
{
|
|
|
|
buttonUpdate();
|
|
|
|
|
|
|
|
// wake from screensaver on any button
|
|
|
|
if (layoutLast == layoutScreensaver && (button.NoUp || button.YesUp)) {
|
|
|
|
layoutHome();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-25 15:45:30 +00:00
|
|
|
// button held for long enough (2 seconds)
|
|
|
|
if (layoutLast == layoutHome && button.NoDown >= 285000 * 2) {
|
2016-08-26 16:50:10 +00:00
|
|
|
|
2017-07-31 00:31:30 +00:00
|
|
|
layoutDialog(&bmp_icon_question, _("Cancel"), _("Lock Device"), NULL, _("Do you really want to"), _("lock your TREZOR?"), NULL, NULL, NULL, NULL);
|
2016-08-26 16:50:10 +00:00
|
|
|
|
|
|
|
// wait until NoButton is released
|
|
|
|
usbTiny(1);
|
|
|
|
do {
|
2016-11-17 19:07:41 +00:00
|
|
|
usbSleep(5);
|
2016-08-26 16:50:10 +00:00
|
|
|
buttonUpdate();
|
|
|
|
} while (!button.NoUp);
|
|
|
|
|
|
|
|
// wait for confirmation/cancellation of the dialog
|
|
|
|
do {
|
2016-11-17 19:07:41 +00:00
|
|
|
usbSleep(5);
|
2016-08-26 16:50:10 +00:00
|
|
|
buttonUpdate();
|
|
|
|
} while (!button.YesUp && !button.NoUp);
|
|
|
|
usbTiny(0);
|
|
|
|
|
|
|
|
if (button.YesUp) {
|
|
|
|
// lock the screen
|
|
|
|
session_clear(true);
|
|
|
|
layoutScreensaver();
|
|
|
|
} else {
|
|
|
|
// resume homescreen
|
|
|
|
layoutHome();
|
|
|
|
}
|
|
|
|
}
|
2016-10-25 15:45:30 +00:00
|
|
|
|
|
|
|
// if homescreen is shown for longer than 10 minutes, lock too
|
|
|
|
if (layoutLast == layoutHome) {
|
2017-12-13 18:38:51 +00:00
|
|
|
if ((timer_ms() - system_millis_lock_start) >= 600000) {
|
2016-10-25 15:45:30 +00:00
|
|
|
// lock the screen
|
|
|
|
session_clear(true);
|
|
|
|
layoutScreensaver();
|
|
|
|
}
|
|
|
|
}
|
2016-08-26 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
2014-07-07 13:03:34 +00:00
|
|
|
#ifndef APPVER
|
2014-04-29 12:26:51 +00:00
|
|
|
setup();
|
2017-02-17 12:18:50 +00:00
|
|
|
__stack_chk_guard = random32(); // this supports compiler provided unpredictable stack protection checks
|
2014-04-29 12:26:51 +00:00
|
|
|
oledInit();
|
2014-07-07 13:03:34 +00:00
|
|
|
#else
|
|
|
|
setupApp();
|
2017-02-17 12:18:50 +00:00
|
|
|
__stack_chk_guard = random32(); // this supports compiler provided unpredictable stack protection checks
|
2014-07-07 13:03:34 +00:00
|
|
|
#endif
|
2016-11-17 19:07:41 +00:00
|
|
|
|
2017-06-10 18:42:10 +00:00
|
|
|
#if FASTFLASH
|
|
|
|
uint16_t state = gpio_port_read(BTN_PORT);
|
|
|
|
if ((state & BTN_PIN_NO) == 0) {
|
|
|
|
run_bootloader();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-11 22:10:12 +00:00
|
|
|
#ifdef APPVER
|
|
|
|
// enable MPU (Memory Protection Unit)
|
|
|
|
mpu_config();
|
|
|
|
#endif
|
|
|
|
|
2016-11-17 19:07:41 +00:00
|
|
|
timer_init();
|
|
|
|
|
2016-12-04 22:24:01 +00:00
|
|
|
#if DEBUG_LINK
|
2017-01-19 15:16:57 +00:00
|
|
|
oledSetDebugLink(1);
|
2017-08-22 17:00:25 +00:00
|
|
|
storage_wipe();
|
2014-04-29 12:26:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
oledDrawBitmap(40, 0, &bmp_logo64);
|
|
|
|
oledRefresh();
|
|
|
|
|
|
|
|
storage_init();
|
|
|
|
layoutHome();
|
|
|
|
usbInit();
|
|
|
|
for (;;) {
|
|
|
|
usbPoll();
|
2016-08-26 16:50:10 +00:00
|
|
|
check_lock_screen();
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|