Skip to content

tests: make the raw requests valid RTU frames - #894

Open
helenkwok wants to merge 1 commit into
stephane:masterfrom
helenkwok:tests-rtu-raw-requests
Open

helenkwok wants to merge 1 commit into
stephane:masterfrom
helenkwok:tests-rtu-raw-requests

Conversation

@helenkwok

Copy link
Copy Markdown

Fixes #893.

Two raw requests in test_server() can't be framed by an RTU server, which works out the request length from the function code and byte count:

  • send_crafted_request() zeroes the byte count of write requests on the "0 values" pass but still sends the data bytes, so the server reads 9 bytes (bad CRC) and then times out waiting on the 6 leftover bytes.
  • The unknown function code request carries 4 payload bytes the server can't account for, so its CRC check fails and nothing is replied.

This sends the zero-value write requests without data, and the unknown function code request as slave and function code only. Only tests/unit-test-client.c changes; TCP keeps working since the MBAP length follows the actual request length.

Tested (unit-test-server / unit-test-client):

  • RTU, QNX 8.0 (Raspberry Pi 4) <-> Linux (Raspberry Pi 3B) over UART at 115200 8N1: all tests pass (before: stopped after 65 OKs)
  • RTU, Linux <-> Linux over a pty pair: all tests pass (before: same stop)
  • TCP and TCP PI (IPv6): all tests pass on Linux and QNX

I agree to the terms of the Contributor License Agreement (CLA.txt).

The RTU unit test stopped in test_server() at the first crafted write
request (unit-test-client.c, "write 0 values") and never reached the end
of the suite.

Two raw requests can't be framed by an RTU server, which works out the
request length from the function code and byte count:

- send_crafted_request() zeroes the byte count of write requests on the
  "0 values" pass but still sends the data bytes. The server takes the
  first 9 bytes as the request (bad CRC), then waits for the rest of a
  "request" made of the 6 leftover bytes and times out.
- The unknown function code request carries 4 payload bytes. The server
  can't know a length for an unknown function code, reads slave, function
  code and CRC only, the CRC fails and nothing is replied.

Send the zero-value write requests without data, and the unknown function
code request as slave and function code only. TCP keeps working since the
MBAP length follows the actual request length.

Tested with unit-test-server/unit-test-client:
- RTU, QNX 8.0 (Raspberry Pi 4) <-> Linux (Raspberry Pi 3B) over UART at
  115200 8N1: all tests pass (before: stopped at the "write 0 values"
  check after 65 OKs).
- RTU, Linux <-> Linux over a pty pair: all tests pass (before: same stop).
- TCP and TCP PI (IPv6): all tests pass on Linux and QNX.
@cla-bot

cla-bot Bot commented Nov 7, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

@helenkwok

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot

cla-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

@cla-bot

cla-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

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.

RTU unit tests stop at "write 0 values": crafted raw requests are not valid RTU frames

1 participant