Remove duplicate code
This commit is contained in:
@@ -36,6 +36,16 @@ fn print_rx_buffer(buf: &mut [u8], amount: usize) {
|
|||||||
writeln!(console, " {:02x?}", buf[amount - 1]).unwrap();
|
writeln!(console, " {:02x?}", buf[amount - 1]).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
/// Helper function to write on console the received packet.
|
||||||
|
fn transmit_slice(buf: &mut [u8] {
|
||||||
|
let amount = buf.len();
|
||||||
|
match NfcTag::transmit(&mut buf, amount) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => writeln!(console, " -- tx error!").unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "with_nfc")]
|
#[cfg(feature = "with_nfc")]
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
/// enum for reserving the NFC tag state.
|
/// enum for reserving the NFC tag state.
|
||||||
@@ -72,46 +82,30 @@ fn main() {
|
|||||||
Err(TockError::Command(CommandError {
|
Err(TockError::Command(CommandError {
|
||||||
return_code: value, ..
|
return_code: value, ..
|
||||||
})) => writeln!(console, " -- Err({})!", value).unwrap(),
|
})) => writeln!(console, " -- Err({})!", value).unwrap(),
|
||||||
Err(_) => writeln!(console, " -- RX ERROR").unwrap(),
|
Err(_) => writeln!(console, " -- RX Err").unwrap(),
|
||||||
}
|
}
|
||||||
|
|
||||||
match rx_buf[0] {
|
match rx_buf[0] {
|
||||||
0xe0 /* RATS */=> {
|
0xe0 /* RATS */=> {
|
||||||
let mut answer_to_select = [0x05, 0x78, 0x80, 0xB1, 0x00];
|
let mut answer_to_select = [0x05, 0x78, 0x80, 0xB1, 0x00];
|
||||||
let amount = answer_to_select.len();
|
transmit_slice(&mut answer_to_select);
|
||||||
match NfcTag::transmit(&mut answer_to_select, amount) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => writeln!(console, " -- tx error!").unwrap(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
0xc2 /* DESELECT */ => {
|
0xc2 /* DESELECT */ => {
|
||||||
// Ignore the request
|
// Ignore the request
|
||||||
let mut command_error = [0x6A, 0x81];
|
let mut command_error = [0x6A, 0x81];
|
||||||
let amount = command_error.len();
|
transmit_slice(&mut command_error);
|
||||||
match NfcTag::transmit(&mut command_error, amount) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => writeln!(console, " -- tx error!").unwrap(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
0x02 | 0x03 /* APDU Prefix */ => {
|
0x02 | 0x03 /* APDU Prefix */ => {
|
||||||
// If the received packet is applet selection command (FIDO 2)
|
// If the received packet is applet selection command (FIDO 2)
|
||||||
if rx_buf[1] == 0x00 && rx_buf[2] == 0xa4 && rx_buf[3] == 0x04 {
|
if rx_buf[1] == 0x00 && rx_buf[2] == 0xa4 && rx_buf[3] == 0x04 {
|
||||||
// Vesion: "U2F_V2"
|
/// Vesion: "U2F_V2"
|
||||||
// let mut reply = [rx_buf[0], 0x55, 0x32, 0x46, 0x5f, 0x56, 0x32, 0x90, 0x00,];
|
// let mut reply = [rx_buf[0], 0x55, 0x32, 0x46, 0x5f, 0x56, 0x32, 0x90, 0x00,];
|
||||||
// Vesion: "FIDO_2_0"
|
/// Vesion: "FIDO_2_0"
|
||||||
let mut reply = [rx_buf[0], 0x46, 0x49, 0x44, 0x4f, 0x5f, 0x32, 0x5f, 0x30, 0x90, 0x00,];
|
let mut reply = [rx_buf[0], 0x46, 0x49, 0x44, 0x4f, 0x5f, 0x32, 0x5f, 0x30, 0x90, 0x00,];
|
||||||
let amount = reply.len();
|
transmit_slice(&mut reply);
|
||||||
match NfcTag::transmit(&mut reply, amount) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => writeln!(console, " -- tx error!").unwrap(),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let mut reply = [rx_buf[0], 0x90, 0x00];
|
let mut reply = [rx_buf[0], 0x90, 0x00];
|
||||||
let amount = reply.len();
|
transmit_slice(&mut reply);
|
||||||
match NfcTag::transmit(&mut reply, amount) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => writeln!(console, " -- tx error!").unwrap(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0x52 | 0x50 /* WUPA | Halt */ => {
|
0x52 | 0x50 /* WUPA | Halt */ => {
|
||||||
|
|||||||
Reference in New Issue
Block a user