Skip to content

Commit 9745323

Browse files
committed
Establish PASE session from code
1 parent 2a38fad commit 9745323

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

src/controller/python/ChipDeviceController-ScriptBinding.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ PyChipError pychip_DeviceController_EstablishPASESessionIP(chip::Controller::Dev
153153
uint32_t setupPINCode, chip::NodeId nodeid, uint16_t port);
154154
PyChipError pychip_DeviceController_EstablishPASESessionBLE(chip::Controller::DeviceCommissioner * devCtrl, uint32_t setupPINCode,
155155
uint16_t discriminator, chip::NodeId nodeid);
156+
PyChipError pychip_DeviceController_EstablishPASESession(chip::Controller::DeviceCommissioner * devCtrl, const char* setUpCode,
157+
chip::NodeId nodeid);
156158
PyChipError pychip_DeviceController_Commission(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId nodeid);
157159

158160
PyChipError pychip_DeviceController_DiscoverCommissionableNodesLongDiscriminator(chip::Controller::DeviceCommissioner * devCtrl,
@@ -620,6 +622,12 @@ PyChipError pychip_DeviceController_EstablishPASESessionBLE(chip::Controller::De
620622
return ToPyChipError(devCtrl->EstablishPASEConnection(nodeid, params));
621623
}
622624

625+
PyChipError pychip_DeviceController_EstablishPASESession(chip::Controller::DeviceCommissioner * devCtrl, const char* setUpCode,
626+
chip::NodeId nodeid) {
627+
sPairingDelegate.SetExpectingPairingComplete(true);
628+
return ToPyChipError(devCtrl->EstablishPASEConnection(nodeid, setUpCode));
629+
}
630+
623631
PyChipError pychip_DeviceController_Commission(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId nodeid)
624632
{
625633
CommissioningParameters params;

src/controller/python/chip/ChipDeviceCtrl.py

+12
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,15 @@ def EstablishPASESessionIP(self, ipaddr: str, setupPinCode: int, nodeid: int, po
500500
self.devCtrl, ipaddr.encode("utf-8"), setupPinCode, nodeid, port)
501501
)
502502

503+
def EstablishPASESession(self, setUpCode: str, nodeid: int):
504+
self.CheckIsActive()
505+
506+
self.state = DCState.RENDEZVOUS_ONGOING
507+
return self._ChipStack.CallAsync(
508+
lambda: self._dmLib.pychip_DeviceController_EstablishPASESession(
509+
self.devCtrl, setUpCode.encode("utf-8"), nodeid)
510+
)
511+
503512
def GetTestCommissionerUsed(self):
504513
return self._ChipStack.Call(
505514
lambda: self._dmLib.pychip_TestCommissionerUsed()
@@ -1605,6 +1614,9 @@ def _InitLib(self):
16051614
self._dmLib.pychip_DeviceController_EstablishPASESessionBLE.argtypes = [
16061615
c_void_p, c_uint32, c_uint16, c_uint64]
16071616
self._dmLib.pychip_DeviceController_EstablishPASESessionBLE.restype = PyChipError
1617+
self._dmLib.pychip_DeviceController_EstablishPASESession.argtypes = [
1618+
c_void_p, c_char_p, c_uint64]
1619+
self._dmLib.pychip_DeviceController_EstablishPASESession.restype = PyChipError
16081620

16091621
self._dmLib.pychip_DeviceController_DiscoverAllCommissionableNodes.argtypes = [
16101622
c_void_p]

src/python_testing/basic_composition_support.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,9 @@ async def setup_class_helper(self, default_to_pase: bool = True):
105105
dump_device_composition_path: Optional[str] = self.user_params.get("dump_device_composition_path", None)
106106

107107
if do_test_over_pase:
108-
info = self.get_setup_payload_info()
109-
110-
commissionable_nodes = dev_ctrl.DiscoverCommissionableNodes(
111-
info.filter_type, info.filter_value, stopOnFirst=True, timeoutSecond=15)
112-
logging.info(f"Commissionable nodes: {commissionable_nodes}")
113-
# TODO: Support BLE
114-
if commissionable_nodes is not None and len(commissionable_nodes) > 0:
115-
commissionable_node = commissionable_nodes[0]
116-
instance_name = f"{commissionable_node.instanceName}._matterc._udp.local"
117-
vid = f"{commissionable_node.vendorId}"
118-
pid = f"{commissionable_node.productId}"
119-
address = f"{commissionable_node.addresses[0]}"
120-
logging.info(f"Found instance {instance_name}, VID={vid}, PID={pid}, Address={address}")
121-
122-
node_id = self.dut_node_id
123-
dev_ctrl.EstablishPASESessionIP(address, info.passcode, node_id)
124-
else:
125-
asserts.fail("Failed to find the DUT according to command line arguments.")
108+
setupCode = self.matter_test_config.qr_code_content if self.matter_test_config.qr_code_content is not None else self.matter_test_config.manual_code
109+
asserts.assert_true(setupCode, "Require either --qr-code or --manual-code.")
110+
dev_ctrl.EstablishPASESession(setupCode, self.dut_node_id)
126111
else:
127112
# Using the already commissioned node
128113
node_id = self.dut_node_id

0 commit comments

Comments
 (0)