Skip to content

Ignore Z-Stack's default ZDO error response - #292

Open
indrajitr wants to merge 2 commits into
zigpy:devfrom
indrajitr:zdo-default-error-rsp
Open

indrajitr wants to merge 2 commits into
zigpy:devfrom
indrajitr:zdo-default-error-rsp

Conversation

@indrajitr

Copy link
Copy Markdown

Z-Stack reports a failed Simple_Desc_rsp (any non-SUCCESS status, e.g. NOT_ACTIVE or INVALID_EP) as a "default" error response, which shares its AREQ ID with ZDO.StateChangeInd. zigpy-znp parses it as StateChangeInd, fails on the trailing bytes, and uart.py logs an ERROR traceback every time a device with such an endpoint is interviewed. The full response also arrives as ZDO.MsgCbIncoming, so nothing is lost. This ignores the frame at DEBUG level, next to the existing ParentAnnceRsp tolerance.

Why 0xC0

From TI's Z-Stack MT layer (simplelink-lowpower-f2-sdk@3615ad5):

  • mt_zdo.c L2269-L2290: MT_ZdoHandleExceptions() rewrites a Simple_Desc_rsp with DataLength <= 5 (no descriptor) to clusterId = MtZdoDef_rsp, DataLength = 2.
  • mt.h L397-L398: MtZdoDef_rsp is 0x0040 ("Some arbitrarily chosen value for a default error status msg").
  • mt_zdo.c L2200-L2232: MT_ZdoDirectCB() sends it as AREQ 0x0040 | 0x80 = 0xC0 (MT_ZDO_CID_TO_AREQ_ID, L113) with SrcAddr (2) + Status (1).
  • mt.h L381: 0xC0 is also MT_ZDO_STATE_CHANGE_IND (one byte, the device state).

Log

SALUS ST100ZB (lists endpoints [9, 242], rejects 242 with INVALID_EP; see zigpy/zigpy#1966), Sonoff ZBDongle-P, Z-Stack 20240710, zigpy-znp 1.1.1. Both frames arrive in one read:

DEBUG [serialx.descriptor_transport] Received b'\xfe\x03E\xc0\xd6\xde\x82\x0c\xfe\rE\xff\xd6\xde\x00\x04\x80\x00\x04\x00\x00\x82\xd6\xde\x00\xb5'
ERROR [zigpy_znp.uart] Received an exception while passing frame to API: TransportFrame(payload=GeneralFrame(header=CommandHeader(id=0xC0, subsystem=Subsystem.ZDO, type=CommandType.AREQ), data=b'\xD6\xDE\x82'))
ValueError: Frame GeneralFrame(header=CommandHeader(id=0xC0, subsystem=Subsystem.ZDO, type=CommandType.AREQ), data=b'\xD6\xDE\x82') contains trailing data after parsing: b'\xde\x82'
DEBUG [zigpy_znp.api] Received command: ZDO.MsgCbIncoming.Callback(Src=0xDED6, IsBroadcast=<Bool.false: 0>, ClusterId=32772, SecurityUse=0, TSN=4, MacDst=0x0000, Data=b'\x82\xD6\xDE\x00')

The first frame is the default error response (NWK 0xDED6, status 0x82). The second is the full Simple_Desc_rsp via MsgCbIncoming, which zigpy handles.

Test

test_handling_zdo_default_error_rsp feeds the frame above and asserts nothing is logged at WARNING or above. It fails on dev with the same ValueError.

Z-Stack reports a failed Simple_Desc_rsp (any non-SUCCESS status, e.g.
NOT_ACTIVE or INVALID_EP) as a "default" error response, MtZdoDef_rsp
(0x0040), sent as AREQ 0xC0 with NWK + Status. 0xC0 is also
ZDO.StateChangeInd, so parsing fails with "trailing data" and the frame
is logged as an error, although the full response is also received as a
ZDO.MsgCbIncoming callback. Ignore it.
Copilot AI balanced review requested due to automatic review settings November 15, 2026 02:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change to suppress noisy ZDO error-response tracebacks.

No open issues 🎉

What changed in this PR

Prevents noisy error tracebacks during device interviews by tolerating Z-Stack’s default ZDO error response. The full response remains available through ZDO.MsgCbIncoming.

Changes:

  • Ignore three-byte responses that share the StateChangeInd identifier, logging them at DEBUG level.
  • Add a regression test for an INVALID_EP response, verifying it produces no WARNING-or-higher logs.
File Description
zigpy_znp/​api.py Recognizes and ignores the default ZDO error response after parsing fails.
tests/​api/​test_request.py Tests that the response is ignored without warning or error logs.

Review effort: Balanced

@TheJulianJES TheJulianJES added the bot-watch: review zigpy-review-bot follows this thread: reviews new pushes, answers, resolves addressed threads label Nov 15, 2026
@indrajitr

Copy link
Copy Markdown
Author

The failed tests seem unrelated. The new test_handling_zdo_default_error_rsp passed.

@zigpy-review-bot zigpy-review-bot added the bugfix This PR fixes a bug label Nov 15, 2026

@zigpy-review-bot zigpy-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The firmware claim checks out, the new branch can't swallow a real StateChangeInd, and the new test fails on dev and passes here.

CI is red, but not because of this PR: locally with zigpy 2.4.1 (which the open zigpy>=1.5.0 pin installs today), the same 137 tests/application/ tests fail on dev too. They hit CommandNotRecognized because the test server has no handler for an AF.DataRequestExt broadcast to endpoint 242, cluster 0x0021 (Green Power). #291 fails CI the same way.

Verified (6 checks)
  • Firmware (TI SDK at the commit the body links): in mt_zdo.c, MT_ZdoHandleExceptions() sets doDefault only in the Simple_Desc_rsp case with DataLength <= 5. That case rewrites clusterId to MtZdoDef_rsp (0x0040) and sets DataLength = 2. MT_ZdoDirectCB() then sends DataLength - 1 + 2 = 3 bytes (SrcAddr LE + Status) as AREQ 0x40 | 0x80 = 0xC0. No other ZDO response takes that path: failed NWK/IEEE address responses are dropped, not defaulted. So b"\xd6\xde\x82" is NWK 0xDED6 with status INVALID_EP, as the test comment says.
  • A real state change can't hit the branch: MT_ZdoStateChangeCB() sends MT_ZDO_STATE_CHANGE_IND with length 1, so a genuine StateChangeInd parses normally. The len(frame.data) == 3 check only runs inside the except ValueError path, after a failed parse.
  • zigpy still sees the failure: zigpy_znp/zigbee/application.py:166 registers ZDO.MsgCallbackRegister(ClusterId=0xFFFF), so the full Simple_Desc_rsp still arrives as ZDO.MsgCbIncoming and goes through on_zdo_message. The only 0xC0 listeners in zigpy-znp are the StartingAsCoordinator / StartedAsCoordinator matches in ZNP.start_network, and a 3-byte frame never matched those either.
  • The test exercises the branch: with dev's zigpy_znp/api.py, test_handling_zdo_default_error_rsp fails with the contains trailing data after parsing ValueError from the PR body. With the PR, tests/api/test_request.py passes (17 passed).
  • Full suite: on the PR head, 137 failed and 260 passed. With dev's api.py swapped in, the list of failing tests is identical (diffed), so none of them come from this change.
  • An independent static second-opinion pass (two models) found no correctness issues.

@TheJulianJES

This comment was marked as resolved.

@zigpy-review-bot

This comment was marked as resolved.

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

Labels

bot-watch: review zigpy-review-bot follows this thread: reviews new pushes, answers, resolves addressed threads bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants