@@ -111,6 +111,17 @@ async def load_network_info(self, *, load_devices=False):
111
111
if not is_on_network :
112
112
raise NetworkNotFormed ("Device is not a part of a network" )
113
113
114
+ ieee = await self .nvram .osal_read (OsalNvIds .EXTADDR , item_type = t .EUI64 )
115
+ logical_type = await self .nvram .osal_read (
116
+ OsalNvIds .LOGICAL_TYPE , item_type = t .DeviceLogicalType
117
+ )
118
+
119
+ node_info = zigpy .state .NodeInfo (
120
+ ieee = ieee ,
121
+ nwk = nib .nwkDevAddress ,
122
+ logical_type = zdo_t .LogicalType (logical_type ),
123
+ )
124
+
114
125
key_desc = await self .nvram .osal_read (
115
126
OsalNvIds .NWK_ACTIVE_KEY_INFO , item_type = t .NwkKeyDesc
116
127
)
@@ -130,17 +141,28 @@ async def load_network_info(self, *, load_devices=False):
130
141
key = key_desc .Key ,
131
142
seq = key_desc .KeySeqNum ,
132
143
tx_counter = tc_frame_counter ,
133
- rx_counter = None ,
144
+ rx_counter = 0 ,
145
+ partner_ieee = node_info .ieee ,
146
+ ),
147
+ tc_link_key = zigpy .state .Key (
148
+ key = None ,
149
+ seq = 0 ,
150
+ tx_counter = 0 ,
151
+ rx_counter = 0 ,
134
152
partner_ieee = None ,
135
153
),
136
- tc_link_key = None ,
137
154
children = [],
138
155
nwk_addresses = {},
139
156
key_table = [],
140
157
stack_specific = None ,
141
158
)
142
159
143
- if self .version > 1.2 :
160
+ if self .version == 1.2 :
161
+ tc_link_key = await self .nvram .osal_read (
162
+ OsalNvIds .TCLK_SEED , item_type = t .TCLinkKey
163
+ )
164
+ network_info .tc_link_key .key = tc_link_key .key
165
+ else :
144
166
tclk_seed = await self .nvram .osal_read (
145
167
OsalNvIds .TCLK_SEED , item_type = t .KeyData
146
168
)
@@ -167,17 +189,6 @@ async def load_network_info(self, *, load_devices=False):
167
189
if dev .key is not None :
168
190
network_info .key_table .append (dev .key )
169
191
170
- ieee = await self .nvram .osal_read (OsalNvIds .EXTADDR , item_type = t .EUI64 )
171
- logical_type = await self .nvram .osal_read (
172
- OsalNvIds .LOGICAL_TYPE , item_type = t .DeviceLogicalType
173
- )
174
-
175
- node_info = zigpy .state .NodeInfo (
176
- ieee = ieee ,
177
- nwk = nib .nwkDevAddress ,
178
- logical_type = zdo_t .LogicalType (logical_type ),
179
- )
180
-
181
192
self .network_info = network_info
182
193
self .node_info = node_info
183
194
@@ -357,20 +368,33 @@ async def write_network_info(
357
368
358
369
tclk_seed = None
359
370
360
- if self .version > 1.2 :
371
+ if self .version == 1.2 :
372
+ # TCLK_SEED is TCLK_TABLE_START in Z-Stack 1
373
+ nvram [OsalNvIds .TCLK_SEED ] = t .TCLinkKey (
374
+ ExtAddr = t .EUI64 .convert ("FF:FF:FF:FF:FF:FF:FF:FF" ), # global
375
+ Key = network_info .tc_link_key .key ,
376
+ TxFrameCounter = 0 ,
377
+ RxFrameCounter = 0 ,
378
+ )
379
+ else :
380
+ if network_info .tc_link_key .key != const .DEFAULT_TC_LINK_KEY :
381
+ LOGGER .warning (
382
+ "TC link key is configured at build time in Z-Stack 3 and cannot be"
383
+ " changed at runtime: %s" ,
384
+ network_info .tc_link_key .key ,
385
+ )
386
+
361
387
if (
362
388
network_info .stack_specific is not None
363
389
and network_info .stack_specific .get ("zstack" , {}).get ("tclk_seed" )
364
390
):
365
- tclk_seed , _ = t .KeyData . deserialize (
391
+ tclk_seed = t .KeyData (
366
392
bytes .fromhex (network_info .stack_specific ["zstack" ]["tclk_seed" ])
367
393
)
368
394
else :
369
395
tclk_seed = t .KeyData (os .urandom (16 ))
370
396
371
397
nvram [OsalNvIds .TCLK_SEED ] = tclk_seed
372
- else :
373
- nvram [OsalNvIds .TCLK_SEED ] = const .DEFAULT_TC_LINK_KEY
374
398
375
399
for key , value in nvram .items ():
376
400
await self .nvram .osal_write (key , value , create = True )
0 commit comments