Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFC refactoring #2529

Closed
wants to merge 152 commits into from
Closed

NFC refactoring #2529

wants to merge 152 commits into from

Conversation

gornekich
Copy link
Member

What's new

  • [ Describe changes here ]

Verification

  • [ Describe how to verify changes ]

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

@gornekich gornekich marked this pull request as draft March 23, 2023 12:45
@github-actions
Copy link

github-actions bot commented Mar 23, 2023

Compiled firmware for commit d1385d18:

@github-actions
Copy link

github-actions bot commented Mar 23, 2023

PVS-Studio report for commit 51ced8af:

@hedger hedger added NFC NFC-related Core+Services HAL, furi & core system services labels Mar 29, 2023
gornekich and others added 8 commits July 18, 2023 17:04
…t cards (#2905)

* Added new scene for Mifare Ultralight

This scene will show a full card dump

* Replaced 'NotImplemented' scene with new 'CardDump' scene

* Moved card_dump scene logic to protocol support

* Added CardDump handlers for Ultralight cards

* Ultralight data format function added

* Implemented _on_event handler for CardDump
* Field scene added

* Moved 'Debug' scene implementation into protocol support layer

* Menu index for Field item added

* Set proper scene and submenu index for 'Debug' button

* Fixed issue when returning from 'Add Manually' screen

Previously wrong menu item ('Read') was selected when returning from  'Add Manually', now it returns back properly

* Revert "Moved 'Debug' scene implementation into protocol support layer"

This reverts commit f739387.

* Removed 'Adu' menu item

* 'Field' button now points to a proper scene

* Revert "Menu index for Field item added"

This reverts commit ab73494.
* Add boilerplate code for ISO14443-4B

* Add boilerplate code for ISO14443-3B gui support

* Partially working ISO14443-3B activation

* Slightly better error handling

* Testing NFC-B

* More changes for NFC-B

* Working NFC-B configuration

* Rearrange f_hal_nfc code

* Prettify info output

* Improve iso-3 poller api

* Working NFC-B activation procedure

* Implement saving & loading of NFC-B tags

* Remove crc calculation from iso14443-3b definition

* Remove crc calculation from iso14443-3a definition, add api headers

* Update NfcFileFormats.md

* Add set_uid method

* Load UID inside nfc_device

* Temporarily disable UID editing for NFC-B
* Restore original confirm scene added

* Menu item and handler added

* Restore done scene added

* "Restore Data Changes" will be shown only when shadow file exists

* Added nfc_delete_shadow_file to internal API defines

* nfc_delete_shadow_file adjustments

Now function sets shadow file name internaly before trying to delete

* Update nfc_scene_restore_original_confirm.c

Now different scene will be shown depending on the result of nfc_delete_shadow_file. 
When true  it will go to success screen, otherwise to start screen.

* nfc_set_shadow_file_path now checks if path already point to .shd file

* Implemented logic of saving card data to shadow file

* Reload card after restoration

Now we perfrom nfc card reloading and depending on the result we show 'SavedMenu' if reload was successful or 'FileSelect' scene in other case

* Moved file_path adjustments from scene to nfc_load_file

Now nfc_load_file checks when there is no shadow file but path points to .shd file, then it replaces extension to .nfc
* Add initial ISO15693-3 support (load and save)

* ISO15693-3 poller skeleton implementation

* NFC chip configuration for NFC-V

* Improve NFC-V chip configuration

* Almost working NFC-B card activation

* Implement system info

* Working NFC-V poller

* Read block security as well

* Refactor NFC-V code

* Improve NFC-V file loading and saving

* Improve NFC-V poller code

* Improve NFC-V error handling

* Finished NFC-V poller implementation

* Improve NFC-V poller states and function names

* Better equality method for NFC-V

* Minor fixes
gornekich and others added 17 commits August 9, 2023 14:48
* nfc: introduce felica support

* nfc: felica chip configuration

* felica: fix chip configuration

* felica: working poller

* nfc: return registers to default values

* nfc scanner: detect multiple technologies

* felica: fix polling cmd parser

* nfc: clean up

* felica: more clean up

* felica: add UID related comments
* Update nfc.c, iso14443_3a_listener.c, and mf_ultralight_listener.c

Added more logging

* Removed a lot of unnecessary logs to comply timings

* Poller adjusted to read single tearing flag for NTAGs

* Fix for proper saving of tear flags

* CHECK_TEARING_CMD support for NTAGs

According to datasheet NTAG21x don't support this command, but some of them do. Only 02 flag works (3E02), so now tearing command checks if SingleCounter feature is supported by the card, then it can be treated as NTAGxx and only flag=2 can be read

* Duplicated gpio call removed

* Added TODO for future work

* Fix MF Classic emulation
* Update nfc.c, iso14443_3a_listener.c, and mf_ultralight_listener.c

Added more logging

* Removed a lot of unnecessary logs to comply timings

* Poller adjusted to read single tearing flag for NTAGs

* Fix for proper saving of tear flags

* CHECK_TEARING_CMD support for NTAGs

According to datasheet NTAG21x don't support this command, but some of them do. Only 02 flag works (3E02), so now tearing command checks if SingleCounter feature is supported by the card, then it can be treated as NTAGxx and only flag=2 can be read

* Duplicated gpio call removed

* Added TODO for future work

* Fix MF Classic emulation

* Function mf_ultralight_support_feature added to API

This function checks whether current Ultralight instance supports feature, mentioned as a second paramete.

* Adjusted listener and poller with new function and removed some nesting
* Update nfc.c, iso14443_3a_listener.c, and mf_ultralight_listener.c

Added more logging

* Removed a lot of unnecessary logs to comply timings

* Poller adjusted to read single tearing flag for NTAGs

* Fix for proper saving of tear flags

* CHECK_TEARING_CMD support for NTAGs

According to datasheet NTAG21x don't support this command, but some of them do. Only 02 flag works (3E02), so now tearing command checks if SingleCounter feature is supported by the card, then it can be treated as NTAGxx and only flag=2 can be read

* Duplicated gpio call removed

* Added TODO for future work

* Fix MF Classic emulation

* Function mf_ultralight_support_feature added to API

This function checks whether current Ultralight instance supports feature, mentioned as a second paramete.

* Adjusted listener and poller with new function and removed some nesting

* NFC layer adjustments

Changed function call from f_hal_nfc_listener_sleep to nfc_listener_sleep for Field Off event
Added new event FHalNfcEventTxEnd where trasmitter state is now changed
Reset after rx command processing is now done only when we don't send anything

* iso14443_3a_listener cleanup to avoid duplicate calls and race conditions

* Added result statuses for mfu commands and command signature changed, now it returns status instead of bool

* mf_ultralight_listener_run adjusted to process statuses

* Comments adjusted according bits set

* Renamed enum type and values
* Update nfc.c, iso14443_3a_listener.c, and mf_ultralight_listener.c

Added more logging

* Removed a lot of unnecessary logs to comply timings

* Poller adjusted to read single tearing flag for NTAGs

* Fix for proper saving of tear flags

* CHECK_TEARING_CMD support for NTAGs

According to datasheet NTAG21x don't support this command, but some of them do. Only 02 flag works (3E02), so now tearing command checks if SingleCounter feature is supported by the card, then it can be treated as NTAGxx and only flag=2 can be read

* Duplicated gpio call removed

* Added TODO for future work

* Fix MF Classic emulation

* Function mf_ultralight_support_feature added to API

This function checks whether current Ultralight instance supports feature, mentioned as a second paramete.

* Adjusted listener and poller with new function and removed some nesting

* NFC layer adjustments

Changed function call from f_hal_nfc_listener_sleep to nfc_listener_sleep for Field Off event
Added new event FHalNfcEventTxEnd where trasmitter state is now changed
Reset after rx command processing is now done only when we don't send anything

* iso14443_3a_listener cleanup to avoid duplicate calls and race conditions

* Added result statuses for mfu commands and command signature changed, now it returns status instead of bool

* mf_ultralight_listener_run adjusted to process statuses

* Comments adjusted according bits set

* Renamed enum type and values

* Command adjustments

Cleaned up all commands. Read and write commands send their NAKs according to status

* f_hal_nfc_listener_tx is now blocking
* Implement basic boilerplate for NFC-V listener

* Improve listener boilerplate

* Better separation between various NFC technologies

* Correct formatting

* Some minor code improvements

* Re-add f_hal_event_start()

* Implement basic framework for transparent mode

* Implement transparent mode rx for NFC-V

* Receiving bytes from reader

* Refine chip NFC-V configuration

* Implement sending via NFC-V listener

* Improve Iso15693Signal code

* Add support for low and high data rates

* Port Iso15693Signal to DigitalSequence

* Rearrange some code

* Minimal INVENTORY emulation

* Minimal GET_SYSTEM_INFO emulation

* Minor NFC-V improvements

* Improve error and flag handling

* Improve command handlers (draft)

* Improve command handlers (final)

* Add STAY_QUIET command

* Add WRITE_BLOCK command

* Add several NFC-V commands

* Add multi read and write

* Add LOCK_BLOCK command

* Add GET_SECURITY command

* Select command handlers from array

* Implement all of the commands (draft)

* Simplify NFC-V request handling

* Change GUI emulation logic for NFC-V

* Implement single EOF handling

* Rework nfcv signal reception (#2998)

* nfc: add wait event methos

* lib: introduce signal reader library

* nfc hal: rework iso15 listener

* nfc hal: rework iso 15 reception with signal reader

* signal reader: don't enable disable dmamux

* lib: move bit buffer to toolbox

* signal reader: add polarity config

* nfc: rework iso15 frame parser

* nfc hal: rework internal events handling

* nfc: move iso15 parser to libs

* nfc iso15693: move poller encoder and decoder to hal

* iso15 parser: check bytes to process

* iso15: fix first eof detect

* iso15 parser: decrease sampling buffer size

* nfc: fix naming

---------

Co-authored-by: gornekich <[email protected]>
…3001)

* Adjusted READ_CNT function to check nfc_cnt_en for NTAG

* INCR_CNT command added for Ultralight

* IncrValue is now taken using MfUltralightCounter union
* nfc: introduce user dict for simplier modifying

* nfc app: add mfc keys scene

* nfc app: add mf classic keys list scene

* nfc: implement user dict delete scene

* nfc tests: add mf dict tests

* mf classic: fix dict attack

* mfc: update card start

* mfc: introduce new MfClassicKeyCache

* nfc app: correct scene switches

* nfc: fix key cache reading

* nfc app: add write and update scenes

* nfc app: rework mfc update

* nfc app: rework mfc write to initial card

* nfc app: introduce plaintain plugin

* mf classic: rework write state machine

* mfc: rework generic card detected and lost events

* nfc: mfc update initial fixes

* mf classic: add read with keys to sync api

* mf classic: rework dict attack

* nfc app: new dict attack

* mfc: rework dict attack view

* mfc: fix incorrect key byte order

* nfc: fix card detect and loss

* nfc: fix mf dict reopen

* mf classic: rework read state machine

* nfc plugins: rework troika parser

* nfc plugins: rework plaintain parser

* mfc: fix block type, mfc detection

* nfc: fix all plugins

* nfc: add todo for key cache handilng
* Update nfc.c, iso14443_3a_listener.c, and mf_ultralight_listener.c

Added more logging

* Removed a lot of unnecessary logs to comply timings

* Poller adjusted to read single tearing flag for NTAGs

* Fix for proper saving of tear flags

* CHECK_TEARING_CMD support for NTAGs

According to datasheet NTAG21x don't support this command, but some of them do. Only 02 flag works (3E02), so now tearing command checks if SingleCounter feature is supported by the card, then it can be treated as NTAGxx and only flag=2 can be read

* Duplicated gpio call removed

* Added TODO for future work

* Fix MF Classic emulation

* Function mf_ultralight_support_feature added to API

This function checks whether current Ultralight instance supports feature, mentioned as a second paramete.

* Adjusted listener and poller with new function and removed some nesting

* NFC layer adjustments

Changed function call from f_hal_nfc_listener_sleep to nfc_listener_sleep for Field Off event
Added new event FHalNfcEventTxEnd where trasmitter state is now changed
Reset after rx command processing is now done only when we don't send anything

* iso14443_3a_listener cleanup to avoid duplicate calls and race conditions

* Added result statuses for mfu commands and command signature changed, now it returns status instead of bool

* mf_ultralight_listener_run adjusted to process statuses

* Comments adjusted according bits set

* Renamed enum type and values

* Command adjustments

Cleaned up all commands. Read and write commands send their NAKs according to status

* f_hal_nfc_listener_tx is now blocking

* Adjusted READ_CNT function to check nfc_cnt_en for NTAG

* INCR_CNT command added for Ultralight

* IncrValue is now taken using MfUltralightCounter union

* Update api_symbols.csv

* New  struct for mirror mode added

* Mirror mode implementation added

* Moved mirror implementation to a separate file mf_ultralight_listener_i.c

* Adjustments according to PR comments
* signal reader: add trigger config

* nfc: remove old cli commands

* nfc: setup test bench

* signal reader: working trigger

* iso15 parser: more optimization

* iso15: add profiling

* iso15 parser: config signal reader trigger

* iso15 parser: more optimizations

* nfc: remove profiling

* iso15 parser: fix incorrect single eof handling

* iso15 hal: code clean up
* nfc hal: move listener start to iso14 config

* nfc hal: don't exit from transparent mode in iso15 emulation
* Added callback on FieldOff event from 14443 to mfu

* Moved command enum and callback type to _i.h file

* Added context for composite command to mfu_listener

* Functions for composite commands processing added

* Composite commands processing logic added

* Added COMP_WRITE command implementation

* Patch with some fixes
* nfc: rework bit buffer to save parity in packed format

* nfc: rework protocol data allocation for listeners

* nfc: rework data allocation in generic listener

* nfc device: rework get data
* Added callback on FieldOff event from 14443 to mfu

* Moved command enum and callback type to _i.h file

* Added context for composite command to mfu_listener

* Functions for composite commands processing added

* Composite commands processing logic added

* Added COMP_WRITE command implementation

* Patch with some fixes

* New mfu command result added for composite commands

* Added variable for storing sector for SECTOR_SELECT cmd

* Implemented proper way of reset for composite cmds

* SECTOR_SELECT implementation added

* Adjust naming for PR

* Update api_symbols.csv, nfc.h, and mf_ultralight_listener.c
* Implement basic SLIX protocol support (Save and Load)

* Implement SLIX listener skeleton code

* Implement SLIX NXP sysinfo and read signature

* Implement SLIX protocol detection

* Implement SLIX poller

* Improve SLIX file handling

* Add SLIX command defines

* Implement listener RANDOM_VALUE command

* Simplify request handlers code

* Implement listener ENABLE_PRIVACY command

* Simplify handler code

* Simplify request handlers code once more

* Refactor SLIX code, add SET_PASSWORD

* Implement listener WRITE_PASSWORD command

* Implement handler override via handler table

* Improve ISO15693 parser error handlng

* Improve ISO standard command override API

* Cleanup ISO15693 listener code

* Remove unused code

* Improve Slix password handling

* Improve SLIX api

* Do not answer any requests after an incorrect password

* Implement standard command overrides for SLIX

* Improve SLIX overrides

* Unify SLIX request handlers into a table

* Do not allocate data inside slix listener

* Improve method naming

* Simplify SLIX protocol data structures

* Fix logical error

* Improve lock bits handling for ISO15693-3 and SLIX

* Implement PROTECT_PAGE command

* Improve SLIX lock bits handling

* Implement SLIX counter feature

* Update comment

* Update comment once more

* Improve SLIX and ISO15693-3 rendering

* Minor rendering changes

---------

Co-authored-by: gornekich <[email protected]>
* nfc hal: remove unused functions

* nfc: remove nfc_sleep from public API

* nfc: rename technology specific API

* nfc hal: move col res disable to nfca specific hal

* nfc: store mode in nfc instance

* nfc: common start and stop

* nfc hal: deinit iso14443a poller

* nfc app: fix detect reader craches

* mf classic: change detect algorythm

* nfc hal: make sleep virtual

* nfc: make it compile

* nfc: introduce NfcSleep command

* nfc: fix naming

* nfc: check nfc hal mutex
@gornekich gornekich closed this Sep 8, 2023
@cptpiepmatz
Copy link

Why is this closed now?

@skotopes
Copy link
Member

skotopes commented Sep 8, 2023

@cptpiepmatz #3050

@gornekich gornekich deleted the gornek/nfc_refactoring branch September 26, 2023 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core+Services HAL, furi & core system services NFC NFC-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants