Esempio n. 1
0
__fatal_error(const char *expr, const char *msg, const char *file, int line_num,
              const char *func) {
  const BITMAP *icon = &bmp_icon_error;
  char line[128] = {0};
  int y = icon->height + 3;
  oledClear();

  oledDrawBitmap(0, 0, icon);
  oledDrawStringCenter(OLED_WIDTH / 2, (icon->height - FONT_HEIGHT) / 2 + 1,
                       "FATAL  ERROR", FONT_STANDARD);

  snprintf(line, sizeof(line), "Expr: %s", expr ? expr : "(null)");
  oledDrawString(0, y, line, FONT_STANDARD);
  y += FONT_HEIGHT + 1;

  snprintf(line, sizeof(line), "Msg: %s", msg ? msg : "(null)");
  oledDrawString(0, y, line, FONT_STANDARD);
  y += FONT_HEIGHT + 1;

  const char *label = "File: ";
  snprintf(line, sizeof(line), "%s:%d", file ? file : "(null)", line_num);
  oledDrawStringRight(OLED_WIDTH - 1, y, line, FONT_STANDARD);
  oledBox(0, y, oledStringWidth(label, FONT_STANDARD), y + FONT_HEIGHT, false);
  oledDrawString(0, y, label, FONT_STANDARD);
  y += FONT_HEIGHT + 1;

  snprintf(line, sizeof(line), "Func: %s", func ? func : "(null)");
  oledDrawString(0, y, line, FONT_STANDARD);
  y += FONT_HEIGHT + 1;

  oledDrawString(0, y, "Contact TREZOR support.", FONT_STANDARD);
  oledRefresh();

  shutdown();
}
Esempio n. 2
0
void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6)
{
	int left = 0;
	oledClear();
	if (icon) {
		oledDrawBitmap(0, 0, icon);
		left = icon->width + 4;
	}
	if (line1) oledDrawString(left, 0 * 9, line1, FONT_STANDARD);
	if (line2) oledDrawString(left, 1 * 9, line2, FONT_STANDARD);
	if (line3) oledDrawString(left, 2 * 9, line3, FONT_STANDARD);
	if (line4) oledDrawString(left, 3 * 9, line4, FONT_STANDARD);
	if (desc) {
		oledDrawStringCenter(OLED_HEIGHT - 2 * 9 - 1, desc, FONT_STANDARD);
		if (btnYes || btnNo) {
			oledHLine(OLED_HEIGHT - 21);
		}
	} else {
		if (line5) oledDrawString(left, 4 * 9, line5, FONT_STANDARD);
		if (line6) oledDrawString(left, 5 * 9, line6, FONT_STANDARD);
		if (btnYes || btnNo) {
			oledHLine(OLED_HEIGHT - 13);
		}
	}
	if (btnNo) {
		layoutButtonNo(btnNo);
	}
	if (btnYes) {
		layoutButtonYes(btnYes);
	}
	oledRefresh();
}
Esempio n. 3
0
int main(void)
{
	__stack_chk_guard = random32();
	setup();
	memory_protect();
	oledInit();

	// at least one button is unpressed
	uint16_t state = gpio_port_read(BTN_PORT);
	if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) {

		check_firmware_sanity();

		oledClear();
		oledDrawBitmap(40, 0, &bmp_logo64_empty);
		oledRefresh();

		uint8_t hash[32];
		if (!signatures_ok(hash)) {
			show_unofficial_warning(hash);
		}

		load_app();

	}

	bootloader_loop();

	return 0;
}
Esempio n. 4
0
void layoutHome(void)
{
	if (layoutLast == layoutHome || layoutLast == layoutScreensaver) {
		oledClear();
	} else {
		layoutSwipe();
	}
	layoutLast = layoutHome;
	const char *label = storage_isInitialized() ? storage_getLabel() : _("Go to trezor.io/start");
	const uint8_t *homescreen = storage_getHomescreen();
	if (homescreen) {
		BITMAP b;
		b.width = 128;
		b.height = 64;
		b.data = homescreen;
		oledDrawBitmap(0, 0, &b);
	} else {
		if (label && strlen(label) > 0) {
			oledDrawBitmap(44, 4, &bmp_logo48);
			oledDrawStringCenter(OLED_HEIGHT - 8, label, FONT_STANDARD);
		} else {
			oledDrawBitmap(40, 0, &bmp_logo64);
		}
	}
	if (storage_noBackup()) {
		oledBox(0, 0, 127, 8, false);
		oledDrawStringCenter(0, "SEEDLESS", FONT_STANDARD);
	} else
	if (storage_unfinishedBackup()) {
		oledBox(0, 0, 127, 8, false);
		oledDrawStringCenter(0, "BACKUP FAILED!", FONT_STANDARD);
	} else
	if (storage_needsBackup()) {
		oledBox(0, 0, 127, 8, false);
		oledDrawStringCenter(0, "NEEDS BACKUP!", FONT_STANDARD);
	}
	oledRefresh();

	// Reset lock screen timeout
	system_millis_lock_start = timer_ms();
}
Esempio n. 5
0
void layoutResetWord(const char *word, int pass, int word_pos, bool last)
{
	layoutLast = layoutResetWord;
	layoutSwipe();

	const char *btnYes;
	if (last) {
		if (pass == 1) {
			btnYes = _("Finish");
		} else {
			btnYes = _("Again");
		}
	} else {
		btnYes = _("Next");
	}

	const char *action;
	if (pass == 1) {
		action = _("Please check the seed");
	} else {
		action = _("Write down the seed");
	}

	char index_str[] = "##th word is:";
	if (word_pos < 10) {
		index_str[0] = ' ';
	} else {
		index_str[0] = '0' + word_pos / 10;
	}
	index_str[1] = '0' + word_pos % 10;
	if (word_pos == 1 || word_pos == 21) {
		index_str[2] = 's'; index_str[3] = 't';
	} else
	if (word_pos == 2 || word_pos == 22) {
		index_str[2] = 'n'; index_str[3] = 'd';
	} else
	if (word_pos == 3 || word_pos == 23) {
		index_str[2] = 'r'; index_str[3] = 'd';
	}

	int left = 0;
	oledClear();
	oledDrawBitmap(0, 0, &bmp_icon_info);
	left = bmp_icon_info.width + 4;

	oledDrawString(left, 0 * 9, action, FONT_STANDARD);
	oledDrawString(left, 2 * 9, word_pos < 10 ? index_str + 1 : index_str, FONT_STANDARD);
	oledDrawString(left, 3 * 9, word, FONT_STANDARD | FONT_DOUBLE);
	oledHLine(OLED_HEIGHT - 13);
	layoutButtonYes(btnYes);
	oledRefresh();
}
Esempio n. 6
0
void layoutProgressUpdate(bool refresh)
{
	static uint8_t step = 0;
	switch (step) {
		case 0:
			oledDrawBitmap(40, 0, &bmp_gears0);
			break;
		case 1:
			oledDrawBitmap(40, 0, &bmp_gears1);
			break;
		case 2:
			oledDrawBitmap(40, 0, &bmp_gears2);
			break;
		case 3:
			oledDrawBitmap(40, 0, &bmp_gears3);
			break;
	}
	step = (step + 1) % 4;
	if (refresh) {
		oledRefresh();
	}
}
Esempio n. 7
0
static void render_address_dialog(const CoinInfo *coin, const char *address, const char *line1, const char *line2, const char *extra_line)
{
	if (coin && coin->cashaddr_prefix) {
		/* If this is a cashaddr address, remove the prefix from the
		 * string presented to the user
		 */
		int prefix_len = strlen(coin->cashaddr_prefix);
		if (strncmp(address, coin->cashaddr_prefix, prefix_len) == 0
			&& address[prefix_len] == ':') {
			address += prefix_len + 1;
		}
	}
	int addrlen = strlen(address);
	int numlines = addrlen <= 42 ? 2 : 3;
	int linelen = (addrlen - 1) / numlines + 1;
	if (linelen > 21) {
		linelen = 21;
	}
	const char **str = split_message((const uint8_t *)address, addrlen, linelen);
	layoutLast = layoutDialogSwipe;
	layoutSwipe();
	oledClear();
	oledDrawBitmap(0, 0, &bmp_icon_question);
	oledDrawString(20, 0 * 9, line1, FONT_STANDARD);
	oledDrawString(20, 1 * 9, line2, FONT_STANDARD);
	int left = linelen > 18 ? 0 : 20;
	oledDrawString(left, 2 * 9, str[0], FONT_FIXED);
	oledDrawString(left, 3 * 9, str[1], FONT_FIXED);
	oledDrawString(left, 4 * 9, str[2], FONT_FIXED);
	oledDrawString(left, 5 * 9, str[3], FONT_FIXED);
	if (!str[3][0]) {
		if (extra_line) {
			oledDrawString(0, 5 * 9, extra_line, FONT_STANDARD);
		} else {
			oledHLine(OLED_HEIGHT - 13);
		}
	}
	layoutButtonNo(_("Cancel"));
	layoutButtonYes(_("Confirm"));
	oledRefresh();
}
Esempio n. 8
0
void pinmatrix_draw(const char *text)
{
	const BITMAP *bmp_digits[10] = {
		&bmp_digit0, &bmp_digit1, &bmp_digit2, &bmp_digit3, &bmp_digit4,
		&bmp_digit5, &bmp_digit6, &bmp_digit7, &bmp_digit8, &bmp_digit9,
	};
	oledSwipeLeft();
	const int w = bmp_digit0.width, h = bmp_digit0.height, pad = 2;
	int i, j, k;
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			// use (2 - j) instead of j to achieve 789456123 layout
			k = pinmatrix_perm[i + (2 - j) * 3] - '0';
			if (text) {
				oledDrawStringCenter(0, text);
			}
			oledDrawBitmap((OLED_WIDTH - 3 * w - 2 * pad) / 2 + i * (w + pad), OLED_HEIGHT - 3 * h - 2 * pad + j * (h + pad), bmp_digits[k]);
		}
	}
	oledRefresh();
}
Esempio n. 9
0
void bootloader_loop(void)
{
	static char serial[25];

	fill_serialno_fixed(serial);

	oledDrawBitmap(0, 0, &bmp_logo64);
	oledDrawString(52, 0, "TREZOR");

	oledDrawString(52, 20, "Serial No.");
	oledDrawString(52, 40, serial + 12); // second part of serial
	serial[12] = 0;
	oledDrawString(52, 30, serial);      // first part of serial

	oledDrawStringRight(OLED_WIDTH - 1, OLED_HEIGHT - 8, "BLv" VERSTR(VERSION_MAJOR) "." VERSTR(VERSION_MINOR) "." VERSTR(VERSION_PATCH));

	oledRefresh();

	usbInit();
	usbLoop();
}
Esempio n. 10
0
void bootloader_loop(void)
{
	oledClear();
	oledDrawBitmap(0, 0, &bmp_logo64);
	if (firmware_present()) {
		oledDrawString(52, 0, "TREZOR", FONT_STANDARD);
		static char serial[25];
		fill_serialno_fixed(serial);
		oledDrawString(52, 20, "Serial No.", FONT_STANDARD);
		oledDrawString(52, 40, serial + 12, FONT_STANDARD); // second part of serial
		serial[12] = 0;
		oledDrawString(52, 30, serial, FONT_STANDARD);      // first part of serial
		oledDrawStringRight(OLED_WIDTH - 1, OLED_HEIGHT - 8, "Loader " VERSTR(VERSION_MAJOR) "." VERSTR(VERSION_MINOR) "." VERSTR(VERSION_PATCH), FONT_STANDARD);
	} else {
		oledDrawString(52, 10, "Welcome!", FONT_STANDARD);
		oledDrawString(52, 30, "Please visit", FONT_STANDARD);
		oledDrawString(52, 50, "trezor.io/start", FONT_STANDARD);
	}
	oledRefresh();

	usbLoop(firmware_present());
}
Esempio n. 11
0
int main(void)
{
#ifndef APPVER
	setup();
#endif
	__stack_chk_guard = random32(); // this supports compiler provided unpredictable stack protection checks
#ifndef APPVER
	memory_protect();
	oledInit();
#endif

#ifndef APPVER
	// at least one button is unpressed
	uint16_t state = gpio_port_read(BTN_PORT);
	int unpressed = ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO);

	if (firmware_present() && unpressed) {

		oledClear();
		oledDrawBitmap(40, 0, &bmp_logo64_empty);
		oledRefresh();

		uint8_t hash[32];
		int signed_firmware = signatures_ok(hash);
		if (SIG_OK != signed_firmware) {
			show_unofficial_warning(hash);
			timer_init();
		}

		load_app(signed_firmware);
	}
