Skip to content

Commit

Permalink
Merge branch 'master' into Test_Added_July1
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple authored Jul 2, 2022
2 parents c66bc18 + e491f85 commit 3c0f2ab
Show file tree
Hide file tree
Showing 29 changed files with 429 additions and 219 deletions.
3 changes: 2 additions & 1 deletion examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ void ModelCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CH

void ModelCommand::Shutdown()
{
ResetArguments();
mOnDeviceConnectedCallback.Cancel();
mOnDeviceConnectionFailureCallback.Cancel();

CHIPCommand::Shutdown();
}
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/common/CHIPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CHIPCommand : public Command

// Shut down the command. After a Shutdown call the command object is ready
// to be used for another command invocation.
virtual void Shutdown() {}
virtual void Shutdown() { ResetArguments(); }

// Clean up any resources allocated by the command. Some commands may hold
// on to resources after Shutdown(), but Cleanup() will guarantee those are
Expand Down
160 changes: 135 additions & 25 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,44 +854,154 @@ size_t Command::AddArgumentToList(Argument && argument)
return 0;
}

namespace {
template <typename T>
void ResetOptionalArg(const Argument & arg)
{
VerifyOrDie(arg.isOptional());

if (arg.isNullable())
{
reinterpret_cast<chip::Optional<chip::app::DataModel::Nullable<T>> *>(arg.value)->ClearValue();
}
else
{
reinterpret_cast<chip::Optional<T> *>(arg.value)->ClearValue();
}
}
} // anonymous namespace

