Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
hub_pairing.h
Go to the documentation of this file.
1#pragma once
2
3/// @file hub_pairing.h
4/// @brief Internal pairing-state model for hub‑owned discovery and key‑exchange flows.
5///
6/// This module implements the three‑phase pairing procedure that temporarily tracks a
7/// newly paired device in the controller's runtime registry and installs the system key on the device:
8///
9/// Phase 1 — Discovery (broadcast 0x28 → device responds 0x29):
10/// Controller broadcasts a discovery packet on the primary channel. A device in
11/// pairing mode (PROG button pressed) responds with its node ID and type/subtype.
12/// The controller validates the response and extracts device metadata.
13///
14/// Phase 2 — Authenticated Key Exchange (0x31 → 0x3C → 0x32 → 0x33):
15/// The controller sends CMD_KEY_INIT (0x31) to the device. The device challenges
16/// with CMD_CHALLENGE_REQ (0x3C). The controller proves knowledge of the system
17/// key with CMD_CHALLENGE_RESP (0x3D) and simultaneously sends the encrypted system
18/// key via CMD_KEY_TRANSFER (0x32). The device confirms with CMD_KEY_CONFIRM (0x33).
19///
20/// Phase 3 — Configuration (CMD_SET_CONFIG1):
21/// The controller sends a configuration frame (0x6F) to enable automatic status
22/// updates from the device. This phase completes even if the config frame fails;
23/// the device will still operate in polled mode.
24///
25/// All frames use the standard authenticated exchange flow defined in hub_exchange.h.
26/// The pairing state machine serializes these phases, logs the YAML metadata the user should add,
27/// and keeps the paired device in the current runtime registry until reboot.
28
29#include "proto_frame.h"
30#include "radio_interface.h"
31#include <cstdint>
32#include <string>
33
34namespace esphome {
35namespace home_io_control {
36
37namespace pairing {
38
39/// @brief State machine for the three‑phase pairing flow.
40enum class PairingState : uint8_t {
41 IDLE, ///< No pairing in progress; idle state.
42 TX_DISCOVER, ///< Discovery broadcast (0x28) sent; awaiting device response.
43 WAIT_DISCOVER_RESPONSE, ///< Listening for discovery response (0x29) from a device in pairing mode.
44 TX_KEY_INIT, ///< Key‑init (0x31) sent to the discovered device.
45 WAIT_KEY_CHALLENGE, ///< Waiting for challenge (0x3C) from device as part of key transfer.
46 TX_KEY_TRANSFER, ///< Key‑transfer (0x32) sent with encrypted system key.
47 WAIT_KEY_CONFIRM, ///< Waiting for key‑confirm (0x33) from device (key receipt acknowledgement).
48 REGISTER_DEVICE, ///< Registering device in the runtime registry for the current boot.
49 COMPLETE, ///< Pairing completed successfully; device ready for use.
50 FAILED, ///< Pairing failed (timeout, radio error, or protocol violation).
51};
52
53/// @brief Context object that lives for the duration of a single pairing attempt.
55 PairingState state{PairingState::IDLE}; ///< Current state machine state.
56 IoDevice device{}; ///< Resolved device metadata after discovery (node_id, type, subtype, etc.).
57 IoFrame req{}; ///< Outbound frame buffer (reused across all phases).
58 IoFrame resp{}; ///< Inbound frame buffer (holds key‑confirm response).
59 IoFrame rx{}; ///< Raw RX frame during waiting phases (discovery, challenge, confirm).
60 IoFrame key_init{}; ///< Key‑init frame retained for key‑transfer IV derivation.
61 RadioRxPacket packet{}; ///< Raw radio capture for the current phase.
62 std::string device_id; ///< Hex string representation of the paired node ID.
63 bool discovery_metadata_complete{false}; ///< True when discovery carried type/subtype bytes.
64};
65
66} // namespace pairing
67
68} // namespace home_io_control
69} // namespace esphome
PairingState
State machine for the three‑phase pairing flow.
Definition hub_pairing.h:40
@ REGISTER_DEVICE
Registering device in the runtime registry for the current boot.
Definition hub_pairing.h:48
@ TX_DISCOVER
Discovery broadcast (0x28) sent; awaiting device response.
Definition hub_pairing.h:42
@ WAIT_DISCOVER_RESPONSE
Listening for discovery response (0x29) from a device in pairing mode.
Definition hub_pairing.h:43
@ COMPLETE
Pairing completed successfully; device ready for use.
Definition hub_pairing.h:49
@ WAIT_KEY_CHALLENGE
Waiting for challenge (0x3C) from device as part of key transfer.
Definition hub_pairing.h:45
@ WAIT_KEY_CONFIRM
Waiting for key‑confirm (0x33) from device (key receipt acknowledgement).
Definition hub_pairing.h:47
@ TX_KEY_INIT
Key‑init (0x31) sent to the discovered device.
Definition hub_pairing.h:44
@ TX_KEY_TRANSFER
Key‑transfer (0x32) sent with encrypted system key.
Definition hub_pairing.h:46
@ IDLE
No pairing in progress; idle state.
Definition hub_pairing.h:41
@ FAILED
Pairing failed (timeout, radio error, or protocol violation).
Definition hub_pairing.h:50
IO-Homecontrol 2W protocol definitions.
Radio abstraction layer for IO-Homecontrol.
Runtime state of a paired IO‑Homecontrol device.
Parsed IO‑Homecontrol frame (CTRL0/1 + addresses + command + data).
Raw packet received from the radio.
Context object that lives for the duration of a single pairing attempt.
Definition hub_pairing.h:54
IoFrame req
Outbound frame buffer (reused across all phases).
Definition hub_pairing.h:57
PairingState state
Current state machine state.
Definition hub_pairing.h:55
IoFrame resp
Inbound frame buffer (holds key‑confirm response).
Definition hub_pairing.h:58
RadioRxPacket packet
Raw radio capture for the current phase.
Definition hub_pairing.h:61
IoDevice device
Resolved device metadata after discovery (node_id, type, subtype, etc.).
Definition hub_pairing.h:56
IoFrame key_init
Key‑init frame retained for key‑transfer IV derivation.
Definition hub_pairing.h:60
std::string device_id
Hex string representation of the paired node ID.
Definition hub_pairing.h:62
bool discovery_metadata_complete
True when discovery carried type/subtype bytes.
Definition hub_pairing.h:63
IoFrame rx
Raw RX frame during waiting phases (discovery, challenge, confirm).
Definition hub_pairing.h:59