#endif

	bootloader_loop();

	return 0;
}
Esempio n. 12
0
void layoutDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6)
{
	int left = 0;
	oledClear();
	if (icon) {
		oledDrawBitmap(0, 0, icon);
		left = icon->width + 4;
	}
	if (line1) oledDrawString(left, 0 * 9, line1);
	if (line2) oledDrawString(left, 1 * 9, line2);
	if (line3) oledDrawString(left, 2 * 9, line3);
	if (line4) oledDrawString(left, 3 * 9, line4);
	if (desc) {
		oledDrawStringCenter(OLED_HEIGHT - 2 * 9 - 1, desc);
		if (btnYes || btnNo) {
			oledHLine(OLED_HEIGHT - 21);
		}
	} else {
		if (line5) oledDrawString(left, 4 * 9, line5);
		if (line6) oledDrawString(left, 5 * 9, line6);
		if (btnYes || btnNo) {
			oledHLine(OLED_HEIGHT - 13);
		}
	}
	if (btnNo) {
		oledDrawString(1, OLED_HEIGHT - 8, "\x15");
		oledDrawString(fontCharWidth('\x15') + 3, OLED_HEIGHT - 8, btnNo);
		oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\x15') + oledStringWidth(btnNo) + 2, OLED_HEIGHT - 1);
	}
	if (btnYes) {
		oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06");
		oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes);
		oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
	}
	oledRefresh();
}