Struct MCTPSMBusContext

Source
pub struct MCTPSMBusContext<'m> { /* private fields */ }
Expand description

The global context for MCTP SMBus operations

Implementations§

Source§

impl<'m> MCTPSMBusContext<'m>

Source

pub fn new( address: u8, msg_types: &'m [u8], vendor_ids: &'m [VendorIDFormat], ) -> Self

Create a new SBMust context

address: The source address of this device.

Source

pub fn get_request(&self) -> &MCTPSMBusContextRequest

Get the underlying request protocol struct. This can be used to manually generate specific packets

Source

pub fn get_response(&self) -> &MCTPSMBusContextResponse

Get the underlying response protocol struct. This can be used to manually generate specific packets

Source

pub fn set_uuid(&mut self, uuid: &[u8])

Set the Unique Identifier for this device

Source

pub fn decode_packet<'a>( &self, packet: &'a [u8], ) -> Result<(MessageType, &'a [u8]), (MessageType, DecodeError)>

Decodes a MCTP packet.

packet: A buffer of the packet to get the headers from.

On success returns the MessageType and a reference into packet where the payload starts. On error returned the MessageType and a DecodeError.

Source

pub fn get_length( &self, packet: &[u8], ) -> Result<usize, (MessageType, DecodeError)>

Get the length of a packet

This function will just return the total byte count of the SMBus packet. This function purposely does almost no checks so that it can be run on a partial packet to determine how many bytes to read from a bus.

When returning the length the length is the byte count from the packet plus four. This is because the byte count does not include the “destination slave address”, “command code”, “byte count” or PEC. This means it’s the total number of bytes in the entire packet.

packet: A buffer of the packet to get the headers from.

On success returns the usize with the total length of the packet based on the length of the command code. On error returned the MessageType and a DecodeError.

Source

pub fn process_packet<'a>( &self, packet: &'a [u8], response_buf: &mut [u8], ) -> Result<((MessageType, &'a [u8]), Option<usize>), (MessageType, DecodeError)>

This function first decodes the packet supplied in the packet argument. This is done using the decode_packet() function. If this packet is a request then the response_buf is populated with a response to the request.

packet: A buffer of the packet to get the headers from.

On success the first two arguments are the same as the return from the decode_packet() function. The third argument is an option. If None then response_buf wasn’t changed because the packet was not a request. If Some it contains the length of the data written in the response_buf.

Auto Trait Implementations§

§

impl<'m> !Freeze for MCTPSMBusContext<'m>

§

impl<'m> !RefUnwindSafe for MCTPSMBusContext<'m>

§

impl<'m> Send for MCTPSMBusContext<'m>

§

impl<'m> !Sync for MCTPSMBusContext<'m>

§

impl<'m> Unpin for MCTPSMBusContext<'m>

§

impl<'m> UnwindSafe for MCTPSMBusContext<'m>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.