hsms: HSMS-GS multi-session support (E37 §11)

Connection now supports both HSMS-SS (single session — the
constructor's behaviour, unchanged) and HSMS-GS (multi-session).
add_session(device_id) registers additional sessions; each one has
its own NotSelected/Selected state and its own message/selected
handlers.  In GS mode the Select.req carries session_id=device_id;
in SS mode it stays at 0xFFFF (legacy).  Linktest/Separate remain
connection-scope per spec.

Public API additions:
  add_session(device_id)
  set_session_message_handler(device_id, h)
  set_session_selected_handler(device_id, h)
  session_state(device_id) -> State
  is_session_selected(device_id) -> bool
  send_request(device_id, msg, cb)
  send_data(device_id, msg)

Internal refactor: state_/on_message_/on_selected_ folded into a
SessionSlot map keyed by device_id; SS-style getters/setters route
through the primary session.  T7 + linktest are connection-scope —
T7 fires only when no session is selected; linktest runs while at
least one is.

Five wire-level tests:
  - passive: two sessions selected independently via Select.req
    with their own session_id
  - GS Select.req for an unregistered session id is Rejected
    (EntityNotSelected)
  - data routed by session_id; data on a not-selected session is
    Rejected
  - active: two registered sessions both end up selected via
    serialized Select.req per session
  - SS legacy: existing single-session API still works (session_id
    0xFFFF in Select.req)

COMPLIANCE.md §1 updated: HSMS-GS row goes .

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 11:40:38 +02:00
parent 998e81b3d8
commit d0c7fb71b6
5 changed files with 516 additions and 54 deletions
+2 -2
View File
@@ -41,8 +41,8 @@ Legend:
| T6 control transaction timeout | ✅ | E37 §10 | One concurrent control transaction. |
| T7 not-selected timeout (passive) | ✅ | E37 §10 | Armed on connect / on Deselect.req. |
| T8 intercharacter timeout | ✅ | E37 §10 | Bounds the payload read after length prefix. |
| HSMS-SS (single-session) | ✅ | E37 §11 | The codebase is HSMS-SS only by design. |
| HSMS-GS (general-session) | | E37 §11 | Multi-session; out of scope for this revision. |
| HSMS-SS (single-session) | ✅ | E37 §11 | Default mode: the constructor registers a single session. |
| HSMS-GS (general-session) | | E37 §11 | `Connection::add_session(device_id)` registers extra sessions; per-session SELECTED state + message handlers; Select.req carries session_id=device_id in GS mode. |
---