Skip to content

Added ACF_CRC format along with unit tests. - #228

Merged
SebastianSchildt merged 6 commits into
COVESA:mainfrom
nayakned:add_format/crc
Nov 20, 2026
Merged

SebastianSchildt merged 6 commits into
COVESA:mainfrom
nayakned:add_format/crc

Conversation

@nayakned

@nayakned nayakned commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Implements only the accessors. #230 will provide the CRC and checksum function implementations.

Copilot AI 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.

🟡 Changes recommended

The CRC validator accepts header-only messages for fixed four-byte CRC types, allowing receivers that trust validation to read past the buffer.

1 open issue
What changed in this PR

Adds ACF_CRC message support to Open1722, including serialization helpers, validation, and unit tests.

Changes:

  • Introduces the CRC header layout, CRC types, and message-handling APIs.
  • Exports the new APIs and documents CRC as a supported format.
  • Adds tests for initialization, fields, payload padding, message creation, and validation.
File Description
unit/​test-crc.c Adds unit tests for ACF_CRC message handling.
unit/​CMakeLists.txt Registers the CRC tests for dual-mode execution.
src/​avtp/​export/​InlineExports.c Includes CRC APIs in inline exports.
README.md Lists CRC among supported ACF formats.
include/​avtp/​acf/​Crc.h Defines the CRC format and message-handling APIs.

Review effort: Balanced

Comment thread include/avtp/acf/Crc.h Resolved
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (906a0de) to head (1934359).

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #228    +/-   ##
========================================
  Coverage   99.56%   99.57%            
========================================
  Files          61       63     +2     
  Lines        9489     9699   +210     
  Branches      334      354    +20     
========================================
+ Hits         9448     9658   +210     
  Misses         40       40            
  Partials        1        1            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the ACF_CRC message-support change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@SebastianSchildt SebastianSchildt left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The "large" comments I added to the relevant code segements. Here are some minor AI nitpicks you may or may nor want to tackle:

  • While updating the tests, add coverage for:
    • header-only CRC_USER is rejected;
    • GetPayloadLength() (if added) returns 4 for CRC_ETH/CRC_32P4 and the variable length for CRC_USER.
  • Crc.h:257-258 calls Avtp_Crc_GetCrcType() twice. A local variable or a switch would be clearer and fits naturally with the minimum-length check above.
  • The convenience CreateAcfMessage() (Crc.h:207-221) does not reject payload_length != 4 for CRC_ETH/CRC_32P4. That is consistent with other formats’ Create functions, which assume caller correctness, but documenting the precondition would help.
  • GetPayload/SetPayload use the generic payload naming while the spec field is crc_data. That is acceptable under the ACF payload convention, but callers must remember that crc_data for types 0/1 is a network-byte-order 32-bit value; SetPayload() copies bytes verbatim. A typed Get/SetCrcData(uint32_t) accessor for the fixed-width types, or at least an endianness note, would be more consistent with Avtp_Checksum_Get/SetChecksum in PR #229. This is a design suggestion, not a spec violation.

I think we discussed this, but for completeless sake
This PR implements the ACF_CRC container only. It does not compute Ethernet CRC-32 or AUTOSAR CRC-32P4, nor does it validate a received CRC over the preceding ACF message. If “ACF_CRC support” is intended to mean the full listener behaviour in §9.4.21.1, this is incomplete. If it is intended to be format support only — consistent with the Checksum PR #229, which also only carries the value — then that should probably be stated in the PR description so it is clear that CRC calculation is a follow-up.

Comment thread include/avtp/acf/Crc.h Resolved
Comment thread include/avtp/acf/Crc.h Resolved
Comment thread unit/test-crc.c Resolved
nayakned added a commit to nayakned/Open1722 that referenced this pull request Oct 30, 2026
- Added function for accessing CRC data
- Disallowed ACF_CRC without CRC data
- Fixed length for CRC_ETH and CRC32P4
- Improved test coverage

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
@nayakned

Copy link
Copy Markdown
Collaborator Author
  • While updating the tests, add coverage for:

    • header-only CRC_USER is rejected;
    • GetPayloadLength() (if added) returns 4 for CRC_ETH/CRC_32P4 and the variable length for CRC_USER.

Tests added for these scenarios. Though for the GetPayloadLength(), the real values are returned irrespective of the CRC type.

  • Crc.h:257-258 calls Avtp_Crc_GetCrcType() twice. A local variable or a switch would be clearer and fits naturally with the minimum-length check above.

Used a local variable

  • The convenience CreateAcfMessage() (Crc.h:207-221) does not reject payload_length != 4 for CRC_ETH/CRC_32P4. That is consistent with other formats’ Create functions, which assume caller correctness, but documenting the precondition would help.

Added an overlapping field CRC_DATA with the payload. The convenience function chooses the right field to set based on the CRC type.

  • GetPayload/SetPayload use the generic payload naming while the spec field is crc_data. That is acceptable under the ACF payload convention, but callers must remember that crc_data for types 0/1 is a network-byte-order 32-bit value; SetPayload() copies bytes verbatim. A typed Get/SetCrcData(uint32_t) accessor for the fixed-width types, or at least an endianness note, would be more consistent with Avtp_Checksum_Get/SetChecksum in PR Add format/checksum #229. This is a design suggestion, not a spec violation.

