1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-05 14:08:39 +00:00
trezor-firmware/legacy/firmware/config.h

179 lines
5.1 KiB
C
Raw Normal View History

2014-04-29 12:26:51 +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/>.
*/
2019-01-25 10:58:23 +00:00
#ifndef __CONFIG_H__
#define __CONFIG_H__
2014-04-29 12:26:51 +00:00
#include "bip32.h"
#include "messages-bitcoin.pb.h"
2019-10-17 11:25:47 +00:00
#include "messages-common.pb.h"
#include "messages-management.pb.h"
#include "messages.pb.h"
2014-04-29 12:26:51 +00:00
2017-12-18 21:16:05 +00:00
#define STORAGE_FIELD(TYPE, NAME) \
bool has_##NAME; \
TYPE NAME;
2017-12-18 21:16:05 +00:00
#define STORAGE_STRING(NAME, SIZE) \
bool has_##NAME; \
char NAME[SIZE];
2017-12-18 21:16:05 +00:00
#define STORAGE_BYTES(NAME, SIZE) \
bool has_##NAME; \
struct { \
uint32_t size; \
uint8_t bytes[SIZE]; \
} NAME;
2017-12-18 21:16:05 +00:00
#define STORAGE_BOOL(NAME) STORAGE_FIELD(bool, NAME)
#define STORAGE_NODE(NAME) STORAGE_FIELD(StorageHDNode, NAME)
#define STORAGE_UINT32(NAME) STORAGE_FIELD(uint32_t, NAME)
2017-12-18 21:16:05 +00:00
typedef struct {
uint32_t depth;
uint32_t fingerprint;
uint32_t child_num;
struct {
uint32_t size;
uint8_t bytes[32];
} chain_code;
STORAGE_BYTES(private_key, 32);
STORAGE_BYTES(public_key, 33);
2017-12-18 21:16:05 +00:00
} StorageHDNode;
typedef struct _Storage {
uint32_t version;
STORAGE_NODE(node)
STORAGE_STRING(mnemonic, 241)
STORAGE_BOOL(passphrase_protection)
STORAGE_UINT32(pin_failed_attempts)
STORAGE_STRING(pin, 10)
STORAGE_STRING(language, 17)
STORAGE_STRING(label, 33)
STORAGE_BOOL(imported)
STORAGE_BYTES(homescreen, 1024)
STORAGE_UINT32(u2f_counter)
STORAGE_BOOL(needs_backup)
STORAGE_UINT32(flags)
STORAGE_NODE(u2froot)
STORAGE_BOOL(unfinished_backup)
STORAGE_UINT32(auto_lock_delay_ms)
STORAGE_BOOL(no_backup)
2017-12-18 21:16:05 +00:00
} Storage;
2019-01-25 10:58:23 +00:00
extern Storage configUpdate;
#define MAX_PIN_LEN 50
#define MAX_LABEL_LEN 32
#define MAX_LANGUAGE_LEN 16
#define MAX_MNEMONIC_LEN 240
#define HOMESCREEN_SIZE 1024
#define UUID_SIZE 12
#if DEBUG_LINK
#define MIN_AUTOLOCK_DELAY_MS (10 * 1000U) // 10 seconds
#else
#define MIN_AUTOLOCK_DELAY_MS (60 * 1000U) // 1 minute
#endif
#define MAX_AUTOLOCK_DELAY_MS 0x20000000U // ~6 days
2014-04-29 12:26:51 +00:00
2019-01-25 10:58:23 +00:00
void config_init(void);
void session_clear(bool lock);
2020-08-25 14:04:36 +00:00
void session_endCurrentSession(void);
void config_lockDevice(void);
2014-04-29 12:26:51 +00:00
2019-01-25 10:58:23 +00:00
void config_loadDevice(const LoadDevice *msg);
2020-01-20 14:00:07 +00:00
const uint8_t *config_getSeed(void);
2014-04-29 12:26:51 +00:00
bool config_setCoinJoinAuthorization(const AuthorizeCoinJoin *authorization);
MessageType config_getAuthorizationType(void);
const AuthorizeCoinJoin *config_getCoinJoinAuthorization(void);
2019-01-25 10:58:23 +00:00
bool config_getU2FRoot(HDNode *node);
2020-01-20 14:00:07 +00:00
bool config_getRootNode(HDNode *node, const char *curve);
2014-04-29 12:26:51 +00:00
2019-01-25 10:58:23 +00:00
bool config_getLabel(char *dest, uint16_t dest_size);
void config_setLabel(const char *label);
2014-04-29 12:26:51 +00:00
2019-01-25 10:58:23 +00:00
bool config_getLanguage(char *dest, uint16_t dest_size);
void config_setLanguage(const char *lang);
2019-01-25 10:58:23 +00:00
void config_setPassphraseProtection(bool passphrase_protection);
bool config_getPassphraseProtection(bool *passphrase_protection);
2019-01-25 10:58:23 +00:00
bool config_getHomescreen(uint8_t *dest, uint16_t dest_size);
void config_setHomescreen(const uint8_t *data, uint32_t size);
2015-02-04 20:27:07 +00:00
uint8_t *session_startSession(const uint8_t *received_session_id);
2014-04-29 12:26:51 +00:00
bool config_setMnemonic(const char *mnemonic);
2019-01-25 10:58:23 +00:00
bool config_containsMnemonic(const char *mnemonic);
bool config_hasMnemonic(void);
2019-01-25 10:58:23 +00:00
bool config_getMnemonic(char *dest, uint16_t dest_size);
bool config_getMnemonicBytes(uint8_t *dest, uint16_t dest_size,
uint16_t *real_size);
2017-12-18 21:16:05 +00:00
#if DEBUG_LINK
bool config_dumpNode(HDNodeType *node);
bool config_getPin(char *dest, uint16_t dest_size);
2017-12-18 21:16:05 +00:00
#endif
bool config_unlock(const char *pin);
2019-01-25 10:58:23 +00:00
bool config_hasPin(void);
bool config_changePin(const char *old_pin, const char *new_pin);
bool session_isUnlocked(void);
2014-04-29 12:26:51 +00:00
bool config_hasWipeCode(void);
bool config_changeWipeCode(const char *pin, const char *wipe_code);
2019-01-25 10:58:23 +00:00
uint32_t config_nextU2FCounter(void);
void config_setU2FCounter(uint32_t u2fcounter);
2015-11-02 23:08:18 +00:00
2019-01-25 10:58:23 +00:00
bool config_isInitialized(void);
2014-04-29 12:26:51 +00:00
bool config_getImported(bool *imported);
2019-01-25 10:58:23 +00:00
void config_setImported(bool imported);
bool config_getNeedsBackup(bool *needs_backup);
2019-01-25 10:58:23 +00:00
void config_setNeedsBackup(bool needs_backup);
bool config_getUnfinishedBackup(bool *unfinished_backup);
2019-01-25 10:58:23 +00:00
void config_setUnfinishedBackup(bool unfinished_backup);
bool config_getNoBackup(bool *no_backup);
2019-01-25 10:58:23 +00:00
void config_setNoBackup(void);
2019-01-25 10:58:23 +00:00
void config_applyFlags(uint32_t flags);
bool config_getFlags(uint32_t *flags);
2019-01-25 10:58:23 +00:00
uint32_t config_getAutoLockDelayMs(void);
void config_setAutoLockDelayMs(uint32_t auto_lock_delay_ms);
SafetyCheckLevel config_getSafetyCheckLevel(void);
void config_setSafetyCheckLevel(SafetyCheckLevel safety_check_level);
2019-01-25 10:58:23 +00:00
void config_wipe(void);
extern char config_uuid_str[2 * UUID_SIZE + 1];
2014-04-29 12:26:51 +00:00
#endif