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
//! Crate card related structures
//! 

#![allow(dead_code)]

use enum_iterator::Sequence;

// #[repr(u8)]
// #[derive(Debug, Default, PartialEq, Sequence, Clone)]
// pub enum UemCardStandard {
//     #[default]
//     Iso14443a = 0x00,
//     Iso14443b = 0x01,
//     Iso15693 = 0x02,
// }

#[repr(u8)]
#[derive(Debug, Default, PartialEq, Sequence, Clone, Copy)]
pub enum UemCardBaudrates {
    #[default]
    Baud106kbps = 0b00,
    Baud212kbps = 0b01,
    Baud424kbps = 0b10,
    Baud848kbps = 0b11,
}

#[derive(Debug, Clone)]
/// ISO14443A card type object
pub struct UemCardIso14443A {
    /// Answer to request - 2 bytes
    pub atq: Vec<u8>,
    /// Select Acknowledge byte 
    pub sak: u8,
    /// Unique identifier - 4/7/10 bytes
    pub uid: Vec<u8>,
    /// Answer to select - returned after switching
    /// to T=CL mode
    pub ats: Vec<u8>,
}

#[derive(Debug, Clone)]
/// ISO14443B card type object
pub struct UemCardIso14443B {
    /// Buffer length identifier
    pub mbli: u8,
    /// Unique identifier - 4 bytes
    pub pupi: Vec<u8>,
    /// Application data - 4 bytes
    pub app_data: Vec<u8>,
    /// Protocol information - 3 bytes
    pub prot_info: Vec<u8>,
    /// Answer to request
    pub atq: Vec<u8>,
}

/// General placeholder for a card object
pub enum UemCard {
    Iso14443A(UemCardIso14443A),
    Iso14443B(UemCardIso14443B),
}

impl UemCard {
    /// Returns unique identifier of a card
    pub fn uid(&self) -> &Vec<u8> {
        match self {
            Self::Iso14443A(card) => &card.uid,
            Self::Iso14443B(card) => &card.pupi,
        }
    }
}