Skip to content

PoC: Zigbee Border Router (raw ZCL over UDP/IPv6) - #148

Draft
t3hk0d3 wants to merge 6 commits into
zigpy:devfrom
t3hk0d3:zbr-spike
Draft

t3hk0d3 wants to merge 6 commits into
zigpy:devfrom
t3hk0d3:zbr-spike

Conversation

@t3hk0d3

@t3hk0d3 t3hk0d3 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Throwaway spike, not for merging. This draft is here to share the code and findings.

What it is

A gateway that makes every device on a Zigbee network reachable over IPv6. Anything with a
UDP socket can then talk to a device in raw ZCL, without a Zigbee radio, zigpy or a vendor
SDK. It is modelled on Z-Wave Z/IP and on how an OpenThread Border Router publishes a Thread
network. Design note: docs/superpowers/specs/2026-11-21-zigbee-border-router-design.md.

  • Address per device: <prefix>::<EUI-64>. The /64 is a ULA derived from the
    Extended PAN ID: fd + 40 bits of SHA-256("zigbee-br" ‖ EPID).
  • Wire format: one UDP port, an 8-byte header, then the raw ZCL/ZDP frame. Header
    fields: flags, seq, endpoint, cluster, profile, status.
  • Replies go back by unicast. Reports and other unsolicited frames go to the
    RFC 3306 group ff35:40:<prefix>::1, sent from the device's own address.
  • Policy presets: read-only (default), commands, full.
flowchart LR
    C["IP client<br/>(any UDP socket)"]
    subgraph Host["Linux host"]
        direction TB
        subgraph A["Spike A: coordinator placement"]
            ZA["ziggurat-server<br/>+ zbr gateway"] --- ZP["zigpy / ZHA"]
        end
        subgraph B["Spike B: router placement"]
            ZB["ziggurat-server (router)<br/>+ zbr gateway"]
        end
    end
    RA(("C6 RCP<br/>coordinator 0x0000"))
    RB(("C6 RCP<br/>router 0x4965"))
    L(("ZBOSS light<br/>0x1f77"))
    C -- "UDP/IPv6 :23106<br/>to fd9e:…:fe0a:e0a0" --> ZA
    C -. "or" .-> ZB
    ZA --- RA
    ZB --- RB
    RA <-- "802.15.4" --> L
    RB <-- "802.15.4" --> L
    ZB -. "network settings<br/>(WebSocket)" .-> ZA
Loading
flowchart LR
    E["Extended PAN ID<br/>bf:21:54:02:88:05:4e:3d"] --> H["SHA-256('zigbee-br' ‖ EPID)"]
    H --> P["fd + first 40 bits, subnet 0<br/>fd9e:4994:3fb::/64"]
    D["Device EUI-64<br/>20:6e:f1:ff:fe:0a:e0:a0"] --> I["modified EUI-64<br/>(U/L bit flipped)"]
    P --> AD["fd9e:4994:3fb::226e:f1ff:fe0a:e0a0"]
    I --> AD
    P --> G["multicast ff35:40:fd9e:4994:3fb::1"]
Loading

Header (8 bytes):

Byte 0 1 2 3–4 5–6 7
Field flags (0x80 ack-req, 0x40 ack, 0x20 nack, 0x08 unsolicited) seq endpoint cluster (LE) profile (LE, 0 = default) status (nack reason)

Spike A: coordinator placement (--zbr-port)

crates/ziggurat-server/src/zbr.rs runs next to the zigpy client. It subscribes to the
notification hub and sends through proto::send_unicast, with no stack changes.

  • On, Off and Read Attributes from a Python client get an APS ack, then the device's reply
    by unicast from the device's address, with the client's ZCL TSN restored.
  • The commands policy nacks Configure Reporting and ZDO.
  • With the full policy, a ZDO Bind and Configure Reporting from IP produce reports on
    the multicast group.

Spike B: router placement (--zbr-router-of <ws url>)

crates/ziggurat-server/src/zbr_router.rs runs Ziggurat on a second radio as a router of
the same network. It is configured from the coordinator's settings (as in the ZLOE satellite
spike), with NodeRole::Router and no stack changes.

  • The same round trips work.
  • Unbind and Bind from IP move the light's reports to the router, and they arrive on the
    multicast group.
  • An unknown EUI-64 triggers a broadcast NWK_addr_req, then a nack unknown-device
    after 3 s.

