MiniMate config writes are mis-encoded: 02/03/04/10 in write data must be DLE-escaped (Blastware does; build_bw_write_frame doesn't) #46

Closed
opened 2026-10-26 17:14:12 -04:00 by serversdown · 3 comments
Owner

Summary

SFM's MiniMate config-write frames are encoded wrongly whenever their data contains a 02, 03, 04 or 10 byte. Blastware escapes those four values in write frames exactly as it does in read requests. minimateplus.framing.build_bw_write_frame sends them raw ("only BW_CMD doubled") and uses a "DLE-aware checksum". Until this is fixed, don't use SFM's MiniMate config push or call-home write. Blastware and the keypad are unaffected, and so is start/stop (0x96/0x97 carry no data).

Measured (2026-10-26, BE9441)

Recording: bridges/captures/10-26-26 - BE9441 blastware histogram/mmlink_20261026_160828/. It holds two Blastware "Send To Unit"s, at 16:26:10 (Histogram mode, 15-minute interval, mic enabled) and 16:27:21 (interval back to 2 s). Each send is the full sequence 68→73 | 71×5→72 | 82→83 | 69→74→72, 13 frames.

  • All 26 write frames rebuild byte for byte as an ordinary request: payload [10 00 SUB 00][length BE][params 10][data], SUM8 of that payload, every 02/03/04/10 DLE-escaped (framing.s3_stuff), wrapped 41 02 … 03.
  • build_bw_write_frame reproduces 6 of 13 per send: the five confirms plus the 82 trigger write, whose data happens to hold no special bytes. It gets 68, all five 71s and 69 wrong.
  • The compliance image is 2,092 bytes. Blastware sends it as 4 × 0x200 plus 0x2C, with payload[4:6] the length and params[2:4] the address (0x0000 … 0x0800).
    • The 3-11-26 notes' "offset 0x1004 / chunk-2 params 00 00 00 10 04" were length 0x0400 and address 0x0400, escaped. Same misreading as the retracted 5A model.
    • Send 2 differs from send 1 in exactly two image bytes: [8:10] 03 84 → 00 02 (the interval).

Inferred, not tested on a unit

  • A raw 03 in the data would end the frame early at the unit. No ack, so it fails loudly.
  • A raw 10 followed by an ordinary byte (e.g. 4096 sps = 10 00) is probably taken as an escape, and the 10 dropped. That would shift the rest of the config by one byte, silently.
  • A wrinkle: compliance_raw comes from the parser, which keeps the 10 of each 10 02/03/04 but collapses 10 10 to 10. So a round-tripped 03 happens to go out correctly escaped, while a 10 goes out bare. Whatever has worked so far may have avoided the dangerous case by luck. Not checked.

Where

  • minimateplus/framing.py: build_bw_write_frame.
  • minimateplus/client.py: push_config_raw, the compliance encoder, the call-home write (0x7E → POST /device/call_home).
  • Docs: the CLAUDE.md "Write commands" section and Series-III reference §3/§10. The suspicion is recorded as row 2026-10-26 (4).

Fix

  • Build write frames like requests: s3_stuff over the logical payload, with a SUM8 checksum.
  • Convert compliance_raw to logical bytes before editing and writing it.
  • Test against all 26 recorded Blastware frames. Cut the image into chunks the way Blastware does.
  • This is code that writes to units, so it gets its own branch and a review before any send.

Found on feat/series4-sfm-parity (8acb951).

## Summary SFM's MiniMate **config-write frames are encoded wrongly** whenever their data contains a `02`, `03`, `04` or `10` byte. Blastware escapes those four values in write frames exactly as it does in read requests. `minimateplus.framing.build_bw_write_frame` sends them raw ("only BW_CMD doubled") and uses a "DLE-aware checksum". **Until this is fixed, don't use SFM's MiniMate config push or call-home write.** Blastware and the keypad are unaffected, and so is start/stop (`0x96`/`0x97` carry no data). ## Measured (2026-10-26, BE9441) Recording: `bridges/captures/10-26-26 - BE9441 blastware histogram/mmlink_20261026_160828/`. It holds two Blastware "Send To Unit"s, at 16:26:10 (Histogram mode, 15-minute interval, mic enabled) and 16:27:21 (interval back to 2 s). Each send is the full sequence `68→73 | 71×5→72 | 82→83 | 69→74→72`, 13 frames. - **All 26 write frames** rebuild byte for byte as an ordinary request: payload `[10 00 SUB 00][length BE][params 10][data]`, SUM8 of that payload, every `02/03/04/10` DLE-escaped (`framing.s3_stuff`), wrapped `41 02 … 03`. - **`build_bw_write_frame` reproduces 6 of 13 per send:** the five confirms plus the 82 trigger write, whose data happens to hold no special bytes. It gets **68, all five 71s and 69** wrong. - **The compliance image is 2,092 bytes.** Blastware sends it as 4 × 0x200 plus 0x2C, with `payload[4:6]` the length and `params[2:4]` the address (0x0000 … 0x0800). - The 3-11-26 notes' "offset 0x1004 / chunk-2 params `00 00 00 10 04`" were length 0x0400 and address 0x0400, escaped. Same misreading as the retracted 5A model. - Send 2 differs from send 1 in exactly two image bytes: `[8:10]` `03 84` → `00 02` (the interval). ## Inferred, not tested on a unit - A raw `03` in the data would end the frame early at the unit. No ack, so it fails loudly. - A raw `10` followed by an ordinary byte (e.g. 4096 sps = `10 00`) is probably taken as an escape, and the `10` dropped. That would shift the rest of the config by one byte, silently. - A wrinkle: `compliance_raw` comes from the parser, which keeps the `10` of each `10 02/03/04` but collapses `10 10` to `10`. So a round-tripped 03 happens to go out correctly escaped, while a 10 goes out bare. Whatever has worked so far may have avoided the dangerous case by luck. Not checked. ## Where - `minimateplus/framing.py`: `build_bw_write_frame`. - `minimateplus/client.py`: `push_config_raw`, the compliance encoder, the call-home write (`0x7E` → `POST /device/call_home`). - Docs: the CLAUDE.md "Write commands" section and Series-III reference §3/§10. The suspicion is recorded as row 2026-10-26 (4). ## Fix - Build write frames like requests: `s3_stuff` over the logical payload, with a SUM8 checksum. - Convert `compliance_raw` to logical bytes before editing and writing it. - Test against all 26 recorded Blastware frames. Cut the image into chunks the way Blastware does. - This is code that writes to units, so it gets its own branch and a review before any send. Found on `feat/series4-sfm-parity` (`8acb951`).
serversdown added the Kind/Bug
Priority
High
2
labels 2026-10-26 17:14:12 -04:00
Author
Owner

Fixed on feat/series4-sfm-parity (b5037b0; docs 329f7f2). Not yet sent to a unit: the first live config push is a bench session with Brian present.

Measured basis, now broader than when this was filed: Brian uploaded the Feb–Apr 2026 captures, and 3,869/3,869 Blastware requests in them re-encode under the uniform rule. That includes 48 write frames carrying data from March, the frames the old model was fitted to, plus the 26 from 2026-10-26.

What changed:

  • build_bw_write_frame: uniform escaping, SUM8, length = len(data).
  • write_image(): unescapes the parser's form, adds the block's 2 trailing bytes when a read returned N, and refuses any image that isn't N+2 before sending. That turns the old encoder's leftover-escape-byte hazard into a loud error.
  • Compliance writes: 512-byte addressed chunks.
  • Reads: read_event_index and read_waveform_data_raw unescape before slicing.
  • Second bug found and fixed: apply_config wrote a trigger block hard-coded from a March capture. Blastware reads it (SUB 0x2E), and its byte 5 varies by unit and session (01 / 03 / 04 on record), so the copy would have changed BE9441's setting. It now reads the unit's own block.
  • Call-home write (7E): goes through the same path. No Blastware 7E frame is on record here, so that one is inferred from the other 77 write frames.

Tests: every write frame on record rebuilt byte for byte; the protocol writes reproduce Blastware's frames from the blocks as read; six mutants, each caught. The old test_write_frames.py now runs against the March capture, rewritten to the measured model.

Fixed on `feat/series4-sfm-parity` (`b5037b0`; docs `329f7f2`). **Not yet sent to a unit:** the first live config push is a bench session with Brian present. Measured basis, now broader than when this was filed: Brian uploaded the Feb–Apr 2026 captures, and **3,869/3,869 Blastware requests** in them re-encode under the uniform rule. That includes **48 write frames carrying data** from March, the frames the old model was fitted to, plus the 26 from 2026-10-26. What changed: - **`build_bw_write_frame`:** uniform escaping, SUM8, length = len(data). - **`write_image()`:** unescapes the parser's form, adds the block's 2 trailing bytes when a read returned N, and **refuses any image that isn't N+2 before sending**. That turns the old encoder's leftover-escape-byte hazard into a loud error. - **Compliance writes:** 512-byte addressed chunks. - **Reads:** `read_event_index` and `read_waveform_data_raw` unescape before slicing. - **Second bug found and fixed:** `apply_config` wrote a trigger block hard-coded from a March capture. Blastware *reads* it (SUB 0x2E), and its byte 5 varies by unit and session (01 / 03 / 04 on record), so the copy would have changed BE9441's setting. It now reads the unit's own block. - **Call-home write (7E):** goes through the same path. No Blastware 7E frame is on record here, so that one is inferred from the other 77 write frames. Tests: every write frame on record rebuilt byte for byte; the protocol writes reproduce Blastware's frames from the blocks as read; six mutants, each caught. The old `test_write_frames.py` now runs against the March capture, rewritten to the measured model.
Author
Owner

Independent review of b5037b0: the framing holds up, but config push is not usable yet. The interim safety fix is 20ea61e.

What holds (measured): every recorded Blastware write rebuilds byte for byte, and all seven no-data frames (start/stop and the confirms) are byte-identical to before. Tonight's start/stop results stand.

C1 (measured on 12 recorded SFM reads): read_compliance_config takes data[11:] of each reply. The reply headers carry escaped bytes (10 04) that the parser keeps, so the block unescapes to 00 + cfg[0:1024] + 00 00 + cfg[1024:2090] (2,093 bytes). Every real config was refused, but only after 68 + 73 had been sent. Fixed in 20ea61e: push_config_raw checks all four blocks first, so nothing is sent.

C2 (measured on BE9441's real block): fixing that read alone would let _encode_compliance_config write some fields to the wrong bytes while the image still passes the N+2 guard. It writes logical values into the parser-form buffer at anchor-relative offsets. Examples: re-asserting 4,096 sps writes 10 10 (= 4,112); recording-mode edits land on byte [4]. In logical form, 49 of 140 edits were wrong but accepted.

The rework (todo):

  • Read the compliance block logically: the reply's page bytes + data, unescaped, then [13:].
  • Encode at the measured logical offsets: mode [5], rate [6:8], interval [8:10], record time [18:22], trigger Tran+30, alarm Tran+38. Range at Tran+29 is inferred. Do this together with #48.
  • Diff-check that only the requested fields changed, and decode the image to confirm the requested values.
  • Pin N per SUB (0x58, 0x082A, 0x1A, 0xC8, 0x7C).
  • Refuse writes unless 0x1C reads idle. (While BE9441 was monitoring, 08 and 1A returned blocks starting 42 45.)
  • Give POST /device/config the start/stop safeguards: identity, audit, read-back, no retry.
  • Test apply_config from recorded replies.

Also from the review:

  • I2: write_image unescapes reads that are already unescaped. That only matters for a logical 10 02/03/04 pair, and none is in the 40 recorded images.
  • I3: the 7E encoder's offsets assume no earlier escapes. This is pre-existing.
  • I4 test gaps: N+1 images, read_trigger_config unescaping, the 7E path, and confirm B.
  • M1–M4: stale docstrings, the unused offset override, and the read's late-frame/timeout handling.
**Independent review of `b5037b0`: the framing holds up, but config push is not usable yet.** The interim safety fix is `20ea61e`. **What holds** (measured): every recorded Blastware write rebuilds byte for byte, and all seven no-data frames (start/stop and the confirms) are byte-identical to before. Tonight's start/stop results stand. **C1 (measured on 12 recorded SFM reads):** `read_compliance_config` takes `data[11:]` of each reply. The reply headers carry escaped bytes (`10 04`) that the parser keeps, so the block unescapes to `00 + cfg[0:1024] + 00 00 + cfg[1024:2090]` (2,093 bytes). Every real config was refused, but only after `68` + `73` had been sent. **Fixed in `20ea61e`:** `push_config_raw` checks all four blocks first, so nothing is sent. **C2 (measured on BE9441's real block):** fixing that read alone would let `_encode_compliance_config` write some fields to the wrong bytes while the image still passes the N+2 guard. It writes logical values into the parser-form buffer at anchor-relative offsets. Examples: re-asserting 4,096 sps writes `10 10` (= 4,112); recording-mode edits land on byte [4]. In logical form, 49 of 140 edits were wrong but accepted. **The rework (todo):** - Read the compliance block logically: the reply's page bytes + data, unescaped, then `[13:]`. - Encode at the measured logical offsets: mode [5], rate [6:8], interval [8:10], record time [18:22], trigger Tran+30, alarm Tran+38. Range at Tran+29 is inferred. Do this together with #48. - Diff-check that only the requested fields changed, and decode the image to confirm the requested values. - Pin N per SUB (0x58, 0x082A, 0x1A, 0xC8, 0x7C). - Refuse writes unless 0x1C reads idle. (While BE9441 was monitoring, 08 and 1A returned blocks starting `42 45`.) - Give `POST /device/config` the start/stop safeguards: identity, audit, read-back, no retry. - Test `apply_config` from recorded replies. **Also from the review:** - **I2:** `write_image` unescapes reads that are already unescaped. That only matters for a logical `10 02/03/04` pair, and none is in the 40 recorded images. - **I3:** the 7E encoder's offsets assume no earlier escapes. This is pre-existing. - **I4 test gaps:** N+1 images, `read_trigger_config` unescaping, the 7E path, and confirm B. - **M1–M4:** stale docstrings, the unused `offset` override, and the read's late-frame/timeout handling.
Author
Owner

Fixed on dev by the Series-4 parity merge (5b342b4, changelog 75a1d13): every MiniMate request escapes 02/03/04/10, and a config write is an ordinary escaped request carrying a whole block, checked before the first frame. SFM's frames equal Blastware's in the 2026-04-20 and 2026-10-26 captures; benched end to end on BE9441 2026-11-04 (trigger, notes, several fields, alarm, restore -- each read back and confirmed on the unit's screen). Ships in the next release; the dev -> main PR will carry Fixes #46.

Fixed on dev by the Series-4 parity merge (5b342b4, changelog 75a1d13): every MiniMate request escapes 02/03/04/10, and a config write is an ordinary escaped request carrying a whole block, checked before the first frame. SFM's frames equal Blastware's in the 2026-04-20 and 2026-10-26 captures; benched end to end on BE9441 2026-11-04 (trigger, notes, several fields, alarm, restore -- each read back and confirmed on the unit's screen). Ships in the next release; the dev -> main PR will carry Fixes #46.
Sign in to join this conversation.