Skip to content

Conversation

@kevinwallace
Copy link
Contributor

@kevinwallace kevinwallace commented Jun 19, 2022

What's new

  • Fix reading DESFire cards which refuse GET_KEY_SETTINGS
  • Fix saving DESFire cards with 0 applications

Verification

  • Read a DESFire card that refuses GET_KEY_SETTINGS, verify read completes (previously it would FURI_LOG_W in a loop)
  • Save a DESFire card that has no applications, verify card data is saved and no error is shown (previously, card data would be saved but an error would be shown)

A "UniFi Access" card can be used to test both of the above scenarios.

flipper_ui_access

Checklist (For Reviewer)

  • PR has description of feature/bug or link to Confluence/Jira task
  • Description contains actions to verify feature/bugfix
  • I've built this code, uploaded it to the device and verified feature/bugfix

Kevin Wallace added 2 commits June 19, 2022 04:07
Some cards are configured to refuse to provide key settings, but still
provide other info.  For example, Ubiquiti UniFi Protect access cards
won't list keys or applications, but will still answer GET_FREE_MEMORY.
@gornekich
Copy link
Member

gornekich commented Jun 21, 2022

Hello @kevinwallace !
I noticed that after saving card with 0 apps flipper crashes when you try to load that card. Back trace shows that you want to allocate 0 bytes:

#0  __furi_halt () at /home/nikita/localgit/flipperzero-firmware-community/core/furi/check.c:28
#1  0x08001478 in furi_crash (message=message@entry=0x80b3ab0 "furi_check failed\r\n")
    at /home/nikita/localgit/flipperzero-firmware-community/core/furi/check.c:54
#2  0x08002c12 in pvPortMalloc (xWantedSize=<optimized out>, xWantedSize@entry=0)
    at /home/nikita/localgit/flipperzero-firmware-community/core/furi/memmgr_heap.c:480
#3  0x08003662 in malloc (size=size@entry=0) at /home/nikita/localgit/flipperzero-firmware-community/core/furi/memmgr.c:12
#4  0x0804491c in nfc_device_load_mifare_df_data (file=file@entry=0x2000ff80, dev=dev@entry=0x20012248)
    at /home/nikita/localgit/flipperzero-firmware-community/applications/nfc/nfc_device.c:545
#5  0x08044c36 in nfc_device_load_data (dev=dev@entry=0x20012248, path=path@entry=0x200132e0)
    at /home/nikita/localgit/flipperzero-firmware-community/applications/nfc/nfc_device.c:867
#6  0x08044e7a in nfc_file_select (dev=0x20012248) at /home/nikita/localgit/flipperzero-firmware-community/applications/nfc/nfc_device.c:920
#7  0x0803e83c in nfc_scene_file_select_on_enter (context=0x20011d98)
    at /home/nikita/localgit/flipperzero-firmware-community/applications/nfc/scenes/nfc_scene_file_select.c:6
#8  0x08009d6c in scene_manager_next_scene (scene_manager=0x20012020, next_scene_id=next_scene_id@entry=7)

Could you please fix it in this PR?
Looks like we want to add some logic in nfc_device.c:545

Copy link
Member

@gornekich gornekich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add support for loading cards with 0 App count

@kevinwallace
Copy link
Contributor Author

Oops, sorry, I should have caught that! Thanks for the stack trace. Fixed in 1464afd, and verified saving and loading with the card shown in the photo above.

(Also, noted that 0-byte mallocs are unsupported, will avoid those in the future)

@gornekich gornekich self-requested a review June 21, 2022 14:49
Copy link
Member

@gornekich gornekich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@skotopes skotopes merged commit 88facf2 into flipperdevices:dev Jun 21, 2022
@kevinwallace kevinwallace deleted the desfire_unifi branch June 21, 2022 14:58
hedger pushed a commit that referenced this pull request Jun 21, 2022
* nfc: don't give up on reading DESFire card if GET_KEY_SETTINGS fails
  Some cards are configured to refuse to provide key settings, but still
  provide other info.  For example, Ubiquiti UniFi Protect access cards
  won't list keys or applications, but will still answer GET_FREE_MEMORY.
* nfc: don't show error when saving DESFire card with no applications
* nfc: fix DESFire load with 0 applications or no PICC key settings

Co-authored-by: Kevin Wallace <[email protected]>
Co-authored-by: gornekich <[email protected]>
Co-authored-by: あく <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants