Skip to content

ieee1722: Initial implementation of parts of IEEE 1722. - #5185

Open
nayakned wants to merge 7 commits into
secdev:masterfrom
nayakned:add_proto/avtp
Open

nayakned wants to merge 7 commits into
secdev:masterfrom
nayakned:add_proto/avtp

Conversation

@nayakned

@nayakned nayakned commented Sep 18, 2026 •

Copy link
Copy Markdown

AI Assisted: no for the implementation/copilot for unit tests.

  • Implemented the Chapter 9 of the IEEE 1722-2025 spec.
  • Added unit test cases for dissecting and generating packets belonging to this protocol

Checklist :

  • Check the contribution guide at https://github.com/secdev/scapy/blob/master/CONTRIBUTING.md (esp. section submitting-pull-requests) ✅
  • Have good commit hygiene. They must have the AI-Assisted tag as explained in the contributing guide. Please squash commits that belong together, and split commits that contain multiple features. ✅
  • AI: You must make sure that you understood the internal concepts of Scapy and have good test coverage (like >90%). Please review ALL the code you generated. ✅
  • Add unit tests or explain why they are not relevant. ✅
  • If the PR is still not finished, please create a Draft Pull Request ✅
  • If this PR contains more than 500 lines of code (excluding unit tests), consider splitting it. -> IEEE 1722 aka Audio/Video Transport Protocol (AVTP) specifies a large number of serialization formats over Ethernet. In this PR only the serialization formats mentioned in the Chapter 9 (these are the ones relevant for automotive usecases) are implemented. While the number of lines may seem large, the PR only has features/serialization formats belonging together.
  • New protocols: I considered interoperability tests with existing packages or utilities to ensure conformity of a newly generated protocol ✅ Tested conformance along with Ethernet, UDP/IP

Description

IEEE 1722 specifies the Audio/Video Transport Protocol (AVTP) along with several serialization formats for data which can be transported over Ethernet (e.g., various audio formats, video formats etc.). The 2016 version of the specification extended the spec to also include so-called control formats including automotive fieldbus frames, e.g., CAN, LIN, FlexRay etc. Now the recent 2025 version also includes serialization formats for I2C, SPI etc.

In this PR, we focus on the AVTP control formats (the ones described in the Chapter 6 of the IEEE 1722 spec.). This is not an exhaustive implementation of IEEE 1722 as we do not focus on the audio/video formats. The reason for contributing this to the upstream project is that we see currently traction for using IEEE 1722. We (myself and a few like-minded colleagues) are working on integrating this protocol into open source projects and encourage adoption. We are also working on:

@nayakned
nayakned marked this pull request as ready for review September 18, 2026 13:54

@polybassa polybassa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focus on simplicity and Scapy-likeness: the protocol fields themselves are mostly fine, but ACF framing, UDP encapsulation, and duplicated post_build/extract_padding should live in the packet hierarchy once.

Main priorities from this review: ACF boundary handling → I2C length fix → UDP wrapper layer → public version classes → collapse duplicated ACF plumbing.

This review was written with the help of AI (ChatGPT).

Comment thread scapy/contrib/ieee1722.py
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread test/contrib/ieee1722.uts Outdated
@polybassa

Copy link
Copy Markdown
Contributor

Thanks for your PR

nayakned added a commit to nayakned/scapy that referenced this pull request Sep 22, 2026
- Removed unused class AvtpHeaderVersion
- Added AvtpUdpEncapsulation as an independent layer
- Use of AvtpStreamType instead of flattening the enum
- Removed usage of "_underlayer" to check for UDP
- Made private hidden classes now public and used match_subclass
- Reduced bolier plate code for ACF data formats
- Added additional unit tests for regression

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
nayakned added a commit to nayakned/scapy that referenced this pull request Sep 22, 2026
- Removed unused class AvtpHeaderVersion
- Added AvtpUdpEncapsulation as an independent layer
- Use of AvtpStreamType instead of flattening the enum
- Removed usage of "_underlayer" to check for UDP
- Made private hidden classes now public and used match_subclass
- Reduced bolier plate code for ACF data formats
- Added additional unit tests for regression

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
nayakned added a commit to nayakned/scapy that referenced this pull request Sep 22, 2026
- Removed unused class AvtpHeaderVersion
- Added AvtpUdpEncapsulation as an independent layer
- Use of AvtpStreamType instead of flattening the enum
- Removed usage of "_underlayer" to check for UDP
- Made private hidden classes now public and used match_subclass
- Reduced bolier plate code for ACF data formats
- Added additional unit tests for regression
- AI-Assisted: no
@nayakned

Copy link
Copy Markdown
Author

Thanks for your PR

Thanks for the exhaustive review. Got to know more about Scapy with this PR.
I have addressed most of your findings.
Perhaps where you can help me:

  • Please have an explicit look at how AvtpAcfTscfHeader and AvtpAcfNtscfHeader and their versions for their "Scapyness".
  • AvtpAcfI2CHeader also contains the payload. So I am toying with the idea to call it just AvtpAcfI2C. Same for the brief format.

Let me know if you have further findings or want me to rearrange the commit history.

@nayakned
nayakned requested a review from polybassa September 22, 2026 02:59

@polybassa polybassa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on the latest tip (9f7e707): the structural cleanup looks good. Two concrete P1 regressions remain.

This review was written with the help of AI (ChatGPT).

Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
nayakned added a commit to nayakned/scapy that referenced this pull request Sep 22, 2026
- Fixed appending of payload to packet in AvtpCommonControlHeader.
- Fixed padding arithmetic of AvtpAcfHeader
- Renamed AvtpAcfI2CHeader to AvtpAcfI2CMessage
- Renamed AvtpAcfI2CBriefHeader to AvtpAcfI2CBriefMessage
- AI-Assisted: no
@nayakned
nayakned requested a review from polybassa September 22, 2026 12:30
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py
Comment thread test/contrib/ieee1722.uts Outdated
Comment thread test/contrib/ieee1722.uts Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
name="mode",
default=AncMode.ANC_8BIT,
size=2,
enum={i.name: i.value for i in AncMode},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Pass Enum classes directly.

Where code still contains:

enum={i.name: i.value for i in AncMode}

prefer:

enum=AncMode

Scapy enum fields already support Python Enum classes. This is already done correctly in several other places in the PR, so the remaining instances should be made consistent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented as suggested.

Comment thread scapy/contrib/ieee1722.py Outdated
@polybassa

Copy link
Copy Markdown
Contributor

Thanks for the PR, just a few more comments

nayakned added a commit to nayakned/scapy that referenced this pull request Sep 25, 2026
- Added a serializable variant of AvtpCommonHeader as a fallback for unknown variants
- Modified dispatch_hooks to avoid silent falling back to version 0
- Added missing fields to AvtpCommonStreamHeaderV0
- Incomplete header classes (other than AvtpCommonHeader) are now private classes
- Improved unit test cases to check for unknown versions and UDP round trips
- AI-Assisted: no
@nayakned

Copy link
Copy Markdown
Author

@polybassa I have often discussed with my colleagues the best way to model the class/packets for this protocol.
Personally, I prefer to align with the specification. It is not our job to fix issues in the specification.
Therefore, I prefer to keep the packet classes AvtpCommon*, even though they will never be seen in a standalone correct system. This allows future developers to inherit or extend these classes or the IEEE 1722 module.

I hope exposing only serializable classes and making non-serializable classes (with the exception of AvtpCommonHeader) is an acceptable solution.

@nayakned
nayakned requested a review from polybassa September 25, 2026 06:22

@polybassa polybassa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work. I think we are almost there.

Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py
Comment thread scapy/contrib/ieee1722.py Outdated
Comment thread scapy/contrib/ieee1722.py Outdated
def dispatch_hook(cls, pkt=None, **kargs):
if "version" in kargs:
version = kargs["version"]
elif pkt:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Length check

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added length checks as suggested.

