pub const MODE_DATA: u8 = 0x06;
pub const BUFFER_ID: u8 = 0x00;
pub const CHUNK: usize = 0x4000;
pub const PROBE_LEN: usize = 0x100;
pub const REQUEST_SENSE_LEN: usize = 16;
pub const INQUIRY_ALLOC: u16 = 96;
pub const FEATURE_SERIAL: u16 = 0x0108;
pub const FEATURE_FIRMWARE_DATE: u16 = 0x010C;
pub const fn read_buffer(mode: u8, buffer_id: u8, off: u32, len: u32) -> [u8; 10] {
[
0x3C,
mode & 0x1f,
buffer_id,
(off >> 16) as u8,
(off >> 8) as u8,
off as u8,
(len >> 16) as u8,
(len >> 8) as u8,
len as u8,
0x00,
]
}
pub const fn write_buffer(mode: u8, buffer_id: u8, off: u32, len: u32) -> [u8; 10] {
[
0x3B,
mode & 0x1f,
buffer_id,
(off >> 16) as u8,
(off >> 8) as u8,
off as u8,
(len >> 16) as u8,
(len >> 8) as u8,
len as u8,
0x00,
]
}
pub const fn read_memory(off: u32, len: u32) -> [u8; 10] {
read_buffer(MODE_DATA, BUFFER_ID, off, len)
}
pub const fn inquiry(alloc: u16) -> [u8; 6] {
[0x12, 0x00, 0x00, (alloc >> 8) as u8, alloc as u8, 0x00]
}
pub const fn get_configuration(code: u16, alloc: u16) -> [u8; 10] {
[
0x46,
0x02,
(code >> 8) as u8,
code as u8,
0x00,
0x00,
0x00,
(alloc >> 8) as u8,
alloc as u8,
0x00,
]
}
pub const fn probe() -> [u8; 12] {
[
0x3C, 0x06, 0x00, 0x1E, 0xC0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
]
}
pub const fn test_unit_ready() -> [u8; 12] {
[0; 12]
}
pub const fn enter_update() -> [u8; 12] {
[
0x3B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00,
]
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Prepare {
ModeOne,
ModeSix67,
}
impl Prepare {
pub const fn command(self) -> [u8; 12] {
let mut command = enter_update();
if matches!(self, Self::ModeSix67) {
command[1] = 6;
command[2] = 0x67;
}
command
}
}
pub const fn transfer(off: u32, len: u16) -> [u8; 12] {
[
0x3B,
0x06,
0x00,
(off >> 16) as u8,
(off >> 8) as u8,
off as u8,
0x00,
(len >> 8) as u8,
len as u8,
0x00,
0x00,
0x00,
]
}
pub const fn finish() -> [u8; 12] {
[
0x3B, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x12,
]
}
pub const fn request_sense() -> [u8; 12] {
[
0x03,
0x00,
0x00,
0x00,
REQUEST_SENSE_LEN as u8,
0x80,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
]
}
#[cfg(test)]
#[path = "cdb_tests.rs"]
mod tests;