diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 21533458c66567..0397c80d05ced8 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -829,6 +829,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); @@ -848,7 +849,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) @@ -967,7 +992,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; } @@ -978,7 +1003,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; }