Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XNCP parsing for hacked LIDL gateway #657

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading