use crate::error::{ParseError, Result};
use bitreader::BitReader;
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct TID {
pub xtid: bool,
pub security: bool,
pub file: bool,
pub mdid: u16,
pub tmid: u16,
}
pub fn decode_tid(data: &[u8]) -> Result<TID> {
let mut reader = BitReader::new(data);
if reader.read_u8(8)? != 0xE2 {
return Err(Box::new(ParseError()));
}
Ok(TID {
xtid: reader.read_bool()?,
security: reader.read_bool()?,
file: reader.read_bool()?,
mdid: reader.read_u16(9)?,
tmid: reader.read_u16(12)?,
})
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct XTIDHeader {
pub extended_header: bool,
pub user_memory_permalock: bool,
pub blockwrite_blockerase: bool,
pub optional_command_support: bool,
pub serial_size: u16,
}
pub fn decode_xtid_header(data: &[u8]) -> Result<XTIDHeader> {
let mut reader = BitReader::new(data);
let extended_header = reader.read_bool()?;
let _rfu = reader.read_u16(9)?;
let user_memory_permalock = reader.read_bool()?;
let blockwrite_blockerase = reader.read_bool()?;
let optional_command_support = reader.read_bool()?;
let mut serial: u16 = reader.read_u16(3)?;
if serial != 0 {
serial = 48 + 16 * (serial - 1);
}
Ok(XTIDHeader {
extended_header,
user_memory_permalock,
blockwrite_blockerase,
optional_command_support,
serial_size: serial,
})
}
pub fn mdid_name(mdid: &u16) -> &str {
match mdid {
#![allow(clippy::unreadable_literal)]
0b000000001 => "Impinj",
0b000000010 => "Texas Instruments",
0b000000011 => "Alien Technology",
0b000000100 => "Intelleflex",
0b000000101 => "Atmel",
0b000000110 => "NXP Semiconductors",
0b000000111 => "ST Microelectronics",
0b000001000 => "EP Microelectronics",
0b000001001 => "Motorola (formerly Symbol Technologies)",
0b000001010 => "Sentech Snd Bhd",
0b000001011 => "EM Microelectronics",
0b000001100 => "Renesas Technology Corp.",
0b000001101 => "Mstar",
0b000001110 => "Tyco International",
0b000001111 => "Quanray Electronics",
0b000010000 => "Fujitsu",
0b000010001 => "LSIS",
0b000010010 => "CAEN RFID srl",
0b000010011 => "Productivity Engineering GmbH",
0b000010100 => "Federal Electric Corp.",
0b000010101 => "ON Semiconductor",
0b000010110 => "Ramtron",
0b000010111 => "Tego",
0b000011000 => "Ceitec S.A.",
0b000011001 => "CPA Wernher von Braun",
0b000011010 => "TransCore",
0b000011011 => "Nationz",
0b000011100 => "Invengo",
0b000011101 => "Kiloway",
0b000011110 => "Longjing Microelectronics Co. Ltd.",
0b000011111 => "Chipus Microelectronics",
0b000100000 => "ORIDAO",
0b000100001 => "Maintag",
0b000100010 => "Yangzhou Daoyuan Microelectronics Co. Ltd",
0b000100011 => "Gate Elektronik",
0b000100100 => "RFMicron, Inc.",
0b000100101 => "RST-Invent LLC",
0b000100110 => "Crystone Technology",
0b000100111 => "Shanghai Fudan Microelectronics Group ",
0b000101000 => "Farsens",
0b000101001 => "Giesecke & Devrient GmbH",
0b000101010 => "AWID",
0b000101011 => "Unitec Semicondutores S/A",
0b000101100 => "Q-Free ASA",
0b000101101 => "Valid S.A.",
0b000101110 => "Fraunhofer IPMS",
0b000101111 => "ams AG",
0b000110000 => "Angstrem JSC",
0b000110001 => "Honeywell",
0b000110010 => "Huada Semiconductor Co. Ltd (HDSC)",
0b000110011 => "Lapis Semiconductor Co., Ltd.",
0b000110100 => "PJSC Mikron",
0b000110101 => "Hangzhou Landa Microelectronics Co., Ltd.",
0b000110110 => "Nanjing NARI Micro-Electronic Technology Co., Ltd.",
0b000110111 => "Southwest Integrated Circuit Design Co., Ltd.",
0b000111000 => "Silictec",
0b000111001 => "Nation RFID",
0b000111010 => "Asygn",
0b000111011 => "Suzhou HCTech Technology Co., Ltd.",
0b000111100 => "AXEM Technology",
_unknown => "Unknown",
}
}
pub fn tmid_name(mdid: u16, tmid: u16) -> &'static str {
match (mdid, tmid) {
(0x1, 0x100) => "Monza 4D",
(0x1, 0x105) => "Monza 4QT",
(0x1, 0x10C) => "Monza 4E",
(0x1, 0x130) => "Monza 5",
(0x1, 0x160) => "Monza R6",
(0x3, 0x412) => "Higgs-3",
(0x3, 0x414) => "Higgs-4",
(0x6, 0x003) => "UCODE G2XM",
(0x6, 0x004) => "UCODE G2XL",
(0x6, 0x806) => "UCODE G2iL",
(0x6, 0x807) => "UCODE G2iL+",
(0x6, 0x80A) => "UCODE G2iM",
(0x6, 0x80D) => "UCODE i2c",
(0x6, 0x88D) => "UCODE i2c",
(0x6, 0x810) => "UCODE 7",
(0x6, 0x890) => "UCODE 7",
(0x6, 0x891) => "UCODE 7m",
(0x6, 0x894) => "UCODE 8",
(0x6, 0x906) => "UCODE G2iL",
(0x6, 0x907) => "UCODE G2iL+",
(0x6, 0x994) => "UCODE 8m",
(0x6, 0xB06) => "UCODE G2iL",
(0x6, 0xB07) => "UCODE G2iL+",
(0x24, 0x401) => "Magnus S2",
(0x24, 0x402) => "Magnus S2",
(0x24, 0x403) => "Magnus S2",
_unknown => "Unknown"
}
}