Skip to content

Commit 471a2ba

Browse files
committed
Update NBGL HomeAndSettings: stop filtering APDU
1 parent a99024c commit 471a2ba

File tree

5 files changed

+61
-273
lines changed

5 files changed

+61
-273
lines changed

ledger_device_sdk/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ pub mod testing;
2525

2626
#[cfg(any(target_os = "stax", target_os = "flex"))]
2727
pub mod nbgl;
28-
#[cfg(any(target_os = "stax", target_os = "flex"))]
29-
pub mod nbgl2;
3028
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
3129
pub mod ui;
3230

ledger_device_sdk/src/nbgl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::io::{ApduHeader, Comm, Event, Reply};
1+
use crate::io::{ApduHeader, Comm};
22
use crate::nvm::*;
33
use const_zero::const_zero;
44
extern crate alloc;
@@ -32,10 +32,6 @@ pub use nbgl_status::*;
3232
pub use nbgl_streaming_review::*;
3333

3434
static mut COMM_REF: Option<&mut Comm> = None;
35-
pub const SETTINGS_SIZE: usize = 10;
36-
static mut NVM_REF: Option<&mut AtomicStorage<[u8; SETTINGS_SIZE]>> = None;
37-
static mut SWITCH_ARRAY: [nbgl_contentSwitch_t; SETTINGS_SIZE] =
38-
[unsafe { const_zero!(nbgl_contentSwitch_t) }; SETTINGS_SIZE];
3935

