Skip to content

Small mctp-estack improvements #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mctp-estack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ log = { version = "0.4", optional = true }
crc = "3"
embedded-io-async = { workspace = true }
defmt = { workspace = true, optional = true }
embassy-sync = "0.6"
embassy-futures = "0.1"
embassy-sync = "0.7"
smbus-pec = { version = "1.0", features = ["lookup-table"] }
uuid = { version = "1.16.0", default-features = false }

Expand Down
22 changes: 14 additions & 8 deletions mctp-estack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
* Copyright (c) 2024-2025 Code Construct
*/

//! MCTP Stack
//! # MCTP Stack
//!
//! This crate provides a MCTP stack that can be embedded in other programs
//! or devices. A [`Stack`] handles MCTP message formatting and parsing, independent
//! of any particular MCTP transport binding.
//! or devices.
//!
//! A [`Router`] object lets programs use a [`Stack`] with
//! MCTP transport binding links. Each "port" handles transmitting and receiving
//! MCTP transport binding links. Each *Port* handles transmitting and receiving
//! packets independently. Messages destined for the stack's own EID will
//! be passed to applications.
//!
//! Applications can create [`router::RouterAsyncListener`] and [`router::RouterAsyncReqChannel`]
//! instances to communicate over MCTP. Those implement the standard [`mctp` crate](mctp)
//! async traits.
//!
//! The IO-less [`Stack`] handles MCTP message formatting and parsing, independent
//! of any particular MCTP transport binding.
//!
//! ## Configuration
//!
//! `mctp-estack` uses fixed sizes to be suitable on no-alloc platforms.
Expand All @@ -30,6 +32,8 @@

/// Re-exported so that callers can use the same `heapless` version.
///
/// `heapless::Vec` is currently an argument of `send_fill()` in transports.
///
/// TODO: will be replaced with something else, maybe `heapless::VecView` once
/// released.
pub use heapless::Vec;
Expand All @@ -39,15 +43,16 @@ use heapless::FnvIndexMap;
use mctp::{Eid, Error, MsgType, Result, Tag, TagValue};

pub mod control;
mod fragment;
pub mod fragment;
pub mod i2c;
mod reassemble;
pub mod router;
pub mod serial;
pub mod usb;
#[macro_use]
mod util;

pub use fragment::{Fragmenter, SendOutput};
use fragment::{Fragmenter, SendOutput};
use reassemble::Reassembler;
pub use router::Router;

Expand Down Expand Up @@ -80,8 +85,6 @@ pub(crate) const HEADER_LEN: usize = 4;
/// during the build. Those variables can be set in the `[env]`
/// section of `.cargo/config.toml`.
pub mod config {
use crate::get_build_var;

/// Maximum size of a MCTP message payload in bytes, default 1032
///
/// This does not include the MCTP type byte.
Expand Down Expand Up @@ -142,6 +145,9 @@ type Header = libmctp::base_packet::MCTPTransportHeader<[u8; HEADER_LEN]>;
#[derive(Debug)]
pub struct ReceiveHandle(usize);

/// Low level MCTP stack.
///
/// This is an IO-less MCTP stack, independent of any particular transport.
#[derive(Debug)]
pub struct Stack {
own_eid: Eid,
Expand Down
1 change: 0 additions & 1 deletion mctp-estack/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Takes a `usize` from a build-time environment variable.
///
/// If unset, the default is used. Can be used in a const context.
#[macro_export]
macro_rules! get_build_var {
($name:literal, $default:expr) => {{
match option_env!($name) {
Expand Down
2 changes: 1 addition & 1 deletion mctp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![forbid(unsafe_code)]
#![warn(missing_docs)]

//! Management Component Transport Protocol (MCTP)
//! # Management Component Transport Protocol (MCTP)
//!
//! This crate provides common types and traits for MCTP.
//! Transport implementations can implement [`ReqChannel`] and [`Listener`] to
Expand Down
3 changes: 2 additions & 1 deletion standalone/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use smol::Timer;

use mctp::{Eid, Error, MsgType, Result, Tag, TagValue};
use mctp_estack::{
serial::MctpSerialHandler, MctpMessage, ReceiveHandle, SendOutput, Stack,
fragment::SendOutput, serial::MctpSerialHandler, MctpMessage,
ReceiveHandle, Stack,
};

struct Inner<S: Read + Write> {
Expand Down