From 9f4d6806a37be712304a192ead4b6b8e86cd1464 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 8 Sep 2022 11:15:29 -0400 Subject: [PATCH] [Android] Add Fabric ID parameter (#22094) (#22483) * Add fabricId parameter in andorid controller * restyle locally Co-authored-by: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> --- .../java/AndroidDeviceControllerWrapper.cpp | 9 ++++----- .../java/AndroidDeviceControllerWrapper.h | 5 +++-- src/controller/java/CHIPDeviceController-JNI.cpp | 5 +++++ .../chip/devicecontroller/ControllerParams.java | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 5b9cc02e96e8c1..b08283c9e22e38 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -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 * tcpEndPointManager, + JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId, const chip::CATValues & cats, + chip::System::Layer * systemLayer, chip::Inet::EndPointManager * tcpEndPointManager, chip::Inet::EndPointManager * udpEndPointManager, AndroidOperationalCredentialsIssuerPtr opCredsIssuerPtr, jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId, uint16_t failsafeTimerSeconds, @@ -238,9 +238,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) { diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index df9e6b9106c178..8c0697b024170a 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -142,8 +142,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 * tcpEndPointManager, + AllocateNew(JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId, + const chip::CATValues & cats, chip::System::Layer * systemLayer, + chip::Inet::EndPointManager * tcpEndPointManager, chip::Inet::EndPointManager * udpEndPointManager, AndroidOperationalCredentialsIssuerPtr opCredsIssuer, jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 95742b7f9cac29..5f2b6fb0b19caf 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -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); @@ -314,6 +318,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); diff --git a/src/controller/java/src/chip/devicecontroller/ControllerParams.java b/src/controller/java/src/chip/devicecontroller/ControllerParams.java index a4fb5b7ea3063d..14088b8d1d715b 100644 --- a/src/controller/java/src/chip/devicecontroller/ControllerParams.java +++ b/src/controller/java/src/chip/devicecontroller/ControllerParams.java @@ -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; @@ -22,6 +23,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; @@ -36,6 +38,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; @@ -105,6 +111,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; @@ -120,6 +127,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");