Skip to content

Commit cf24eb5

Browse files
committed
Support commissioning with manual pairing code on network only
1 parent dbb960a commit cf24eb5

1 file changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
From e34fbf7b58908fa777335cbc4da4a0d6b26fe6d7 Mon Sep 17 00:00:00 2001
2+
Message-ID: <e34fbf7b58908fa777335cbc4da4a0d6b26fe6d7.1703059244.git.stefan@agner.ch>
3+
From: Stefan Agner <stefan@agner.ch>
4+
Date: Thu, 14 Dec 2023 13:33:05 +0100
5+
Subject: [PATCH] [Python] Support commissioning with code on network only
6+
(#31000)
7+
8+
* [Python] Support commissioning with code on network only
9+
10+
Add an additional parameter to support commissioning on network only.
11+
This is useful when a manual pairing code is given and we know the
12+
device is on the network already.
13+
14+
* Use consistent casing for newly added parameter
15+
---
16+
.../python/ChipDeviceController-ScriptBinding.cpp | 10 +++++++---
17+
src/controller/python/chip/ChipDeviceCtrl.py | 6 +++---
18+
2 files changed, 10 insertions(+), 6 deletions(-)
19+
20+
diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
21+
index a7732a4836..c4b12570fd 100644
22+
--- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp
23+
+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
24+
@@ -50,6 +50,7 @@
25+
#include <controller/CommissioningWindowOpener.h>
26+
#include <controller/CurrentFabricRemover.h>
27+
#include <controller/ExampleOperationalCredentialsIssuer.h>
28+
+#include <controller/SetUpCodePairer.h>
29+
30+
#include <controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h>
31+
#include <controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h>
32+
@@ -135,7 +136,7 @@ PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissio
33+
PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissioner * devCtrl, const char * peerAddrStr,
34+
uint32_t setupPINCode, chip::NodeId nodeid);
35+
PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
36+
- chip::NodeId nodeid);
37+
+ chip::NodeId nodeid, bool networkOnly);
38+
PyChipError pychip_DeviceController_UnpairDevice(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId remoteDeviceId,
39+
DeviceUnpairingCompleteFunct callback);
40+
PyChipError pychip_DeviceController_SetThreadOperationalDataset(const char * threadOperationalDataset, uint32_t size);
41+
@@ -397,10 +398,13 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission
42+
}
43+
44+
PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
45+
- chip::NodeId nodeid)
46+
+ chip::NodeId nodeid, bool networkOnly)
47+
{
48+
+ chip::Controller::DiscoveryType discoveryType = chip::Controller::DiscoveryType::kAll;
49+
sPairingDelegate.SetExpectingPairingComplete(true);
50+
- return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters));
51+
+ if (networkOnly)
52+
+ discoveryType = chip::Controller::DiscoveryType::kDiscoveryNetworkOnly;
53+
+ return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters, discoveryType));
54+
}
55+
56+
namespace {
57+
diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
58+
index 22ae11cda6..de6f1fff03 100644
59+
--- a/src/controller/python/chip/ChipDeviceCtrl.py
60+
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
61+
@@ -1422,7 +1422,7 @@ class ChipDeviceControllerBase():
62+
self._dmLib.pychip_DeviceController_ConnectIP.restype = PyChipError
63+
64+
self._dmLib.pychip_DeviceController_ConnectWithCode.argtypes = [
65+
- c_void_p, c_char_p, c_uint64]
66+
+ c_void_p, c_char_p, c_uint64, c_bool]
67+
self._dmLib.pychip_DeviceController_ConnectWithCode.restype = PyChipError
68+
69+
self._dmLib.pychip_DeviceController_UnpairDevice.argtypes = [
70+
@@ -1726,7 +1726,7 @@ class ChipDeviceController(ChipDeviceControllerBase):
71+
return PyChipError(CHIP_ERROR_TIMEOUT)
72+
return self._ChipStack.commissioningEventRes
73+
74+
- def CommissionWithCode(self, setupPayload: str, nodeid: int) -> PyChipError:
75+
+ def CommissionWithCode(self, setupPayload: str, nodeid: int, networkOnly: bool = False) -> PyChipError:
76+
self.CheckIsActive()
77+
78+
setupPayload = setupPayload.encode() + b'\0'
79+
@@ -1739,7 +1739,7 @@ class ChipDeviceController(ChipDeviceControllerBase):
80+
81+
self._ChipStack.CallAsync(
82+
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
83+
- self.devCtrl, setupPayload, nodeid)
84+
+ self.devCtrl, setupPayload, nodeid, networkOnly)
85+
)
86+
if not self._ChipStack.commissioningCompleteEvent.isSet():
87+
# Error 50 is a timeout
88+
--
89+
2.43.0
90+

0 commit comments

Comments
 (0)