Skip to content

Commit 19088d2

Browse files
committed
Update to match new zigpy state key structure
1 parent d2bd4b4 commit 19088d2

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

zigpy_znp/api.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,14 @@ async def load_network_info(self, *, load_devices=False):
139139
channel=nib.nwkLogicalChannel,
140140
channel_mask=nib.channelList,
141141
security_level=nib.SecurityLevel,
142-
network_key=zigpy.state.Key(
143-
key=key_desc.Key,
144-
seq=key_desc.KeySeqNum,
145-
tx_counter=tc_frame_counter,
146-
rx_counter=0,
147-
partner_ieee=node_info.ieee,
148-
),
149-
tc_link_key=zigpy.state.Key(
150-
key=const.DEFAULT_TC_LINK_KEY,
151-
seq=0,
152-
tx_counter=0,
153-
rx_counter=0,
154-
partner_ieee=t.EUI64.convert("FF:FF:FF:FF:FF:FF:FF:FF"),
142+
network_key=key_desc.Key,
143+
network_key_seq=key_desc.KeySeqNum,
144+
network_key_counter=tc_frame_counter,
145+
tc_link_key=const.DEFAULT_TC_LINK_KEY,
146+
tc_address=(
147+
node_info.ieee
148+
if node_info.logical_type == zdo_t.LogicalType.Coordinator
149+
else None
155150
),
156151
children=[],
157152
nwk_addresses={},
@@ -179,8 +174,9 @@ async def load_network_info(self, *, load_devices=False):
179174
)
180175

181176
if dev.is_child:
182-
network_info.children.append(dev.node_info)
183-
elif dev.node_info.nwk is not None:
177+
network_info.children.append(dev.node_info.ieee)
178+
179+
if dev.node_info.nwk is not None:
184180
network_info.nwk_addresses[dev.node_info.ieee] = dev.node_info.nwk
185181

186182
if dev.key is not None:
@@ -345,10 +341,10 @@ async def write_network_info(
345341

346342
key_info = t.NwkActiveKeyItems(
347343
Active=t.NwkKeyDesc(
348-
KeySeqNum=network_info.network_key.seq,
349-
Key=network_info.network_key.key,
344+
KeySeqNum=network_info.network_key_seq,
345+
Key=network_info.network_key,
350346
),
351-
FrameCounter=network_info.network_key.tx_counter,
347+
FrameCounter=network_info.network_key_counter,
352348
)
353349

354350
nvram = {
@@ -369,19 +365,19 @@ async def write_network_info(
369365
# TCLK_SEED is TCLK_TABLE_START in Z-Stack 1
370366
nvram[OsalNvIds.TCLK_SEED] = t.TCLinkKey(
371367
ExtAddr=t.EUI64.convert("FF:FF:FF:FF:FF:FF:FF:FF"), # global
372-
Key=network_info.tc_link_key.key or const.DEFAULT_TC_LINK_KEY,
368+
Key=network_info.tc_link_key or const.DEFAULT_TC_LINK_KEY,
373369
TxFrameCounter=0,
374370
RxFrameCounter=0,
375371
)
376372
else:
377373
if (
378374
network_info.tc_link_key is not None
379-
and network_info.tc_link_key.key != const.DEFAULT_TC_LINK_KEY
375+
and network_info.tc_link_key != const.DEFAULT_TC_LINK_KEY
380376
):
381377
LOGGER.warning(
382378
"TC link key is configured at build time in Z-Stack 3 and cannot be"
383379
" changed at runtime: %s",
384-
network_info.tc_link_key.key,
380+
network_info.tc_link_key,
385381
)
386382

387383
if (
@@ -401,7 +397,7 @@ async def write_network_info(
401397

402398
await security.write_tc_frame_counter(
403399
self,
404-
network_info.network_key.tx_counter,
400+
network_info.network_key_counter,
405401
ext_pan_id=network_info.extended_pan_id,
406402
)
407403

zigpy_znp/tools/network_restore.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ def json_backup_to_zigpy_state(
3939
network_info.channel_mask = t.Channels.from_channel_list(backup["channel_mask"])
4040
network_info.security_level = backup["security_level"]
4141
network_info.stack_specific = backup.get("stack_specific")
42-
network_info.tc_link_key.key = const.DEFAULT_TC_LINK_KEY
42+
network_info.tc_link_key = const.DEFAULT_TC_LINK_KEY
4343

44-
network_info.network_key = zigpy.state.Key()
45-
network_info.network_key.key, _ = t.KeyData.deserialize(
44+
network_info.network_key, _ = t.KeyData.deserialize(
4645
bytes.fromhex(backup["network_key"]["key"])
4746
)
48-
network_info.network_key.tx_counter = backup["network_key"]["frame_counter"]
49-
network_info.network_key.rx_counter = 0
50-
network_info.network_key.partner_ieee = None
51-
network_info.network_key.seq = backup["network_key"]["sequence_number"]
47+
network_info.network_key_counter = backup["network_key"]["frame_counter"]
48+
network_info.network_key_seq = backup["network_key"]["sequence_number"]
5249

5350
network_info.children = []
5451
network_info.nwk_addresses = {}
@@ -92,7 +89,7 @@ async def restore_network(
9289
counter_increment: int,
9390
) -> None:
9491
network_info, node_info = json_backup_to_zigpy_state(backup)
95-
network_info.network_key.tx_counter += counter_increment
92+
network_info.network_key_counter += counter_increment
9693

9794
znp = ZNP(ControllerApplication.SCHEMA({"device": {"path": radio_path}}))
9895
await znp.connect()

0 commit comments

Comments
 (0)