ipmi_rs_core/connection/
completion_code.rs

1#[derive(Clone, Copy, Debug, PartialEq)]
2pub enum ResponseUnavailableReason {
3    Unknown,
4    SDRInUpdate,
5    DeviceInFwUpdate,
6    BMCInitializing,
7}
8
9#[derive(Clone, Copy, Debug, PartialEq)]
10#[allow(missing_docs)]
11pub enum CompletionErrorCode {
12    NodeBusy,
13    InvalidCommand,
14    InvalidCommandForLun,
15    ProcessingTimeout,
16    OutOfSpace,
17    ReservationCancelledOrInvalidId,
18    RequestDataTruncated,
19    RequestDataLenInvalid,
20    RequestDataLengthLimitExceeded,
21    ParameterOutOfRange,
22    CannotReturnNumOfRequestedBytes,
23    RequestedDatapointNotPresent,
24    InvalidDataFieldInRequest,
25    CommandIllegalForSensorOrRecord,
26    ResponseUnavailable { reason: ResponseUnavailableReason },
27    CannotExecuteDuplicateRequest,
28    DestinationUnavailable,
29    InsufficientPrivilege,
30    CannotExecuteCommandInCurrentState,
31    SubFunctionDisabled,
32    Unspecified,
33    Oem(u8),
34    CommandSpecific(u8),
35    Reserved(u8),
36}
37
38impl TryFrom<u8> for CompletionErrorCode {
39    type Error = ();
40
41    fn try_from(value: u8) -> Result<Self, Self::Error> {
42        let value = match value {
43            0 => return Err(()),
44            0xC0 => Self::NodeBusy,
45            0xC1 => Self::InvalidCommand,
46            0xC2 => Self::InvalidCommandForLun,
47            0xC3 => Self::ProcessingTimeout,
48            0xC4 => Self::OutOfSpace,
49            0xC5 => Self::ReservationCancelledOrInvalidId,
50            0xC6 => Self::RequestDataTruncated,
51            0xC7 => Self::RequestDataLenInvalid,
52            0xC8 => Self::RequestDataLengthLimitExceeded,
53            0xC9 => Self::ParameterOutOfRange,
54            0xCA => Self::CannotReturnNumOfRequestedBytes,
55            0xCB => Self::RequestedDatapointNotPresent,
56            0xCC => Self::InvalidDataFieldInRequest,
57            0xCD => Self::CommandIllegalForSensorOrRecord,
58            0xCE => Self::ResponseUnavailable {
59                reason: ResponseUnavailableReason::Unknown,
60            },
61            0xCF => Self::CannotExecuteDuplicateRequest,
62            0xD0 => Self::ResponseUnavailable {
63                reason: ResponseUnavailableReason::SDRInUpdate,
64            },
65            0xD1 => Self::ResponseUnavailable {
66                reason: ResponseUnavailableReason::DeviceInFwUpdate,
67            },
68            0xD2 => Self::ResponseUnavailable {
69                reason: ResponseUnavailableReason::BMCInitializing,
70            },
71            0xD3 => Self::DestinationUnavailable,
72            0xD4 => Self::InsufficientPrivilege,
73            0xD5 => Self::CannotExecuteCommandInCurrentState,
74            0xD6 => Self::SubFunctionDisabled,
75            0xFF => Self::Unspecified,
76            0x01..=0x7E => Self::Oem(value),
77            0x80..=0xBE => Self::CommandSpecific(value),
78            v => Self::Reserved(v),
79        };
80
81        Ok(value)
82    }
83}
84
85impl CompletionErrorCode {
86    /// Whether this completion code is a reserved value or not.
87    pub fn is_reserved(&self) -> bool {
88        matches!(self, Self::Reserved(_))
89    }
90}