pyvisionect 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. pyvisionect-0.3.0/CHANGELOG.md +18 -0
  2. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/PKG-INFO +47 -4
  3. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/README.md +46 -3
  4. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/README.md +1 -0
  5. pyvisionect-0.3.0/docs/bootloader.md +225 -0
  6. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/firmware.md +45 -10
  7. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/pyproject.toml +1 -1
  8. pyvisionect-0.3.0/src/pyvisionect/bootloader.py +611 -0
  9. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/__init__.py +2 -0
  10. pyvisionect-0.3.0/src/pyvisionect/io/bootloader.py +165 -0
  11. pyvisionect-0.3.0/src/pyvisionect/io/firmware.py +473 -0
  12. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/tcp.py +49 -2
  13. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/session/connection.py +3 -6
  14. pyvisionect-0.3.0/tests/test_bootloader.py +502 -0
  15. pyvisionect-0.3.0/tests/test_bootloader_io.py +336 -0
  16. pyvisionect-0.3.0/tests/test_firmware_repo.py +424 -0
  17. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_sansio_purity.py +1 -0
  18. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/.github/workflows/publish.yml +0 -0
  19. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/.github/workflows/test.yml +0 -0
  20. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/.gitignore +0 -0
  21. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/LICENSE +0 -0
  22. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/OPEN-QUESTIONS.md +0 -0
  23. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/framing.md +0 -0
  24. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/imaging.md +0 -0
  25. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/overview.md +0 -0
  26. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/packets.md +0 -0
  27. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/parameters.md +0 -0
  28. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/status.md +0 -0
  29. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/unknowns.md +0 -0
  30. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/docs/usb-cli.md +0 -0
  31. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/examples/push_test_card.py +0 -0
  32. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/__init__.py +0 -0
  33. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/devices/__init__.py +0 -0
  34. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/devices/enums.py +0 -0
  35. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/devices/panels.py +0 -0
  36. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/devices/tclv.py +0 -0
  37. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/README.md +0 -0
  38. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/__init__.py +0 -0
  39. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/checksum.py +0 -0
  40. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/constants.py +0 -0
  41. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/data/blue_noise_64.npy +0 -0
  42. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/decode.py +0 -0
  43. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/dither.py +0 -0
  44. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/encoder.py +0 -0
  45. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/geometry.py +0 -0
  46. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/grey.py +0 -0
  47. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/interlace.py +0 -0
  48. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/pack.py +0 -0
  49. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/panel.py +0 -0
  50. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/partial.py +0 -0
  51. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/imaging/rects.py +0 -0
  52. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/__init__.py +0 -0
  53. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/cli.py +0 -0
  54. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/commands.py +0 -0
  55. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/console.py +0 -0
  56. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/device.py +0 -0
  57. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/discovery.py +0 -0
  58. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/encryption.py +0 -0
  59. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/errors.py +0 -0
  60. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/fake.py +0 -0
  61. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/parsers.py +0 -0
  62. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/io/usb/provisioning.py +0 -0
  63. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/__init__.py +0 -0
  64. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/control.py +0 -0
  65. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/file.py +0 -0
  66. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/image.py +0 -0
  67. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/misc.py +0 -0
  68. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/param.py +0 -0
  69. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/status.py +0 -0
  70. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/packets/stored.py +0 -0
  71. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/py.typed +0 -0
  72. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/session/__init__.py +0 -0
  73. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/session/device.py +0 -0
  74. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/session/events.py +0 -0
  75. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/session/filetransfer.py +0 -0
  76. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/session/pending.py +0 -0
  77. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/wire/__init__.py +0 -0
  78. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/wire/blocks.py +0 -0
  79. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/wire/checksum.py +0 -0
  80. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/wire/errors.py +0 -0
  81. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/src/pyvisionect/wire/framing.py +0 -0
  82. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/conftest.py +0 -0
  83. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/data/image0_pv2_head.bin +0 -0
  84. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/data/test-tls-cert.pem +0 -0
  85. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/data/test-tls-key.pem +0 -0
  86. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/fixtures/golden.json.gz +0 -0
  87. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/conftest.py +0 -0
  88. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/data/golden_canvas_1440x2560_grey8.raw.xz +0 -0
  89. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/data/golden_capture.json +0 -0
  90. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_decode.py +0 -0
  91. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_dither.py +0 -0
  92. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_encode_frame.py +0 -0
  93. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_golden_capture.py +0 -0
  94. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_grey.py +0 -0
  95. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_interlace.py +0 -0
  96. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_pack.py +0 -0
  97. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_panel.py +0 -0
  98. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_partial.py +0 -0
  99. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/imaging/test_rects.py +0 -0
  100. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_api_additions.py +0 -0
  101. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_blocks.py +0 -0
  102. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_checksum.py +0 -0
  103. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_file_readback.py +0 -0
  104. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_filetransfer.py +0 -0
  105. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_framing.py +0 -0
  106. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_golden_replay.py +0 -0
  107. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_packets.py +0 -0
  108. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_panel_fallback.py +0 -0
  109. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_pcap_full_replay.py +0 -0
  110. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_pending.py +0 -0
  111. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_persistence.py +0 -0
  112. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_session.py +0 -0
  113. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_status_codecs.py +0 -0
  114. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_stored_frames.py +0 -0
  115. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_sync_status.py +0 -0
  116. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_tclv.py +0 -0
  117. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/test_tcp_server.py +0 -0
  118. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/usb/__init__.py +0 -0
  119. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/usb/test_cli.py +0 -0
  120. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/usb/test_commands.py +0 -0
  121. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/usb/test_console.py +0 -0
  122. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/usb/test_discovery.py +0 -0
  123. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/usb/test_parsers.py +0 -0
  124. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tests/usb/test_provisioning.py +0 -0
  125. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tools/extract_pcap_fixture.py +0 -0
  126. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/tools/gen_blue_noise.py +0 -0
  127. {pyvisionect-0.2.0 → pyvisionect-0.3.0}/uv.lock +0 -0
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ - Firmware updates relayed through the bootloader (experimental; measured on a
6
+ 32" Place & Play only). From Tesserae, released here under MIT (#2).
7
+ - `VisionectServer(on_bootloader=...)` hands bootloader connections to
8
+ `pyvisionect.io.run_bootloader`; without it they are closed.
9
+ - `pyvisionect.io.FirmwareRepository` lists and caches Visionect's builds.
10
+ Unpinned builds are refused unless `allow_unpinned=True`.
11
+ - `ServerStats` gains `bootloader_handled`, `bootloader_unhandled` and
12
+ `bootloader_failed`.
13
+
14
+ ## 0.2.0
15
+
16
+ - Unknown display types are sized from the device's reported status; Joan 6
17
+ (`0x501100EB`) recognised (#3). Types 8 and 9 are now 1024x758.
18
+ - `VisionectServer.close()` no longer hangs on Python 3.12.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyvisionect
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Sans-io reimplementation of the Visionect e-ink sign wire protocol (protocol v3)
5
5
  Author: schlarpc
6
6
  License: MIT
@@ -918,15 +918,58 @@ Verified by hand on one device — `HardwareNameID 8`, the 31.2" Place&Play 32,
918
918
  there is no vendor behaviour to match and no vendor support if it misbehaves. See
919
919
  `OPEN-QUESTIONS.md` A10 and `docs/imaging.md`.
920
920
 
921
+ ## Firmware updates
922
+
923
+ Firmware can be relayed through the bootloader on the same TCP port as normal
924
+ traffic. This was measured on a Place & Play 32" (hardware 1.1.0, bootloader
925
+ 6.3.3830), with firmware 7.4.4407 and 7.3.4358. The implementation comes from
926
+ [Tesserae](https://github.com/dmellok/tesserae)'s updater (AGPL-3.0); its
927
+ authors agreed to its release here under MIT in
928
+ [#2](https://github.com/schlarpc/pyvisionect/pull/2). Other hardware and
929
+ bootloader families remain untested, so treat this as experimental.
930
+
931
+ `pyvisionect.bootloader.BootloaderSession` is sans-io: pass bytes to
932
+ `feed_at(data, now)`, send `drain()`, and call `advance(now)` for timeouts.
933
+ It validates the whole file before accepting a hello, then sends each original
934
+ record only after the preceding acknowledgment. `accept_hello` lets your
935
+ transport reject an unexpected device before sending an offer.
936
+
937
+ For asyncio, set `VisionectServer(on_bootloader=...)` and call
938
+ `pyvisionect.io.bootloader.run_bootloader` from that callback. The callback gets
939
+ `(reader, writer, first)`, where `first` is the prefix already read by the
940
+ listener. With no callback, bootloader connections close without an offer.
941
+ The driver requires the selected device id and a `Build`; it refuses mismatched
942
+ hardware, display, or a bootloader outside the measured 6.3 family.
943
+
944
+ `pyvisionect.io.firmware.FirmwareRepository(cache_dir)` lists builds from
945
+ Visionect's repository and caches files. Call `refresh()` and `fetch(build)`
946
+ in a worker thread (`asyncio.to_thread`); `builds()` and `cached_file(build)`
947
+ read only the cache. `compatible(...)` filters the list by hardware revision,
948
+ hardware name id and display id, newest first. Choose the target explicitly.
949
+ The repository uses plain HTTP. The two measured builds have SHA-256 pins;
950
+ other files receive structural validation only, so `run_bootloader` refuses an
951
+ unpinned build unless you pass `allow_unpinned=True`.
952
+
953
+ Install the handler and load the complete file before calling `conn.reboot()`
954
+ and flushing the normal connection. Consume each authorized request once so a
955
+ second bootloader connection cannot start the same transfer. Use `BlockAcked`
956
+ for progress and inspect the returned session's `state` and `error`. `DONE`
957
+ means all records were acknowledged. Confirm `Firmware` and `FirmwareID` in a
958
+ subsequent normal status before reporting the update as installed.
959
+
960
+ Transfers are never retried automatically. If one stops after sending records,
961
+ the frame may need a power cycle or Visionect's USB Configurator. Firmware
962
+ payloads remain opaque; no firmware binaries or decryption keys are included.
963
+ See [the usage example and wire protocol](docs/bootloader.md).
964
+
921
965
  ## What is deliberately out of scope
922
966
 
923
967
  - **Link encryption.** `Security != 0` needs a 16-byte session key that the
924
968
  vendor's gateway escrows with a Visionect HTTPS service; that key material is
925
969
  not in the server image, so a self-hosted deployment is plaintext by
926
970
  construction. The decoder raises a clear error and the seam is there.
927
- - **Firmware and bootloader push.** The payloads are AES-CBC (fixed, fleet-wide IV) under a key that
928
- exists only on Visionect's servers. Relaying an opaque blob to a device that
929
- will flash it is not something to ship untested.
971
+ - **Bootloader replacement.** Firmware relay is supported, but replacing the
972
+ bootloader itself has not been measured.
930
973
  - **Discovery.** There is none. Give Home Assistant an explicit address.
931
974
  - **`packet.Type 12` (CBOR) payloads.** The framing is implemented; the CBOR body
932
975
  is not parsed. That channel belongs to the newer "AC"/JS-app device generation
@@ -890,15 +890,58 @@ Verified by hand on one device — `HardwareNameID 8`, the 31.2" Place&Play 32,
890
890
  there is no vendor behaviour to match and no vendor support if it misbehaves. See
891
891
  `OPEN-QUESTIONS.md` A10 and `docs/imaging.md`.
892
892
 
893
+ ## Firmware updates
894
+
895
+ Firmware can be relayed through the bootloader on the same TCP port as normal
896
+ traffic. This was measured on a Place & Play 32" (hardware 1.1.0, bootloader
897
+ 6.3.3830), with firmware 7.4.4407 and 7.3.4358. The implementation comes from
898
+ [Tesserae](https://github.com/dmellok/tesserae)'s updater (AGPL-3.0); its
899
+ authors agreed to its release here under MIT in
900
+ [#2](https://github.com/schlarpc/pyvisionect/pull/2). Other hardware and
901
+ bootloader families remain untested, so treat this as experimental.
902
+
903
+ `pyvisionect.bootloader.BootloaderSession` is sans-io: pass bytes to
904
+ `feed_at(data, now)`, send `drain()`, and call `advance(now)` for timeouts.
905
+ It validates the whole file before accepting a hello, then sends each original
906
+ record only after the preceding acknowledgment. `accept_hello` lets your
907
+ transport reject an unexpected device before sending an offer.
908
+
909
+ For asyncio, set `VisionectServer(on_bootloader=...)` and call
910
+ `pyvisionect.io.bootloader.run_bootloader` from that callback. The callback gets
911
+ `(reader, writer, first)`, where `first` is the prefix already read by the
912
+ listener. With no callback, bootloader connections close without an offer.
913
+ The driver requires the selected device id and a `Build`; it refuses mismatched
914
+ hardware, display, or a bootloader outside the measured 6.3 family.
915
+
916
+ `pyvisionect.io.firmware.FirmwareRepository(cache_dir)` lists builds from
917
+ Visionect's repository and caches files. Call `refresh()` and `fetch(build)`
918
+ in a worker thread (`asyncio.to_thread`); `builds()` and `cached_file(build)`
919
+ read only the cache. `compatible(...)` filters the list by hardware revision,
920
+ hardware name id and display id, newest first. Choose the target explicitly.
921
+ The repository uses plain HTTP. The two measured builds have SHA-256 pins;
922
+ other files receive structural validation only, so `run_bootloader` refuses an
923
+ unpinned build unless you pass `allow_unpinned=True`.
924
+
925
+ Install the handler and load the complete file before calling `conn.reboot()`
926
+ and flushing the normal connection. Consume each authorized request once so a
927
+ second bootloader connection cannot start the same transfer. Use `BlockAcked`
928
+ for progress and inspect the returned session's `state` and `error`. `DONE`
929
+ means all records were acknowledged. Confirm `Firmware` and `FirmwareID` in a
930
+ subsequent normal status before reporting the update as installed.
931
+
932
+ Transfers are never retried automatically. If one stops after sending records,
933
+ the frame may need a power cycle or Visionect's USB Configurator. Firmware
934
+ payloads remain opaque; no firmware binaries or decryption keys are included.
935
+ See [the usage example and wire protocol](docs/bootloader.md).
936
+
893
937
  ## What is deliberately out of scope
894
938
 
895
939
  - **Link encryption.** `Security != 0` needs a 16-byte session key that the
896
940
  vendor's gateway escrows with a Visionect HTTPS service; that key material is
897
941
  not in the server image, so a self-hosted deployment is plaintext by
898
942
  construction. The decoder raises a clear error and the seam is there.
899
- - **Firmware and bootloader push.** The payloads are AES-CBC (fixed, fleet-wide IV) under a key that
900
- exists only on Visionect's servers. Relaying an opaque blob to a device that
901
- will flash it is not something to ship untested.
943
+ - **Bootloader replacement.** Firmware relay is supported, but replacing the
944
+ bootloader itself has not been measured.
902
945
  - **Discovery.** There is none. Give Home Assistant an explicit address.
903
946
  - **`packet.Type 12` (CBOR) payloads.** The framing is implemented; the CBOR body
904
947
  is not parsed. That channel belongs to the newer "AC"/JS-app device generation
@@ -79,6 +79,7 @@ See [usb-cli.md](usb-cli.md#help-is-not-a-complete-index).
79
79
  | [parameters.md](parameters.md) | TCLV configuration parameters: encoding, the three banks, the read-only set |
80
80
  | [imaging.md](imaging.md) | Encodings, bit packing, geometry, interlacing, dithering, the state checksum |
81
81
  | [firmware.md](firmware.md) | Firmware and bootloader transfer, the vendor firmware service, the encryption |
82
+ | [bootloader.md](bootloader.md) | The app-firmware update as captured, and how to drive it with this library |
82
83
  | [usb-cli.md](usb-cli.md) | The USB serial console and the provisioning bootstrap |
83
84
  | [unknowns.md](unknowns.md) | What is still unresolved, and what would settle it |
84
85
 
@@ -0,0 +1,225 @@
1
+ # Visionect bootloader firmware update protocol
2
+
3
+ What a Visionect frame's bootloader says when it is flashed over the network,
4
+ as measured from packet captures. `pyvisionect.bootloader` implements it
5
+ without I/O; `pyvisionect.io.bootloader` drives it on asyncio streams.
6
+
7
+ [firmware.md](firmware.md) describes the same protocol as the vendor gateway
8
+ implements it (firmware protocol v3, `0xF0000002`): the `StartV3`, `Control`
9
+ and `DataV2` structs, the flag bits and the container format. The field names
10
+ below come from there. Where the capture disagrees with that reading, the
11
+ capture wins, and firmware.md records the correction.
12
+
13
+ ## Using the asyncio driver
14
+
15
+ Load the file and install the handler before rebooting the chosen frame.
16
+ This factory creates a handler for one transfer to one device:
17
+
18
+ ```python
19
+ import asyncio
20
+
21
+ from pyvisionect.bootloader import HELLO_SIZE, State, parse_hello
22
+ from pyvisionect.io.bootloader import run_bootloader
23
+
24
+
25
+ def firmware_handler(build, firmware, device_id):
26
+ pending = True
27
+
28
+ async def handle(reader, writer, first):
29
+ nonlocal pending
30
+ hello_bytes = first + await asyncio.wait_for(
31
+ reader.readexactly(HELLO_SIZE - len(first)), timeout=30,
32
+ )
33
+ hello = parse_hello(hello_bytes)
34
+ if hello.device_id != device_id or not pending:
35
+ return
36
+ pending = False
37
+ session = await run_bootloader(
38
+ reader, writer, hello_bytes,
39
+ firmware=firmware, build=build, device_id=device_id,
40
+ on_events=lambda events: print(events),
41
+ # allow_unpinned=True, # only to flash a build with no SHA-256 pin
42
+ )
43
+ if session.state is State.FAILED:
44
+ print(session.error, "records sent:", session.sent_any_record)
45
+ else:
46
+ print("Transfer complete; waiting for a normal status to verify it")
47
+
48
+ return handle
49
+ ```
50
+
51
+ For an existing `VisionectServer`, select and prepare the file in a worker
52
+ thread, then install the handler and send the reboot:
53
+
54
+ ```python
55
+ from pathlib import Path
56
+
57
+ from pyvisionect.io.firmware import FirmwareRepository, compatible
58
+
59
+ repo = FirmwareRepository(Path("firmware-cache"))
60
+ if not await asyncio.to_thread(repo.refresh) and repo.builds() is None:
61
+ raise RuntimeError(repo.last_error)
62
+
63
+ # Use the hardware and display from the selected device's status.
64
+ choices = compatible(
65
+ repo.builds() or [], hardware=(1, 1, 0),
66
+ hardware_name_id=8, display_id=3255107884,
67
+ )
68
+ build = next(b for b in choices if b.checksum == target_checksum)
69
+ firmware = await asyncio.to_thread(repo.fetch, build)
70
+ conn = server.connection_for(device_id) # 16-byte id, not the UUID string
71
+ if conn is None:
72
+ raise RuntimeError("Wait for the frame to connect before rebooting it")
73
+ server.on_bootloader = firmware_handler(build, firmware, device_id)
74
+ conn.reboot()
75
+ await server.flush(device_id)
76
+ ```
77
+
78
+ `run_bootloader` only flashes builds with a SHA-256 pin in
79
+ `pyvisionect.io.firmware.KNOWN_SHA256` (`build.pinned`): the two measured on
80
+ hardware. Any other build came over plain HTTP with nothing to check it
81
+ against, and a substituted file could stop a flash part way, so it raises
82
+ `RepositoryError` before sending anything unless the caller passes
83
+ `allow_unpinned=True`.
84
+
85
+ The application owns the pending-request timeout and final verification.
86
+ On a subsequent `StatusReceived` for this device, compare the status fields
87
+ `Firmware` (a dict with `major`, `minor`, `revision`) and `FirmwareID` with
88
+ `build.version` and `build.checksum`. Keep serving the normal protocol while waiting. A completed
89
+ transfer alone does not prove the new firmware booted.
90
+
91
+ ## What was measured
92
+
93
+ Two captures of Visionect's own Software Suite 7.6.5 flashing a Place & Play 32"
94
+ (hardware 1.1.0, hardware name id 8, display id 3255107884), bootloader 6.3.3830:
95
+ from firmware 7.4.4407 (`2cb91ed6`) to 7.3.4358 (`a529a106`), and back to
96
+ 7.4.4407. One frame, two builds. The tables below quote the first; the second has
97
+ the same shape, and replaying it through the module reproduces all 233336 bytes
98
+ the Suite sent. A decoder over the capture reproduces every
99
+ message below byte for byte, including the 232064-byte file the server relayed,
100
+ which is identical to the body the Suite downloaded from the repository.
101
+
102
+ All integers are little-endian. Every bootloader message starts with the word
103
+ `0xF0000002` (bytes `02 00 00 f0`, the firmware protocol v3 `Header.Version`);
104
+ the second word (`Header.Type`) says what it is.
105
+
106
+ ## The conversation
107
+
108
+ 1. The frame is told to reboot with an ordinary command packet (`CommandType 1`).
109
+ About 12 s later its bootloader opens a **new** TCP connection to the same
110
+ server port (11113). It did not on the boot right after the flash, which went
111
+ straight to the normal protocol, so it is not every boot. Frames on Tesserae
112
+ have rebooted normally without an answer, but a hello going unanswered has not
113
+ been captured.
114
+ 2. **Hello** (the vendor's `StartV3`), frame to server, 88 bytes (22 words):
115
+
116
+ | word | value in the capture | `StartV3` field | meaning |
117
+ |---|---|---|---|
118
+ | 0 | `0xf0000002` | `Header.Version` | magic |
119
+ | 1 | 0 | `Header.Type` | kind: hello (firmware.md's reading says 3; the capture says 0) |
120
+ | 2 | `0x2cb91ed6` | `FW` | checksum of the firmware running now (equals the repository's checksum for 7.4.4407) |
121
+ | 3 | `0xffffffff` | `HW` | hardware id word |
122
+ | 4 | `0x000a0000` | `Space` | bytes available for the image (655360) |
123
+ | 5-8 | `36002000 12473830 39333036 00000000` | `ID` | the 16-byte device id |
124
+ | 9-11 | 7, 4, 4407 | `FirmwareMajor/Minor/Revision` | firmware version |
125
+ | 12-14 | 6, 3, 3830 | `BootloaderMajor/Minor/Revision` | bootloader version |
126
+ | 15 | 8 | `HardwareNameID` | hardware name id |
127
+ | 16-18 | 1, 1, 0 | `HardwareMajor/Minor/Revision` | hardware version (the repository calls the last one BOM) |
128
+ | 19 | 0 | `HWFWInterface` | the status packet's `HardwareFirmwareIface` |
129
+ | 20 | `0x1e` | `HeartbeatInterval` | 30 |
130
+ | 21 | `0xc205012c` | `DisplayID` | display id (the `DisplayType` of the normal status packet) |
131
+
132
+ The 16-byte device id that the normal protocol uses is bytes 20..35 (words 5
133
+ to 8): `36002000-1247-3830-3933-303600000000` for this frame. The values
134
+ agree with the repository's metadata and the normal status packet (firmware,
135
+ hardware, display id and checksum). `Space` is what the vendor gateway checks
136
+ the image against ("no enough space on device"), and so does this module.
137
+ 3. **Offer**, server to frame, 16 bytes: a `Control` packet with
138
+ `PacketNumber` 0, `Ack` `0xffff`, and the target firmware checksum in `Info`
139
+ (`06 a1 29 a5` for `a529a106`). No reply to it was seen.
140
+ 4. **Firmware file**, relayed unchanged, one **record** at a time. A record is
141
+ the 8-byte header, a 16-byte `DataV2`, and a payload:
142
+
143
+ | bytes | value | `DataV2` field | meaning |
144
+ |---|---|---|---|
145
+ | 0-3 | `02 00 00 f0` | `Header.Version` | magic |
146
+ | 4-7 | 2 | `Header.Type` | kind: record |
147
+ | 8-9 | 1..184 | `PacketNumber` | block index, 1-based |
148
+ | 10-11 | 9, once in most builds 8; 13 on the last | `Flags` | bit 0 LZ4, bit 2 last record, bit 3 encrypted |
149
+ | 12-13 | 1616 on the first | `PayloadLength` | so the record is `24 + length` bytes; always a multiple of 16 |
150
+ | 14-15 | 2020; 1452 on the last | `Uncompressed` | plaintext size of the block |
151
+ | 16-17 | 0..15 | `Payload` | cipher padding bytes |
152
+ | 18-19 | 0 | `Reserved` | |
153
+ | 20-23 | | `Checksum` | CRC-32 of the plaintext block |
154
+
155
+ The payload is AES-CBC under a fleet-wide key (firmware.md). The file is 184
156
+ records ending exactly at its end (232064 bytes). Records are found by
157
+ following the length field from byte 0, never by searching for the magic,
158
+ which could occur in ciphertext. Record sizes were 56 to 2040 bytes.
159
+ 5. **Stop and wait.** After each record the frame sends a 16-byte `Control`
160
+ ack: magic, `1`, the block index (uint16), `ff ff`, `00 00 00 00`. The server
161
+ sends the next record only after the ack. Acks came 27 ms to 1.16 s after the
162
+ record (median 50 ms); three took about a second (possibly flash erase).
163
+ Offer to first record took 1.3 s, which was the Suite downloading the file.
164
+ Flags 8 (encrypted, not LZ4: a block compression did not shrink) is on one
165
+ block of some builds (block 130 of 7.4.4407) and none of others. The frame
166
+ acked it like any other, 44 ms later, and the slowest ack in that flash was
167
+ 1.7 s. The whole flash took about 13 s.
168
+ 6. After the last ack the Suite closed the connection with a TCP reset 4.6 ms
169
+ later. The frame then booted the new firmware and connected on the normal
170
+ protocol about 10 s later with connect reason "reboot".
171
+
172
+ The repository (`http://firmware.visionect.com:8089`): `GET /api/v2/list` (the
173
+ v1 list lacks this display), JSON with ETag support, entries with
174
+ `Meta.AppName`, `type`, `Checksum` (hex, leading zeros dropped), `FwMajor`,
175
+ `FwMinor`, `FwRevision`, `HwMajor`, `HwMinor`, `HwBOM`, `HwNameID`, `DisplayID`;
176
+ `GET /api/v1/get/<checksum>` returns the file.
177
+
178
+ ## What the module checks
179
+
180
+ These are all errors: wrong magic or kind; a hello or ack of the wrong size; an
181
+ ack for any block but the one just sent (or a repeat); data the frame had no
182
+ reason to send before the last ack; a hello that does not arrive complete in
183
+ time; no ack within 15 s (the vendor gateway's per-block timeout); a disconnect;
184
+ a file larger than the hello's `Space`; and a file that does not walk. A file
185
+ walks when its blocks are numbered 1..N with no gap, it ends exactly at the end
186
+ of the file, every record has the encrypted bit, only the last has the
187
+ last-record bit, no unknown bit is set, and every payload is whole 16-byte
188
+ blocks with under 16 bytes of padding.
189
+
190
+ Bytes after the last ack are reported as a `TrailingData` event and the
191
+ transfer stays `DONE`, since every record was acknowledged.
192
+
193
+ The asyncio driver refuses a bootloader other than 6.3 before sending an offer,
194
+ and checks the device id, hardware revision, hardware name and display. It
195
+ refuses a build without a SHA-256 pin unless `allow_unpinned=True`. Sans-io
196
+ callers supply their own `accept_hello` policy. Nothing is retried.
197
+
198
+ ## What is not known
199
+
200
+ - What the `HW` word means beyond "0 is unconfigured", and the record
201
+ `Checksum`'s exact role on the frame. Bits 1 and 4..15 of `Flags` have never
202
+ been seen, and a record using them is refused.
203
+ - How a NACK is encoded. firmware.md's reading of the gateway treats
204
+ `Ack == 0xffff` as a NACK, but every ack in the capture carries `0xffff` with
205
+ `Info` 0, so that reading is inverted or incomplete. A NACK has never been
206
+ captured. The module stops on anything but the observed ack, where the vendor
207
+ gateway would resend the block up to 3 times.
208
+ - Whether the firmware is signed or checksummed beyond what the frame checks
209
+ itself, and how the repository's checksum is computed (it is not CRC32 or
210
+ Adler-32 of the file, nor of the payloads; firmware.md argues it is the CRC-32
211
+ of the decrypted image). The file is checked for structure. The repository
212
+ client also checks SHA-256 pins for the two builds measured on hardware; other
213
+ builds have no trusted digest.
214
+ - What the frame does if a flash is interrupted. It has never been observed. The
215
+ documented way out is the USB Configurator. (The vendor gateway resumes an
216
+ interrupted update from the last acknowledged block; this module does not.)
217
+ - Whether the 1.3 s between offer and first record, or the reset (rather than a
218
+ normal close) after the last ack, matter. Both mirror the capture. The file is
219
+ fetched over plain HTTP with no signature to check, the same as the Suite does;
220
+ its SHA-256 is logged when it is offered.
221
+ - Whether the frame needs the hello to be answered within some time (the Suite
222
+ answered in 1.5 ms), whether it acks the offer, and any behaviour on a server
223
+ that sends something other than the Suite did.
224
+ - Other hardware, other firmware versions, other bootloader versions, downgrades
225
+ from another family.
@@ -6,6 +6,11 @@ toolchain and the device's bootloader. What you *can* do is relay a vendor image
6
6
  because the container is fully understood. Whether you should is another matter — see
7
7
  [the warning](#should-a-reimplementation-do-this-at-all).
8
8
 
9
+ This library now does relay one, opt-in: [bootloader.md](bootloader.md) is the protocol
10
+ as captured from the vendor's Software Suite flashing a real frame, and the module that
11
+ implements it. Where that capture contradicts the reading of the gateway below, the
12
+ capture is marked here as a correction.
13
+
9
14
  ## Three transports, not one
10
15
 
11
16
  This is the most important structural fact, and it is easy to miss:
@@ -67,6 +72,12 @@ inside the protocol accepts `0xF0000000` too.
67
72
  | 2 | Data (one firmware block) | server → device |
68
73
  | 3 | Start (the first packet) | device → server |
69
74
 
75
+ > **Correction from the capture.** [W] On bootloader 6.3.3830 the Start packet arrives
76
+ > with `Type = 0`, not 3. `Control` (`Type = 1`) also goes **device → server**: the frame
77
+ > acks every block with one, and the server's first packet (its answer to Start) is a
78
+ > `Control` too. `Data` is `Type = 2` as read. Whether the verifier described above is
79
+ > misread or the 6.3 bootloader differs is [GAP]. See [bootloader.md](bootloader.md).
80
+
70
81
  Every packet on this connection is the 8-byte `Header` followed by a fixed-size body, read
71
82
  with little-endian binary decoding. It is **not** the normal `ProtocolHeader` /
72
83
  `DataHeader` nesting.
@@ -204,6 +215,13 @@ Server-internal errors in the same package, never on the wire: `timed out`,
204
215
  `sent incomplete data`, `resend limit reached`, `invalid version`,
205
216
  `already in progress`. [D]
206
217
 
218
+ > **Correction from the capture.** [W] Every ack the frame sent carried `Ack = 0xFFFF`
219
+ > and `Info = 0`, block after block, and the flash completed — so `0xFFFF` is **not** a
220
+ > NACK on the wire, and the reading above is inverted or incomplete. The server's answer
221
+ > to Start was `Control{PacketNumber: 0, Ack: 0xFFFF, Info: <target firmware checksum>}`:
222
+ > `Info` carries the requested image's CRC there, not a reason code. A real NACK has never
223
+ > been captured, so its encoding is [GAP].
224
+
207
225
  ## The transfer state machine
208
226
 
209
227
  ```
@@ -625,15 +643,32 @@ once.** Do not re-run key searches without new information.
625
643
 
626
644
  ## Should a reimplementation do this at all?
627
645
 
628
- **Probably not.** The honest position:
646
+ This section used to answer "probably not". The library now ships the app-firmware relay
647
+ ([bootloader.md](bootloader.md)), so the question is how narrowly. The risks have not
648
+ gone away:
629
649
 
630
650
  - You cannot build an image, so there is nothing to gain beyond relaying a vendor blob.
631
- - Relaying a blob means handing a device an opaque payload it will write to its own flash,
632
- with a container you reconstructed, over a path you cannot test without risking the only
633
- hardware you have. The update is not transactional and there is no rollback packet.
634
- - The reference sign is already at the newest version its hardware revision can take, which
635
- is a common situation given the catalogue shape.
636
-
637
- If you implement anything here, implement the **read** side — parse the containers, read
638
- the catalogue, report to the user which version they are on and whether a newer one exists
639
- for their key. That is useful and risk-free. Leave the write path off by default.
651
+ - Relaying a blob means handing a device an opaque payload it will write to its own flash.
652
+ The update is not transactional and there is no rollback packet.
653
+ - Many signs are already at the newest version their hardware revision can take, given
654
+ the catalogue shape.
655
+
656
+ What changed is that the write path was measured rather than reconstructed: a capture of
657
+ the vendor's Software Suite flashing a real frame, both directions, byte for byte, on one
658
+ hardware revision and two builds. The implementation is kept to that envelope:
659
+
660
+ - **Off by default.** `VisionectServer` answers a bootloader only when given an
661
+ `on_bootloader` callback; without one the frame gets no offer and boots as before.
662
+ - **Only what was measured.** It refuses a bootloader other than 6.3, a device, hardware
663
+ revision, hardware name or display that does not match the chosen build, an image larger
664
+ than the Start packet's `Space`, and a file that does not walk cleanly.
665
+ - **Only trusted files, unless told otherwise.** The two builds flashed in the capture
666
+ carry SHA-256 pins; anything else needs an explicit `allow_unpinned=True`, because the
667
+ vendor service is plain HTTP with nothing else to check a file against.
668
+ - **No retries, no resume.** Unlike the vendor gateway, it stops on the first unexpected
669
+ message instead of resending or resuming. An interrupted flash is left to the vendor's
670
+ USB Configurator.
671
+
672
+ The **read** side — parse the containers, read the catalogue, report which version a sign
673
+ is on and whether a newer one exists for its key — remains useful and risk-free on its
674
+ own, and is what `pyvisionect.io.firmware` provides without touching a device.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pyvisionect"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Sans-io reimplementation of the Visionect e-ink sign wire protocol (protocol v3)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"