Skip to content

Commit

Permalink
[Android] Add Fabric ID parameter (project-chip#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 and andy31415 committed Sep 8, 2022
1 parent ef75ba4 commit 16f0763
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 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 @@ -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)
{
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 @@ -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<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
5 changes: 5 additions & 0 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 @@ -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);
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 @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit 16f0763

Please sign in to comment.