@@ -357,16 +357,19 @@ async def write_network_info(
357
357
358
358
tclk_seed = None
359
359
360
- if (
361
- self .version > 1.2
362
- and network_info .stack_specific is not None
363
- and "tclk_seed" in network_info .stack_specific .get ("zstack" , {})
364
- ):
365
- tclk_seed , _ = t .KeyData .deserialize (
366
- bytes .fromhex (network_info .stack_specific ["zstack" ]["tclk_seed" ])
367
- )
360
+ if self .version > 1.2 :
361
+ if (
362
+ network_info .stack_specific is not None
363
+ and network_info .stack_specific .get ("zstack" , {}).get ("tclk_seed" )
364
+ ):
365
+ tclk_seed , _ = t .KeyData .deserialize (
366
+ bytes .fromhex (network_info .stack_specific ["zstack" ]["tclk_seed" ])
367
+ )
368
+ else :
369
+ tclk_seed = t .KeyData (os .urandom (16 ))
370
+
368
371
nvram [OsalNvIds .TCLK_SEED ] = tclk_seed
369
- elif self . version == 1.2 :
372
+ else :
370
373
nvram [OsalNvIds .TCLK_SEED ] = const .DEFAULT_TC_LINK_KEY
371
374
372
375
for key , value in nvram .items ():
@@ -407,17 +410,21 @@ async def write_network_info(
407
410
408
411
LOGGER .debug ("Writing children and keys" )
409
412
410
- optimal_tclk_seed = security .find_optimal_tclk_seed (devices .values (), tclk_seed )
411
-
412
- if tclk_seed != optimal_tclk_seed :
413
- LOGGER .warning (
414
- "Provided TCLK seed %s is not optimal, using %s instead." ,
415
- tclk_seed ,
416
- optimal_tclk_seed ,
413
+ # Recompute the TCLK if necessary
414
+ if self .version > 1.2 :
415
+ optimal_tclk_seed = security .find_optimal_tclk_seed (
416
+ devices .values (), tclk_seed
417
417
)
418
418
419
- await self .nvram .osal_write (OsalNvIds .TCLK_SEED , optimal_tclk_seed )
420
- tclk_seed = optimal_tclk_seed
419
+ if tclk_seed != optimal_tclk_seed :
420
+ LOGGER .warning (
421
+ "Provided TCLK seed %s is not optimal, using %s instead." ,
422
+ tclk_seed ,
423
+ optimal_tclk_seed ,
424
+ )
425
+
426
+ await self .nvram .osal_write (OsalNvIds .TCLK_SEED , optimal_tclk_seed )
427
+ tclk_seed = optimal_tclk_seed
421
428
422
429
await security .write_devices (
423
430
znp = self ,
0 commit comments