Skip to content

pnio_rpc: read the RTA PDU type from the low nibble of PDUType - #5297

Open
bIackr0se wants to merge 1 commit into
secdev:masterfrom
bIackr0se:fix/pnio-rta-pdutype-nibbles
Open

bIackr0se wants to merge 1 commit into
secdev:masterfrom
bIackr0se:fix/pnio-rta-pdutype-nibbles

Conversation

@bIackr0se

Copy link
Copy Markdown
Contributor

Description

PNIORealTimeAcyclicPDUHeader declares PDUTypeType before PDUTypeVersion (pnio_rpc.py#L1356-L1357), so scapy reads the type from the high nibble of the PDUType octet. Wireshark (masks) and the rt-labs p-net stack (reader) put the type in bits 0-3 and the version in bits 4-7. A received RTA acknowledgement (0x13, ACK version 1) dissects as RTA_TYPE_DATA version 3, and Alarm_Low(PDUTypeType=3, PDUTypeVersion=1) writes 0x31, which Wireshark reads as a Data-RTA-PDU version 3. The existing tests do not check these two fields: the alarm captures use 0x11, where both orders agree, and the acknowledgement test uses 0x13 without asserting the type or version.

This PR swaps the two fields so the version is the high nibble.

from scapy.all import Ether, raw, load_contrib
load_contrib("pnio")
load_contrib("pnio_rpc")
from scapy.contrib.pnio_rpc import Alarm_Low
a = Alarm_Low(b'\x00\x03\x00\x03\x13\x00\x00\x00\xff\xff\x00\x00')
print(a.PDUTypeType, a.PDUTypeVersion)
print(raw(Alarm_Low(PDUTypeType=3, PDUTypeVersion=1))[4:5])

Before:

1 3
b'1'

After:

3 1
b'\x13'

tshark 4.6.9 decodes the PDUType of an Alarm_Low frame for each of the 256 octet values the same way scapy does after this change (before, only the 16 values with equal nibbles matched). A test is added to test/contrib/pnio_rpc.uts.

This message was written with the help of AI (Claude Opus 5.5).

PNIORealTimeAcyclicPDUHeader declared PDUTypeType before
PDUTypeVersion, so the type was read from and written to bits 4-7.
IEC 61158-6-10 and Wireshark put the type in bits 0-3 and the
version in bits 4-7: an ACK (0x13) dissected as DATA version 3, and
PDUTypeType=3 with PDUTypeVersion=1 was written as 0x31.

AI-Assisted: yes (Claude Opus 5.5)
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.15%. Comparing base (0e2f6ba) to head (1ae8e54).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5297      +/-   ##
==========================================
+ Coverage   80.06%   80.15%   +0.08%     
==========================================
  Files         375      375              
  Lines       98775    98775              
==========================================
+ Hits        79083    79169      +86     
+ Misses      19692    19606      -86     
Files with missing lines Coverage Δ
scapy/contrib/pnio_rpc.py 94.72% <ø> (ø)

... and 13 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.

1 participant