Better handling of read/write failure

This commit is contained in:
Willy-JL
2025-03-18 03:46:00 +00:00
parent b1346bc9bb
commit 106d72a332
3 changed files with 12 additions and 14 deletions

View File

@@ -14,6 +14,7 @@ typedef enum {
Type4TagErrorWrongFormat,
Type4TagErrorNotSupported,
Type4TagErrorApduFailed,
Type4TagErrorCardUnformatted,
Type4TagErrorCardLocked,
Type4TagErrorCustomCommand,
} Type4TagError;

View File

@@ -74,7 +74,7 @@ static NfcCommand type_4_tag_poller_handler_select_app(Type4TagPoller* instance)
} else {
FURI_LOG_E(TAG, "Failed to select application");
if(instance->mode == Type4TagPollerModeWrite &&
instance->error == Type4TagErrorApduFailed) {
instance->error == Type4TagErrorCardUnformatted) {
instance->state = Type4TagPollerStateCreateApplication;
} else {
instance->state = Type4TagPollerStateFailed;
@@ -94,7 +94,7 @@ static NfcCommand type_4_tag_poller_handler_read_cc(Type4TagPoller* instance) {
} else {
FURI_LOG_E(TAG, "Failed to read CC");
if(instance->mode == Type4TagPollerModeWrite &&
instance->error == Type4TagErrorApduFailed) {
instance->error == Type4TagErrorCardUnformatted) {
instance->state = Type4TagPollerStateCreateCapabilityContainer;
} else {
instance->state = Type4TagPollerStateFailed;
@@ -124,9 +124,6 @@ static NfcCommand type_4_tag_poller_handler_create_app(Type4TagPoller* instance)
instance->state = Type4TagPollerStateSelectApplication;
} else {
FURI_LOG_E(TAG, "Failed to create application");
if(instance->error == Type4TagErrorApduFailed) {
instance->error = Type4TagErrorCardLocked;
}
instance->state = Type4TagPollerStateFailed;
}
@@ -140,9 +137,6 @@ static NfcCommand type_4_tag_poller_handler_create_cc(Type4TagPoller* instance)
instance->state = Type4TagPollerStateReadCapabilityContainer;
} else {
FURI_LOG_E(TAG, "Failed to create CC");
if(instance->error == Type4TagErrorApduFailed) {
instance->error = Type4TagErrorCardLocked;
}
instance->state = Type4TagPollerStateFailed;
}
@@ -156,9 +150,6 @@ static NfcCommand type_4_tag_poller_handler_create_ndef(Type4TagPoller* instance
instance->state = Type4TagPollerStateWriteNdefMessage;
} else {
FURI_LOG_E(TAG, "Failed to create NDEF");
if(instance->error == Type4TagErrorApduFailed) {
instance->error = Type4TagErrorCardLocked;
}
instance->state = Type4TagPollerStateFailed;
}
@@ -173,7 +164,7 @@ static NfcCommand type_4_tag_poller_handler_write_ndef(Type4TagPoller* instance)
} else {
FURI_LOG_E(TAG, "Failed to write NDEF");
if(instance->mode == Type4TagPollerModeWrite &&
instance->error == Type4TagErrorApduFailed) {
instance->error == Type4TagErrorCardUnformatted) {
instance->state = Type4TagPollerStateCreateNdefMessage;
} else {
instance->state = Type4TagPollerStateFailed;

View File

@@ -56,7 +56,10 @@ static Type4TagError type_5_tag_poller_iso_select_name(
bit_buffer_append_byte(instance->tx_buffer, name_len);
bit_buffer_append_bytes(instance->tx_buffer, name, name_len);
return type_4_tag_apdu_trx(instance, instance->tx_buffer, instance->rx_buffer);
Type4TagError error = type_4_tag_apdu_trx(instance, instance->tx_buffer, instance->rx_buffer);
if(error == Type4TagErrorApduFailed) error = Type4TagErrorCardUnformatted;
return error;
}
static Type4TagError
@@ -76,7 +79,10 @@ static Type4TagError
sizeof(type_4_tag_iso_select_file_apdu));
bit_buffer_append_bytes(instance->tx_buffer, file_id_be, sizeof(file_id_be));
return type_4_tag_apdu_trx(instance, instance->tx_buffer, instance->rx_buffer);
Type4TagError error = type_4_tag_apdu_trx(instance, instance->tx_buffer, instance->rx_buffer);
if(error == Type4TagErrorApduFailed) error = Type4TagErrorCardUnformatted;
return error;
}
static Type4TagError type_5_tag_poller_iso_read(