Skip to content

Commit

Permalink
Merge branch 'master' into pase-session-new-fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
mlepage-google committed Jan 19, 2022
2 parents c7f2c43 + fba51b9 commit 0bae2cf
Show file tree
Hide file tree
Showing 270 changed files with 13,751 additions and 13,755 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN apt-get update \
avahi-utils=0.7-4ubuntu7.1 \
ca-certificates=20210119~20.04.2 \
dhcpcd5=7.1.0-2build1 \
gdb=9.2-0ubuntu1~20.04 \
gdb=9.2-0ubuntu1~20.04.1 \
git=1:2.25.1-1ubuntu3.2 \
iproute2=5.5.0-1ubuntu1 \
libavahi-client3=0.7-4ubuntu7.1 \
Expand Down
37 changes: 37 additions & 0 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,43 @@ CHIP_ERROR TestAttrAccess::WriteStructAttribute(AttributeValueDecoder & aDecoder
bool emberAfTestClusterClusterTestCallback(app::CommandHandler *, const app::ConcreteCommandPath & commandPath,
const Test::DecodableType & commandData)
{
// Setup the test variables
emAfLoadAttributeDefaults(commandPath.mEndpointId, true, MakeOptional(commandPath.mClusterId));
for (int i = 0; i < kAttributeListLength; ++i)
{
gListUint8Data[i] = 0;
gListOctetStringData[i].SetLength(0);
gListOperationalCert[i].SetLength(0);
listStructOctetStringData[i].fabricIndex = 0;
listStructOctetStringData[i].operationalCert = ByteSpan();
gSimpleEnums[i] = SimpleEnum::kUnspecified;
}
gSimpleEnumCount = 0;

gStructAttributeValue.a = 0;
gStructAttributeValue.b = false;
gStructAttributeValue.c = SimpleEnum::kValueA;
gStructAttributeValue.d = ByteSpan();
gStructAttributeValue.e = CharSpan();
gStructAttributeValue.f = BitFlags<SimpleBitmap>();
gStructAttributeValue.g = 0;
gStructAttributeValue.h = 0;

gNullableStructAttributeValue.SetNull();

gNullablesAndOptionalsStruct.nullableInt.SetNull();
gNullablesAndOptionalsStruct.optionalInt = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalInt = NullOptional;
gNullablesAndOptionalsStruct.nullableString.SetNull();
gNullablesAndOptionalsStruct.optionalString = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalString = NullOptional;
gNullablesAndOptionalsStruct.nullableStruct.SetNull();
gNullablesAndOptionalsStruct.optionalStruct = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalStruct = NullOptional;
gNullablesAndOptionalsStruct.nullableList.SetNull();
gNullablesAndOptionalsStruct.optionalList = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalList = NullOptional;

emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
return true;
}
Expand Down
9 changes: 8 additions & 1 deletion src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ void emberAfResetAttributes(EndpointId endpoint)
emAfLoadAttributeDefaults(endpoint, true);
}

