Skip to content

Commit

Permalink
Restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
tehampson committed Jul 7, 2022
1 parent da8fddf commit e66a1f5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/controller/python/chip/utils/CommissioningUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

_UINT16_MAX = 65535


async def _IsBasicAttributeReadSuccessful(devCtrl, nodeId):
resp = await devCtrl.ReadAttribute(nodeId, [(Clusters.Basic.Attributes.ClusterRevision)])
clusterRevision = resp[0][Clusters.Basic][Clusters.Basic.Attributes.ClusterRevision]
Expand All @@ -33,15 +34,15 @@ async def AddNOC(commissionedDevCtrl, newDevCtrl, existingNodeId, newNodeId):
resp = await commissionedDevCtrl.SendCommand(existingNodeId, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(60), timedRequestTimeoutMs=1000)
if resp.errorCode is not Clusters.GeneralCommissioning.Enums.CommissioningError.kOk:
return False

csrForAddNOC = await commissionedDevCtrl.SendCommand(existingNodeId, 0, Clusters.OperationalCredentials.Commands.CSRRequest(CSRNonce=b'1' * 32))

chainForAddNOC = newDevCtrl.IssueNOCChain(csrForAddNOC, newNodeId)
if chainForAddNOC.rcacBytes is None or chainForAddNOC.icacBytes is None or chainForAddNOC.nocBytes is None or chainForAddNOC.ipkBytes is None:
# Expiring the failsafe timer in an attempt to clean up.
await commissionedDevCtrl.SendCommand(existingNodeId, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0), timedRequestTimeoutMs=1000)
return False

# TODO error check on the commands below
await commissionedDevCtrl.SendCommand(existingNodeId, 0, Clusters.OperationalCredentials.Commands.AddTrustedRootCertificate(chainForAddNOC.rcacBytes))
resp = await commissionedDevCtrl.SendCommand(existingNodeId, 0, Clusters.OperationalCredentials.Commands.AddNOC(chainForAddNOC.nocBytes, chainForAddNOC.icacBytes, chainForAddNOC.ipkBytes, newDevCtrl.GetNodeId(), 0xFFF1))
Expand All @@ -55,12 +56,13 @@ async def AddNOC(commissionedDevCtrl, newDevCtrl, existingNodeId, newNodeId):
# Expiring the failsafe timer in an attempt to clean up.
await commissionedDevCtrl.SendCommand(existingNodeId, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0), timedRequestTimeoutMs=1000)
return False

if not await _IsBasicAttributeReadSuccessful(newDevCtrl, newNodeId):
return False

return True


async def UpdateNOC(devCtrl, existingNodeId, newNodeId):
resp = await devCtrl.SendCommand(existingNodeId, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(600), timedRequestTimeoutMs=1000)
if resp.errorCode is not Clusters.GeneralCommissioning.Enums.CommissioningError.kOk:
Expand Down

0 comments on commit e66a1f5

Please sign in to comment.