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