From b8d0f59dcf7271167e8115b91b8210264e59568f Mon Sep 17 00:00:00 2001 From: Dylan Knutson Date: Fri, 26 Jun 2026 00:29:37 +0000 Subject: [PATCH] uart-service: add default_mctp_serial constructor Add MctpSerialService and default_mctp_serial(), the MctpSerialMedium twin of the existing DefaultService/default_smbusespi pair. The constructor hardcodes the canonical EC->SP serial reply context (source=EC_EID, destination=SP_EID, tag=0, medium_context=()), so serial consumers (the QEMU EC<->SP relay path) call one constructor instead of hand-assembling an MctpReplyContext. Enables mctp-rs/serial so the MctpSerialMedium type is available. Assisted-by: GitHub Copilot:claude-opus-4.8 --- uart-service/Cargo.toml | 2 +- uart-service/src/lib.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/uart-service/Cargo.toml b/uart-service/Cargo.toml index beb373559..2d8fcb938 100644 --- a/uart-service/Cargo.toml +++ b/uart-service/Cargo.toml @@ -18,7 +18,7 @@ embedded-services.workspace = true defmt = { workspace = true, optional = true } log = { workspace = true, optional = true } embassy-sync.workspace = true -mctp-rs = { workspace = true } +mctp-rs = { workspace = true, features = ["serial"] } embedded-io-async.workspace = true [features] diff --git a/uart-service/src/lib.rs b/uart-service/src/lib.rs index e3ecffe6a..eb62e6402 100644 --- a/uart-service/src/lib.rs +++ b/uart-service/src/lib.rs @@ -188,3 +188,29 @@ impl DefaultService { ) } } + +/// Type alias for `MctpSerialMedium` services (DSP0253-style framed +/// serial, no per-medium addressing). Used by the QEMU EC ↔ SP relay +/// path where the secure PL011 is bridged via a host PTY. +pub type MctpSerialService = Service; + +impl MctpSerialService { + /// Constructor for `MctpSerialMedium` services. Hardcodes the + /// EC ↔ SP reply context (`source = EC_EID`, `message_tag = 0`, + /// `medium_context = ()`). The `destination_endpoint_id` is + /// overridden per-response inside `process_response`, so the + /// `SP_EID` passed here is a placeholder. + pub fn default_mctp_serial(relay_handler: R) -> Result> { + Self::new( + relay_handler, + mctp_rs::MctpSerialMedium, + mctp_rs::MctpReplyContext { + source_endpoint_id: mctp_rs::EC_EID, + destination_endpoint_id: mctp_rs::SP_EID, + packet_sequence_number: mctp_rs::MctpSequenceNumber::new(0), + message_tag: mctp_rs::MctpMessageTag::try_from(0).map_err(Error::Serialize)?, + medium_context: (), + }, + ) + } +}