FeliCa Emulation: Handle certain Polling commands in firmware (#4204)

* FeliCa: Handle non-hardware Polling commands

NFC TagInfo and possibly other readers rely on Polling commands with Request Code of 1 (default System Code request) or non-FFFF System Code to detect card type. Since the NFC controller doesn't seem to handle them in hardware and simply bubbles them up, and then the Flipper firmware will just ignore them and refuse to respond afterwards, this causes the reading operation to fail.

This commit adds a simple handler for such Polling commands so that readers behaving like NFC TagInfo could read the emulated card without failing.

* Only handle cases when System Code is not FFFF

The NFC controller should handle Polling commands with the System Code set to FFFF, so it's not necessary for the firmware to handle it.

* Remove system code logging

* More cleanups

* Remove the claim that we need a poller change

We already have enough information to determine whether or not the card supports NDEF since SYS_OP register value is included in all current Lite-S card dumps.

* Respond to 12FC polling command when needed

* Handle Polling with NDEF and Lite-S Service Code

This allows the reader to specifically select the service by naming the Service Code.

* Introduce API for manual handling of Polling commands

Introduce nfc_felica_listener_timer_anticol_start() and nfc_felica_listener_timer_anticol_stop(). These are for now just wrappers around the block_tx timer that can be used to delay the response until the desired Time Slot. Thanks to the loose timing constraints of FeliCa collision resolution protocol, no compensation seems to be necessary. Also enabled the block_tx timer for FeliCa listener, but with both compensation and fdt set to 0 to keep the original behavior of not using the timer during normal data exchange.

This API is now being used for handling Polling commands that are not handled by the NFC controller on the hardware side.

* Document target_time_slot

* Implement changes suggested by @RebornedBrain

* api: f18 version sync

* nfc: added stubs for `nfc_felica_listener_timer_anticol` for unit tests

---------

Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
dogtopus
2025-09-24 19:08:40 +09:00
committed by GitHub
parent ad94694fbd
commit dfd753703a
10 changed files with 182 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,86.0,,
Version,+,86.1,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
Header,+,applications/services/cli/cli.h,,
1 entry status name type params
2 Version + 86.0 86.1
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/bt/bt_service/bt_keys_storage.h
5 Header + applications/services/cli/cli.h

View File

@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,86.0,,
Version,+,86.1,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
@@ -2859,6 +2859,8 @@ Function,+,nfc_device_set_data,void,"NfcDevice*, NfcProtocol, const NfcDeviceDat
Function,+,nfc_device_set_loading_callback,void,"NfcDevice*, NfcLoadingCallback, void*"
Function,+,nfc_device_set_uid,_Bool,"NfcDevice*, const uint8_t*, size_t"
Function,+,nfc_felica_listener_set_sensf_res_data,NfcError,"Nfc*, const uint8_t*, const uint8_t, const uint8_t*, const uint8_t, const uint16_t"
Function,+,nfc_felica_listener_timer_anticol_start,void,"Nfc*, uint8_t"
Function,+,nfc_felica_listener_timer_anticol_stop,void,Nfc*
Function,+,nfc_free,void,Nfc*
Function,+,nfc_iso14443a_listener_set_col_res_data,NfcError,"Nfc*, uint8_t*, uint8_t, uint8_t*, uint8_t"
Function,+,nfc_iso14443a_listener_tx_custom_parity,NfcError,"Nfc*, const BitBuffer*"
1 entry status name type params
2 Version + 86.0 86.1
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/bt/bt_service/bt_keys_storage.h
2859 Function + nfc_device_set_loading_callback void NfcDevice*, NfcLoadingCallback, void*
2860 Function + nfc_device_set_uid _Bool NfcDevice*, const uint8_t*, size_t
2861 Function + nfc_felica_listener_set_sensf_res_data NfcError Nfc*, const uint8_t*, const uint8_t, const uint8_t*, const uint8_t, const uint16_t
2862 Function + nfc_felica_listener_timer_anticol_start void Nfc*, uint8_t
2863 Function + nfc_felica_listener_timer_anticol_stop void Nfc*
2864 Function + nfc_free void Nfc*
2865 Function + nfc_iso14443a_listener_set_col_res_data NfcError Nfc*, uint8_t*, uint8_t, uint8_t*, uint8_t
2866 Function + nfc_iso14443a_listener_tx_custom_parity NfcError Nfc*, const BitBuffer*

View File

@@ -1,8 +1,7 @@
#include "furi_hal_nfc_i.h"
#include "furi_hal_nfc_tech_i.h"
// Prevent FDT timer from starting
#define FURI_HAL_NFC_FELICA_LISTENER_FDT_COMP_FC (INT32_MAX)
#define FURI_HAL_NFC_FELICA_LISTENER_FDT_COMP_FC (0)
#define FURI_HAL_FELICA_COMMUNICATION_PERFORMANCE (0x0083U)
#define FURI_HAL_FELICA_RESPONSE_CODE (0x01)