Skip to content

Commit c689680

Browse files
committed
standalone: MCTP type vendor prefix for echo/req
This matches the format used in recent Linux mctp userspace utils. Signed-off-by: Matt Johnston <[email protected]>
1 parent 0ae21b3 commit c689680

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

standalone/examples/echo.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct Args {
3636
serial: String,
3737
}
3838

39+
const REQ_MSG_TYPE: MsgType = mctp::MCTP_TYPE_VENDOR_PCIE;
40+
const VENDOR_SUBTYPE_ECHO: [u8; 3] = [0xcc, 0xde, 0xf0];
41+
3942
fn main() -> Result<()> {
4043
let args: Args = argh::from_env();
4144

@@ -58,15 +61,24 @@ fn main() -> Result<()> {
5861
let s = embedded_io_adapters::futures_03::FromFutures::new(s);
5962

6063
let eid = Eid(13);
61-
let typ = MsgType(1);
64+
let typ = REQ_MSG_TYPE;
6265
let mut l = MctpSerialListener::new(eid, typ, s);
6366

6467
let mut buf = [0u8; 2000];
6568

6669
loop {
6770
let r = l.recv(&mut buf);
71+
6872
match r {
69-
Ok((_typ, _ic, buf, mut resp)) => {
73+
Ok((typ, _ic, buf, mut resp)) => {
74+
assert!(typ == REQ_MSG_TYPE);
75+
if !buf.starts_with(&VENDOR_SUBTYPE_ECHO) {
76+
warn!(
77+
"Bad vendor prefix: {:02x?}",
78+
&buf[..VENDOR_SUBTYPE_ECHO.len()]
79+
);
80+
}
81+
7082
info!("Received OK {buf:02x?}");
7183
let r = resp.send(buf);
7284
if let Err(e) = r {

standalone/examples/req.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ struct Args {
3939
serial: String,
4040
}
4141

42-
const REQ_MSG_TYPE: MsgType = MsgType(1);
42+
const REQ_MSG_TYPE: MsgType = mctp::MCTP_TYPE_VENDOR_PCIE;
43+
const VENDOR_SUBTYPE_ECHO: [u8; 3] = [0xcc, 0xde, 0xf0];
4344

4445
fn main() -> Result<()> {
4546
let args: Args = argh::from_env();
@@ -80,7 +81,7 @@ fn main() -> Result<()> {
8081
let l = (l as usize) % 24;
8182
let payload = &payload[..l];
8283

83-
if let Err(e) = req(&mut ch, REQ_MSG_TYPE, &payload, args.fatal) {
84+
if let Err(e) = req(&mut ch, payload, args.fatal) {
8485
warn!("Error {e:?}");
8586
if args.fatal {
8687
bail!("Response error.")
@@ -89,13 +90,14 @@ fn main() -> Result<()> {
8990
}
9091
}
9192

92-
fn req(
93-
ch: &mut impl ReqChannel,
94-
typ: MsgType,
95-
payload: &[u8],
96-
fatal: bool,
97-
) -> Result<()> {
98-
ch.send(typ, &payload).context("Error sending")?;
93+
fn req(ch: &mut impl ReqChannel, payload: &[u8], fatal: bool) -> Result<()> {
94+
let typ = REQ_MSG_TYPE;
95+
// Vendor prefix
96+
let mut p = Vec::from(VENDOR_SUBTYPE_ECHO);
97+
p.extend_from_slice(payload);
98+
let payload = &p;
99+
100+
ch.send(typ, payload).context("Error sending")?;
99101

100102
info!("Sent OK");
101103

@@ -130,12 +132,12 @@ fn serial_corner_cases(ch: &mut impl ReqChannel) -> Result<()> {
130132
}
131133

132134
// Unmodified
133-
req(ch, REQ_MSG_TYPE, &b, true)?;
135+
req(ch, &b, true)?;
134136

135137
let mut addescape = |n| {
136138
if let Some(c) = b.get_mut(n) {
137139
*c = ESCAPE;
138-
req(ch, REQ_MSG_TYPE, &b, true)?;
140+
req(ch, &b, true)?;
139141
}
140142
anyhow::Result::<_>::Ok(())
141143
};

0 commit comments

Comments
 (0)