micromate/opcodes.py holds WRITE_SUBS and the cross-series collision 0xA2.
MicromateProtocol._send reads the SUB of the bytes about to go out
(framing.request_sub) and refuses any write SUB not in allowed_writes, and
0xA2 unconditionally. Docstrings now say the reads-only policy is enforced.
request_sub also refuses any frame not in canonical form
(stuff(unstuff(body)) == body): an interior unescaped 02/03/04, a 10 XX
outside {02,03,04,10}, or a trailing lone DLE. What the gate checks is then
exactly what the unit parses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
"""Micromate (Series IV) opcode table: which SUBs write, and which collide.
|
|
|
|
One place, as the parity spec requires. `MicromateProtocol._send` consults it
|
|
on every outgoing frame, so a write cannot reach a unit by a path nobody
|
|
thought about -- a scratch tool calling `protocol._send`, a hand-built frame, a
|
|
method added later.
|
|
|
|
Every SUB here was seen as a host->unit request in THOR's captures
|
|
(`docs/micromate_protocol_reference.md`). The table classifies REQUESTS: a few
|
|
of these values are also ACK SUBs of other commands (0x71 acks 0x8E, 0x72 acks
|
|
0x8D), which is irrelevant to a send-side check.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Dict, FrozenSet
|
|
|
|
WRITE_SUBS: Dict[int, str] = {
|
|
0x47: "scheduler enable/disable",
|
|
0x68: "setup push: preferences block (0x08)",
|
|
0x71: "setup push: setup block (0x1A)",
|
|
0x72: "setup push: setup confirm",
|
|
0x73: "setup push: preferences confirm",
|
|
0x7E: "call-home config write (0x2C)",
|
|
0x7F: "call-home config confirm",
|
|
0x82: "setup push: trigger block (0x2E)",
|
|
0x83: "setup push: trigger confirm",
|
|
0x8D: "file open for write",
|
|
0x8E: "file body write",
|
|
0x96: "start monitoring",
|
|
0x97: "stop monitoring",
|
|
0xA2: "end call-home",
|
|
0xA8: "delete one event",
|
|
0xAA: "delete-event confirm",
|
|
0xDA: "setup push: file name",
|
|
}
|
|
|
|
# Same bytes, opposite consequence on the other series. Never transmitted on
|
|
# Series IV, allowed or not: if a Series-III unit is at the address (a moved
|
|
# modem, a stale IP), it would execute the other meaning. Lifting an entry is
|
|
# a spec change, not a parameter.
|
|
CROSS_SERIES_COLLISIONS: Dict[int, str] = {
|
|
0xA2: "CONFIRM ERASE on Series III -- erases every stored event; "
|
|
"'end call-home' on Series IV",
|
|
}
|
|
|
|
|
|
class OpcodeRefused(RuntimeError):
|
|
"""A frame was stopped before it reached the wire."""
|
|
|
|
|
|
def check_transmit(sub: int, allowed_writes: FrozenSet[int] = frozenset()) -> None:
|
|
if sub in CROSS_SERIES_COLLISIONS:
|
|
raise OpcodeRefused(
|
|
f"refused to transmit SUB 0x{sub:02X}: {CROSS_SERIES_COLLISIONS[sub]}")
|
|
if sub in WRITE_SUBS and sub not in allowed_writes:
|
|
raise OpcodeRefused(
|
|
f"refused to transmit SUB 0x{sub:02X} ({WRITE_SUBS[sub]}): writes are "
|
|
"not enabled on this connection")
|