diff --git a/examples/lit-icd-app/linux/AppOptions.cpp b/examples/lit-icd-app/linux/AppOptions.cpp deleted file mode 100644 index c3f80a2302a484..00000000000000 --- a/examples/lit-icd-app/linux/AppOptions.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AppOptions.h" - -#include -#include - -using chip::ArgParser::OptionDef; -using chip::ArgParser::OptionSet; -using chip::ArgParser::PrintArgError; - -constexpr uint16_t kOptionDacProviderFilePath = 0xFF01; -constexpr uint16_t kOptionMinCommissioningTimeout = 0xFF02; - -static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider; - -bool AppOptions::HandleOptions(const char * program, OptionSet * options, int identifier, const char * name, const char * value) -{ - bool retval = true; - switch (identifier) - { - case kOptionDacProviderFilePath: - mDacProvider.Init(value); - break; - case kOptionMinCommissioningTimeout: { - auto & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager(); - commissionMgr.OverrideMinCommissioningTimeout(chip::System::Clock::Seconds16(static_cast(atoi(value)))); - break; - } - default: - PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", program, name); - retval = false; - break; - } - - return retval; -} - -OptionSet * AppOptions::GetOptions() -{ - static OptionDef optionsDef[] = { - { "dac_provider", chip::ArgParser::kArgumentRequired, kOptionDacProviderFilePath }, - { "min_commissioning_timeout", chip::ArgParser::kArgumentRequired, kOptionMinCommissioningTimeout }, - {}, - }; - - static OptionSet options = { - AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS", - " --dac_provider \n" - " A json file with data used by the example dac provider to validate device attestation procedure.\n" - " --min_commissioning_timeout \n" - " The minimum time in seconds during which commissioning session establishment is allowed by the Node.\n" - }; - - return &options; -} - -chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider() -{ - return &mDacProvider; -} diff --git a/examples/lit-icd-app/linux/AppOptions.h b/examples/lit-icd-app/linux/AppOptions.h deleted file mode 100644 index 3073c66176331f..00000000000000 --- a/examples/lit-icd-app/linux/AppOptions.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "AppMain.h" - -#include - -class AppOptions -{ -public: - static chip::ArgParser::OptionSet * GetOptions(); - static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider(); - -private: - static bool HandleOptions(const char * program, chip::ArgParser::OptionSet * options, int identifier, const char * name, - const char * value); -}; diff --git a/examples/lit-icd-app/linux/BUILD.gn b/examples/lit-icd-app/linux/BUILD.gn index ea25284906df07..ce54d7d4fd906d 100644 --- a/examples/lit-icd-app/linux/BUILD.gn +++ b/examples/lit-icd-app/linux/BUILD.gn @@ -14,95 +14,30 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -import("${build_root}/config/compiler/compiler.gni") -import("${chip_root}/src/lib/lib.gni") -import("${chip_root}/src/platform/device.gni") - -source_set("chip-all-clusters-common") { +executable("chip-lock-app") { sources = [ - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp", - "${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp", - "AppOptions.cpp", - "include/tv-callbacks.cpp", - "include/tv-callbacks.h", - "main-common.cpp", + "main.cpp", + "src/LockAppCommandDelegate.cpp", ] deps = [ - "${chip_root}/examples/all-clusters-minimal-app/all-clusters-common", + "${chip_root}/examples/lock-app/lock-common", + "${chip_root}/examples/lock-app/lock-common:lock-cluster-service", "${chip_root}/examples/platform/linux:app-main", - "${chip_root}/src/app/tests/suites/credentials:dac_provider", "${chip_root}/src/lib", + "${chip_root}/third_party/jsoncpp", ] - include_dirs = - [ "${chip_root}/examples/all-clusters-app/all-clusters-common/include" ] - - cflags = [ "-Wconversion" ] - - if (chip_build_libshell) { - defines = [ "ENABLE_CHIP_SHELL" ] - } -} - -source_set("chip-lock-app-common") { - sources = [ - "${chip_root}/examples/lock-app/lock-common/include/LockEndpoint.h", - "${chip_root}/examples/lock-app/lock-common/include/LockManager.h", - "${chip_root}/examples/lock-app/lock-common/src/LockEndpoint.cpp", - "${chip_root}/examples/lock-app/lock-common/src/LockManager.cpp", - "${chip_root}/examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp", - ] - - deps = - [ "${chip_root}/examples/all-clusters-minimal-app/all-clusters-common" ] - - include_dirs = [ "${chip_root}/examples/lock-app/lock-common/include" ] + include_dirs = [ "include" ] cflags = [ "-Wconversion" ] -} - -executable("chip-all-clusters-minimal-app") { - sources = [ "main.cpp" ] - - deps = [ - ":chip-all-clusters-common", - ":chip-lock-app-common", - "${chip_root}/examples/platform/linux:app-main", - ] - - cflags = [ "-Wconversion" ] - - include_dirs = - [ "${chip_root}/examples/all-clusters-app/all-clusters-common/include" ] output_dir = root_out_dir } -if (chip_device_platform == "darwin") { - action("codesign") { - script = "entitlements/codesign.py" - public_deps = [ ":chip-all-clusters-minimal-app" ] - - args = [ - "--target_path", - rebase_path("${root_build_dir}/chip-all-clusters-minimal-app", - root_build_dir), - "--log_path", - rebase_path("${root_build_dir}/codesign_log.txt", root_build_dir), - ] - - output_name = "codesign_log.txt" - outputs = [ "${root_build_dir}/${output_name}" ] - } -} - group("linux") { - deps = [] - deps += [ ":chip-all-clusters-minimal-app" ] + deps = [ ":chip-lock-app" ] } group("default") { diff --git a/examples/lit-icd-app/linux/Dockerfile b/examples/lit-icd-app/linux/Dockerfile index 697ae5fe2d0087..25ba6f0684c46e 100644 --- a/examples/lit-icd-app/linux/Dockerfile +++ b/examples/lit-icd-app/linux/Dockerfile @@ -17,7 +17,7 @@ from generic_node_image RUN apt-get install -y libglib2.0 -COPY out/debug/chip-all-clusters-minimal-app /usr/bin/ +COPY out/debug/chip-lit-icd-app /usr/bin/ COPY entrypoint.sh / ENTRYPOINT ["/entrypoint.sh", "server"] diff --git a/examples/lit-icd-app/linux/args.gni b/examples/lit-icd-app/linux/args.gni index 8b332edc7e2b06..c8ef0dcc25f68e 100644 --- a/examples/lit-icd-app/linux/args.gni +++ b/examples/lit-icd-app/linux/args.gni @@ -21,7 +21,6 @@ chip_project_config_include = "" chip_system_project_config_include = "" chip_project_config_include_dirs = - [ "${chip_root}/examples/all-clusters-minimal-app/linux/include" ] + [ "${chip_root}/examples/lit-icd-app/linux/include" ] chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] - matter_enable_tracing_support = true diff --git a/examples/lit-icd-app/linux/entitlements/codesign.py b/examples/lit-icd-app/linux/entitlements/codesign.py deleted file mode 100644 index 86a820fcd9884e..00000000000000 --- a/examples/lit-icd-app/linux/entitlements/codesign.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env -S python3 -B - -# 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import argparse -import re -import subprocess - - -def run_command(command): - print("Running {}".format(command)) - return str(subprocess.check_output(command.split())) - - -def get_identity(): - command = "/usr/bin/security find-identity -v -p codesigning" - command_result = run_command(command) - - failure_str = "Error: 0 valid identities found" - if failure_str in command_result: - print( - "No valid identity has been found. Application will run without entitlements.") - exit(0) - - command_result = command_result.replace("\\n", "\n") - identity = re.search(r'\b[0-9a-fA-F]{40}\b(?![^\n]*\(CSSMERR_TP_CERT_EXPIRED\))', command_result) - if identity is None: - print( - "No valid identity has been found. Application will run without entitlements.") - exit(0) - - return identity.group() - - -def codesign(args): - command = "codesign --force -d --sign {identity} {target}".format( - identity=get_identity(), - target=args.target_path) - command_result = run_command(command) - - print("Codesign Result: {}".format(command_result)) - with open(args.log_path, "w") as f: - f.write(command_result) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description='Codesign the binary') - parser.add_argument( - '--log_path', help='Output log file destination', required=True) - parser.add_argument('--target_path', help='Binary to sign', required=True) - - args = parser.parse_args() - codesign(args) diff --git a/examples/lit-icd-app/linux/entrypoint.sh b/examples/lit-icd-app/linux/entrypoint.sh index 0d54ba0a11c681..597d1f2874564a 100755 --- a/examples/lit-icd-app/linux/entrypoint.sh +++ b/examples/lit-icd-app/linux/entrypoint.sh @@ -26,4 +26,4 @@ ot-ctl panid 0x1234 ot-ctl ifconfig up ot-ctl thread start -chip-all-clusters-minimal-app +chip-lit-icd-app diff --git a/examples/lit-icd-app/linux/fuzzing-main.cpp b/examples/lit-icd-app/linux/fuzzing-main.cpp deleted file mode 100644 index b1736826ef335a..00000000000000 --- a/examples/lit-icd-app/linux/fuzzing-main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AppMain.h" -#include - -using namespace chip; -using namespace chip::DeviceLayer; - -void CleanShutdown() -{ - Server::GetInstance().Shutdown(); - PlatformMgr().Shutdown(); - // TODO: We don't Platform::MemoryShutdown because ~CASESessionManager calls - // Dnssd::ResolverProxy::Shutdown, which starts doing Platform::Delete. - // Platform::MemoryShutdown(); -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize) -{ - static bool matterStackInitialized = false; - if (!matterStackInitialized) - { - // Might be simpler to do ChipLinuxAppInit() with argc == 0, argv set to - // just a fake executable name? - VerifyOrDie(Platform::MemoryInit() == CHIP_NO_ERROR); - VerifyOrDie(PlatformMgr().InitChipStack() == CHIP_NO_ERROR); - - // ChipLinuxAppMainLoop blocks, and we don't want that here. - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - VerifyOrDie(Server::GetInstance().Init(initParams) == CHIP_NO_ERROR); - - ApplicationInit(); - - // We don't start the event loop task, because we don't plan to deliver - // data on a separate thread. - - matterStackInitialized = true; - - // The fuzzer does not have a way to tell us when it's done, so just - // shut down things on exit. - atexit(CleanShutdown); - } - - // For now, just dump the data as a UDP payload into the session manager. - // But maybe we should try to separately extract a PeerAddress and data from - // the incoming data? - Transport::PeerAddress peerAddr; - System::PacketBufferHandle buf = - System::PacketBufferHandle::NewWithData(aData, aSize, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0); - if (buf.IsNull()) - { - // Too big; we couldn't represent this as a packetbuffer to start with. - return 0; - } - - // Ignoring the return value from OnMessageReceived, because we might be - // passing it all sorts of garbage that will cause it to fail. - Server::GetInstance().GetSecureSessionManager().OnMessageReceived(peerAddr, std::move(buf)); - - // Now process pending events until our sentinel is reached. - PlatformMgr().ScheduleWork([](intptr_t) { PlatformMgr().StopEventLoopTask(); }); - PlatformMgr().RunEventLoop(); - return 0; -} diff --git a/examples/lit-icd-app/linux/include/tv-callbacks.cpp b/examples/lit-icd-app/linux/include/tv-callbacks.cpp deleted file mode 100644 index 33a8154e9be6d7..00000000000000 --- a/examples/lit-icd-app/linux/include/tv-callbacks.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * Copyright (c) 2021 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/**************************************************************************** - * @file - * @brief Routines for TV stubs - *server stub implementation of TV cluster code. - ******************************************************************************* - ******************************************************************************/ - -#include "tv-callbacks.h" - -bool LowPowerManager::HandleSleep() -{ - return true; -} diff --git a/examples/lit-icd-app/linux/include/tv-callbacks.h b/examples/lit-icd-app/linux/include/tv-callbacks.h deleted file mode 100644 index 1ee3f4264370af..00000000000000 --- a/examples/lit-icd-app/linux/include/tv-callbacks.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * - * Copyright (c) 2021 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/**************************************************************************** - * @file - * @brief Routines for TV stubs - *server stub implementation of TV cluster code. - ******************************************************************************* - ******************************************************************************/ - -#include - -class LowPowerManager : public chip::app::Clusters::LowPower::Delegate -{ -public: - bool HandleSleep() override; -}; diff --git a/examples/lit-icd-app/linux/main-common.cpp b/examples/lit-icd-app/linux/main-common.cpp deleted file mode 100644 index a6fd0a9866220e..00000000000000 --- a/examples/lit-icd-app/linux/main-common.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "include/tv-callbacks.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace chip; -using namespace chip::app; -using namespace chip::DeviceLayer; - -namespace { -static LowPowerManager lowPowerManager; -} // namespace - -void OnIdentifyStart(::Identify *) -{ - ChipLogProgress(Zcl, "OnIdentifyStart"); -} - -void OnIdentifyStop(::Identify *) -{ - ChipLogProgress(Zcl, "OnIdentifyStop"); -} - -void OnTriggerEffect(::Identify * identify) -{ - switch (identify->mCurrentEffectIdentifier) - { - case Clusters::Identify::EffectIdentifierEnum::kBlink: - ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBlink"); - break; - case Clusters::Identify::EffectIdentifierEnum::kBreathe: - ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBreathe"); - break; - case Clusters::Identify::EffectIdentifierEnum::kOkay: - ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kOkay"); - break; - case Clusters::Identify::EffectIdentifierEnum::kChannelChange: - ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kChannelChange"); - break; - default: - ChipLogProgress(Zcl, "No identifier effect"); - return; - } -} - -static Identify gIdentify0 = { - chip::EndpointId{ 0 }, OnIdentifyStart, OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator, - OnTriggerEffect, -}; - -static Identify gIdentify1 = { - chip::EndpointId{ 1 }, OnIdentifyStart, OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator, - OnTriggerEffect, -}; - -void ApplicationInit() {} - -void ApplicationShutdown() {} - -void emberAfLowPowerClusterInitCallback(EndpointId endpoint) -{ - ChipLogProgress(Zcl, "TV Linux App: LowPower::SetDefaultDelegate"); - chip::app::Clusters::LowPower::SetDefaultDelegate(endpoint, &lowPowerManager); -} diff --git a/examples/lit-icd-app/linux/main.cpp b/examples/lit-icd-app/linux/main.cpp index 766a5820d0eed3..8019498a84521e 100644 --- a/examples/lit-icd-app/linux/main.cpp +++ b/examples/lit-icd-app/linux/main.cpp @@ -17,22 +17,22 @@ */ #include "AppMain.h" -#include "AppOptions.h" -#include "binding-handler.h" +#include -// Network commissioning -namespace { -constexpr chip::EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE; -} // anonymous namespace +using namespace chip; +using namespace chip::app; + +void ApplicationShutdown() {} int main(int argc, char * argv[]) { - VerifyOrDie( - ChipLinuxAppInit(argc, argv, AppOptions::GetOptions(), chip::MakeOptional(kNetworkCommissioningEndpointSecondary)) == 0); - VerifyOrDie(InitBindingHandlers() == CHIP_NO_ERROR); - - LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider(); - + VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); ChipLinuxAppMainLoop(); return 0; } + +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, + uint8_t * value) +{ + // TODO: Watch ICDM Cluster changes +}