Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ee8b328
feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 5, 2026
22206f3
feat(nfc): move NFC discovery parameters to const structure
ludekfarsky-star Jun 3, 2026
3fc7bef
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
0af40d5
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
aab1e04
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
8e3a9b3
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
31c7656
fixup! feat(nfc): move NFC discovery parameters to const structure
ludekfarsky-star Jun 18, 2026
fd7e741
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
6807212
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
3e3ceb2
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
da1e1b2
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 18, 2026
bff6414
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 19, 2026
0066705
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 22, 2026
67bb665
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 26, 2026
d208302
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 26, 2026
27c9685
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 26, 2026
f37d56f
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 26, 2026
b35a061
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 26, 2026
090d7de
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 26, 2026
2dab336
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 29, 2026
f318efa
fixup! feat(nfc): enable polling the NFC in the sysevent loop
ludekfarsky-star Jun 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/embed/io/nfc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn def_module(lib: &mut CLibrary) -> Result<()> {
lib.add_sources_with_attrs(
[
"nfc/st25/nfc.c",
"nfc/st25/nfc_poll.c",
"nfc/st25/ndef.c",
"nfc/st25/card_emulation.c",
"nfc/st25/rfal002/source/st25r3916/rfal_rfst25r3916.c",
Expand Down
99 changes: 48 additions & 51 deletions core/embed/io/nfc/inc/io/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,76 +24,73 @@
#define NFC_MAX_UID_LEN 10
#define NFC_MAX_UID_BUF_SIZE ((NFC_MAX_UID_LEN + 1) * 2)

typedef enum {
NFC_POLLER_TECH_A = 0x1,
NFC_POLLER_TECH_B = 0x1 << 1,
NFC_POLLER_TECH_F = 0x1 << 2,
NFC_POLLER_TECH_V = 0x1 << 3,
NFC_CARD_EMU_TECH_A = 0x1 << 4,
NFC_CARD_EMU_TECH_F = 0x1 << 5,
} nfc_tech_t;

/** @brief Supported NFC types. **/
typedef enum {
NFC_DEV_TYPE_A,
NFC_DEV_TYPE_B,
NFC_DEV_TYPE_F,
NFC_DEV_TYPE_V,
NFC_DEV_TYPE_ST25TB,
NFC_DEV_TYPE_AP2P,
NFC_DEV_TYPE_UNKNOWN,
} nfc_dev_type_t;

/** @brief NFC interface */
typedef enum {
NFC_NO_EVENT,
NFC_EVENT_DEACTIVATED,
NFC_EVENT_ACTIVATED,
} nfc_event_t;
NFC_DEV_INTERFACE_RF,
NFC_DEV_INTERFACE_ISODEP,
NFC_DEV_INTERFACE_NFCDEP,
NFC_DEV_INTERFACE_UNKNOWN,
} nfc_dev_interface_t;

/** @brief NFC poll events */
typedef enum {
NFC_OK,
NFC_ERROR,
NFC_NOT_INITIALIZED,
NFC_SPI_BUS_ERROR,
NFC_INITIALIZATION_FAILED,
} nfc_status_t;
NFC_NO_EVENT = 0,
NFC_EVENT_CONNECTED,
NFC_EVENT_DISCONNECTED,
} nfc_event_t;

/** @brief NFC card details */
typedef struct {
uint8_t type;
char uid[NFC_MAX_UID_BUF_SIZE]; // Plus one for string termination
nfc_dev_type_t type; //!< NFC card type
nfc_dev_interface_t interface; //!< NFC card interface
char uid[NFC_MAX_UID_BUF_SIZE]; //!< Card UID string
uint8_t uid_len;
} nfc_dev_info_t;

// Initialize NFC driver including supportive RFAL middleware
nfc_status_t nfc_init(void);
/** @brief NFC APDU command buffer structure */
typedef struct {
const uint8_t *data;
uint16_t data_len;
} nfc_apdu_cmd_t;

// Deinitialize NFC driver
void nfc_deinit(void);
/** @brief NFC APDU response buffer pointers */
typedef struct {
uint8_t **data;
uint16_t **data_len;
} nfc_apdu_response_t;

// Register NFC technology (or several) to be explored by NFC state machine
// use this function before activating the state machine with nfc_activate_stm()
nfc_status_t nfc_register_tech(const nfc_tech_t tech);
/** @brief Initialize NFC driver including supportive
RFAL middleware and polling mechanism. */
ts_t nfc_init(void);

// Activates the NFC RFAL state machine to explore the previously registered
// technologies. The RFAL handles low-level NFC protocols and provides
// information about the activated device. This function only starts the
// exploration; you must regularly call nfc_get_event() to continue processing
// NFC operations.
nfc_status_t nfc_activate_stm(void);
/** @brief Deinitialize NFC driver. */
void nfc_deinit(void);

// Deactivate the NFC RFAL state machine (put in IDLE state).
nfc_status_t nfc_deactivate_stm(void);
/**
* @brief Activates the NFC RFAL state machine to explore the previously
* registered technologies. The RFAL handles low-level NFC protocols and
* provides information about the activated device. This function only starts
* the exploration; you must regularly call nfc_get_event() to continue
* processing NFC operations.
*/
ts_t nfc_start_discovery(void);

// Calls NFC RFAL worker to service the NFC state machine and expolore
// registered technologies. This function has to be actively called in loop
// (main NFC poll function), returns nfc event.
nfc_status_t nfc_get_event(nfc_event_t *event);
/** @brief Deactivate the NFC RFAL state machine (put in IDLE state). */
ts_t nfc_stop_discovery(void);

// Deactivate the currently activated NFC device and put RFAL state machine back
// to discovary state.
nfc_status_t nfc_dev_deactivate(void);
/** @brief Get current events of NFC device. */
bool nfc_get_event(nfc_event_t *event);

// Read the general device information of the activated NFC device.
nfc_status_t nfc_dev_read_info(nfc_dev_info_t *dev_info);
/** @brief Read the general device information of the activated NFC device. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also add parameters and return value context into the doc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed e1aa816

ts_t nfc_dev_read_info(nfc_dev_info_t *dev_info);

// Write the NDEF message with the trezor.io URI to the activated NFC device.
nfc_status_t nfc_dev_write_ndef_uri(void);
/** @brief Transceive data with the activated NFC device. This is a blocking
* call. */
ts_t nfc_transceive(const nfc_apdu_cmd_t cmd, nfc_apdu_response_t resp);
Loading