-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
* Allow UDP listening port selection for Android * Restyled by google-java-format * Restyled by clang-format Co-authored-by: Restyled.io <commits@restyled.io>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package chip.devicecontroller; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
/** Parameters representing initialization arguments for {@link ChipDeviceController}. */ | ||
public final class ControllerParams { | ||
|
||
private final int udpListenPort; | ||
@Nullable private final KeypairDelegate keypairDelegate; | ||
@Nullable private final byte[] rootCertificate; | ||
@Nullable private final byte[] intermediateCertificate; | ||
@Nullable private final byte[] operationalCertificate; | ||
@Nullable private final byte[] ipk; | ||
|
||
private static final int LEGACY_GLOBAL_CHIP_PORT = 5540; | ||
|
||
/** @param udpListenPort the UDP listening port, or 0 to pick any available port. */ | ||
private ControllerParams(Builder builder) { | ||
this.udpListenPort = builder.udpListenPort; | ||
this.keypairDelegate = builder.keypairDelegate; | ||
this.rootCertificate = builder.rootCertificate; | ||
this.intermediateCertificate = builder.intermediateCertificate; | ||
this.operationalCertificate = builder.operationalCertificate; | ||
this.ipk = builder.ipk; | ||
} | ||
|
||
/** Gets the UDP listening port; 0 indicates "any available port" */ | ||
public int getUdpListenPort() { | ||
return udpListenPort; | ||
} | ||
|
||
public KeypairDelegate getKeypairDelegate() { | ||
return keypairDelegate; | ||
} | ||
|
||
public byte[] getRootCertificate() { | ||
return rootCertificate; | ||
} | ||
|
||
public byte[] getIntermediateCertificate() { | ||
return intermediateCertificate; | ||
} | ||
|
||
public byte[] getOperationalCertificate() { | ||
return operationalCertificate; | ||
} | ||
|
||
public byte[] getIpk() { | ||
return ipk; | ||
} | ||
|
||
/** Returns parameters with ephemerally generated operational credentials */ | ||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* Returns parameters which uses the provided {@code operationalKeyConfig} as its operating | ||
* credentials. | ||
*/ | ||
public static Builder newBuilder(OperationalKeyConfig operationalKeyConfig) { | ||
return newBuilder() | ||
.setKeypairDelegate(operationalKeyConfig.getKeypairDelegate()) | ||
.setRootCertificate(operationalKeyConfig.getTrustedRootCertificate()) | ||
.setIntermediateCertificate(operationalKeyConfig.getIntermediateCertificate()) | ||
.setOperationalCertificate(operationalKeyConfig.getNodeOperationalCertificate()) | ||
.setIpk(operationalKeyConfig.getIpkEpochKey()); | ||
} | ||
|
||
/** Builder for {@link ControllerParams}. */ | ||
public static class Builder { | ||
private int udpListenPort = LEGACY_GLOBAL_CHIP_PORT + 1; | ||
@Nullable private KeypairDelegate keypairDelegate = null; | ||
@Nullable private byte[] rootCertificate = null; | ||
@Nullable private byte[] intermediateCertificate = null; | ||
@Nullable private byte[] operationalCertificate = null; | ||
@Nullable private byte[] ipk = null; | ||
|
||
private Builder() {} | ||
|
||
public Builder setUdpListenPort(int udpListenPort) { | ||
if (udpListenPort < 0) { | ||
throw new IllegalArgumentException("udpListenPort must be >= 0"); | ||
} | ||
this.udpListenPort = udpListenPort; | ||
return this; | ||
} | ||
|
||
public Builder setKeypairDelegate(KeypairDelegate keypairDelegate) { | ||
this.keypairDelegate = keypairDelegate; | ||
return this; | ||
} | ||
|
||
public Builder setRootCertificate(byte[] rootCertificate) { | ||
this.rootCertificate = rootCertificate; | ||
return this; | ||
} | ||
|
||
public Builder setIntermediateCertificate(byte[] intermediateCertificate) { | ||
this.intermediateCertificate = intermediateCertificate; | ||
return this; | ||
} | ||
|
||
public Builder setOperationalCertificate(byte[] operationalCertificate) { | ||
this.operationalCertificate = operationalCertificate; | ||
return this; | ||
} | ||
|
||
public Builder setIpk(byte[] ipk) { | ||
this.ipk = ipk; | ||
return this; | ||
} | ||
|
||
public ControllerParams build() { | ||
return new ControllerParams(this); | ||
} | ||
} | ||
} |
4 comments
on commit fd2e975
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Marcos,
I'm seeing error finding getUdpListenPort during newDeviceController().
Not sure is this only me or others having the same issue.
This happened when I run CHIPTool and click 'Discover' in AddressCommissioningFragment.
Could you help sheding some light how this can be fixed? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JniReferences::FindMethod() can't find a method here:
*methodId = env->GetMethodID(javaClass, methodName, methodSignature);
VerifyOrReturnError(*methodId != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some try and error, I think this can find methods correctly:
> - err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getUdpListenPort", PARAMS_CLASS, &getUdpListenPort);
> + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getUdpListenPort", "()I",
> + &getUdpListenPort);
>
> - err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getKeypairDelegate", PARAMS_CLASS,
> + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getKeypairDelegate", "()Lchip/devicecontroller/KeypairDelegate;",
>
> - err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getRootCertificate", PARAMS_CLASS,
> + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getRootCertificate", "()[B",
>
> - err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIntermediateCertificate", PARAMS_CLASS,
> + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIntermediateCertificate", "()[B",
>
> - err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getOperationalCertificate", PARAMS_CLASS,
> + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getOperationalCertificate", "()[B",
>
> - err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIpk", PARAMS_CLASS, &getIpk);
> + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIpk", "()[B",
> + &getIpk);
>
>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please submit the above code to resolve this issue. I have similar changes to resolve the FindMethod issue. The method signatures above (not class signature) are correct.
PARAMS_CLASS is not the proper signature of "getUdpListenPort" or any of the subsequent FindMethod() calls.