Skip to content

Commit

Permalink
Allow null NetworkCredentials in commissionDevice() (#13655)
Browse files Browse the repository at this point in the history
For IP commissioning, no credentials should be added, but currently the
Java layer requires either a Thread or Wi-Fi network. The underlying
commissioner logic already has safeguards to ensure that a network is
provided unless we are doing IP commissioning.
  • Loading branch information
g-coppock authored Jan 18, 2022
1 parent b306824 commit 78a6636
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@ JNI_METHOD(void, commissionDevice)
ChipLogProgress(Controller, "commissionDevice() called");

CommissioningParameters commissioningParams = CommissioningParameters();
err = wrapper->ApplyNetworkCredentials(commissioningParams, networkCredentials);
VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_INVALID_ARGUMENT);
if (networkCredentials != nullptr)
{
err = wrapper->ApplyNetworkCredentials(commissioningParams, networkCredentials);
VerifyOrExit(err == CHIP_NO_ERROR, err = CHIP_ERROR_INVALID_ARGUMENT);
}

if (csrNonce != nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void establishPaseConnection(long deviceId, String address, int port, lon
* @param deviceId the ID of the node to be commissioned
* @param networkCredentials the credentials (Wi-Fi or Thread) to be provisioned
*/
public void commissionDevice(long deviceId, NetworkCredentials networkCredentials) {
public void commissionDevice(long deviceId, @Nullable NetworkCredentials networkCredentials) {
commissionDevice(deviceControllerPtr, deviceId, /* csrNonce= */ null, networkCredentials);
}

Expand All @@ -155,7 +155,7 @@ public void commissionDevice(long deviceId, NetworkCredentials networkCredential
* @param networkCredentials the credentials (Wi-Fi or Thread) to be provisioned
*/
public void commissionDevice(
long deviceId, @Nullable byte[] csrNonce, NetworkCredentials networkCredentials) {
long deviceId, @Nullable byte[] csrNonce, @Nullable NetworkCredentials networkCredentials) {
commissionDevice(deviceControllerPtr, deviceId, csrNonce, networkCredentials);
}

Expand Down Expand Up @@ -331,7 +331,7 @@ private native void commissionDevice(
long deviceControllerPtr,
long deviceId,
@Nullable byte[] csrNonce,
NetworkCredentials networkCredentials);
@Nullable NetworkCredentials networkCredentials);

private native void unpairDevice(long deviceControllerPtr, long deviceId);

Expand Down

0 comments on commit 78a6636

Please sign in to comment.