feat: expose the PLC protection level on the S7CommPlus clients - #826
feat: expose the PLC protection level on the S7CommPlus clients#826bvanelli wants to merge 1 commit into
Conversation
gijzelaerr
left a comment
There was a problem hiding this comment.
Thanks for the hardware captures and focused implementation. I merged current master into the branch so the PR now targets master cleanly and shows only the intended five files.
I found three issues to address:
-
The protection-level GET_VAR_SUBSTREAMED request currently runs before _session_activate(). V1-initial SessionKey PLCs require activation before any data read, so this can reject or reset connect(). The query is also unconditional when session setup is incomplete, which can break the existing fallback path. Please activate first for SessionKey sessions and only query a session where this operation is supported.
-
protection_level is cached during connect but is never refreshed after sync or async authenticate(). Successful legitimation changes the effective access level, so the exposed value becomes stale. Please refresh it after authentication, or rename/document it as the initial protection level if that is the intended contract.
-
_parse_protection_level_response() skips the PValue flags/type bytes without validating them and leaks ValueError for short VLQ data. Please require a scalar UDINT, validate bounds, and wrap malformed framing in S7ConnectionError like _parse_get_var_substreamed_response(). Add malformed/type regression coverage as well.
Local validation of the master merge: 1,766 tests passed, 82 skipped; mypy, Ruff, formatting, and the other pre-commit hooks passed; wheel build passed.
Read the session's effective protection level (id 1842) once the S7CommPlus session is established, and expose it as a protection_level property on the connection, the sync client and the async client, so callers can tell an unprotected PLC from one that needs legitimation. AccessLevel names the values the PLC reports. The request reuses the existing GetVarSubStreamed payload builder, whose framing matches the reference driver: the 0x0001 field following the ObjectQualifier is a protocol constant, and the IntegrityId is the separate VLQ that send_request splices in after it.
a26f492 to
ce4c1c6
Compare
Read the session's effective protection level once the S7CommPlus session is established, and expose it as a
protection_levelproperty on the connection, the sync client and the async client, so callers can tell an unprotected PLC from one that needs legitimation.AccessLevelnames the values the PLC reports.This is required to display better exceptions whenever the PLC is not browsable/partially browsable. A high-protection level (4) indicates that the PLC is password protected.
See reference code during legitimation:
https://github.com/thomas-v2/S7CommPlusDriver/blob/dbd61e447c7aaf4486cf1f1fe0201212a6bd93c8/src/S7CommPlusDriver/Legitimation/Legitimation.cs#L118-L123
Here are the logs from the connection test to three different PLCs
Easier to review and merge to master after #775