diff --git a/firmware/fsm.c b/firmware/fsm.c index b000e29..5f6385e 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -1017,9 +1017,11 @@ void fsm_msgSetAccountLabel(SetAccountLabel *msg) return ; } + const uint32_t labels_count_init = storage_getAccountCount(coin_index); + if(labels_count_init == 0xffffffff) + storage_labelInit(); const uint32_t labels_count = storage_getAccountCount(coin_index); - const uint32_t find_index = storage_findAccountLabel(msg->index, coin_index); - if((labels_count >= LABEL_COUNT) && (find_index > LABEL_COUNT)) { + if(labels_count >= LABEL_COUNT) { fsm_sendFailure(FailureType_Failure_Other, "Label cannot be more than 32"); return ; } @@ -1071,6 +1073,7 @@ void fsm_msgSetAccountLabel(SetAccountLabel *msg) return; } + const uint32_t find_index = storage_findAccountLabel(msg->index, coin_index); if(msg->has_label && msg->has_index) { storage_setAccountLabel(msg->label, msg->index, coin_index, labels_count, find_index); } @@ -1096,6 +1099,7 @@ void fsm_msgGetAccountLabels(GetAccountLabels *msg) return ; } + const uint32_t find_index = storage_findAccountLabel(msg->index, coin_index); RESP_INIT(AccountLabels); diff --git a/firmware/protob/messages.options b/firmware/protob/messages.options index 05fa8b5..6c0bdf8 100644 --- a/firmware/protob/messages.options +++ b/firmware/protob/messages.options @@ -6,6 +6,8 @@ Features.coins max_count:6 Features.revision max_size:20 Features.bootloader_hash max_size:32 +Initialize.language max_size:17 + ApplySettings.language max_size:17 ApplySettings.label max_size:33 ApplySettings.homescreen max_size:1024 diff --git a/firmware/protob/messages.pb.c b/firmware/protob/messages.pb.c index 1d45fca..31ee033 100644 --- a/firmware/protob/messages.pb.c +++ b/firmware/protob/messages.pb.c @@ -20,7 +20,7 @@ const char SetAccountLabel_coin_name_default[17] = "Bitcoin"; const pb_field_t Initialize_fields[2] = { - PB_FIELD2( 1, STRING , OPTIONAL, CALLBACK, FIRST, Initialize, language, language, 0), + PB_FIELD2( 1, STRING , OPTIONAL, STATIC , FIRST, Initialize, language, language, 0), PB_LAST_FIELD }; diff --git a/firmware/protob/messages.pb.h b/firmware/protob/messages.pb.h index 8a6f221..393e2cb 100644 --- a/firmware/protob/messages.pb.h +++ b/firmware/protob/messages.pb.h @@ -436,7 +436,8 @@ typedef struct _GetPublicKey { } GetPublicKey; typedef struct _Initialize { - pb_callback_t language; + bool has_language; + char language[17]; } Initialize; typedef struct _LoadDevice { @@ -669,7 +670,7 @@ extern const char GetAccountLabels_coin_name_default[17]; extern const char SetAccountLabel_coin_name_default[17]; /* Initializer values for message structs */ -#define Initialize_init_default {{{NULL}, NULL}} +#define Initialize_init_default {false, ""} #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} @@ -727,7 +728,7 @@ extern const char SetAccountLabel_coin_name_default[17]; #define DebugLinkState_init_default {false, {0, {0}}, false, "", false, "", false, "", false, HDNodeType_init_default, false, 0, false, "", false, {0, {0}}, false, "", false, 0} #define DebugLinkStop_init_default {0} #define DebugLinkLog_init_default {false, 0, false, "", false, ""} -#define Initialize_init_zero {{{NULL}, NULL}} +#define Initialize_init_zero {false, ""} #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} @@ -989,6 +990,7 @@ extern const pb_field_t DebugLinkStop_fields[1]; extern const pb_field_t DebugLinkLog_fields[4]; /* Maximum encoded size of messages (where known) */ +#define Initialize_size 19 #define GetFeatures_size 0 #define Features_size (242 + 6*CoinType_size) #define ClearSession_size 0 diff --git a/firmware/storage.c b/firmware/storage.c index 598212c..21d53e6 100644 --- a/firmware/storage.c +++ b/firmware/storage.c @@ -202,6 +202,20 @@ void storage_loadDevice(LoadDevice *msg) } } +void storage_labelInit(void) +{ + int i, j; + for(i = 0; i < COINS_COUNT; i++){ + storage.label_list[i].count = 0; + for(j = 0; j < LABEL_COUNT; j++) { + storage.label_list[i].labels[j].index = 0; + memset(storage.label_list[i].labels[j].label, 0, + sizeof(storage.label_list[i].labels[j].label)); + } + } + storage_commit(); +} + uint32_t storage_findAccountLabel(const uint32_t index, const uint32_t coin_index) { uint32_t find_index, count; diff --git a/firmware/storage.h b/firmware/storage.h index 9243414..4d30b98 100644 --- a/firmware/storage.h +++ b/firmware/storage.h @@ -53,6 +53,7 @@ void storage_setHomescreen(const uint8_t *data, uint32_t size); void session_cachePassphrase(const char *passphrase); bool session_isPassphraseCached(void); +void storage_labelInit(void); void storage_getAccountLabels(bool all, const uint32_t index, AccountLabels *coin_labels, const uint32_t coin_index); void storage_setAccountLabel(const char *label, const uint32_t index, const uint32_t coin_index, const uint32_t count, const uint32_t find_index); void storage_delAccountLabel(const uint32_t coin_index, const uint32_t count, const uint32_t find_index);