Skip to content

Commit

Permalink
Expose EstablishPaseConnection to Android (project-chip#13341)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinh0 authored Jan 7, 2022
1 parent fb154cf commit b81facc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ JNI_METHOD(void, pairDeviceWithAddress)
}
}

JNI_METHOD(void, establishPaseConnection)(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jint connObj, jlong pinCode)
{
chip::DeviceLayer::StackLock lock;
CHIP_ERROR err = CHIP_NO_ERROR;
AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle);

RendezvousParameters rendezvousParams = RendezvousParameters()
.SetSetupPINCode(pinCode)
#if CONFIG_NETWORK_LAYER_BLE
.SetConnectionObject(reinterpret_cast<BLE_CONNECTION_OBJECT>(connObj))
#endif
.SetPeerAddress(Transport::PeerAddress::BLE());

err = wrapper->Controller()->EstablishPASEConnection(deviceId, rendezvousParams);

if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Failed to establish PASE connection.");
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
}
}

JNI_METHOD(void, unpairDevice)(JNIEnv * env, jobject self, jlong handle, jlong deviceId)
{
chip::DeviceLayer::StackLock lock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public void pairDeviceWithAddress(
deviceControllerPtr, deviceId, address, port, discriminator, pinCode, csrNonce);
}

public void establishPaseConnection(long deviceId, int connId, long setupPincode) {
if (connectionId == 0) {
connectionId = connId;

if (connectionId == 0) {
Log.e(TAG, "Failed to add Bluetooth connection.");
completionListener.onError(new Exception("Failed to add Bluetooth connection."));
return;
}

Log.d(TAG, "Bluetooth connection added with ID: " + connectionId);
Log.d(TAG, "Establishing PASE connection with ID: " + deviceId);
establishPaseConnection(deviceControllerPtr, deviceId, connId, setupPincode);
} else {
Log.e(TAG, "Bluetooth connection already in use.");
completionListener.onError(new Exception("Bluetooth connection already in use."));
}
}

public void unpairDevice(long deviceId) {
unpairDevice(deviceControllerPtr, deviceId);
}
Expand Down Expand Up @@ -263,6 +282,9 @@ private native void pairDeviceWithAddress(
long pinCode,
@Nullable byte[] csrNonce);

private native void establishPaseConnection(
long deviceControllerPtr, long deviceId, int connId, long setupPincode);

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

private native long getDeviceBeingCommissionedPointer(long deviceControllerPtr, long nodeId);
Expand Down

0 comments on commit b81facc

Please sign in to comment.