Skip to content

Commit

Permalink
A more eloquent solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Demae committed Jan 3, 2025
1 parent 8a00874 commit deef40f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/nfc/protocols/mf_desfire/mf_desfire.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ typedef enum {
MfDesfireErrorProtocol,
MfDesfireErrorTimeout,
MfDesfireErrorAuthentication,
MfDesfireErrorCommandNotSupported,
} MfDesfireError;

typedef struct {
Expand Down
10 changes: 4 additions & 6 deletions lib/nfc/protocols/mf_desfire/mf_desfire_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,17 @@ static NfcCommand mf_desfire_poller_handler_read_version(MfDesfirePoller* instan
static NfcCommand mf_desfire_poller_handler_read_free_memory(MfDesfirePoller* instance) {
NfcCommand command = NfcCommandContinue;

if(instance->data->version.hw_major == 0x00 && instance->data->version.hw_minor == 0x02) {
instance->state = MfDesfirePollerStateReadMasterKeySettings;
return command;
}

instance->error = mf_desfire_poller_read_free_memory(instance, &instance->data->free_memory);
if(instance->error == MfDesfireErrorNone) {
FURI_LOG_D(TAG, "Read free memory success");
instance->state = MfDesfirePollerStateReadMasterKeySettings;
} else if(instance->error == MfDesfireErrorNotPresent) {
FURI_LOG_D(TAG, "Read free memoty is unsupported");
FURI_LOG_D(TAG, "Read free memory is unsupported");
instance->state = MfDesfirePollerStateReadMasterKeySettings;
command = NfcCommandReset;
} else if(instance->error == MfDesfireErrorCommandNotSupported) {
FURI_LOG_D(TAG, "Read free memory is unsupported");
instance->state = MfDesfirePollerStateReadMasterKeySettings;
} else {
FURI_LOG_E(TAG, "Failed to read free memory");
iso14443_4a_poller_halt(instance->iso14443_4a_poller);
Expand Down
2 changes: 2 additions & 0 deletions lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ MfDesfireError mf_desfire_process_status_code(uint8_t status_code) {
return MfDesfireErrorNone;
case MF_DESFIRE_STATUS_AUTHENTICATION_ERROR:
return MfDesfireErrorAuthentication;
case MF_DESFIRE_STATUS_ILLEGAL_COMMAND_CODE:
return MfDesfireErrorCommandNotSupported;
default:
return MfDesfireErrorProtocol;
}
Expand Down

0 comments on commit deef40f

Please sign in to comment.