Skip to content

Telink: start the NWK frame counter above what stock firmware reached - #557

Open
patapovich wants to merge 1 commit into
romasku:mainfrom
patapovich:fix/nwk-frame-counter-floor
Open

patapovich wants to merge 1 commit into
romasku:mainfrom
patapovich:fix/nwk-frame-counter-floor

Conversation

@patapovich

Copy link
Copy Markdown

Refs #255

Problem
After the update from the stock Tuya firmware, the device's outgoing NWK frame counter starts again from zero. Routers still running stock Tuya firmware remember the much higher counter the stock firmware had reached for this device. NWK security is checked hop by hop, so these routers acknowledge our frames at the MAC level and then drop them as replays instead of forwarding them. This matches the sniffer observation reported in #255.

Seen on an AVATTO ZDMS16-2 (router) with about ten stock Tuya routers around it:

  • Replies stop reaching the coordinator for 1–15 minutes at a time. The device does not reboot and still executes the commands it receives.
  • Almost all replies that do arrive were sent directly to the coordinator, which reset its counter when the device rejoined.
  • Power-cycling a neighbouring stock router gives a few good minutes, because that router forgets the old counter.

Fix
Right after zb_init() restores the counter from flash, raise it to 0x10000000 if it is lower, and save it. This happens once per device, and the counter only grows from there. 0x10000000 is far above what a stock firmware reaches in years (a few million frames per year from link status and routed traffic), and it still leaves about 3.7·10⁹ frames of headroom.

Testing
Same device in the same place, updated custom→custom without re-pairing. During the first ~10 minutes, while routes settled, there were two short gaps. In the following 22 minutes (pings every 30 s) no command failed, one timeout was recovered by a retry, and replies now also arrive relayed through stock routers. Before the change there were outages of several minutes every few minutes.
The change is Telink-only (Silabs has no Tuya migration path) and cannot run in the stub test HAL.

A device updated from the stock Tuya firmware restarts its outgoing NWK
frame counter from zero. Neighbouring routers still on stock Tuya
firmware keep the old, much higher counter, acknowledge our frames at
the MAC level and drop them as replays instead of forwarding them, so
the device keeps losing the coordinator for minutes at a time
(romasku#255).

Raise the counter once to 0x10000000 right after zb_init() restores it
from flash.
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.

1 participant