Skip to content

Commit

Permalink
fix set label init, set initalize language size
Browse files Browse the repository at this point in the history
  • Loading branch information
ykevin committed May 5, 2015
1 parent a79f651 commit 98820b1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
8 changes: 6 additions & 2 deletions firmware/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -1096,6 +1099,7 @@ void fsm_msgGetAccountLabels(GetAccountLabels *msg)
return ;
}


const uint32_t find_index = storage_findAccountLabel(msg->index, coin_index);

RESP_INIT(AccountLabels);
Expand Down
2 changes: 2 additions & 0 deletions firmware/protob/messages.options
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion firmware/protob/messages.pb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
8 changes: 5 additions & 3 deletions firmware/protob/messages.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions firmware/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions firmware/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 98820b1

Please sign in to comment.