4036
#[derive(Copy, Clone)]
4137
enum SyncNbgl {

ledger_device_sdk/src/nbgl/nbgl_home_and_settings.rs

Lines changed: 60 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use super::*;
22

3+
pub const SETTINGS_SIZE: usize = 10;
4+
static mut NVM_REF: Option<&mut AtomicStorage<[u8; SETTINGS_SIZE]>> = None;
5+
static mut SWITCH_ARRAY: [nbgl_contentSwitch_t; SETTINGS_SIZE] =
6+
[unsafe { const_zero!(nbgl_contentSwitch_t) }; SETTINGS_SIZE];
7+
38
/// Callback triggered by the NBGL API when a setting switch is toggled.
49
unsafe extern "C" fn settings_callback(token: c_int, _index: u8, _page: c_int) {
510
let idx = token - FIRST_USER_TOKEN as i32;
@@ -47,7 +52,9 @@ pub struct NbglHomeAndSettings {
4752
icon: nbgl_icon_details_t,
4853
}
4954

50-
impl SyncNBGL for NbglHomeAndSettings {}
55+
unsafe extern "C" fn quit_callback() {
56+
exit_app(0);
57+
}
5158

5259
impl<'a> NbglHomeAndSettings {
5360
pub fn new() -> NbglHomeAndSettings {
@@ -111,83 +118,62 @@ impl<'a> NbglHomeAndSettings {
111118
}
112119
}
113120

114-
pub fn show<T: TryFrom<ApduHeader>>(&mut self) -> Event<T>
115-
where
116-
Reply: From<<T as TryFrom<ApduHeader>>::Error>,
117-
{
121+
pub fn show(&mut self) {
118122
unsafe {
119-
loop {
120-
self.info_contents_ptr = self
121-
.info_contents
122-
.iter()
123-
.map(|s| s.as_ptr())
124-
.collect::<Vec<_>>();
125-
126-
self.info_list = nbgl_contentInfoList_t {
127-
infoTypes: INFO_FIELDS.as_ptr() as *const *const c_char,
128-
infoContents: self.info_contents_ptr[..].as_ptr() as *const *const c_char,
129-
nbInfos: INFO_FIELDS.len() as u8,
130-
};
131-
132-
for (i, setting) in self.setting_contents.iter().enumerate() {
133-
SWITCH_ARRAY[i].text = setting[0].as_ptr();
134-
SWITCH_ARRAY[i].subText = setting[1].as_ptr();
135-
let state = if let Some(data) = NVM_REF.as_mut() {
136-
data.get_ref()[i]
137-
} else {
138-
OFF_STATE
139-
};
140-
SWITCH_ARRAY[i].initState = state;
141-
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
142-
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
143-
}
144-
145-
self.content = nbgl_content_t {
146-
content: nbgl_content_u {
147-
switchesList: nbgl_pageSwitchesList_s {
148-
switches: &SWITCH_ARRAY as *const nbgl_contentSwitch_t,
149-
nbSwitches: self.nb_settings,
150-
},
151-
},
152-
contentActionCallback: Some(settings_callback),
153-
type_: SWITCHES_LIST,
123+
self.info_contents_ptr = self
124+
.info_contents
125+
.iter()
126+
.map(|s| s.as_ptr())
127+
.collect::<Vec<_>>();
128+
129+
self.info_list = nbgl_contentInfoList_t {
130+
infoTypes: INFO_FIELDS.as_ptr() as *const *const c_char,
131+
infoContents: self.info_contents_ptr[..].as_ptr() as *const *const c_char,
132+
nbInfos: INFO_FIELDS.len() as u8,
133+
};
134+
135+
for (i, setting) in self.setting_contents.iter().enumerate() {
136+
SWITCH_ARRAY[i].text = setting[0].as_ptr();
137+
SWITCH_ARRAY[i].subText = setting[1].as_ptr();
138+
let state = if let Some(data) = NVM_REF.as_mut() {
139+
data.get_ref()[i]
140+
} else {
141+
OFF_STATE
154142
};
143+
SWITCH_ARRAY[i].initState = state;
144+
SWITCH_ARRAY[i].token = (FIRST_USER_TOKEN + i as u32) as u8;
145+
SWITCH_ARRAY[i].tuneId = TuneIndex::TapCasual as u8;
146+
}
155147

156-
self.generic_contents = nbgl_genericContents_t {
157-
callbackCallNeeded: false,
158-
__bindgen_anon_1: nbgl_genericContents_t__bindgen_ty_1 {
159-
contentsList: &self.content as *const nbgl_content_t,
148+
self.content = nbgl_content_t {
149+
content: nbgl_content_u {
150+
switchesList: nbgl_pageSwitchesList_s {
151+
switches: &SWITCH_ARRAY as *const nbgl_contentSwitch_t,
152+
nbSwitches: self.nb_settings,
160153
},
161-
nbContents: if self.nb_settings > 0 { 1 } else { 0 },
162-
};
163-
164-
self.ux_sync_init();
165-
nbgl_useCaseHomeAndSettings(
166-
self.app_name.as_ptr() as *const c_char,
167-
&self.icon as *const nbgl_icon_details_t,
168-
core::ptr::null(),
169-
INIT_HOME_PAGE as u8,
170-
&self.generic_contents as *const nbgl_genericContents_t,
171-
&self.info_list as *const nbgl_contentInfoList_t,
172-
core::ptr::null(),
173-
Some(quit_callback),
174-
);
175-
match self.ux_sync_wait(true) {
176-
SyncNbgl::UxSyncRetApduReceived => {
177-
if let Some(comm) = COMM_REF.as_mut() {
178-
if let Some(value) = comm.check_event() {
179-
return value;
180-
}
181-
}
182-
}
183-
SyncNbgl::UxSyncRetQuitted => {
184-
exit_app(0);
185-
}
186-
_ => {
187-
panic!("Unexpected return value from ux_sync_homeAndSettings");
188-
}
189-
}
190-
}
154+
},
155+
contentActionCallback: Some(settings_callback),
156+
type_: SWITCHES_LIST,
157+
};
158+
159+
self.generic_contents = nbgl_genericContents_t {
160+
callbackCallNeeded: false,
161+
__bindgen_anon_1: nbgl_genericContents_t__bindgen_ty_1 {
162+
contentsList: &self.content as *const nbgl_content_t,
163+
},
164+
nbContents: if self.nb_settings > 0 { 1 } else { 0 },
165+
};
166+
167+
nbgl_useCaseHomeAndSettings(
168+
self.app_name.as_ptr() as *const c_char,
169+
&self.icon as *const nbgl_icon_details_t,
170+
core::ptr::null(),
171+
INIT_HOME_PAGE as u8,
172+
&self.generic_contents as *const nbgl_genericContents_t,
173+
&self.info_list as *const nbgl_contentInfoList_t,
174+
core::ptr::null(),
175+
Some(quit_callback),
176+
);
191177
}
192178
}
193179
}

ledger_device_sdk/src/nbgl2.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

ledger_device_sdk/src/nbgl2/nbgl2_home_and_settings.rs

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)