use crate::mctp_traits::MCTPControlMessageRequest;
bitfield! {
pub struct MCTPControlMessageHeader(MSB0 [u8]);
u8;
pub rq, set_rq : 0, 0;
pub d, set_d: 1, 1;
rsvd, _: 2, 2;
pub instance_id, set_instance_id: 7, 3;
pub command_code, set_command_code: 15, 8;
}
#[derive(PartialEq, Debug, Clone, Copy, Eq)]
pub enum CommandCode {
Reserved = 0x00,
SetEndpointID = 0x01,
GetEndpointID = 0x02,
GetEndpointUUID = 0x03,
GetMCTPVersionSupport = 0x04,
GetMessageTypeSupport = 0x05,
GetVendorDefinedMessageSupport = 0x06,
ResolveEndpointID = 0x07,
AllocateEndpointIDs = 0x08,
RoutingInformationUpdate = 0x09,
GetRoutingTableEntries = 0x0A,
PrepareForEndpointDiscovery = 0x0B,
EndpointDiscovery = 0x0C,
DiscoveryNotify = 0x0D,
GetNetworkID = 0x0E,
QueryHop = 0x0F,
ResolveUUID = 0x10,
QueryRateLimit = 0x11,
RequestTXRateLimit = 0x12,
UpdateRateLimit = 0x13,
QuerySupportedInterfaces = 0x14,
Unknown = 0xFF,
}
impl From<u8> for CommandCode {
fn from(num: u8) -> CommandCode {
match num {
0x00 => CommandCode::Reserved,
0x01 => CommandCode::SetEndpointID,
0x02 => CommandCode::GetEndpointID,
0x03 => CommandCode::GetEndpointUUID,
0x04 => CommandCode::GetMCTPVersionSupport,
0x05 => CommandCode::GetMessageTypeSupport,
0x06 => CommandCode::GetVendorDefinedMessageSupport,
0x07 => CommandCode::ResolveEndpointID,
0x08 => CommandCode::AllocateEndpointIDs,
0x09 => CommandCode::RoutingInformationUpdate,
0x0A => CommandCode::GetRoutingTableEntries,
0x0B => CommandCode::PrepareForEndpointDiscovery,
0x0C => CommandCode::EndpointDiscovery,
0x0D => CommandCode::DiscoveryNotify,
0x0E => CommandCode::GetNetworkID,
0x0F => CommandCode::QueryHop,
0x10 => CommandCode::ResolveUUID,
0x11 => CommandCode::QueryRateLimit,
0x12 => CommandCode::RequestTXRateLimit,
0x13 => CommandCode::UpdateRateLimit,
0x14 => CommandCode::QuerySupportedInterfaces,
_ => CommandCode::Unknown,
}
}
}
#[derive(Debug, PartialEq)]
pub enum CompletionCode {
Success = 0x00,
Error = 0x01,
ErrorInvalidData = 0x02,
ErrorInvalidLength = 0x03,
ErrorNotReady = 0x04,
ErrorUnsupportedCmd = 0x05,
}
impl From<u8> for CompletionCode {
fn from(num: u8) -> CompletionCode {
match num {
0x00 => CompletionCode::Success,
0x01 => CompletionCode::Error,
0x02 => CompletionCode::ErrorInvalidData,
0x03 => CompletionCode::ErrorInvalidLength,
0x04 => CompletionCode::ErrorNotReady,
0x05 => CompletionCode::ErrorUnsupportedCmd,
_ => unreachable!(),
}
}
}
pub enum MCTPSetEndpointIDOperations {
SetEID = 0b00,
ForceEID = 0b01,
ResetEID = 0b10,
SetDiscoveredFlag = 0b11,
}
#[derive(PartialEq)]
pub enum MCTPSetEndpointIDAssignmentStatus {
Accpeted = 0b00,
Rejected = 0b01,
}
#[derive(PartialEq)]
pub enum MCTPSetEndpointIDAllocationStatus {
NoIDPool = 0b00,
RequiresAllocation = 0b01,
AlreadyAllocated = 0b10,
}
pub enum MCTPGetEndpointIDEndpointType {
Simple = 0b00,
Bus = 0b01,
}
pub enum MCTPGetEndpointIDEndpointIDType {
DynamicEID = 0b00,
StaticEID = 0b01,
StaticPresentMatchEID = 0b10,
StaticPresentNoMatchEID = 0b11,
}
pub enum MCTPVersionQuery {
MCTPBaseSpec = 0xFF,
MCTPControlProcMessage = 0x00,
DSP0241 = 0x01,
DSP0261 = 0x02,
DSP0261_2 = 0x03,
}
pub enum AllocateEndpointIDOperation {
AllocateEIDs = 0b00,
ForceAllocation = 0b01,
GetAllocationInformation = 0b10,
}
pub enum RoutingInformationUpdateEntryType {
SingleEndpointNotBridge = 0b00,
EIDRangeIncludeBridge = 0b01,
SingleEndpointBridge = 0b10,
EIDRangeNotIncludeBridge = 0b11,
}
impl MCTPControlMessageHeader<[u8; 2]> {
pub fn new(request: bool, datagram: bool, instance_id: u8, command_code: CommandCode) -> Self {
let buf = [0; 2];
let mut con_header = MCTPControlMessageHeader(buf);
con_header.set_rq(request as u8);
con_header.set_d(datagram as u8);
con_header.set_instance_id(instance_id);
con_header.set_command_code(command_code as u8);
con_header
}
pub fn new_from_buf(buf: [u8; 2]) -> Self {
MCTPControlMessageHeader(buf)
}
}
impl MCTPControlMessageRequest for MCTPControlMessageHeader<[u8; 2]> {
fn command_code(&self) -> u8 {
self.command_code()
}
}