-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IssueNOCChain and GetNodeId for chip-repl to use (#19890)
Add IssueNOCChain and GetNodeId for chip-repl to use This is added to allow for manual testing AddNOC and UpdateNOC using chip-repl.
- Loading branch information
Showing
10 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/controller/python/ChipDeviceController-IssueNocChain.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
#include <controller/CHIPDeviceController.h> | ||
#include <lib/core/CHIPError.h> | ||
#include <lib/support/Span.h> | ||
|
||
typedef void PyObject; | ||
|
||
using namespace chip; | ||
|
||
extern "C" { | ||
|
||
typedef void (*pychip_DeviceController_IssueNOCChainCallbackPythonCallback)( | ||
PyObject * context, ChipError::StorageType status, const uint8_t * noc, size_t nocLen, const uint8_t * icac, size_t icacLen, | ||
const uint8_t * rcac, size_t rcacLen, const uint8_t * ipk, size_t ipkLen, NodeId adminSubject); | ||
|
||
static pychip_DeviceController_IssueNOCChainCallbackPythonCallback pychip_DeviceController_IssueNOCChainCallbackPythonCallbackFunct; | ||
|
||
void pychip_DeviceController_SetIssueNOCChainCallbackPythonCallback( | ||
pychip_DeviceController_IssueNOCChainCallbackPythonCallback callback) | ||
{ | ||
pychip_DeviceController_IssueNOCChainCallbackPythonCallbackFunct = callback; | ||
} | ||
|
||
ChipError::StorageType pychip_DeviceController_IssueNOCChain(chip::Controller::DeviceCommissioner * devCtrl, | ||
PyObject * pythonContext, uint8_t * NOCSRElements, | ||
size_t NOCSRElementsLen, NodeId nodeId); | ||
} | ||
|
||
void pychip_DeviceController_IssueNOCChainCallback(void * context, CHIP_ERROR status, const ByteSpan & noc, const ByteSpan & icac, | ||
const ByteSpan & rcac, Optional<Crypto::AesCcm128KeySpan> ipk, | ||
Optional<NodeId> adminSubject) | ||
{ | ||
if (pychip_DeviceController_IssueNOCChainCallbackPythonCallbackFunct != nullptr) | ||
{ | ||
Crypto::AesCcm128KeySpan ipkData; | ||
ipkData = ipk.ValueOr(Crypto::AesCcm128KeySpan()); | ||
pychip_DeviceController_IssueNOCChainCallbackPythonCallbackFunct( | ||
context, status.AsInteger(), noc.data(), noc.size(), icac.data(), icac.size(), rcac.data(), rcac.size(), ipkData.data(), | ||
ipk.HasValue() ? ipkData.size() : 0, adminSubject.ValueOr(kUndefinedNodeId)); | ||
} | ||
} | ||
|
||
ChipError::StorageType pychip_DeviceController_IssueNOCChain(chip::Controller::DeviceCommissioner * devCtrl, | ||
PyObject * pythonContext, uint8_t * NOCSRElements, | ||
size_t NOCSRElementsLen, NodeId nodeId) | ||
{ | ||
return devCtrl | ||
->IssueNOCChain( | ||
ByteSpan(NOCSRElements, NOCSRElementsLen), nodeId, | ||
/* Note: Memory leak here. This is a quick and a bit dirty PoC */ | ||
new Callback::Callback<Controller::OnNOCChainGeneration>(pychip_DeviceController_IssueNOCChainCallback, pythonContext)) | ||
.AsInteger(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.