void Command::ResetArguments()
{
for (size_t i = 0; i < mArgs.size(); i++)
{
const Argument arg = mArgs[i];
const ArgumentType type = arg.type;
const uint8_t flags = arg.flags;
if (type == ArgumentType::VectorBool && flags == Argument::kOptional)
if (arg.isOptional())
{
auto vectorArgument = static_cast<std::vector<uint16_t> *>(arg.value);
vectorArgument->clear();
}
else if (type == ArgumentType::Vector16 && flags != Argument::kOptional)
{
auto vectorArgument = static_cast<std::vector<uint16_t> *>(arg.value);
vectorArgument->clear();
}
else if (type == ArgumentType::Vector32 && flags != Argument::kOptional)
{
auto vectorArgument = static_cast<std::vector<uint32_t> *>(arg.value);
vectorArgument->clear();
}
else if (type == ArgumentType::Vector32 && flags == Argument::kOptional)
{
auto optionalArgument = static_cast<chip::Optional<std::vector<uint32_t>> *>(arg.value);
if (optionalArgument->HasValue())
// Must always clean these up so they don't carry over to the next
// command invocation in interactive mode.
switch (type)
{
optionalArgument->Value().clear();
case ArgumentType::Complex: {
// No optional complex arguments so far.
VerifyOrDie(false);
break;
}
case ArgumentType::Custom: {
// No optional custom arguments so far.
VerifyOrDie(false);
break;
}
case ArgumentType::VectorBool: {
auto vectorArgument = static_cast<std::vector<bool> *>(arg.value);
vectorArgument->clear();
break;
}
case ArgumentType::Vector16: {
// No optional Vector16 arguments so far.
VerifyOrDie(false);
break;
}
case ArgumentType::Vector32: {
ResetOptionalArg<std::vector<uint32_t>>(arg);
break;
}
case ArgumentType::VectorCustom: {
// No optional VectorCustom arguments so far.
VerifyOrDie(false);
break;
}
case ArgumentType::Attribute: {
// No optional Attribute arguments so far.
VerifyOrDie(false);
break;
}
case ArgumentType::String: {
ResetOptionalArg<char *>(arg);
break;
}
case ArgumentType::CharString: {
ResetOptionalArg<chip::CharSpan>(arg);
break;
}
case ArgumentType::OctetString: {
ResetOptionalArg<chip::ByteSpan>(arg);
break;
}
case ArgumentType::Bool: {
ResetOptionalArg<bool>(arg);
break;
}
case ArgumentType::Number_uint8: {
ResetOptionalArg<uint8_t>(arg);
break;
}
case ArgumentType::Number_uint16: {
ResetOptionalArg<uint16_t>(arg);
break;
}
case ArgumentType::Number_uint32: {
ResetOptionalArg<uint32_t>(arg);
break;
}
case ArgumentType::Number_uint64: {
ResetOptionalArg<uint64_t>(arg);
break;
}
case ArgumentType::Number_int8: {
ResetOptionalArg<int8_t>(arg);
break;
}
case ArgumentType::Number_int16: {
ResetOptionalArg<int16_t>(arg);
break;
}
case ArgumentType::Number_int32: {
ResetOptionalArg<int32_t>(arg);
break;
}
case ArgumentType::Number_int64: {
ResetOptionalArg<int64_t>(arg);
break;
}
case ArgumentType::Float: {
ResetOptionalArg<float>(arg);
break;
}
case ArgumentType::Double: {
ResetOptionalArg<double>(arg);
break;
}
case ArgumentType::Address: {
ResetOptionalArg<AddressWithInterface>(arg);
break;
}
}
}
else if (type == ArgumentType::VectorCustom && flags != Argument::kOptional)
else
{
auto vectorArgument = static_cast<std::vector<CustomArgument *> *>(arg.value);
for (auto & customArgument : *vectorArgument)
// Some non-optional arguments have state that needs to be cleaned
// up too.
if (type == ArgumentType::Vector16)
{
delete customArgument;
auto vectorArgument = static_cast<std::vector<uint16_t> *>(arg.value);
vectorArgument->clear();
}
else if (type == ArgumentType::Vector32)
{
auto vectorArgument = static_cast<std::vector<uint32_t> *>(arg.value);
vectorArgument->clear();
}
else if (type == ArgumentType::VectorCustom)
{
auto vectorArgument = static_cast<std::vector<CustomArgument *> *>(arg.value);
for (auto & customArgument : *vectorArgument)
{
delete customArgument;
}
vectorArgument->clear();
}
vectorArgument->clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ void DiscoverCommissionersCommand::Shutdown()

ChipLogProgress(chipTool, "Total of %d commissioner(s) discovered in %u sec", commissionerCount,
std::chrono::duration_cast<System::Clock::Seconds16>(GetWaitDuration()).count());

CHIPCommand::Shutdown();
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,11 @@ class TestCommandBridge : public CHIPCommandBridge,

SetIdentity(identity);

// Disconnect our existing device; otherwise getConnectedDevice will
// just hand it right back to us without establishing a new CASE
// Invalidate our existing CASE session; otherwise getConnectedDevice
// will just hand it right back to us without establishing a new CASE
// session.
if (GetDevice(identity) != nil) {
auto device = [GetDevice(identity) internalDevice];
if (device != nullptr) {
device->Disconnect();
}
[GetDevice(identity) invalidateCASESession];
mConnectedDevices[identity] = nil;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
break;
case TransferSession::OutputEventType::kAckEOFReceived:
ChipLogDetail(BDX, "Transfer completed, got AckEOF");
mStopPolling = true;
Reset();
break;
case TransferSession::OutputEventType::kStatusReceived:
Expand Down
5 changes: 3 additions & 2 deletions scripts/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ mbed-tools==7.49.1 ; platform_machine != "aarch64" and sys_platform == "linux"
# via -r requirements.mbed.txt
mobly==1.10.1
# via -r requirements.txt
numpy==1.20.3
numpy>=1.22
# via pandas
packaging==20.9
# via
# fastcore
# ghapi
# pytest
# west
pandas==1.2.4 ; platform_machine != "aarch64" and platform_machine != "arm64"
pandas==1.4.3 ; platform_machine != "aarch64" and platform_machine != "arm64"
# via -r requirements.txt
parso==0.8.2
# via jedi
Expand Down Expand Up @@ -297,6 +297,7 @@ west==0.12.0
# via -r requirements.txt
wheel==0.36.2
# via -r requirements.txt
tornado==6.1

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
3 changes: 3 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ cryptography

# python unit tests
colorama

# update tornado for pw_watch
tornado
4 changes: 3 additions & 1 deletion src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
}
MutableByteSpan rcacSpan(rcac.Get(), kMaxCHIPDERCertLength);

// The lifetime of the ephemeralKey variable must be kept until SetupParams is saved.
Crypto::P256Keypair ephemeralKey;

if (rootCertificate != nullptr && intermediateCertificate != nullptr && nodeOperationalCertificate != nullptr &&
keypairDelegate != nullptr)
{
Expand All @@ -217,7 +220,6 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
}
else
{
Crypto::P256Keypair ephemeralKey;
*errInfoOnFailure = ephemeralKey.Initialize();
if (*errInfoOnFailure != CHIP_NO_ERROR)
{
Expand Down
22 changes: 12 additions & 10 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ pthread_t sIOThread = PTHREAD_NULL;

jclass sChipDeviceControllerExceptionCls = NULL;

const char * PARAMS_CLASS = "()Lchip/devicecontroller/ControllerParams;";

} // namespace

// NOTE: Remote device ID is in sync with the echo server device id
Expand Down Expand Up @@ -166,27 +164,31 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr

// Retrieve initialization params.
jmethodID getUdpListenPort;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getUdpListenPort", PARAMS_CLASS, &getUdpListenPort);
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getUdpListenPort", "()I", &getUdpListenPort);
SuccessOrExit(err);

jmethodID getKeypairDelegate;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getKeypairDelegate", PARAMS_CLASS,
&getKeypairDelegate);
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getKeypairDelegate",
"()Lchip/devicecontroller/KeypairDelegate;", &getKeypairDelegate);
SuccessOrExit(err);

jmethodID getRootCertificate;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getRootCertificate", PARAMS_CLASS,
&getRootCertificate);
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getRootCertificate", "()[B", &getRootCertificate);
SuccessOrExit(err);

jmethodID getIntermediateCertificate;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIntermediateCertificate", PARAMS_CLASS,
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIntermediateCertificate", "()[B",
&getIntermediateCertificate);
SuccessOrExit(err);

jmethodID getOperationalCertificate;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getOperationalCertificate", PARAMS_CLASS,
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getOperationalCertificate", "()[B",
&getOperationalCertificate);
SuccessOrExit(err);

jmethodID getIpk;
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIpk", PARAMS_CLASS, &getIpk);
err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIpk", "()[B", &getIpk);
SuccessOrExit(err);

{
uint16_t listenPort = env->CallIntMethod(controllerParams, getUdpListenPort);
Expand Down
Loading

0 comments on commit 3c0f2ab

Please sign in to comment.