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

Consolidate all EZSP types #634

Merged
merged 34 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f18227e
Reformat commands onto new lines
puddly Jul 20, 2024
9c9bf1a
Use v4 structs for v5, they're identical
puddly Jul 20, 2024
0c19e68
Move `sl_zb_sec_man_key_type_t` and `sl_zb_sec_man_flags_t` to types
puddly Jul 20, 2024
03243db
Replace per-version `EzspConfigId` with a global enum
puddly Jul 20, 2024
3beaee7
Same with `EzspValueId`
puddly Jul 20, 2024
fd94a4e
Move Rf4ce types as well
puddly Jul 20, 2024
ef47b5d
`EmberKeyType` as well
puddly Jul 20, 2024
4377eb5
`EzspPolicyId`
puddly Jul 21, 2024
0c0c086
`EzspDecisionBitmask`
puddly Jul 21, 2024
864edd8
`EzspDecisionId`
puddly Jul 21, 2024
ce21c8e
`EmberDeviceUpdate`
puddly Jul 21, 2024
48f8540
`EmberCounterType`
puddly Jul 21, 2024
220a99a
`EmberNetworkInitBitmask`
puddly Jul 21, 2024
1a57906
`SecureEzspSecurityType`
puddly Jul 21, 2024
eff4fe5
`SecureEzspSecurityLevel`
puddly Jul 21, 2024
513e2c1
`SecureEzspRandomNumber` -> `uint128_t`
puddly Jul 21, 2024
c1a11d2
`EmberMultiPhyNwkConfig`
puddly Jul 21, 2024
7993abd
Rename `EmberNetworkInitStruct` to `EmberNetworkInitBitmask`
puddly Jul 21, 2024
379614f
`EmberDutyCycleState`
puddly Jul 21, 2024
f9cd00a
`EmberRadioPowerMode`
puddly Jul 21, 2024
af9def6
`EmberDutyCycleHectoPct`
puddly Jul 21, 2024
6fbf798
`EmberGpProxyTableEntryStatus`
puddly Jul 21, 2024
7576f03
`EmberGpSecurityFrameCounter`
puddly Jul 21, 2024
4f56316
`EmberGpSinkTableEntryStatus`
puddly Jul 21, 2024
57b2bbf
`EmberJoinMethod`
puddly Jul 21, 2024
fbaa9be
`EmberEntropySource`
puddly Jul 21, 2024
d4276df
Migrate most structs
puddly Jul 21, 2024
2bfae63
Split `EmberChildData` into `EmberChildDataV8` and `EmberChildDataV10`
puddly Jul 21, 2024
e94f3b4
Give all of the `sl_zb_sec_man_*` types proper names
puddly Jul 21, 2024
af3725c
Split up security manager context into V12 and V13 types
puddly Jul 21, 2024
6009497
Delete all EZSP version-specific types
puddly Jul 21, 2024
97ab671
Delete all references to types
puddly Jul 21, 2024
f0baee0
Unit test fixup: pass 1
puddly Jul 21, 2024
9f71062
Remove references to instance-level `ezsp.types`
puddly Jul 21, 2024
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
18 changes: 8 additions & 10 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ async def get_board_info(

tokens[token] = result

(status, ver_info_bytes) = await self.getValue(
self.types.EzspValueId.VALUE_VERSION_INFO
)
(status, ver_info_bytes) = await self.getValue(t.EzspValueId.VALUE_VERSION_INFO)
version = None

if t.sl_Status.from_ember_status(status) == t.sl_Status.OK:
Expand Down Expand Up @@ -500,7 +498,7 @@ async def set_source_routing(self) -> None:
"""Enable source routing on NCP."""
res = await self.setConcentrator(
True,
self.types.EmberConcentratorType.HIGH_RAM_CONCENTRATOR,
t.EmberConcentratorType.HIGH_RAM_CONCENTRATOR,
MTOR_MIN_INTERVAL,
MTOR_MAX_INTERVAL,
MTOR_ROUTE_ERROR_THRESHOLD,
Expand Down Expand Up @@ -548,11 +546,11 @@ async def write_config(self, config: dict) -> None:
for cfg in DEFAULT_CONFIG[self._ezsp_version]:
if isinstance(cfg, RuntimeConfig):
ezsp_config[cfg.config_id.name] = dataclasses.replace(
cfg, config_id=self.types.EzspConfigId[cfg.config_id.name]
cfg, config_id=t.EzspConfigId[cfg.config_id.name]
)
elif isinstance(cfg, ValueConfig):
ezsp_values[cfg.value_id.name] = dataclasses.replace(
cfg, value_id=self.types.EzspValueId[cfg.value_id.name]
cfg, value_id=t.EzspValueId[cfg.value_id.name]
)

# Override the defaults with user-specified values (or `None` for deletions)
Expand All @@ -562,16 +560,16 @@ async def write_config(self, config: dict) -> None:
continue

ezsp_config[name] = RuntimeConfig(
config_id=self.types.EzspConfigId[name],
config_id=t.EzspConfigId[name],
value=value,
)

# Make sure CONFIG_PACKET_BUFFER_COUNT is always set last
if self.types.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT.name in ezsp_config:
if t.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT.name in ezsp_config:
ezsp_config = {
**ezsp_config,
self.types.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT.name: ezsp_config[
self.types.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT.name
t.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT.name: ezsp_config[
t.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT.name
],
}

Expand Down
43 changes: 19 additions & 24 deletions bellows/ezsp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import dataclasses
import typing

import bellows.ezsp.v4.types as types_v4
import bellows.ezsp.v6.types as types_v6
import bellows.ezsp.v7.types as types_v7
import bellows.types as t


Expand All @@ -24,97 +21,95 @@ class ValueConfig:

DEFAULT_CONFIG_COMMON = [
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_INDIRECT_TRANSMISSION_TIMEOUT,
config_id=t.EzspConfigId.CONFIG_INDIRECT_TRANSMISSION_TIMEOUT,
value=7680,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_STACK_PROFILE,
config_id=t.EzspConfigId.CONFIG_STACK_PROFILE,
value=2,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_SUPPORTED_NETWORKS,
config_id=t.EzspConfigId.CONFIG_SUPPORTED_NETWORKS,
value=1,
minimum=True,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_MULTICAST_TABLE_SIZE,
config_id=t.EzspConfigId.CONFIG_MULTICAST_TABLE_SIZE,
value=16,
minimum=True,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE,
config_id=t.EzspConfigId.CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE,
value=2,
minimum=True,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_SECURITY_LEVEL,
config_id=t.EzspConfigId.CONFIG_SECURITY_LEVEL,
value=5,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_ADDRESS_TABLE_SIZE,
config_id=t.EzspConfigId.CONFIG_ADDRESS_TABLE_SIZE,
value=16,
minimum=True,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_PAN_ID_CONFLICT_REPORT_THRESHOLD,
config_id=t.EzspConfigId.CONFIG_PAN_ID_CONFLICT_REPORT_THRESHOLD,
value=2,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_KEY_TABLE_SIZE,
config_id=t.EzspConfigId.CONFIG_KEY_TABLE_SIZE,
value=4,
minimum=True,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_MAX_END_DEVICE_CHILDREN,
config_id=t.EzspConfigId.CONFIG_MAX_END_DEVICE_CHILDREN,
value=32,
minimum=True,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_APPLICATION_ZDO_FLAGS,
config_id=t.EzspConfigId.CONFIG_APPLICATION_ZDO_FLAGS,
value=(
t.EmberZdoConfigurationFlags.APP_RECEIVES_SUPPORTED_ZDO_REQUESTS
| t.EmberZdoConfigurationFlags.APP_HANDLES_UNSUPPORTED_ZDO_REQUESTS
),
),
# Must be set last
RuntimeConfig(types_v4.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT, value=0xFF),
RuntimeConfig(t.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT, value=0xFF),
]

DEFAULT_CONFIG_LEGACY = [
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE,
config_id=t.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE,
value=16,
minimum=True,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT,
config_id=t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT,
value=60,
),
RuntimeConfig(
config_id=types_v4.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT,
config_id=t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT,
value=8,
),
] + DEFAULT_CONFIG_COMMON


DEFAULT_CONFIG_NEW = [
RuntimeConfig(
config_id=types_v6.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE,
config_id=t.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE,
value=200,
minimum=True,
),
RuntimeConfig(
config_id=types_v6.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT,
config_id=t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT,
value=8,
),
RuntimeConfig(
config_id=(
types_v6.EzspConfigId.CONFIG_TC_REJOINS_USING_WELL_KNOWN_KEY_TIMEOUT_S
),
config_id=(t.EzspConfigId.CONFIG_TC_REJOINS_USING_WELL_KNOWN_KEY_TIMEOUT_S),
value=90,
),
ValueConfig(
value_id=types_v7.EzspValueId.VALUE_FORCE_TX_AFTER_FAILED_CCA_ATTEMPTS,
value_id=t.EzspValueId.VALUE_FORCE_TX_AFTER_FAILED_CCA_ATTEMPTS,
value=t.uint8_t(1),
),
] + DEFAULT_CONFIG_COMMON
Expand Down
8 changes: 4 additions & 4 deletions bellows/ezsp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _ezsp_frame(self, name: str, *args: tuple[Any, ...]) -> bytes:
"""Serialize the named frame and data."""
c = self.COMMANDS[name]
frame = self._ezsp_frame_tx(name)
data = self.types.serialize(args, c[1])
data = t.serialize(args, c[1])
return frame + data

@abc.abstractmethod
Expand Down Expand Up @@ -75,10 +75,10 @@ async def update_policies(self, policy_config: dict) -> None:
"""Set up the policies for what the NCP should do."""

policies = self.SCHEMAS[CONF_EZSP_POLICIES](policy_config)
self.tc_policy = policies[self.types.EzspPolicyId.TRUST_CENTER_POLICY.name]
self.tc_policy = policies[t.EzspPolicyId.TRUST_CENTER_POLICY.name]

for policy, value in policies.items():
(status,) = await self.setPolicy(self.types.EzspPolicyId[policy], value)
(status,) = await self.setPolicy(t.EzspPolicyId[policy], value)
assert (
t.sl_Status.from_ember_status(status) == t.sl_Status.OK
) # TODO: Better check
Expand All @@ -101,7 +101,7 @@ def __call__(self, data: bytes) -> None:

try:
if isinstance(rx_schema, tuple):
result, data = self.types.deserialize(data, rx_schema)
result, data = t.deserialize(data, rx_schema)
else:
result, data = rx_schema.deserialize(data)
except Exception:
Expand Down
5 changes: 2 additions & 3 deletions bellows/ezsp/v10/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import bellows.config
import bellows.types as t

from . import commands, config, types as v10_types
from . import commands, config
from ..v9 import EZSPv9

LOGGER = logging.getLogger(__name__)
Expand All @@ -23,13 +23,12 @@ class EZSPv10(EZSPv9):
bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA),
bellows.config.CONF_EZSP_POLICIES: voluptuous.Schema(config.EZSP_POLICIES_SCH),
}
types = v10_types

