Skip to content

Commit

Permalink
Implement Establish PASE Connection for SetupCode
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Aug 13, 2024
1 parent 128c37a commit fa66547
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fa66547

Please sign in to comment.