Comment thread scapy/contrib/ieee1722.py
Comment thread scapy/contrib/ieee1722.py Outdated
@polybassa polybassa self-assigned this Sep 30, 2026
@nayakned
nayakned requested a review from polybassa September 30, 2026 16:27
@polybassa

Copy link
Copy Markdown
Contributor

Please fix the AI-Assisted trailer check.

nayakned added a commit to nayakned/scapy that referenced this pull request Sep 30, 2026
- Removed unused class AvtpHeaderVersion
- Added AvtpUdpEncapsulation as an independent layer
- Use of AvtpStreamType instead of flattening the enum
- Removed usage of "_underlayer" to check for UDP
- Made private hidden classes now public and used match_subclass
- Reduced bolier plate code for ACF data formats
- Added additional unit tests for regression
- AI-Assisted: no
nayakned added a commit to nayakned/scapy that referenced this pull request Sep 30, 2026
- Fixed appending of payload to packet in AvtpCommonControlHeader.
- Fixed padding arithmetic of AvtpAcfHeader
- Renamed AvtpAcfI2CHeader to AvtpAcfI2CMessage
- Renamed AvtpAcfI2CBriefHeader to AvtpAcfI2CBriefMessage
- AI-Assisted: no
nayakned added a commit to nayakned/scapy that referenced this pull request Sep 30, 2026
- Added a serializable variant of AvtpCommonHeader as a fallback for unknown variants
- Modified dispatch_hooks to avoid silent falling back to version 0
- Added missing fields to AvtpCommonStreamHeaderV0
- Incomplete header classes (other than AvtpCommonHeader) are now private classes
- Improved unit test cases to check for unknown versions and UDP round trips
- AI-Assisted: no
- Implemented the Chapter 9 of the IEEE 1722-2025 spec.
- Added unit test cases
- AI-Assisted: Co-pilot for unit tests
- Removed unused class AvtpHeaderVersion
- Added AvtpUdpEncapsulation as an independent layer
- Use of AvtpStreamType instead of flattening the enum
- Removed usage of "_underlayer" to check for UDP
- Made private hidden classes now public and used match_subclass
- Reduced bolier plate code for ACF data formats
- Added additional unit tests for regression
- AI-Assisted: no
- Fixed appending of payload to packet in AvtpCommonControlHeader.
- Fixed padding arithmetic of AvtpAcfHeader
- Renamed AvtpAcfI2CHeader to AvtpAcfI2CMessage
- Renamed AvtpAcfI2CBriefHeader to AvtpAcfI2CBriefMessage
- AI-Assisted: no
- Replaced convenience import scapy.all with individual items import.
- Consolidated padding functions in the AvtpAcfHeader and _AvtpAcfPaddedHeader.
- AI-Assisted: no
- Added a serializable variant of AvtpCommonHeader as a fallback for unknown variants
- Modified dispatch_hooks to avoid silent falling back to version 0
- Added missing fields to AvtpCommonStreamHeaderV0
- Incomplete header classes (other than AvtpCommonHeader) are now private classes
- Improved unit test cases to check for unknown versions and UDP round trips
- AI-Assisted: no
- Added packet length checks before packet acceses
- Introduced enums for CRC types
- Improved unit tests
- AI-Assisted: no
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.64516% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.38%. Comparing base (7daa15d) to head (9a08caf).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
scapy/contrib/ieee1722.py 80.64% 60 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5185      +/-   ##
==========================================
+ Coverage   47.28%   47.38%   +0.10%     
==========================================
  Files         375      376       +1     
  Lines       97732    98042     +310     
==========================================
+ Hits        46209    46459     +250     
- Misses      51523    51583      +60     
Files with missing lines Coverage Δ
scapy/contrib/ieee1722.py 80.64% <80.64%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants