diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index c1efe8fa9ac603..933e446ddd3bb9 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -850,6 +850,7 @@ CHIP_ERROR DeviceCommissioner::PairTestDeviceWithoutSecurity(NodeId remoteDevice SecurePairingUsingTestSecret * testSecurePairingSecret = nullptr; + // Check that the caller has provided an IP address (instead of a BLE peer address) VerifyOrExit(peerAddress.GetTransportType() == Transport::Type::kUdp, err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(remoteDeviceId != kUndefinedNodeId && remoteDeviceId != kAnyNodeId, err = CHIP_ERROR_INVALID_ARGUMENT); @@ -869,7 +870,31 @@ CHIP_ERROR DeviceCommissioner::PairTestDeviceWithoutSecurity(NodeId remoteDevice device->Serialize(serialized); - OnSessionEstablished(); + err = mSessionMgr->NewPairing(Optional::Value(peerAddress), device->GetDeviceId(), + testSecurePairingSecret, SecureSession::SessionRole::kInitiator, mAdminId, nullptr); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "Failed in setting up secure channel: err %s", ErrorStr(err)); + OnSessionEstablishmentError(err); + } + SuccessOrExit(err); + + mPairedDevices.Insert(device->GetDeviceId()); + mPairedDevicesUpdated = true; + + // Note - This assumes storage is synchronous, the device must be in storage before we can cleanup + // the rendezvous session and mark pairing success + PersistDevice(device); + // Also persist the device list at this time + // This makes sure that a newly added device is immediately available + PersistDeviceList(); + + if (mPairingDelegate != nullptr) + { + mPairingDelegate->OnStatusUpdate(DevicePairingDelegate::SecurePairingSuccess); + } + + RendezvousCleanup(CHIP_NO_ERROR); exit: if (testSecurePairingSecret != nullptr) @@ -988,7 +1013,7 @@ void DeviceCommissioner::OnSessionEstablished() SecureSession::SessionRole::kInitiator, mAdminId, nullptr); if (err != CHIP_NO_ERROR) { - ChipLogError(Ble, "Failed in setting up secure channel: err %s", ErrorStr(err)); + ChipLogError(Controller, "Failed in setting up secure channel: err %s", ErrorStr(err)); OnSessionEstablishmentError(err); return; } @@ -999,7 +1024,7 @@ void DeviceCommissioner::OnSessionEstablished() err = SendOperationalCertificateSigningRequestCommand(device->GetDeviceId()); if (err != CHIP_NO_ERROR) { - ChipLogError(Ble, "Failed in sending opcsr request command to the device: err %s", ErrorStr(err)); + ChipLogError(Controller, "Failed in sending opcsr request command to the device: err %s", ErrorStr(err)); OnSessionEstablishmentError(err); return; }