Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Implement Establish PASE Connection for SetupCode #34971

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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,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
Expand Down Expand Up @@ -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,
Expand Down
Loading