mctp_req/mctp-req.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2/*
3 * Simple MCTP example using Linux sockets: Get Endpoint ID requester.
4 *
5 * Copyright (c) 2024 Code Construct
6 */
7
8use mctp::{Eid, ReqChannel, MCTP_TYPE_CONTROL};
9use mctp_linux::MctpLinuxReq;
10
11fn main() -> std::io::Result<()> {
12 const EID: Eid = Eid(8);
13
14 // Create a new endpoint using the linux socket support
15 let mut ep = MctpLinuxReq::new(EID, None)?;
16
17 // for subsequent use of `ep`, we're just interacting with the
18 // mctp::ReqChannel trait, which is independent of the socket support
19
20 // Get Endpoint ID message: command 0x02, no data. Allow the MCTP stack
21 // to allocate an owned tag.
22 let tx_buf = vec![0x02u8];
23 ep.send(MCTP_TYPE_CONTROL, &tx_buf)?;
24
25 // Receive a response. We create a 16-byte vec to read into; ep.recv()
26 // will return the sub-slice containing just the response data.
27 let mut rx_buf = vec![0u8; 16];
28 let (typ, ic, rx_buf) = ep.recv(&mut rx_buf)?;
29
30 println!("response type {}, ic {:?}: {:x?}", typ, ic, rx_buf);
31
32 Ok(())
33}