Skip to content

Commit

Permalink
nfc: NTAG21x complete emulation (#1313)
Browse files Browse the repository at this point in the history
* nfc: Refactor Mifare Ultralight feature flags
  Unify them in both reader and emulator to make handling easier
* nfc: Refactor MFUL PWD_AUTH and add AUTHLIM counter
* nfc: Add MFUL EV1 VCSL command emulation
* nfc: Enforce message size check in MFUL emulation
  Also fix READ_CNT byte order, but it's not fully working
* nfc: Add MFUL auth counter serialization
  Also fill counter on successful read from tag
* nfc: Fix MFUL INCR_CNT emulation
* nfc: Fix MFUL READ_CNT emulation
* nfc: Refactor MFUL emulation and implement full write support
* nfc: Fix Mifare Ultralight serialization
* nfc: Add MFUL OTP/CC handling
* nfc: Make sure MF0UL21 dynamic lock byte 3 also reads 0xBD
* nfc: Small MFUL refactor and fix CFGLCK behavior
* WIP: nfc: MFUL read support with ASCII mirror and auth roll-over
  This is too complex and I don't like it
* nfc: Simplify MFUL read emulation, fix mirror range check
* nfc: Implement MFUL auth and ASCII mirror for FAST_READ
* nfc: Fix MFUL read roll-over with AUTH0 set
* nfc: Implement MFUL read counter increment
* nfc: Align ASCII mirror to NTAG21x behavior
* nfc: Handle invalid command in MFUL emulation
* nfc: Fix MFUL static lock check
* nfc: Refactor MFUL emulation to use cached config pages
* nfc: Refactor MFUL auth counter to count up instead of down
* nfc: Add missing NULL check
* WIP: nfc: Various MFUL emulation behavior tweaks
* WIP: nfc: More MFUL emulation behavior adjustments
* nfc: Match AUTHLIM emulation to NTAG21x behavior
* nfc: Fix MFUL dynamic lock emulation
* nfc: Fix typo in MFUL read counters
* nfc: Fix typo in MFUL FAST_READ emulation
* nfc: Increase emulation TX buffer size
  Enough space for if someone requests FAST_READ of all pages of an NTAG
* nfc: Fix MFUL negative verification counter overflow
* nfc: Change auth counter kv name
* nfc: Fix NTAG I2C FAST_READ emulation
* nfc: Fix NTAG21x config reload behavior

Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
GMMan and skotopes authored Jun 21, 2022
1 parent 88facf2 commit 556af0b
Show file tree
Hide file tree
Showing 5 changed files with 951 additions and 321 deletions.
12 changes: 12 additions & 0 deletions applications/nfc/nfc_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ static bool nfc_device_save_mifare_ul_data(FlipperFormat* file, NfcDevice* dev)
}
}
if(!pages_saved) break;

// Write authentication counter
uint32_t auth_counter = data->curr_authlim;
if(!flipper_format_write_uint32(file, "Failed authentication attempts", &auth_counter, 1))
break;

saved = true;
} while(false);

Expand Down Expand Up @@ -169,6 +175,12 @@ bool nfc_device_load_mifare_ul_data(FlipperFormat* file, NfcDevice* dev) {
}
}
if(!pages_parsed) break;

// Read authentication counter
uint32_t auth_counter;
if(!flipper_format_read_uint32(file, "Failed authentication attempts", &auth_counter, 1))
auth_counter = 0;

parsed = true;
} while(false);

Expand Down
6 changes: 1 addition & 5 deletions applications/nfc/nfc_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,7 @@ void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) {
MfUltralightEmulator emulator = {};
mf_ul_prepare_emulation(&emulator, &nfc_worker->dev_data->mf_ul_data);
while(nfc_worker->state == NfcWorkerStateEmulateMifareUltralight) {
emulator.auth_success = false;
if(emulator.data.type >= MfUltralightTypeNTAGI2C1K) {
// Sector index needs to be reset
emulator.curr_sector = 0;
}
mf_ul_reset_emulation(&emulator, true);
furi_hal_nfc_emulate_nfca(
nfc_data->uid,
nfc_data->uid_len,
Expand Down
2 changes: 1 addition & 1 deletion firmware/targets/f7/furi_hal/furi_hal_nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool furi_hal_nfc_emulate_nfca(
uint8_t buff_rx[256];
uint16_t buff_rx_size = 256;
uint16_t buff_rx_len = 0;
uint8_t buff_tx[256];
uint8_t buff_tx[1040];
uint16_t buff_tx_len = 0;
uint32_t data_type = FURI_HAL_NFC_TXRX_DEFAULT;

Expand Down
Loading

0 comments on commit 556af0b

Please sign in to comment.