Skip to content

ISO-DEP timeout overrides and configurable NFC-A RATS FSDI/CID #5

Closed

Description

@Sped0n

Context

Hi, I am an engineer from Espressif working on an Aliro-related project with M5NanoC6 + Unit NFC.

While debugging larger Aliro ISO-DEP exchanges, I found two lower-level issues and opened PRs for them:

Those are small bug fixes. While this issue is for discussing two follow-up API needs before opening more PRs.

1. Per-exchange ISO-DEP timeout override

Some ISO-DEP applications have command-specific processing time longer than the default ATS-derived FWT. In our case, some Aliro commands can take longer because of certificate/crypto processing.
It would be useful to support per-exchange timeout options, for example:

  • override initial fwt_ms for one transceiveINF()
  • override wtx_max_ms
  • optionally disable/reduce retries for non-idempotent commands

This avoids changing global ISO-DEP config mid-session and avoids resetting block-number state.

2. Configurable NFC-A RATS FSDI/CID

Current higher-level NFC-A activation sends RATS internally with default parameters. For some ISO-DEP applications, the caller may want to request a larger FSDI, e.g. FSDI=8, or specify CID.

A possible API shape could be an activation options struct:

struct activation_options_t {
    bool force_rats{};
    uint8_t fsdi{5};
    uint8_t cid{};
};
bool select(m5::nfc::a::PICC& picc, const activation_options_t& options);
bool activate(const m5::nfc::a::PICC& picc, const activation_options_t& options);
bool reactivate(const m5::nfc::a::PICC& picc, const activation_options_t& options);

Existing APIs can remain unchanged and call through with default options.

Question

Would you be open to these API additions? If yes, I can split them into two small PRs:

  1. Add per-exchange ISO-DEP timeout options.
  2. Make NFC-A RATS FSDI/CID configurable during activation.

Activity

  1. GOB52 commented on May 21, 2026

    @GOB52
    Contributor

    I'm currently investigating and reviewing the matter.
    I have other tasks to attend to, so I can’t respond right away, but please bear with me for a moment.

  2. Sped0n commented on May 21, 2026

    @Sped0n
    ContributorAuthor

    also is it possible to take a look at m5stack/M5UnitUnified#1

    huge thanks!

  3. GOB52 commented on May 22, 2026

    @GOB52
    Contributor

    Thanks for the detailed proposal — both additions are implemented and now on develop (will ship in the next release).

    1. Per-exchange ISO-DEP timeout/retry override

    A policy_t can be passed per call to transceiveINF / transceiveAPDU (nullptr = use the session config). It does not change the session config and does not reset the block number:

    namespace m5::nfc::isodep {
    struct policy_t {
        uint32_t fwt_ms{};      //!< Frame waiting time (ms). 0 is clamped to 1 internally
        uint32_t wtx_max_ms{};  //!< Upper bound for WTX extension (ms)
        uint8_t max_retries{};  //!< Number of resends (0 = no resend)
    };
    }
    
    bool IsoDEP::transceiveINF (..., RxInfo* info = nullptr, const policy_t* override_policy = nullptr);
    bool IsoDEP::transceiveAPDU(..., const policy_t* override_policy = nullptr);
    auto* dep = nfc_a.isoDEP();                    // nfc_b.isoDEP() too -- shared ISO-DEP layer
    m5::nfc::isodep::policy_t p{2000, 8000, 0};    // long fwt, no retry (non-idempotent command)
    dep->transceiveAPDU(rx, rx_len, cmd, len, &p);

    This covers the per-exchange fwt_ms / wtx_max_ms override and max_retries = 0 for non-idempotent commands, without touching the global config or block-number state. It works for both NFC-A and NFC-B via the shared ISO-DEP layer.

    2. Configurable NFC-A RATS FSDI/CID

    Instead of new activate(...) overloads, this is a layer-level config set once before activation -- the select / activate / reactivate signatures are unchanged:

    namespace m5::nfc::a {
    struct config_t {
        uint8_t fsdi{5};  // 0..8 (16..256 bytes)
        uint8_t cid{0};   // 0..14
    };
    }
    
    m5::nfc::a::config_t NFCLayerA::config() const;
    void                 NFCLayerA::config(const config_t& cfg);  // fsdi clamped [0,8], cid [0,14]
    auto c = layerA.config();
    c.fsdi = 8;
    c.cid  = 3;
    layerA.config(c);
    layerA.activate(picc);   // RATS now sent with FSDI=8, CID=3

    Internally nfca_request_ats() builds the RATS PARAM byte as (FSDI << 4) | CID from these values; reactivate() inherits via activate(). We chose a layer config (set once) over per-call activation options because FSDI/CID are PCD-side, fairly static settings, and this keeps the activation API unchanged.


    Both were verified on hardware (Core / M5NanoC6 / NessoN1 / CapCC1101, I2C & SPI) with DESFire / MIFARE Plus / ST25TA and an NFC-B card. There's also a new examples/UnitUnified/NFCA/PolicyOverride demonstrating the timeout override.

    Thanks again, and for #3 (merged).

  4. Sped0n commented on May 22, 2026

    @Sped0n
    ContributorAuthor

    will ship in the next release

    Can you also help rebase the feat/esp-idf-native-support branch at that time? (It would be best if the ESP-IDF native support branch can be merged to main at the same time, but you can always take your time.)

    Thanks!

  5. GOB52 commented on May 22, 2026

    @GOB52
    Contributor

    Native esp-idf support was originally scheduled to be implemented alongside the M5HAL update.

    If this is essential for your project, we will consider merging esp-idf support for M5UnitUnified, M5Utility, M5HAL, and M5Unit-NFC into the main branch ahead of schedule.

  6. Sped0n commented on May 22, 2026

    @Sped0n
    ContributorAuthor

    If this is essential for your project, we will consider merging esp-idf support for M5UnitUnified, M5Utility, M5HAL, and M5Unit-NFC into the main branch ahead of schedule.

    This couldn't be better!

    Our plan to release Aliro SDK and examples is around first week of June, but it is not like a hard requirement for you guys, seeing things are moving forward is enough.

  7. Sped0n commented on May 25, 2026

    @Sped0n
    ContributorAuthor

    is it possible to sync changes in #4 (comment) to the feat/esp-idf-native-support branch, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions