Skip to content

Commit e582c25

Browse files
[io] fix some issues
1 parent ce921c2 commit e582c25

File tree

1 file changed

+15
-4
lines changed
  • ledger_device_sdk/src

1 file changed

+15
-4
lines changed

ledger_device_sdk/src/io.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ pub enum Event<T> {
109109
/// Manages the communication of the device: receives events such as button presses, incoming
110110
/// APDU requests, and provides methods to build and transmit APDU responses.
111111
pub struct Comm {
112+
pub apdu_buffer: [u8; 272],
113+
pub rx: usize,
114+
pub tx: usize,
112115
pub event_pending: bool,
113116
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
114117
buttons: ButtonsState,
@@ -122,9 +125,6 @@ pub struct Comm {
122125
pub io_buffer: [u8; 273],
123126
pub rx_length: usize,
124127
pub tx_length: usize,
125-
126-
// Legacy
127-
pub rx: usize,
128128
}
129129

130130
impl Default for Comm {
@@ -150,6 +150,9 @@ impl Comm {
150150
/// Creates a new [`Comm`] instance, which accepts any CLA APDU by default.
151151
pub const fn new() -> Self {
152152
Self {
153+
apdu_buffer: [0u8; 272],
154+
rx: 0,
155+
tx: 0,
153156
event_pending: false,
154157
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
155158
buttons: ButtonsState::new(),
@@ -185,7 +188,13 @@ impl Comm {
185188
// This is private. Users should call reply to set the satus word and
186189
// transmit the response.
187190
fn apdu_send(&mut self, _is_swap: bool) {
188-
sys_seph::io_tx(self.apdu_type, &self.io_buffer, self.tx_length);
191+
if self.tx {
192+
sys_seph::io_tx(self.apdu_type, &self.apdu_buffer, self.tx_length);
193+
self.tx = 0;
194+
}
195+
else {
196+
sys_seph::io_tx(self.apdu_type, &self.io_buffer, self.tx_length);
197+
}
189198
self.tx_length = 0;
190199
self.rx_length = 0;
191200
}
@@ -384,6 +393,7 @@ impl Comm {
384393
}
385394

386395
seph::ItcUxEvent::Redisplay => {
396+
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nano_nbgl"))]
387397
unsafe {
388398
nbgl_objAllowDrawing(true);
389399
nbgl_screenRedraw();
@@ -437,6 +447,7 @@ impl Comm {
437447
return None;
438448
}
439449
}
450+
self.apdu_buffer[0..272].copy_from_slice(&self.io_buffer[1..273]);
440451
self.apdu_type = packet_type;
441452
self.rx_length = length as usize;
442453
self.rx = self.rx_length-1;

0 commit comments

Comments
 (0)