Skip to content

fix(server): encode V2 response IntegrityIds - #818

Merged
gijzelaerr merged 5 commits into
masterfrom
fix/802-v2-response-integrity-id
Sep 10, 2026
Merged

fix(server): encode V2 response IntegrityIds#818
gijzelaerr merged 5 commits into
masterfrom
fix/802-v2-response-integrity-id

Conversation

@gijzelaerr

@gijzelaerr gijzelaerr commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • append the current per-client read or write IntegrityId to every established-session V2 response
  • preserve the legacy V1 response layout
  • preserve the current server's optional TCP-reset behavior after symbolic reads
  • cover read/write counter selection and sequential V2 TLS operations

The branch now includes current master through a merge commit; its previous conflicts are resolved without rewriting history.

Verification

  • uv run --frozen --extra test --extra s7commplus pytest -q (1779 passed, 82 skipped)
  • focused V2/TLS/server tests (124 passed)
  • uv run --frozen pre-commit run --all-files
  • uv build --no-sources

Fixes #802

@gijzelaerr
gijzelaerr requested a review from spreeker September 1, 2026 17:07
@gijzelaerr

Copy link
Copy Markdown
Owner Author

@bvanelli Could you review the V2 emulator response behavior here, particularly selecting the read/write counter and appending the IntegrityId without changing the V1 payload layout? The conflict repair also preserves the newer symbolic-read TCP-reset emulation.

The refreshed head passes 1,779 tests, the complete pre-commit suite, and the package build.

@gijzelaerr gijzelaerr modified the milestones: 4.1, 4.0 Sep 8, 2026
@gijzelaerr
gijzelaerr removed the request for review from spreeker September 8, 2026 10:04
@gijzelaerr

Copy link
Copy Markdown
Owner Author

@ale-rinaldi you have detailed V2/TLS observations from the 1507S and 1211C. Could you review the server response layout here against your real-PLC captures or traces, particularly whether the read/write IntegrityId selection and appended counter match V2 responses without changing the V1 payload shape?\n\nThis is primarily a capture/protocol review; it does not require exposing project data or pointing a real PLC at the emulator.

Comment thread s7commplus/server.py
response = self._build_error_response(seq_num, req_session_id, function_code)
rst = False

if self._protocol_version >= ProtocolVersion.V2 and req_session_id != 0:

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.

Here, it appends the integrity_id to every function. In theory, this could also apply to _build_error_response and _handle_init_ssl. I'm not sure those use need the integrity id.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good question—the generic placement needed an explicit audit. InitSSL cannot receive this suffix because it runs with a zero request session id, so the active-session guard skips it. An unsupported request made inside an established V2 session does use the write IntegrityId, matching the client, which advances its write counter for every non-read request.

While checking this, I found a nearby real bug: GetVarSubStreamed still emitted its legacy zero field before the generic V2 path appended the current counter, producing two IntegrityIds. The updated head 66afe4f fixes that and adds regressions covering exactly one V2 substreamed IntegrityId, no InitSSL IntegrityId, and the write counter on an in-session error response. The merged tree passes all pinned hooks, source/wheel builds, and the full local suite (2,005 passed, 82 skipped). Thanks for prompting the broader check.

@gijzelaerr
gijzelaerr merged commit 6d7f50e into master Sep 10, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S7CommPlus server: encode IntegrityId in V2 response payloads

2 participants