PyMCTP is a tool to craft/decode DMTF MCTP communication packets
Project description
PyMCTP
PyMCTP is a tool to craft/decode DMTF MCTP communication packets
Table of Contents
Introduction
PyMCTP is a Python library designed to craft and decode DMTF MCTP (Management Component Transport Protocol) communication packets. It provides tools and utilities to work with MCTP packets, making it easier to develop and test MCTP-based communication systems.
Features
- Utilizes Scapy, a powerful Python library used for interactive packet manipulation and network protocol analysis
- Supports crafting and decoding MCTP packets
- Easy-to-use API
- Extensible interface for Physical and Virtual device exercisers:
- Support for Total Phase Aardvark I2C exerciser
- Support for QEMU I2C-socket and I3C-chardev drivers
Currently Supported Protocols
- MCTP Control messages:
crafting
anddecoding
- PLDM Base and Type 2 messages:
decoding
- Very basic decoding of MCTP Vendor Defined Messages:
decoding
- IPMI
MasterWriteRead
messages:decoding
Installation
You can install PyMCTP using pip:
pip install pymctp
Usage
Decoding MCTP Packets
Here is a simple example of how to use the PyMCTP library to decode an MCTP Transport packet
from pymctp.layers import mctp
data = "01 0b 0a c5 00 00 0a 00 ff 01 01 0a 02 00 04 01 00"
bdata = bytes([int(x, 16) for x in data.split(" ")])
pkt = mctp.TransportHdrPacket(bdata)
print(f"{pkt.summary()}")
MCTP 0:5 (0B <-- 0A) (S:E) CTRL / CONTROL RSP (instance_id: 0, cmd_code=10, completion_code=0) / GetRoutingTableEntries (next_hdl=0xFF, cnt=1) [0x0A:1]
Here is a simple example of how to decode an MCTP-over-SMBUS packet:
from pymctp.layers import mctp
data = "20 0F 0C 65 01 0A 43 D0 00 1A 01 00 00 43 00 F4"
bdata = bytes([int(x, 16) for x in data.split(" ")])
pkt = mctp.SmbusTransportPacket(bdata)
print(f"{pkt.summary()}")
SMBUS (dst=0x20, src=0x65, byte_count=12, pec=0xF4) / MCTP 1:0 (0A <-- 43) (S:E) CTRL / CONTROL RSP (instance_id: 26, cmd_code=1, completion_code=0) / SetEndpointIDPacket (assign_status: accepted, eid_alloc_status: no_pool, eid_setting: 0x43, eid_pool_size: 0)
Crafting MCTP Packets
Here is an example of crafting a complete MCTP-over-SMBUS packet:
from pymctp.layers.mctp import SmbusTransport, TransportHdr
from pymctp.layers.mctp.control import SetEndpointID, SetEndpointIDOperation, ControlHdr
from pymctp.types import MsgTypes, Smbus7bitAddress
pkt = (
TransportHdr(src=10, dst=0, som=1, eom=1, to=1, tag=7, msg_type=MsgTypes.CTRL)
/ ControlHdr(rq=True, cmd_code=ContrlCmdCodes.SET_ENDPOINT_ID, instance_id=0x11)
/ SetEndpointID(op=SetEndpointIDOperation.SetEID, eid=29)
)
smbus_pkt = SmbusTransport(
dst_addr=Smbus7bitAddress(0x32),
src_addr=Smbus7bitAddress(0x10),
load=pkt
)
Here is the same packet decoded to show the raw payload that was generated:
>>> print(f"{hexdump(smbus_pkt)}")
0000 64 0F 0A 21 01 00 0A CF 00 91 01 00 1D FC d..!..........
None
>>> print(f"{smbus_pkt.summary()}")
SMBUS (dst=0x64, src=0x21, byte_count=10, pec=0xFC) / MCTP 0:7 (00 <-- 0A) (S:E:TO) CTRL / CONTROL REQ (instance_id: 17, cmd_code=1) / SetEndpointIDPacket (eid: 0x1D, op: set)
Once you have the fully crafted packet, you can convert it to a bytes object to get the raw payload:
>>> raw_bytes = raw(smbus_pkt)
>>> hexdump(raw_bytes)
0000 64 0F 0A 21 01 00 0A CF 00 91 01 00 1D FC d..!..........
>>> type(raw_bytes)
bytes
Contributing
Contributions are welcome! If you would like to contribute to PyMCTP, please follow these steps:
- Fork the repository
- Create a new branch (git checkout -b feature-branch)
- Make your changes
- Commit your changes (git commit -am 'Add new feature')
- Push to the branch (git push origin feature-branch)
- Create a new Pull Request
Please ensure that your code follows the project's coding standards and includes appropriate tests.
License
pymctp
is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymctp-0.1.2.tar.gz
.
File metadata
- Download URL: pymctp-0.1.2.tar.gz
- Upload date:
- Size: 42.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca9013d2ea3fc4d436829aacf4cc1e6074624964beed537a48a7776247b493ad |
|
MD5 | da544ab84e3794cb397b626a8d68f3c9 |
|
BLAKE2b-256 | 7fbf1e7f55313840a590ed198b8d4083dba0ca594952330a25044a621bcd7227 |
Provenance
The following attestation bundles were made for pymctp-0.1.2.tar.gz
:
Publisher:
publish.yml
on jls5177/pymctp
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pymctp-0.1.2.tar.gz
- Subject digest:
ca9013d2ea3fc4d436829aacf4cc1e6074624964beed537a48a7776247b493ad
- Sigstore transparency entry: 149448554
- Sigstore integration time:
- Predicate type:
File details
Details for the file pymctp-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: pymctp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 62.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be331d7e66ca789eeaa4d8593c44fb84ca3c6522b129a1cafa76f8aad7e81d2b |
|
MD5 | a93e3b17514ad3ded98b42ff8778596c |
|
BLAKE2b-256 | b2bdacddd08b1f5f047c8843f85015b56955ee4cfe7eb1e07e490c2dabded64d |
Provenance
The following attestation bundles were made for pymctp-0.1.2-py3-none-any.whl
:
Publisher:
publish.yml
on jls5177/pymctp
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pymctp-0.1.2-py3-none-any.whl
- Subject digest:
be331d7e66ca789eeaa4d8593c44fb84ca3c6522b129a1cafa76f8aad7e81d2b
- Sigstore transparency entry: 149448563
- Sigstore integration time:
- Predicate type: