Skip to content

Commit

Permalink
[Android] Add Fabric ID parameter (#22094)
Browse files Browse the repository at this point in the history
* Add fabricId parameter in andorid controller

* restyle locally
  • Loading branch information
joonhaengHeo authored Aug 25, 2022
1 parent cf4cf8a commit 3fb09d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void AndroidDeviceControllerWrapper::CallJavaMethod(const char * methodName, jin
}

AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, const chip::CATValues & cats, chip::System::Layer * systemLayer,
chip::Inet::EndPointManager<Inet::TCPEndPoint> * tcpEndPointManager,
JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId, const chip::CATValues & cats,
chip::System::Layer * systemLayer, chip::Inet::EndPointManager<Inet::TCPEndPoint> * tcpEndPointManager,
chip::Inet::EndPointManager<Inet::UDPEndPoint> * udpEndPointManager, AndroidOperationalCredentialsIssuerPtr opCredsIssuerPtr,
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate,
jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId, uint16_t failsafeTimerSeconds,
Expand Down Expand Up @@ -237,9 +237,8 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
setupParams.operationalKeypair = &ephemeralKey;
setupParams.hasExternallyOwnedOperationalKeypair = false;

*errInfoOnFailure = opCredsIssuer->GenerateNOCChainAfterValidation(nodeId,
/* fabricId = */ 1, cats, ephemeralKey.Pubkey(),
rcacSpan, icacSpan, nocSpan);
*errInfoOnFailure = opCredsIssuer->GenerateNOCChainAfterValidation(nodeId, fabricId, cats, ephemeralKey.Pubkey(), rcacSpan,
icacSpan, nocSpan);

if (*errInfoOnFailure != CHIP_NO_ERROR)
{
Expand Down
5 changes: 3 additions & 2 deletions src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
* @param[out] errInfoOnFailure a pointer to a CHIP_ERROR that will be populated if this method returns nullptr
*/
static AndroidDeviceControllerWrapper *
AllocateNew(JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, const chip::CATValues & cats,
chip::System::Layer * systemLayer, chip::Inet::EndPointManager<chip::Inet::TCPEndPoint> * tcpEndPointManager,
AllocateNew(JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId,
const chip::CATValues & cats, chip::System::Layer * systemLayer,
chip::Inet::EndPointManager<chip::Inet::TCPEndPoint> * tcpEndPointManager,
chip::Inet::EndPointManager<chip::Inet::UDPEndPoint> * udpEndPointManager,
AndroidOperationalCredentialsIssuerPtr opCredsIssuer, jobject keypairDelegate, jbyteArray rootCertificate,
jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey,
Expand Down
13 changes: 9 additions & 4 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
ChipLogProgress(Controller, "newDeviceController() called");

// Retrieve initialization params.
jmethodID getFabricId;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getFabricId", "()J", &getFabricId);
SuccessOrExit(err);

jmethodID getUdpListenPort;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getUdpListenPort", "()I", &getUdpListenPort);
SuccessOrExit(err);
Expand Down Expand Up @@ -309,6 +313,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
SuccessOrExit(err);

{
uint64_t fabricId = env->CallLongMethod(controllerParams, getFabricId);
uint16_t listenPort = env->CallIntMethod(controllerParams, getUdpListenPort);
uint16_t controllerVendorId = env->CallIntMethod(controllerParams, getControllerVendorId);
jobject keypairDelegate = env->CallObjectMethod(controllerParams, getKeypairDelegate);
Expand All @@ -324,10 +329,10 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
std::unique_ptr<chip::Controller::AndroidOperationalCredentialsIssuer> opCredsIssuer(
new chip::Controller::AndroidOperationalCredentialsIssuer());
wrapper = AndroidDeviceControllerWrapper::AllocateNew(
sJVM, self, kLocalDeviceId, chip::kUndefinedCATs, &DeviceLayer::SystemLayer(), DeviceLayer::TCPEndPointManager(),
DeviceLayer::UDPEndPointManager(), std::move(opCredsIssuer), keypairDelegate, rootCertificate, intermediateCertificate,
operationalCertificate, ipk, listenPort, controllerVendorId, failsafeTimerSeconds, attemptNetworkScanWiFi,
attemptNetworkScanThread, &err);
sJVM, self, kLocalDeviceId, fabricId, chip::kUndefinedCATs, &DeviceLayer::SystemLayer(),
DeviceLayer::TCPEndPointManager(), DeviceLayer::UDPEndPointManager(), std::move(opCredsIssuer), keypairDelegate,
rootCertificate, intermediateCertificate, operationalCertificate, ipk, listenPort, controllerVendorId,
failsafeTimerSeconds, attemptNetworkScanWiFi, attemptNetworkScanThread, &err);
SuccessOrExit(err);

if (adminSubject != kUndefinedNodeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/** Parameters representing initialization arguments for {@link ChipDeviceController}. */
public final class ControllerParams {

private final long fabricId;
private final int udpListenPort;
private final int controllerVendorId;
private final int failsafeTimerSeconds;
Expand All @@ -21,6 +22,7 @@ public final class ControllerParams {

/** @param udpListenPort the UDP listening port, or 0 to pick any available port. */
private ControllerParams(Builder builder) {
this.fabricId = builder.fabricId;
this.udpListenPort = builder.udpListenPort;
this.controllerVendorId = builder.controllerVendorId;
this.failsafeTimerSeconds = builder.failsafeTimerSeconds;
Expand All @@ -34,6 +36,10 @@ private ControllerParams(Builder builder) {
this.adminSubject = builder.adminSubject;
}

public long getFabricId() {
return fabricId;
}

/** Gets the UDP listening port; 0 indicates "any available port" */
public int getUdpListenPort() {
return udpListenPort;
Expand Down Expand Up @@ -100,6 +106,7 @@ public static Builder newBuilder(OperationalKeyConfig operationalKeyConfig) {

/** Builder for {@link ControllerParams}. */
public static class Builder {
private long fabricId = 1;
private int udpListenPort = LEGACY_GLOBAL_CHIP_PORT + 1;
private int controllerVendorId = 0xFFFF;
private int failsafeTimerSeconds = 30;
Expand All @@ -114,6 +121,14 @@ public static class Builder {

private Builder() {}

public Builder setFabricId(long fabricId) {
if (fabricId < 1) {
throw new IllegalArgumentException("fabricId must be > 0");
}
this.fabricId = fabricId;
return this;
}

public Builder setUdpListenPort(int udpListenPort) {
if (udpListenPort < 0) {
throw new IllegalArgumentException("udpListenPort must be >= 0");
Expand Down

0 comments on commit 3fb09d0

Please sign in to comment.