mirror of
https://github.com/trezor/trezor-firmware.git
synced 2026-02-20 00:33:30 +01:00
feat(core): allow reading out of telemetry data
[no changelog]
This commit is contained in:
@@ -67,6 +67,7 @@ FEATURES_WANTED = [
|
||||
"serial_number",
|
||||
"storage",
|
||||
"suspend",
|
||||
'telemetry',
|
||||
"tropic",
|
||||
"usb",
|
||||
"usb_iface_wire",
|
||||
@@ -748,6 +749,8 @@ if FROZEN:
|
||||
))
|
||||
)
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
|
||||
if 'telemetry' in FEATURES_AVAILABLE:
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/telemetry/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/*.py'))
|
||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/*/*.py',
|
||||
exclude=[
|
||||
|
||||
@@ -54,6 +54,7 @@ smp = []
|
||||
tropic = []
|
||||
serial_number = []
|
||||
storage = []
|
||||
telemetry = []
|
||||
translations = ["crypto"]
|
||||
secmon_layout = []
|
||||
dbg_console = []
|
||||
|
||||
@@ -46,6 +46,10 @@
|
||||
#include "blake2s.h"
|
||||
#include "memzero.h"
|
||||
|
||||
#ifdef USE_TELEMETRY
|
||||
#include <sec/telemetry.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_BLE
|
||||
#include <io/ble.h>
|
||||
#endif
|
||||
@@ -63,6 +67,30 @@
|
||||
|
||||
/// from trezor import utils
|
||||
|
||||
#ifdef USE_TELEMETRY
|
||||
/// def telemetry_get() -> tuple[int, int, int] | None:
|
||||
/// """
|
||||
/// Retrieves the stored telemetry data. Returns a tuple
|
||||
/// (min_temp_milli_c, max_temp_milli_c, battery_errors)
|
||||
/// or None if telemetry is not available.
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorutils_telemetry_get(void) {
|
||||
telemetry_data_t data;
|
||||
if (!telemetry_get(&data)) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t tuple[3];
|
||||
tuple[0] = mp_obj_new_int((int32_t)(data.min_temp_c * 1000.0f));
|
||||
tuple[1] = mp_obj_new_int((int32_t)(data.max_temp_c * 1000.0f));
|
||||
tuple[2] = mp_obj_new_int(data.battery_errors.all);
|
||||
|
||||
return mp_obj_new_tuple(3, tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorutils_telemetry_get_obj,
|
||||
mod_trezorutils_telemetry_get);
|
||||
#endif
|
||||
|
||||
/// def consteq(sec: AnyBytes, pub: AnyBytes) -> bool:
|
||||
/// """
|
||||
/// Compares the private information in `sec` with public, user-provided
|
||||
@@ -763,6 +791,8 @@ STATIC const mp_obj_tuple_t mod_trezorutils_version_obj = {
|
||||
/// """Whether a debug console is enabled."""
|
||||
/// USE_APP_LOADING: bool
|
||||
/// """Whether the firmware supports loading 3rd-party applications."""
|
||||
/// USE_TELEMETRY: bool
|
||||
/// """Whether a telemetry is supported."""
|
||||
/// MODEL: str
|
||||
/// """Model name."""
|
||||
/// MODEL_FULL_NAME: str
|
||||
@@ -831,6 +861,13 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
|
||||
MP_ROM_PTR(&mod_trezorutils_bootloader_locked_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_notify_send),
|
||||
MP_ROM_PTR(&mod_trezorutils_notify_send_obj)},
|
||||
#ifdef USE_TELEMETRY
|
||||
{MP_ROM_QSTR(MP_QSTR_telemetry_get),
|
||||
MP_ROM_PTR(&mod_trezorutils_telemetry_get_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_USE_TELEMETRY), mp_const_true},
|
||||
#else
|
||||
{MP_ROM_QSTR(MP_QSTR_USE_TELEMETRY), mp_const_false},
|
||||
#endif
|
||||
{MP_ROM_QSTR(MP_QSTR_NOTIFY_BOOT), MP_ROM_INT(NOTIFY_BOOT)},
|
||||
{MP_ROM_QSTR(MP_QSTR_NOTIFY_UNLOCK), MP_ROM_INT(NOTIFY_UNLOCK)},
|
||||
{MP_ROM_QSTR(MP_QSTR_NOTIFY_LOCK), MP_ROM_INT(NOTIFY_LOCK)},
|
||||
|
||||
@@ -10,6 +10,15 @@ def meminfo(filename: str | None) -> None:
|
||||
from trezor import utils
|
||||
|
||||
|
||||
# upymod/modtrezorutils/modtrezorutils.c
|
||||
def telemetry_get() -> tuple[int, int, int] | None:
|
||||
"""
|
||||
Retrieves the stored telemetry data. Returns a tuple
|
||||
(min_temp_milli_c, max_temp_milli_c, battery_errors)
|
||||
or None if telemetry is not available.
|
||||
"""
|
||||
|
||||
|
||||
# upymod/modtrezorutils/modtrezorutils.c
|
||||
def consteq(sec: AnyBytes, pub: AnyBytes) -> bool:
|
||||
"""
|
||||
@@ -268,6 +277,8 @@ USE_DBG_CONSOLE: bool
|
||||
"""Whether a debug console is enabled."""
|
||||
USE_APP_LOADING: bool
|
||||
"""Whether the firmware supports loading 3rd-party applications."""
|
||||
USE_TELEMETRY: bool
|
||||
"""Whether a telemetry is supported."""
|
||||
MODEL: str
|
||||
"""Model name."""
|
||||
MODEL_FULL_NAME: str
|
||||
|
||||
@@ -241,6 +241,7 @@ def configure(
|
||||
sources += ["embed/sec/telemetry/telemetry.c"]
|
||||
paths += ["embed/sec/telemetry/inc"]
|
||||
defines += [("USE_TELEMETRY", "1")]
|
||||
features_available.append("telemetry")
|
||||
|
||||
defines += [
|
||||
"FRAMEBUFFER",
|
||||
|
||||
0
core/src/apps/telemetry/__init__.py
Normal file
0
core/src/apps/telemetry/__init__.py
Normal file
20
core/src/apps/telemetry/get_telemetry.py
Normal file
20
core/src/apps/telemetry/get_telemetry.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from trezor.messages import Telemetry, TelemetryGet
|
||||
|
||||
|
||||
async def get_telemetry(msg: TelemetryGet) -> Telemetry:
|
||||
from trezor.messages import Telemetry
|
||||
from trezor.utils import telemetry_get
|
||||
|
||||
data = telemetry_get()
|
||||
if data:
|
||||
min_temp_c, max_temp_c, battery_errors = data
|
||||
return Telemetry(
|
||||
min_temp_c=min_temp_c,
|
||||
max_temp_c=max_temp_c,
|
||||
battery_errors=battery_errors,
|
||||
)
|
||||
else:
|
||||
return Telemetry()
|
||||
@@ -64,6 +64,9 @@ def _find_message_handler_module(msg_type: int) -> str:
|
||||
if msg_type == MessageType.ShowDeviceTutorial:
|
||||
return "apps.management.show_tutorial"
|
||||
|
||||
if utils.USE_TELEMETRY and msg_type == MessageType.TelemetryGet:
|
||||
return "apps.telemetry.get_telemetry"
|
||||
|
||||
if utils.USE_BACKLIGHT and msg_type == MessageType.SetBrightness:
|
||||
return "apps.management.set_brightness"
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ from trezorutils import ( # noqa: F401
|
||||
USE_RGB_LED,
|
||||
USE_SD_CARD,
|
||||
USE_SERIAL_NUMBER,
|
||||
USE_TELEMETRY,
|
||||
USE_THP,
|
||||
USE_TOUCH,
|
||||
USE_TROPIC,
|
||||
@@ -57,6 +58,9 @@ from trezorutils import ( # noqa: F401
|
||||
unit_production_date,
|
||||
)
|
||||
|
||||
if USE_TELEMETRY:
|
||||
from trezorutils import telemetry_get # noqa: F401
|
||||
|
||||
if USE_NRF:
|
||||
from trezorutils import nrf_get_version # noqa: F401
|
||||
|
||||
|
||||
Reference in New Issue
Block a user