Request, reply and report

sequenceDiagram
    participant C as IP client
    participant G as zbr gateway
    participant Z as Zigbee light
    participant M as Multicast group
    C->>G: hdr(ack-req, seq) + ZCL (TSN 17)<br/>to device address
    G->>G: policy check, EUI-64 to NWK<br/>(NWK_addr_req if unknown)
    G->>Z: APS unicast, TSN rewritten 17 to 128
    Z-->>G: APS ack
    G-->>C: hdr(ack, seq)
    Z-->>G: ZCL response (TSN 128)
    G-->>C: hdr(seq) + ZCL (TSN 17)<br/>from device address
    Z-->>G: Report Attributes (bound, unsolicited)
    G-->>M: hdr(unsolicited) + ZCL<br/>from device address
Loading

Findings

  • Serving AnyIP-routed device addresses needs IPV6_PKTINFO plus IPV6_FREEBIND, and
    SO_REUSEADDR for local group listeners.
  • Coordinator placement: rewriting the TSN keeps IP clients apart from each other but not
    from zigpy.
  • Router placement avoids the TSN clash. But it only sees reports from devices bound to it.
    Moving the binding takes state updates away from ZHA, and keeping both bindings doubles
    the traffic. This is the main open design question.
  • The router's gateway also forwards ZDP requests addressed to its own node to the
    multicast group. It should drop them.
  • Profile is assumed (ZDO on endpoint 0, HA elsewhere), with no descriptor lookup.

