int main(void) { _buttonusr_isr = (void *)&buttonisr_usr; _timerusr_isr = (void *)&timerisr_usr; _mmhusr_isr = (void *)&mmhisr; /* Drop privileges */ drop_privs(); /* Init board */ kk_board_init(); /* Program the model into OTP, if we're not in screen-test mode, and it's * not already there */ (void)flash_programModel(); /* Init for safeguard against stack overflow (-fstack-protector-all) */ __stack_chk_guard = (uintptr_t)random32(); /* Bootloader Verification */ check_bootloader(); led_func(SET_RED_LED); dbg_print("Application Version %d.%d.%d\n\r", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION); /* Init storage */ storage_init(); /* Init protcol buffer message map and usb msg callback */ fsm_init(); led_func(SET_GREEN_LED); usbInit(); u2fInit(); led_func(CLR_RED_LED); reset_idle_time(); if (is_mfg_mode()) layout_screen_test(); else if (!storage_isInitialized()) layout_standard_notification("Welcome", "keepkey.com/get-started", NOTIFICATION_LOGO); else layoutHomeForced(); while (1) { delay_ms_with_callback(ONE_SEC, &exec, 1); increment_idle_time(ONE_SEC); toggle_screensaver(); } return 0; }
void next_word(void) { word_pos = word_order[word_index]; char title_formatted[SMALL_STR_BUF]; char body_formatted[MEDIUM_STR_BUF]; /* Form title */ /* snprintf: 24 + 10 (%u) + 1 (NULL) = 35 */ snprintf(title_formatted, SMALL_STR_BUF, "Device Recovery Step %lu/24", (unsigned long)(word_index + 1)); if (word_pos == 0) { const char * const *wl = mnemonic_wordlist(); strlcpy(fake_word, wl[random_uniform(2048)], sizeof(fake_word)); /* Format body for fake word */ /* snprintf: 18 + 12 (fake_word) + 1 (NULL) = 31 */ snprintf(body_formatted, MEDIUM_STR_BUF, "Enter the word \"%s\".", fake_word); layout_standard_notification(title_formatted, body_formatted, NOTIFICATION_RECOVERY); } else { fake_word[0] = 0; char desc[] = "th word"; if (word_pos == 1 || word_pos == 21) { desc[0] = 's'; desc[1] = 't'; } else if (word_pos == 2 || word_pos == 22) { desc[0] = 'n'; desc[1] = 'd'; } else if (word_pos == 3 || word_pos == 23) { desc[0] = 'r'; desc[1] = 'd'; } /* Format body for real word */ /* snprintf: 37 + 10 (%u) + 8 (desc) + 1 (NULL) = 56 */ snprintf(body_formatted, MEDIUM_STR_BUF, "Enter the %lu%s of your recovery sentence.", (unsigned long)word_pos, desc); layout_standard_notification(title_formatted, body_formatted, NOTIFICATION_RECOVERY); } WordRequest resp; memset(&resp, 0, sizeof(WordRequest)); msg_write(MessageType_MessageType_WordRequest, &resp); }
/* * update_fw() - Firmware update mode * * INPUT * none * OUTPUT * none * */ static void update_fw(void) { led_func(CLR_GREEN_LED); if(usb_flash_firmware()) { layout_standard_notification("Firmware Update Complete", "Please disconnect and reconnect.", NOTIFICATION_UNPLUG); display_refresh(); } else { layout_simple_message("Firmware Update Failure, Try Again"); } }