chore(core): export `USE_NFC` from `trezor.utils`
What changed, and why it matters
This is a routine feature-flag plumbing change for an upcoming NFC hardware feature. It exposes a new USE_NFC constant in Python code and disables advertising NFC capability to host software until the NFC driver is considered stable. There is no security bug or vulnerability in the diff.
No security action required. Treat as normal feature-enablement/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds a Cargo feature ‘nfc’ and a C preprocessor define USE_NFC, then propagates that flag into the MicroPython trezorutils module as USE_NFC. It also changes apps/base.py so the device reports Capability.NFC only when USE_NFC is true, replacing a temporary hard-coded internal-model check for ‘T3W1’. The feature is enabled only for the n1w1 (T3W1) firmware build for now, with a TODO comment noting it should move back after driver stabilization. No cryptographic, authentication, or memory-safety code is modified.
Changed components
core/embed/projects/firmware/Cargo.tomlcore/embed/projects/firmware/project.tomlcore/embed/projects/unix/Cargo.tomlcore/embed/upymod/Cargo.tomlcore/embed/upymod/build.rscore/embed/upymod/modtrezorutils/modtrezorutils.ccore/mocks/generated/trezorutils.pyicore/src/apps/base.pycore/src/trezor/utils.pyInspect captured patch +21 / −2
### core/embed/projects/firmware/Cargo.toml
@@ -120,6 +120,7 @@ hash_processor = ["sec/hash_processor"]
iwdg = ["sec/iwdg"]
lockable_bootloader = ["io/lockable_bootloader"]
mcu_attestation = ["sec/mcu_attestation", "upymod/mcu_attestation"]
+nfc = ["io/nfc", "upymod/nfc"]
nrf = ["io/nrf"]
nrf_auth = ["io/nrf_auth"]
optiga = ["sec/optiga", "upymod/optiga", "trezor_lib/optiga"]
### core/embed/projects/firmware/project.toml
@@ -69,7 +69,7 @@ force-bootloader-upgrade = { true = ["force_bootloader_upgrade"] }
frozen = { true = ["frozen"] }
log-stack-usage = { true = ["log_stack_usage"] }
mem-perf = { true = ["memperf"] }
-n1w1 = { true = ["n1w1"] }
+n1w1 = { true = ["n1w1", "nfc"] } # TODO: move back to `uses` section (after stabilization)
perf-overlay = { true = ["ui_performance_overlay"] }
production = { true = ["production"], false = ["dev_keys"] }
pyopt = { true = ["pyopt"], false = ["debug", "optiga_testing", "ui_debug_overlay"] }
### core/embed/projects/unix/Cargo.toml
@@ -37,6 +37,7 @@ log_stack_usage = ["upymod/log_stack_usage"]
memperf = ["upymod/memperf"]
micropy_enable_source_lines = ["upymod/enable_source_lines"]
n1w1 = ["upymod/n1w1"]
+nfc = ["upymod/nfc"]
optiga_testing = ["sec/optiga_testing"]
pyopt = ["upymod/pyopt"]
ui_debug = ["trezor_lib/ui_debug"]
### core/embed/upymod/Cargo.toml
@@ -65,6 +65,7 @@ touch = ["io/touch"]
touch_wakeup = ["io/touch_wakeup"]
tropic = ["sec/tropic"]
universal_fw = ["crypto/universal_fw"]
+nfc = []
# --------------------------------------------------------------------------
# Automatically derived features (do not enable from outside)
### core/embed/upymod/build.rs
@@ -72,6 +72,10 @@ fn main() -> Result<()> {
lib.add_define("USE_N1W1", Some("1"));
}
+ if cfg!(feature = "nfc") {
+ lib.add_define("USE_NFC", Some("1"));
+ }
+
lib.add_define(
"MICROPY_ENABLE_SOURCE_LINE",
Some(if cfg!(feature = "enable_source_lines") {
@@ -950,6 +954,7 @@ impl<'a> MpyBuilder<'a> {
let touch_wakeup = py_bool(cfg!(feature = "touch_wakeup"));
let tropic = py_bool(cfg!(feature = "tropic"));
let scm_revision_xor2 = self.scm_revision_xor2;
+ let nfc = py_bool(cfg!(feature = "nfc"));
let layout_bolt = py_bool(cfg!(feature = "layout_bolt"));
let layout_caesar = py_bool(cfg!(feature = "layout_caesar"));
@@ -973,6 +978,7 @@ impl<'a> MpyBuilder<'a> {
format!(r"s/utils\.USE_TOUCH_WAKEUP/{touch_wakeup}/g"), // must be before USE_TOUCH
format!(r"s/utils\.USE_TOUCH/{touch}/g"),
format!(r"s/utils\.USE_TROPIC/{tropic}/g"),
+ format!(r"s/utils\.USE_NFC/{nfc}/g"),
format!(r"s/utils\.SCM_REVISION_XOR2/{scm_revision_xor2}/g"),
format!(r#"s/utils\.UI_LAYOUT == "BOLT"/{layout_bolt}/g"#),
format!(r#"s/utils\.UI_LAYOUT == "CAESAR"/{layout_caesar}/g"#),
### core/embed/upymod/modtrezorutils/modtrezorutils.c
@@ -814,6 +814,8 @@ static const mp_obj_tuple_t mod_trezorutils_version_obj = {
/// """Firmware version as a tuple (major, minor, patch, build)."""
/// USE_BLE: bool
/// """Whether the hardware supports BLE."""
+/// USE_NFC: bool
+/// """Whether the hardware supports NFC."""
/// USE_SD_CARD: bool
/// """Whether the hardware supports SD card."""
/// USE_SERIAL_NUMBER: bool
@@ -1011,6 +1013,11 @@ static const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
#else
{MP_ROM_QSTR(MP_QSTR_USE_BLE), mp_const_false},
#endif
+#ifdef USE_NFC
+ {MP_ROM_QSTR(MP_QSTR_USE_NFC), mp_const_true},
+#else
+ {MP_ROM_QSTR(MP_QSTR_USE_NFC), mp_const_false},
+#endif
#ifdef USE_BACKLIGHT
{MP_ROM_QSTR(MP_QSTR_USE_BACKLIGHT), mp_const_true},
#else
### core/mocks/generated/trezorutils.pyi
@@ -256,6 +256,8 @@ VERSION: VersionTuple
"""Firmware version as a tuple (major, minor, patch, build)."""
USE_BLE: bool
"""Whether the hardware supports BLE."""
+USE_NFC: bool
+"""Whether the hardware supports NFC."""
USE_SD_CARD: bool
"""Whether the hardware supports SD card."""
USE_SERIAL_NUMBER: bool
### core/src/apps/base.py
@@ -166,7 +166,7 @@ def get_features() -> Features:
if utils.USE_BLE:
f.capabilities.append(Capability.BLE)
- if utils.INTERNAL_MODEL == "T3W1": # TODO utils.USE_NFC
+ if utils.USE_NFC:
f.capabilities.append(Capability.NFC)
if utils.USE_N1W1:
### core/src/trezor/utils.py
@@ -29,6 +29,7 @@
USE_HAPTIC,
USE_MCU_ATTESTATION,
USE_N1W1,
+ USE_NFC,
USE_NRF,
USE_OPTIGA,
USE_POWER_MANAGER,Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.