Skip to content

Commit 35a649c

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

File tree

1 file changed

+15
-5
lines changed
  • ledger_device_sdk/src

1 file changed

+15
-5
lines changed

ledger_device_sdk/src/io.rs

Lines changed: 15 additions & 5 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(),
@@ -158,7 +161,6 @@ impl Comm {
158161
io_buffer: [0u8; 273],
159162
rx_length: 0,
160163
tx_length: 0,
161-
rx: 0,
162164
}
163165
}
164166

@@ -185,7 +187,13 @@ impl Comm {
185187
// This is private. Users should call reply to set the satus word and
186188
// transmit the response.
187189
fn apdu_send(&mut self, _is_swap: bool) {
188-
sys_seph::io_tx(self.apdu_type, &self.io_buffer, self.tx_length);
190+
if self.tx != 0 {
191+
sys_seph::io_tx(self.apdu_type, &self.apdu_buffer, self.tx_length);
192+
self.tx = 0;
193+
}
194+
else {
195+
sys_seph::io_tx(self.apdu_type, &self.io_buffer, self.tx_length);
196+
}
189197
self.tx_length = 0;
190198
self.rx_length = 0;
191199
}
@@ -384,6 +392,7 @@ impl Comm {
384392
}
385393

386394
seph::ItcUxEvent::Redisplay => {
395+
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nano_nbgl"))]
387396
unsafe {
388397
nbgl_objAllowDrawing(true);
389398
nbgl_screenRedraw();
@@ -437,6 +446,7 @@ impl Comm {
437446
return None;
438447
}
439448
}
449+
self.apdu_buffer[0..272].copy_from_slice(&self.io_buffer[1..273]);
440450
self.apdu_type = packet_type;
441451
self.rx_length = length as usize;
442452
self.rx = self.rx_length-1;

0 commit comments

Comments
 (0)