hyperv_ic_protocol/
lib.rs1#![forbid(unsafe_code)]
7
8pub mod heartbeat;
9pub mod kvp;
10pub mod shutdown;
11pub mod timesync;
12pub mod vss;
13
14use bitfield_struct::bitfield;
15use open_enum::open_enum;
16use std::fmt::Display;
17use zerocopy::FromBytes;
18use zerocopy::Immutable;
19use zerocopy::IntoBytes;
20use zerocopy::KnownLayout;
21
22pub const MAX_MESSAGE_SIZE: usize = 13312;
24
25#[repr(C)]
27#[derive(
28 Debug, Copy, Clone, IntoBytes, Immutable, KnownLayout, FromBytes, PartialEq, Eq, PartialOrd, Ord,
29)]
30pub struct Version {
31 pub major: u16,
33 pub minor: u16,
35}
36
37pub const FRAMEWORK_VERSION_1: Version = Version::new(1, 0);
39pub const FRAMEWORK_VERSION_3: Version = Version::new(3, 0);
41
42impl Version {
43 pub const fn new(major: u16, minor: u16) -> Self {
45 Version { major, minor }
46 }
47}
48
49impl Display for Version {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 write!(f, "{}.{}", self.major, self.minor)
52 }
53}
54
55open_enum! {
56 #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
58 pub enum MessageType: u16 {
59 VERSION_NEGOTIATION = 0,
61 HEARTBEAT = 1,
63 KVP_EXCHANGE = 2,
65 SHUTDOWN = 3,
67 TIME_SYNC = 4,
69 VSS = 5,
71 RDV = 6,
73 GUEST_INTERFACE = 7,
75 VM_SESSION = 8,
77 }
78}
79
80#[repr(C)]
82#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Debug)]
83pub struct Header {
84 pub framework_version: Version,
86 pub message_type: MessageType,
88 pub message_version: Version,
90 pub message_size: u16,
92 pub status: Status,
94 pub transaction_id: u8,
96 pub flags: HeaderFlags,
98 pub reserved: [u8; 2],
100}
101
102open_enum! {
103 #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
105 pub enum Status: u32 {
106 SUCCESS = 0,
108 NO_MORE_ITEMS = 0x80070103,
110 FAIL = 0x80004005,
112 NOT_SUPPORTED = 0x80070032,
114 NOT_FOUND = 0x80041002,
116 }
117}
118
119#[bitfield(u8)]
121#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
122pub struct HeaderFlags {
123 pub transaction: bool,
125 pub request: bool,
127 pub response: bool,
129 #[bits(5)]
131 _reserved: u8,
132}
133
134#[repr(C)]
136#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
137pub struct NegotiateMessage {
138 pub framework_version_count: u16,
141 pub message_version_count: u16,
144 pub reserved: u32,
146}