Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Add Fabric ID parameter #22094

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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,
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,
Expand Down Expand Up @@ -238,7 +238,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
setupParams.hasExternallyOwnedOperationalKeypair = false;

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

if (*errInfoOnFailure != CHIP_NO_ERROR)
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ 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,
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,
Expand Down
7 changes: 6 additions & 1 deletion 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,7 +329,7 @@ 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(),
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);
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