1
-
2
1
#[ cfg( not( any( target_os = "stax" , target_os = "flex" ) ) ) ]
3
2
use ledger_secure_sdk_sys:: buttons:: { get_button_event, ButtonEvent , ButtonsState } ;
4
3
use ledger_secure_sdk_sys:: seph as sys_seph;
@@ -17,7 +16,6 @@ unsafe extern "C" {
17
16
pub unsafe static mut G_ux_params : bolos_ux_params_t ;
18
17
}
19
18
20
-
21
19
#[ derive( Copy , Clone ) ]
22
20
#[ repr( u16 ) ]
23
21
pub enum StatusWords {
@@ -103,7 +101,7 @@ pub enum Event<T> {
103
101
#[ cfg( any( target_os = "stax" , target_os = "flex" ) ) ]
104
102
TouchEvent ,
105
103
/// Ticker
106
- Ticker
104
+ Ticker ,
107
105
}
108
106
109
107
/// Manages the communication of the device: receives events such as button presses, incoming
@@ -190,8 +188,7 @@ impl Comm {
190
188
if self . tx != 0 {
191
189
sys_seph:: io_tx ( self . apdu_type , & self . apdu_buffer , self . tx ) ;
192
190
self . tx = 0 ;
193
- }
194
- else {
191
+ } else {
195
192
sys_seph:: io_tx ( self . apdu_type , & self . io_buffer , self . tx_length ) ;
196
193
}
197
194
self . tx_length = 0 ;
@@ -261,7 +258,7 @@ impl Comm {
261
258
if status > 0 {
262
259
return self . detect_apdu :: < T > ( status) ;
263
260
}
264
- return false
261
+ return false ;
265
262
}
266
263
267
264
pub fn check_event < T > ( & mut self ) -> Option < Event < T > >
@@ -287,10 +284,7 @@ impl Comm {
287
284
}
288
285
289
286
// Manage BOLOS specific APDUs B0xx0000
290
- if self . io_buffer [ 1 ] == 0xB0
291
- && self . io_buffer [ 3 ] == 0x00
292
- && self . io_buffer [ 4 ] == 0x00
293
- {
287
+ if self . io_buffer [ 1 ] == 0xB0 && self . io_buffer [ 3 ] == 0x00 && self . io_buffer [ 4 ] == 0x00 {
294
288
handle_bolos_apdu ( self , self . io_buffer [ 2 ] ) ;
295
289
return None ;
296
290
}
@@ -327,13 +321,12 @@ impl Comm {
327
321
let tag = seph_buffer[ 0 ] ;
328
322
let _len: usize = u16:: from_be_bytes ( [ seph_buffer[ 1 ] , seph_buffer[ 2 ] ] ) as usize ;
329
323
330
- if ( length as usize ) < _len+ 3 {
324
+ if ( length as usize ) < _len + 3 {
331
325
self . reply ( StatusWords :: BadLen ) ;
332
- return None
326
+ return None ;
333
327
}
334
328
335
329
match seph:: Events :: from ( tag) {
336
-
337
330
// BUTTON PUSH EVENT
338
331
#[ cfg( not( any( target_os = "stax" , target_os = "flex" ) ) ) ]
339
332
seph:: Events :: ButtonPushEvent => {
@@ -352,7 +345,7 @@ impl Comm {
352
345
seph:: Events :: ScreenTouchEvent => unsafe {
353
346
ux_process_finger_event ( seph_buffer. as_mut_ptr ( ) ) ;
354
347
return Some ( Event :: TouchEvent ) ;
355
- }
348
+ } ,
356
349
357
350
// TICKER EVENT
358
351
seph:: Events :: TickerEvent => {
@@ -367,29 +360,26 @@ impl Comm {
367
360
seph:: Events :: ItcEvent => {
368
361
#[ cfg( any( target_os = "nanox" , target_os = "stax" , target_os = "flex" ) ) ]
369
362
match ItcUxEvent :: from ( seph_buffer[ 3 ] ) {
370
-
371
- seph:: ItcUxEvent :: AskBlePairing => {
372
- unsafe {
373
- G_ux_params . ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST ;
374
- G_ux_params . len = 20 ;
375
- G_ux_params . u . pairing_request . type_ = seph_buffer[ 4 ] ;
376
- G_ux_params . u . pairing_request . pairing_info_len = ( _len-2 ) as u32 ;
377
- for i in 0 ..G_ux_params . u . pairing_request . pairing_info_len as usize {
378
- G_ux_params . u . pairing_request . pairing_info [ i as usize ] = seph_buffer[ 5 +i] as i8 ;
379
- }
380
- G_ux_params . u . pairing_request . pairing_info [ G_ux_params . u . pairing_request . pairing_info_len as usize ] = 0 ;
381
- os_ux ( & raw mut G_ux_params as * mut bolos_ux_params_t ) ;
363
+ seph:: ItcUxEvent :: AskBlePairing => unsafe {
364
+ G_ux_params . ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST ;
365
+ G_ux_params . len = 20 ;
366
+ G_ux_params . u . pairing_request . type_ = seph_buffer[ 4 ] ;
367
+ G_ux_params . u . pairing_request . pairing_info_len = ( _len - 2 ) as u32 ;
368
+ for i in 0 ..G_ux_params . u . pairing_request . pairing_info_len as usize {
369
+ G_ux_params . u . pairing_request . pairing_info [ i as usize ] =
370
+ seph_buffer[ 5 + i] as i8 ;
382
371
}
383
- }
384
-
385
- seph:: ItcUxEvent :: BlePairingStatus => {
386
- unsafe {
387
- G_ux_params . ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS ;
388
- G_ux_params . len = 0 ;
389
- G_ux_params . u . pairing_status . pairing_ok = seph_buffer[ 4 ] ;
390
- os_ux ( & raw mut G_ux_params as * mut bolos_ux_params_t ) ;
391
- }
392
- }
372
+ G_ux_params . u . pairing_request . pairing_info
373
+ [ G_ux_params . u . pairing_request . pairing_info_len as usize ] = 0 ;
374
+ os_ux ( & raw mut G_ux_params as * mut bolos_ux_params_t ) ;
375
+ } ,
376
+
377
+ seph:: ItcUxEvent :: BlePairingStatus => unsafe {
378
+ G_ux_params . ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS ;
379
+ G_ux_params . len = 0 ;
380
+ G_ux_params . u . pairing_status . pairing_ok = seph_buffer[ 4 ] ;
381
+ os_ux ( & raw mut G_ux_params as * mut bolos_ux_params_t ) ;
382
+ } ,
393
383
394
384
seph:: ItcUxEvent :: Redisplay => {
395
385
#[ cfg( any( target_os = "stax" , target_os = "flex" , feature = "nano_nbgl" ) ) ]
@@ -400,11 +390,9 @@ impl Comm {
400
390
}
401
391
}
402
392
403
- _ => {
404
- return None
405
- }
393
+ _ => return None ,
406
394
}
407
- return None
395
+ return None ;
408
396
}
409
397
410
398
// DEFAULT EVENT
@@ -422,7 +410,7 @@ impl Comm {
422
410
None
423
411
}
424
412
425
- pub fn decode_event < T > ( & mut self , length : i32 ) -> Option < Event < T > >
413
+ pub fn decode_event < T > ( & mut self , length : i32 ) -> Option < Event < T > >
426
414
where
427
415
T : TryFrom < ApduHeader > ,
428
416
Reply : From < <T as TryFrom < ApduHeader > >:: Error > ,
@@ -434,45 +422,45 @@ impl Comm {
434
422
// SE or SEPH event
435
423
let mut seph_buffer = [ 0u8 ; 272 ] ;
436
424
seph_buffer[ 0 ..272 ] . copy_from_slice ( & self . io_buffer [ 1 ..273 ] ) ;
437
- if let Some ( event) = self . process_event ( seph_buffer, length- 1 ) {
425
+ if let Some ( event) = self . process_event ( seph_buffer, length - 1 ) {
438
426
return Some ( event) ;
439
427
}
440
428
}
441
429
442
- seph:: PacketTypes :: PacketTypeRawApdu |
443
- seph:: PacketTypes :: PacketTypeUsbHidApdu |
444
- seph:: PacketTypes :: PacketTypeUsbWebusbApdu |
445
- seph:: PacketTypes :: PacketTypeBleApdu => {
430
+ seph:: PacketTypes :: PacketTypeRawApdu
431
+ | seph:: PacketTypes :: PacketTypeUsbHidApdu
432
+ | seph:: PacketTypes :: PacketTypeUsbWebusbApdu
433
+ | seph:: PacketTypes :: PacketTypeBleApdu => {
446
434
unsafe {
447
435
if os_perso_is_pin_set ( ) == BOLOS_TRUE . try_into ( ) . unwrap ( )
448
- && os_global_pin_is_validated ( ) != BOLOS_TRUE . try_into ( ) . unwrap ( ) {
436
+ && os_global_pin_is_validated ( ) != BOLOS_TRUE . try_into ( ) . unwrap ( )
437
+ {
449
438
self . reply ( StatusWords :: DeviceLocked ) ;
450
439
return None ;
451
440
}
452
441
}
453
442
self . apdu_buffer [ 0 ..272 ] . copy_from_slice ( & self . io_buffer [ 1 ..273 ] ) ;
454
443
self . apdu_type = packet_type;
455
444
self . rx_length = length as usize ;
456
- self . rx = self . rx_length - 1 ;
445
+ self . rx = self . rx_length - 1 ;
457
446
self . event_pending = true ;
458
447
return self . check_event ( ) ;
459
448
}
460
449
461
- _ => {
462
- }
450
+ _ => { }
463
451
}
464
452
None
465
453
}
466
454
467
- fn detect_apdu < T > ( & mut self , length : i32 ) -> bool
455
+ fn detect_apdu < T > ( & mut self , length : i32 ) -> bool
468
456
where
469
457
T : TryFrom < ApduHeader > ,
470
458
Reply : From < <T as TryFrom < ApduHeader > >:: Error > ,
471
459
{
472
460
match self . decode_event :: < T > ( length) {
473
461
Some ( Event :: Command ( _) ) => {
474
462
self . rx_length = length as usize ;
475
- self . rx = self . rx_length - 1 ;
463
+ self . rx = self . rx_length - 1 ;
476
464
self . event_pending = true ;
477
465
return true ;
478
466
}
@@ -585,8 +573,7 @@ impl Comm {
585
573
( 0 , 6 ) => Ok ( & [ ] ) , // Non-conforming zero-data APDU
586
574
( 0 , 7 ) => Err ( StatusWords :: BadLen ) ,
587
575
( 0 , _) => {
588
- let len =
589
- u16:: from_le_bytes ( [ self . io_buffer [ 6 ] , self . io_buffer [ 7 ] ] ) as usize ;
576
+ let len = u16:: from_le_bytes ( [ self . io_buffer [ 6 ] , self . io_buffer [ 7 ] ] ) as usize ;
590
577
get_data_from_buffer ( len, 8 )
591
578
}
592
579
( len, _) => get_data_from_buffer ( len, 6 ) ,
0 commit comments