[−][src]Module libmctp::smbus
The SMBus specific protocol implementation.
This should be used when you want to communicate via MCTP over SMBus/I2C.
In order to use this you first need to create the main context struct. Then
the get_request()
/get_response()
functions can be used to issue raw
commands.
The libmctp library will not send the packets, instead it will create a buffer containing the data to be sent. This allows you to use your own SMBus/I2C implementation.
Generate a MCTP request
use libmctp::control_packet::MCTPVersionQuery; use libmctp::smbus::{MCTPSMBusContext, VendorIDFormat}; // The address of this device const MY_ID: u8 = 0x23; // Support vendor defined protocol 0x7E let msg_types: [u8; 1] = [0x7E]; // Specify a PCI vendor ID that we support let vendor_ids = [VendorIDFormat { // PCI Vendor ID format: 0x00, // PCI VID data: 0x1414, // Extra data numeric_value: 4, }]; let ctx = MCTPSMBusContext::new(MY_ID, &msg_types, &vendor_ids); let mut buf: [u8; 32] = [0; 32]; const DEST_ID: u8 = 0x34; let len = ctx.get_request().get_mctp_version_support( DEST_ID, MCTPVersionQuery::MCTPBaseSpec, &mut buf, ); // Send the request buf of length len via SMBus
Generate a MCTP response
use libmctp::control_packet::{CompletionCode, MCTPVersionQuery}; use libmctp::smbus::{MCTPSMBusContext, VendorIDFormat}; // The address of this device const MY_ID: u8 = 0x23; // Support vendor defined protocol 0x7E let msg_types: [u8; 1] = [0x7E]; // Specify a PCI vendor ID that we support let vendor_ids = [VendorIDFormat { // PCI Vendor ID format: 0x00, // PCI VID data: 0x1414, // Extra data numeric_value: 4, }]; let ctx = MCTPSMBusContext::new(MY_ID, &msg_types, &vendor_ids); let mut buf: [u8; 32] = [0; 32]; const DEST_ID: u8 = 0x34; let len = ctx.get_response().get_mctp_version_support( CompletionCode::Success, DEST_ID, &mut buf, ); // Send the response buf of length len via SMBus
Decode a packet received
use libmctp::control_packet::MCTPVersionQuery; use libmctp::smbus::{MCTPSMBusContext, VendorIDFormat}; // The address of this device const MY_ID: u8 = 0x23; // Support vendor defined protocol 0x7E let msg_types: [u8; 1] = [0x7E]; // Specify a PCI vendor ID that we support let vendor_ids = [VendorIDFormat { // PCI Vendor ID format: 0x00, // PCI VID data: 0x1414, // Extra data numeric_value: 4, }]; let ctx = MCTPSMBusContext::new(MY_ID, &msg_types, &vendor_ids); let mut buf: [u8; 32] = [0; 32]; // Receive data into buf from SMBus let ret = ctx.decode_packet(&buf); // Match and decode the returned value
Process a request to generate a response
use libmctp::control_packet::MCTPVersionQuery; use libmctp::smbus::{MCTPSMBusContext, VendorIDFormat}; // The address of this device const MY_ID: u8 = 0x23; // Support vendor defined protocol 0x7E let msg_types: [u8; 1] = [0x7E]; // Specify a PCI vendor ID that we support let vendor_ids = [VendorIDFormat { // PCI Vendor ID format: 0x00, // PCI VID data: 0x1414, // Extra data numeric_value: 4, }]; let ctx = MCTPSMBusContext::new(MY_ID, &msg_types, &vendor_ids); let mut buf_request: [u8; 32] = [0; 32]; let mut buf_response: [u8; 32] = [0; 32]; // Receive data into buf_request from SMBus let ret = ctx.process_packet(&buf_request, &mut buf_response); // Match and decode the returned value
Structs
MCTPSMBusContext | The global context for MCTP SMBus operations |
VendorIDFormat | The Vendor ID Format as described in table 21 |