Skip to content

Commit 134a3dc

Browse files
committed
Delay lock + better ticker management
1 parent 13ede06 commit 134a3dc

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

ledger_device_sdk/src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl Comm {
397397
seph::Events::BleReceive => ble::receive(&mut self.apdu_buffer, spi_buffer),
398398

399399
seph::Events::TickerEvent => {
400-
#[cfg(any(target_os = "stax", target_os = "flex"))]
400+
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nano_nbgl"))]
401401
unsafe {
402402
ux_process_ticker_event();
403403
}

ledger_device_sdk/src/seph.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ pub fn handle_event(apdu_buffer: &mut [u8], spi_buffer: &[u8]) {
201201
#[cfg(any(target_os = "nanox", target_os = "stax", target_os = "flex"))]
202202
Events::BleReceive => ble::receive(apdu_buffer, spi_buffer),
203203
Events::CAPDUEvent => handle_capdu_event(apdu_buffer, spi_buffer),
204-
Events::TickerEvent => { /* unsafe{ G_io_app.ms += 100; } */ }
204+
Events::TickerEvent => {
205+
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nano_nbgl"))]
206+
unsafe {
207+
ux_process_ticker_event();
208+
}
209+
}
205210
_ => (),
206211
}
207212
}

ledger_device_sdk/src/ui/gadgets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl<'a> MultiPageMenu<'a> {
567567
},
568568
io::Event::Command(ins) => return EventOrPageIndex::Event(io::Event::Command(ins)),
569569
io::Event::Ticker => {
570-
if UxEvent::Event.request() != BOLOS_UX_OK {
570+
if UxEvent::Event.request(None) != BOLOS_UX_OK {
571571
// pin lock management
572572
UxEvent::block_and_get_event::<Temp>(self.comm);
573573
// notify Ticker event only when redisplay is required

ledger_device_sdk/src/uxapp.rs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub use ledger_secure_sdk_sys::BOLOS_UX_IGNORE;
1111
pub use ledger_secure_sdk_sys::BOLOS_UX_OK;
1212
pub use ledger_secure_sdk_sys::BOLOS_UX_REDRAW;
1313

14-
fn os_ux_rs(params: &bolos_ux_params_t) {
15-
unsafe { os_ux(params as *const bolos_ux_params_t as *mut bolos_ux_params_t) };
14+
unsafe extern "C" {
15+
pub unsafe static mut G_ux_params: bolos_ux_params_t;
1616
}
1717

1818
#[repr(u8)]
@@ -21,31 +21,46 @@ pub enum UxEvent {
2121
Keyboard = BOLOS_UX_KEYBOARD,
2222
WakeUp = BOLOS_UX_WAKE_UP,
2323
ValidatePIN = BOLOS_UX_VALIDATE_PIN,
24-
LastID = BOLOS_UX_VALIDATE_PIN + 1,
24+
DelayLock = BOLOS_UX_DELAY_LOCK,
25+
LastID = BOLOS_UX_DELAY_LOCK + 1,
2526
}
2627

2728
impl UxEvent {
28-
pub fn request(&self) -> u32 {
29-
let mut params = bolos_ux_params_t::default();
30-
params.ux_id = match self {
31-
Self::Event => Self::Event as u8,
32-
Self::Keyboard => Self::Keyboard as u8,
33-
Self::WakeUp => Self::WakeUp as u8,
34-
Self::ValidatePIN => {
35-
// Perform pre-wake up
36-
params.ux_id = Self::WakeUp as u8;
37-
os_ux_rs(&params);
29+
#[allow(unused)]
30+
pub fn request(&self, val: Option<u32>) -> u32 {
31+
unsafe {
32+
//let mut params = bolos_ux_params_t::default();
33+
G_ux_params.ux_id = match self {
34+
Self::Event => Self::Event as u8,
35+
Self::Keyboard => Self::Keyboard as u8,
36+
Self::WakeUp => Self::WakeUp as u8,
37+
Self::ValidatePIN => {
38+
// Perform pre-wake up
39+
G_ux_params.ux_id = Self::WakeUp as u8;
40+
os_ux(&raw mut G_ux_params as *mut bolos_ux_params_t);
3841

39-
Self::ValidatePIN as u8
40-
}
41-
Self::LastID => panic!("Unknown UX Event"),
42-
};
42+
Self::ValidatePIN as u8
43+
}
44+
Self::DelayLock => {
45+
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nano_nbgl"))]
46+
{
47+
G_ux_params.u = bolos_ux_params_s__bindgen_ty_1 {
48+
lock_delay: bolos_ux_params_s__bindgen_ty_1__bindgen_ty_3 {
49+
delay_ms: val.unwrap_or(10000),
50+
},
51+
};
52+
}
53+
Self::DelayLock as u8
54+
}
55+
Self::LastID => panic!("Unknown UX Event"),
56+
};
4357

44-
os_ux_rs(&params);
58+
os_ux(&raw mut G_ux_params as *mut bolos_ux_params_t);
4559

46-
match self {
47-
Self::ValidatePIN => Self::block(),
48-
_ => unsafe { os_sched_last_status(TASK_BOLOS_UX as u32) as u32 },
60+
match self {
61+
Self::ValidatePIN => Self::block(),
62+
_ => os_sched_last_status(TASK_BOLOS_UX as u32) as u32,
63+
}
4964
}
5065
}
5166

@@ -58,7 +73,7 @@ impl UxEvent {
5873
let mut spi_buffer = [0u8; 256];
5974
sys_seph::send_general_status();
6075
sys_seph::seph_recv(&mut spi_buffer, 0);
61-
UxEvent::Event.request();
76+
UxEvent::Event.request(None);
6277
} else {
6378
unsafe { os_sched_yield(BOLOS_UX_OK as u8) };
6479
}
@@ -83,7 +98,7 @@ impl UxEvent {
8398
seph::seph_recv(&mut spi_buffer, 0);
8499
event = comm.decode_event(&mut spi_buffer);
85100

86-
UxEvent::Event.request();
101+
UxEvent::Event.request(None);
87102

88103
if let Option::Some(Event::Command(_)) = event {
89104
return (ret, event);

ledger_secure_sdk_sys/src/c/src.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void c_reset_bss() {
251251
memset(bss, 0, bss_len);
252252
}
253253

254-
bolos_ux_params_t G_ux_params;
254+
bolos_ux_params_t G_ux_params = {0};
255255

256256
void c_boot_std() {
257257
// below is a 'manual' implementation of `io_seproxyhal_init`

0 commit comments

Comments
 (0)