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] Support ICD Check in message #32476

Merged
merged 9 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ object ChipClient {

if (!this::chipDeviceController.isInitialized) {
chipDeviceController =
ChipDeviceController(ControllerParams.newBuilder().setControllerVendorId(VENDOR_ID).build())
ChipDeviceController(
ControllerParams.newBuilder()
.setControllerVendorId(VENDOR_ID)
.setEnableServerInteractions(true)
.build()
)

// Set delegate for attestation trust store for device attestation verifier.
// It will replace the default attestation trust store.
Expand Down
11 changes: 10 additions & 1 deletion src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate,
jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId, uint16_t failsafeTimerSeconds,
bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete,
bool skipAttestationCertificateValidation, jstring countryCode, CHIP_ERROR * errInfoOnFailure)
bool skipAttestationCertificateValidation, jstring countryCode, bool enableServerInteractions, CHIP_ERROR * errInfoOnFailure)
{
if (errInfoOnFailure == nullptr)
{
Expand Down Expand Up @@ -351,6 +351,9 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
setupParams.controllerNOC = nocSpan;
}

initParams.enableServerInteractions = enableServerInteractions;
setupParams.enableServerInteractions = enableServerInteractions;

*errInfoOnFailure = DeviceControllerFactory::GetInstance().Init(initParams);
if (*errInfoOnFailure != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -393,6 +396,11 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(

wrapper->getICDClientStorage()->UpdateFabricList(wrapper->Controller()->GetFabricIndex());

auto engine = chip::app::InteractionModelEngine::GetInstance();
*errInfoOnFailure = wrapper->mCheckInDelegate.Init(&wrapper->mICDClientStorage, engine);
*errInfoOnFailure = wrapper->mCheckInHandler.Init(DeviceControllerFactory::GetInstance().GetSystemState()->ExchangeMgr(),
&wrapper->mICDClientStorage, &wrapper->mCheckInDelegate, engine);

memset(ipkBuffer.data(), 0, ipkBuffer.size());

if (*errInfoOnFailure != CHIP_NO_ERROR)
Expand Down Expand Up @@ -769,6 +777,7 @@ void AndroidDeviceControllerWrapper::OnReadCommissioningInfo(const chip::Control

// For ICD
mUserActiveModeTriggerHint = info.icd.userActiveModeTriggerHint;
memset(mUserActiveModeTriggerInstructionBuffer, 0x00, kUserActiveModeTriggerInstructionBufferLen);
CopyCharSpanToMutableCharSpan(info.icd.userActiveModeTriggerInstruction, mUserActiveModeTriggerInstruction);

env->CallVoidMethod(mJavaObjectRef.ObjectRef(), onReadCommissioningInfoMethod, static_cast<jint>(info.basic.vendorId),
Expand Down
26 changes: 16 additions & 10 deletions src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <jni.h>

#include <app/icd/client/CheckInHandler.h>
#include <app/icd/client/DefaultCheckInDelegate.h>
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
#include <app/icd/client/DefaultICDClientStorage.h>
#include <controller/CHIPDeviceController.h>
#include <credentials/GroupDataProviderImpl.h>
Expand Down Expand Up @@ -170,19 +172,21 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
* @param[in] skipCommissioningComplete whether to skip the CASE commissioningComplete command during commissioning
* @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, 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,
static AndroidDeviceControllerWrapper *
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,
#ifdef JAVA_MATTER_CONTROLLER_TEST
ExampleOperationalCredentialsIssuerPtr opCredsIssuer,
ExampleOperationalCredentialsIssuerPtr opCredsIssuer,
#else
AndroidOperationalCredentialsIssuerPtr opCredsIssuer,
AndroidOperationalCredentialsIssuerPtr opCredsIssuer,
#endif
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate,
jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId,
uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete,
bool skipAttestationCertificateValidation, jstring countryCode, CHIP_ERROR * errInfoOnFailure);
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate,
jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId,
uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread,
bool skipCommissioningComplete, bool skipAttestationCertificateValidation, jstring countryCode,
bool enableServerInteractions, CHIP_ERROR * errInfoOnFailure);

void Shutdown();

Expand Down Expand Up @@ -221,6 +225,8 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
chip::Crypto::RawKeySessionKeystore mSessionKeystore;

chip::app::DefaultICDClientStorage mICDClientStorage;
chip::app::DefaultCheckInDelegate mCheckInDelegate;
chip::app::CheckInHandler mCheckInHandler;

JavaVM * mJavaVM = nullptr;
chip::JniGlobalReference mJavaObjectRef;
Expand Down
8 changes: 7 additions & 1 deletion src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getAdminSubject", "()J", &getAdminSubject);
SuccessOrExit(err);

jmethodID getEnableServerInteractions;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getEnableServerInteractions", "()Z",
&getEnableServerInteractions);
SuccessOrExit(err);

{
uint64_t fabricId = static_cast<uint64_t>(env->CallLongMethod(controllerParams, getFabricId));
uint16_t listenPort = static_cast<uint16_t>(env->CallIntMethod(controllerParams, getUdpListenPort));
Expand All @@ -370,6 +375,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
uint64_t adminSubject = static_cast<uint64_t>(env->CallLongMethod(controllerParams, getAdminSubject));
jobject countryCodeOptional = env->CallObjectMethod(controllerParams, getCountryCode);
jobject regulatoryLocationOptional = env->CallObjectMethod(controllerParams, getRegulatoryLocation);
bool enableServerInteractions = env->CallBooleanMethod(controllerParams, getEnableServerInteractions) == JNI_TRUE;

jobject countryCode;
err = chip::JniReferences::GetInstance().GetOptionalValue(countryCodeOptional, countryCode);
Expand All @@ -387,7 +393,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
DeviceLayer::TCPEndPointManager(), DeviceLayer::UDPEndPointManager(), std::move(opCredsIssuer), keypairDelegate,
rootCertificate, intermediateCertificate, operationalCertificate, ipk, listenPort, controllerVendorId,
failsafeTimerSeconds, attemptNetworkScanWiFi, attemptNetworkScanThread, skipCommissioningComplete,
skipAttestationCertificateValidation, static_cast<jstring>(countryCode), &err);
skipAttestationCertificateValidation, static_cast<jstring>(countryCode), enableServerInteractions, &err);
SuccessOrExit(err);

if (caseFailsafeTimerSeconds > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class ControllerParams {
@Nullable private final byte[] operationalCertificate;
@Nullable private final byte[] ipk;
private final long adminSubject;
private final boolean enableServerInteractions;

/** @param udpListenPort the UDP listening port, or 0 to pick any available port. */
private ControllerParams(Builder builder) {
Expand All @@ -43,6 +44,7 @@ private ControllerParams(Builder builder) {
this.operationalCertificate = builder.operationalCertificate;
this.ipk = builder.ipk;
this.adminSubject = builder.adminSubject;
this.enableServerInteractions = builder.enableServerInteractions;
}

public long getFabricId() {
Expand Down Expand Up @@ -114,6 +116,10 @@ public long getAdminSubject() {
return adminSubject;
}

public boolean getEnableServerInteractions() {
return enableServerInteractions;
}

/** Returns parameters with ephemerally generated operational credentials */
public static Builder newBuilder() {
return new Builder();
Expand Down Expand Up @@ -152,6 +158,7 @@ public static class Builder {
@Nullable private byte[] operationalCertificate = null;
@Nullable private byte[] ipk = null;
private long adminSubject = 0;
private boolean enableServerInteractions = false;

private Builder() {}

Expand Down Expand Up @@ -357,6 +364,18 @@ public Builder setAdminSubject(long adminSubject) {
return this;
}

/**
* Controls enabling server interactions on a controller. For ICD check-in message, this feature
* has to enable.
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
*
* @param enableServerInteractions
* @return
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
*/
public Builder setEnableServerInteractions(boolean enableServerInteractions) {
this.enableServerInteractions = enableServerInteractions;
return this;
}

public ControllerParams build() {
return new ControllerParams(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ constructor(
val udpListenPort: Int = UDP_PORT_AUTO,
val vendorId: Int = VENDOR_ID_TEST,
val countryCode: String? = null,
val enableServerInteractions: Boolean = false,
) {
companion object {
/** Matter assigned vendor ID for Google. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ class MatterControllerImpl(params: ControllerParams) : MatterController {
.setUdpListenPort(params.udpListenPort)
.setControllerVendorId(params.vendorId)
.setCountryCode(params.countryCode)
.setEnableServerInteractions(params.enableServerInteractions)

if (config != null) {
val intermediateCertificate = config.certificateData.intermediateCertificate
Expand Down
Loading