ipmi_rs_core/storage/sel/reserve.rs
1//! Reserve SEL Command
2//!
3//! Reference: IPMI 2.0 Specification, Section 31.4 "Reserve SEL Command"
4
5use std::num::NonZeroU16;
6
7use crate::connection::{IpmiCommand, Message, NetFn, NotEnoughData};
8
9/// Reserve SEL command.
10///
11/// This command is used to set the present 'owner' of the SEL, and is used
12/// to provide a mechanism to prevent SEL record deletion from being corrupted
13/// when multiple parties are accessing the SEL.
14///
15/// A reservation ID is required before clearing the SEL.
16///
17/// Reference: IPMI 2.0 Specification, Section 31.4, Table 31-4
18pub struct ReserveSel;
19
20impl IpmiCommand for ReserveSel {
21 type Output = NonZeroU16;
22 type Error = NotEnoughData;
23
24 /// Parse the response which contains the Reservation ID.
25 ///
26 /// Response data format (IPMI 2.0 Spec, Table 31-4):
27 /// - Byte 0: Reservation ID, LS Byte
28 /// - Byte 1: Reservation ID, MS Byte
29 fn parse_success_response(data: &[u8]) -> Result<Self::Output, Self::Error> {
30 if data.len() < 2 {
31 return Err(NotEnoughData);
32 }
33
34 let reservation_id = u16::from_le_bytes([data[0], data[1]]);
35 // Reservation ID of 0 is not valid per spec
36 NonZeroU16::new(reservation_id).ok_or(NotEnoughData)
37 }
38}
39
40impl From<ReserveSel> for Message {
41 /// Build the request message.
42 ///
43 /// Request format (IPMI 2.0 Spec, Table 31-4):
44 /// - No request data
45 fn from(_: ReserveSel) -> Self {
46 // NetFn: Storage (0x0A), Cmd: 0x42
47 Message::new_request(NetFn::Storage, 0x42, Vec::new())
48 }
49}