This should now be fixed with an overlapping field with the payload data.

I think we discussed this, but for completeless sake This PR implements the ACF_CRC container only. It does not compute Ethernet CRC-32 or AUTOSAR CRC-32P4, nor does it validate a received CRC over the preceding ACF message. If “ACF_CRC support” is intended to mean the full listener behaviour in §9.4.21.1, this is incomplete. If it is intended to be format support only — consistent with the Checksum PR #229, which also only carries the value — then that should probably be stated in the PR description so it is clear that CRC calculation is a follow-up.

Is also included in the PR description now

@SebastianSchildt SebastianSchildt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See comments in code.

There is also a style thing:

AI says

API/convention issue: CRC_DATA was added to the header descriptor table
Crc.h:86-88 and Crc.h:113 add AVTP_CRC_FIELD_CRC_DATA at quadlet 1, but AVTP_CRC_HEADER_LEN is only 4 bytes. The project guidance says the format field enum/table describes the header, covering every header bit exactly once (docs/api-design.md:433-491). The new test name crc_field_descriptors_cover_header now covers 8 bytes and no longer asserts quadlet == 0, so the convention is no longer enforced.
The typed accessor itself is useful and works, but it should not make Avtp_CrcFieldDesc a header-plus-payload table. Options:

  • Keep the header table header-only and implement Get/SetCrcData over pdu->payload using the existing Avtp_BeToCpu32()/Avtp_CpuToBe32() helpers, or
  • Use a separate descriptor for the fixed 32-bit data view, or
  • If this exception is intentional, update docs/api-design.md, the enum comment, and the test name to say the table covers “header + first CRC data quadlet”.

Sebastian says

I think we maybe can just remove the entry from the header descriptor table and let Get/setCrcData deal with with it internally?

Comment thread include/avtp/acf/Crc.h Resolved
Comment thread include/avtp/acf/Crc.h Outdated
// The function will only set the first 4 bytes of the payload as the CRC data.
// The endianness of the payload will be adjusted based on the host endianness.
uint32_t crc_data;
memcpy(&crc_data, payload, sizeof(crc_data));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OOB read:

AI said

always reads 4 bytes for fixed types, regardless of payload_length. Even if the documented contract says “payload length must be 4,” the function should not read beyond the caller-supplied length.
This is a real OOB:

uint8_t payload[1] = {0};
Avtp_Crc_CreateAcfMessage(crc, AVTP_CRC_TYPE_CRC_ETH, payload, 0);

ASan reports:
READ of size 4 ... in Avtp_Crc_CreateAcfMessage include/avtp/acf/Crc.h:277

It also silently truncates a longer payload: passing 8 bytes for a fixed type keeps only the first 4 and produces a valid 8-byte message instead of an invalid 12-byte one.

Recommended fix: copy exactly payload_length bytes and let IsValid() reject non-4-byte fixed-type messages, consistent with other CreateAcfMessage() implementations. If the function should enforce 4 bytes, it must at least check payload_length before reading.

Sebastian says:

I would probably check if it is 4 bytes and just do not nothing if it isn't for the fixed length types. But definitely make sure not to overread

