Skip to content

Commit afee3c9

Browse files
sportron-ledgeryogh333
authored andcommitted
[io] fix some issues
1 parent 1eea6d3 commit afee3c9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ jobs:
8080
uses: ./.github/workflows/reusable_build_all_apps.yml
8181
with:
8282
rust_sdk_branch: ${{ github.ref }}
83+
c_sdk_branch: API_LEVEL_24

ledger_device_sdk/src/io.rs

Lines changed: 16 additions & 6 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);
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
}
@@ -350,7 +358,7 @@ impl Comm {
350358
seph::Events::TickerEvent => {
351359
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nano_nbgl"))]
352360
unsafe {
353-
ux_process_ticker_event();
361+
ux_process_ticker_event();
354362
}
355363
return Some(Event::Ticker);
356364
}
@@ -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();
@@ -441,6 +450,7 @@ impl Comm {
441450
return None;
442451
}
443452
}
453+
self.apdu_buffer[0..272].copy_from_slice(&self.io_buffer[1..273]);
444454
self.apdu_type = packet_type;
445455
self.rx_length = length as usize;
446456
self.rx = self.rx_length-1;

0 commit comments

Comments
 (0)