Skip to content

Commit f222d57

Browse files
committed
chore(app): Review changes
1 parent e6c8904 commit f222d57

File tree

5 files changed

+52
-150
lines changed

5 files changed

+52
-150
lines changed

src/card_operations/card_fetch_data.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ typedef struct {
5353
* GLOBAL FUNCTION PROTOTYPES
5454
*****************************************************************************/
5555

56-
/**
57-
* @brief Fetches wallet list from card after applet initialization.
58-
*
59-
* @param card_data card_operation_data_t used for applet init.
60-
*
61-
* @return The card error type indicating the result of the operation.
62-
*/
63-
card_error_type_e card_get_wallet_list(
64-
card_operation_data_t card_data,
65-
const card_fetch_wallet_list_config_t *configuration,
66-
card_fetch_wallet_list_response_t *response);
67-
6856
/**
6957
* @brief Fetches and encrypts data for a given wallet ID.
7058
*

src/card_operations/card_fetch_decrypt_data.c

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -124,48 +124,7 @@ card_error_type_e card_fetch_decrypt_data(const uint8_t *wallet_id,
124124
#if USE_SIMULATOR == 0
125125
memcpy(card_data.nfc_data.family_id, get_family_id(), FAMILY_ID_SIZE);
126126
result = card_initialize_applet(&card_data);
127-
#endif
128-
// Fetch wallet list from card
129-
wallet_list_t wallets_in_card = {0};
130-
card_fetch_wallet_list_config_t configuration = {
131-
.operation = {.acceptable_cards = ACCEPTABLE_CARDS_ALL,
132-
.skip_card_removal = true,
133-
.expected_family_id = card_data.nfc_data.family_id,
134-
.buzzer_on_success = false},
135-
.frontend = {.heading = ui_text_tap_1_2_cards,
136-
.msg = ui_text_place_card_below}};
137-
138-
card_fetch_wallet_list_response_t response = {
139-
.wallet_list = &wallets_in_card, .card_info = {0}};
140-
#if USE_SIMULATOR == 0
141-
card_error_type_e status =
142-
card_get_wallet_list(card_data, &configuration, &response);
143-
// If the tapped card is not paired, it is a terminal case in the flow
144-
if (true == response.card_info.pairing_error) {
145-
return CARD_OPERATION_DEFAULT_INVALID;
146-
}
147-
148-
// At this stage, either there is no core error message set, or it is set
149-
// but we want to overwrite the error message using user facing messages in
150-
// this flow
151-
uint32_t card_fault_status = 0;
152-
if (1 == response.card_info.recovery_mode) {
153-
card_fault_status = NFC_NULL_PTR_ERROR;
154-
} else if (CARD_OPERATION_SUCCESS != status) {
155-
card_fault_status = response.card_info.status;
156-
}
157-
158-
for (uint8_t i = 0; i < wallets_in_card.count; i++) {
159-
if (memcmp(wallet_id, wallets_in_card.wallet[i].id, WALLET_ID_SIZE) ==
160-
0) {
161-
memcpy(wallet_name,
162-
(const char *)wallets_in_card.wallet[i].name,
163-
NAME_SIZE);
164-
break;
165-
}
166-
}
167-
if (0 == strlen(wallet_name)) {
168-
delay_scr_init(ui_text_wallet_doesnt_exists_on_this_card, DELAY_TIME);
127+
if (!card_fetch_wallet_name(card_data, wallet_id, wallet_name)) {
169128
return CARD_OPERATION_DEFAULT_INVALID;
170129
}
171130
#endif

src/card_operations/card_fetch_encrypt_data.c

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
* INCLUDES
6060
*****************************************************************************/
6161

62+
#include <stdbool.h>
63+
6264
#include "buzzer.h"
6365
#include "card_fetch_data.h"
6466
#include "card_fetch_wallet_list.h"
@@ -88,38 +90,7 @@
8890
/*****************************************************************************
8991
* STATIC VARIABLES
9092
*****************************************************************************/
91-
card_error_type_e card_get_wallet_list(
92-
card_operation_data_t card_data,
93-
const card_fetch_wallet_list_config_t *configuration,
94-
card_fetch_wallet_list_response_t *response) {
95-
if (NULL == configuration || NULL == response ||
96-
NULL == response->wallet_list) {
97-
return CARD_OPERATION_DEFAULT_INVALID;
98-
}
99-
if (CARD_OPERATION_SUCCESS == card_data.error_type) {
100-
card_data.nfc_data.status = nfc_list_all_wallet(response->wallet_list);
10193

102-
if (card_data.nfc_data.status == SW_NO_ERROR ||
103-
card_data.nfc_data.status == SW_RECORD_NOT_FOUND) {
104-
if (card_data.nfc_data.status == SW_RECORD_NOT_FOUND ||
105-
configuration->operation.buzzer_on_success) {
106-
buzzer_start(BUZZER_DURATION);
107-
}
108-
if (!configuration->operation.skip_card_removal) {
109-
wait_for_card_removal();
110-
}
111-
// break;
112-
} else {
113-
card_handle_errors(&card_data);
114-
}
115-
}
116-
117-
response->card_info.pairing_error = card_data.nfc_data.pairing_error;
118-
response->card_info.tapped_card = card_data.nfc_data.tapped_card;
119-
response->card_info.recovery_mode = card_data.nfc_data.recovery_mode;
120-
response->card_info.status = card_data.nfc_data.status;
121-
return card_data.error_type;
122-
}
12394
/*****************************************************************************
12495
* GLOBAL VARIABLES
12596
*****************************************************************************/
@@ -156,48 +127,7 @@ card_error_type_e card_fetch_encrypt_data(const uint8_t *wallet_id,
156127
#if USE_SIMULATOR == 0
157128
memcpy(card_data.nfc_data.family_id, get_family_id(), FAMILY_ID_SIZE);
158129
result = card_initialize_applet(&card_data);
159-
#endif
160-
// Fetch wallet list from card
161-
wallet_list_t wallets_in_card = {0};
162-
card_fetch_wallet_list_config_t configuration = {
163-
.operation = {.acceptable_cards = ACCEPTABLE_CARDS_ALL,
164-
.skip_card_removal = true,
165-
.expected_family_id = card_data.nfc_data.family_id,
166-
.buzzer_on_success = false},
167-
.frontend = {.heading = ui_text_tap_1_2_cards,
168-
.msg = ui_text_place_card_below}};
169-
170-
card_fetch_wallet_list_response_t response = {
171-
.wallet_list = &wallets_in_card, .card_info = {0}};
172-
#if USE_SIMULATOR == 0
173-
card_error_type_e status =
174-
card_get_wallet_list(card_data, &configuration, &response);
175-
// If the tapped card is not paired, it is a terminal case in the flow
176-
if (true == response.card_info.pairing_error) {
177-
return CARD_OPERATION_DEFAULT_INVALID;
178-
}
179-
180-
// At this stage, either there is no core error message set, or it is set
181-
// but we want to overwrite the error message using user facing messages in
182-
// this flow
183-
uint32_t card_fault_status = 0;
184-
if (1 == response.card_info.recovery_mode) {
185-
card_fault_status = NFC_NULL_PTR_ERROR;
186-
} else if (CARD_OPERATION_SUCCESS != status) {
187-
card_fault_status = response.card_info.status;
188-
}
189-
190-
for (uint8_t i = 0; i < wallets_in_card.count; i++) {
191-
if (memcmp(wallet_id, wallets_in_card.wallet[i].id, WALLET_ID_SIZE) ==
192-
0) {
193-
memcpy(wallet_name,
194-
(const char *)wallets_in_card.wallet[i].name,
195-
NAME_SIZE);
196-
break;
197-
}
198-
}
199-
if (0 == strlen(wallet_name)) {
200-
delay_scr_init(ui_text_wallet_doesnt_exists_on_this_card, DELAY_TIME);
130+
if (!card_fetch_wallet_name(card_data, wallet_id, wallet_name)) {
201131
return CARD_OPERATION_DEFAULT_INVALID;
202132
}
203133
#endif

src/card_operations/card_fetch_wallet_list.c

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -184,42 +184,64 @@ card_error_type_e card_fetch_wallet_list(
184184
return card_data.error_type;
185185
}
186186

187-
bool card_fetch_wallet_name(const uint8_t *wallet_id, char *wallet_name) {
187+
bool card_fetch_wallet_name(card_operation_data_t card_data,
188+
const uint8_t *wallet_id,
189+
char *wallet_name) {
188190
wallet_list_t wallets_in_card = {0};
189191

190-
card_fetch_wallet_list_config_t configuration = {
191-
.operation = {.acceptable_cards = ACCEPTABLE_CARDS_ALL,
192-
.skip_card_removal = true,
193-
.expected_family_id = get_family_id(),
194-
.buzzer_on_success = false},
195-
.frontend = {.heading = ui_text_tap_1_2_cards,
196-
.msg = ui_text_place_card_below}};
197-
198-
card_fetch_wallet_list_response_t response = {.wallet_list = &wallets_in_card,
199-
.card_info = {0}};
200-
201192
// P0 abort is the only condition we want to exit the flow
202193
// Card abort error will be explicitly shown here as error codes
203-
card_error_type_e status = card_fetch_wallet_list(&configuration, &response);
194+
while (1) {
195+
card_data.nfc_data.acceptable_cards = ACCEPTABLE_CARDS_ALL;
196+
card_initialize_applet(&card_data);
197+
198+
if (CARD_OPERATION_SUCCESS == card_data.error_type) {
199+
card_data.nfc_data.status = nfc_list_all_wallet(&wallets_in_card);
200+
201+
if (card_data.nfc_data.status == SW_NO_ERROR ||
202+
card_data.nfc_data.status == SW_RECORD_NOT_FOUND) {
203+
break;
204+
} else {
205+
card_handle_errors(&card_data);
206+
}
207+
}
208+
if (CARD_OPERATION_CARD_REMOVED == card_data.error_type ||
209+
CARD_OPERATION_RETAP_BY_USER_REQUIRED == card_data.error_type) {
210+
const char *error_msg = card_data.error_message;
211+
/**
212+
* In case the same card as before is tapped, the user should be told to
213+
* tap a different card instead of the default message "Wrong card
214+
* sequence"
215+
*/
216+
if (SW_CONDITIONS_NOT_SATISFIED == card_data.nfc_data.status) {
217+
error_msg = ui_text_tap_another_card;
218+
}
219+
if (CARD_OPERATION_SUCCESS == indicate_card_error(error_msg)) {
220+
// Re-render the instruction screen
221+
instruction_scr_init(ui_text_place_card_below, ui_text_tap_1_2_cards);
222+
continue;
223+
}
224+
}
225+
// If control reached here, it is an unrecoverable error, so break
226+
break;
227+
}
228+
229+
card_error_type_e status = card_data.error_type;
204230
if (CARD_OPERATION_P0_OCCURED == status) {
205231
return false;
206232
}
207233

208234
// If the tapped card is not paired, it is a terminal case in the flow
209-
if (true == response.card_info.pairing_error) {
235+
if (card_data.nfc_data.pairing_error) {
236+
delay_scr_init(ui_text_device_and_card_not_paired, DELAY_TIME);
210237
return false;
211238
}
212239

213-
// At this stage, either there is no core error message set, or it is set but
214-
// we want to overwrite the error message using user facing messages in this
215-
// flow
216-
clear_core_error_screen();
217-
218240
uint32_t card_fault_status = 0;
219-
if (1 == response.card_info.recovery_mode) {
241+
if (1 == card_data.nfc_data.recovery_mode) {
220242
card_fault_status = NFC_NULL_PTR_ERROR;
221243
} else if (CARD_OPERATION_SUCCESS != status) {
222-
card_fault_status = response.card_info.status;
244+
card_fault_status = card_data.nfc_data.status;
223245
}
224246

225247
for (uint8_t i = 0; i < wallets_in_card.count; i++) {
@@ -231,6 +253,7 @@ bool card_fetch_wallet_name(const uint8_t *wallet_id, char *wallet_name) {
231253
}
232254

233255
if (0 == strlen(wallet_name)) {
256+
delay_scr_init(ui_text_wallet_doesnt_exists_on_this_card, DELAY_TIME);
234257
return false;
235258
}
236259

src/card_operations/card_fetch_wallet_list.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdbool.h>
1616
#include <stdint.h>
1717

18+
#include "card_internal.h"
1819
#include "card_operation_typedefs.h"
1920
#include "wallet_list.h"
2021

@@ -69,6 +70,7 @@ card_error_type_e card_fetch_wallet_list(
6970
* copied.
7071
* @return true if the wallet name is successfully fetched, false otherwise.
7172
*/
72-
bool card_fetch_wallet_name(const uint8_t *wallet_id, char *wallet_name);
73-
73+
bool card_fetch_wallet_name(card_operation_data_t card_data,
74+
const uint8_t *wallet_id,
75+
char *wallet_name);
7476
#endif /* CARD_FETCH_WALLET_LIST_H */

0 commit comments

Comments
 (0)