ipmi_rs_core/connection/
request.rs

1use crate::connection::{LogicalUnit, NetFn};
2
3use super::{Address, Channel, Message};
4
5/// An IPMI request message.
6pub struct Request {
7    target: RequestTargetAddress,
8    message: Message,
9}
10
11impl Request {
12    /// Create a new IPMI request message.
13    ///
14    /// The netfn for `request` should be of the `request` variant, see [`Message::new_request`].
15    // TODO: don't accept `Message` directly (could be malformed?)
16    pub const fn new(request: Message, target: RequestTargetAddress) -> Self {
17        Self {
18            target,
19            message: request,
20        }
21    }
22
23    /// Get the netfn for the request.
24    pub fn netfn(&self) -> NetFn {
25        self.message.netfn()
26    }
27
28    /// Get the raw value of the netfn for the request.
29    pub fn netfn_raw(&self) -> u8 {
30        self.message.netfn_raw()
31    }
32
33    /// Get the command value for the request.
34    pub fn cmd(&self) -> u8 {
35        self.message.cmd
36    }
37
38    /// Get a shared reference to the data of the request (does not include netfn or command).
39
40    pub fn data(&self) -> &[u8] {
41        self.message.data()
42    }
43
44    /// Get a mutable reference to the data of the request (does not include netfn or command).
45    pub fn data_mut(&mut self) -> &mut [u8] {
46        self.message.data_mut()
47    }
48
49    /// Get the target for the request.
50    pub fn target(&self) -> RequestTargetAddress {
51        self.target
52    }
53}
54
55/// The target address of a request.
56#[derive(Copy, Clone, Debug, PartialEq)]
57pub enum RequestTargetAddress {
58    /// A logical unit on the BMC (Board Management Controller).
59    Bmc(LogicalUnit),
60    /// An address on the BMC or IPMB.
61    BmcOrIpmb(Address, Channel, LogicalUnit),
62}
63
64impl RequestTargetAddress {
65    /// Get the logical unit for the target address.
66    pub fn lun(&self) -> LogicalUnit {
67        match self {
68            RequestTargetAddress::Bmc(lun) | RequestTargetAddress::BmcOrIpmb(_, _, lun) => *lun,
69        }
70    }
71}