Skip to main content

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    pub fn data(&self) -> &[u8] {
40        self.message.data()
41    }
42
43    /// Get a mutable reference to the data of the request (does not include netfn or command).
44    pub fn data_mut(&mut self) -> &mut [u8] {
45        self.message.data_mut()
46    }
47
48    /// Get the target for the request.
49    pub fn target(&self) -> RequestTargetAddress {
50        self.target
51    }
52}
53
54/// The target address of a request.
55#[derive(Copy, Clone, Debug, PartialEq)]
56pub enum RequestTargetAddress {
57    /// A logical unit on the BMC (Board Management Controller).
58    Bmc(LogicalUnit),
59    /// An address on the BMC or IPMB.
60    BmcOrIpmb(Address, Channel, LogicalUnit),
61}
62
63impl RequestTargetAddress {
64    /// Get the logical unit for the target address.
65    pub fn lun(&self) -> LogicalUnit {
66        match self {
67            RequestTargetAddress::Bmc(lun) | RequestTargetAddress::BmcOrIpmb(_, _, lun) => *lun,
68        }
69    }
70}