1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// #[repr(u8)]
// #[derive(Copy, Clone, Debug)]
// pub enum MessageType {
// // REQUESTS
// // supported
// PowerOn = 0x62,
// PowerOff = 0x63,
// GetSlotStatus = 0x65,
// XfrBlock = 0x6f,
// Abort = 0x72,
// // unsupported
// GetParameters = 0x6c,
// ResetParameters = 0x6d,
// SetParameters = 0x61,
// Escape = 0x6b,// for vendor commands
// IccClock = 0x7e,
// T0Apdu = 0x6a,
// Secure = 0x69,
// Mechanical = 0x71,
// SetDataRateAndClockFrequency = 0x73,
// // RESPONSES
// // used
// DataBlock = 0x80,
// SlotStatus = 0x81,
// // unused
// Parameters = 0x82,
// // Escape = 0x83,
// DataRateAndClockFrequency = 0x84,
// }
// pub struct SlotStatus {
// seq: u8
// }
// impl SlotStatus {
// pub fn new(seq: u8) -> Self {
// Self { seq }
// }
// }
// impl From<SlotStatus> for Packet {
// fn from(slot_status: SlotStatus) -> Self {
// let mut buffer = [0u8; PACKET_SIZE];
// buffer[0] = 0x81;
// // buffer[1..5] = 0, no extra data
// // buffer[5] = 0, only one slot
// buffer[6] = slot_status.seq;
// // buffer[7] = 0, status
// // buffer[8] = 0, error
// // buffer[9] = 0, chain parameter, this is complete
// Packet { buffer }
// }
// }
// pub struct DataBlock<'a> {
// seq: u8,
// data: &'a [u8],
// }
// impl<'a> DataBlock<'a> {
// pub fn new(seq: u8, data: &'a [u8]) -> Self {
// assert!(data.len() + 10 <= PACKET_SIZE);
// Self { seq, data }
// }
// }
// impl<'a> From<DataBlock<'a>> for Packet {
// fn from(data_block: DataBlock) -> Self {
// let mut buffer = [0u8; PACKET_SIZE];
// let len = data_block.data.len();
// buffer[0] = 0x80;
// buffer[1..5].copy_from_slice(&len.to_le_bytes());
// // buffer[5] = 0, only one slot
// buffer[6] = data_block.seq;
// // buffer[7] = 0, status
// // buffer[8] = 0, error
// // buffer[9] = 0, chain parameter, this is complete
// buffer[10..][..len].copy_from_slice(data_block.data);
// Packet { buffer }
// }
// }
// impl core::convert::TryFrom<u8> for MessageType {
// type Error = ();
// fn try_from(message_type_byte: u8) -> core::result::Result<Self, ()> {
// Ok(match message_type_byte {
// 0x62 => Self::PowerOn,
// 0x63 => Self::PowerOff,
// 0x65 => Self::GetSlotStatus,
// 0x6f => Self::XfrBlock,
// 0x71 => Self::Mechanical,
// 0x80 => Self::DataBlock,
// 0x81 => Self::SlotStatus,
// _ => return Err(()),
// })
// }
// }