Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support commissioning with manual pairing code on network only #25

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions 0004-Python-Support-commissioning-with-code-on-network-on.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
From e34fbf7b58908fa777335cbc4da4a0d6b26fe6d7 Mon Sep 17 00:00:00 2001
Message-ID: <e34fbf7b58908fa777335cbc4da4a0d6b26fe6d7.1703059244.git.stefan@agner.ch>
From: Stefan Agner <[email protected]>
Date: Thu, 14 Dec 2023 13:33:05 +0100
Subject: [PATCH] [Python] Support commissioning with code on network only
(#31000)

* [Python] Support commissioning with code on network only

Add an additional parameter to support commissioning on network only.
This is useful when a manual pairing code is given and we know the
device is on the network already.

* Use consistent casing for newly added parameter
---
.../python/ChipDeviceController-ScriptBinding.cpp | 10 +++++++---
src/controller/python/chip/ChipDeviceCtrl.py | 6 +++---
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
index a7732a4836..c4b12570fd 100644
--- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp
+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
@@ -50,6 +50,7 @@
#include <controller/CommissioningWindowOpener.h>
#include <controller/CurrentFabricRemover.h>
#include <controller/ExampleOperationalCredentialsIssuer.h>
+#include <controller/SetUpCodePairer.h>

#include <controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h>
#include <controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h>
@@ -135,7 +136,7 @@ PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissio
PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissioner * devCtrl, const char * peerAddrStr,
uint32_t setupPINCode, chip::NodeId nodeid);
PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
- chip::NodeId nodeid);
+ chip::NodeId nodeid, bool networkOnly);
PyChipError pychip_DeviceController_UnpairDevice(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId remoteDeviceId,
DeviceUnpairingCompleteFunct callback);
PyChipError pychip_DeviceController_SetThreadOperationalDataset(const char * threadOperationalDataset, uint32_t size);
@@ -397,10 +398,13 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission
}

PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
- chip::NodeId nodeid)
+ chip::NodeId nodeid, bool networkOnly)
{
+ chip::Controller::DiscoveryType discoveryType = chip::Controller::DiscoveryType::kAll;
sPairingDelegate.SetExpectingPairingComplete(true);
- return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters));
+ if (networkOnly)
+ discoveryType = chip::Controller::DiscoveryType::kDiscoveryNetworkOnly;
+ return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters, discoveryType));
}

namespace {
diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
index 22ae11cda6..de6f1fff03 100644
--- a/src/controller/python/chip/ChipDeviceCtrl.py
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
@@ -1422,7 +1422,7 @@ class ChipDeviceControllerBase():
self._dmLib.pychip_DeviceController_ConnectIP.restype = PyChipError

self._dmLib.pychip_DeviceController_ConnectWithCode.argtypes = [
- c_void_p, c_char_p, c_uint64]
+ c_void_p, c_char_p, c_uint64, c_bool]
self._dmLib.pychip_DeviceController_ConnectWithCode.restype = PyChipError

self._dmLib.pychip_DeviceController_UnpairDevice.argtypes = [
@@ -1726,7 +1726,7 @@ class ChipDeviceController(ChipDeviceControllerBase):
return PyChipError(CHIP_ERROR_TIMEOUT)
return self._ChipStack.commissioningEventRes

- def CommissionWithCode(self, setupPayload: str, nodeid: int) -> PyChipError:
+ def CommissionWithCode(self, setupPayload: str, nodeid: int, networkOnly: bool = False) -> PyChipError:
self.CheckIsActive()

setupPayload = setupPayload.encode() + b'\0'
@@ -1739,7 +1739,7 @@ class ChipDeviceController(ChipDeviceControllerBase):

self._ChipStack.CallAsync(
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
- self.devCtrl, setupPayload, nodeid)
+ self.devCtrl, setupPayload, nodeid, networkOnly)
)
if not self._ChipStack.commissioningCompleteEvent.isSet():
# Error 50 is a timeout
--
2.43.0

Loading