Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinpan1 authored Feb 3, 2023
2 parents 1348e67 + 17d7f00 commit a169e46
Show file tree
Hide file tree
Showing 47 changed files with 4,143 additions and 1,011 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker_img.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
- "-telink"
- "-ti"
- "-tizen"
- "-tizen-qemu"
- "-openiotsdk"
# NOTE: vscode image consumes ~52 GB disk space but GitHub-hosted runners provide ~10 GB free disk space(https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources)
#- "-vscode"
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,10 @@ jobs:
if: always()
run: |
git grep -n '0x%[0-9-]*" *PRI[^xX]' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
# git grep exits with 0 if it finds a match, but we want
# to fail (exit nonzero) on match.
- name: Check for use of NSLog instead of Matter logging in Matter framework
if: always()
run: |
git grep -n 'NSLog(' -- src/darwin/Framework/CHIP && exit 1 || exit 0
8 changes: 4 additions & 4 deletions docs/guides/matter-repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ launched into the playground:
## Guides
[REPL Basics](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter%20-%20REPL%20Intro.ipynb)
[REPL Basics](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter_REPL_Intro.ipynb)
[Using the IM](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter%20-%20Basic%20Interactions.ipynb)
[Using the IM](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter_Basic_Interactions.ipynb)
[Multi Fabric Commissioning](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter%20-%20Multi%20Fabric%20Commissioning.ipynb)
[Multi Fabric Commissioning](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter_Multi_Fabric_Commissioning.ipynb)
[Access Control](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter%20-%20Access%20Control.ipynb)
[Access Control](https://deepnote.com/viewer/github/project-chip/connectedhomeip/blob/master/docs/guides/repl/Matter_Access_Control.ipynb)
## Testing
Expand Down
49 changes: 31 additions & 18 deletions examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@
#include "DataModelLogger.h"
#include "ModelCommand.h"

constexpr const char * kWriteCommandKey = "write";
constexpr const char * kWriteByIdCommandKey = "write-by-id";
constexpr const char * kForceWriteCommandKey = "force-write";

enum class WriteCommandType
{
kWrite, // regular, writable attributes
kForceWrite, // forced writes, send a write command on something expected to fail
};

template <class T = std::vector<CustomArgument *>>
class WriteAttribute : public InteractionModelWriter, public ModelCommand, public chip::app::WriteClient::Callback
{
public:
WriteAttribute(CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this), ModelCommand("write-by-id", credsIssuerConfig)
InteractionModelWriter(this), ModelCommand(kWriteByIdCommandKey, credsIssuerConfig)
{
AddArgumentClusterIds();
AddArgumentAttributeIds();
Expand All @@ -37,7 +47,7 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
}

WriteAttribute(chip::ClusterId clusterId, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this), ModelCommand("write-by-id", credsIssuerConfig), mClusterIds(1, clusterId)
InteractionModelWriter(this), ModelCommand(kWriteByIdCommandKey, credsIssuerConfig), mClusterIds(1, clusterId)
{
AddArgumentAttributeIds();
AddArgumentAttributeValues();
Expand All @@ -46,44 +56,45 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi

template <typename minType, typename maxType>
WriteAttribute(chip::ClusterId clusterId, const char * attributeName, minType minValue, maxType maxValue,
chip::AttributeId attributeId, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, credsIssuerConfig)
chip::AttributeId attributeId, WriteCommandType commandType, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, commandType, credsIssuerConfig)
{
AddArgumentAttributeName(attributeName);
AddArgumentAttributeValues(static_cast<int64_t>(minValue), static_cast<uint64_t>(maxValue));
AddArguments();
}

WriteAttribute(chip::ClusterId clusterId, const char * attributeName, float minValue, float maxValue,
chip::AttributeId attributeId, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, credsIssuerConfig)
chip::AttributeId attributeId, WriteCommandType commandType, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, commandType, credsIssuerConfig)
{
AddArgumentAttributeName(attributeName);
AddArgumentAttributeValues(minValue, maxValue);
AddArguments();
}

WriteAttribute(chip::ClusterId clusterId, const char * attributeName, double minValue, double maxValue,
chip::AttributeId attributeId, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, credsIssuerConfig)
chip::AttributeId attributeId, WriteCommandType commandType, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, commandType, credsIssuerConfig)
{
AddArgumentAttributeName(attributeName);
AddArgumentAttributeValues(minValue, maxValue);
AddArguments();
}

