1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-22 12:32:02 +00:00

feat(core): Fix UID parsing and error printouts

This commit is contained in:
kopecdav 2025-02-10 12:16:01 +01:00 committed by tychovrahe
parent dd38dcc0ee
commit 10e275d652
3 changed files with 10 additions and 13 deletions

View File

@ -23,6 +23,7 @@
#include <trezor_types.h>
#define NFC_MAX_UID_LEN 10
#define NFC_MAX_UID_BUF_SIZE ((NFC_MAX_UID_LEN + 1) * 2)
typedef enum {
NFC_POLLER_TECH_A = 0x1,
@ -58,7 +59,7 @@ typedef enum {
typedef struct {
uint8_t type;
char uid[NFC_MAX_UID_LEN + 1]; // Plus one for string termination
char uid[NFC_MAX_UID_BUF_SIZE]; // Plus one for string termination
uint8_t uid_len;
} nfc_dev_info_t;

View File

@ -537,17 +537,12 @@ nfc_status_t nfc_dev_read_info(nfc_dev_info_t *dev_info) {
dev_info->uid_len = nfcDevice->nfcidLen;
if (dev_info->uid_len > 10) {
// Unexpected UID length
return NFC_ERROR;
}
if (nfcDevice->nfcidLen <= NFC_MAX_UID_LEN) {
if (nfcDevice->nfcidLen > NFC_MAX_UID_LEN) {
return NFC_ERROR;
}
// Copy the hex UID in printable string
cstr_encode_hex(dev_info->uid, NFC_MAX_UID_LEN, nfcDevice->nfcid, nfcDevice->nfcidLen);
cstr_encode_hex(dev_info->uid, NFC_MAX_UID_BUF_SIZE, nfcDevice->nfcid, nfcDevice->nfcidLen);
} else {
// No device activated

View File

@ -107,12 +107,12 @@ static void prodtest_nfc_read_card(cli_t* cli) {
cli_trace(cli, "NFC Type AP2P: UID: %s", dev_info.uid);
break;
case NFC_DEV_TYPE_UNKNOWN:
cli_error(cli, CLI_ERROR, "NFC Type UNKNOWN");
cli_error(cli, CLI_ERROR_ABORT, "NFC Type UNKNOWN");
goto cleanup;
return;
default:
cli_error(cli, CLI_ERROR, "NFC Type UNKNOWN");
cli_error(cli, CLI_ERROR_ABORT, "NFC Type UNKNOWN");
goto cleanup;
}
@ -203,7 +203,8 @@ static void prodtest_nfc_write_card(cli_t* cli) {
timeout);
}
nfc_register_tech(NFC_POLLER_TECH_A);
nfc_register_tech(NFC_POLLER_TECH_A | NFC_POLLER_TECH_B | NFC_POLLER_TECH_F |
NFC_POLLER_TECH_V);
nfc_activate_stm();
nfc_event_t nfc_event;
@ -219,7 +220,7 @@ static void prodtest_nfc_write_card(cli_t* cli) {
nfc_status_t nfc_status = nfc_get_event(&nfc_event);
if(nfc_status != NFC_OK) {
cli_error(cli, CLI_ERROR, "NFC error");
cli_error(cli, CLI_ERROR_FATAL, "NFC error");
goto cleanup;
}
@ -228,7 +229,7 @@ static void prodtest_nfc_write_card(cli_t* cli) {
nfc_dev_read_info(&dev_info);
if (dev_info.type != NFC_DEV_TYPE_A) {
cli_error(cli, CLI_ERROR, "Only NFC type A cards supported");
cli_error(cli, CLI_ERROR_ABORT, "Only NFC type A cards supported");
goto cleanup;
}