Skip to content

Commit 937125f

Browse files
committed
feat(nfc): Add single card pairing
1 parent 4a7fb46 commit 937125f

File tree

6 files changed

+74
-3
lines changed

6 files changed

+74
-3
lines changed

apps/inheritance_app/inheritance_auth_wallet.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "bip39.h"
2121
#include "card_fetch_data.h"
22+
#include "card_pair.h"
2223
#include "inheritance/core.pb.h"
2324
#include "inheritance_api.h"
2425
#include "inheritance_main.h"
@@ -28,7 +29,6 @@
2829
#include "status_api.h"
2930
#include "ui_core_confirm.h"
3031
#include "ui_screens.h"
31-
3232
/*****************************************************************************
3333
* EXTERN VARIABLES
3434
*****************************************************************************/
@@ -123,6 +123,15 @@ static bool auth_wallet_get_entropy() {
123123
memcpy(msgs[0].plain_data, auth->wallet_id, WALLET_ID_SIZE);
124124

125125
card_error_type_e status = card_fetch_encrypt_data(auth->wallet_id, msgs, 1);
126+
// Pair the card first
127+
if (CARD_OPERATION_UNPAIRED_CARD == status) {
128+
card_error_type_e value =
129+
single_card_pair_operation("Pair Card", "Tap to start");
130+
if (value != CARD_OPERATION_SUCCESS) {
131+
return false;
132+
}
133+
status = card_fetch_encrypt_data(auth->wallet_id, msgs, 1);
134+
}
126135

127136
delay_scr_init(ui_text_inheritance_wallet_authenticating, DELAY_SHORT);
128137

common/flash/flash_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
32 ///< Size of IO protection key (used for encrypted comm b/w MCU and
2727
///< ATECC608A)
2828
#define ECDSA_PUB_KEY_SIZE 33 ///< Size of ECDSA (compressed) public key
29-
#define MAX_KEYSTORE_ENTRY 4 ///< Maximum number of keystore entries
29+
#define MAX_KEYSTORE_ENTRY 4 + 1 ///< Maximum number of keystore entries
3030
#define FS_KEYSTORE_KEYID_LEN 4 ///< Length of key id in keystore entry
3131
#define FS_KEYSTORE_KEYPATH_LEN 8 ///< Length of key path in keystore entry
3232
#define FS_KEYSTORE_PRIVKEY_LEN \

src/card_operations/card_fetch_encrypt_data.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ card_error_type_e card_fetch_encrypt_data(uint8_t *wallet_id,
128128
#if USE_SIMULATOR == 0
129129
memcpy(card_data.nfc_data.family_id, get_family_id(), FAMILY_ID_SIZE);
130130
result = card_initialize_applet(&card_data);
131+
if (true == card_data.nfc_data.pairing_error) {
132+
result = CARD_OPERATION_UNPAIRED_CARD;
133+
}
131134
#endif
132135

133136
if (CARD_OPERATION_SUCCESS == card_data.error_type) {

src/card_operations/card_operation_typedefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ typedef enum card_errors_type {
4646
can be associated to @ref
4747
card_error_status_word_e errors or PN532
4848
errors */
49-
49+
CARD_OPERATION_UNPAIRED_CARD, /** Error indicating failed operation due to
50+
card not being paired*/
5051
CARD_OPERATION_DEFAULT_INVALID = 0xFF, /** Default invalid value */
5152
} card_error_type_e;
5253

src/card_operations/card_pair.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,58 @@ card_error_type_e card_pair_operation(uint8_t card_number,
484484
break;
485485
}
486486

487+
nfc_deselect_card();
488+
return card_data.error_type;
489+
}
490+
491+
card_error_type_e single_card_pair_operation(char *heading,
492+
const char *message) {
493+
// Need to handle how assign new card its number
494+
card_operation_data_t card_data = {0};
495+
card_pairing_data_t pair_data = {0};
496+
497+
if (SUCCESS != pair_card_preprocess(&pair_data)) {
498+
return CARD_OPERATION_ABORT_OPERATION;
499+
}
500+
501+
instruction_scr_init(message, heading);
502+
card_data.nfc_data.retries = 5;
503+
504+
while (1) {
505+
// Initialize card tap config
506+
card_data.nfc_data.acceptable_cards = ACCEPTABLE_CARDS_ALL;
507+
508+
init_and_pair_card(&card_data, &pair_data);
509+
510+
if (CARD_OPERATION_SUCCESS == card_data.error_type) {
511+
if (SW_NO_ERROR != handle_pairing_success(&card_data, &pair_data)) {
512+
card_data.error_type = CARD_OPERATION_ABORT_OPERATION;
513+
break;
514+
}
515+
516+
buzzer_start(BUZZER_DURATION);
517+
// if (4 != card_number) {
518+
// wait_for_card_removal();
519+
// }
520+
// since we are pairing only one card
521+
wait_for_card_removal();
522+
523+
break;
524+
}
525+
526+
if (CARD_OPERATION_CARD_REMOVED == card_data.error_type ||
527+
CARD_OPERATION_RETAP_BY_USER_REQUIRED == card_data.error_type) {
528+
const char *error_msg = card_data.error_message;
529+
if (CARD_OPERATION_SUCCESS == indicate_card_error(error_msg)) {
530+
// Re-render the instruction screen
531+
instruction_scr_init(message, heading);
532+
continue;
533+
}
534+
}
535+
536+
break;
537+
}
538+
487539
nfc_deselect_card();
488540
return card_data.error_type;
489541
}

src/card_operations/card_pair.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ card_error_type_e card_pair_without_retap(uint8_t card_number,
6262
card_error_type_e card_pair_operation(uint8_t card_number,
6363
char *heading,
6464
const char *message);
65+
// To Improvise:
66+
// Single card pairing operation,
67+
// Should allow single or extra card to be paired if not already,
68+
// for any required flow
69+
card_error_type_e single_card_pair_operation(char *heading,
70+
const char *message);
6571
#endif

0 commit comments

Comments
 (0)