Skip to main content

leviathan_common/
lib.rs

1//! Common types and definitions shared between driver and user-mode applications
2//!
3//! This crate provides shared IOCTL definitions, structures, and constants
4//! that are used by both the kernel-mode driver and user-mode applications.
5
6#![no_std]
7
8/// Device interface GUID for finding the Leviathan device
9/// {12345678-1234-1234-1234-123456789ABC}
10pub const DEVICE_INTERFACE_GUID: [u8; 16] = [
11    0x78, 0x56, 0x34, 0x12, // Data1 (little-endian)
12    0x34, 0x12,             // Data2
13    0x34, 0x12,             // Data3
14    0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, // Data4
15];
16
17/// Custom device type for IOCTL codes
18pub const FILE_DEVICE_LEVIATHAN: u32 = 0x8000;
19
20/// IOCTL code definitions
21pub mod ioctl {
22    use super::FILE_DEVICE_LEVIATHAN;
23
24    /// Helper macro to create IOCTL codes
25    const fn ctl_code(device_type: u32, function: u32, method: u32, access: u32) -> u32 {
26        (device_type << 16) | (access << 14) | (function << 2) | method
27    }
28
29    // Method types
30    pub const METHOD_BUFFERED: u32 = 0;
31    pub const METHOD_IN_DIRECT: u32 = 1;
32    pub const METHOD_OUT_DIRECT: u32 = 2;
33    pub const METHOD_NEITHER: u32 = 3;
34
35    // Access types
36    pub const FILE_ANY_ACCESS: u32 = 0;
37    pub const FILE_READ_ACCESS: u32 = 1;
38    pub const FILE_WRITE_ACCESS: u32 = 2;
39
40    /// Get driver version string
41    pub const IOCTL_GET_VERSION: u32 =
42        ctl_code(FILE_DEVICE_LEVIATHAN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS);
43
44    /// Echo data back (input -> output)
45    pub const IOCTL_ECHO: u32 =
46        ctl_code(FILE_DEVICE_LEVIATHAN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS);
47
48    /// Get driver statistics
49    pub const IOCTL_GET_STATS: u32 =
50        ctl_code(FILE_DEVICE_LEVIATHAN, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS);
51}
52
53/// Driver statistics structure - shared between kernel and user mode
54#[repr(C)]
55#[derive(Debug, Clone, Copy, Default)]
56pub struct DriverStats {
57    pub read_count: u64,
58    pub write_count: u64,
59    pub ioctl_count: u64,
60    pub bytes_read: u64,
61    pub bytes_written: u64,
62}
63
64/// Version information structure
65#[repr(C)]
66#[derive(Debug, Clone, Copy)]
67pub struct VersionInfo {
68    pub major: u16,
69    pub minor: u16,
70    pub patch: u16,
71    pub build: u16,
72}
73
74impl VersionInfo {
75    pub const fn new(major: u16, minor: u16, patch: u16, build: u16) -> Self {
76        Self { major, minor, patch, build }
77    }
78}