Skip to content

Commit 53150fd

Browse files
committed
Update to match new zigpy state key structure
1 parent 1b1de86 commit 53150fd

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
@@ -143,19 +143,14 @@ async def load_network_info(self, *, load_devices=False):
143143
channel=nib.nwkLogicalChannel,
144144
channel_mask=nib.channelList,
145145
security_level=nib.SecurityLevel,
146-
network_key=zigpy.state.Key(
147-
key=key_desc.Key,
148-
seq=key_desc.KeySeqNum,
149-
tx_counter=tc_frame_counter,
150-
rx_counter=0,
151-
partner_ieee=node_info.ieee,
152-
),
153-
tc_link_key=zigpy.state.Key(
154-
key=const.DEFAULT_TC_LINK_KEY,
155-
seq=0,
156-
tx_counter=0,
157-
rx_counter=0,
158-
partner_ieee=t.EUI64.convert("FF:FF:FF:FF:FF:FF:FF:FF"),
146+
network_key=key_desc.Key,
147+
network_key_seq=key_desc.KeySeqNum,
148+
network_key_counter=tc_frame_counter,
149+
tc_link_key=const.DEFAULT_TC_LINK_KEY,
150+
tc_address=(
151+
node_info.ieee
152+
if node_info.logical_type == zdo_t.LogicalType.Coordinator
153+
else None
159154
),
160155
children=[],
161156
nwk_addresses={},
@@ -183,8 +178,9 @@ async def load_network_info(self, *, load_devices=False):
183178
)
184179

185180
if dev.is_child:
186-
network_info.children.append(dev.node_info)
187-
elif dev.node_info.nwk is not None:
181+
network_info.children.append(dev.node_info.ieee)
182+
183+
if dev.node_info.nwk is not None:
188184
network_info.nwk_addresses[dev.node_info.ieee] = dev.node_info.nwk
189185

190186
if dev.key is not None:
@@ -349,10 +345,10 @@ async def write_network_info(
349345

350346
key_info = t.NwkActiveKeyItems(
351347
Active=t.NwkKeyDesc(
352-
KeySeqNum=network_info.network_key.seq,
353-
Key=network_info.network_key.key,
348+
KeySeqNum=network_info.network_key_seq,
349+
Key=network_info.network_key,
354350
),
355-
FrameCounter=network_info.network_key.tx_counter,
351+
FrameCounter=network_info.network_key_counter,
356352
)
357353

358354
nvram = {
@@ -373,19 +369,19 @@ async def write_network_info(
373369
# TCLK_SEED is TCLK_TABLE_START in Z-Stack 1
374370
nvram[OsalNvIds.TCLK_SEED] = t.TCLinkKey(
375371
ExtAddr=t.EUI64.convert("FF:FF:FF:FF:FF:FF:FF:FF"), # global
376-
Key=network_info.tc_link_key.key or const.DEFAULT_TC_LINK_KEY,
372+
Key=network_info.tc_link_key or const.DEFAULT_TC_LINK_KEY,
377373
TxFrameCounter=0,
378374
RxFrameCounter=0,
379375
)
380376
else:
381377
if (
382378
network_info.tc_link_key is not None
383-
and network_info.tc_link_key.key != const.DEFAULT_TC_LINK_KEY
379+
and network_info.tc_link_key != const.DEFAULT_TC_LINK_KEY
384380
):
385381
LOGGER.warning(
386382
"TC link key is configured at build time in Z-Stack 3 and cannot be"
387383
" changed at runtime: %s",
388-
network_info.tc_link_key.key,
384+
network_info.tc_link_key,
389385
)
390386

391387
if (
@@ -405,7 +401,7 @@ async def write_network_info(
405401

406402
await security.write_tc_frame_counter(
407403
self,
408-
network_info.network_key.tx_counter,
404+
network_info.network_key_counter,
409405
ext_pan_id=network_info.extended_pan_id,
410406
)
411407

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)