async def write_child_data(self, children: dict[t.EUI64, t.NWK]) -> None:
for index, (eui64, nwk) in enumerate(children.items()):
await self.setChildData(
index,
self.types.EmberChildData(
t.EmberChildDataV10(
eui64=eui64,
type=t.EmberNodeType.SLEEPY_END_DEVICE,
id=nwk,
Expand Down
7 changes: 4 additions & 3 deletions bellows/ezsp/v10/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import types as t
import bellows.types as t

from ..v9.commands import COMMANDS as COMMANDS_v9

COMMANDS = {
Expand All @@ -7,11 +8,11 @@
"getChildData": (
0x004A,
(t.uint8_t,),
(t.EmberStatus, t.EmberChildData),
(t.EmberStatus, t.EmberChildDataV10),
),
"setChildData": (
0x00AC,
(t.uint8_t, t.EmberChildData),
(t.uint8_t, t.EmberChildDataV10),
(t.EmberStatus,),
),
}
2 changes: 1 addition & 1 deletion bellows/ezsp/v10/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import voluptuous as vol

from bellows.config import cv_uint16
from bellows.types import EzspPolicyId

from ..v4.config import EZSP_POLICIES_SHARED
from ..v9 import config as v9_config
from .types import EzspPolicyId

EZSP_SCHEMA = {
**v9_config.EZSP_SCHEMA,
Expand Down
5 changes: 0 additions & 5 deletions bellows/ezsp/v10/types/__init__.py

This file was deleted.

Loading
Loading