From cea118cf2d92c545ee75297811beac01e340f6eb Mon Sep 17 00:00:00 2001 From: gornekich Date: Wed, 20 Apr 2022 17:08:36 +0300 Subject: [PATCH] [FL-2470, FL-2385, FL-2411] NFC fixes (#1138) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * mifare classic: increase data exchange timeout * nfc: exit from app if can't parse file * furi_hal_nfc: allow to switch context during detect Co-authored-by: あく --- applications/nfc/nfc.c | 13 +++++++++---- firmware/targets/f7/furi_hal/furi_hal_nfc.c | 2 +- lib/nfc_protocols/mifare_classic.c | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/applications/nfc/nfc.c b/applications/nfc/nfc.c index e59896e3..4660b344 100755 --- a/applications/nfc/nfc.c +++ b/applications/nfc/nfc.c @@ -169,11 +169,16 @@ int32_t nfc_app(void* p) { char* args = p; // Check argument and run corresponding scene - if((*args != '\0') && nfc_device_load(nfc->dev, p)) { - if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl); + if((*args != '\0')) { + if(nfc_device_load(nfc->dev, p)) { + if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) { + scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl); + } else { + scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid); + } } else { - scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid); + // Exit app + view_dispatcher_stop(nfc->view_dispatcher); } } else { scene_manager_next_scene(nfc->scene_manager, NfcSceneStart); diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc.c b/firmware/targets/f7/furi_hal/furi_hal_nfc.c index 1d2c02d9..ae776b53 100755 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc.c +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc.c @@ -96,7 +96,7 @@ bool furi_hal_nfc_detect(FuriHalNfcDevData* nfc_data, uint32_t timeout) { FURI_LOG_T(TAG, "Timeout"); break; } - osThreadYield(); + osDelay(1); } rfalNfcGetDevicesFound(&dev_list, &dev_cnt); if(detected) { diff --git a/lib/nfc_protocols/mifare_classic.c b/lib/nfc_protocols/mifare_classic.c index eb5d3dda..7aa39991 100644 --- a/lib/nfc_protocols/mifare_classic.c +++ b/lib/nfc_protocols/mifare_classic.c @@ -118,7 +118,7 @@ static bool mf_classic_auth( tx_rx->tx_data[1] = block; tx_rx->tx_rx_type = FuriHalNfcTxRxTypeRxNoCrc; tx_rx->tx_bits = 2 * 8; - if(!furi_hal_nfc_tx_rx(tx_rx, 4)) break; + if(!furi_hal_nfc_tx_rx(tx_rx, 5)) break; uint32_t nt = (uint32_t)nfc_util_bytes2num(tx_rx->rx_data, 4); crypto1_init(crypto, key); @@ -140,7 +140,7 @@ static bool mf_classic_auth( } tx_rx->tx_rx_type = FuriHalNfcTxRxTypeRaw; tx_rx->tx_bits = 8 * 8; - if(!furi_hal_nfc_tx_rx(tx_rx, 4)) break; + if(!furi_hal_nfc_tx_rx(tx_rx, 5)) break; if(tx_rx->rx_bits == 32) { crypto1_word(crypto, 0, 0); auth_success = true; @@ -220,7 +220,7 @@ bool mf_classic_read_block( tx_rx->tx_bits = 4 * 9; tx_rx->tx_rx_type = FuriHalNfcTxRxTypeRaw; - if(furi_hal_nfc_tx_rx(tx_rx, 4)) { + if(furi_hal_nfc_tx_rx(tx_rx, 5)) { if(tx_rx->rx_bits == 8 * 18) { for(uint8_t i = 0; i < 18; i++) { block->value[i] = crypto1_byte(crypto, 0, 0) ^ tx_rx->rx_data[i];