diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ad808d72571692..0b185ee22518d1 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -18,7 +18,7 @@ RUN apt-get -fy install git vim emacs sudo \ iproute2 procps lsb-release \ bash-completion \ build-essential cmake cppcheck valgrind \ - wget curl telnet bsdtar \ + wget curl telnet \ docker.io RUN groupadd -g $USER_GID $USERNAME RUN useradd -s /bin/bash -u $USER_UID -g $USER_GID -G docker -m $USERNAME @@ -27,7 +27,8 @@ RUN chmod 0440 /etc/sudoers.d/$USERNAME RUN mkdir -p /var/downloads RUN cd /var/downloads -RUN curl -JL https://github.com/microsoft/vscode-cpptools/releases/download/0.27.0/cpptools-linux.vsix | bsdtar -xvf - extension +RUN curl -JL https://github.com/microsoft/vscode-cpptools/releases/download/0.27.0/cpptools-linux.vsix > extension.zip +RUN unzip extension.zip RUN mkdir -p /home/$USERNAME/.vscode-server/extensions RUN mv extension /home/$USERNAME/.vscode-server/extensions/ms-vscode.cpptools-0.27.0 RUN mkdir -p /home/$USERNAME/bin diff --git a/.github/workflows/bloat_check.yaml b/.github/workflows/bloat_check.yaml index b60b0c4a6309ca..94e790233a1179 100644 --- a/.github/workflows/bloat_check.yaml +++ b/.github/workflows/bloat_check.yaml @@ -1,7 +1,7 @@ name: Bloat Check on: schedule: - - cron: '*/10 * * * *' + - cron: '*/5 * * * *' jobs: @@ -11,9 +11,12 @@ jobs: runs-on: ubuntu-latest container: - image: "connectedhomeip/chip-build-openssl:0.2.18" + image: connectedhomeip/chip-build:0.3.0 steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Report run: | scripts/helpers/bloat_check.py \ diff --git a/.github/workflows/gn_examples.yaml b/.github/workflows/gn_examples.yaml index 2c34f50fa3db05..971208233c61c0 100644 --- a/.github/workflows/gn_examples.yaml +++ b/.github/workflows/gn_examples.yaml @@ -9,7 +9,7 @@ jobs: name: nRF env: - BUILD_TYPE: nrf + BUILD_TYPE: gn_nrf BUILD_VERSION: 0.2.14 BUILD_IMAGE: chip-build-nrf-platform BUILD_ORG: connectedhomeip @@ -33,18 +33,26 @@ jobs: run: scripts/examples/gn_nrf_example.sh examples/lock-app/nrf5 out/lock_app_debug - name: Build example nRF5 Lighting App run: scripts/examples/gn_nrf_example.sh examples/lighting-app/nrf5 out/lighting_app_debug - - name: Preserve artifacts - run: | - mkdir -p example_binaries/nrf-build - cp out/lock_app_debug/chip-nrf52840-lock-example \ - out/lighting_app_debug/chip-nrf52840-lighting-example \ - example_binaries/nrf-build/ + - name: Binary artifact suffix + id: outsuffix + uses: haya14busa/action-cond@v1.0.0 + with: + cond: ${{ github.event.pull_request.number == '' }} + if_true: "${{ github.sha }}" + if_false: "pull-${{ github.event.pull_request.number }}" + - name: Uploading Binaries + uses: actions/upload-artifact@v2 + with: + name: ${{ env.BUILD_TYPE }}-example-build-${{ steps.outsuffix.outputs.value }} + path: | + out/lock_app_debug/chip-nrf52840-lock-example + out/lighting_app_debug/chip-nrf52840-lighting-example linux-standalone: name: Linux Standalone env: - BUILD_TYPE: linux + BUILD_TYPE: gn_linux BUILD_VERSION: 0.2.14 BUILD_IMAGE: chip-build BUILD_ORG: connectedhomeip @@ -68,9 +76,17 @@ jobs: run: scripts/examples/gn_build_example.sh examples/chip-tool out/chip_tool_debug - name: Build example Standalone Shell run: scripts/examples/gn_build_example.sh examples/shell out/shell_debug - - name: Preserve artifacts - run: | - mkdir -p example_binaries/$BUILD_TYPE - cp out/chip_tool_debug/bin/chip-standalone-demo \ - out/shell_debug/bin/chip-shell \ - example_binaries/$BUILD_TYPE/ + - name: Binary artifact suffix + id: outsuffix + uses: haya14busa/action-cond@v1.0.0 + with: + cond: ${{ github.event.pull_request.number == '' }} + if_true: "${{ github.sha }}" + if_false: "pull-${{ github.event.pull_request.number }}" + - name: Uploading Binaries + uses: actions/upload-artifact@v2 + with: + name: ${{ env.BUILD_TYPE }}-example-build-${{ steps.outsuffix.outputs.value }} + path: | + out/chip_tool_debug/chip-standalone-demo + out/shell_debug/chip-shell diff --git a/.gitmodules b/.gitmodules index dc76d02b80f28b..dfcf6fa17a7326 100644 --- a/.gitmodules +++ b/.gitmodules @@ -39,22 +39,22 @@ url = https://github.com/jeremyjh/ESP32_TFT_library.git branch = master ignore = dirty - commit = 35be9760b4edf485287f78c0cf652beb19c047f0 + commit = 42cadf2de25fa7e9b5d5d5189e90756cf9938df2 [submodule "pigweed"] path = third_party/pigweed/repo url = https://pigweed.googlesource.com/pigweed/pigweed branch = master ignore = dirty - commit = 023f35bab59c73c498377d1be1b4e60534ce7b20 + commit = ce87bc01d82d813506ece5122250a1b909d78e68 [submodule "openthread"] path = third_party/openthread/repo url = https://github.com/openthread/openthread.git branch = master ignore = dirty - commit = 5f0e36eeb236a507631e9c822e43f742b7b6738a + commit = c6d5c4aae0ff9f891ec9f734f6b44598e569c48d [submodule "ot-br-posix"] path = third_party/ot-br-posix/repo url = https://github.com/openthread/ot-br-posix.git branch = master ignore = dirty - commit = 38e91052d1fb12a55c4e34073f9e399471650b4b + commit = 250c6d605b83910f86fa61fcdbde9ba67dcc7d93 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0cd88daedb8a84..3b1154935e33b5 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -17,6 +17,21 @@ }, "problemMatcher": ["$gcc"] }, + { + "label": "GN Build", + "type": "shell", + "command": "./gn_build.sh", + "group": { + "kind": "build", + "isDefault": true + }, + "isBackground": false, + "presentation": { + "reveal": "always", + "panel": "shared" + }, + "problemMatcher": ["$gcc"] + }, { "label": "Auto-enforce coding style", "type": "shell", diff --git a/BUILD.gn b/BUILD.gn index d389987140676e..51108f295081ed 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -40,6 +40,7 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { "${chip_root}/src/inet", "${chip_root}/src/lib", "${chip_root}/src/lib/core", + "${chip_root}/src/lib/datamodel", "${chip_root}/src/lib/shell", "${chip_root}/src/lib/support", "${chip_root}/src/lwip:all", @@ -59,6 +60,7 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { deps += [ "${chip_root}/src/qrcodetool", "${chip_root}/src/setup_payload", + "${chip_root}/examples/shell", ] } } @@ -73,6 +75,7 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { "${chip_root}/src/crypto/tests", "${chip_root}/src/inet/tests", "${chip_root}/src/lib/core/tests", + "${chip_root}/src/lib/datamodel/tests", "${chip_root}/src/lib/support/tests", "${chip_root}/src/lwip/tests", "${chip_root}/src/platform/tests", @@ -104,8 +107,11 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { # Enable building chip with gcc. enable_host_gcc_build = enable_default_builds - # Build building chip with gcc & mbedtls. - enable_host_gcc_mbdtls_build = enable_default_builds + # Enable building chip with gcc & mbedtls. + enable_host_gcc_mbedtls_build = enable_default_builds + + # Enable building chip for linux embedded. + enable_linux_embedded_build = enable_default_builds && host_os == "linux" # Build the chip-tool example. enable_standalone_chip_tool_build = enable_default_builds @@ -132,6 +138,13 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { toolchain = "${chip_root}/config/mbedtls/toolchain:${host_os}_${host_cpu}_gcc_mbedtls" } + if (host_os == "linux") { + chip_build("linux_embedded") { + toolchain = + "${chip_root}/config/linux/toolchain:linux_${host_cpu}_gcc_embedded" + } + } + standalone_toolchain = "${chip_root}/config/standalone/toolchain:standalone" group("standalone_chip_tool") { @@ -162,9 +175,12 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { if (enable_host_gcc_build) { deps += [ ":all_host_gcc" ] } - if (enable_host_gcc_mbdtls_build) { + if (enable_host_gcc_mbedtls_build) { deps += [ ":all_host_gcc_mbedtls" ] } + if (enable_linux_embedded_build) { + deps += [ ":all_linux_embedded" ] + } if (enable_standalone_chip_tool_build) { deps += [ ":standalone_chip_tool" ] } @@ -188,9 +204,12 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { if (enable_host_gcc_build) { deps += [ ":check_host_gcc" ] } - if (enable_host_gcc_mbdtls_build) { + if (enable_host_gcc_mbedtls_build) { deps += [ ":check_host_gcc_mbedtls" ] } + if (enable_linux_embedded_build) { + deps += [ ":check_linux_embedded" ] + } } } } diff --git a/config/efr32/efr32-app.mk b/config/efr32/efr32-app.mk index 81bd2fe4cccd37..b745493fc884a8 100644 --- a/config/efr32/efr32-app.mk +++ b/config/efr32/efr32-app.mk @@ -122,7 +122,8 @@ EXTRA_SRCS += \ $(EFR32_SDK_ROOT)/util/third_party/segger/systemview/SEGGER/SEGGER_RTT.c STD_INC_DIRS += \ - $(CHIP_ROOT)/src/include/platform/EFR32 \ + $(CHIP_ROOT)/src/include/platform \ + $(CHIP_ROOT)/src/platform/EFR32 \ $(FREERTOS_ROOT)/Source/include \ $(FREERTOS_ROOT)/Source/portable/GCC/ARM_CM3 \ $(EFR32_SDK_ROOT) \ @@ -252,13 +253,15 @@ ifeq ($(EFR32FAMILY), efr32mg12) STD_LIBS += \ $(EFR32_SDK_ROOT)/protocol/bluetooth/lib/EFR32MG12P/GCC/libbluetooth.a \ $(EFR32_SDK_ROOT)/platform/radio/rail_lib/autogen/librail_release/librail_multiprotocol_efr32xg12_gcc_release.a \ - $(EFR32_SDK_ROOT)/platform/emdrv/nvm3/lib/libnvm3_CM4_gcc.a + $(EFR32_SDK_ROOT)/platform/emdrv/nvm3/lib/libnvm3_CM4_gcc.a \ + $(EFR32_SDK_ROOT)/protocol/bluetooth/lib/EFR32MG12P/GCC/libmbedtls.a else ifeq ($(EFR32FAMILY), efr32mg21) STD_LIBS += \ $(EFR32_SDK_ROOT)/protocol/bluetooth/lib/EFR32MG21/GCC/libbluetooth.a \ $(EFR32_SDK_ROOT)/platform/radio/rail_lib/autogen/librail_release/librail_multiprotocol_efr32xg21_gcc_release.a \ - $(EFR32_SDK_ROOT)/platform/emdrv/nvm3/lib/libnvm3_CM33_gcc.a + $(EFR32_SDK_ROOT)/platform/emdrv/nvm3/lib/libnvm3_CM33_gcc.a \ + $(EFR32_SDK_ROOT)/protocol/bluetooth/lib/EFR32MG21/GCC/libmbedtls.a endif endif diff --git a/config/linux/toolchain/BUILD.gn b/config/linux/toolchain/BUILD.gn new file mode 100644 index 00000000000000..c77a89f01e66e9 --- /dev/null +++ b/config/linux/toolchain/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2020 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("//build_overrides/chip.gni") + +import("//build/toolchain/gcc_toolchain.gni") + +gcc_toolchain("linux_${host_cpu}_gcc_embedded") { + toolchain_args = { + current_os = "linux" + current_cpu = host_cpu + is_clang = false + import("${chip_root}/src/platform/Linux/args.gni") + } +} diff --git a/config/nrf5/nrf5-chip.mk b/config/nrf5/nrf5-chip.mk index 8abc89e69daeb3..38ea27e1bf232d 100644 --- a/config/nrf5/nrf5-chip.mk +++ b/config/nrf5/nrf5-chip.mk @@ -109,7 +109,7 @@ CHIP_CONFIGURE_OPTIONS = \ --with-chip-ble-project-includes=$(CHIP_PROJECT_CONFIG) \ --with-chip-warm-project-includes=$(CHIP_PROJECT_CONFIG) \ --with-chip-device-project-includes=$(CHIP_PROJECT_CONFIG) \ - --with-openthread=$(NRF5_SDK_ROOT)/external/openthread \ + --with-openthread=internal \ --disable-ipv4 \ --disable-tests \ --disable-tools \ diff --git a/config/standalone/args.gni b/config/standalone/args.gni index 162d52f203c3e5..4b2640923ea6eb 100644 --- a/config/standalone/args.gni +++ b/config/standalone/args.gni @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Options from standalone-chip.mk that differ from configure defaults. These +# options are used from examples/. chip_build_tests = false - config_network_layer_ble = false -inet_config_enable_async_dns_sockets = false - -project_config_include_dirs = rebase_path([ "." ]) -chip_project_config_include = "" -system_project_config_include = "" +inet_config_enable_tun_endpoint = false +inet_config_enable_raw_endpoint = false +inet_config_enable_dns_resolver = false diff --git a/config/standalone/standalone-chip.mk b/config/standalone/standalone-chip.mk index e189f64736764f..17daab73a69299 100644 --- a/config/standalone/standalone-chip.mk +++ b/config/standalone/standalone-chip.mk @@ -58,10 +58,10 @@ CHIP_OUTPUT_DIR = $(OUTPUT_DIR)/chip # An optional file containing application-specific configuration overrides. CHIP_PROJECT_CONFIG = $(wildcard $(PROJECT_ROOT)/include/CHIPProjectConfig.h) -# Architcture on which CHIP is being built. +# Architecture on which CHIP is being built. CHIP_BUILD_ARCH = $(shell $(CHIP_ROOT)/third_party/nlbuild-autotools/repo/third_party/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g') -# Archtecture for which CHIP will be built. +# Architecture for which CHIP will be built. CHIP_HOST_ARCH := $(CHIP_BUILD_ARCH) @@ -135,12 +135,18 @@ STD_LDFLAGS += -L$(CHIP_OUTPUT_DIR)/lib # Add CHIP libraries to standard libraries list. STD_LIBS += \ -lCHIP \ + -lDeviceLayer \ -lInetLayer \ -lnlfaultinjection \ -lSystemLayer STD_LIBS += $(shell pkg-config --libs openssl) +ifeq ($(findstring linux,$(CHIP_HOST_ARCH)),linux) +STD_LIBS += $(shell pkg-config --libs gio-2.0) +STD_CFLAGS += $(shell pkg-config --cflags gio-2.0) +endif + # Add the appropriate CHIP target as a prerequisite to all application # compilation targets to ensure that CHIP gets built and its header # files installed prior to compiling any dependent source files. @@ -149,6 +155,7 @@ STD_COMPILE_PREREQUISITES += install-chip # Add the CHIP libraries as prerequisites for linking the application. STD_LINK_PREREQUISITES += \ $(CHIP_OUTPUT_DIR)/lib/libCHIP.a \ + $(CHIP_OUTPUT_DIR)/lib/libDeviceLayer.a \ $(CHIP_OUTPUT_DIR)/lib/libInetLayer.a \ $(CHIP_OUTPUT_DIR)/lib/libnlfaultinjection.a \ $(CHIP_OUTPUT_DIR)/lib/libSystemLayer.a diff --git a/configure.ac b/configure.ac index b48c5c0761fa09..8eb7f16898bae5 100644 --- a/configure.ac +++ b/configure.ac @@ -904,36 +904,6 @@ NL_ENABLE_DOCS([auto],[NO]) AM_CONDITIONAL(CHIP_BUILD_DOCS, [test "${nl_cv_build_docs}" = "yes"]) -# -# OpenThread -# - -NL_WITH_OPTIONAL_INTERNAL_PACKAGE( - [OpenThread], - [OPENTHREAD], - [openthread], - [], - [ - AC_MSG_NOTICE([No internal OpenThread support yet!]) - with_openthread=no - ], - [ - # Check for required OpenThread headers. - AC_CHECK_HEADERS([openthread/dataset.h] [openthread/dataset_ftd.h] [openthread/error.h] [openthread/icmp6.h] [openthread/instance.h] [openthread/ip6.h] [openthread/link.h] [openthread/message.h] [openthread/netdata.h] [openthread/tasklet.h] [openthread/thread.h], - [], - [ - AC_MSG_ERROR(The nlio header "$ac_header" is required but cannot be found.) - ]) - ] -) -AM_CONDITIONAL([CHIP_ENABLE_OPENTHREAD], [test "${with_openthread}" != "no"]) -if test "${with_openthread}" != "no"; then - CHIP_ENABLE_OPENTHREAD=1 -else - CHIP_ENABLE_OPENTHREAD=0 -fi -AC_DEFINE_UNQUOTED([CHIP_ENABLE_OPENTHREAD],[${CHIP_ENABLE_OPENTHREAD}],[Define to 1 if you want to enable OpenThread.]) - # # Network Technology Layer # @@ -996,11 +966,11 @@ AC_DEFINE_UNQUOTED([CONFIG_NETWORK_LAYER_INET],[${CONFIG_NETWORK_LAYER_INET}],[D AC_MSG_CHECKING([device layer]) AC_ARG_WITH(device-layer, [AS_HELP_STRING([--with-device-layer=LAYER], - [Specify the target environment for the CHIP Device Layer. Choose one of: darwin, efr32, esp32, nrf5, linux, or none @<:@default=none@:>@.])], + [Specify the target environment for the CHIP Device Layer. Choose one of: auto, darwin, efr32, esp32, nrf5, linux, or none @<:@default=auto@:>@.])], [ case "${with_device_layer}" in - darwin|efr32|esp32|nrf5|linux|none) + auto|darwin|efr32|esp32|nrf5|linux|none) ;; *) @@ -1009,7 +979,7 @@ AC_ARG_WITH(device-layer, esac ], - [with_device_layer=none]) + [with_device_layer=auto]) AC_MSG_RESULT(${with_device_layer}) # Disable all device layer targets by default @@ -1019,6 +989,24 @@ CHIP_DEVICE_LAYER_TARGET_ESP32=0 CHIP_DEVICE_LAYER_TARGET_NRF5=0 CHIP_DEVICE_LAYER_TARGET_LINUX=0 +if test "${with_device_layer}" = "auto"; then + case ${target_os} in + + *darwin*) + with_device_layer=darwin + ;; + + *linux*) + with_device_layer=linux + ;; + + *) + with_device_layer=none + ;; + + esac +fi + case "${with_device_layer}" in darwin) @@ -1043,6 +1031,8 @@ nrf5) CONFIG_DEVICE_LAYER=1 CHIP_DEVICE_LAYER_TARGET=nRF5 CHIP_DEVICE_LAYER_TARGET_NRF5=1 + CFLAGS="${CFLAGS} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -mabi=aapcs" + CXXFLAGS="${CXXFLAGS} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -mabi=aapcs" ;; linux) @@ -1541,7 +1531,7 @@ fi AM_CONDITIONAL([CHIP_WITH_OPENSSL], [test "${nl_with_openssl}" != "no"]) if test "${nl_with_openssl}" = "no"; then - AC_DEFINE([CHIP_WITH_OPENSSL], [0], [Define to 1 to build CHIP with OpenSSL]) + AC_DEFINE([CHIP_WITH_OPENSSL], [0], [Define to 0 to build CHIP without OpenSSL]) else AC_DEFINE([CHIP_WITH_OPENSSL], [1], [Define to 1 to build CHIP with OpenSSL]) fi @@ -1611,11 +1601,111 @@ AM_CONDITIONAL([CHIP_WITH_MBEDTLS_INTERNAL], [test "${nl_with_mbedtls}" = "inter AM_CONDITIONAL([CHIP_WITH_MBEDTLS], [test "${nl_with_mbedtls}" != "no"]) if test "${nl_with_mbedtls}" = "no"; then - AC_DEFINE([CHIP_WITH_MBEDTLS], [0], [Define to 1 to build CHIP with mbedTLS]) + AC_DEFINE([CHIP_WITH_MBEDTLS], [0], [Define to 0 to build CHIP without mbedTLS]) else AC_DEFINE([CHIP_WITH_MBEDTLS], [1], [Define to 1 to build CHIP with mbedTLS]) fi +# +# OpenThread +# + +NL_WITH_OPTIONAL_INTERNAL_PACKAGE( + [OpenThread], + [OPENTHREAD], + [openthread], + [], + [ + # use absolute path to support build out of source tree + chip_srcdir="$(cd ${srcdir} && pwd)" + + # bootstrap + test -f ${chip_srcdir}/third_party/openthread/repo/configure || (cd ${chip_srcdir}/third_party/openthread/repo && ./bootstrap) + + case "${with_device_layer}" in + nrf5) + OPENTHREAD_CPPFLAGS="-I\${abs_top_srcdir}/third_party/openthread/repo/include" + OPENTHREAD_LDFLAGS="-L${ac_pwd}/third_party/openthread" + OPENTHREAD_LIBS="-lopenthread-cli-ftd \ + -lopenthread-ftd \ + -lopenthread-platform-utils \ + -lopenthread-nrf52840-transport \ + -lopenthread-nrf52840-softdevice-sdk \ + -lnordicsemi-nrf52840-radio-driver-softdevice \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_cc310_backend.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedcrypto_vanilla_backend.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedtls_base_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ + \${NRF5_SDK_ROOT}/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a" + + # private definitions + ot_cppflags="-Wno-expansion-to-defined \ + -I${chip_srcdir}/third_party/openthread/repo/examples/platforms/nrf528xx/nrf52840 \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/config \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/include \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/mbedtls_plat_config \ + -I${chip_srcdir}/third_party/openthread/repo/third_party/NordicSemiconductor/libraries/nrf_security/nrf_cc310_plat/include \ + -I${chip_srcdir}/third_party/mbedtls/repo/include \ + -DMBEDTLS_CONFIG_FILE=\ \ + -DMBEDTLS_USER_CONFIG_FILE=\ \ + -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\ \ + -DOPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\ \ + -DOPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE=1 \ + -DOPENTHREAD_CONFIG_JOINER_ENABLE=1 \ + -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1 \ + -DUART_AS_SERIAL_TRANSPORT=1" + + (mkdir -p ${ac_pwd}/third_party/openthread \ + && cd ${ac_pwd}/third_party/openthread \ + && CPPFLAGS="${ot_cppflags}" CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" ${chip_srcdir}/third_party/openthread/repo/configure \ + --disable-builtin-mbedtls \ + --disable-docs \ + --disable-executable \ + --disable-tools \ + --enable-cli \ + --enable-ftd \ + --host=arm-none-eabi \ + --prefix=${prefix} \ + --exec-prefix=${exec_prefix} \ + --with-examples=nrf52840) + + if test $? != 0; then + AC_MSG_ERROR([Failed to configure OpenThread!]) + fi + + maybe_openthread_dirstem="openthread" + ;; + + *) + AC_MSG_NOTICE([No internal OpenThread support yet!]) + nl_with_openthread=no + with_openthread=no + ;; + esac + ], + [ + # Check for required OpenThread headers. + AC_CHECK_HEADERS([openthread/dataset.h] [openthread/dataset_ftd.h] [openthread/error.h] [openthread/icmp6.h] [openthread/instance.h] [openthread/ip6.h] [openthread/link.h] [openthread/message.h] [openthread/netdata.h] [openthread/tasklet.h] [openthread/thread.h], + [], + [ + AC_MSG_ERROR(The OpenThread header "$ac_header" is required but cannot be found.) + ]) + maybe_openthread_dirstem="" + ] +) +AC_SUBST(OPENTHREAD_SUBDIRS, [${maybe_openthread_dirstem}]) +AM_CONDITIONAL([CHIP_ENABLE_OPENTHREAD], [test "${nl_with_openthread}" != "no"]) +if test "${nl_with_openthread}" != "no"; then + CHIP_ENABLE_OPENTHREAD=1 +else + CHIP_ENABLE_OPENTHREAD=0 +fi +AC_DEFINE_UNQUOTED([CHIP_ENABLE_OPENTHREAD],[${CHIP_ENABLE_OPENTHREAD}],[Define to 1 if you want to enable OpenThread.]) + # # LwIP # @@ -1785,7 +1875,7 @@ AM_CONDITIONAL([CHIP_WITH_NLFAULTINJECTION], [test "${nl_with_nlfaultinjection}" AM_CONDITIONAL([CHIP_WITH_NLFAULTINJECTION_INTERNAL], [test "${nl_with_nlfaultinjection}" = "internal"]) if test "${nl_with_nlfaultinjection}" = "no"; then - AC_DEFINE([CHIP_WITH_NLFAULTINJECTION], [0], [Define to 1 to build CHIP with nlFaultInjection features]) + AC_DEFINE([CHIP_WITH_NLFAULTINJECTION], [0], [Define to 0 to build CHIP without nlFaultInjection features]) else AC_DEFINE([CHIP_WITH_NLFAULTINJECTION], [1], [Define to 1 to build CHIP with nlFaultInjection features]) fi @@ -1926,6 +2016,25 @@ if test "${CHIP_DEVICE_LAYER_TARGET_LINUX}" = 1; then ) fi +# +# +# GIO +# + +if test "${CHIP_DEVICE_LAYER_TARGET_LINUX}" = 1; then + PKG_CHECK_MODULES([GIO], [gio-2.0]) + + # Check for GIO library is available. + AC_CHECK_LIB([gio-2.0], [g_bus_get_sync], + [ + AC_DEFINE([CHIP_WITH_GIO], [1], [Define to 1 to build CHIP with GIO]) + ], + [ + AC_DEFINE([CHIP_WITH_GIO], [0], [Define to 0 to build CHIP without GIO]) + ] + ) +fi + # # Sockets # @@ -2139,9 +2248,9 @@ AC_SUBST(CRYPTO_CPPFLAGS) AC_SUBST(CRYPTO_LDFLAGS) AC_SUBST(CRYPTO_LIBS) -CPPFLAGS="${CPPFLAGS} ${CRYPTO_CPPFLAGS}" -LDFLAGS="${LDFLAGS} ${CRYPTO_LDFLAGS}" -LIBS="${LIBS} ${CRYPTO_LIBS}" +CPPFLAGS="${CPPFLAGS} ${CRYPTO_CPPFLAGS} ${OPENTHREAD_CPPFLAGS}" +LDFLAGS="${LDFLAGS} ${CRYPTO_LDFLAGS} ${OPENTHREAD_LDFLAGS}" +LIBS="${LIBS} ${CRYPTO_LIBS} ${OPENTHREAD_LIBS}" # Add any code coverage CPPFLAGS, LDFLAGS, and LIBS @@ -2231,6 +2340,8 @@ src/inet/Makefile src/inet/tests/Makefile src/lib/Makefile src/lib/core/tests/Makefile +src/lib/datamodel/Makefile +src/lib/datamodel/tests/Makefile src/lib/shell/Makefile src/lib/shell/tests/Makefile src/lib/support/Makefile @@ -2319,6 +2430,10 @@ AC_MSG_NOTICE([ mbedTLS compile flags : ${MBEDTLS_CPPFLAGS:--} mbedTLS link flags : ${MBEDTLS_LDFLAGS:--} mbedTLS link libraries : ${MBEDTLS_LIBS:--} + OpenThread source : ${nl_with_openthread} + OpenThread compile flags : ${OPENTHREAD_CPPFLAGS:--} + OpenThread link flags : ${OPENTHREAD_LDFLAGS:--} + OpenThread link libraries : ${OPENTHREAD_LIBS:--} OpenSSL source : ${nl_with_openssl} OpenSSL compile flags : ${OPENSSL_CPPFLAGS:--} OpenSSL link flags : ${OPENSSL_LDFLAGS:--} @@ -2350,6 +2465,7 @@ AC_MSG_NOTICE([ PThreads compile flags : ${PTHREAD_CFLAGS:--} PThreads link libraries : ${PTHREAD_LIBS:--} IniPP compile flags : ${INIPP_CPPFLAGS:--} + GIO compile flags : ${GIO_CFLAGS:--} C Preprocessor : ${CPP} C Compiler : ${CC} C++ Preprocessor : ${CXXCPP} diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index f0713d89b6269b..64495f2456a4ae 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -29,7 +29,7 @@ executable("chip-standalone-demo") { public_deps = [ "${chip_root}/src/lib" ] - output_dir = "${root_out_dir}/bin" + output_dir = root_out_dir } group("chip-tool") { diff --git a/examples/chip-tool/main.cpp b/examples/chip-tool/main.cpp index 4165855e5d32ac..e8c2c435b2149e 100644 --- a/examples/chip-tool/main.cpp +++ b/examples/chip-tool/main.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #include #include #include @@ -50,6 +52,7 @@ extern "C" { using namespace ::chip; using namespace ::chip::Inet; +using namespace ::chip::DataModel; // NOTE: Remote device ID is in sync with the echo server device id // At some point, we may want to add an option to connect to a device without @@ -151,7 +154,7 @@ bool DetermineAddress(int argc, char * argv[], IPAddress * hostAddr, uint16_t * return true; } -enum class Command +enum class CommandIndicator { Off, On, @@ -165,7 +168,7 @@ bool EqualsLiteral(const char * str, const char (&literal)[N]) return strncmp(str, literal, N) == 0; } -bool DetermineCommand(int argc, char * argv[], Command * command) +bool DetermineCommand(int argc, char * argv[], CommandIndicator * command) { if (argc < 4) { @@ -174,25 +177,25 @@ bool DetermineCommand(int argc, char * argv[], Command * command) if (EqualsLiteral(argv[3], "off")) { - *command = Command::Off; + *command = CommandIndicator::Off; return true; } if (EqualsLiteral(argv[3], "on")) { - *command = Command::On; + *command = CommandIndicator::On; return true; } if (EqualsLiteral(argv[3], "toggle")) { - *command = Command::Toggle; + *command = CommandIndicator::Toggle; return true; } if (EqualsLiteral(argv[3], "echo")) { - *command = Command::Echo; + *command = CommandIndicator::Echo; return true; } @@ -205,15 +208,15 @@ union CommandArgs ChipZclEndpointId_t endpointId; }; -bool DetermineCommandArgs(int argc, char * argv[], Command command, CommandArgs * commandArgs) +bool DetermineCommandArgs(int argc, char * argv[], CommandIndicator command, CommandArgs * commandArgs) { - if (command == Command::Echo) + if (command == CommandIndicator::Echo) { // No args. return true; } - if (command != Command::On && command != Command::Off && command != Command::Toggle) + if (command != CommandIndicator::On && command != CommandIndicator::Off && command != CommandIndicator::Toggle) { fprintf(stderr, "Need to define arg handling for command '%d'\n", int(command)); return false; @@ -266,56 +269,40 @@ void DoEcho(DeviceController::ChipDeviceController * controller, const IPAddress // Handle the on/off/toggle case, where we are sending a ZCL command and not // expecting a response at all. -void DoOnOff(DeviceController::ChipDeviceController * controller, Command command, ChipZclEndpointId_t endpoint) +void DoOnOff(DeviceController::ChipDeviceController * controller, CommandIndicator command, ChipZclEndpointId_t endpoint) { - ChipZclCommandId_t zclCommand; + // Make sure our buffer is big enough, but this will need a better setup! + static const size_t bufferSize = 1024; + auto * buffer = System::PacketBuffer::NewWithAvailableSize(bufferSize); + ZCLCommand cmd(buffer); + switch (command) { - case Command::Off: - zclCommand = CHIP_ZCL_CLUSTER_ON_OFF_SERVER_COMMAND_OFF; + case CommandIndicator::Off: + ClusterOnOffEncodeOff(&cmd, endpoint); break; - case Command::On: - zclCommand = CHIP_ZCL_CLUSTER_ON_OFF_SERVER_COMMAND_ON; + case CommandIndicator::On: + ClusterOnOffEncodeOn(&cmd, endpoint); break; - case Command::Toggle: - zclCommand = CHIP_ZCL_CLUSTER_ON_OFF_SERVER_COMMAND_TOGGLE; + case CommandIndicator::Toggle: + ClusterOnOffEncodeToggle(&cmd, endpoint); break; default: fprintf(stderr, "Unknown command: %d\n", command); return; } - // Make sure our buffer is big enough, but this will need a better setup! - static const size_t bufferSize = 1024; - auto * buffer = System::PacketBuffer::NewWithAvailableSize(bufferSize); - - ChipZclBuffer_t * zcl_buffer = (ChipZclBuffer_t *) buffer; - ChipZclCommandContext_t ctx = { - endpoint, // endpointId - CHIP_ZCL_CLUSTER_ON_OFF, // clusterId - true, // clusterSpecific - false, // mfgSpecific - 0, // mfgCode - zclCommand, // commandId - ZCL_DIRECTION_CLIENT_TO_SERVER, // direction - 0, // payloadStartIndex - nullptr, // request - nullptr // response - }; - chipZclEncodeZclHeader(zcl_buffer, &ctx); - #ifdef DEBUG - const size_t data_len = chipZclBufferDataLength(zcl_buffer); + const size_t data_len = chipZclBufferDataLength((ChipZclBuffer_t *) cmd.mBuffer); fprintf(stderr, "SENDING: %zu ", data_len); for (size_t i = 0; i < data_len; ++i) { - fprintf(stderr, "%d ", chipZclBufferPointer(zcl_buffer)[i]); + fprintf(stderr, "%d ", chipZclBufferPointer((ChipZclBuffer_t *) cmd.mBuffer)[i]); } fprintf(stderr, "\n"); #endif - - controller->SendMessage(NULL, buffer); + controller->SendMessage(NULL, (System::PacketBuffer *) cmd.mBuffer); controller->ServiceEvents(); } @@ -326,7 +313,7 @@ int main(int argc, char * argv[]) { IPAddress host_addr; uint16_t port; - Command command; + CommandIndicator command; CHIP_ERROR err; CommandArgs commandArgs; if (!DetermineAddress(argc, argv, &host_addr, &port) || !DetermineCommand(argc, argv, &command) || @@ -343,7 +330,7 @@ int main(int argc, char * argv[]) err = controller->ConnectDevice(kRemoteDeviceId, host_addr, NULL, EchoKeyExchange, EchoResponse, ReceiveError, port); VerifyOrExit(err == CHIP_NO_ERROR, fprintf(stderr, "Failed to connect to the device")); - if (command == Command::Echo) + if (command == CommandIndicator::Echo) { DoEcho(controller, host_addr, port); } diff --git a/examples/wifi-echo/server/esp32/main/Display.cpp b/examples/common/screen-framework/Display.cpp similarity index 100% rename from examples/wifi-echo/server/esp32/main/Display.cpp rename to examples/common/screen-framework/Display.cpp diff --git a/examples/wifi-echo/server/esp32/main/ListScreen.cpp b/examples/common/screen-framework/ListScreen.cpp similarity index 96% rename from examples/wifi-echo/server/esp32/main/ListScreen.cpp rename to examples/common/screen-framework/ListScreen.cpp index e358f3ab9a59e5..cc38ff27f00382 100644 --- a/examples/wifi-echo/server/esp32/main/ListScreen.cpp +++ b/examples/common/screen-framework/ListScreen.cpp @@ -52,7 +52,7 @@ void ListScreen::Display() for (int count = 0, y = ScreenTitleSafeTop; i < model->GetItemCount() && count < items; ++i, ++count, y += ScreenFontHeight) { tft_fg = focusIndex == i ? ScreenFocusColor : ScreenNormalColor; - TFT_print(model->GetItemText(i).c_str(), ScreenTitleSafeTop, y); + TFT_print(const_cast(model->GetItemText(i).c_str()), ScreenTitleSafeTop, y); } } diff --git a/examples/wifi-echo/server/esp32/README.screen.md b/examples/common/screen-framework/README.md similarity index 100% rename from examples/wifi-echo/server/esp32/README.screen.md rename to examples/common/screen-framework/README.md diff --git a/examples/wifi-echo/server/esp32/main/Screen.cpp b/examples/common/screen-framework/Screen.cpp similarity index 100% rename from examples/wifi-echo/server/esp32/main/Screen.cpp rename to examples/common/screen-framework/Screen.cpp diff --git a/examples/wifi-echo/server/esp32/main/ScreenManager.cpp b/examples/common/screen-framework/ScreenManager.cpp similarity index 94% rename from examples/wifi-echo/server/esp32/main/ScreenManager.cpp rename to examples/common/screen-framework/ScreenManager.cpp index 6814e50d8496c9..e4d6c6fffe09bf 100644 --- a/examples/wifi-echo/server/esp32/main/ScreenManager.cpp +++ b/examples/common/screen-framework/ScreenManager.cpp @@ -96,7 +96,7 @@ struct LazyDisplay // Print text centered horizontally at x. void PrintCentered(const char * s, int x, int y) { - TFT_print(s, x - (TFT_getStringWidth(s) / 2), y); + TFT_print(const_cast(s), x - (TFT_getStringWidth(const_cast(s)) / 2), y); } // Print button text in appropriate location (1 to 3). @@ -150,13 +150,14 @@ void ScreenManager::Display() if (screens.size() > 1) { tft_fg = focusBack ? ScreenFocusColor : ScreenNormalColor; - TFT_print("<", ScreenFontHeight, ScreenFontHeight / 2); + TFT_print(const_cast("<"), ScreenFontHeight, ScreenFontHeight / 2); } std::string title = screens.back()->GetTitle(); tft_fg = ScreenNormalColor; - TFT_print(title.c_str(), ScreenTitleSafeTop, ScreenFontHeight / 2); // within ScreenTitleSafeTop - TFT_drawRect(ScreenTitleSafeTop, ScreenFontHeight * 3 / 2, TFT_getStringWidth(title.c_str()), 2, ScreenNormalColor); + TFT_print(const_cast(title.c_str()), ScreenTitleSafeTop, ScreenFontHeight / 2); // within ScreenTitleSafeTop + TFT_drawRect(ScreenTitleSafeTop, ScreenFontHeight * 3 / 2, TFT_getStringWidth(const_cast(title.c_str())), 2, + ScreenNormalColor); TFT_setFont(kButtonFont, nullptr); if (screens.back()->IsFocusable()) diff --git a/examples/common/screen-framework/component.mk b/examples/common/screen-framework/component.mk new file mode 100644 index 00000000000000..5ed0594cd5b0d2 --- /dev/null +++ b/examples/common/screen-framework/component.mk @@ -0,0 +1,24 @@ +# +# 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. +# +# Description: +# Component makefile for the screen framework component used by the CHIP +# ESP32 demo applications. +# + +COMPONENT_ADD_INCLUDEDIRS := include +COMPONENT_SRCDIRS := . +COMPONENT_OBJS := Display.o ScreenManager.o Screen.o ListScreen.o diff --git a/examples/wifi-echo/server/esp32/main/include/Display.h b/examples/common/screen-framework/include/Display.h similarity index 100% rename from examples/wifi-echo/server/esp32/main/include/Display.h rename to examples/common/screen-framework/include/Display.h diff --git a/examples/wifi-echo/server/esp32/main/include/ListScreen.h b/examples/common/screen-framework/include/ListScreen.h similarity index 100% rename from examples/wifi-echo/server/esp32/main/include/ListScreen.h rename to examples/common/screen-framework/include/ListScreen.h diff --git a/examples/wifi-echo/server/esp32/main/include/Screen.h b/examples/common/screen-framework/include/Screen.h similarity index 100% rename from examples/wifi-echo/server/esp32/main/include/Screen.h rename to examples/common/screen-framework/include/Screen.h diff --git a/examples/wifi-echo/server/esp32/main/include/ScreenManager.h b/examples/common/screen-framework/include/ScreenManager.h similarity index 100% rename from examples/wifi-echo/server/esp32/main/include/ScreenManager.h rename to examples/common/screen-framework/include/ScreenManager.h diff --git a/examples/lighting-app/nrf5/Makefile b/examples/lighting-app/nrf5/Makefile index f2cc97e3bd1a85..56fa0a6fc30766 100644 --- a/examples/lighting-app/nrf5/Makefile +++ b/examples/lighting-app/nrf5/Makefile @@ -194,15 +194,9 @@ DEFINES = \ NRF52840_XXAA \ NRFX_PRS_ENABLED=0 \ NRF_SD_BLE_API_VERSION=7 \ - OPENTHREAD_CONFIG_COAP_API_ENABLE \ - OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=0 \ - OPENTHREAD_CONFIG_FILE=\"openthread-config-wrap.h\" \ - OPENTHREAD_FTD=1 \ PRINTF_DISABLE_SUPPORT_EXPONENTIAL \ S140 \ SOFTDEVICE_PRESENT \ - THREAD_EXAMPLE_COAP_SERVER=1 \ - THREAD_EXAMPLE_FREERTOS=1 \ UART0_ENABLED=0 \ UART1_ENABLED=1 \ USE_APP_CONFIG \ @@ -210,9 +204,12 @@ DEFINES = \ __STACK_SIZE=8192 \ LIBS = \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-cli-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ + -lopenthread-cli-ftd \ + -lopenthread-ftd \ + -lopenthread-platform-utils \ + -lopenthread-nrf52840-transport \ + -lopenthread-nrf52840-softdevice-sdk \ + -lnordicsemi-nrf52840-radio-driver-softdevice \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ @@ -222,19 +219,6 @@ LIBS = \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-nrf52840-softdevice-sdk.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libnordicsemi-nrf52840-radio-driver-softdevice.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_cc310_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_vanilla_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_base_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ CFLAGS = \ --specs=nano.specs diff --git a/examples/lock-app/efr32/Makefile b/examples/lock-app/efr32/Makefile index 50cfc789c05f9f..f63aef428948ec 100644 --- a/examples/lock-app/efr32/Makefile +++ b/examples/lock-app/efr32/Makefile @@ -116,6 +116,7 @@ SRCS = \ INC_DIRS = \ $(PROJECT_ROOT) \ + $(PROJECT_ROOT)/src/platform/EFR32/ \ $(PROJECT_ROOT)/include \ $(PROJECT_ROOT)/traits/include \ $(PROJECT_ROOT)/schema/include \ diff --git a/examples/lock-app/nrf5/Makefile b/examples/lock-app/nrf5/Makefile index 0396de152b5361..ec385e33d1afdc 100644 --- a/examples/lock-app/nrf5/Makefile +++ b/examples/lock-app/nrf5/Makefile @@ -194,15 +194,9 @@ DEFINES = \ NRF52840_XXAA \ NRFX_PRS_ENABLED=0 \ NRF_SD_BLE_API_VERSION=7 \ - OPENTHREAD_CONFIG_COAP_API_ENABLE \ - OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=0 \ - OPENTHREAD_CONFIG_FILE=\"openthread-config-wrap.h\" \ - OPENTHREAD_FTD=1 \ PRINTF_DISABLE_SUPPORT_EXPONENTIAL \ S140 \ SOFTDEVICE_PRESENT \ - THREAD_EXAMPLE_COAP_SERVER=1 \ - THREAD_EXAMPLE_FREERTOS=1 \ UART0_ENABLED=0 \ UART1_ENABLED=1 \ USE_APP_CONFIG \ @@ -210,9 +204,12 @@ DEFINES = \ __STACK_SIZE=8192 \ LIBS = \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-cli-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ + -lopenthread-cli-ftd \ + -lopenthread-ftd \ + -lopenthread-platform-utils \ + -lopenthread-nrf52840-transport \ + -lopenthread-nrf52840-softdevice-sdk \ + -lnordicsemi-nrf52840-radio-driver-softdevice \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ @@ -222,19 +219,6 @@ LIBS = \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-nrf52840-softdevice-sdk.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_cc310.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_glue_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libnordicsemi-nrf52840-radio-driver-softdevice.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_cc310_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedcrypto_vanilla_backend.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-platform-utils.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_base_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_tls_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libmbedtls_x509_vanilla.a \ - $(NRF5_SDK_ROOT)/external/openthread/nrf_security/lib/libnrf_cc310_platform_0.9.1.a \ - $(NRF5_SDK_ROOT)/external/openthread/lib/nrf52840/gcc/libopenthread-ftd.a \ CFLAGS = \ --specs=nano.specs diff --git a/examples/shell/BUILD.gn b/examples/shell/BUILD.gn index ed5a84f17cb8a5..95239268380250 100644 --- a/examples/shell/BUILD.gn +++ b/examples/shell/BUILD.gn @@ -21,6 +21,7 @@ assert(chip_build_tools) executable("chip-shell") { sources = [ "cmd_base64.cpp", + "cmd_device.cpp", "cmd_misc.cpp", "main.cpp", ] @@ -33,7 +34,7 @@ executable("chip-shell") { defines = [ "BUILD_RELEASE=1" ] } - output_dir = "${root_out_dir}/bin" + output_dir = root_out_dir } group("shell") { diff --git a/examples/shell/README.md b/examples/shell/README.md new file mode 100644 index 00000000000000..30ff5783f579fe --- /dev/null +++ b/examples/shell/README.md @@ -0,0 +1,116 @@ +# CHIP Shell Reference + +The `chip-shell` firmware exposes configuration and management APIs via a +command line interface (CLI). Use the shell CLI to experiment with CHIP +interactively, which can also be used with additional application code. The CHIP +functional test scripts use the shell CLI to execute test cases. + +## Separator and escaping characters + +The whitespace character (`' '`) is used to delimit the command name and the +different arguments, together with tab (`'\t'`) and new line characters (`'\r'`, +`'\n'`). + +Some arguments might require to accept whitespaces on them. For those cases the +backslash character (`'\'`) can be used to escape separators or the backslash +itself. + +Example: + +```bash +> networkname Test\ Network +Done +> networkname +Test Network +Done +> +``` + +## CHIP Shell Command List + +- [base64](#base64-decode-b64_string) +- [device](README_DEVICE.md) +- [echo](#echo-string) +- [exit](#exit) +- [help](#help) +- [rand](#rand) +- [version](#version) + +## CHIP Shell Command Details + +### help + +Display a list of all top-level commands supported and a brief description. + +```bash +> help + echo Echo back provided inputs + log Logging utilities + rand Random number utilities + base64 Base64 encode / decode utilities + device Device Layer commands + exit Exit the shell application + help List out all top level commands + version Output the software version +Done +``` + +### base64 decode \ + +Decode the given base64 string into hex. + +```bash +> base64 decode EjQ= +1234 +Done +``` + +### base64 encode \ + +Decode the given hex string into base64. + +```bash +> base64 encode 1234 +EjQ= +Done +``` + +### echo \ + +Echo back the provided string to the terminal. + +```bash +> echo hello +hello +Done +``` + +### exit + +Exit the shell terminal. On an embedded system this may trigger a watchdog +reset. + +```bash +> exit +Goodbye +``` + +### rand + +Output a single byte random number. + +```bash +> rand +103 +Done +``` + +### version + +Output the version of the CHIP stack. + +```bash +> version +CHIP 0.0.g54591338-dirty +Done +``` diff --git a/examples/shell/README_DEVICE.md b/examples/shell/README_DEVICE.md new file mode 100644 index 00000000000000..1d9db72f218bad --- /dev/null +++ b/examples/shell/README_DEVICE.md @@ -0,0 +1,83 @@ +# CHIP Shell - Device Layer module + +The chip::DeviceLayer APIs may be invoked via the CHIP Shell CLI. + +## Command List + +- [help](#help) +- [config](#config) +- [get](#get-parameter) +- [start](#start) + +## Command Details + +### help + +List the Device CLI commands. + +```bash +> device help + help Usage: device + start Start the device layer. Usage: device start + get Get configuration value. Usage: device get + config Dump entire configuration of device. Usage: device dump +Done +``` + +### config + +Dump the configuration of the device. + +```bash +> device config +VendorId: 235a +ProductId: feff +ProductRevision: 0001 +SerialNumber: +ServiceId: +FabricId: +PairingCode: +DeviceId: +DeviceCert: +DeviceCaCerts: +MfrDeviceId: +MfrDeviceCert: +MfgDeviceCaCerts: +``` + +### get \ + +- parameter: name of field to query + +Where valid parameter names include: + +- vendorid: Vendor Identifier +- productid: Product Identifier +- productrev: Product Revision +- serial: Serial Number +- deviceid: Device Identification Number +- cert: Device Certificate +- cacerts: Device CA Certificates +- mfrdeviceid: Manufacturer Device Identification Number +- mfrcert: Manufacturer Device Certificate +- mfrcacerts: Manufacturer Device CA Certs +- pairingcode: Pairing Code +- serviceid: Service Identifier +- fabricid: Fabric Identifier + +```bash +> device get vendorid +235a +Done +``` + +### start + +Initialize the chip stack and start the device layer event loop. + +```bash +> device start +Init CHIP Stack +Starting Platform Manager Event Loop +Done +``` diff --git a/examples/shell/cmd_device.cpp b/examples/shell/cmd_device.cpp new file mode 100644 index 00000000000000..27601198150b0d --- /dev/null +++ b/examples/shell/cmd_device.cpp @@ -0,0 +1,508 @@ +/* + * + * Copyright (c) 2020 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. + */ + +#include + +#if CONFIG_DEVICE_LAYER + +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::Shell; +using namespace chip::Platform; +using namespace chip::DeviceLayer; +using namespace chip::Logging; +using namespace chip::ArgParser; + +static chip::Shell::Shell sShellDeviceSubcommands; + +int cmd_device_help_iterator(shell_command_t * command, void * arg) +{ + streamer_printf(streamer_get(), " %-15s %s\n\r", command->cmd_name, command->cmd_help); + return 0; +} + +int cmd_device_help(int argc, char ** argv) +{ + sShellDeviceSubcommands.ForEachCommand(cmd_device_help_iterator, NULL); + return 0; +} + +int cmd_device_start(int argc, char ** argv) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + + VerifyOrExit(argc == 0, error = CHIP_ERROR_INVALID_ARGUMENT); + + streamer_printf(sout, "Init CHIP Stack\r\n"); + error = PlatformMgr().InitChipStack(); + SuccessOrExit(error); + + streamer_printf(sout, "Starting Platform Manager Event Loop\r\n"); + error = PlatformMgr().StartEventLoopTask(); + SuccessOrExit(error); + +exit: + return error; +} + +static CHIP_ERROR ConfigGetDone(streamer_t * sout, CHIP_ERROR error) +{ + if (error) + { + streamer_printf(sout, ""); + } + streamer_printf(sout, "\r\n"); + return error; +} + +static CHIP_ERROR ConfigGetVendorId(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint16_t value16; + + if (printHeader) + { + streamer_printf(sout, "VendorId: "); + } + SuccessOrExit(error = ConfigurationMgr().GetVendorId(value16)); + streamer_printf(sout, "%04x", value16); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetProductId(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint16_t value16; + + if (printHeader) + { + streamer_printf(sout, "ProductId: "); + } + SuccessOrExit(error = ConfigurationMgr().GetProductId(value16)); + streamer_printf(sout, "%04x", value16); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetProductRevision(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint16_t value16; + + if (printHeader) + { + streamer_printf(sout, "ProductRevision: "); + } + SuccessOrExit(error = ConfigurationMgr().GetProductRevision(value16)); + streamer_printf(sout, "%04x", value16); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetSerialNumber(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + char buf[ConfigurationManager::kMaxSerialNumberLength]; + size_t bufSize; + + if (printHeader) + { + streamer_printf(sout, "SerialNumber: "); + } + SuccessOrExit(error = ConfigurationMgr().GetSerialNumber(buf, sizeof(buf), bufSize)); + streamer_print_hex(sout, reinterpret_cast(buf), bufSize); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetDeviceId(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint64_t value64; + + if (printHeader) + { + streamer_printf(sout, "DeviceId: "); + } + SuccessOrExit(error = ConfigurationMgr().GetDeviceId(value64)); + streamer_print_hex(sout, reinterpret_cast(&value64), sizeof(value64)); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetDeviceCert(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint8_t * certBuf = NULL; + size_t certLen; + + if (printHeader) + { + streamer_printf(sout, "DeviceCert: "); + } + // Determine the length of the device certificate. + error = ConfigurationMgr().GetDeviceCertificate((uint8_t *) NULL, 0, certLen); + SuccessOrExit(error); + + // Fail if no certificate has been configured. + VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); + + // Create a temporary buffer to hold the certificate. + certBuf = (uint8_t *) MemoryAlloc(certLen); + VerifyOrExit(certBuf != NULL, error = CHIP_ERROR_NO_MEMORY); + + // Read the certificate + error = ConfigurationMgr().GetDeviceCertificate(certBuf, certLen, certLen); + SuccessOrExit(error); + + streamer_print_hex(sout, const_cast(certBuf), certLen); + +exit: + if (certBuf != NULL) + { + MemoryFree(certBuf); + } + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetDeviceCaCerts(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint8_t * certBuf = NULL; + size_t certLen; + + if (printHeader) + { + streamer_printf(sout, "DeviceCaCerts: "); + } + // Determine the length of the device certificate. + error = ConfigurationMgr().GetDeviceIntermediateCACerts((uint8_t *) NULL, 0, certLen); + SuccessOrExit(error); + + // Fail if no certificate has been configured. + VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); + + // Create a temporary buffer to hold the certificate. + certBuf = (uint8_t *) MemoryAlloc(certLen); + VerifyOrExit(certBuf != NULL, error = CHIP_ERROR_NO_MEMORY); + + // Read the certificate + error = ConfigurationMgr().GetDeviceIntermediateCACerts(certBuf, certLen, certLen); + SuccessOrExit(error); + + streamer_print_hex(sout, const_cast(certBuf), certLen); + +exit: + if (certBuf != NULL) + { + MemoryFree(certBuf); + } + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetManufacturerDeviceId(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint64_t value64; + + if (printHeader) + { + streamer_printf(sout, "MfrDeviceId: "); + } + SuccessOrExit(error = ConfigurationMgr().GetManufacturerDeviceId(value64)); + streamer_print_hex(sout, reinterpret_cast(&value64), sizeof(value64)); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetManufacturerDeviceCert(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint8_t * certBuf = NULL; + size_t certLen; + + if (printHeader) + { + streamer_printf(sout, "MfrDeviceCert: "); + } + // Determine the length of the device certificate. + error = ConfigurationMgr().GetManufacturerDeviceCertificate((uint8_t *) NULL, 0, certLen); + SuccessOrExit(error); + + // Fail if no certificate has been configured. + VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); + + // Create a temporary buffer to hold the certificate. + certBuf = (uint8_t *) MemoryAlloc(certLen); + VerifyOrExit(certBuf != NULL, error = CHIP_ERROR_NO_MEMORY); + + // Read the certificate + error = ConfigurationMgr().GetManufacturerDeviceCertificate(certBuf, certLen, certLen); + SuccessOrExit(error); + + streamer_print_hex(sout, const_cast(certBuf), certLen); + +exit: + if (certBuf != NULL) + { + MemoryFree(certBuf); + } + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetManufacturerDeviceCaCerts(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint8_t * certBuf = NULL; + size_t certLen; + + if (printHeader) + { + streamer_printf(sout, "MfgDeviceCaCerts:"); + } + // Determine the length of the device certificate. + error = ConfigurationMgr().GetManufacturerDeviceIntermediateCACerts((uint8_t *) NULL, 0, certLen); + SuccessOrExit(error); + + // Fail if no certificate has been configured. + VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); + + // Create a temporary buffer to hold the certificate. + certBuf = (uint8_t *) MemoryAlloc(certLen); + VerifyOrExit(certBuf != NULL, error = CHIP_ERROR_NO_MEMORY); + + // Read the certificate + error = ConfigurationMgr().GetManufacturerDeviceIntermediateCACerts(certBuf, certLen, certLen); + SuccessOrExit(error); + + streamer_print_hex(sout, const_cast(certBuf), certLen); + +exit: + if (certBuf != NULL) + { + MemoryFree(certBuf); + } + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetPairingCode(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + char buf[ConfigurationManager::kMaxPairingCodeLength]; + size_t bufSize; + + if (printHeader) + { + streamer_printf(sout, "PairingCode: "); + } + SuccessOrExit(error = ConfigurationMgr().GetPairingCode(buf, sizeof(buf), bufSize)); + streamer_print_hex(sout, reinterpret_cast(buf), bufSize); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetServiceId(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint64_t value64; + + if (printHeader) + { + streamer_printf(sout, "ServiceId: "); + } + SuccessOrExit(error = ConfigurationMgr().GetServiceId(value64)); + streamer_print_hex(sout, reinterpret_cast(&value64), sizeof(value64)); + +exit: + return ConfigGetDone(sout, error); +} + +static CHIP_ERROR ConfigGetFabricId(bool printHeader) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + uint64_t value64; + + if (printHeader) + { + streamer_printf(sout, "FabricId: "); + } + SuccessOrExit(error = ConfigurationMgr().GetFabricId(value64)); + streamer_print_hex(sout, reinterpret_cast(&value64), sizeof(value64)); + +exit: + return ConfigGetDone(sout, error); +} + +int cmd_device_config(int argc, char ** argv) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + + VerifyOrExit(argc == 0, error = CHIP_ERROR_INVALID_ARGUMENT); + + error |= ConfigGetVendorId(true); + error |= ConfigGetProductId(true); + error |= ConfigGetProductRevision(true); + error |= ConfigGetSerialNumber(true); + + error |= ConfigGetServiceId(true); + error |= ConfigGetFabricId(true); + error |= ConfigGetPairingCode(true); + + error |= ConfigGetDeviceId(true); + error |= ConfigGetDeviceCert(true); + error |= ConfigGetDeviceCaCerts(true); + + error |= ConfigGetManufacturerDeviceId(true); + error |= ConfigGetManufacturerDeviceCert(true); + error |= ConfigGetManufacturerDeviceCaCerts(true); + +exit: + return (error) ? CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND : CHIP_NO_ERROR; +} + +int cmd_device_get(int argc, char ** argv) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + streamer_t * sout = streamer_get(); + + if (argc == 0) + { + return cmd_device_config(argc, argv); + } + + if (strcmp(argv[0], "vendorid") == 0) + { + SuccessOrExit(error = ConfigGetVendorId(false)); + } + else if (strcmp(argv[0], "productid") == 0) + { + SuccessOrExit(error = ConfigGetProductId(false)); + } + else if (strcmp(argv[0], "productrev") == 0) + { + SuccessOrExit(error = ConfigGetProductRevision(false)); + } + else if (strcmp(argv[0], "serial") == 0) + { + SuccessOrExit(error = ConfigGetSerialNumber(false)); + } + else if (strcmp(argv[0], "deviceid") == 0) + { + SuccessOrExit(error = ConfigGetDeviceId(false)); + } + else if (strcmp(argv[0], "cert") == 0) + { + SuccessOrExit(error = ConfigGetDeviceCert(false)); + } + else if (strcmp(argv[0], "cacerts") == 0) + { + SuccessOrExit(error = ConfigGetDeviceCaCerts(false)); + } + else if (strcmp(argv[0], "mfrdeviceid") == 0) + { + SuccessOrExit(error = ConfigGetManufacturerDeviceId(false)); + } + else if (strcmp(argv[0], "mfrcert") == 0) + { + SuccessOrExit(error = ConfigGetManufacturerDeviceCert(false)); + } + else if (strcmp(argv[0], "mfrcacerts") == 0) + { + SuccessOrExit(error = ConfigGetManufacturerDeviceCaCerts(false)); + } + else if (strcmp(argv[0], "pairingcode") == 0) + { + SuccessOrExit(error = ConfigGetPairingCode(false)); + } + else if (strcmp(argv[0], "serviceid") == 0) + { + SuccessOrExit(error = ConfigGetServiceId(false)); + } + else if (strcmp(argv[0], "fabricid") == 0) + { + SuccessOrExit(error = ConfigGetFabricId(false)); + } + else + { + ExitNow(error = CHIP_ERROR_INVALID_ARGUMENT); + } + +exit: + return error; +} + +int cmd_device_dispatch(int argc, char ** argv) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + + VerifyOrExit(argc > 0, error = CHIP_ERROR_INVALID_ARGUMENT); + + error = sShellDeviceSubcommands.ExecCommand(argc, argv); + +exit: + return error; +} + +static const shell_command_t cmds_base64_root = { &cmd_device_dispatch, "device", "Device Layer commands" }; + +/// Subcommands for root command: `base64 ` +static const shell_command_t cmds_device[] = { + { &cmd_device_help, "help", "Usage: device " }, + { &cmd_device_start, "start", "Start the device layer. Usage: device start" }, + { &cmd_device_get, "get", "Get configuration value. Usage: device get " }, + { &cmd_device_config, "config", "Dump entire configuration of device. Usage: device dump" }, +}; + +#endif // CONFIG_DEVICE_LAYER + +void cmd_device_init(void) +{ +#if CONFIG_DEVICE_LAYER + // Register `device` subcommands with the local shell dispatcher. + sShellDeviceSubcommands.RegisterCommands(cmds_device, ARRAY_SIZE(cmds_device)); + + // Register the root `base64` command with the top-level shell. + shell_register(&cmds_base64_root, 1); +#endif // CONFIG_DEVICE_LAYER +} diff --git a/examples/shell/main.cpp b/examples/shell/main.cpp index 1ff210c208b313..ddd6cc576a72c6 100644 --- a/examples/shell/main.cpp +++ b/examples/shell/main.cpp @@ -34,11 +34,13 @@ using namespace chip::Shell; void cmd_misc_init(); void cmd_base64_init(); +void cmd_device_init(); int main(void) { cmd_misc_init(); cmd_base64_init(); + cmd_device_init(); shell_task(NULL); } diff --git a/examples/shell/standalone/Makefile b/examples/shell/standalone/Makefile index f55ae6057d5b50..d62ff73fe03460 100644 --- a/examples/shell/standalone/Makefile +++ b/examples/shell/standalone/Makefile @@ -38,6 +38,7 @@ SRCS = \ $(PROJECT_ROOT)/main.cpp \ $(PROJECT_ROOT)/cmd_misc.cpp \ $(PROJECT_ROOT)/cmd_base64.cpp \ + $(PROJECT_ROOT)/cmd_device.cpp \ $(NULL) INC_DIRS = \ diff --git a/examples/wifi-echo/server/esp32/Makefile b/examples/wifi-echo/server/esp32/Makefile index 8dc5ee6bd8a7bd..97bde5213c670a 100644 --- a/examples/wifi-echo/server/esp32/Makefile +++ b/examples/wifi-echo/server/esp32/Makefile @@ -24,9 +24,10 @@ PROJECT_NAME := chip-wifi-echo EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32/components \ $(PROJECT_PATH)/../../../common/m5stack-tft/repo/components \ $(PROJECT_PATH)/../../../common/QRCode \ + $(PROJECT_PATH)/../../../common/screen-framework \ CXXFLAGS += -std=c++11 -Os CPPFLAGS += -Os -CLAGS += -Os +CFLAGS += -Os include $(IDF_PATH)/make/project.mk diff --git a/examples/wifi-echo/server/esp32/main/CHIPDeviceManager.cpp b/examples/wifi-echo/server/esp32/main/CHIPDeviceManager.cpp index c5f8d57e81ad8d..4da81322318164 100644 --- a/examples/wifi-echo/server/esp32/main/CHIPDeviceManager.cpp +++ b/examples/wifi-echo/server/esp32/main/CHIPDeviceManager.cpp @@ -84,17 +84,5 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) return err; } -extern "C" { -void chipZclPostAttributeChangeCallback(uint8_t endpoint, ChipZclClusterId clusterId, ChipZclAttributeId attributeId, uint8_t mask, - uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value) -{ - CHIPDeviceManagerCallbacks * cb = CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks(); - if (cb != nullptr) - { - cb->PostAttributeChangeCallback(endpoint, clusterId, attributeId, mask, manufacturerCode, type, size, value); - } -} -} // extern "C" - } // namespace DeviceManager } // namespace chip diff --git a/examples/wifi-echo/server/esp32/main/DataModelHandler.cpp b/examples/wifi-echo/server/esp32/main/DataModelHandler.cpp index 82dfdec73c1a3c..5181d581dd536a 100644 --- a/examples/wifi-echo/server/esp32/main/DataModelHandler.cpp +++ b/examples/wifi-echo/server/esp32/main/DataModelHandler.cpp @@ -21,36 +21,38 @@ */ #include "esp_log.h" -#include +#include #include "DataModelHandler.h" #include "LEDWidget.h" extern "C" { +#include "chip-zcl/chip-zcl-codec.h" #include "chip-zcl/chip-zcl.h" #include "gen/gen-cluster-id.h" #include "gen/gen-types.h" } using namespace ::chip; +using namespace ::chip::DataModel; static const char * TAG = "data_model_server"; -void InitDataModelHandler() -{ - chipZclEndpointInit(); -} +void InitDataModelHandler() {} -void HandleDataModelMessage(System::PacketBuffer * buffer) +void HandleDataModelMessage(ClusterServer & server, System::PacketBuffer * buffer) { - ChipZclStatus_t zclStatus = chipZclProcessIncoming((ChipZclBuffer_t *) buffer); - if (zclStatus == CHIP_ZCL_STATUS_SUCCESS) + ZCLCommand cmd(buffer); + cmd.StartDecode(); + + if (server.HandleCommand(cmd) != CHIP_NO_ERROR) { ESP_LOGI(TAG, "Data model processing success!"); } else { - ESP_LOGI(TAG, "Data model processing failure: %d", zclStatus); + ESP_LOGI(TAG, "Data model processing failure"); } - System::PacketBuffer::Free(buffer); + cmd.EndDecode(); + System::PacketBuffer::Free((chip::System::PacketBuffer *) cmd.mBuffer); } diff --git a/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp b/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp index 1428c770658635..a27a17b1538099 100644 --- a/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp +++ b/examples/wifi-echo/server/esp32/main/EchoDeviceCallbacks.cpp @@ -34,6 +34,7 @@ static const char * TAG = "echo-devicecallbacks"; using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; +using namespace ::chip::DataModel; extern LEDWidget statusLED; // In wifi-echo.cpp @@ -69,23 +70,3 @@ void EchoDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, int ESP_LOGI(TAG, "Commissioner detected!"); } } - -void EchoDeviceCallbacks::PostAttributeChangeCallback(uint8_t endpoint, ChipZclClusterId clusterId, ChipZclAttributeId attributeId, - uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size, - uint8_t * value) -{ - if (clusterId != CHIP_ZCL_CLUSTER_ON_OFF) - { - ESP_LOGI(TAG, "Unknown cluster ID: %d", clusterId); - return; - } - - if (attributeId != CHIP_ZCL_CLUSTER_ON_OFF_SERVER_ATTRIBUTE_ON_OFF) - { - ESP_LOGI(TAG, "Unknown attribute ID: %d", attributeId); - return; - } - ESP_LOGI(TAG, "Got the post attribute callback"); - // At this point we can assume that value points to a boolean value. - statusLED.Set(*value); -} diff --git a/examples/wifi-echo/server/esp32/main/EchoServer.cpp b/examples/wifi-echo/server/esp32/main/EchoServer.cpp index 4dd2fd43626dd4..4ebb3dadc81e88 100644 --- a/examples/wifi-echo/server/esp32/main/EchoServer.cpp +++ b/examples/wifi-echo/server/esp32/main/EchoServer.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,8 @@ using namespace ::chip::Inet; using namespace ::chip::Transport; constexpr NodeId kLocalNodeId = 12344321; -extern LEDWidget statusLED; // In wifi-echo.cpp +extern LEDWidget statusLED; // In wifi-echo.cpp +extern chip::DataModel::ClusterServer gServer; // In wifi-echo.cpp namespace { @@ -159,7 +161,7 @@ class EchoServerCallback : public SecureSessionMgrCallback // port from data model processing. if (ContentMayBeADataModelMessage(buffer)) { - HandleDataModelMessage(buffer); + HandleDataModelMessage(gServer, buffer); buffer = NULL; } else diff --git a/examples/wifi-echo/server/esp32/main/LEDWidget.cpp b/examples/wifi-echo/server/esp32/main/LEDWidget.cpp index 502a4b0a4f1899..aef6e284162ded 100644 --- a/examples/wifi-echo/server/esp32/main/LEDWidget.cpp +++ b/examples/wifi-echo/server/esp32/main/LEDWidget.cpp @@ -31,6 +31,7 @@ #include "esp_log.h" #include "esp_system.h" #include "esp_timer.h" +#include #if CONFIG_HAVE_DISPLAY // The Y position of the LED Status message on screen as a @@ -46,7 +47,7 @@ static const char * onMsg = "LIGHT: ON"; static const char * offMsg = "LIGHT: OFF"; #endif - +using namespace ::chip::DataModel; extern const char * TAG; void LEDWidget::Init(gpio_num_t gpioNum) @@ -71,6 +72,19 @@ void LEDWidget::Set(bool state) { mBlinkOnTimeMS = mBlinkOffTimeMS = 0; DoSet(state); + Cluster::Set(kAttributeIdOnOff, ValueBool(state)); +} + +CHIP_ERROR LEDWidget::Set(uint16_t attrId, const Value & value) +{ + if (attrId == kAttributeIdOnOff) + { + printf("Setting value to %d\n", ValueToBool(value)); + DoSet(ValueToBool(value)); + /* Update our internal data model as well */ + Cluster::Set(attrId, value); + } + return CHIP_NO_ERROR; } void LEDWidget::Blink(uint32_t changeRateMS) diff --git a/examples/wifi-echo/server/esp32/main/include/CHIPDeviceManager.h b/examples/wifi-echo/server/esp32/main/include/CHIPDeviceManager.h index b05ceae259e513..f3f1381129fd12 100644 --- a/examples/wifi-echo/server/esp32/main/include/CHIPDeviceManager.h +++ b/examples/wifi-echo/server/esp32/main/include/CHIPDeviceManager.h @@ -64,22 +64,6 @@ class DLL_EXPORT CHIPDeviceManagerCallbacks */ virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); - /** - * @brief - * Called after an attribute has been changed - * - * @param endpoint endpoint id - * @param clusterID cluster id - * @param attributeId attribute id that was changed - * @param mask mask of the attribute - * @param manufacturerCode manufacturer code - * @param type attribute type - * @param size size of the attribute - * @param value pointer to the new value - */ - virtual void PostAttributeChangeCallback(uint8_t endpoint, ChipZclClusterId clusterId, ChipZclAttributeId attributeId, - uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value) - {} virtual ~CHIPDeviceManagerCallbacks() {} }; diff --git a/examples/wifi-echo/server/esp32/main/include/DataModelHandler.h b/examples/wifi-echo/server/esp32/main/include/DataModelHandler.h index 06c78bd8e58db7..bf4cf302556d88 100644 --- a/examples/wifi-echo/server/esp32/main/include/DataModelHandler.h +++ b/examples/wifi-echo/server/esp32/main/include/DataModelHandler.h @@ -23,6 +23,7 @@ #ifndef DATA_MODEL_HANDLER_H #define DATA_MODEL_HANDLER_H +#include namespace chip { namespace System { class PacketBuffer; @@ -39,9 +40,10 @@ void InitDataModelHandler(); * Handle a message that should be processed via our data model processing * codepath. * + * @param [in] server The ClusterServer object that holds the data model * @param [in] buffer The buffer holding the message. This function guarantees * that it will free the buffer before returning. */ -void HandleDataModelMessage(chip::System::PacketBuffer * buffer); +void HandleDataModelMessage(chip::DataModel::ClusterServer & server, chip::System::PacketBuffer * buffer); #endif // DATA_MODEL_HANDLER_H diff --git a/examples/wifi-echo/server/esp32/main/include/EchoDeviceCallbacks.h b/examples/wifi-echo/server/esp32/main/include/EchoDeviceCallbacks.h index 2386b900fc28ce..aad620430d7278 100644 --- a/examples/wifi-echo/server/esp32/main/include/EchoDeviceCallbacks.h +++ b/examples/wifi-echo/server/esp32/main/include/EchoDeviceCallbacks.h @@ -34,8 +34,6 @@ class EchoDeviceCallbacks : public CHIPDeviceManagerCallbacks { public: virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); - virtual void PostAttributeChangeCallback(uint8_t endpoint, ChipZclClusterId clusterId, ChipZclAttributeId attributeId, - uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value); }; #endif // ECHO_DEVICE_CALLBACKS_H diff --git a/examples/wifi-echo/server/esp32/main/include/LEDWidget.h b/examples/wifi-echo/server/esp32/main/include/LEDWidget.h index 9941845adfd61c..6eb98d2c0c2a80 100644 --- a/examples/wifi-echo/server/esp32/main/include/LEDWidget.h +++ b/examples/wifi-echo/server/esp32/main/include/LEDWidget.h @@ -27,12 +27,14 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/timers.h" +#include -class LEDWidget +class LEDWidget : public chip::DataModel::ClusterOnOff { public: void Init(gpio_num_t gpioNum); void Set(bool state); + int Set(uint16_t attrId, const chip::DataModel::Value & value); void Blink(uint32_t changeRateMS); void Blink(uint32_t onTimeMS, uint32_t offTimeMS); void BlinkOnError(); diff --git a/examples/wifi-echo/server/esp32/main/wifi-echo.cpp b/examples/wifi-echo/server/esp32/main/wifi-echo.cpp index 3410e1d12dd3db..e7f1710da29f01 100644 --- a/examples/wifi-echo/server/esp32/main/wifi-echo.cpp +++ b/examples/wifi-echo/server/esp32/main/wifi-echo.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -49,6 +50,7 @@ using namespace ::chip; using namespace ::chip::DeviceLayer; +using namespace ::chip::DataModel; extern void startServer(); @@ -104,6 +106,9 @@ LEDWidget statusLED; const char * TAG = "wifi-echo-demo"; static EchoDeviceCallbacks EchoCallbacks; +const uint8_t applicationVersion = 20; +const uint8_t HWVersion = 1; +ClusterServer gServer(applicationVersion, HWVersion); namespace { @@ -111,37 +116,37 @@ std::vector