void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage)
void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional<ClusterId> clusterId)
{
uint16_t ep;
uint8_t clusterI, curNetwork = 0 /* emberGetCurrentNetwork() */;
Expand Down Expand Up @@ -1142,6 +1142,13 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage)
for (clusterI = 0; clusterI < de->endpointType->clusterCount; clusterI++)
{
EmberAfCluster * cluster = &(de->endpointType->cluster[clusterI]);
if (clusterId.HasValue())
{
if (clusterId.Value() != cluster->clusterId)
{
continue;
}
}

// when the attributeCount is high, the loop takes too long to run and a
// watchdog kicks in causing a reset. As a workaround, we'll
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void emberAfResetAttributes(chip::EndpointId endpoint);
// Loads the attributes from built-in default and / or storage. If
// ignoreStorage is true, only defaults will be read, and the storage for
// non-volatile attributes will be overwritten with those defaults.
void emAfLoadAttributeDefaults(chip::EndpointId endpoint, bool ignoreStorage);
void emAfLoadAttributeDefaults(chip::EndpointId endpoint, bool ignoreStorage, chip::Optional<chip::ClusterId> = chip::NullOptional);

// After the RAM value has changed, code should call this function. If this
// attribute has been tagged as non-volatile, its value will be stored.
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/partials/header.zapt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 1 addition & 3 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,9 +1714,7 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
GeneralCommissioningCluster genCom;
// TODO: should get the endpoint information from the descriptor cluster.
genCom.Associate(proxy, 0);
// TODO(cecille): Make this a parameter
uint16_t commissioningExpirySeconds = 60;
genCom.ArmFailSafe(mSuccess.Cancel(), mFailure.Cancel(), commissioningExpirySeconds, breadcrumb, kCommandTimeoutMs);
genCom.ArmFailSafe(mSuccess.Cancel(), mFailure.Cancel(), params.GetFailsafeTimerSeconds(), breadcrumb, kCommandTimeoutMs);
}
break;
case CommissioningStage::kConfigRegulatory: {
Expand Down
8 changes: 8 additions & 0 deletions src/controller/CommissioningDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ class CommissioningParameters
bool HasAttestationNonce() const { return mAttestationNonce.HasValue(); }
bool HasWiFiCredentials() const { return mWiFiCreds.HasValue(); }
bool HasThreadOperationalDataset() const { return mThreadOperationalDataset.HasValue(); }
uint16_t GetFailsafeTimerSeconds() const { return mFailsafeTimerSeconds; }
const Optional<ByteSpan> GetCSRNonce() const { return mCSRNonce; }
const Optional<ByteSpan> GetAttestationNonce() const { return mAttestationNonce; }
const Optional<WiFiCredentials> GetWiFiCredentials() const { return mWiFiCreds; }
const Optional<ByteSpan> GetThreadOperationalDataset() const { return mThreadOperationalDataset; }

CommissioningParameters & SetFailsafeTimerSeconds(uint16_t seconds)
{
mFailsafeTimerSeconds = seconds;
return *this;
}

// The lifetime of the buffer csrNonce is pointing to, should exceed the lifetime of CommissioningParameters object.
CommissioningParameters & SetCSRNonce(ByteSpan csrNonce)
{
Expand Down Expand Up @@ -95,6 +102,7 @@ class CommissioningParameters
CHIP_ERROR GetCompletionStatus() { return completionStatus; }

private:
uint16_t mFailsafeTimerSeconds = 60;
Optional<ByteSpan> mCSRNonce; ///< CSR Nonce passed by the commissioner
Optional<ByteSpan> mAttestationNonce; ///< Attestation Nonce passed by the commissioner
Optional<WiFiCredentials> mWiFiCreds;
Expand Down
1 change: 1 addition & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ shared_library("jni") {
"CHIPDeviceController-JNI.cpp",
"zap-generated/CHIPClusters-JNI.cpp",
"zap-generated/CHIPClustersRead-JNI.cpp",
"zap-generated/CHIPClustersWrite-JNI.cpp",
"zap-generated/CHIPInvokeCallbacks.cpp",
"zap-generated/CHIPInvokeCallbacks.h",
"zap-generated/CHIPReadCallbacks.cpp",
Expand Down
41 changes: 0 additions & 41 deletions src/controller/java/templates/CHIPClusters-JNI.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -87,47 +87,6 @@ JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, {{asLowerCamelCase name}})
{{/chip_cluster_commands}}
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if isWritableAttribute}}
{{! TODO: Lists not supported in attribute writes yet. }}
{{#unless isList}}

JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, write{{asUpperCamelCase name}}Attribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, {{asJniBasicType type true}} value, jobject timedWriteTimeoutMs)
{
chip::DeviceLayer::StackLock lock;
using TypeInfo = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo;
TypeInfo::Type cppValue;

{{>encode_value target="cppValue" source="value" cluster=parent.name}}

std::unique_ptr<CHIPDefaultSuccessCallback, void (*)(CHIPDefaultSuccessCallback *)> onSuccess(Platform::New<CHIPDefaultSuccessCallback>(callback), Platform::Delete<CHIPDefaultSuccessCallback>);
VerifyOrReturn(onSuccess.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native success callback", CHIP_ERROR_NO_MEMORY));

std::unique_ptr<CHIPDefaultFailureCallback, void (*)(CHIPDefaultFailureCallback *)> onFailure(Platform::New<CHIPDefaultFailureCallback>(callback), Platform::Delete<CHIPDefaultFailureCallback>);
VerifyOrReturn(onFailure.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native failure callback", CHIP_ERROR_NO_MEMORY));

CHIP_ERROR err = CHIP_NO_ERROR;
{{asCamelCased ../name false}}Cluster * cppCluster = reinterpret_cast<{{asCamelCased ../name false}}Cluster *>(clusterPtr);
VerifyOrReturn(cppCluster != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Could not get native cluster", CHIP_ERROR_INCORRECT_STATE));

auto successFn = chip::Callback::Callback<CHIPDefaultWriteSuccessCallbackType>::FromCancelable(onSuccess->Cancel());
auto failureFn = chip::Callback::Callback<CHIPDefaultFailureCallbackType>::FromCancelable(onFailure->Cancel());

{{#if mustUseTimedWrite}}
err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall, chip::JniReferences::GetInstance().IntegerToPrimitive(timedWriteTimeoutMs));
{{else}}
if (timedWriteTimeoutMs == nullptr) {
err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall);
} else {
err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall, chip::JniReferences::GetInstance().IntegerToPrimitive(timedWriteTimeoutMs));
}
{{/if}}
VerifyOrReturn(err == CHIP_NO_ERROR, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error writing attribute", err));

onSuccess.release();
onFailure.release();
}
{{/unless}}
{{/if}}
{{#if isReportableAttribute}}
{{#unless isList}}
JNI_METHOD(void, {{asCamelCased ../name false}}Cluster, subscribe{{asCamelCased name false}}Attribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, jint minInterval, jint maxInterval)
Expand Down
74 changes: 74 additions & 0 deletions src/controller/java/templates/CHIPClustersWrite-JNI.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{> header}}
{{#if (chip_has_client_clusters)}}
#include "CHIPCallbackTypes.h"
#include "CHIPInvokeCallbacks.h"
#include "CHIPReadCallbacks.h"

#include <app-common/zap-generated/cluster-objects.h>
#include <zap-generated/CHIPClusters.h>
#include <zap-generated/CHIPClientCallbacks.h>

#include <controller/java/AndroidCallbacks.h>
#include <controller/java/AndroidClusterExceptions.h>
#include <controller/java/CHIPDefaultCallbacks.h>
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>
#include <jni.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/Span.h>
#include <platform/PlatformManager.h>

#define JNI_METHOD(RETURN, CLASS_NAME, METHOD_NAME) \
extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipClusters_00024##CLASS_NAME##_##METHOD_NAME

using namespace chip;
using namespace chip::Controller;

{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if isWritableAttribute}}
{{! TODO: Lists not supported in attribute writes yet. }}
{{#unless isList}}

JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, write{{asUpperCamelCase name}}Attribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, {{asJniBasicType type true}} value, jobject timedWriteTimeoutMs)
{
chip::DeviceLayer::StackLock lock;
using TypeInfo = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo;
TypeInfo::Type cppValue;

{{>encode_value target="cppValue" source="value" cluster=parent.name}}

std::unique_ptr<CHIPDefaultSuccessCallback, void (*)(CHIPDefaultSuccessCallback *)> onSuccess(Platform::New<CHIPDefaultSuccessCallback>(callback), Platform::Delete<CHIPDefaultSuccessCallback>);
VerifyOrReturn(onSuccess.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native success callback", CHIP_ERROR_NO_MEMORY));

std::unique_ptr<CHIPDefaultFailureCallback, void (*)(CHIPDefaultFailureCallback *)> onFailure(Platform::New<CHIPDefaultFailureCallback>(callback), Platform::Delete<CHIPDefaultFailureCallback>);
VerifyOrReturn(onFailure.get() != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native failure callback", CHIP_ERROR_NO_MEMORY));

CHIP_ERROR err = CHIP_NO_ERROR;
{{asCamelCased ../name false}}Cluster * cppCluster = reinterpret_cast<{{asCamelCased ../name false}}Cluster *>(clusterPtr);
VerifyOrReturn(cppCluster != nullptr, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Could not get native cluster", CHIP_ERROR_INCORRECT_STATE));

auto successFn = chip::Callback::Callback<CHIPDefaultWriteSuccessCallbackType>::FromCancelable(onSuccess->Cancel());
auto failureFn = chip::Callback::Callback<CHIPDefaultFailureCallbackType>::FromCancelable(onFailure->Cancel());

{{#if mustUseTimedWrite}}
err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall, chip::JniReferences::GetInstance().IntegerToPrimitive(timedWriteTimeoutMs));
{{else}}
if (timedWriteTimeoutMs == nullptr) {
err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall);
} else {
err = cppCluster->WriteAttribute<TypeInfo>(cppValue, onSuccess->mContext, successFn->mCall, failureFn->mCall, chip::JniReferences::GetInstance().IntegerToPrimitive(timedWriteTimeoutMs));
}
{{/if}}
VerifyOrReturn(err == CHIP_NO_ERROR, chip::AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error writing attribute", err));

onSuccess.release();
onFailure.release();
}
{{/unless}}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}
{{/if}}
5 changes: 5 additions & 0 deletions src/controller/java/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"name": "CHIP ZCL API for Java (native code for reads)",
"output": "src/controller/java/zap-generated/CHIPClustersRead-JNI.cpp"
},
{
"path": "CHIPClustersWrite-JNI.zapt",
"name": "CHIP ZCL API for Java (native code for writes)",
"output": "src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp"
},
{
"path": "CHIPReadCallbacks.zapt",
"name": "CHIP cluster attribute read callback for Java (native code)",
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/zap-generated/CHIPCallbackTypes.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0bae2cf

Please sign in to comment.