Skip to content

Commit

Permalink
Merge branch 'master' into case-eviction-final
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjerryjohns committed Jun 17, 2022
2 parents 20763ca + 147cab2 commit 4394802
Show file tree
Hide file tree
Showing 46 changed files with 2,835 additions and 3,156 deletions.
6 changes: 5 additions & 1 deletion examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ def main(argv: Sequence[str]) -> None:
#

if options.do_build:
branch = shell.run_cmd(
"git branch | awk -v FS=' ' '/\*/{print $NF}' | sed 's|[()]||g'", return_cmd_output=True).replace("\n", "")
commit_id = shell.run_cmd("git rev-parse HEAD", return_cmd_output=True).replace("\n", "")

if options.use_zzz:
flush_print("Using pre-generated ZAP output")
zzz_dir = os.path.join(_CHEF_SCRIPT_PATH,
Expand Down Expand Up @@ -574,7 +578,7 @@ def main(argv: Sequence[str]) -> None:
chip_shell_cmd_server = false
chip_build_libshell = true
chip_config_network_layer_ble = false
target_defines = ["CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID={options.vid}", "CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID={options.pid}", "CONFIG_ENABLE_PW_RPC={'1' if options.do_rpc else '0'}"]
target_defines = ["CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID={options.vid}", "CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID={options.pid}", "CONFIG_ENABLE_PW_RPC={'1' if options.do_rpc else '0'}", "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\\"{branch}:{commit_id}\\""]
"""))
with open(f"{_CHEF_SCRIPT_PATH}/linux/sample.gni", "w") as f:
f.write(textwrap.dedent(f"""\
Expand Down
12 changes: 8 additions & 4 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static_library("chip-tool-utils") {
"commands/pairing/CloseSessionCommand.h",
"commands/pairing/OpenCommissioningWindowCommand.cpp",
"commands/pairing/OpenCommissioningWindowCommand.h",
"commands/pairing/PairingCommand.cpp",
"commands/payload/AdditionalDataParseCommand.cpp",
"commands/payload/SetupPayloadGenerateCommand.cpp",
"commands/payload/SetupPayloadParseCommand.cpp",
Expand All @@ -95,7 +94,6 @@ static_library("chip-tool-utils") {
"${chip_root}/src/app/tests/suites/commands/log",
"${chip_root}/src/app/tests/suites/commands/system",
"${chip_root}/src/app/tests/suites/pics",
"${chip_root}/src/controller/data_model",
"${chip_root}/src/credentials:file_attestation_trust_store",
"${chip_root}/src/lib",
"${chip_root}/src/platform",
Expand All @@ -114,9 +112,15 @@ static_library("chip-tool-utils") {
}

executable("chip-tool") {
sources = [ "main.cpp" ]
sources = [
"commands/pairing/PairingCommand.cpp",
"main.cpp",
]

deps = [ ":chip-tool-utils" ]
deps = [
":chip-tool-utils",
"${chip_root}/src/controller/data_model",
]

output_dir = root_out_dir
}
Expand Down
6 changes: 6 additions & 0 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ config("config") {
include_dirs = [
".",
"${chip_root}/zzz_generated/darwin-framework-tool",
"${chip_root}/zzz_generated/controller-clusters",
"${chip_root}/examples/chip-tool/commands/clusters/ComplexArgument.h",
]

Expand All @@ -44,6 +45,11 @@ config("config") {

executable("darwin-framework-tool") {
sources = [
# We have to include privilege-storage.cpp here, not in the "Darwin
# framework" library, because otherwise the weak symbols from
# RequiredPrivilege.cpp mean we never actually pull in the function from
# privilege-storage.cpp.
"${chip_root}/src/app/util/privilege-storage.cpp",
"${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp",
"commands/clusters/ClusterCommandBridge.h",
"commands/clusters/ModelCommandBridge.mm",
Expand Down
3 changes: 2 additions & 1 deletion examples/ota-requestor-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/network-commissioning"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common"
)
Expand Down
14 changes: 13 additions & 1 deletion examples/ota-requestor-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#include "nvs_flash.h"
#include <common/CHIPDeviceManager.h>
#include <common/Esp32AppServer.h>

#include <lib/support/ErrorStr.h>
#include <ota/OTAHelper.h>
#include <shell_extension/launch.h>

#include "OTAImageProcessorImpl.h"

Expand All @@ -41,14 +42,20 @@
using namespace ::chip;
using namespace ::chip::System;
using namespace ::chip::DeviceManager;
using namespace chip::Shell;

namespace {
const char * TAG = "ota-requester-app";
static AppDeviceCallbacks EchoCallbacks;

constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

static void InitServer(intptr_t context)
{
Esp32AppServer::Init(); // Init ZCL Data Model and CHIP App Server AND Initialize device attestation config

// We only have network commissioning on endpoint 0.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
}

} // namespace
Expand Down Expand Up @@ -80,6 +87,11 @@ extern "C" void app_main()
return;
}

#if CONFIG_ENABLE_CHIP_SHELL
chip::LaunchShell();
OTARequestorCommands::GetInstance().Register();
#endif // CONFIG_ENABLE_CHIP_SHELL

CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();

CHIP_ERROR error = deviceMgr.Init(&EchoCallbacks);
Expand Down
3 changes: 3 additions & 0 deletions examples/ota-requestor-app/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
# Enable OTA Requestor
CONFIG_ENABLE_OTA_REQUESTOR=y
CONFIG_DEVICE_SOFTWARE_VERSION_NUMBER=2

# Enable Chip Shell
CONFIG_ENABLE_CHIP_SHELL=y
114 changes: 112 additions & 2 deletions examples/platform/esp32/ota/OTAHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,43 @@

#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
#include <platform/ESP32/OTAImageProcessorImpl.h>
#include <system/SystemEvent.h>

#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h>
#include <lib/shell/Commands.h>
#include <lib/shell/Engine.h>
#include <lib/shell/commands/Help.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip::DeviceLayer;
using namespace chip;

class CustomOTARequestorDriver : public DeviceLayer::ExtendedOTARequestorDriver
{
public:
bool CanConsent() override;
};

namespace {
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
DefaultOTARequestorDriver gRequestorUser;
CustomOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
chip::Optional<bool> gRequestorCanConsent;
static chip::ota::UserConsentState gUserConsentState = chip::ota::UserConsentState::kUnknown;
chip::ota::DefaultOTARequestorUserConsent gUserConsentProvider;

} // namespace

bool CustomOTARequestorDriver::CanConsent()
{
return gRequestorCanConsent.ValueOr(DeviceLayer::ExtendedOTARequestorDriver::CanConsent());
}

static void InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
SetRequestorInstance(&gRequestorCore);
Expand All @@ -43,10 +64,99 @@ static void InitOTARequestorHandler(System::Layer * systemLayer, void * appState
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

if (gUserConsentState != chip::ota::UserConsentState::kUnknown)
{
gUserConsentProvider.SetUserConsentState(gUserConsentState);
gRequestorUser.SetUserConsentDelegate(&gUserConsentProvider);
}
}

void OTAHelpers::InitOTARequestor()
{
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler,
nullptr);
}

namespace chip {
namespace Shell {
namespace {

Shell::Engine sSubShell;

CHIP_ERROR UserConsentStateHandler(int argc, char ** argv)
{
VerifyOrReturnError(argc == 1, CHIP_ERROR_INVALID_ARGUMENT);

if (strcmp(argv[0], "granted") == 0)
{
gUserConsentState = chip::ota::UserConsentState::kGranted;
}
else if (strcmp(argv[0], "denied") == 0)
{
gUserConsentState = chip::ota::UserConsentState::kDenied;
}
else if (strcmp(argv[0], "deferred") == 0)
{
gUserConsentState = chip::ota::UserConsentState::kObtaining;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR RequestorCanConsentHandler(int argc, char ** argv)
{
VerifyOrReturnError(argc == 1, CHIP_ERROR_INVALID_ARGUMENT);

if (strcmp(argv[0], "true") == 0)
{
gRequestorCanConsent.SetValue(true);
}
else if (strcmp(argv[0], "false") == 0)
{
gRequestorCanConsent.SetValue(false);
}
return CHIP_NO_ERROR;
}

CHIP_ERROR OTARequestorHandler(int argc, char ** argv)
{
if (argc == 0)
{
sSubShell.ForEachCommand(PrintCommandHelp, nullptr);
return CHIP_NO_ERROR;
}

CHIP_ERROR error = sSubShell.ExecCommand(argc, argv);

if (error != CHIP_NO_ERROR)
{
streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", error.Format());
}

return error;
}
} // namespace

void OTARequestorCommands::Register()
{
// Register subcommands of the `OTARequestor` commands.
static const shell_command_t subCommands[] = {
{ &UserConsentStateHandler, "userConsentState",
"Set UserConsentState for QueryImageCommand\n"
"Usage: OTARequestor userConsentState <granted/denied/deferred>" },
{ &RequestorCanConsentHandler, "requestorCanConsent",
"Set requestorCanConsent for QueryImageCommand\n"
"Usage: OTARequestor requestorCanConsent <true/false>" },

};

sSubShell.RegisterCommands(subCommands, ArraySize(subCommands));

// Register the root `OTA Requestor` command in the top-level shell.
static const shell_command_t otaRequestorCommand = { &OTARequestorHandler, "OTARequestor", "OTA Requestor commands" };

Engine::Root().RegisterCommands(&otaRequestorCommand, 1);
}

} // namespace Shell
} // namespace chip
31 changes: 31 additions & 0 deletions examples/platform/esp32/ota/OTAHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <stdint.h>
class OTAHelpers
{
Expand All @@ -26,3 +28,32 @@ class OTAHelpers
static constexpr uint32_t kInitOTARequestorDelaySec = 3;
void InitOTARequestor(void);
};

namespace chip {
namespace Shell {

class OTARequestorCommands
{
public:
// delete the copy constructor
OTARequestorCommands(const OTARequestorCommands &) = delete;
// delete the move constructor
OTARequestorCommands(OTARequestorCommands &&) = delete;
// delete the assignment operator
OTARequestorCommands & operator=(const OTARequestorCommands &) = delete;

static OTARequestorCommands & GetInstance()
{
static OTARequestorCommands instance;
return instance;
}

// Register the OTA requestor commands
void Register();

private:
OTARequestorCommands() {}
};

} // namespace Shell
} // namespace chip
26 changes: 8 additions & 18 deletions examples/platform/nrfconnect/util/PigweedLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,17 @@ void init(const log_backend *)
pw_sys_io_Init();
}

void putMessageSync(const log_backend *, log_msg_ids srcLevel, uint32_t timestamp, const char * fmt, va_list args)
void processMessage(const struct log_backend * const backend, union log_msg2_generic * msg)
{
int ret = k_sem_take(&sLoggerLock, K_FOREVER);
assert(ret == 0);

if (!sIsPanicMode)
log_backend_std_sync_string(&pigweedLogOutput, 0, srcLevel, timestamp, fmt, args);

k_sem_give(&sLoggerLock);
}

void putHexdumpSync(const log_backend *, log_msg_ids srcLevel, uint32_t timestamp, const char * metadata, const uint8_t * data,
uint32_t length)
{
int ret = k_sem_take(&sLoggerLock, K_FOREVER);
assert(ret == 0);
{
log_format_func_t outputFunc = log_format_func_t_get(LOG_OUTPUT_TEXT);

if (!sIsPanicMode)
log_backend_std_sync_hexdump(&pigweedLogOutput, 0, srcLevel, timestamp, metadata, data, length);
outputFunc(&pigweedLogOutput, &msg->log, log_backend_std_get_flags());
}

k_sem_give(&sLoggerLock);
}
Expand All @@ -134,11 +126,9 @@ void panic(const log_backend *)
}

const log_backend_api pigweedLogApi = {
.put = nullptr,
.put_sync_string = putMessageSync,
.put_sync_hexdump = putHexdumpSync,
.panic = panic,
.init = init,
.process = processMessage,
.panic = panic,
.init = init,
};

LOG_BACKEND_DEFINE(pigweedLogBackend, pigweedLogApi, /* autostart */ true);
Expand Down
Loading

0 comments on commit 4394802

Please sign in to comment.