mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-15 15:46:06 +00:00
feat(core): Fix UID parsing and error printouts
This commit is contained in:
parent
9ca4e03843
commit
f9f3d1a3cb
@ -23,6 +23,7 @@
|
|||||||
#include <trezor_types.h>
|
#include <trezor_types.h>
|
||||||
|
|
||||||
#define NFC_MAX_UID_LEN 10
|
#define NFC_MAX_UID_LEN 10
|
||||||
|
#define NFC_MAX_UID_BUF_SIZE ((NFC_MAX_UID_LEN + 1) * 2)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NFC_POLLER_TECH_A = 0x1,
|
NFC_POLLER_TECH_A = 0x1,
|
||||||
@ -58,7 +59,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t type;
|
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;
|
uint8_t uid_len;
|
||||||
} nfc_dev_info_t;
|
} nfc_dev_info_t;
|
||||||
|
|
||||||
|
@ -537,17 +537,12 @@ nfc_status_t nfc_dev_read_info(nfc_dev_info_t *dev_info) {
|
|||||||
|
|
||||||
dev_info->uid_len = nfcDevice->nfcidLen;
|
dev_info->uid_len = nfcDevice->nfcidLen;
|
||||||
|
|
||||||
if (dev_info->uid_len > 10) {
|
if (nfcDevice->nfcidLen > NFC_MAX_UID_LEN) {
|
||||||
// Unexpected UID length
|
|
||||||
return NFC_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nfcDevice->nfcidLen <= NFC_MAX_UID_LEN) {
|
|
||||||
return NFC_ERROR;
|
return NFC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the hex UID in printable string
|
// 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 {
|
} else {
|
||||||
// No device activated
|
// No device activated
|
||||||
|
@ -107,12 +107,12 @@ static void prodtest_nfc_read_card(cli_t* cli) {
|
|||||||
cli_trace(cli, "NFC Type AP2P: UID: %s", dev_info.uid);
|
cli_trace(cli, "NFC Type AP2P: UID: %s", dev_info.uid);
|
||||||
break;
|
break;
|
||||||
case NFC_DEV_TYPE_UNKNOWN:
|
case NFC_DEV_TYPE_UNKNOWN:
|
||||||
cli_error(cli, CLI_ERROR, "NFC Type UNKNOWN");
|
cli_error(cli, CLI_ERROR_ABORT, "NFC Type UNKNOWN");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cli_error(cli, CLI_ERROR, "NFC Type UNKNOWN");
|
cli_error(cli, CLI_ERROR_ABORT, "NFC Type UNKNOWN");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +203,8 @@ static void prodtest_nfc_write_card(cli_t* cli) {
|
|||||||
timeout);
|
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_activate_stm();
|
||||||
|
|
||||||
nfc_event_t nfc_event;
|
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);
|
nfc_status_t nfc_status = nfc_get_event(&nfc_event);
|
||||||
|
|
||||||
if(nfc_status != NFC_OK) {
|
if(nfc_status != NFC_OK) {
|
||||||
cli_error(cli, CLI_ERROR, "NFC error");
|
cli_error(cli, CLI_ERROR_FATAL, "NFC error");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +229,7 @@ static void prodtest_nfc_write_card(cli_t* cli) {
|
|||||||
nfc_dev_read_info(&dev_info);
|
nfc_dev_read_info(&dev_info);
|
||||||
|
|
||||||
if (dev_info.type != NFC_DEV_TYPE_A) {
|
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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user