Skip to content

Commit

Permalink
Fix XNCP parsing for hacked LIDL gateway (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Dec 5, 2024
1 parent 5dd3447 commit a81bbd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bellows/ezsp/xncp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def from_payload(cls, payload: XncpCommandPayload) -> XncpCommand:
def from_bytes(cls, data: bytes) -> XncpCommand:
command_id, data = XncpCommandId.deserialize(data)
status, data = EmberStatus.deserialize(data)

if command_id not in COMMANDS:
raise ValueError(
f"Unknown XNCP command ID: 0x{command_id:04X} (payload {data!r})"
)

payload, rest = COMMANDS[command_id].deserialize(data)

if rest:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_xncp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ async def test_xncp_failure_multiprotocol(ezsp_f: EZSP) -> None:
]


async def test_xncp_failure_lidl(ezsp_f: EZSP) -> None:
"""Test XNCP failure with hacked LIDL gateway."""
ezsp_f._mock_commands["customFrame"] = customFrame = AsyncMock(
return_value=[t.EmberStatus.SUCCESS, b"\x00\x01\x03"]
)

with pytest.raises(InvalidCommandError):
await ezsp_f.xncp_get_supported_firmware_features()

assert customFrame.mock_calls == [
call(xncp.XncpCommand.from_payload(xncp.GetSupportedFeaturesReq()).serialize())
]


async def test_xncp_failure_unknown(ezsp_f: EZSP) -> None:
"""Test XNCP failure, unknown command."""
ezsp_f._mock_commands["customFrame"] = customFrame = AsyncMock(
Expand Down

0 comments on commit a81bbd4

Please sign in to comment.