1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

implement Storage.flags and related stuff

This commit is contained in:
Pavol Rusnak 2017-07-17 18:36:09 +02:00
parent 1a72a49ee5
commit cf04279774
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
10 changed files with 65 additions and 12 deletions

View File

@ -235,6 +235,7 @@ void fsm_msgGetFeatures(GetFeatures *msg)
resp->has_pin_cached = true; resp->pin_cached = session_isPinCached();
resp->has_passphrase_cached = true; resp->passphrase_cached = session_isPassphraseCached();
resp->has_needs_backup = true; resp->needs_backup = storage_needsBackup();
resp->has_flags = true; resp->flags = storage_getFlags();
msg_write(MessageType_MessageType_Features, resp);
}
@ -618,6 +619,14 @@ void fsm_msgApplySettings(ApplySettings *msg)
layoutHome();
}
void fsm_msgApplyFlags(ApplyFlags *msg)
{
if (msg->has_flags) {
storage_applyFlags(msg->flags);
}
fsm_sendSuccess(_("Flags applied"));
}
void fsm_msgGetAddress(GetAddress *msg)
{
RESP_INIT(Address);

View File

@ -44,6 +44,7 @@ void fsm_msgTxAck(TxAck *msg);
void fsm_msgCipherKeyValue(CipherKeyValue *msg);
void fsm_msgClearSession(ClearSession *msg);
void fsm_msgApplySettings(ApplySettings *msg);
void fsm_msgApplyFlags(ApplyFlags *msg);
//void fsm_msgButtonAck(ButtonAck *msg);
void fsm_msgGetAddress(GetAddress *msg);
void fsm_msgEntropyAck(EntropyAck *msg);

View File

@ -25,7 +25,7 @@ const pb_field_t GetFeatures_fields[1] = {
PB_LAST_FIELD
};
const pb_field_t Features_fields[20] = {
const pb_field_t Features_fields[21] = {
PB_FIELD2( 1, STRING , OPTIONAL, STATIC , FIRST, Features, vendor, vendor, 0),
PB_FIELD2( 2, UINT32 , OPTIONAL, STATIC , OTHER, Features, major_version, vendor, 0),
PB_FIELD2( 3, UINT32 , OPTIONAL, STATIC , OTHER, Features, minor_version, major_version, 0),
@ -45,6 +45,7 @@ const pb_field_t Features_fields[20] = {
PB_FIELD2( 17, BOOL , OPTIONAL, STATIC , OTHER, Features, passphrase_cached, pin_cached, 0),
PB_FIELD2( 18, BOOL , OPTIONAL, STATIC , OTHER, Features, firmware_present, passphrase_cached, 0),
PB_FIELD2( 19, BOOL , OPTIONAL, STATIC , OTHER, Features, needs_backup, firmware_present, 0),
PB_FIELD2( 20, UINT32 , OPTIONAL, STATIC , OTHER, Features, flags, needs_backup, 0),
PB_LAST_FIELD
};
@ -60,6 +61,11 @@ const pb_field_t ApplySettings_fields[5] = {
PB_LAST_FIELD
};
const pb_field_t ApplyFlags_fields[2] = {
PB_FIELD2( 1, UINT32 , OPTIONAL, STATIC , FIRST, ApplyFlags, flags, flags, 0),
PB_LAST_FIELD
};
const pb_field_t ChangePin_fields[2] = {
PB_FIELD2( 1, BOOL , OPTIONAL, STATIC , FIRST, ChangePin, remove, remove, 0),
PB_LAST_FIELD
@ -432,7 +438,7 @@ const pb_field_t DebugLinkFlashErase_fields[2] = {
* numbers or field sizes that are larger than what can fit in 8 or 16 bit
* field descriptors.
*/
STATIC_ASSERT((pb_membersize(Features, coins[0]) < 65536 && pb_membersize(PublicKey, node) < 65536 && pb_membersize(GetAddress, multisig) < 65536 && pb_membersize(LoadDevice, node) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, identity) < 65536 && pb_membersize(GetECDHSessionKey, identity) < 65536 && pb_membersize(DebugLinkState, node) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Initialize_GetFeatures_Features_ClearSession_ApplySettings_ChangePin_Ping_Success_Failure_ButtonRequest_ButtonAck_PinMatrixRequest_PinMatrixAck_Cancel_PassphraseRequest_PassphraseAck_GetEntropy_Entropy_GetPublicKey_PublicKey_GetAddress_EthereumGetAddress_Address_EthereumAddress_WipeDevice_LoadDevice_ResetDevice_BackupDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_CipherKeyValue_CipheredKeyValue_SignTx_TxRequest_TxAck_EthereumSignTx_EthereumTxRequest_EthereumTxAck_EthereumSignMessage_EthereumVerifyMessage_EthereumMessageSignature_SignIdentity_SignedIdentity_GetECDHSessionKey_ECDHSessionKey_SetU2FCounter_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog_DebugLinkMemoryRead_DebugLinkMemory_DebugLinkMemoryWrite_DebugLinkFlashErase)
STATIC_ASSERT((pb_membersize(Features, coins[0]) < 65536 && pb_membersize(PublicKey, node) < 65536 && pb_membersize(GetAddress, multisig) < 65536 && pb_membersize(LoadDevice, node) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, identity) < 65536 && pb_membersize(GetECDHSessionKey, identity) < 65536 && pb_membersize(DebugLinkState, node) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Initialize_GetFeatures_Features_ClearSession_ApplySettings_ApplyFlags_ChangePin_Ping_Success_Failure_ButtonRequest_ButtonAck_PinMatrixRequest_PinMatrixAck_Cancel_PassphraseRequest_PassphraseAck_GetEntropy_Entropy_GetPublicKey_PublicKey_GetAddress_EthereumGetAddress_Address_EthereumAddress_WipeDevice_LoadDevice_ResetDevice_BackupDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_CipherKeyValue_CipheredKeyValue_SignTx_TxRequest_TxAck_EthereumSignTx_EthereumTxRequest_EthereumTxAck_EthereumSignMessage_EthereumVerifyMessage_EthereumMessageSignature_SignIdentity_SignedIdentity_GetECDHSessionKey_ECDHSessionKey_SetU2FCounter_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog_DebugLinkMemoryRead_DebugLinkMemory_DebugLinkMemoryWrite_DebugLinkFlashErase)
#endif
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)

View File

@ -40,6 +40,7 @@ typedef enum _MessageType {
MessageType_MessageType_ApplySettings = 25,
MessageType_MessageType_ButtonRequest = 26,
MessageType_MessageType_ButtonAck = 27,
MessageType_MessageType_ApplyFlags = 28,
MessageType_MessageType_GetAddress = 29,
MessageType_MessageType_Address = 30,
MessageType_MessageType_SelfTest = 32,
@ -135,6 +136,11 @@ typedef struct _Address {
char address[60];
} Address;
typedef struct _ApplyFlags {
bool has_flags;
uint32_t flags;
} ApplyFlags;
typedef struct {
size_t size;
uint8_t bytes[1024];
@ -517,6 +523,8 @@ typedef struct _Features {
bool firmware_present;
bool has_needs_backup;
bool needs_backup;
bool has_flags;
uint32_t flags;
} Features;
typedef struct _GetAddress {
@ -792,9 +800,10 @@ extern const uint32_t SignTx_lock_time_default;
/* Initializer values for message structs */
#define Initialize_init_default {0}
#define GetFeatures_init_default {0}
#define Features_init_default {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0, false, 0, false, 0, false, 0, false, 0}
#define Features_init_default {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default, CoinType_init_default}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0}
#define ClearSession_init_default {0}
#define ApplySettings_init_default {false, "", false, "", false, 0, false, {0, {0}}}
#define ApplyFlags_init_default {false, 0}
#define ChangePin_init_default {false, 0}
#define Ping_init_default {false, "", false, 0, false, 0, false, 0}
#define Success_init_default {false, ""}
@ -853,9 +862,10 @@ extern const uint32_t SignTx_lock_time_default;
#define DebugLinkFlashErase_init_default {false, 0}
#define Initialize_init_zero {0}
#define GetFeatures_init_zero {0}
#define Features_init_zero {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0, false, 0, false, 0, false, 0, false, 0}
#define Features_init_zero {false, "", false, 0, false, 0, false, 0, false, 0, false, "", false, 0, false, 0, false, "", false, "", 0, {CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero, CoinType_init_zero}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0}
#define ClearSession_init_zero {0}
#define ApplySettings_init_zero {false, "", false, "", false, 0, false, {0, {0}}}
#define ApplyFlags_init_zero {false, 0}
#define ChangePin_init_zero {false, 0}
#define Ping_init_zero {false, "", false, 0, false, 0, false, 0}
#define Success_init_zero {false, ""}
@ -915,6 +925,7 @@ extern const uint32_t SignTx_lock_time_default;
/* Field tags (for use in manual encoding/decoding) */
#define Address_address_tag 1
#define ApplyFlags_flags_tag 1
#define ApplySettings_language_tag 1
#define ApplySettings_label_tag 2
#define ApplySettings_use_passphrase_tag 3
@ -999,6 +1010,7 @@ extern const uint32_t SignTx_lock_time_default;
#define Features_passphrase_cached_tag 17
#define Features_firmware_present_tag 18
#define Features_needs_backup_tag 19
#define Features_flags_tag 20
#define GetAddress_address_n_tag 1
#define GetAddress_coin_name_tag 2
#define GetAddress_show_display_tag 3
@ -1079,9 +1091,10 @@ extern const uint32_t SignTx_lock_time_default;
/* Struct field encoding specification for nanopb */
extern const pb_field_t Initialize_fields[1];
extern const pb_field_t GetFeatures_fields[1];
extern const pb_field_t Features_fields[20];
extern const pb_field_t Features_fields[21];
extern const pb_field_t ClearSession_fields[1];
extern const pb_field_t ApplySettings_fields[5];
extern const pb_field_t ApplyFlags_fields[2];
extern const pb_field_t ChangePin_fields[2];
extern const pb_field_t Ping_fields[5];
extern const pb_field_t Success_fields[2];
@ -1142,9 +1155,10 @@ extern const pb_field_t DebugLinkFlashErase_fields[2];
/* Maximum encoded size of messages (where known) */
#define Initialize_size 0
#define GetFeatures_size 0
#define Features_size (260 + 8*CoinType_size)
#define Features_size (267 + 8*CoinType_size)
#define ClearSession_size 0
#define ApplySettings_size 1083
#define ApplyFlags_size 6
#define ChangePin_size 2
#define Ping_size 265
#define Success_size 259

View File

@ -21,6 +21,7 @@
{ 'n', 'i', MessageType_MessageType_ClearSession, ClearSession_fields, (void (*)(void *)) fsm_msgClearSession },
{ 'n', 'i', MessageType_MessageType_ApplySettings, ApplySettings_fields, (void (*)(void *)) fsm_msgApplySettings },
// Message ButtonAck is used in tiny mode
{ 'n', 'i', MessageType_MessageType_ApplyFlags, ApplyFlags_fields, (void (*)(void *)) fsm_msgApplyFlags },
{ 'n', 'i', MessageType_MessageType_GetAddress, GetAddress_fields, (void (*)(void *)) fsm_msgGetAddress },
// Message SelfTest is used in bootloader mode only
{ 'n', 'i', MessageType_MessageType_BackupDevice, BackupDevice_fields, (void (*)(void *)) fsm_msgBackupDevice },

View File

@ -5,7 +5,7 @@
const pb_field_t Storage_fields[13] = {
const pb_field_t Storage_fields[14] = {
PB_FIELD2( 1, UINT32 , REQUIRED, STATIC , FIRST, Storage, version, version, 0),
PB_FIELD2( 2, MESSAGE , OPTIONAL, STATIC , OTHER, Storage, node, version, &HDNodeType_fields),
PB_FIELD2( 3, STRING , OPTIONAL, STATIC , OTHER, Storage, mnemonic, node, 0),
@ -18,6 +18,7 @@ const pb_field_t Storage_fields[13] = {
PB_FIELD2( 10, BYTES , OPTIONAL, STATIC , OTHER, Storage, homescreen, imported, 0),
PB_FIELD2( 11, UINT32 , OPTIONAL, STATIC , OTHER, Storage, u2f_counter, homescreen, 0),
PB_FIELD2( 12, BOOL , OPTIONAL, STATIC , OTHER, Storage, needs_backup, u2f_counter, 0),
PB_FIELD2( 13, UINT32 , OPTIONAL, STATIC , OTHER, Storage, flags, needs_backup, 0),
PB_LAST_FIELD
};

View File

@ -41,13 +41,15 @@ typedef struct _Storage {
uint32_t u2f_counter;
bool has_needs_backup;
bool needs_backup;
bool has_flags;
uint32_t flags;
} Storage;
/* Default values for struct fields */
/* Initializer values for message structs */
#define Storage_init_default {0, false, HDNodeType_init_default, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}, false, 0, false, 0}
#define Storage_init_zero {0, false, HDNodeType_init_zero, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}, false, 0, false, 0}
#define Storage_init_default {0, false, HDNodeType_init_default, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}, false, 0, false, 0, false, 0}
#define Storage_init_zero {0, false, HDNodeType_init_zero, false, "", false, 0, false, 0, false, "", false, "", false, "", false, 0, false, {0, {0}}, false, 0, false, 0, false, 0}
/* Field tags (for use in manual encoding/decoding) */
#define Storage_version_tag 1
@ -62,12 +64,13 @@ typedef struct _Storage {
#define Storage_homescreen_tag 10
#define Storage_u2f_counter_tag 11
#define Storage_needs_backup_tag 12
#define Storage_flags_tag 13
/* Struct field encoding specification for nanopb */
extern const pb_field_t Storage_fields[13];
extern const pb_field_t Storage_fields[14];
/* Maximum encoded size of messages (where known) */
#define Storage_size (1367 + HDNodeType_size)
#define Storage_size (1373 + HDNodeType_size)
#ifdef __cplusplus
} /* extern "C" */

View File

@ -585,6 +585,21 @@ bool storage_needsBackup(void)
return storage.has_needs_backup && storage.needs_backup;
}
void storage_applyFlags(uint32_t flags)
{
if ((storage.flags | flags) == storage.flags) {
return; // no new flags
}
storage.has_flags = true;
storage.flags |= flags;
storage_commit();
}
uint32_t storage_getFlags(void)
{
return storage.has_flags ? storage.flags : 0;
}
uint32_t storage_nextU2FCounter(void)
{
uint32_t *ptr = ((uint32_t *) FLASH_STORAGE_U2FAREA) + (storage_u2f_offset / 32);

View File

@ -70,6 +70,9 @@ bool storage_isInitialized(void);
bool storage_needsBackup(void);
void storage_applyFlags(uint32_t flags);
uint32_t storage_getFlags(void);
extern Storage storage;
extern char storage_uuid_str[25];

@ -1 +1 @@
Subproject commit b29b98d69ba43571dcbe54dc927aa3ecd2b95113
Subproject commit 2eb9c7e352f708506d910f2d5b9aac1e85cafa10