mctp_rs/
error.rs

1use crate::{
2    endpoint_id::EndpointId, mctp_completion_code::MctpCompletionCode,
3    mctp_message_tag::MctpMessageTag, mctp_sequence_number::MctpSequenceNumber, medium::MctpMedium,
4};
5
6#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
7#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8pub enum ProtocolError {
9    #[error("Expected start of message")]
10    ExpectedStartOfMessage,
11    #[error("Unexpected start of message")]
12    UnexpectedStartOfMessage,
13    #[error("Message tag mismatch")]
14    MessageTagMismatch(MctpMessageTag, MctpMessageTag),
15    #[error("Tag owner mismatch")]
16    TagOwnerMismatch(u8, u8),
17    #[error("Source endpoint id mismatch")]
18    SourceEndpointIdMismatch(EndpointId, EndpointId),
19    #[error("Unexpected packet sequence number")]
20    UnexpectedPacketSequenceNumber(MctpSequenceNumber, MctpSequenceNumber),
21    #[error("Received non-success completion code on request message")]
22    CompletionCodeOnRequestMessage(MctpCompletionCode),
23    #[error("Cannot send message while assembling")]
24    SendMessageWhileAssembling,
25    #[error("Cannot send message while receiving")]
26    SendingMessageWhileReceiving,
27}
28
29#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
30#[cfg_attr(feature = "defmt", derive(defmt::Format))]
31pub enum MctpPacketError<M: MctpMedium> {
32    HeaderParseError(&'static str),
33    CommandParseError(&'static str),
34    SerializeError(&'static str),
35    UnsupportedMessageType(u8),
36    ProtocolError(#[from] ProtocolError),
37    MediumError(M::Error),
38}
39
40// TODO - MctpPacketResult type alias
41pub type MctpPacketResult<T, Medium> = Result<T, MctpPacketError<Medium>>;