mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-26 00:18:15 +00:00
WIP - flags
This commit is contained in:
parent
b61b4cac04
commit
9237c376dd
@ -47,6 +47,8 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_set_slip39_iteration_exponent;
|
MP_QSTR_set_slip39_iteration_exponent;
|
||||||
MP_QSTR_get_autolock_delay_ms;
|
MP_QSTR_get_autolock_delay_ms;
|
||||||
MP_QSTR_set_autolock_delay_ms;
|
MP_QSTR_set_autolock_delay_ms;
|
||||||
|
MP_QSTR_get_flags;
|
||||||
|
MP_QSTR_set_flags;
|
||||||
|
|
||||||
MP_QSTR_set_timer_fn;
|
MP_QSTR_set_timer_fn;
|
||||||
MP_QSTR_touch_event;
|
MP_QSTR_touch_event;
|
||||||
|
@ -368,6 +368,32 @@ extern "C" fn storagedevice_set_autolock_delay_ms(delay_ms: Obj) -> Obj {
|
|||||||
unsafe { util::try_or_raise(block) }
|
unsafe { util::try_or_raise(block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" fn storagedevice_get_flags() -> Obj {
|
||||||
|
let block = || {
|
||||||
|
let key = _get_appkey(_FLAGS, false);
|
||||||
|
match storagedevice_storage_get_u32(key) {
|
||||||
|
Some(flag) => flag.try_into(),
|
||||||
|
None => 0.try_into(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
unsafe { util::try_or_raise(block) }
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" fn storagedevice_set_flags(flags: Obj) -> Obj {
|
||||||
|
let block = || {
|
||||||
|
let flags = u32::try_from(flags)?;
|
||||||
|
|
||||||
|
let key = _get_appkey(_FLAGS, false);
|
||||||
|
|
||||||
|
let old_flags = storagedevice_storage_get_u32(key).unwrap_or(0);
|
||||||
|
|
||||||
|
// Not deleting old flags
|
||||||
|
let new_flags = flags | old_flags;
|
||||||
|
Ok(storagedevice_storage_set_u32(key, new_flags).into())
|
||||||
|
};
|
||||||
|
unsafe { util::try_or_raise(block) }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn storagedevice_storage_get(key: u16) -> Vec<u8, MAX_LEN> {
|
pub fn storagedevice_storage_get(key: u16) -> Vec<u8, MAX_LEN> {
|
||||||
let mut buf: [u8; MAX_LEN] = [0; MAX_LEN];
|
let mut buf: [u8; MAX_LEN] = [0; MAX_LEN];
|
||||||
let mut len: u16 = 0;
|
let mut len: u16 = 0;
|
||||||
@ -619,6 +645,14 @@ pub static mp_module_trezorstoragedevice: Module = obj_module! {
|
|||||||
/// def set_autolock_delay_ms(delay_ms: int) -> bool:
|
/// def set_autolock_delay_ms(delay_ms: int) -> bool:
|
||||||
/// """Set autolock delay."""
|
/// """Set autolock delay."""
|
||||||
Qstr::MP_QSTR_set_autolock_delay_ms => obj_fn_1!(storagedevice_set_autolock_delay_ms).as_obj(),
|
Qstr::MP_QSTR_set_autolock_delay_ms => obj_fn_1!(storagedevice_set_autolock_delay_ms).as_obj(),
|
||||||
|
|
||||||
|
/// def get_flags() -> int:
|
||||||
|
/// """Get flags."""
|
||||||
|
Qstr::MP_QSTR_get_flags => obj_fn_0!(storagedevice_get_flags).as_obj(),
|
||||||
|
|
||||||
|
/// def set_flags(flags: int) -> bool:
|
||||||
|
/// """Set flags."""
|
||||||
|
Qstr::MP_QSTR_set_flags => obj_fn_1!(storagedevice_set_flags).as_obj(),
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -142,3 +142,13 @@ def get_autolock_delay_ms() -> int:
|
|||||||
# rust/src/storagedevice/storage_device.rs
|
# rust/src/storagedevice/storage_device.rs
|
||||||
def set_autolock_delay_ms(delay_ms: int) -> bool:
|
def set_autolock_delay_ms(delay_ms: int) -> bool:
|
||||||
"""Set autolock delay."""
|
"""Set autolock delay."""
|
||||||
|
|
||||||
|
|
||||||
|
# rust/src/storagedevice/storage_device.rs
|
||||||
|
def get_flags() -> int:
|
||||||
|
"""Get flags."""
|
||||||
|
|
||||||
|
|
||||||
|
# rust/src/storagedevice/storage_device.rs
|
||||||
|
def set_flags(flags: int) -> bool:
|
||||||
|
"""Set flags."""
|
||||||
|
@ -85,7 +85,7 @@ def get_features() -> Features:
|
|||||||
f.needs_backup = storagedevice.needs_backup()
|
f.needs_backup = storagedevice.needs_backup()
|
||||||
f.unfinished_backup = storagedevice.unfinished_backup()
|
f.unfinished_backup = storagedevice.unfinished_backup()
|
||||||
f.no_backup = storagedevice.no_backup()
|
f.no_backup = storagedevice.no_backup()
|
||||||
f.flags = storage.device.get_flags()
|
f.flags = storagedevice.get_flags()
|
||||||
f.recovery_mode = storage.recovery.is_in_progress()
|
f.recovery_mode = storage.recovery.is_in_progress()
|
||||||
f.backup_type = mnemonic.get_type()
|
f.backup_type = mnemonic.get_type()
|
||||||
f.sd_protection = storage.sd_salt.is_enabled()
|
f.sd_protection = storage.sd_salt.is_enabled()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from storage.device import set_flags
|
|
||||||
from trezor import storagedevice, wire
|
from trezor import storagedevice, wire
|
||||||
from trezor.messages import Success
|
from trezor.messages import Success
|
||||||
|
|
||||||
@ -11,5 +10,5 @@ if TYPE_CHECKING:
|
|||||||
async def apply_flags(ctx: wire.GenericContext, msg: ApplyFlags) -> Success:
|
async def apply_flags(ctx: wire.GenericContext, msg: ApplyFlags) -> Success:
|
||||||
if not storagedevice.is_initialized():
|
if not storagedevice.is_initialized():
|
||||||
raise wire.NotInitialized("Device is not initialized")
|
raise wire.NotInitialized("Device is not initialized")
|
||||||
set_flags(msg.flags)
|
storagedevice.set_flags(msg.flags)
|
||||||
return Success(message="Flags applied")
|
return Success(message="Flags applied")
|
||||||
|
@ -10,6 +10,8 @@ if TYPE_CHECKING:
|
|||||||
from trezor.enums import BackupType
|
from trezor.enums import BackupType
|
||||||
from typing_extensions import Literal
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
StorageSafetyCheckLevel = Literal[0, 1]
|
||||||
|
|
||||||
# Namespace:
|
# Namespace:
|
||||||
_NAMESPACE = common.APP_DEVICE
|
_NAMESPACE = common.APP_DEVICE
|
||||||
|
|
||||||
@ -41,8 +43,6 @@ _EXPERIMENTAL_FEATURES = const(0x15) # bool (0x01 or empty)
|
|||||||
SAFETY_CHECK_LEVEL_STRICT : Literal[0] = const(0)
|
SAFETY_CHECK_LEVEL_STRICT : Literal[0] = const(0)
|
||||||
SAFETY_CHECK_LEVEL_PROMPT : Literal[1] = const(1)
|
SAFETY_CHECK_LEVEL_PROMPT : Literal[1] = const(1)
|
||||||
_DEFAULT_SAFETY_CHECK_LEVEL = SAFETY_CHECK_LEVEL_STRICT
|
_DEFAULT_SAFETY_CHECK_LEVEL = SAFETY_CHECK_LEVEL_STRICT
|
||||||
if TYPE_CHECKING:
|
|
||||||
StorageSafetyCheckLevel = Literal[0, 1]
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
HOMESCREEN_MAXSIZE = 16384
|
HOMESCREEN_MAXSIZE = 16384
|
||||||
@ -207,23 +207,24 @@ def store_mnemonic_secret(
|
|||||||
# common.set_bool(_NAMESPACE, _PASSPHRASE_ALWAYS_ON_DEVICE, enable)
|
# common.set_bool(_NAMESPACE, _PASSPHRASE_ALWAYS_ON_DEVICE, enable)
|
||||||
|
|
||||||
|
|
||||||
def get_flags() -> int:
|
# def get_flags() -> int:
|
||||||
b = common.get(_NAMESPACE, _FLAGS)
|
# b = common.get(_NAMESPACE, _FLAGS)
|
||||||
if b is None:
|
# if b is None:
|
||||||
return 0
|
# return 0
|
||||||
else:
|
# else:
|
||||||
return int.from_bytes(b, "big")
|
# return int.from_bytes(b, "big")
|
||||||
|
|
||||||
|
|
||||||
def set_flags(flags: int) -> None:
|
# def set_flags(flags: int) -> None:
|
||||||
b = common.get(_NAMESPACE, _FLAGS)
|
# b = common.get(_NAMESPACE, _FLAGS)
|
||||||
if b is None:
|
# if b is None:
|
||||||
i = 0
|
# i = 0
|
||||||
else:
|
# else:
|
||||||
i = int.from_bytes(b, "big")
|
# i = int.from_bytes(b, "big")
|
||||||
flags = (flags | i) & 0xFFFF_FFFF
|
# flags = (flags | i) & 0xFFFF_FFFF
|
||||||
if flags != i:
|
# print("flags_mpppppp", flags)
|
||||||
common.set(_NAMESPACE, _FLAGS, flags.to_bytes(4, "big"))
|
# if flags != i:
|
||||||
|
# common.set(_NAMESPACE, _FLAGS, flags.to_bytes(4, "big"))
|
||||||
|
|
||||||
|
|
||||||
# def _normalize_autolock_delay(delay_ms: int) -> int:
|
# def _normalize_autolock_delay(delay_ms: int) -> int:
|
||||||
|
Loading…
Reference in New Issue
Block a user