From aee35dc768c96c6c9dc8ea6ea95dee1d1cb88603 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 30 Mar 2015 15:47:03 +0200 Subject: [PATCH] add pin_cached + passphrase_cached fields to Features message; add GetFeatures message --- firmware/fsm.c | 8 ++++++++ firmware/fsm.h | 1 + firmware/messages.c | 1 + firmware/protob/messages.pb.c | 10 ++++++++-- firmware/protob/messages.pb.h | 23 +++++++++++++++++++---- trezor-common | 2 +- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/firmware/fsm.c b/firmware/fsm.c index ac0cd3ad08..fea3eef66a 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -114,6 +114,12 @@ void fsm_msgInitialize(Initialize *msg) recovery_abort(); signing_abort(); session_clear(); + fsm_msgGetFeatures(0); +} + +void fsm_msgGetFeatures(GetFeatures *msg) +{ + (void)msg; RESP_INIT(Features); resp->has_vendor = true; strlcpy(resp->vendor, "bitcointrezor.com", sizeof(resp->vendor)); resp->has_major_version = true; resp->major_version = VERSION_MAJOR; @@ -139,6 +145,8 @@ void fsm_msgInitialize(Initialize *msg) memcpy(resp->coins, coins, COINS_COUNT * sizeof(CoinType)); resp->has_initialized = true; resp->initialized = storage_isInitialized(); resp->has_imported = true; resp->imported = storage.has_imported && storage.imported; + resp->has_pin_cached = true; resp->pin_cached = session_isPinCached(); + resp->has_passphrase_cached = true; resp->passphrase_cached = session_isPassphraseCached(); msg_write(MessageType_MessageType_Features, resp); } diff --git a/firmware/fsm.h b/firmware/fsm.h index 021eeb31a3..1a3fcf8f1e 100644 --- a/firmware/fsm.h +++ b/firmware/fsm.h @@ -28,6 +28,7 @@ void fsm_sendSuccess(const char *text); void fsm_sendFailure(FailureType code, const char *text); void fsm_msgInitialize(Initialize *msg); +void fsm_msgGetFeatures(GetFeatures *msg); void fsm_msgPing(Ping *msg); void fsm_msgChangePin(ChangePin *msg); void fsm_msgWipeDevice(WipeDevice *msg); diff --git a/firmware/messages.c b/firmware/messages.c index 1c95d8167e..7803efee62 100644 --- a/firmware/messages.c +++ b/firmware/messages.c @@ -40,6 +40,7 @@ struct MessagesMap_t { static const struct MessagesMap_t MessagesMap[] = { // in messages {'n', 'i', MessageType_MessageType_Initialize, Initialize_fields, (void (*)(void *))fsm_msgInitialize}, + {'n', 'i', MessageType_MessageType_GetFeatures, GetFeatures_fields, (void (*)(void *))fsm_msgGetFeatures}, {'n', 'i', MessageType_MessageType_Ping, Ping_fields, (void (*)(void *))fsm_msgPing}, {'n', 'i', MessageType_MessageType_ChangePin, ChangePin_fields, (void (*)(void *))fsm_msgChangePin}, {'n', 'i', MessageType_MessageType_WipeDevice, WipeDevice_fields, (void (*)(void *))fsm_msgWipeDevice}, diff --git a/firmware/protob/messages.pb.c b/firmware/protob/messages.pb.c index 3e4e41bf27..8823d70f96 100644 --- a/firmware/protob/messages.pb.c +++ b/firmware/protob/messages.pb.c @@ -19,7 +19,11 @@ const pb_field_t Initialize_fields[1] = { PB_LAST_FIELD }; -const pb_field_t Features_fields[16] = { +const pb_field_t GetFeatures_fields[1] = { + PB_LAST_FIELD +}; + +const pb_field_t Features_fields[18] = { 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), @@ -35,6 +39,8 @@ const pb_field_t Features_fields[16] = { PB_FIELD2( 13, BYTES , OPTIONAL, STATIC , OTHER, Features, revision, initialized, 0), PB_FIELD2( 14, BYTES , OPTIONAL, STATIC , OTHER, Features, bootloader_hash, revision, 0), PB_FIELD2( 15, BOOL , OPTIONAL, STATIC , OTHER, Features, imported, bootloader_hash, 0), + PB_FIELD2( 16, BOOL , OPTIONAL, STATIC , OTHER, Features, pin_cached, imported, 0), + PB_FIELD2( 17, BOOL , OPTIONAL, STATIC , OTHER, Features, passphrase_cached, pin_cached, 0), PB_LAST_FIELD }; @@ -365,7 +371,7 @@ const pb_field_t DebugLinkLog_fields[4] = { * 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(SimpleSignTx, inputs[0]) < 65536 && pb_membersize(SimpleSignTx, outputs[0]) < 65536 && pb_membersize(SimpleSignTx, transactions[0]) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, identity) < 65536 && pb_membersize(DebugLinkState, node) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Initialize_Features_ClearSession_ApplySettings_ChangePin_Ping_Success_Failure_ButtonRequest_ButtonAck_PinMatrixRequest_PinMatrixAck_Cancel_PassphraseRequest_PassphraseAck_GetEntropy_Entropy_GetPublicKey_PublicKey_GetAddress_Address_WipeDevice_LoadDevice_ResetDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_EncryptMessage_EncryptedMessage_DecryptMessage_DecryptedMessage_CipherKeyValue_CipheredKeyValue_EstimateTxSize_TxSize_SignTx_SimpleSignTx_TxRequest_TxAck_SignIdentity_SignedIdentity_FirmwareErase_FirmwareUpload_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog) +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(SimpleSignTx, inputs[0]) < 65536 && pb_membersize(SimpleSignTx, outputs[0]) < 65536 && pb_membersize(SimpleSignTx, transactions[0]) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, 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_Address_WipeDevice_LoadDevice_ResetDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_EncryptMessage_EncryptedMessage_DecryptMessage_DecryptedMessage_CipherKeyValue_CipheredKeyValue_EstimateTxSize_TxSize_SignTx_SimpleSignTx_TxRequest_TxAck_SignIdentity_SignedIdentity_FirmwareErase_FirmwareUpload_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog) #endif #if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) diff --git a/firmware/protob/messages.pb.h b/firmware/protob/messages.pb.h index 873c950f79..b56c8d37fa 100644 --- a/firmware/protob/messages.pb.h +++ b/firmware/protob/messages.pb.h @@ -60,6 +60,7 @@ typedef enum _MessageType { MessageType_MessageType_DecryptedMessage = 52, MessageType_MessageType_SignIdentity = 53, MessageType_MessageType_SignedIdentity = 54, + MessageType_MessageType_GetFeatures = 55, MessageType_MessageType_DebugLinkDecision = 100, MessageType_MessageType_DebugLinkGetState = 101, MessageType_MessageType_DebugLinkState = 102, @@ -96,6 +97,10 @@ typedef struct _FirmwareErase { uint8_t dummy_field; } FirmwareErase; +typedef struct _GetFeatures { + uint8_t dummy_field; +} GetFeatures; + typedef struct _Initialize { uint8_t dummy_field; } Initialize; @@ -379,6 +384,10 @@ typedef struct _Features { Features_bootloader_hash_t bootloader_hash; bool has_imported; bool imported; + bool has_pin_cached; + bool pin_cached; + bool has_passphrase_cached; + bool passphrase_cached; } Features; typedef struct { @@ -624,7 +633,8 @@ extern const char SimpleSignTx_coin_name_default[17]; /* Initializer values for message structs */ #define Initialize_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}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 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}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0, false, 0, false, 0} #define ClearSession_init_default {0} #define ApplySettings_init_default {false, "", false, "", false, 0, false, {0, {0}}} #define ChangePin_init_default {false, 0} @@ -677,7 +687,8 @@ extern const char SimpleSignTx_coin_name_default[17]; #define DebugLinkStop_init_default {0} #define DebugLinkLog_init_default {false, 0, false, "", false, ""} #define Initialize_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}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 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}, false, 0, false, {0, {0}}, false, {0, {0}}, false, 0, false, 0, false, 0} #define ClearSession_init_zero {0} #define ApplySettings_init_zero {false, "", false, "", false, 0, false, {0, {0}}} #define ChangePin_init_zero {false, 0} @@ -796,6 +807,8 @@ extern const char SimpleSignTx_coin_name_default[17]; #define Features_revision_tag 13 #define Features_bootloader_hash_tag 14 #define Features_imported_tag 15 +#define Features_pin_cached_tag 16 +#define Features_passphrase_cached_tag 17 #define FirmwareUpload_payload_tag 1 #define GetAddress_address_n_tag 1 #define GetAddress_coin_name_tag 2 @@ -862,7 +875,8 @@ extern const char SimpleSignTx_coin_name_default[17]; /* Struct field encoding specification for nanopb */ extern const pb_field_t Initialize_fields[1]; -extern const pb_field_t Features_fields[16]; +extern const pb_field_t GetFeatures_fields[1]; +extern const pb_field_t Features_fields[18]; extern const pb_field_t ClearSession_fields[1]; extern const pb_field_t ApplySettings_fields[5]; extern const pb_field_t ChangePin_fields[2]; @@ -917,7 +931,8 @@ extern const pb_field_t DebugLinkLog_fields[4]; /* Maximum encoded size of messages (where known) */ #define Initialize_size 0 -#define Features_size (236 + 6*CoinType_size) +#define GetFeatures_size 0 +#define Features_size (242 + 6*CoinType_size) #define ClearSession_size 0 #define ApplySettings_size 1083 #define ChangePin_size 2 diff --git a/trezor-common b/trezor-common index 137ae02853..e96ec085d5 160000 --- a/trezor-common +++ b/trezor-common @@ -1 +1 @@ -Subproject commit 137ae028531567ec2e042ffcd6d6c73a97cfd4c8 +Subproject commit e96ec085d55c20eccecb47e0a55b33295164de6d