rust_ipmi/commands/command.rs
1use core::fmt;
2
3use crate::{err::CommandError, NetFn};
4
5#[derive(Clone)]
6pub enum Command {
7 Unknown(u8),
8 // *APP Commands*
9 // Reserved,
10 // GetDeviceId,
11 // ColdReset,
12 // WarmReset,
13 // GetSelfTestResults,
14 // ManufacturingTestOn,
15 // SetACPIPowerState,
16 // GetACPIPowerState,
17 // GetDeviceGUID,
18 // GetNetFnSupport,
19 // GetCommandSupport,
20 // GetCommandSubfunctionSupport,
21 // GetConfigurableCommandSubfunctions,
22 // Unassigned,
23 // SetCommandEnables,
24 // GetCommandEnables,
25 // SetCommandSubfunctionEnables,
26 // GetCommandSubfunctionEnables,
27 // GetOEMNetFnIANASupport,
28 // ResetWatchdogTimer,
29 // SetWatchdogTimer,
30 // GetWatchdogTimer,
31 // SetBMCGlobalEnables,
32 // GetBMCGlobalEnables,
33 // ClearMessageFlags,
34 // GetMessageFlags,
35 // EnableMessageChannelReceive,
36 // GetMessage,
37 // SendMessage,
38 // ReadEventMessageBuffer,
39 // GetBTInterfaceCapabilities,
40 // GetSystemGUID,
41 // SetSystemInfoParameters,
42 // GetSystemInfoParameters,
43 GetChannelAuthCapabilities,
44 // GetSessionChallenge,
45 // ActivateSession,
46 SetSessionPrivilegeLevel,
47 // CloseSession,
48 // GetAuthCode,
49 // SetChannelAccess,
50 // GetChannelAccess,
51 // GetChannelInfoCommand,
52 // SetUserAccessCommand,
53 // GetUserAccessCommand,
54 // SetUserName,
55 // GetUserNameCommand,
56 // SetUserPasswordCommand,
57 // ActivatePayload,
58 // DeactivatePayload,
59 // GetPayloadActivationStatus,
60 // GetPayloadInstanceInfo,
61 // SetUserPayloadAccess,
62 // GetUserPayloadAccess,
63 // GetChannelPayloadSupport,
64 // GetChannelPayloadVersion,
65 // GetChannelOEMPayloadInfo,
66 // MasterWriteRead,
67 GetChannelCipherSuites,
68 // SuspendResumePayloadEncryption,
69 // SetChannelSecurityKeys,
70 // GetSystemInterfaceCapabilities,
71 // FirmwareFirewallConfiguration,
72}
73
74impl fmt::Display for Command {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 match self {
77 Command::Unknown(x) => write!(f, "Unknown: {}", x),
78 Command::GetChannelAuthCapabilities => write!(f, "Get Channel Auth Capabilities"),
79 Command::SetSessionPrivilegeLevel => write!(f, "Set Session Privilege Level"),
80 Command::GetChannelCipherSuites => write!(f, "Get Channel Cipher Suites"),
81 }
82 }
83}
84
85type CommandAndNetfn = (u8, NetFn);
86
87impl TryFrom<CommandAndNetfn> for Command {
88 type Error = CommandError;
89
90 fn try_from(value: CommandAndNetfn) -> Result<Self, CommandError> {
91 let command_code = value.0;
92 let netfn = value.1;
93 match netfn {
94 NetFn::App => match command_code {
95 0x38 => Ok(Command::GetChannelAuthCapabilities),
96 0x54 => Ok(Command::GetChannelCipherSuites),
97 0x3b => Ok(Command::SetSessionPrivilegeLevel),
98 _ => Ok(Command::Unknown(command_code)), // _ => Err(CommandError::UnknownCommandCode(command_code))?,
99 },
100 _ => Ok(Command::Unknown(command_code)),
101 }
102 }
103}
104
105impl Into<u8> for Command {
106 fn into(self) -> u8 {
107 match self {
108 Command::GetChannelAuthCapabilities => 0x38,
109 Command::GetChannelCipherSuites => 0x54,
110 Command::SetSessionPrivilegeLevel => 0x3b,
111 // Command::Reserved => 0x00,
112 Command::Unknown(x) => x,
113 }
114 }
115}
116
117impl Into<CommandAndNetfn> for Command {
118 fn into(self) -> CommandAndNetfn {
119 match self {
120 Command::GetChannelAuthCapabilities => (0x38, NetFn::App),
121 Command::GetChannelCipherSuites => (0x54, NetFn::App),
122 Command::SetSessionPrivilegeLevel => (0x3b, NetFn::App),
123 // Command::Reserved => (0x00, NetFn::Unknown(0)),
124 Command::Unknown(x) => (x, NetFn::Unknown(0)),
125 }
126 }
127}