Skip to content

Commit 8f38c76

Browse files
committed
Fixed MF3ICD40 DESFire cards freezing NFC application on read due to free memory unable to be read, and added names for each DESFire protocol
Fixed MF3ICD40 DESFire cards soft-locking NFC application due to read free memory being an unsupported function, added naming for DESFire cards
1 parent 35c1bfc commit 8f38c76

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

lib/nfc/protocols/mf_desfire/mf_desfire.c

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@
44

55
#define MF_DESFIRE_PROTOCOL_NAME "Mifare DESFire"
66

7+
typedef struct {
8+
uint8_t minor;
9+
uint8_t major;
10+
uint8_t storage;
11+
const char* full_name;
12+
const char* type_name;
13+
} MfDesfireNames;
14+
15+
static const MfDesfireNames mf_desfire_names[] = {
16+
{0x02, 0x00, 0xFF, "Mifare DESFire 4K (MF3ICD40)", "4K (MF3ICD40)"},
17+
{0x00, 0x01, 0x16, "Mifare DESFire EV1 2K", "EV1 2K"},
18+
{0x00, 0x01, 0x18, "Mifare DESFire EV1 4K", "EV1 4K"},
19+
{0x00, 0x01, 0x1A, "Mifare DESFire EV1 8K", "EV1 8K"},
20+
{0x00, 0x01, 0xFF, "Mifare DESFire EV1", "EV1"},
21+
{0x00, 0x12, 0x16, "Mifare DESFire EV2 2K", "EV2 2K"},
22+
{0x00, 0x12, 0x18, "Mifare DESFire EV2 4K", "EV2 4K"},
23+
{0x00, 0x12, 0x1A, "Mifare DESFire EV2 8K", "EV2 8K"},
24+
{0x00, 0x12, 0xFF, "Mifare DESFire EV2", "EV2"},
25+
{0x00, 0x22, 0x1C, "Mifare DESFire EV2 XL 16K", "EV2 XL 16K"},
26+
{0x00, 0x22, 0x1E, "Mifare DESFire EV2 XL 32K", "EV2 XL 32K"},
27+
{0x00, 0x22, 0xFF, "Mifare DESFire EV2 XL", "EV2 XL"},
28+
{0x00, 0x33, 0x16, "Mifare DESFire EV3 2K", "EV3 2K"},
29+
{0x00, 0x33, 0x18, "Mifare DESFire EV3 4K", "EV3 4K"},
30+
{0x00, 0x33, 0x1A, "Mifare DESFire EV3 8K", "EV3 8K"},
31+
{0x00, 0x33, 0xFF, "Mifare DESFire EV3", "EV3"},
32+
{0xFF, 0xFF, 0xFF, "Unknown Mifare DESFire", "UNK"},
33+
};
34+
735
const NfcDeviceBase nfc_device_mf_desfire = {
836
.protocol_name = MF_DESFIRE_PROTOCOL_NAME,
937
.alloc = (NfcDeviceAlloc)mf_desfire_alloc,
@@ -229,9 +257,24 @@ bool mf_desfire_is_equal(const MfDesfireData* data, const MfDesfireData* other)
229257
}
230258

231259
const char* mf_desfire_get_device_name(const MfDesfireData* data, NfcDeviceNameType name_type) {
232-
UNUSED(data);
233-
UNUSED(name_type);
234-
return MF_DESFIRE_PROTOCOL_NAME;
260+
furi_check(data);
261+
262+
for(size_t i = 0; i < COUNT_OF(mf_desfire_names); i++) {
263+
if((mf_desfire_names[i].minor == data->version.hw_minor ||
264+
mf_desfire_names[i].minor == 0xFF) &&
265+
(mf_desfire_names[i].major == data->version.hw_major ||
266+
mf_desfire_names[i].major == 0xFF) &&
267+
(mf_desfire_names[i].storage == data->version.hw_storage ||
268+
mf_desfire_names[i].storage == 0xFF)) {
269+
if(name_type == NfcDeviceNameTypeFull) {
270+
return mf_desfire_names[i].full_name;
271+
} else {
272+
return mf_desfire_names[i].type_name;
273+
}
274+
}
275+
}
276+
277+
return "Unknown Mifare DESFire";
235278
}
236279

237280
const uint8_t* mf_desfire_get_uid(const MfDesfireData* data, size_t* uid_len) {

lib/nfc/protocols/mf_desfire/mf_desfire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ typedef enum {
131131
MfDesfireErrorProtocol,
132132
MfDesfireErrorTimeout,
133133
MfDesfireErrorAuthentication,
134+
MfDesfireErrorCommandNotSupported,
134135
} MfDesfireError;
135136

136137
typedef struct {

lib/nfc/protocols/mf_desfire/mf_desfire_poller.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ static NfcCommand mf_desfire_poller_handler_read_free_memory(MfDesfirePoller* in
8282
FURI_LOG_D(TAG, "Read free memory success");
8383
instance->state = MfDesfirePollerStateReadMasterKeySettings;
8484
} else if(instance->error == MfDesfireErrorNotPresent) {
85-
FURI_LOG_D(TAG, "Read free memoty is unsupported");
85+
FURI_LOG_D(TAG, "Read free memory is not present");
8686
instance->state = MfDesfirePollerStateReadMasterKeySettings;
8787
command = NfcCommandReset;
88+
} else if(instance->error == MfDesfireErrorCommandNotSupported) {
89+
FURI_LOG_D(TAG, "Read free memory is unsupported");
90+
instance->state = MfDesfirePollerStateReadMasterKeySettings;
8891
} else {
8992
FURI_LOG_E(TAG, "Failed to read free memory");
9093
iso14443_4a_poller_halt(instance->iso14443_4a_poller);

lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ MfDesfireError mf_desfire_process_status_code(uint8_t status_code) {
2525
return MfDesfireErrorNone;
2626
case MF_DESFIRE_STATUS_AUTHENTICATION_ERROR:
2727
return MfDesfireErrorAuthentication;
28+
case MF_DESFIRE_STATUS_ILLEGAL_COMMAND_CODE:
29+
return MfDesfireErrorCommandNotSupported;
2830
default:
2931
return MfDesfireErrorProtocol;
3032
}

0 commit comments

Comments
 (0)