Comment thread unit/test-crc.c Outdated
{
(void)state;
uint8_t pdu[MAX_PDU_SIZE];
uint8_t payload[8] = {0};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The test itself has an OOB read
unit/test-crc.c:182 declares:

uint8_t payload[8] = {0};

but unit/test-crc.c:199 calls:

Avtp_Crc_CreateAcfMessage(crc, type, payload, 12);

For CRC_USER, this copies 12 bytes from an 8-byte array. ASan reports a stack-buffer-overflow at Crc.h:177/:284, called from test-crc.c:199. The normal and UBSan builds pass because CI does not run ASan, but the test is wrong. Increase the array to at least 12 bytes, or drop the 12-byte “too long” case.

Sebastian says:

note to self ASan might be another wonderful tool to make our CI more annoying!

@nayakned

Copy link
Copy Markdown
Collaborator Author

Before we read too much into what AI has to say, we should consider some of the peculiarities of the ACF_CRC format.
Mainly the differentiation between header and payload.

Status Quo:

Open1722 API is designed to have accessor (get/set) functions for different header fields of the corresponding data formats. In most of the data formats, there is a clear distinction between header and payload, which the specification also notes. However, in ACF_CRC (along with the I2C and the Checksum formats) this distinction is not very clear.
There is the CRC Data. We can look at it as the payload of the data format, but this can be treated as a header field as well.

Header vs. Payload

My current mental model about what counts as header and what counts as payload:

  1. Treat fields with fixed sizes under 8 bytes as header fields. Use our field engines for the accessors. Benefit: We need not handle the endianness of the host platform.
  2. Variable-length fields or fields larger than 8 bytes are payloads, especially if they are at the end of the data format.

Does this differentiation help in ACF_CRC data format?

Unfortunately, no. Even if you go by the above definition, ACF_CRC is still brings its own peculiarities.

ACF_CRC has CRC Data at the end of the data format. From the three supported CRC types in the IEEE 1722 spec., two types have a 32-bit CRC, while there is a user-defined CRC type with an arbitrarily long quadlet-aligned CRC data.

Proposed solution

Treat ACF_CRC as an exception.

  1. For CRC types with a fixed length of 4-byte CRC, think of CRC Data as a header field. Encode the lengths and offset in the field-descriptor table and provide appropriate accessors.
  2. For user-defined CRC type with an arbitrary length, think of CRC Data as payload and use the payload functions (Get/SetPayload and Get/SetPayloadLength).

Quirks

  1. What shall be the length of the ACF_CRC header length? Does the length include the fixed-length CRC data or not? I am a little undecided on this.
  2. We have an overlap between the first four bytes of the CRC Data when interpreted as a header field and as payload at the same time. So if we use the accessor to set the field and payload function to get the CRC data, depending on the endianness we will get different readback.
  3. Do we need two different AcfCrcCreateMessage() implementations -- one for fixed-length CRC variants and one for the user-defined variant? A single parameterized implementation keeps the format consistent with other formats at the cost of unintuitive parameter handling, e.g., the payload length is ignored when the CRC type points to a fixed-length variant.

Quite a few open points regarding design requiring human opinions before an AI can jump in.

@SebastianSchildt

Copy link
Copy Markdown
Collaborator

My view is: crc_data is payload for this ACF and thus I would define header lenght as the length without the crc. And I would not defined crc_data in the header field descriptor table to make it consistent.

So my view is: crc_data is not part of the header and should probably not be in the header descriptor table.

I.e. CAN or LIN also do not define payload in header, (even though for Lin with max 2 quadlets payload that would be possible).

That would be a correct form. Then the question is, what convenience we give for the defined CRC. I think one could use additional convenience setters/getters for getCrcEth or setCrc32P4 in addition the raw setPayload that internally deal with setting the correct payload (and also deal with endianess, whteher they do it "by hand" or by defining a field descriptor and going through the field accessor engine I would consider an implementation detail).

Maybe the Create-Functions would need to be split as well, but not sure, or maybe they only support the 4 byte types and if you want an "user" you need to construct it yourself with init and the appropriate setters/getters

@adriaan-niess

Copy link
Copy Markdown
Member

Proposal from @SebastianSchildt looks good to me. Since ACF_CRC (in contrary to ACF_Checksum) gives the flexibility to support variable size CRCs it makes sense to treat the CRC data as payload. Providing different create functions to support the most common CRC methods, would definitely help usability. To my knowledge there are only 2-3 CRC options anyway.

I'm not sure if it's really that helpful to provide explicit getters for all kinds of CRC types instead of a generic getter for the payload aka CRC data. It might be more helpful to provide a validate function to check validity of a byte array (typically another ACF message) based on the CRC data and type. Something like

bool Crc_Validate(Crc_t* acfCrc, uint8* Data, size_t len)

But in principle this can also be done in another PR. I can also look into adding support for the AUTOSAR CRC-32 in case you need help.

nayakned added a commit to nayakned/Open1722 that referenced this pull request Nov 2, 2026
- CRC Data is now handled using an accessor
- AcfCreateMessage creates only PDUs for fixed length CRC
- CRC Data does not overlap with header fields.

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
Comment thread include/avtp/acf/Crc.h Resolved
Comment thread include/avtp/acf/Crc.h Resolved
Comment thread include/avtp/acf/Crc.h Resolved
Comment thread include/avtp/acf/Crc.h Resolved
Comment thread unit/test-crc.c Resolved
Comment thread unit/test-crc.c Resolved
Comment thread include/avtp/acf/Crc.h Resolved
Comment thread include/avtp/acf/Crc.h Resolved
Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
- Added unit tests for ACF_CRC to improve coverage.
- Refactored conditions in IsValid() for better test coverage.

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
- Added function for accessing CRC data
- Disallowed ACF_CRC without CRC data
- Fixed length for CRC_ETH and CRC32P4
- Improved test coverage

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
- CRC Data is now handled using an accessor
- AcfCreateMessage creates only PDUs for fixed length CRC
- CRC Data does not overlap with header fields.

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>

@SebastianSchildt SebastianSchildt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is looking good now I think. Let's merge ⚙️

@SebastianSchildt
SebastianSchildt merged commit 2ef078b into COVESA:main Nov 20, 2026
9 checks passed
SebastianSchildt pushed a commit that referenced this pull request Nov 20, 2026
- Added function for accessing CRC data
- Disallowed ACF_CRC without CRC data
- Fixed length for CRC_ETH and CRC32P4
- Improved test coverage

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
SebastianSchildt pushed a commit that referenced this pull request Nov 20, 2026
- CRC Data is now handled using an accessor
- AcfCreateMessage creates only PDUs for fixed length CRC
- CRC Data does not overlap with header fields.

Signed-off-by: Naresh Nayak <Naresh.Nayak@hs-furtwangen.de>
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.

4 participants