diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 93ab5ccd0a1012..a0482b41db65b8 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -852,6 +852,31 @@ JNI_METHOD(void, establishPaseConnectionByAddress) } } +JNI_METHOD(void, establishPaseConnectionByCode) +(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jstring setUpCode, jboolean useOnlyOnNetworkDiscovery) +{ + chip::DeviceLayer::StackLock lock; + CHIP_ERROR err = CHIP_NO_ERROR; + AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); + + auto discoveryType = DiscoveryType::kAll; + if (useOnlyOnNetworkDiscovery) + { + discoveryType = DiscoveryType::kDiscoveryNetworkOnly; + } + + JniUtfString setUpCodeJniString(env, setUpCode); + + err = wrapper->Controller()->EstablishPASEConnection(static_cast(deviceId), setUpCodeJniString.c_str(), + discoveryType); + + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "Failed to establish PASE connection."); + JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err); + } +} + JNI_METHOD(void, continueCommissioning) (JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jboolean ignoreAttestationFailure) { diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 37e9e7093a1afc..4a59b178f85ef6 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -470,6 +470,21 @@ public void establishPaseConnection(long deviceId, String address, int port, lon establishPaseConnectionByAddress(deviceControllerPtr, deviceId, address, port, setupPincode); } + /** + * Establish a secure PASE connection using the scanned QR code or manual entry code. + * + * @param deviceId the ID of the node to connect to + * @param setupCode the scanned QR code or manual entry code + * @param useOnlyOnNetworkDiscovery the flag to indicate the commissionable device is available on + * the network + */ + public void establishPaseConnection( + long deviceId, String setupCode, boolean useOnlyOnNetworkDiscovery) { + Log.d(TAG, "Establishing PASE connection using Code: " + setupCode); + establishPaseConnectionByCode( + deviceControllerPtr, deviceId, setupCode, useOnlyOnNetworkDiscovery); + } + /** * Initiates the automatic commissioning flow using the specified network credentials. It is * expected that a secure session has already been established via {@link @@ -1624,6 +1639,9 @@ private native void establishPaseConnection( private native void establishPaseConnectionByAddress( long deviceControllerPtr, long deviceId, String address, int port, long setupPincode); + private native void establishPaseConnectionByCode( + long deviceControllerPtr, long deviceId, String setupCode, boolean useOnlyOnNetworkDiscovery); + private native void commissionDevice( long deviceControllerPtr, long deviceId,