From fa665479523393f4fcadecb2aabcdaee8073bcfa Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo <jh.heo@lge.com> Date: Wed, 14 Aug 2024 08:42:29 +0900 Subject: [PATCH 1/3] Implement Establish PASE Connection for SetupCode --- .../java/CHIPDeviceController-JNI.cpp | 24 +++++++++++++++++++ .../ChipDeviceController.java | 16 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 93ab5ccd0a1012..e94e3ad2e81e71 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -852,6 +852,30 @@ 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<chip::NodeId>(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..2a280165fe1c8a 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -470,6 +470,19 @@ 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 +1637,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, From 428daa5623f01c6a95d89a2088daaff3302a2238 Mon Sep 17 00:00:00 2001 From: "Restyled.io" <commits@restyled.io> Date: Tue, 13 Aug 2024 23:47:05 +0000 Subject: [PATCH 2/3] Restyled by google-java-format --- .../src/chip/devicecontroller/ChipDeviceController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 2a280165fe1c8a..4a59b178f85ef6 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -478,9 +478,11 @@ public void establishPaseConnection(long deviceId, String address, int port, lon * @param useOnlyOnNetworkDiscovery the flag to indicate the commissionable device is available on * the network */ - public void establishPaseConnection(long deviceId, String setupCode, boolean useOnlyOnNetworkDiscovery) { + public void establishPaseConnection( + long deviceId, String setupCode, boolean useOnlyOnNetworkDiscovery) { Log.d(TAG, "Establishing PASE connection using Code: " + setupCode); - establishPaseConnectionByCode(deviceControllerPtr, deviceId, setupCode, useOnlyOnNetworkDiscovery); + establishPaseConnectionByCode( + deviceControllerPtr, deviceId, setupCode, useOnlyOnNetworkDiscovery); } /** @@ -1638,7 +1640,7 @@ 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); + long deviceControllerPtr, long deviceId, String setupCode, boolean useOnlyOnNetworkDiscovery); private native void commissionDevice( long deviceControllerPtr, From f7534f2974ce9eae3f0eb52d9105faea9cd51b4c Mon Sep 17 00:00:00 2001 From: "Restyled.io" <commits@restyled.io> Date: Tue, 13 Aug 2024 23:47:05 +0000 Subject: [PATCH 3/3] Restyled by clang-format --- src/controller/java/CHIPDeviceController-JNI.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index e94e3ad2e81e71..a0482b41db65b8 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -867,7 +867,8 @@ JNI_METHOD(void, establishPaseConnectionByCode) JniUtfString setUpCodeJniString(env, setUpCode); - err = wrapper->Controller()->EstablishPASEConnection(static_cast<chip::NodeId>(deviceId), setUpCodeJniString.c_str(), discoveryType); + err = wrapper->Controller()->EstablishPASEConnection(static_cast<chip::NodeId>(deviceId), setUpCodeJniString.c_str(), + discoveryType); if (err != CHIP_NO_ERROR) {