Skip to content

Commit 531c3c9

Browse files
extract SEL constants, NVB constructors, and public re-exports
Replace magic 0x93/0x95/0x97 literals with SEL_CL1/CL2/CL3 constants throughout Cascade. Add NumberOfValidBits::anticollision() and select() constructors. Re-export NumberOfValidBits, Sak, and SEL constants from the type_a module.
1 parent acd6060 commit 531c3c9

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

src/type_a/anticol_select.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,37 @@ impl TryFrom<&[u8]> for UidCl {
4141
}
4242
}
4343

44+
/// SEL command codes for each cascade level (ISO14443-3 Table 6).
45+
pub const SEL_CL1: u8 = 0x93;
46+
pub const SEL_CL2: u8 = 0x95;
47+
pub const SEL_CL3: u8 = 0x97;
48+
4449
/// Table 6 - Coding of SEL
4550
#[derive(Debug, Clone)]
4651
#[repr(u8)]
4752
pub enum Cascade {
48-
Level1(UidCl) = 0x93,
49-
Level2(UidCl) = 0x95,
50-
Level3(UidCl) = 0x97,
53+
Level1(UidCl) = SEL_CL1,
54+
Level2(UidCl) = SEL_CL2,
55+
Level3(UidCl) = SEL_CL3,
5156
}
5257

5358
impl Cascade {
5459
pub(crate) fn check_sel(sel: u8) -> bool {
55-
sel == 0x93 || sel == 0x95 || sel == 0x97
60+
sel == SEL_CL1 || sel == SEL_CL2 || sel == SEL_CL3
5661
}
5762
pub(crate) fn try_from(sel: u8, uid_cl: &[u8; 5]) -> Result<Self, TypeAError> {
5863
match sel {
59-
0x93 => Ok(Cascade::Level1(UidCl::try_from(uid_cl)?)),
60-
0x95 => Ok(Cascade::Level2(UidCl::try_from(uid_cl)?)),
61-
0x97 => Ok(Cascade::Level3(UidCl::try_from(uid_cl)?)),
64+
SEL_CL1 => Ok(Cascade::Level1(UidCl::try_from(uid_cl)?)),
65+
SEL_CL2 => Ok(Cascade::Level2(UidCl::try_from(uid_cl)?)),
66+
SEL_CL3 => Ok(Cascade::Level3(UidCl::try_from(uid_cl)?)),
6267
_ => Err(TypeAError::UnknownOpcode(sel)),
6368
}
6469
}
6570
fn code(&self) -> u8 {
6671
match self {
67-
Cascade::Level1(_) => 0x93,
68-
Cascade::Level2(_) => 0x95,
69-
Cascade::Level3(_) => 0x97,
72+
Cascade::Level1(_) => SEL_CL1,
73+
Cascade::Level2(_) => SEL_CL2,
74+
Cascade::Level3(_) => SEL_CL3,
7075
}
7176
}
7277

@@ -128,6 +133,24 @@ impl TryFrom<u8> for NumberOfValidBits {
128133
}
129134

130135
impl NumberOfValidBits {
136+
/// NVB for initial anticollision: 2 bytes valid (SEL + NVB), no UID bits
137+
/// known yet. ISO14443-3 Table 7.
138+
pub fn anticollision() -> Self {
139+
Self {
140+
byte_cnt: BoundedU8::new(2).unwrap(),
141+
bit_cnt: BoundedU8::new(0).unwrap(),
142+
}
143+
}
144+
145+
/// NVB for SELECT: 7 bytes valid (SEL + NVB + UID[4] + BCC).
146+
/// ISO14443-3 Table 7.
147+
pub fn select() -> Self {
148+
Self {
149+
byte_cnt: BoundedU8::new(7).unwrap(),
150+
bit_cnt: BoundedU8::new(0).unwrap(),
151+
}
152+
}
153+
131154
pub(crate) fn has_40_data_bits(&self) -> bool {
132155
self.byte_cnt == 7 && self.bit_cnt == 0
133156
}

src/type_a/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ mod rats;
1313
mod sak;
1414
pub mod vec;
1515

16-
use anticol_select::{Cascade, NumberOfValidBits, UidCl};
16+
use anticol_select::{Cascade, UidCl};
17+
pub use anticol_select::{NumberOfValidBits, SEL_CL1, SEL_CL2, SEL_CL3};
1718
use atqa::AtqA;
1819
use ats::Ats;
1920
use crc::{append_crc_a, crc_a};
2021
use pps::{PpsParam, PpsResp};
2122
use rats::RatsParam;
22-
use sak::Sak;
23+
pub use sak::Sak;
2324
use vec::{FrameVec, VecExt};
2425

2526
#[derive(Debug, Clone, PartialEq, Eq)]

0 commit comments

Comments
 (0)