Details, setup and logs: spike/zbr/SPIKE.md and spike/zbr/*.log.

Hardware

ESP32-C6 boards running the stock OpenThread RCP firmware as radios, a ZBOSS on/off light
as the test device, and zigpy-ziggurat 1.2.1. Everything ran in a rootless network namespace.

🤖 Generated with Claude Code

t3hk0d3 and others added 2 commits November 21, 2026 13:27
Raw ZCL over UDP/IPv6 to per-device addresses derived from the Extended
PAN ID, with ack/nack, a send policy and multicast copies of unsolicited
frames. Throwaway; see spike/zbr/SPIKE.md and the design note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ziggurat as a router of the spike network on a second C6, configured from
the coordinator's settings, serving the same gateway; NWK_addr_req
discovery for unknown devices. Results in spike/zbr/SPIKE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@t3hk0d3 t3hk0d3 changed the title SPIKE: Zigbee Border Router (raw ZCL over UDP/IPv6) PoC: Zigbee Border Router (raw ZCL over UDP/IPv6) Nov 21, 2026
@t3hk0d3

t3hk0d3 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Soak (router placement, 1 h)

Every 5 s: toggle the light (ack requested), read On/Off back, wait for the multicast report.
720 of 720 cycles passed: no missing ack, reply or report, no nacks, no wrong values read back.
Both Ziggurat processes stayed flat at ~14 MB; no new warnings in Ziggurat or zigpy.

Leg p50 p95 p99 max
Command ack 34 ms 42 ms 44 ms 76 ms
Command response 51 ms 63 ms 72 ms 83 ms
Multicast report 89 ms 141 ms 149 ms 156 ms
Read ack 40 ms 53 ms 64 ms 79 ms
Read response 60 ms 73 ms 83 ms 100 ms

t3hk0d3 and others added 2 commits November 21, 2026 23:53
Mark devices sleepy from their Device_annce capability, pass
sleepy_destination to the stack, retry once after an APS ack timeout.
Probe results against a C6 sleepy end device in spike/zbr/SPIKE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The router answers NWK_addr_req / IEEE_addr_req for itself, so a sleepy
device bound to it can resolve the binding and its reports reach the
multicast group. Adds the sed_steps.py client, a parametrised soak, and
the SED functional and 1 h soak results to SPIKE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@t3hk0d3

t3hk0d3 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Sleepy end device through the border router (router placement)

An ESP32-C6 running as a sleepy end device: receiver off when idle, data poll about every 15 s. Its parent is a mains-powered light, not the gateway. Commits 8c7f7a6 and e4b8e1a; details are in spike/zbr/SPIKE.md.

Probes: a read every 2 s for 60 s (30 requests)

Run Gateway Responses
1 treats it as a normal device 15/30, and 4 nacks were false (the APS ack timeout of 5 s is too short)
2 marks it sleepy from Device_annce rx-off-when-idle, ack timeout 12.7 s 16/30, every nack real
3 run 2 plus one re-send after an APS ack timeout 22/30, latency up to 15 s

Functional

  • ZDO Bind from IP works, but needed a router fix. The bind targets the border router, and the device then broadcasts NWK_addr_req for the router's EUI-64. Nobody answered until the router's ZDP responder answered it. After the fix, every executed toggle produced a multicast report.
  • On, Read, Off and Read all complete when the client retries a nack. The nack comes 25.4 s after sending, when the first send and the gateway's re-send have both expired in the parent.
  • Right after any exchange the device polls fast, so follow-up requests answer in about 0.2 s.

1 h soak: toggle, then read back, every 45 s, no client retries

n p50 p90 max
toggle ack 46/80 5.2 s 13.9 s 15.0 s
report 44/80 5.3 s 14.0 s 15.1 s
read response 79/80 0.3 s 13.9 s 15.0 s
  • 44 of 80 cycles fully OK. 34 toggles were nacked with aps-ack-timeout, and in every one the device kept its old state, so these were real losses. Memory (RSS) held steady at 13–14 MB.
  • Failures come in runs: cycles 1–13, 36–55 and 79. The 45 s interval is close to three poll periods, so the send time drifts slowly through the poll cycle. A toggle is lost when a poll falls between 7.7 s and 12.7 s after the send. In that gap the first send has already expired in the parent's 7.68 s indirect queue, and the gateway's re-send has not been sent yet.

Takeaways

  • The gateway must know which devices sleep, or it nacks requests that do get answered. Device_annce is one source, but the gateway only sees it on join or rejoin. The node descriptor and the controller's database are others.
  • In the router placement the gateway is not the parent, so it cannot see polls and cannot hold a frame until the next one. Re-sending every 7.68 s for one poll period would close the gap; a single re-send at the ack timeout cannot. The other options:
    • make the gateway the parent;
    • have the device cooperate, using Poll Control check-ins and fast poll;
    • send the client a "queued, expected delay" answer, the nack-waiting flag in the design note.
  • Reports from sleepy devices are fine once the border router answers address discovery for itself.

A frame for a sleepy device is re-sent at the parent's persistence
time (7.68 s, 15.36 s) with the same APS counter until one copy is
acked. The 1 h soak goes from 44/80 to 80/80 cycles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@t3hk0d3

t3hk0d3 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Sleepy end device: re-sending every 7.68 s closes the gap

This follows up the previous comment. The gateway now re-sends a frame for a sleepy device at 7.68 s and 15.36 s after the first send, which is the parent's indirect-queue persistence time. It stops as soon as one copy is acked. Every copy reuses the first one's APS counter, so the device drops duplicates instead of running the command twice. Together the three copies cover a poll period of up to about 23 s. Commit 029c88a.

The 1 h soak used the same setup: toggle, then read back, every 45 s, with no client retries.

One re-send at the ack timeout (12.7 s) Re-send every 7.68 s
Cycles fully OK 44/80 80/80
Toggle acks 46/80; p50 5.2 s, p90 13.9 s 80/80; p50 7.8 s, p90 13.8 s, max 15.1 s
Reports 44/80 80/80; p50 7.8 s, max 15.2 s
Reads 79/80; p50 0.3 s 80/80; p50 0.3 s, max 16.9 s
  • There were no nacks, no wrong read-backs and no duplicate execution. About 42 cycles needed the first re-send and about 1 needed the second. Memory (RSS) held steady at 14 MB.
  • The median toggle latency rises from 5.2 s to 7.8 s only because commands that used to be lost now arrive at the next poll.
  • In the router placement the gateway cannot see the device's polls. Even so, timed re-sends give delivery with no losses, at a latency of up to one poll period. That needs two things from the gateway:
    • it knows the device sleeps (here from Device_annce);
    • its re-send window covers the device's poll interval.

@MattWestb

Copy link
Copy Markdown

Great to see that you have one eye on both the classic sed and with modern pull-control. I have only sniffing Ikea controllers that doing end device timeout request then connecting its parent but i dont knowing how long its can being but i have seen some hours being acked from the parent.
I have not looking what controllers is doing if the new parent not supporting end device timeout / pull control but i assume its falling back to classic pulling of its parent.

Great work done !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants