fix(server): reassemble COTP fragments and fix INT/DINT byte count - #806
Merged
Conversation
) Two bugs in the pure-Python server: 1. COTP fragmentation not reassembled: the server's Connection Confirm omitted the TPDU size parameter, causing spec-compliant clients to fall back to the ISO 8073 default of 128 bytes and fragment requests. The server then tried to process each fragment as a standalone PDU. Fix: parse TPDU size from the client's Connection Request, echo it in the Connection Confirm, and reassemble DT fragments by looping until the EOT bit is set. 2. INT and DINT word lengths missing from byte-count conversion: read requests using word_len=INT or word_len=DINT returned count bytes instead of count*2 or count*4 bytes. Fix: add INT to the 2-byte branch and DINT to the 4-byte branch in both _handle_read_area and _parse_read_address. Closes #804
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two bugs in the pure-Python server reported in #804:
1. COTP fragmented requests not reassembled
The server's COTP Connection Confirm omitted the TPDU size parameter (
0xC0), causing spec-compliant clients to fall back to the ISO 8073 class-0 default of 128 bytes. Any request larger than 128 bytes was legitimately fragmented by the client, but the server tried to process each fragment as a standalone S7 PDU — producingPDU too short for S7 headererrors.Fix:
receive_data()by looping until the EOT bit is set2. INT/DINT word lengths return wrong byte count
Read requests using
word_len=INT(16-bit) orword_len=DINT(32-bit) fell through to theelsebranch and treated the item count as a byte count. Requesting 10 DINTs returned 10 bytes instead of 40.Fix: Add
S7WordLen.INTto the 2-byte branch andS7WordLen.DINTto the 4-byte branch in both_handle_read_areaand_parse_read_address.Closes #804