Commit f0e47eb
committed
fix: browse() and list_datablocks() for V3 multi-frame EXPLORE (S7-1200 FW V4.5)
On V3 PLCs (FW >= V4.5) the EXPLORE response for RID 0x8A11FFFF spans
multiple TPKT frames and uses a zlib-compressed PlcContentInfo XML format
instead of the PObject tree expected by _parse_explore_datablocks().
The existing reassemble=True path does not strip V3 HMAC prefixes from
continuation frames, so list_datablocks() returned [] on these PLCs.
Changes:
connection.py:
- Add collect_explore_frames(): collects V3 multi-fragment EXPLORE
responses by receiving continuation frames and stripping their HMAC
prefix, stopping when a shorter-than-reference frame is detected.
_s7commplus_client.py:
- Add _build_explore_payload_v3(): VLQ-encoded EXPLORE payload for
V3 PLCs (required format for 0x8A11FFFF and per-DB RID explores).
- Add _parse_explore_datablocks_xml(): decompresses the zlib PlcContentInfo
XML blob and extracts Entity[@id="Block"][@type="DB"] entries; falls back
to _parse_explore_datablocks() when no zlib magic is found.
- list_datablocks(): when protocol_version >= V3, use _build_explore_payload_v3
+ collect_explore_frames + _parse_explore_datablocks_xml.
- browse(): when protocol_version >= V3, use V3 payload builder and frame
collector for each per-DB EXPLORE.
- _parse_explore_fields(): three fixes for V3 PLCs:
* Accept WSTRING dtype 0x15 in addition to 0x13 for name attributes.
* Auto-detect encoding: UTF-8 (V3, no null bytes) vs UTF-16-BE (V1/V2).
* BLOB skip: account for the extra 0x00 byte V3 PLCs insert before VLQ len.
* WSTRING skip: advance past string data bytes (was only skipping VLQ).
Tested on S7-1200 CPU 1212C DC/DC/DC, firmware V4.5 (V3 protocol, no TLS):
- list_datablocks() now returns [{"name": "Data_block_1", "number": 100,
"rid": 2316173412}] where it previously returned [].
- The PlcContentInfo XML (6131 bytes after decompression) is correctly
parsed from a 3-frame response (first 946-byte frame + two continuations).
Known limitation: on FW V4.5, DB field definitions and I/Q/M tag names are
stored in zlib BLOBs with a Siemens preset dictionary (magic 78 7D, FDICT
flag set). Python zlib.decompress() returns Z_NEED_DICT. browse() returns
DB names/numbers but cannot enumerate individual field names on V3 PLCs.1 parent 34ef7b6 commit f0e47eb
2 files changed
Lines changed: 170 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
368 | 377 | | |
369 | 378 | | |
370 | 379 | | |
| |||
394 | 403 | | |
395 | 404 | | |
396 | 405 | | |
397 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
398 | 411 | | |
399 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
400 | 417 | | |
401 | 418 | | |
402 | 419 | | |
| |||
763 | 780 | | |
764 | 781 | | |
765 | 782 | | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
766 | 857 | | |
767 | 858 | | |
768 | 859 | | |
| |||
910 | 1001 | | |
911 | 1002 | | |
912 | 1003 | | |
913 | | - | |
| 1004 | + | |
914 | 1005 | | |
915 | 1006 | | |
916 | 1007 | | |
917 | 1008 | | |
918 | 1009 | | |
| 1010 | + | |
919 | 1011 | | |
920 | | - | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
921 | 1019 | | |
922 | 1020 | | |
923 | 1021 | | |
924 | 1022 | | |
925 | 1023 | | |
926 | | - | |
927 | | - | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
928 | 1028 | | |
929 | 1029 | | |
930 | 1030 | | |
931 | 1031 | | |
932 | 1032 | | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
933 | 1046 | | |
934 | 1047 | | |
935 | 1048 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
411 | 461 | | |
412 | 462 | | |
413 | 463 | | |
| |||
0 commit comments