@@ -109,6 +109,9 @@ pub enum Event<T> {
109
109
/// Manages the communication of the device: receives events such as button presses, incoming
110
110
/// APDU requests, and provides methods to build and transmit APDU responses.
111
111
pub struct Comm {
112
+ pub apdu_buffer : [ u8 ; 272 ] ,
113
+ pub rx : usize ,
114
+ pub tx : usize ,
112
115
pub event_pending : bool ,
113
116
#[ cfg( not( any( target_os = "stax" , target_os = "flex" ) ) ) ]
114
117
buttons : ButtonsState ,
@@ -122,9 +125,6 @@ pub struct Comm {
122
125
pub io_buffer : [ u8 ; 273 ] ,
123
126
pub rx_length : usize ,
124
127
pub tx_length : usize ,
125
-
126
- // Legacy
127
- pub rx : usize ,
128
128
}
129
129
130
130
impl Default for Comm {
@@ -150,6 +150,9 @@ impl Comm {
150
150
/// Creates a new [`Comm`] instance, which accepts any CLA APDU by default.
151
151
pub const fn new ( ) -> Self {
152
152
Self {
153
+ apdu_buffer : [ 0u8 ; 272 ] ,
154
+ rx : 0 ,
155
+ tx : 0 ,
153
156
event_pending : false ,
154
157
#[ cfg( not( any( target_os = "stax" , target_os = "flex" ) ) ) ]
155
158
buttons : ButtonsState :: new ( ) ,
@@ -158,7 +161,6 @@ impl Comm {
158
161
io_buffer : [ 0u8 ; 273 ] ,
159
162
rx_length : 0 ,
160
163
tx_length : 0 ,
161
- rx : 0 ,
162
164
}
163
165
}
164
166
@@ -185,7 +187,13 @@ impl Comm {
185
187
// This is private. Users should call reply to set the satus word and
186
188
// transmit the response.
187
189
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
+ }
189
197
self . tx_length = 0 ;
190
198
self . rx_length = 0 ;
191
199
}
@@ -350,7 +358,7 @@ impl Comm {
350
358
seph:: Events :: TickerEvent => {
351
359
#[ cfg( any( target_os = "stax" , target_os = "flex" , feature = "nano_nbgl" ) ) ]
352
360
unsafe {
353
- ux_process_ticker_event ( ) ;
361
+ ux_process_ticker_event ( ) ;
354
362
}
355
363
return Some ( Event :: Ticker ) ;
356
364
}
@@ -384,6 +392,7 @@ impl Comm {
384
392
}
385
393
386
394
seph:: ItcUxEvent :: Redisplay => {
395
+ #[ cfg( any( target_os = "stax" , target_os = "flex" , feature = "nano_nbgl" ) ) ]
387
396
unsafe {
388
397
nbgl_objAllowDrawing ( true ) ;
389
398
nbgl_screenRedraw ( ) ;
@@ -441,6 +450,7 @@ impl Comm {
441
450
return None ;
442
451
}
443
452
}
453
+ self . apdu_buffer [ 0 ..272 ] . copy_from_slice ( & self . io_buffer [ 1 ..273 ] ) ;
444
454
self . apdu_type = packet_type;
445
455
self . rx_length = length as usize ;
446
456
self . rx = self . rx_length -1 ;
0 commit comments