WriteAttribute(chip::ClusterId clusterId, const char * attributeName, chip::AttributeId attributeId,
CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, credsIssuerConfig)
WriteCommandType commandType, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, commandType, credsIssuerConfig)
{
AddArgumentAttributeName(attributeName);
AddArgumentAttributeValues();
AddArguments();
}

WriteAttribute(chip::ClusterId clusterId, const char * attributeName, chip::AttributeId attributeId,
TypedComplexArgument<T> & attributeParser, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, credsIssuerConfig)
TypedComplexArgument<T> & attributeParser, WriteCommandType commandType,
CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute(clusterId, attributeId, commandType, credsIssuerConfig)
{
AddArgumentAttributeName(attributeName);
AddArgumentAttributeValues(attributeParser);
Expand Down Expand Up @@ -159,7 +170,7 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi

protected:
WriteAttribute(const char * attributeName, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this), ModelCommand("write", credsIssuerConfig)
InteractionModelWriter(this), ModelCommand(kWriteCommandKey, credsIssuerConfig)
{
// Subclasses are responsible for calling AddArguments.
}
Expand Down Expand Up @@ -244,9 +255,11 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi

private:
// This constructor is private as it is not intended to be used from outside the class.
WriteAttribute(chip::ClusterId clusterId, chip::AttributeId attributeId, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this), ModelCommand("write", credsIssuerConfig), mClusterIds(1, clusterId),
mAttributeIds(1, attributeId)
WriteAttribute(chip::ClusterId clusterId, chip::AttributeId attributeId, WriteCommandType commandType,
CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this),
ModelCommand(commandType == WriteCommandType::kWrite ? kWriteCommandKey : kForceWriteCommandKey, credsIssuerConfig),
mClusterIds(1, clusterId), mAttributeIds(1, attributeId)
{}

std::vector<chip::ClusterId> mClusterIds;
Expand All @@ -261,8 +274,8 @@ class WriteAttributeAsComplex : public WriteAttribute<T>
{
public:
WriteAttributeAsComplex(chip::ClusterId clusterId, const char * attributeName, chip::AttributeId attributeId,
CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute<T>(clusterId, attributeName, attributeId, mAttributeParser, credsIssuerConfig)
WriteCommandType commandType, CredentialIssuerCommands * credsIssuerConfig) :
WriteAttribute<T>(clusterId, attributeName, attributeId, mAttributeParser, commandType, credsIssuerConfig)
{}

private:
Expand Down
41 changes: 40 additions & 1 deletion examples/chip-tool/commands/common/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ std::vector<std::string> GetArgumentsFromJson(Command * command, Json::Value & v
return args;
};

// Check for arguments with a starting '"' but no ending '"': those
// would indicate that people are using double-quoting, not single
// quoting, on arguments with spaces.
static void DetectAndLogMismatchedDoubleQuotes(int argc, char ** argv)
{
for (int curArg = 0; curArg < argc; ++curArg)
{
char * arg = argv[curArg];
if (!arg)
{
continue;
}

auto len = strlen(arg);
if (len == 0)
{
continue;
}

if (arg[0] == '"' && arg[len - 1] != '"')
{
ChipLogError(chipTool,
"Mismatched '\"' detected in argument: '%s'. Use single quotes to delimit arguments with spaces "
"in them: 'x y', not \"x y\".",
arg);
}
}
}

} // namespace

void Commands::Register(const char * clusterName, commands_list commandsList)
Expand Down Expand Up @@ -217,6 +246,10 @@ CHIP_ERROR Commands::RunCommand(int argc, char ** argv, bool interactive)
int argumentsPosition = isGlobalCommand ? 4 : 3;
if (!command->InitArguments(argc - argumentsPosition, &argv[argumentsPosition]))
{
if (interactive)
{
DetectAndLogMismatchedDoubleQuotes(argc - argumentsPosition, &argv[argumentsPosition]);
}
ShowCommand(argv[0], argv[1], command);
return CHIP_ERROR_INVALID_ARGUMENT;
}
Expand Down Expand Up @@ -267,7 +300,8 @@ Command * Commands::GetGlobalCommand(CommandsVector & commands, std::string comm

bool Commands::IsAttributeCommand(std::string commandName) const
{
return commandName.compare("read") == 0 || commandName.compare("write") == 0 || commandName.compare("subscribe") == 0;
return commandName.compare("read") == 0 || commandName.compare("write") == 0 || commandName.compare("force-write") == 0 ||
commandName.compare("subscribe") == 0;
}

bool Commands::IsEventCommand(std::string commandName) const
Expand Down Expand Up @@ -308,6 +342,7 @@ void Commands::ShowCluster(std::string executable, std::string clusterName, Comm
fprintf(stderr, " +-------------------------------------------------------------------------------------+\n");
bool readCommand = false;
bool writeCommand = false;
bool writeOverrideCommand = false;
bool subscribeCommand = false;
bool readEventCommand = false;
bool subscribeEventCommand = false;
Expand All @@ -325,6 +360,10 @@ void Commands::ShowCluster(std::string executable, std::string clusterName, Comm
{
writeCommand = true;
}
else if (strcmp(command->GetName(), "force-write") == 0 && !writeOverrideCommand)
{
writeOverrideCommand = true;
}
else if (strcmp(command->GetName(), "subscribe") == 0 && !subscribeCommand)
{
subscribeCommand = true;
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/commands/common/CredentialIssuerCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class CredentialIssuerCommands

virtual chip::Controller::OperationalCredentialsDelegate * GetCredentialIssuer() = 0;

virtual void SetCredentialIssuerCATValues(chip::CATValues cats) = 0;

/**
* @brief
* This function is used to Generate NOC Chain for the Controller/Commissioner. Parameters follow the example implementation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ExampleCredentialIssuerCommands : public CredentialIssuerCommands
return CHIP_NO_ERROR;
}
chip::Controller::OperationalCredentialsDelegate * GetCredentialIssuer() override { return &mOpCredsIssuer; }
void SetCredentialIssuerCATValues(chip::CATValues cats) override { mOpCredsIssuer.SetCATValuesForNextNOCRequest(cats); }
CHIP_ERROR GenerateControllerNOCChain(chip::NodeId nodeId, chip::FabricId fabricId, const chip::CATValues & cats,
chip::Crypto::P256Keypair & keypair, chip::MutableByteSpan & rcac,
chip::MutableByteSpan & icac, chip::MutableByteSpan & noc) override
Expand Down
15 changes: 15 additions & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ using namespace ::chip::Controller;
CHIP_ERROR PairingCommand::RunCommand()
{
CurrentCommissioner().RegisterPairingDelegate(this);
// Clear the CATs in OperationalCredentialsIssuer
mCredIssuerCmds->SetCredentialIssuerCATValues(kUndefinedCATs);

if (mCASEAuthTags.HasValue() && mCASEAuthTags.Value().size() <= kMaxSubjectCATAttributeCount)
{
CATValues cats = kUndefinedCATs;
for (size_t index = 0; index < mCASEAuthTags.Value().size(); ++index)
{
cats.values[index] = mCASEAuthTags.Value()[index];
}
if (cats.AreValid())
{
mCredIssuerCmds->SetCredentialIssuerCATValues(cats);
}
}
return RunInternal(mNodeId);
}

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PairingCommand : public CHIPCommand,
AddArgument("bypass-attestation-verifier", 0, 1, &mBypassAttestationVerifier,
"Bypass the attestation verifier. If not provided or false, the attestation verifier is not bypassed."
" If true, the commissioning will continue in case of attestation verification failure.");
AddArgument("case-auth-tags", 1, UINT32_MAX, &mCASEAuthTags, "The CATs to be encoded in the NOC sent to the commissionee");

switch (networkType)
{
Expand Down Expand Up @@ -188,6 +189,7 @@ class PairingCommand : public CHIPCommand,
chip::Optional<bool> mPaseOnly;
chip::Optional<bool> mSkipCommissioningComplete;
chip::Optional<bool> mBypassAttestationVerifier;
chip::Optional<std::vector<uint32_t>> mCASEAuthTags;
uint16_t mRemotePort;
uint16_t mDiscriminator;
uint32_t mSetupPINCode;
Expand Down
10 changes: 3 additions & 7 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,17 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands, CredentialIss
{{/zcl_attributes_server}}
make_unique<WriteAttribute<>>(Id, credsIssuerConfig), //
{{#zcl_attributes_server}}
{{#if isWritable}}
{{#if_chip_complex}}
make_unique<WriteAttributeAsComplex<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}>>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
make_unique<WriteAttributeAsComplex<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}>>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, WriteCommandType::k{{#unless isWritable}}Force{{/unless}}Write, credsIssuerConfig), //
{{else if (isString type)}}
make_unique<WriteAttribute<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}>>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
make_unique<WriteAttribute<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}>>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, WriteCommandType::k{{#unless isWritable}}Force{{/unless}}Write, credsIssuerConfig), //
{{else}}
make_unique<WriteAttribute<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}>>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", {{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
make_unique<WriteAttribute<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}>>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", {{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, Attributes::{{asUpperCamelCase name}}::Id, WriteCommandType::k{{#unless isWritable}}Force{{/unless}}Write, credsIssuerConfig), //
{{/if_chip_complex}}
{{/if}}
{{/zcl_attributes_server}}
make_unique<SubscribeAttribute>(Id, credsIssuerConfig), //
{{#zcl_attributes_server}}
{{#if isReportable}}
make_unique<SubscribeAttribute>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), //
{{/if}}
{{/zcl_attributes_server}}
//
// Events
Expand Down
6 changes: 6 additions & 0 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ CHIP_ERROR AppTask::Init()
return err;
}

#if CONFIG_CHIP_THREAD_SSED
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SynchronizedSleepyEndDevice);
#elif CONFIG_OPENTHREAD_MTD_SED
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#else
err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#endif

if (err != CHIP_NO_ERROR)
{
Expand Down
1 change: 1 addition & 0 deletions examples/tv-app/android/java/AppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <platform/DeviceInstanceInfoProvider.h>

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::AppPlatform;
using namespace chip::DeviceLayer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
*/
package com.chip.casting;

import android.util.Log;
import java.math.BigInteger;
import java.util.Arrays;

public class AppParameters {
private static final String TAG = AppParameters.class.getSimpleName();
public static final int MIN_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH = 16;
private static final int TEST_SETUP_PASSCODE = 20202021;
private static final int TEST_DISCRIMINATOR = 0xF00;
Expand All @@ -32,11 +37,20 @@ public class AppParameters {
private int discriminator = TEST_DISCRIMINATOR;

public void setRotatingDeviceIdUniqueId(byte[] rotatingDeviceIdUniqueId) {
this.rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueId;
Log.d(
TAG,
"AppParameters.setRotatingDeviceIdUniqueId called with "
+ new BigInteger(1, rotatingDeviceIdUniqueId).toString(16));
this.rotatingDeviceIdUniqueId =
Arrays.copyOf(rotatingDeviceIdUniqueId, rotatingDeviceIdUniqueId.length);
}

public byte[] getRotatingDeviceIdUniqueId() {
return rotatingDeviceIdUniqueId;
Log.d(
TAG,
"AppParameters.getRotatingDeviceIdUniqueId returning copyOf "
+ new BigInteger(1, rotatingDeviceIdUniqueId).toString(16));
return Arrays.copyOf(rotatingDeviceIdUniqueId, rotatingDeviceIdUniqueId.length);
}

public DACProvider getDacProvider() {
Expand Down
Loading

0 comments on commit a169e46

Please sign in to comment.