From e4ab6f47a1b8c0121b2d30f5c73e5f6a1f60e8b6 Mon Sep 17 00:00:00 2001
From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com>
Date: Thu, 11 Mar 2021 15:17:03 +0100
Subject: [PATCH 01/39] [nrfconnect] Add script to checkout recommended nRF
Connect SDK version. (#5292)
The nRF Connect SDK recommended version changes from time to time
and users may face problems to notice it and update to the supported
one.
* Added script allowing to check if current nRF Connect SDK version
is the same as recommended one and also to update it
to the recommended version.
---
.github/workflows/examples-nrfconnect.yaml | 2 +
.../.nrfconnect-recommended-revision | 1 +
.../app/check-nrfconnect-version.cmake | 21 ++++
.../lighting-app/nrfconnect/CMakeLists.txt | 3 +-
examples/lighting-app/nrfconnect/README.md | 50 ++++----
examples/lock-app/nrfconnect/CMakeLists.txt | 3 +-
examples/lock-app/nrfconnect/README.md | 50 ++++----
.../pigweed-app/nrfconnect/CMakeLists.txt | 6 +-
examples/pigweed-app/nrfconnect/README.md | 50 ++++----
examples/shell/nrfconnect/CMakeLists.txt | 3 +-
scripts/setup/nrfconnect/update_ncs.py | 114 ++++++++++++++++++
11 files changed, 219 insertions(+), 84 deletions(-)
create mode 100644 config/nrfconnect/.nrfconnect-recommended-revision
create mode 100644 config/nrfconnect/app/check-nrfconnect-version.cmake
create mode 100755 scripts/setup/nrfconnect/update_ncs.py
diff --git a/.github/workflows/examples-nrfconnect.yaml b/.github/workflows/examples-nrfconnect.yaml
index 835dbadd1aeb85..00f6f024a3fbf8 100644
--- a/.github/workflows/examples-nrfconnect.yaml
+++ b/.github/workflows/examples-nrfconnect.yaml
@@ -40,6 +40,8 @@ jobs:
with:
fetch-depth: 0
submodules: true
+ - name: Update nRF Connect SDK revision to the currently recommended.
+ run: python3 scripts/setup/nrfconnect/update_ncs.py --update
# https://github.com/project-chip/connectedhomeip/issues/3100
# - name: Initialize CodeQL
# uses: github/codeql-action/init@v1
diff --git a/config/nrfconnect/.nrfconnect-recommended-revision b/config/nrfconnect/.nrfconnect-recommended-revision
new file mode 100644
index 00000000000000..56e68719154e67
--- /dev/null
+++ b/config/nrfconnect/.nrfconnect-recommended-revision
@@ -0,0 +1 @@
+8e8c60897eac40f61db9f578ce521970fff8e4d2
diff --git a/config/nrfconnect/app/check-nrfconnect-version.cmake b/config/nrfconnect/app/check-nrfconnect-version.cmake
new file mode 100644
index 00000000000000..a4e6a0cf294c4c
--- /dev/null
+++ b/config/nrfconnect/app/check-nrfconnect-version.cmake
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+find_package(Python3 REQUIRED)
+add_custom_target(check-nrfconnect-version ALL
+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../../..
+ COMMAND ${Python3_EXECUTABLE} scripts/setup/nrfconnect/update_ncs.py --check --quiet || (exit 0)
+ USES_TERMINAL)
diff --git a/examples/lighting-app/nrfconnect/CMakeLists.txt b/examples/lighting-app/nrfconnect/CMakeLists.txt
index 32a65e7982ee08..bc46f101bc75c2 100644
--- a/examples/lighting-app/nrfconnect/CMakeLists.txt
+++ b/examples/lighting-app/nrfconnect/CMakeLists.txt
@@ -19,9 +19,10 @@ get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connect
get_filename_component(NRFCONNECT_COMMON ${CHIP_ROOT}/examples/platform/nrfconnect REALPATH)
get_filename_component(LIGHTING_COMMON ${CHIP_ROOT}/examples/lighting-app/lighting-common REALPATH)
-set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
+include(${CHIP_ROOT}/config/nrfconnect/app/check-nrfconnect-version.cmake)
# Load NCS/Zephyr build system
+set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nrfconnect/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
diff --git a/examples/lighting-app/nrfconnect/README.md b/examples/lighting-app/nrfconnect/README.md
index 4faa0998da9576..80c0504569ec37 100644
--- a/examples/lighting-app/nrfconnect/README.md
+++ b/examples/lighting-app/nrfconnect/README.md
@@ -92,7 +92,9 @@ with other Thread devices in the network.
## Requirements
-The application requires the nRF Connect SDK v1.5.0 to work correctly.
+The application requires a specific revision of the nRF Connect SDK to work
+correctly. See [Setting up the environment](#setting-up-the-environment) for
+more information.
@@ -176,9 +178,9 @@ using the following command:
$ git submodule update --init
-The example requires the nRF Connect SDK v1.5.0. You can either install it along
-with the related tools directly on your system or use a Docker image that has
-the tools pre-installed.
+The example requires a specific revision of the nRF Connect SDK. You can either
+install it along with the related tools directly on your system or use a Docker
+image that has the tools pre-installed.
If you are a macOS user, you won't be able to use the Docker container to flash
the application onto a Nordic development kit due to
@@ -220,13 +222,11 @@ To use the Docker container for setup, complete the following steps:
- _-e RUNAS=\$(id -u)_ is needed to start the container session as the
current user instead of root.
-4. Check out or update the nRF Connect SDK to the recommended `v1.5.0` version
- by running the following command in the Docker container:
+4. Update the nRF Connect SDK to the most recent supported revision, by running
+ the following command:
- $ setup --ncs v1.5.0
- /var/ncs repository is empty. Do you wish to check out nRF Connect SDK sources [v1.5.0]? [Y/N] y
- ...
- /var/chip repository is initialized, skipping...
+ $ cd /var/chip
+ $ python3 scripts/setup/nrfconnect/update_ncs.py --update
Now you can proceed with the [Building](#building) instruction.
@@ -239,23 +239,14 @@ To use the native shell for setup, complete the following steps:
- [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
- [GN meta-build system](https://gn.googlesource.com/gn/)
-2. Depending on whether you have the nRF Connect SDK installed:
-
- - Follow the
- [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
- in the nRF Connect SDK documentation to install the nRF Connect SDK
- v1.5.0. Since command-line tools will be used for building the example,
- installing SEGGER Embedded Studio is not required.
-
- - If you have an older version of the SDK installed, use the following
- commands to update it to the recommended version. Replace
- _nrfconnect-dir_ with the path to your nRF Connect SDK installation
- directory.
+2. If you do not have the nRF Connect SDK installed, follow the
+ [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
+ in the nRF Connect SDK documentation to install the latest stable nRF
+ Connect SDK version. Since command-line tools will be used for building the
+ example, installing SEGGER Embedded Studio is not required.
- $ cd nrfconnect-dir/nrf
- $ git fetch origin
- $ git checkout v1.5.0
- $ west update
+ If you have the SDK already installed, continue to the next step and update
+ the nRF Connect SDK after initializing environment variables.
3. Initialize environment variables referred to by the CHIP and the nRF Connect
SDK build scripts. Replace _nrfconnect-dir_ with the path to your nRF
@@ -266,6 +257,13 @@ To use the native shell for setup, complete the following steps:
$ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
$ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
+4. Update the nRF Connect SDK to the most recent supported revision by running
+ the following command (replace _chip-dir_ with the path to CHIP repository
+ directory):
+
+ $ cd chip-dir
+ $ python3 scripts/setup/nrfconnect/update_ncs.py --update
+
Now you can proceed with the [Building](#building) instruction.
diff --git a/examples/lock-app/nrfconnect/CMakeLists.txt b/examples/lock-app/nrfconnect/CMakeLists.txt
index b97d0ba9ebc4ac..3b51c837dc18d4 100644
--- a/examples/lock-app/nrfconnect/CMakeLists.txt
+++ b/examples/lock-app/nrfconnect/CMakeLists.txt
@@ -19,9 +19,10 @@ get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connect
get_filename_component(NRFCONNECT_COMMON ${CHIP_ROOT}/examples/platform/nrfconnect REALPATH)
get_filename_component(LOCK_COMMON ${CHIP_ROOT}/examples/lock-app/lock-common REALPATH)
-set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
+include(${CHIP_ROOT}/config/nrfconnect/app/check-nrfconnect-version.cmake)
# Load NCS/Zephyr build system
+set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nrfconnect/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
diff --git a/examples/lock-app/nrfconnect/README.md b/examples/lock-app/nrfconnect/README.md
index 857136bd65e25a..814f0b9e2a3379 100644
--- a/examples/lock-app/nrfconnect/README.md
+++ b/examples/lock-app/nrfconnect/README.md
@@ -89,7 +89,9 @@ with other Thread devices in the network.
## Requirements
-The application requires the nRF Connect SDK v1.5.0 to work correctly.
+The application requires a specific revision of the nRF Connect SDK to work
+correctly. See [Setting up the environment](#setting-up-the-environment) for
+more information.
@@ -176,9 +178,9 @@ using the following command:
$ git submodule update --init
-The example requires the nRF Connect SDK v1.5.0. You can either install it along
-with the related tools directly on your system or use a Docker image that has
-the tools pre-installed.
+The example requires a specific revision of the nRF Connect SDK. You can either
+install it along with the related tools directly on your system or use a Docker
+image that has the tools pre-installed.
If you are a macOS user, you won't be able to use the Docker container to flash
the application onto a Nordic development kit due to
@@ -220,13 +222,11 @@ To use the Docker container for setup, complete the following steps:
- _-e RUNAS=\$(id -u)_ is needed to start the container session as the
current user instead of root.
-4. Check out or update the nRF Connect SDK to the recommended `v1.5.0` version
- by running the following command in the Docker container:
+4. Update the nRF Connect SDK to the most recent supported revision, by running
+ the following command:
- $ setup --ncs v1.5.0
- /var/ncs repository is empty. Do you wish to check out nRF Connect SDK sources [v1.5.0]? [Y/N] y
- ...
- /var/chip repository is initialized, skipping...
+ $ cd /var/chip
+ $ python3 scripts/setup/nrfconnect/update_ncs.py --update
Now you can proceed with the [Building](#building) instruction.
@@ -239,23 +239,14 @@ To use the native shell for setup, complete the following steps:
- [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
- [GN meta-build system](https://gn.googlesource.com/gn/)
-2. Depending on whether you have the nRF Connect SDK installed:
-
- - Follow the
- [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
- in the nRF Connect SDK documentation to install the nRF Connect SDK
- v1.5.0. Since command-line tools will be used for building the example,
- installing SEGGER Embedded Studio is not required.
-
- - If you have an older version of the SDK installed, use the following
- commands to update it to the recommended version. Replace
- _nrfconnect-dir_ with the path to your nRF Connect SDK installation
- directory.
+2. If you do not have the nRF Connect SDK installed, follow the
+ [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
+ in the nRF Connect SDK documentation to install the latest stable nRF
+ Connect SDK version. Since command-line tools will be used for building the
+ example, installing SEGGER Embedded Studio is not required.
- $ cd nrfconnect-dir/nrf
- $ git fetch origin
- $ git checkout v1.5.0
- $ west update
+ If you have the SDK already installed, continue to the next step and update
+ the nRF Connect SDK after initializing environment variables.
3. Initialize environment variables referred to by the CHIP and the nRF Connect
SDK build scripts. Replace _nrfconnect-dir_ with the path to your nRF
@@ -266,6 +257,13 @@ To use the native shell for setup, complete the following steps:
$ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
$ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
+4. Update the nRF Connect SDK to the most recent supported revision by running
+ the following command (replace _chip-dir_ with the path to CHIP repository
+ directory):
+
+ $ cd chip-dir
+ $ python3 scripts/setup/nrfconnect/update_ncs.py --update
+
Now you can proceed with the [Building](#building) instruction.
diff --git a/examples/pigweed-app/nrfconnect/CMakeLists.txt b/examples/pigweed-app/nrfconnect/CMakeLists.txt
index bb956771c7ef5c..eaeb2e3b5140e8 100644
--- a/examples/pigweed-app/nrfconnect/CMakeLists.txt
+++ b/examples/pigweed-app/nrfconnect/CMakeLists.txt
@@ -19,13 +19,13 @@ get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connect
get_filename_component(NRFCONNECT_COMMON ${CHIP_ROOT}/examples/platform/nrfconnect REALPATH)
set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
-set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
+include(${CHIP_ROOT}/config/nrfconnect/app/check-nrfconnect-version.cmake)
+# Load NCS/Zephyr build system
+set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
if(${BOARD} STREQUAL "nrf52840dongle_nrf52840")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-usb_support.conf)
endif()
-
-# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nrfconnect/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
diff --git a/examples/pigweed-app/nrfconnect/README.md b/examples/pigweed-app/nrfconnect/README.md
index d41732a855c99b..00dc0ef929f59e 100644
--- a/examples/pigweed-app/nrfconnect/README.md
+++ b/examples/pigweed-app/nrfconnect/README.md
@@ -64,7 +64,9 @@ other cases.
## Requirements
-The application requires the nRF Connect SDK v1.5.0 to work correctly.
+The application requires a specific revision of the nRF Connect SDK to work
+correctly. See [Setting up the environment](#setting-up-the-environment) for
+more information.
@@ -114,9 +116,9 @@ using the following command:
$ git submodule update --init
-The example requires the nRF Connect SDK v1.5.0. You can either install it along
-with the related tools directly on your system or use a Docker image that has
-the tools pre-installed.
+The example requires a specific revision of the nRF Connect SDK. You can either
+install it along with the related tools directly on your system or use a Docker
+image that has the tools pre-installed.
If you are a macOS user, you won't be able to use the Docker container to flash
the application onto a Nordic development kit due to
@@ -158,13 +160,11 @@ To use the Docker container for setup, complete the following steps:
- _-e RUNAS=\$(id -u)_ is needed to start the container session as the
current user instead of root.
-4. Check out or update the nRF Connect SDK to the recommended `v1.5.0` version
- by running the following command in the Docker container:
+4. Update the nRF Connect SDK to the most recent supported revision, by running
+ the following command:
- $ setup --ncs v1.5.0
- /var/ncs repository is empty. Do you wish to check out nRF Connect SDK sources [v1.5.0]? [Y/N] y
- ...
- /var/chip repository is initialized, skipping...
+ $ cd /var/chip
+ $ python3 scripts/setup/nrfconnect/update_ncs.py --update
Now you can proceed with the [Building](#building) instruction.
@@ -177,23 +177,14 @@ To use the native shell for setup, complete the following steps:
- [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
- [GN meta-build system](https://gn.googlesource.com/gn/)
-2. Depending on whether you have the nRF Connect SDK installed:
-
- - Follow the
- [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
- in the nRF Connect SDK documentation to install the nRF Connect SDK
- v1.5.0. Since command-line tools will be used for building the example,
- installing SEGGER Embedded Studio is not required.
-
- - If you have an older version of the SDK installed, use the following
- commands to update it to the recommended version. Replace
- _nrfconnect-dir_ with the path to your nRF Connect SDK installation
- directory.
+2. If you do not have the nRF Connect SDK installed, follow the
+ [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
+ in the nRF Connect SDK documentation to install the latest stable nRF
+ Connect SDK version. Since command-line tools will be used for building the
+ example, installing SEGGER Embedded Studio is not required.
- $ cd nrfconnect-dir/nrf
- $ git fetch origin
- $ git checkout v1.5.0
- $ west update
+ If you have the SDK already installed, continue to the next step and update
+ the nRF Connect SDK after initializing environment variables.
3. Initialize environment variables referred to by the CHIP and the nRF Connect
SDK build scripts. Replace _nrfconnect-dir_ with the path to your nRF
@@ -204,6 +195,13 @@ To use the native shell for setup, complete the following steps:
$ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
$ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
+4. Update the nRF Connect SDK to the most recent supported revision by running
+ the following command (replace _chip-dir_ with the path to CHIP repository
+ directory):
+
+ $ cd chip-dir
+ $ python3 scripts/setup/nrfconnect/update_ncs.py --update
+
Now you can proceed with the [Building](#building) instruction.
diff --git a/examples/shell/nrfconnect/CMakeLists.txt b/examples/shell/nrfconnect/CMakeLists.txt
index 117eef28b4f4ba..d1e95b9cdb4966 100644
--- a/examples/shell/nrfconnect/CMakeLists.txt
+++ b/examples/shell/nrfconnect/CMakeLists.txt
@@ -18,9 +18,10 @@ cmake_minimum_required(VERSION 3.13.1)
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH)
-set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
+include(${CHIP_ROOT}/config/nrfconnect/app/check-nrfconnect-version.cmake)
# Load NCS/Zephyr build system
+set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nrfconnect/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
diff --git a/scripts/setup/nrfconnect/update_ncs.py b/scripts/setup/nrfconnect/update_ncs.py
new file mode 100755
index 00000000000000..fdd2998bc33243
--- /dev/null
+++ b/scripts/setup/nrfconnect/update_ncs.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+
+#
+# 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.
+#
+
+import argparse
+import os
+import subprocess
+import sys
+
+def get_repository_commit_sha(repository_location):
+ command = ['git', '-C', repository_location, 'rev-parse', 'HEAD']
+ process = subprocess.run(command, check=True, stdout=subprocess.PIPE)
+ return process.stdout.decode('ascii').strip()
+
+def update_ncs(repository_location, revision):
+ # Fetch sdk-nrf to the desired revision.
+ command = ['git', '-C', repository_location, 'fetch']
+ subprocess.run(command, check=True)
+
+ # Checkout sdk-nrf to the desired revision.
+ command = ['git', '-C', repository_location, 'checkout', revision]
+ subprocess.run(command, check=True)
+
+ # Call west update command to update all projects and submodules used by sdk-nrf.
+ command = ['west', 'update', '-r']
+ subprocess.run(command, check=True)
+
+def get_ncs_recommended_revision():
+ chip_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.normpath('../../..')))
+
+ # Read recommended revision saved in the .nrfconnect-recommended-revision file.
+ try:
+ with open(os.path.join(chip_root, 'config/nrfconnect/.nrfconnect-recommended-revision'), 'r') as f:
+ return f.readline().strip()
+ except:
+ raise RuntimeError("Encountered problem when trying to read .nrfconnect-recommended-revision file.")
+
+def print_messages(messages : list, yellow_text : bool):
+ # Add colour formatting if yellow text was set
+ if yellow_text:
+ messages = [f"\33[33m{message}\x1b[0m" for message in messages]
+
+ for message in messages:
+ print(message)
+
+def print_check_revision_warning_message(current_revision, recommended_revision):
+ current_revision_message = f"WARNING: Your current NCS revision ({current_revision})"
+ recommended_revision_message = f"differs from the recommended ({recommended_revision})."
+ allowed_message = "Please be aware that it may lead to encountering unexpected problems."
+ update_message = "Consider updating NCS to the recommended revision, by calling:"
+ call_command_message = os.path.abspath(__file__) + " --update"
+
+ # Get the longest message lenght, to fit warning frame size.
+ longest_message_len = max([len(current_revision_message), len(recommended_revision_message), len(allowed_message), len(update_message), len(call_command_message)])
+
+ # To keep right frame shape the space characters are added to messages shorter than the longest one.
+ fmt = "# {:<%s}#" % (longest_message_len)
+
+ print_messages([(longest_message_len+3)*'#', fmt.format(current_revision_message), fmt.format(recommended_revision_message), fmt.format(''),
+ fmt.format(allowed_message), fmt.format(update_message), fmt.format(call_command_message), (longest_message_len+3)*'#'], sys.stdout.isatty())
+
+def main():
+
+ try:
+ zephyr_base = os.getenv("ZEPHYR_BASE")
+ if not zephyr_base:
+ raise RuntimeError("No ZEPHYR_BASE environment variable found, please set ZEPHYR_BASE to a zephyr repository path.")
+
+ parser = argparse.ArgumentParser(description='Script helping to update nRF Connect SDK to currently recommended revision.')
+ parser.add_argument("-c", "--check", help="Check if your current nRF Connect SDK revision is the same as recommended one.", action="store_true")
+ parser.add_argument("-u", "--update", help="Update your nRF Connect SDK to currently recommended revision.", action="store_true")
+ parser.add_argument("-q", "--quiet", help="Don't print any message if the check succeeds.", action="store_true")
+ args = parser.parse_args()
+
+ ncs_base = os.path.join(zephyr_base, '../nrf')
+ recommended_revision = get_ncs_recommended_revision()
+
+ if args.check:
+ if not args.quiet:
+ print("Checking current nRF Connect SDK revision...")
+
+ current_revision = get_repository_commit_sha(ncs_base)
+
+ if current_revision != recommended_revision:
+ print_check_revision_warning_message(current_revision, recommended_revision)
+ sys.exit(1)
+
+ if not args.quiet:
+ print("Your current version is up to date with the recommended one.")
+
+ if args.update:
+ print("Updating nRF Connect SDK to recommended revision...")
+ update_ncs(ncs_base, recommended_revision)
+
+ except (RuntimeError, subprocess.CalledProcessError) as e:
+ print(e)
+ sys.exit(1)
+
+if __name__ == '__main__':
+ main()
From e6e4d67a049daeb9559bc670a018be33df381de6 Mon Sep 17 00:00:00 2001
From: Andrei Litvin
Date: Thu, 11 Mar 2021 10:59:02 -0500
Subject: [PATCH 02/39] Switch pigweed repo to point to github (#5316)
---
.gitmodules | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.gitmodules b/.gitmodules
index fd9e0b53b12536..bc43cb1814727f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -28,7 +28,7 @@
branch = master
[submodule "pigweed"]
path = third_party/pigweed/repo
- url = https://pigweed.googlesource.com/pigweed/pigweed
+ url = https://github.com/google/pigweed.git
branch = master
[submodule "openthread"]
path = third_party/openthread/repo
From d8a2d1f2e53dc57de4c480f9574121d32799c1e9 Mon Sep 17 00:00:00 2001
From: Yufeng Wang
Date: Thu, 11 Mar 2021 08:20:44 -0800
Subject: [PATCH 03/39] [TE1]: Provide test interface in chip-shell to test
CRMP. (#5228)
---
examples/shell/README.md | 2 +
examples/shell/nrfconnect/CHIPProjectConfig.h | 2 +
examples/shell/shell_common/BUILD.gn | 6 +
examples/shell/shell_common/cmd_ping.cpp | 482 ++++++++++++++++++
.../include/ChipShellCollection.h | 1 +
examples/shell/standalone/main.cpp | 4 +
src/messaging/tests/echo/echo_requester.cpp | 2 +-
src/protocols/echo/Echo.h | 4 +-
src/protocols/echo/EchoClient.cpp | 8 +-
src/transport/SecureSessionMgr.cpp | 10 +
src/transport/SecureSessionMgr.h | 7 +
11 files changed, 522 insertions(+), 6 deletions(-)
create mode 100644 examples/shell/shell_common/cmd_ping.cpp
diff --git a/examples/shell/README.md b/examples/shell/README.md
index 696ab03dec36f4..47d79d0e72fff3 100644
--- a/examples/shell/README.md
+++ b/examples/shell/README.md
@@ -34,6 +34,7 @@ Done
- [exit](#exit)
- [help](#help)
- [otcli](README_OTCLI.md)
+- [ping](#ping)
- [rand](#rand)
- [version](#version)
@@ -51,6 +52,7 @@ Display a list of all top-level commands supported and a brief description.
base64 Base64 encode / decode utilities
device Device Layer commands
otcli Dispatch OpenThread CLI command
+ ping Using Echo Protocol to measure packet loss across network paths
exit Exit the shell application
help List out all top level commands
version Output the software version
diff --git a/examples/shell/nrfconnect/CHIPProjectConfig.h b/examples/shell/nrfconnect/CHIPProjectConfig.h
index 31220b0ac0817c..34387950391ff5 100644
--- a/examples/shell/nrfconnect/CHIPProjectConfig.h
+++ b/examples/shell/nrfconnect/CHIPProjectConfig.h
@@ -33,3 +33,5 @@
// Enable support functions for parsing command-line arguments
#define CHIP_CONFIG_ENABLE_ARG_PARSER 1
+
+#define CHIP_DEVICE_CONFIG_DISABLE_SHELL_PING 1
diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn
index d11a5ae99a9e87..29674db404790e 100644
--- a/examples/shell/shell_common/BUILD.gn
+++ b/examples/shell/shell_common/BUILD.gn
@@ -36,12 +36,18 @@ static_library("shell_common") {
"cmd_device.cpp",
"cmd_misc.cpp",
"cmd_otcli.cpp",
+ "cmd_ping.cpp",
]
public_deps = [
"${chip_root}/src/lib",
+ "${chip_root}/src/lib/core",
"${chip_root}/src/lib/shell",
+ "${chip_root}/src/lib/support",
+ "${chip_root}/src/platform",
+ "${chip_root}/src/protocols",
"${chip_root}/src/setup_payload",
+ "${chip_root}/src/system",
]
if (chip_enable_openthread &&
diff --git a/examples/shell/shell_common/cmd_ping.cpp b/examples/shell/shell_common/cmd_ping.cpp
new file mode 100644
index 00000000000000..afb21bcaf6859b
--- /dev/null
+++ b/examples/shell/shell_common/cmd_ping.cpp
@@ -0,0 +1,482 @@
+/*
+ *
+ * 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.
+ */
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+using namespace chip;
+using namespace Shell;
+using namespace Logging;
+
+constexpr size_t kMaxTcpActiveConnectionCount = 4;
+constexpr size_t kMaxTcpPendingPackets = 4;
+constexpr size_t kNetworkSleepTimeMsecs = (100 * 1000);
+constexpr size_t kDecimalDigitsForUint64 = 20;
+
+namespace {
+
+class PingArguments
+{
+public:
+ void Reset()
+ {
+ mMaxEchoCount = 3;
+ mEchoInterval = 1000;
+ mLastEchoTime = 0;
+ mEchoCount = 0;
+ mEchoRespCount = 0;
+ mWaitingForEchoResp = false;
+ mUsingTCP = false;
+ mUsingCRMP = true;
+ mEchoPort = CHIP_PORT;
+ }
+
+ uint64_t GetLastEchoTime() const { return mLastEchoTime; }
+ void SetLastEchoTime(uint64_t value) { mLastEchoTime = value; }
+
+ uint64_t GetEchoCount() const { return mEchoCount; }
+ void SetEchoCount(uint64_t value) { mEchoCount = value; }
+ void IncrementEchoCount() { mEchoCount++; }
+
+ uint64_t GetEchoRespCount() const { return mEchoRespCount; }
+ void SetEchoRespCount(uint64_t value) { mEchoRespCount = value; }
+ void IncrementEchoRespCount() { mEchoRespCount++; }
+
+ uint32_t GetMaxEchoCount() const { return mMaxEchoCount; }
+ void SetMaxEchoCount(uint32_t id) { mMaxEchoCount = id; }
+
+ uint32_t GetEchoInterval() const { return mEchoInterval; }
+ void SetEchoInterval(uint32_t value) { mEchoInterval = value; }
+
+ uint16_t GetEchoPort() const { return mEchoPort; }
+ void SetEchoPort(uint16_t value) { mEchoPort = value; }
+
+ bool IsWaitingForEchoResp() const { return mWaitingForEchoResp; }
+ void SetWaitingForEchoResp(bool value) { mWaitingForEchoResp = value; }
+
+ bool IsUsingTCP() const { return mUsingTCP; }
+ void SetUsingTCP(bool value) { mUsingTCP = value; }
+
+ bool IsUsingCRMP() const { return mUsingCRMP; }
+ void SetUsingCRMP(bool value) { mUsingCRMP = value; }
+
+private:
+ // The last time a echo request was attempted to be sent.
+ uint64_t mLastEchoTime;
+
+ // Count of the number of echo requests sent.
+ uint64_t mEchoCount;
+
+ // Count of the number of echo responses received.
+ uint64_t mEchoRespCount;
+
+ // Max value for the number of echo requests sent.
+ uint32_t mMaxEchoCount;
+
+ // The CHIP Echo interval time in milliseconds.
+ uint32_t mEchoInterval;
+
+ uint16_t mEchoPort;
+
+ // True, if the echo client is waiting for an echo response
+ // after sending an echo request, false otherwise.
+ bool mWaitingForEchoResp;
+
+ bool mUsingTCP;
+ bool mUsingCRMP;
+} gPingArguments;
+
+constexpr Transport::AdminId gAdminId = 0;
+
+Protocols::Echo::EchoClient gEchoClient;
+TransportMgr gUDPManager;
+TransportMgr> gTCPManager;
+Messaging::ExchangeManager gExchangeManager;
+SecureSessionMgr gSessionManager;
+Inet::IPAddress gDestAddr;
+
+bool EchoIntervalExpired(void)
+{
+ uint64_t now = System::Timer::GetCurrentEpoch();
+
+ return (now >= gPingArguments.GetLastEchoTime() + gPingArguments.GetEchoInterval());
+}
+
+CHIP_ERROR SendEchoRequest(streamer_t * stream)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ Messaging::SendFlags sendFlags;
+ const char kRequestFormat[] = "Echo Message %" PRIu64 "\n";
+ char requestData[(sizeof kRequestFormat) + kDecimalDigitsForUint64];
+ snprintf(requestData, sizeof requestData, kRequestFormat, gPingArguments.GetEchoCount());
+ System::PacketBufferHandle payloadBuf = MessagePacketBuffer::NewWithData(requestData, strlen(requestData));
+
+ if (gPingArguments.IsUsingCRMP())
+ {
+ sendFlags.Set(Messaging::SendMessageFlags::kNone);
+ }
+ else
+ {
+ sendFlags.Set(Messaging::SendMessageFlags::kNoAutoRequestAck);
+ }
+
+ if (payloadBuf.IsNull())
+ {
+ streamer_printf(stream, "Unable to allocate packet buffer\n");
+ return CHIP_ERROR_NO_MEMORY;
+ }
+
+ gPingArguments.SetLastEchoTime(System::Timer::GetCurrentEpoch());
+
+ streamer_printf(stream, "\nSend echo request message to Node: %" PRIu64 "\n", kTestDeviceNodeId);
+
+ err = gEchoClient.SendEchoRequest(std::move(payloadBuf), sendFlags);
+
+ if (err == CHIP_NO_ERROR)
+ {
+ gPingArguments.SetWaitingForEchoResp(true);
+ gPingArguments.IncrementEchoCount();
+ }
+ else
+ {
+ streamer_printf(stream, "Send echo request failed, err: %s\n", ErrorStr(err));
+ }
+
+ return err;
+}
+
+CHIP_ERROR EstablishSecureSession(streamer_t * stream)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ Optional peerAddr;
+ SecurePairingUsingTestSecret * testSecurePairingSecret = chip::Platform::New();
+ VerifyOrExit(testSecurePairingSecret != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ if (gPingArguments.IsUsingTCP())
+ {
+ peerAddr = Optional::Value(Transport::PeerAddress::TCP(gDestAddr, gPingArguments.GetEchoPort()));
+ }
+ else
+ {
+ peerAddr = Optional::Value(
+ Transport::PeerAddress::UDP(gDestAddr, gPingArguments.GetEchoPort(), INET_NULL_INTERFACEID));
+ }
+
+ // Attempt to connect to the peer.
+ err = gSessionManager.NewPairing(peerAddr, kTestDeviceNodeId, testSecurePairingSecret,
+ SecureSessionMgr::PairingDirection::kInitiator, gAdminId);
+
+exit:
+ if (err != CHIP_NO_ERROR)
+ {
+ streamer_printf(stream, "Establish secure session failed, err: %s\n", ErrorStr(err));
+ gPingArguments.SetLastEchoTime(System::Timer::GetCurrentEpoch());
+ }
+ else
+ {
+ streamer_printf(stream, "Establish secure session succeeded\n");
+ }
+
+ return err;
+}
+
+void HandleEchoResponseReceived(Messaging::ExchangeContext * ec, System::PacketBufferHandle payload)
+{
+ uint32_t respTime = System::Timer::GetCurrentEpoch();
+ uint32_t transitTime = respTime - gPingArguments.GetLastEchoTime();
+ streamer_t * sout = streamer_get();
+
+ gPingArguments.SetWaitingForEchoResp(false);
+ gPingArguments.IncrementEchoRespCount();
+
+ streamer_printf(sout, "Echo Response: %" PRIu64 "/%" PRIu64 "(%.2f%%) len=%u time=%.3fms\n", gPingArguments.GetEchoRespCount(),
+ gPingArguments.GetEchoCount(),
+ static_cast(gPingArguments.GetEchoRespCount()) * 100 / gPingArguments.GetEchoCount(),
+ payload->DataLength(), static_cast(transitTime) / 1000);
+}
+
+void DriveIO(streamer_t * stream)
+{
+ struct timeval sleepTime;
+ fd_set readFDs, writeFDs, exceptFDs;
+ int numFDs = 0;
+ int selectRes;
+
+ sleepTime.tv_sec = 0;
+ sleepTime.tv_usec = kNetworkSleepTimeMsecs;
+
+ FD_ZERO(&readFDs);
+ FD_ZERO(&writeFDs);
+ FD_ZERO(&exceptFDs);
+
+ if (chip::DeviceLayer::SystemLayer.State() == chip::System::kLayerState_Initialized)
+ chip::DeviceLayer::SystemLayer.PrepareSelect(numFDs, &readFDs, &writeFDs, &exceptFDs, sleepTime);
+
+ if (chip::DeviceLayer::InetLayer.State == chip::Inet::InetLayer::kState_Initialized)
+ chip::DeviceLayer::InetLayer.PrepareSelect(numFDs, &readFDs, &writeFDs, &exceptFDs, sleepTime);
+
+ selectRes = select(numFDs, &readFDs, &writeFDs, &exceptFDs, &sleepTime);
+ if (selectRes < 0)
+ {
+ streamer_printf(stream, "Select failed: %s\n", chip::ErrorStr(chip::System::MapErrorPOSIX(errno)));
+ return;
+ }
+
+ if (chip::DeviceLayer::SystemLayer.State() == chip::System::kLayerState_Initialized)
+ {
+ chip::DeviceLayer::SystemLayer.HandleSelectResult(selectRes, &readFDs, &writeFDs, &exceptFDs);
+ }
+
+ if (chip::DeviceLayer::InetLayer.State == chip::Inet::InetLayer::kState_Initialized)
+ {
+ chip::DeviceLayer::InetLayer.HandleSelectResult(selectRes, &readFDs, &writeFDs, &exceptFDs);
+ }
+}
+
+void StartPinging(streamer_t * stream, char * destination)
+{
+ CHIP_ERROR err = CHIP_NO_ERROR;
+
+ Transport::AdminPairingTable admins;
+ Transport::AdminPairingInfo * adminInfo = nullptr;
+ uint32_t maxEchoCount = 0;
+
+ if (!Inet::IPAddress::FromString(destination, gDestAddr))
+ {
+ streamer_printf(stream, "Invalid Echo Server IP address: %s\n", destination);
+ ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT);
+ }
+
+ adminInfo = admins.AssignAdminId(gAdminId, kTestControllerNodeId);
+ VerifyOrExit(adminInfo != nullptr, err = CHIP_ERROR_NO_MEMORY);
+
+ err = gTCPManager.Init(Transport::TcpListenParameters(&DeviceLayer::InetLayer)
+ .SetAddressType(Inet::kIPAddressType_IPv4)
+ .SetListenPort(gPingArguments.GetEchoPort() + 1));
+ VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init TCP manager error: %s\r\n", ErrorStr(err)));
+
+ err = gUDPManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer)
+ .SetAddressType(Inet::kIPAddressType_IPv4)
+ .SetListenPort(gPingArguments.GetEchoPort() + 1));
+ VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init UDP manager error: %s\r\n", ErrorStr(err)));
+
+ if (gPingArguments.IsUsingTCP())
+ {
+ err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gTCPManager, &admins);
+ SuccessOrExit(err);
+
+ err = gExchangeManager.Init(kTestControllerNodeId, &gTCPManager, &gSessionManager);
+ SuccessOrExit(err);
+ }
+ else
+ {
+ err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gUDPManager, &admins);
+ SuccessOrExit(err);
+
+ err = gExchangeManager.Init(kTestControllerNodeId, &gUDPManager, &gSessionManager);
+ SuccessOrExit(err);
+ }
+
+ // Start the CHIP connection to the CHIP echo responder.
+ err = EstablishSecureSession(stream);
+ SuccessOrExit(err);
+
+ // TODO: temprary create a SecureSessionHandle from node id to unblock end-to-end test. Complete solution is tracked in PR:4451
+ err = gEchoClient.Init(&gExchangeManager, { kTestDeviceNodeId, 0, gAdminId });
+ SuccessOrExit(err);
+
+ // Arrange to get a callback whenever an Echo Response is received.
+ gEchoClient.SetEchoResponseReceived(HandleEchoResponseReceived);
+
+ maxEchoCount = gPingArguments.GetMaxEchoCount();
+
+ // Connection has been established. Now send the EchoRequests.
+ for (unsigned int i = 0; i < maxEchoCount; i++)
+ {
+ err = SendEchoRequest(stream);
+ if (err != CHIP_NO_ERROR)
+ {
+ streamer_printf(stream, "Send request failed: %s\n", ErrorStr(err));
+ break;
+ }
+
+ // Wait for response until the Echo interval.
+ while (!EchoIntervalExpired())
+ {
+ DriveIO(stream);
+ }
+
+ // Check if expected response was received.
+ if (gPingArguments.IsWaitingForEchoResp())
+ {
+ streamer_printf(stream, "No response received\n");
+ gPingArguments.SetWaitingForEchoResp(false);
+ }
+ }
+
+ gEchoClient.Shutdown();
+ gExchangeManager.Shutdown();
+ gSessionManager.Shutdown();
+
+exit:
+ if ((err != CHIP_NO_ERROR))
+ {
+ streamer_printf(stream, "Ping failed with error: %s\n", ErrorStr(err));
+ }
+}
+
+void PrintUsage(streamer_t * stream)
+{
+ streamer_printf(stream, "Usage: ping [options] \n\nOptions:\n");
+
+ streamer_printf(stream,
+ " -h print help information\n"
+ " -u use UDP (default)\n"
+ " -t use TCP\n"
+ " -p echo server port\n"
+ " -i ping interval time in seconds\n"
+ " -c stop after replies\n"
+ " -r <1|0> enalbe/disable CRMP\n");
+}
+
+int cmd_ping(int argc, char ** argv)
+{
+ streamer_t * sout = streamer_get();
+ int ret = 0;
+ int optIndex = 0;
+
+ gPingArguments.Reset();
+
+ while (optIndex < argc && argv[optIndex][0] == '-')
+ {
+ switch (argv[optIndex][1])
+ {
+ case 'h':
+ PrintUsage(sout);
+ return 0;
+ case 'u':
+ gPingArguments.SetUsingTCP(false);
+ break;
+ case 't':
+ gPingArguments.SetUsingTCP(true);
+ break;
+ case 'i':
+ if (++optIndex >= argc || argv[optIndex][0] == '-')
+ {
+ streamer_printf(sout, "Invalid argument specified for -i\n");
+ return -1;
+ }
+ else
+ {
+ gPingArguments.SetEchoInterval(atol(argv[optIndex]) * 1000);
+ }
+ break;
+ case 'c':
+ if (++optIndex >= argc || argv[optIndex][0] == '-')
+ {
+ streamer_printf(sout, "Invalid argument specified for -c\n");
+ return -1;
+ }
+ else
+ {
+ gPingArguments.SetMaxEchoCount(atol(argv[optIndex]));
+ }
+ break;
+ case 'p':
+ if (++optIndex >= argc || argv[optIndex][0] == '-')
+ {
+ streamer_printf(sout, "Invalid argument specified for -c\n");
+ return -1;
+ }
+ else
+ {
+ gPingArguments.SetEchoPort(atol(argv[optIndex]));
+ }
+ break;
+ case 'r':
+ if (++optIndex >= argc || argv[optIndex][0] == '-')
+ {
+ streamer_printf(sout, "Invalid argument specified for -r\n");
+ return -1;
+ }
+ else
+ {
+ int arg = atoi(argv[optIndex]);
+
+ if (arg == 0)
+ {
+ gPingArguments.SetUsingCRMP(false);
+ }
+ else if (arg == 1)
+ {
+ gPingArguments.SetUsingCRMP(true);
+ }
+ else
+ {
+ ret = -1;
+ }
+ }
+ break;
+ default:
+ ret = -1;
+ }
+
+ optIndex++;
+ }
+
+ if (optIndex >= argc)
+ {
+ streamer_printf(sout, "Missing IP address\n");
+ ret = -1;
+ }
+
+ if (ret == 0)
+ {
+ streamer_printf(sout, "IP address: %s\n", argv[optIndex]);
+ StartPinging(sout, argv[optIndex]);
+ }
+
+ return ret;
+}
+
+} // namespace
+
+static shell_command_t cmds_ping[] = {
+ { &cmd_ping, "ping", "Using Echo Protocol to measure packet loss across network paths" },
+};
+
+void cmd_ping_init()
+{
+ shell_register(cmds_ping, ArraySize(cmds_ping));
+}
diff --git a/examples/shell/shell_common/include/ChipShellCollection.h b/examples/shell/shell_common/include/ChipShellCollection.h
index 3306a4cb03c0a2..1e837d71b4d888 100644
--- a/examples/shell/shell_common/include/ChipShellCollection.h
+++ b/examples/shell/shell_common/include/ChipShellCollection.h
@@ -24,4 +24,5 @@ void cmd_btp_init(void);
void cmd_device_init(void);
void cmd_misc_init(void);
void cmd_otcli_init(void);
+void cmd_ping_init(void);
}
diff --git a/examples/shell/standalone/main.cpp b/examples/shell/standalone/main.cpp
index a6a14f3975e41b..9642f33c34963e 100644
--- a/examples/shell/standalone/main.cpp
+++ b/examples/shell/standalone/main.cpp
@@ -46,6 +46,10 @@ int main()
cmd_btp_init();
cmd_otcli_init();
+#ifndef CHIP_DEVICE_CONFIG_DISABLE_SHELL_PING
+ cmd_ping_init();
+#endif
+
shell_task(nullptr);
return 0;
}
diff --git a/src/messaging/tests/echo/echo_requester.cpp b/src/messaging/tests/echo/echo_requester.cpp
index 275d39dc0d8921..9f0cc44e647b5c 100644
--- a/src/messaging/tests/echo/echo_requester.cpp
+++ b/src/messaging/tests/echo/echo_requester.cpp
@@ -103,7 +103,7 @@ CHIP_ERROR SendEchoRequest(void)
printf("\nSend echo request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId);
- err = gEchoClient.SendEchoRequest(std::move(payloadBuf));
+ err = gEchoClient.SendEchoRequest(std::move(payloadBuf), chip::Messaging::SendFlags(chip::Messaging::SendMessageFlags::kNone));
if (err == CHIP_NO_ERROR)
{
diff --git a/src/protocols/echo/Echo.h b/src/protocols/echo/Echo.h
index cbf0abb6a7627c..271f512f8c48e2 100644
--- a/src/protocols/echo/Echo.h
+++ b/src/protocols/echo/Echo.h
@@ -87,14 +87,14 @@ class DLL_EXPORT EchoClient : public Messaging::ExchangeDelegate
/**
* Send an echo request to a CHIP node.
*
- * @param nodeId The destination's nodeId
* @param payload A PacketBufferHandle with the payload.
+ * @param sendFlags Flags set by the application for the CHIP message being sent.
*
* @return CHIP_ERROR_NO_MEMORY if no ExchangeContext is available.
* Other CHIP_ERROR codes as returned by the lower layers.
*
*/
- CHIP_ERROR SendEchoRequest(System::PacketBufferHandle && payload);
+ CHIP_ERROR SendEchoRequest(System::PacketBufferHandle && payload, const Messaging::SendFlags & sendFlags);
private:
Messaging::ExchangeManager * mExchangeMgr = nullptr;
diff --git a/src/protocols/echo/EchoClient.cpp b/src/protocols/echo/EchoClient.cpp
index 70a9405bcb6bb1..6feeafeca94e80 100644
--- a/src/protocols/echo/EchoClient.cpp
+++ b/src/protocols/echo/EchoClient.cpp
@@ -50,9 +50,12 @@ void EchoClient::Shutdown()
mExchangeCtx->Abort();
mExchangeCtx = nullptr;
}
+
+ OnEchoResponseReceived = nullptr;
+ mExchangeMgr = nullptr;
}
-CHIP_ERROR EchoClient::SendEchoRequest(System::PacketBufferHandle && payload)
+CHIP_ERROR EchoClient::SendEchoRequest(System::PacketBufferHandle && payload, const Messaging::SendFlags & sendFlags)
{
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -72,8 +75,7 @@ CHIP_ERROR EchoClient::SendEchoRequest(System::PacketBufferHandle && payload)
}
// Send an Echo Request message. Discard the exchange context if the send fails.
- err = mExchangeCtx->SendMessage(MsgType::EchoRequest, std::move(payload),
- Messaging::SendFlags(Messaging::SendMessageFlags::kNone));
+ err = mExchangeCtx->SendMessage(MsgType::EchoRequest, std::move(payload), sendFlags);
if (err != CHIP_NO_ERROR)
{
diff --git a/src/transport/SecureSessionMgr.cpp b/src/transport/SecureSessionMgr.cpp
index 95219e5af0b098..8c4cad670ba81e 100644
--- a/src/transport/SecureSessionMgr.cpp
+++ b/src/transport/SecureSessionMgr.cpp
@@ -85,6 +85,16 @@ CHIP_ERROR SecureSessionMgr::Init(NodeId localNodeId, System::Layer * systemLaye
return CHIP_NO_ERROR;
}
+void SecureSessionMgr::Shutdown()
+{
+ mState = State::kNotReady;
+ mLocalNodeId = kUndefinedNodeId;
+ mSystemLayer = nullptr;
+ mTransportMgr = nullptr;
+ mAdmins = nullptr;
+ mCB = nullptr;
+}
+
Transport::Type SecureSessionMgr::GetTransportType(NodeId peerNodeId)
{
PeerConnectionState * state = mPeerConnections.FindPeerConnectionState(peerNodeId, nullptr);
diff --git a/src/transport/SecureSessionMgr.h b/src/transport/SecureSessionMgr.h
index 443262006894f9..eeef685420e596 100644
--- a/src/transport/SecureSessionMgr.h
+++ b/src/transport/SecureSessionMgr.h
@@ -270,6 +270,13 @@ class DLL_EXPORT SecureSessionMgr : public TransportMgrDelegate
CHIP_ERROR Init(NodeId localNodeId, System::Layer * systemLayer, TransportMgrBase * transportMgr,
Transport::AdminPairingTable * admins);
+ /**
+ * @brief
+ * Shutdown the Secure Session Manager. This terminates this instance
+ * of the object and reset it's state.
+ */
+ void Shutdown();
+
/**
* @brief
* Set local node ID
From 8ea423ae5981596e67304ebc7b2e5072b48ba8c8 Mon Sep 17 00:00:00 2001
From: Kevin Schoedel <67607049+kpschoedel@users.noreply.github.com>
Date: Thu, 11 Mar 2021 11:49:18 -0500
Subject: [PATCH 04/39] #### Problem (#5319)
- `BitFlags.h` has relatively unsafe deprecated functions.
- Some bit flags use `enum` rather than type-safe `enum class`.
#### Summary of Changes
- Removed deprecated `SetFlags()`, `ClearFlags()`, and `GetFlags()`,
replacing uses with `BitFlags`.
- BitFlags.h changes:
- Default to use `std::underlying_type` rather than requiring it as a template parameter.
- Added `BitFlags` operations to reduce uses of type-unsafe `Raw()` and `SetRaw()`:
- Multi-argument constructors.
- `operator FlagsEnum()`.
- `ClearAll()`.
- `HasAny()` and `HasAll()`, following the pattern of the existing `HasOnly()`.
- Binary `&`.
- Converted various bit flag types from `enum` to `enum class`:
- BLEEndPoint::ConnectionStateFlags
- BLEEndPoint::TimerStateFlags
- BLEManagerImpl::Flags
- Command::CommandPathFlags
- Encoding::HexFlags
- GenericConfigurationManagerImpl::Flags
- GenericConnectivityManagerImpl_Thread::Flags
- GenericConnectivityManagerImpl_WiFi::ConnectivityFlags
- bdx::RangeControlFlags
- bdx::StatusCode
- bdx::TransferControlFlags
- bdx::TransferRole
Reland of 4b8d5582 (#5232) to a logic error in `*/BLEManagerImpl.cpp` and a large
accidental deletion in `K32W/BLEManagerImpl.cpp`.
---
src/app/Command.cpp | 18 +-
src/app/Command.h | 25 +-
.../tests/integration/chip_im_initiator.cpp | 4 +-
.../tests/integration/chip_im_responder.cpp | 4 +-
.../util/ember-compatibility-functions.cpp | 2 +-
.../templates/chip/CHIPClusters-src.zapt | 2 +-
src/ble/BLEEndPoint.cpp | 107 +++---
src/ble/BLEEndPoint.h | 36 +-
src/ble/BtpEngine.cpp | 47 +--
src/ble/BtpEngine.h | 20 +-
src/controller/CHIPClusters.cpp | 186 +++++-----
src/credentials/CHIPCert.cpp | 39 +-
src/credentials/CHIPCert.h | 64 ++--
src/credentials/CHIPCertFromX509.cpp | 3 +-
src/credentials/CHIPCertToX509.cpp | 19 +-
.../tests/CHIPCert_test_vectors.cpp | 6 +-
src/credentials/tests/CHIPCert_test_vectors.h | 7 +-
src/credentials/tests/TestChipCert.cpp | 114 +++---
.../GenericConfigurationManagerImpl.cpp | 47 ++-
.../GenericConfigurationManagerImpl.h | 18 +-
.../GenericConnectivityManagerImpl_Thread.cpp | 14 +-
.../GenericConnectivityManagerImpl_Thread.h | 19 +-
.../GenericConnectivityManagerImpl_WiFi.h | 10 +-
src/lib/support/BitFlags.h | 233 ++++++++----
src/lib/support/BytesToHex.cpp | 6 +-
src/lib/support/BytesToHex.h | 6 +-
src/messaging/ExchangeContext.h | 4 +-
src/messaging/Flags.h | 6 +-
src/messaging/ReliableMessageContext.cpp | 4 +-
src/messaging/ReliableMessageContext.h | 6 +-
src/platform/EFR32/BLEManagerImpl.cpp | 39 +-
src/platform/EFR32/BLEManagerImpl.h | 22 +-
src/platform/ESP32/BLEManagerImpl.h | 36 +-
.../ESP32/ConnectivityManagerImpl.cpp | 16 +-
src/platform/ESP32/ConnectivityManagerImpl.h | 10 +-
.../ESP32/bluedroid/BLEManagerImpl.cpp | 114 +++---
src/platform/ESP32/nimble/BLEManagerImpl.cpp | 74 ++--
src/platform/K32W/BLEManagerImpl.cpp | 56 ++-
src/platform/K32W/BLEManagerImpl.h | 17 +-
src/platform/Linux/BLEManagerImpl.cpp | 71 ++--
src/platform/Linux/BLEManagerImpl.h | 32 +-
.../Linux/ConnectivityManagerImpl.cpp | 15 +-
src/platform/Linux/ConnectivityManagerImpl.h | 4 +-
src/platform/Linux/bluez/Helper.cpp | 2 +-
src/platform/Zephyr/BLEManagerImpl.cpp | 42 +--
src/platform/Zephyr/BLEManagerImpl.h | 22 +-
src/platform/cc13x2_26x2/BLEManagerImpl.cpp | 55 ++-
src/platform/qpg6100/BLEManagerImpl.cpp | 52 +--
src/platform/qpg6100/BLEManagerImpl.h | 25 +-
src/protocols/bdx/BdxMessages.cpp | 77 ++--
src/protocols/bdx/BdxMessages.h | 56 +--
src/protocols/bdx/BdxTransferSession.cpp | 341 +++++++++---------
src/protocols/bdx/BdxTransferSession.h | 30 +-
src/protocols/bdx/tests/TestBdxMessages.cpp | 9 +-
.../bdx/tests/TestBdxTransferSession.cpp | 180 ++++-----
.../AdditionalDataPayloadGenerator.cpp | 2 +-
.../AdditionalDataPayloadGenerator.h | 2 +-
src/transport/raw/MessageHeader.cpp | 8 +-
src/transport/raw/MessageHeader.h | 8 +-
59 files changed, 1293 insertions(+), 1200 deletions(-)
diff --git a/src/app/Command.cpp b/src/app/Command.cpp
index 110999635d5cf7..432e39b7075070 100644
--- a/src/app/Command.cpp
+++ b/src/app/Command.cpp
@@ -152,18 +152,10 @@ chip::TLV::TLVWriter & Command::CreateCommandDataElementTLVWriter()
return mCommandDataWriter;
}
-CHIP_ERROR Command::AddCommand(chip::EndpointId aEndpintId, chip::GroupId aGroupId, chip::ClusterId aClusterId,
- chip::CommandId aCommandId, uint8_t aFlags)
+CHIP_ERROR Command::AddCommand(chip::EndpointId aEndpointId, chip::GroupId aGroupId, chip::ClusterId aClusterId,
+ chip::CommandId aCommandId, BitFlags aFlags)
{
- CommandParams commandParams;
-
- memset(&commandParams, 0, sizeof(CommandParams));
-
- commandParams.EndpointId = aEndpintId;
- commandParams.GroupId = aGroupId;
- commandParams.ClusterId = aClusterId;
- commandParams.CommandId = aCommandId;
- commandParams.Flags = aFlags;
+ CommandParams commandParams(aEndpointId, aGroupId, aClusterId, aCommandId, aFlags);
return AddCommand(commandParams);
}
@@ -191,12 +183,12 @@ CHIP_ERROR Command::AddCommand(CommandParams & aCommandParams)
CommandDataElement::Builder commandDataElement =
mInvokeCommandBuilder.GetCommandListBuilder().CreateCommandDataElementBuilder();
CommandPath::Builder commandPath = commandDataElement.CreateCommandPathBuilder();
- if (aCommandParams.Flags & kCommandPathFlag_EndpointIdValid)
+ if (aCommandParams.Flags.Has(CommandPathFlags::kEndpointIdValid))
{
commandPath.EndpointId(aCommandParams.EndpointId);
}
- if (aCommandParams.Flags & kCommandPathFlag_GroupIdValid)
+ if (aCommandParams.Flags.Has(CommandPathFlags::kGroupIdValid))
{
commandPath.GroupId(aCommandParams.GroupId);
}
diff --git a/src/app/Command.h b/src/app/Command.h
index 19ebc7d0e43bd6..5103e05514831a 100644
--- a/src/app/Command.h
+++ b/src/app/Command.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2020-2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -59,25 +60,31 @@ class Command
Sending, //< The invoke command message has sent out the invoke command
};
+ enum class CommandPathFlags : uint8_t
+ {
+ kEndpointIdValid = 0x01, /**< Set when the EndpointId field is valid */
+ kGroupIdValid = 0x02, /**< Set when the GroupId field is valid */
+ };
+
/**
* Encapsulates arguments to be passed into SendCommand().
*
*/
struct CommandParams
{
+ CommandParams(chip::EndpointId endpointId, chip::GroupId groupId, chip::ClusterId clusterId, chip::CommandId commandId,
+ const BitFlags & flags) :
+ EndpointId(endpointId),
+ GroupId(groupId), ClusterId(clusterId), CommandId(commandId), Flags(flags)
+ {}
+
chip::EndpointId EndpointId;
chip::GroupId GroupId;
chip::ClusterId ClusterId;
chip::CommandId CommandId;
- uint8_t Flags;
+ BitFlags Flags;
};
- enum CommandPathFlags
- {
- kCommandPathFlag_EndpointIdValid = 0x0001, /**< Set when the EndpointId field is valid */
- kCommandPathFlag_GroupIdValid = 0x0002, /**< Set when the GroupId field is valid */
- } CommandPathFlags;
-
/**
* Initialize the Command object. Within the lifetime
* of this instance, this method is invoked once after object
@@ -110,7 +117,7 @@ class Command
chip::TLV::TLVWriter & CreateCommandDataElementTLVWriter();
CHIP_ERROR AddCommand(chip::EndpointId aEndpintId, chip::GroupId aGroupId, chip::ClusterId aClusterId,
- chip::CommandId aCommandId, uint8_t Flags);
+ chip::CommandId aCommandId, BitFlags Flags);
CHIP_ERROR AddCommand(CommandParams & aCommandParams);
CHIP_ERROR AddStatusCode(const uint16_t aGeneralCode, const uint32_t aProtocolId, const uint16_t aProtocolCode,
const chip::ClusterId aClusterId);
diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp
index c35de4bc95a86e..a536fa9e263ca9 100644
--- a/src/app/tests/integration/chip_im_initiator.cpp
+++ b/src/app/tests/integration/chip_im_initiator.cpp
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2020-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.
@@ -90,7 +90,7 @@ CHIP_ERROR SendCommandRequest(void)
kTestGroupId, // GroupId
kTestClusterId, // ClusterId
kTestCommandId, // CommandId
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
// Add command data here
diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp
index bde7daf7610907..f4f3d3dfcbb57f 100644
--- a/src/app/tests/integration/chip_im_responder.cpp
+++ b/src/app/tests/integration/chip_im_responder.cpp
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2020-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.
@@ -60,7 +60,7 @@ void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aC
kTestGroupId, // GroupId
kTestClusterId, // ClusterId
kTestCommandId, // CommandId
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
// Add command data here
diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp
index 017d7a0d5df228..981ec253e6fffc 100644
--- a/src/app/util/ember-compatibility-functions.cpp
+++ b/src/app/util/ember-compatibility-functions.cpp
@@ -73,7 +73,7 @@ bool IMEmberAfSendDefaultResponseWithCallback(EmberAfStatus status)
0, // GroupId
imCompatibilityEmberApsFrame.clusterId,
imCompatibilityEmberAfCluster.commandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
chip::TLV::TLVType dummyType = chip::TLV::kTLVType_NotSpecified;
chip::TLV::TLVWriter writer = currentCommandObject->CreateCommandDataElementTLVWriter();
diff --git a/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt b/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt
index bcfa34eca00cb4..b06cb3c7832109 100644
--- a/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt
+++ b/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt
@@ -26,7 +26,7 @@ CHIP_ERROR {{asCamelCased clusterName false}}Cluster::{{asCamelCased name false}
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, k{{asCamelCased name false}}CommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
diff --git a/src/ble/BLEEndPoint.cpp b/src/ble/BLEEndPoint.cpp
index 6abdb70877ffe8..aaf0d52c7aec3f 100644
--- a/src/ble/BLEEndPoint.cpp
+++ b/src/ble/BLEEndPoint.cpp
@@ -272,7 +272,7 @@ void BLEEndPoint::HandleSubscribeReceived()
void BLEEndPoint::HandleSubscribeComplete()
{
ChipLogProgress(Ble, "subscribe complete, ep = %p", this);
- SetFlag(mConnStateFlags, kConnState_GattOperationInFlight, false);
+ mConnStateFlags.Clear(ConnectionStateFlag::kGattOperationInFlight);
BLE_ERROR err = DriveSending();
@@ -295,7 +295,7 @@ bool BLEEndPoint::IsConnected(uint8_t state) const
bool BLEEndPoint::IsUnsubscribePending() const
{
- return (GetFlag(mTimerStateFlags, kTimerState_UnsubscribeTimerRunning));
+ return mTimerStateFlags.Has(TimerStateFlag::kUnsubscribeTimerRunning);
}
void BLEEndPoint::Abort()
@@ -392,7 +392,7 @@ void BLEEndPoint::FinalizeClose(uint8_t oldState, uint8_t flags, BLE_ERROR err)
}
else // Otherwise, try to signal close to remote device before end point releases BLE connection and frees itself.
{
- if (mRole == kBleRole_Central && GetFlag(mConnStateFlags, kConnState_DidBeginSubscribe))
+ if (mRole == kBleRole_Central && mConnStateFlags.Has(ConnectionStateFlag::kDidBeginSubscribe))
{
// Cancel send and receive-ack timers, if running.
StopAckReceivedTimer();
@@ -420,10 +420,10 @@ void BLEEndPoint::FinalizeClose(uint8_t oldState, uint8_t flags, BLE_ERROR err)
}
// Mark unsubscribe GATT operation in progress.
- SetFlag(mConnStateFlags, kConnState_GattOperationInFlight, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kGattOperationInFlight);
}
}
- else // mRole == kBleRole_Peripheral, OR GetFlag(mTimerStateFlags, kConnState_DidBeginSubscribe) == false...
+ else // mRole == kBleRole_Peripheral, OR mTimerStateFlags.Has(ConnectionStateFlag::kDidBeginSubscribe) == false...
{
Free();
}
@@ -456,7 +456,7 @@ void BLEEndPoint::ReleaseBleConnection()
{
if (mConnObj != BLE_CONNECTION_UNINITIALIZED)
{
- if (GetFlag(mConnStateFlags, kConnState_AutoClose))
+ if (mConnStateFlags.Has(ConnectionStateFlag::kAutoClose))
{
ChipLogProgress(Ble, "Auto-closing end point's BLE connection.");
mBle->mPlatformDelegate->CloseConnection(mConnObj);
@@ -562,11 +562,10 @@ BLE_ERROR BLEEndPoint::Init(BleLayer * bleLayer, BLE_CONNECTION_OBJECT connObj,
mRefCount = 1;
// BLEEndPoint data members:
- mConnObj = connObj;
- mRole = role;
- mConnStateFlags = 0;
- mTimerStateFlags = 0;
- SetFlag(mConnStateFlags, kConnState_AutoClose, autoClose);
+ mConnObj = connObj;
+ mRole = role;
+ mTimerStateFlags.ClearAll();
+ mConnStateFlags.ClearAll().Set(ConnectionStateFlag::kAutoClose, autoClose);
mLocalReceiveWindowSize = 0;
mRemoteReceiveWindowSize = 0;
mReceiveWindowMaxSize = 0;
@@ -686,7 +685,7 @@ BLE_ERROR BLEEndPoint::Send(PacketBufferHandle data)
bool BLEEndPoint::PrepareNextFragment(PacketBufferHandle && data, bool & sentAck)
{
// If we have a pending fragment acknowledgement to send, piggyback it on the fragment we're about to transmit.
- if (GetFlag(mTimerStateFlags, kTimerState_SendAckTimerRunning))
+ if (mTimerStateFlags.Has(TimerStateFlag::kSendAckTimerRunning))
{
// Reset local receive window counter.
mLocalReceiveWindowSize = mReceiveWindowMaxSize;
@@ -818,10 +817,10 @@ BLE_ERROR BLEEndPoint::HandleHandshakeConfirmationReceived()
err = BLE_ERROR_GATT_SUBSCRIBE_FAILED);
// We just sent a GATT subscribe request, so make sure to attempt unsubscribe on close.
- SetFlag(mConnStateFlags, kConnState_DidBeginSubscribe, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kDidBeginSubscribe);
// Mark GATT operation in progress for subscribe request.
- SetFlag(mConnStateFlags, kConnState_GattOperationInFlight, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kGattOperationInFlight);
}
else // (mRole == kBleRole_Peripheral), verified on Init
{
@@ -882,12 +881,12 @@ BLE_ERROR BLEEndPoint::HandleFragmentConfirmationReceived()
// TODO Packet buffer high water mark optimization: if ack pending, but fragmenter state == complete, free fragmenter's
// tx buf before sending ack.
- if (GetFlag(mConnStateFlags, kConnState_StandAloneAckInFlight))
+ if (mConnStateFlags.Has(ConnectionStateFlag::kStandAloneAckInFlight))
{
// If confirmation was received for stand-alone ack, free its tx buffer.
mAckToSend = nullptr;
- SetFlag(mConnStateFlags, kConnState_StandAloneAckInFlight, false);
+ mConnStateFlags.Clear(ConnectionStateFlag::kStandAloneAckInFlight);
}
// If local receive window size has shrunk to or below immediate ack threshold, AND a message fragment is not
@@ -922,12 +921,12 @@ BLE_ERROR BLEEndPoint::HandleGattSendConfirmationReceived()
ChipLogDebugBleEndPoint(Ble, "entered HandleGattSendConfirmationReceived");
// Mark outstanding GATT operation as finished.
- SetFlag(mConnStateFlags, kConnState_GattOperationInFlight, false);
+ mConnStateFlags.Clear(ConnectionStateFlag::kGattOperationInFlight);
// If confirmation was for outbound portion of BTP connect handshake...
- if (!GetFlag(mConnStateFlags, kConnState_CapabilitiesConfReceived))
+ if (!mConnStateFlags.Has(ConnectionStateFlag::kCapabilitiesConfReceived))
{
- SetFlag(mConnStateFlags, kConnState_CapabilitiesConfReceived, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kCapabilitiesConfReceived);
return HandleHandshakeConfirmationReceived();
}
@@ -970,7 +969,7 @@ BLE_ERROR BLEEndPoint::DoSendStandAloneAck()
mLocalReceiveWindowSize = mReceiveWindowMaxSize;
ChipLogDebugBleEndPoint(Ble, "reset local rx window on stand-alone ack tx, size = %u", mLocalReceiveWindowSize);
- SetFlag(mConnStateFlags, kConnState_StandAloneAckInFlight, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kStandAloneAckInFlight);
// Start ack received timer, if it's not already running.
err = StartAckReceivedTimer();
@@ -989,12 +988,12 @@ BLE_ERROR BLEEndPoint::DriveSending()
// If receiver's window is almost closed and we don't have an ack to send, OR we do have an ack to send but
// receiver's window is completely empty, OR another GATT operation is in flight, awaiting confirmation...
if ((mRemoteReceiveWindowSize <= BTP_WINDOW_NO_ACK_SEND_THRESHOLD &&
- !GetFlag(mTimerStateFlags, kTimerState_SendAckTimerRunning) && mAckToSend.IsNull()) ||
- (mRemoteReceiveWindowSize == 0) || (GetFlag(mConnStateFlags, kConnState_GattOperationInFlight)))
+ !mTimerStateFlags.Has(TimerStateFlag::kSendAckTimerRunning) && mAckToSend.IsNull()) ||
+ (mRemoteReceiveWindowSize == 0) || (mConnStateFlags.Has(ConnectionStateFlag::kGattOperationInFlight)))
{
#ifdef CHIP_BLE_END_POINT_DEBUG_LOGGING_ENABLED
if (mRemoteReceiveWindowSize <= BTP_WINDOW_NO_ACK_SEND_THRESHOLD &&
- !GetFlag(mTimerStateFlags, kTimerState_SendAckTimerRunning) && mAckToSend == NULL)
+ !mTimerStateFlags.Has(TimerStateFlag::kSendAckTimerRunning) && mAckToSend == NULL)
{
ChipLogDebugBleEndPoint(Ble, "NO SEND: receive window almost closed, and no ack to send");
}
@@ -1004,7 +1003,7 @@ BLE_ERROR BLEEndPoint::DriveSending()
ChipLogDebugBleEndPoint(Ble, "NO SEND: remote receive window closed");
}
- if (GetFlag(mConnStateFlags, kConnState_GattOperationInFlight))
+ if (mConnStateFlags.Has(ConnectionStateFlag::kGattOperationInFlight))
{
ChipLogDebugBleEndPoint(Ble, "NO SEND: Gatt op in flight");
}
@@ -1273,13 +1272,13 @@ BLE_ERROR BLEEndPoint::Receive(PacketBufferHandle data)
}
// If we're receiving the first inbound packet of a BLE transport connection handshake...
- if (!GetFlag(mConnStateFlags, kConnState_CapabilitiesMsgReceived))
+ if (!mConnStateFlags.Has(ConnectionStateFlag::kCapabilitiesMsgReceived))
{
if (mRole == kBleRole_Central) // If we're a central receiving a capabilities response indication...
{
// Ensure end point's in the right state before continuing.
VerifyOrExit(mState == kState_Connecting, err = BLE_ERROR_INCORRECT_STATE);
- SetFlag(mConnStateFlags, kConnState_CapabilitiesMsgReceived, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kCapabilitiesMsgReceived);
err = HandleCapabilitiesResponseReceived(std::move(data));
SuccessOrExit(err);
@@ -1288,7 +1287,7 @@ BLE_ERROR BLEEndPoint::Receive(PacketBufferHandle data)
{
// Ensure end point's in the right state before continuing.
VerifyOrExit(mState == kState_Ready, err = BLE_ERROR_INCORRECT_STATE);
- SetFlag(mConnStateFlags, kConnState_CapabilitiesMsgReceived, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kCapabilitiesMsgReceived);
err = HandleCapabilitiesRequestReceived(std::move(data));
@@ -1391,7 +1390,7 @@ BLE_ERROR BLEEndPoint::Receive(PacketBufferHandle data)
if (mBtpEngine.HasUnackedData())
{
if (mLocalReceiveWindowSize <= BLE_CONFIG_IMMEDIATE_ACK_WINDOW_THRESHOLD &&
- !GetFlag(mConnStateFlags, kConnState_GattOperationInFlight))
+ !mConnStateFlags.Has(ConnectionStateFlag::kGattOperationInFlight))
{
ChipLogDebugBleEndPoint(Ble, "sending immediate ack");
err = DriveStandAloneAck();
@@ -1446,14 +1445,14 @@ BLE_ERROR BLEEndPoint::Receive(PacketBufferHandle data)
bool BLEEndPoint::SendWrite(PacketBufferHandle && buf)
{
- SetFlag(mConnStateFlags, kConnState_GattOperationInFlight, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kGattOperationInFlight);
return mBle->mPlatformDelegate->SendWriteRequest(mConnObj, &CHIP_BLE_SVC_ID, &mBle->CHIP_BLE_CHAR_1_ID, std::move(buf));
}
bool BLEEndPoint::SendIndication(PacketBufferHandle && buf)
{
- SetFlag(mConnStateFlags, kConnState_GattOperationInFlight, true);
+ mConnStateFlags.Set(ConnectionStateFlag::kGattOperationInFlight);
return mBle->mPlatformDelegate->SendIndication(mConnObj, &CHIP_BLE_SVC_ID, &mBle->CHIP_BLE_CHAR_2_ID, std::move(buf));
}
@@ -1465,7 +1464,7 @@ BLE_ERROR BLEEndPoint::StartConnectTimer()
timerErr = mBle->mSystemLayer->StartTimer(BLE_CONNECT_TIMEOUT_MS, HandleConnectTimeout, this);
VerifyOrExit(timerErr == CHIP_SYSTEM_NO_ERROR, err = BLE_ERROR_START_TIMER_FAILED);
- SetFlag(mTimerStateFlags, kTimerState_ConnectTimerRunning, true);
+ mTimerStateFlags.Set(TimerStateFlag::kConnectTimerRunning);
exit:
return err;
@@ -1478,7 +1477,7 @@ BLE_ERROR BLEEndPoint::StartReceiveConnectionTimer()
timerErr = mBle->mSystemLayer->StartTimer(BLE_CONNECT_TIMEOUT_MS, HandleReceiveConnectionTimeout, this);
VerifyOrExit(timerErr == CHIP_SYSTEM_NO_ERROR, err = BLE_ERROR_START_TIMER_FAILED);
- SetFlag(mTimerStateFlags, kTimerState_ReceiveConnectionTimerRunning, true);
+ mTimerStateFlags.Set(TimerStateFlag::kReceiveConnectionTimerRunning);
exit:
return err;
@@ -1489,12 +1488,12 @@ BLE_ERROR BLEEndPoint::StartAckReceivedTimer()
BLE_ERROR err = BLE_NO_ERROR;
chip::System::Error timerErr;
- if (!GetFlag(mTimerStateFlags, kTimerState_AckReceivedTimerRunning))
+ if (!mTimerStateFlags.Has(TimerStateFlag::kAckReceivedTimerRunning))
{
timerErr = mBle->mSystemLayer->StartTimer(BTP_ACK_RECEIVED_TIMEOUT_MS, HandleAckReceivedTimeout, this);
VerifyOrExit(timerErr == CHIP_SYSTEM_NO_ERROR, err = BLE_ERROR_START_TIMER_FAILED);
- SetFlag(mTimerStateFlags, kTimerState_AckReceivedTimerRunning, true);
+ mTimerStateFlags.Set(TimerStateFlag::kAckReceivedTimerRunning);
}
exit:
@@ -1505,7 +1504,7 @@ BLE_ERROR BLEEndPoint::RestartAckReceivedTimer()
{
BLE_ERROR err = BLE_NO_ERROR;
- VerifyOrExit(GetFlag(mTimerStateFlags, kTimerState_AckReceivedTimerRunning), err = BLE_ERROR_INCORRECT_STATE);
+ VerifyOrExit(mTimerStateFlags.Has(TimerStateFlag::kAckReceivedTimerRunning), err = BLE_ERROR_INCORRECT_STATE);
StopAckReceivedTimer();
@@ -1523,13 +1522,13 @@ BLE_ERROR BLEEndPoint::StartSendAckTimer()
ChipLogDebugBleEndPoint(Ble, "entered StartSendAckTimer");
- if (!GetFlag(mTimerStateFlags, kTimerState_SendAckTimerRunning))
+ if (!mTimerStateFlags.Has(TimerStateFlag::kSendAckTimerRunning))
{
ChipLogDebugBleEndPoint(Ble, "starting new SendAckTimer");
timerErr = mBle->mSystemLayer->StartTimer(BTP_ACK_SEND_TIMEOUT_MS, HandleSendAckTimeout, this);
VerifyOrExit(timerErr == CHIP_SYSTEM_NO_ERROR, err = BLE_ERROR_START_TIMER_FAILED);
- SetFlag(mTimerStateFlags, kTimerState_SendAckTimerRunning, true);
+ mTimerStateFlags.Set(TimerStateFlag::kSendAckTimerRunning);
}
exit:
@@ -1543,7 +1542,7 @@ BLE_ERROR BLEEndPoint::StartUnsubscribeTimer()
timerErr = mBle->mSystemLayer->StartTimer(BLE_UNSUBSCRIBE_TIMEOUT_MS, HandleUnsubscribeTimeout, this);
VerifyOrExit(timerErr == CHIP_SYSTEM_NO_ERROR, err = BLE_ERROR_START_TIMER_FAILED);
- SetFlag(mTimerStateFlags, kTimerState_UnsubscribeTimerRunning, true);
+ mTimerStateFlags.Set(TimerStateFlag::kUnsubscribeTimerRunning);
exit:
return err;
@@ -1553,35 +1552,35 @@ void BLEEndPoint::StopConnectTimer()
{
// Cancel any existing connect timer.
mBle->mSystemLayer->CancelTimer(HandleConnectTimeout, this);
- SetFlag(mTimerStateFlags, kTimerState_ConnectTimerRunning, false);
+ mTimerStateFlags.Clear(TimerStateFlag::kConnectTimerRunning);
}
void BLEEndPoint::StopReceiveConnectionTimer()
{
// Cancel any existing receive connection timer.
mBle->mSystemLayer->CancelTimer(HandleReceiveConnectionTimeout, this);
- SetFlag(mTimerStateFlags, kTimerState_ReceiveConnectionTimerRunning, false);
+ mTimerStateFlags.Clear(TimerStateFlag::kReceiveConnectionTimerRunning);
}
void BLEEndPoint::StopAckReceivedTimer()
{
// Cancel any existing ack-received timer.
mBle->mSystemLayer->CancelTimer(HandleAckReceivedTimeout, this);
- SetFlag(mTimerStateFlags, kTimerState_AckReceivedTimerRunning, false);
+ mTimerStateFlags.Clear(TimerStateFlag::kAckReceivedTimerRunning);
}
void BLEEndPoint::StopSendAckTimer()
{
// Cancel any existing send-ack timer.
mBle->mSystemLayer->CancelTimer(HandleSendAckTimeout, this);
- SetFlag(mTimerStateFlags, kTimerState_SendAckTimerRunning, false);
+ mTimerStateFlags.Clear(TimerStateFlag::kSendAckTimerRunning);
}
void BLEEndPoint::StopUnsubscribeTimer()
{
// Cancel any existing unsubscribe timer.
mBle->mSystemLayer->CancelTimer(HandleUnsubscribeTimeout, this);
- SetFlag(mTimerStateFlags, kTimerState_UnsubscribeTimerRunning, false);
+ mTimerStateFlags.Clear(TimerStateFlag::kUnsubscribeTimerRunning);
}
void BLEEndPoint::HandleConnectTimeout(chip::System::Layer * systemLayer, void * appState, chip::System::Error err)
@@ -1589,10 +1588,10 @@ void BLEEndPoint::HandleConnectTimeout(chip::System::Layer * systemLayer, void *
BLEEndPoint * ep = static_cast(appState);
// Check for event-based timer race condition.
- if (GetFlag(ep->mTimerStateFlags, kTimerState_ConnectTimerRunning))
+ if (ep->mTimerStateFlags.Has(TimerStateFlag::kConnectTimerRunning))
{
ChipLogError(Ble, "connect handshake timed out, closing ep %p", ep);
- SetFlag(ep->mTimerStateFlags, kTimerState_ConnectTimerRunning, false);
+ ep->mTimerStateFlags.Clear(TimerStateFlag::kConnectTimerRunning);
ep->DoClose(kBleCloseFlag_AbortTransmission, BLE_ERROR_CONNECT_TIMED_OUT);
}
}
@@ -1602,10 +1601,10 @@ void BLEEndPoint::HandleReceiveConnectionTimeout(chip::System::Layer * systemLay
BLEEndPoint * ep = static_cast(appState);
// Check for event-based timer race condition.
- if (GetFlag(ep->mTimerStateFlags, kTimerState_ReceiveConnectionTimerRunning))
+ if (ep->mTimerStateFlags.Has(TimerStateFlag::kReceiveConnectionTimerRunning))
{
ChipLogError(Ble, "receive handshake timed out, closing ep %p", ep);
- SetFlag(ep->mTimerStateFlags, kTimerState_ReceiveConnectionTimerRunning, false);
+ ep->mTimerStateFlags.Clear(TimerStateFlag::kReceiveConnectionTimerRunning);
ep->DoClose(kBleCloseFlag_SuppressCallback | kBleCloseFlag_AbortTransmission, BLE_ERROR_RECEIVE_TIMED_OUT);
}
}
@@ -1615,11 +1614,11 @@ void BLEEndPoint::HandleAckReceivedTimeout(chip::System::Layer * systemLayer, vo
BLEEndPoint * ep = static_cast(appState);
// Check for event-based timer race condition.
- if (GetFlag(ep->mTimerStateFlags, kTimerState_AckReceivedTimerRunning))
+ if (ep->mTimerStateFlags.Has(TimerStateFlag::kAckReceivedTimerRunning))
{
ChipLogError(Ble, "ack recv timeout, closing ep %p", ep);
ep->mBtpEngine.LogStateDebug();
- SetFlag(ep->mTimerStateFlags, kTimerState_AckReceivedTimerRunning, false);
+ ep->mTimerStateFlags.Clear(TimerStateFlag::kAckReceivedTimerRunning);
ep->DoClose(kBleCloseFlag_AbortTransmission, BLE_ERROR_FRAGMENT_ACK_TIMED_OUT);
}
}
@@ -1629,12 +1628,12 @@ void BLEEndPoint::HandleSendAckTimeout(chip::System::Layer * systemLayer, void *
BLEEndPoint * ep = static_cast(appState);
// Check for event-based timer race condition.
- if (GetFlag(ep->mTimerStateFlags, kTimerState_SendAckTimerRunning))
+ if (ep->mTimerStateFlags.Has(TimerStateFlag::kSendAckTimerRunning))
{
- SetFlag(ep->mTimerStateFlags, kTimerState_SendAckTimerRunning, false);
+ ep->mTimerStateFlags.Clear(TimerStateFlag::kSendAckTimerRunning);
// If previous stand-alone ack isn't still in flight...
- if (!GetFlag(ep->mConnStateFlags, kConnState_StandAloneAckInFlight))
+ if (!ep->mConnStateFlags.Has(ConnectionStateFlag::kStandAloneAckInFlight))
{
BLE_ERROR sendErr = ep->DriveStandAloneAck();
@@ -1651,10 +1650,10 @@ void BLEEndPoint::HandleUnsubscribeTimeout(chip::System::Layer * systemLayer, vo
BLEEndPoint * ep = static_cast(appState);
// Check for event-based timer race condition.
- if (GetFlag(ep->mTimerStateFlags, kTimerState_UnsubscribeTimerRunning))
+ if (ep->mTimerStateFlags.Has(TimerStateFlag::kUnsubscribeTimerRunning))
{
ChipLogError(Ble, "unsubscribe timed out, ble ep %p", ep);
- SetFlag(ep->mTimerStateFlags, kTimerState_UnsubscribeTimerRunning, false);
+ ep->mTimerStateFlags.Clear(TimerStateFlag::kUnsubscribeTimerRunning);
ep->HandleUnsubscribeComplete();
}
}
diff --git a/src/ble/BLEEndPoint.h b/src/ble/BLEEndPoint.h
index 36daf0de7af5ff..cc1aa3a03119d7 100644
--- a/src/ble/BLEEndPoint.h
+++ b/src/ble/BLEEndPoint.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2014-2017 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -107,26 +107,26 @@ class DLL_EXPORT BLEEndPoint : public BleLayerObject
private:
// Private data members:
- enum ConnectionStateFlags
+ enum class ConnectionStateFlag : uint8_t
{
- kConnState_AutoClose = 0x01, // End point should close underlying BLE conn on BTP close.
- kConnState_CapabilitiesConfReceived = 0x02, // GATT confirmation received for sent capabilities req/resp.
- kConnState_CapabilitiesMsgReceived = 0x04, // Capabilities request or response message received.
- kConnState_DidBeginSubscribe = 0x08, // GATT subscribe request sent; must unsubscribe on close.
- kConnState_StandAloneAckInFlight = 0x10, // Stand-alone ack in flight, awaiting GATT confirmation.
- kConnState_GattOperationInFlight = 0x20 // GATT write, indication, subscribe, or unsubscribe in flight,
- // awaiting GATT confirmation.
+ kAutoClose = 0x01, // End point should close underlying BLE conn on BTP close.
+ kCapabilitiesConfReceived = 0x02, // GATT confirmation received for sent capabilities req/resp.
+ kCapabilitiesMsgReceived = 0x04, // Capabilities request or response message received.
+ kDidBeginSubscribe = 0x08, // GATT subscribe request sent; must unsubscribe on close.
+ kStandAloneAckInFlight = 0x10, // Stand-alone ack in flight, awaiting GATT confirmation.
+ kGattOperationInFlight = 0x20 // GATT write, indication, subscribe, or unsubscribe in flight,
+ // awaiting GATT confirmation.
};
- enum TimerStateFlags
+ enum class TimerStateFlag : uint8_t
{
- kTimerState_ConnectTimerRunning = 0x01, // BTP connect completion timer running.
- kTimerState_ReceiveConnectionTimerRunning = 0x02, // BTP receive connection completion timer running.
- kTimerState_AckReceivedTimerRunning = 0x04, // Ack received timer running due to unacked sent fragment.
- kTimerState_SendAckTimerRunning = 0x08, // Send ack timer running; indicates pending ack to send.
- kTimerState_UnsubscribeTimerRunning = 0x10, // Unsubscribe completion timer running.
+ kConnectTimerRunning = 0x01, // BTP connect completion timer running.
+ kReceiveConnectionTimerRunning = 0x02, // BTP receive connection completion timer running.
+ kAckReceivedTimerRunning = 0x04, // Ack received timer running due to unacked sent fragment.
+ kSendAckTimerRunning = 0x08, // Send ack timer running; indicates pending ack to send.
+ kUnsubscribeTimerRunning = 0x10, // Unsubscribe completion timer running.
#if CHIP_ENABLE_CHIPOBLE_TEST
- kTimerState_UnderTestTimerRunnung = 0x80 // running throughput Tx test
+ kUnderTestTimerRunnung = 0x80 // running throughput Tx test
#endif
};
@@ -147,8 +147,8 @@ class DLL_EXPORT BLEEndPoint : public BleLayerObject
BtpEngine mBtpEngine;
BleRole mRole;
- uint8_t mConnStateFlags;
- uint8_t mTimerStateFlags;
+ BitFlags mConnStateFlags;
+ BitFlags mTimerStateFlags;
SequenceNumber_t mLocalReceiveWindowSize;
SequenceNumber_t mRemoteReceiveWindowSize;
SequenceNumber_t mReceiveWindowMaxSize;
diff --git a/src/ble/BtpEngine.cpp b/src/ble/BtpEngine.cpp
index ef83b90a7133b7..4b62c98c2139e1 100644
--- a/src/ble/BtpEngine.cpp
+++ b/src/ble/BtpEngine.cpp
@@ -55,10 +55,10 @@ static inline void IncSeqNum(SequenceNumber_t & a_seq_num)
a_seq_num = static_cast(0xff & ((a_seq_num) + 1));
}
-static inline bool DidReceiveData(uint8_t rx_flags)
+static inline bool DidReceiveData(BitFlags rx_flags)
{
- return (GetFlag(rx_flags, BtpEngine::kHeaderFlag_StartMessage) || GetFlag(rx_flags, BtpEngine::kHeaderFlag_ContinueMessage) ||
- GetFlag(rx_flags, BtpEngine::kHeaderFlag_EndMessage));
+ return rx_flags.HasAny(BtpEngine::HeaderFlags::kStartMessage, BtpEngine::HeaderFlags::kContinueMessage,
+ BtpEngine::HeaderFlags::kEndMessage);
}
static void PrintBufDebug(const System::PacketBufferHandle & buf)
@@ -213,7 +213,7 @@ BLE_ERROR BtpEngine::EncodeStandAloneAck(const PacketBufferHandle & data)
characteristic = data->Start();
// Since there's no preexisting message payload, we can write BTP header without adjusting data start pointer.
- characteristic[0] = kHeaderFlag_FragmentAck;
+ characteristic[0] = static_cast(HeaderFlags::kFragmentAck);
// Acknowledge most recently received sequence number.
characteristic[1] = GetAndRecordRxAckSeqNum();
@@ -245,8 +245,8 @@ BLE_ERROR BtpEngine::EncodeStandAloneAck(const PacketBufferHandle & data)
BLE_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle data, SequenceNumber_t & receivedAck,
bool & didReceiveAck)
{
- BLE_ERROR err = BLE_NO_ERROR;
- uint8_t rx_flags = 0;
+ BLE_ERROR err = BLE_NO_ERROR;
+ BitFlags rx_flags;
// BLE data uses little-endian byte order.
Encoding::LittleEndian::Reader reader(data->Start(), data->DataLength());
@@ -255,15 +255,15 @@ BLE_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle dat
mRxCharCount++;
// Get header flags, always in first byte.
- VerifyOrExit(reader.Read8(&rx_flags).StatusCode() == CHIP_NO_ERROR, err = BLE_ERROR_MESSAGE_INCOMPLETE);
+ VerifyOrExit(reader.Read8(rx_flags.RawStorage()).StatusCode() == CHIP_NO_ERROR, err = BLE_ERROR_MESSAGE_INCOMPLETE);
#if CHIP_ENABLE_CHIPOBLE_TEST
- if (GetFlag(rx_flags, kHeaderFlag_CommandMessage))
+ if (rx_flags.Has(HeaderFlags::kCommandMessage))
SetRxPacketType(kType_Control);
else
SetRxPacketType(kType_Data);
#endif
- didReceiveAck = GetFlag(rx_flags, kHeaderFlag_FragmentAck);
+ didReceiveAck = rx_flags.Has(HeaderFlags::kFragmentAck);
// Get ack number, if any.
if (didReceiveAck)
@@ -309,7 +309,7 @@ BLE_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle dat
Encoding::LittleEndian::Reader startReader(data->Start(), data->DataLength());
// Verify StartMessage header flag set.
- VerifyOrExit(rx_flags & kHeaderFlag_StartMessage, err = BLE_ERROR_INVALID_BTP_HEADER_FLAGS);
+ VerifyOrExit(rx_flags.Has(HeaderFlags::kStartMessage), err = BLE_ERROR_INVALID_BTP_HEADER_FLAGS);
VerifyOrExit(startReader.Read16(&mRxLength).StatusCode() == CHIP_NO_ERROR, err = BLE_ERROR_MESSAGE_INCOMPLETE);
@@ -328,10 +328,10 @@ BLE_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle dat
else if (mRxState == kState_InProgress)
{
// Verify StartMessage header flag NOT set, since we're in the middle of receiving a message.
- VerifyOrExit((rx_flags & kHeaderFlag_StartMessage) == 0, err = BLE_ERROR_INVALID_BTP_HEADER_FLAGS);
+ VerifyOrExit(!rx_flags.Has(HeaderFlags::kStartMessage), err = BLE_ERROR_INVALID_BTP_HEADER_FLAGS);
// Verify ContinueMessage or EndMessage header flag set.
- VerifyOrExit((rx_flags & kHeaderFlag_ContinueMessage) || (rx_flags & kHeaderFlag_EndMessage),
+ VerifyOrExit(rx_flags.HasAny(HeaderFlags::kContinueMessage, HeaderFlags::kEndMessage),
err = BLE_ERROR_INVALID_BTP_HEADER_FLAGS);
// Add received fragment to reassembled message buffer.
@@ -348,7 +348,7 @@ BLE_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle dat
ExitNow();
}
- if (rx_flags & kHeaderFlag_EndMessage)
+ if (rx_flags.Has(HeaderFlags::kEndMessage))
{
// Trim remainder, if any, of the received packet buffer based on sender-specified length of reassembled message.
int padding = mRxBuf->DataLength() - mRxLength;
@@ -372,7 +372,7 @@ BLE_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle dat
mRxState = kState_Error;
// Dump protocol engine state, plus header flags and received data length.
- ChipLogError(Ble, "HandleCharacteristicReceived failed, err = %d, rx_flags = %u", err, rx_flags);
+ ChipLogError(Ble, "HandleCharacteristicReceived failed, err = %d, rx_flags = %u", err, rx_flags.Raw());
if (didReceiveAck)
{
ChipLogError(Ble, "With rx'd ack = %u", receivedAck);
@@ -457,17 +457,16 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
characteristic -= header_size;
mTxBuf->SetStart(characteristic);
uint8_t cursor = 1; // first position past header flags byte
-
- characteristic[0] = kHeaderFlag_StartMessage;
+ BitFlags headerFlags(HeaderFlags::kStartMessage);
#if CHIP_ENABLE_CHIPOBLE_TEST
if (TxPacketType() == kType_Control)
- SetFlag(characteristic[0], kHeaderFlag_CommandMessage, true);
+ headerFlags.Set(HeaderFlags::kCommandMessage);
#endif
if (send_ack)
{
- SetFlag(characteristic[0], kHeaderFlag_FragmentAck, true);
+ headerFlags.Set(HeaderFlags::kFragmentAck);
characteristic[cursor++] = GetAndRecordRxAckSeqNum();
ChipLogDebugBtpEngine(Ble, "===> encoded piggybacked ack, ack_num = %u", characteristic[cursor - 1]);
}
@@ -480,7 +479,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
{
mTxBuf->SetDataLength(static_cast(mTxLength + cursor));
mTxLength = 0;
- SetFlag(characteristic[0], kHeaderFlag_EndMessage, true);
+ headerFlags.Set(HeaderFlags::kEndMessage);
mTxState = kState_Complete;
mTxPacketCount++;
}
@@ -490,6 +489,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
mTxLength = static_cast((mTxLength + cursor) - mTxFragmentSize);
}
+ characteristic[0] = headerFlags.Raw();
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send first fragment:");
PrintBufDebug(data);
}
@@ -510,16 +510,16 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
mTxBuf->SetStart(characteristic);
uint8_t cursor = 1; // first position past header flags byte
- characteristic[0] = kHeaderFlag_ContinueMessage;
+ BitFlags headerFlags(HeaderFlags::kContinueMessage);
#if CHIP_ENABLE_CHIPOBLE_TEST
if (TxPacketType() == kType_Control)
- SetFlag(characteristic[0], kHeaderFlag_CommandMessage, true);
+ headerFlags.Set(HeaderFlags::kCommandMessage);
#endif
if (send_ack)
{
- SetFlag(characteristic[0], kHeaderFlag_FragmentAck, true);
+ headerFlags.Set(HeaderFlags::kFragmentAck);
characteristic[cursor++] = GetAndRecordRxAckSeqNum();
ChipLogDebugBtpEngine(Ble, "===> encoded piggybacked ack, ack_num = %u", characteristic[cursor - 1]);
}
@@ -530,7 +530,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
{
mTxBuf->SetDataLength(static_cast(mTxLength + cursor));
mTxLength = 0;
- SetFlag(characteristic[0], kHeaderFlag_EndMessage, true);
+ headerFlags.Set(HeaderFlags::kEndMessage);
mTxState = kState_Complete;
mTxPacketCount++;
}
@@ -540,6 +540,7 @@ bool BtpEngine::HandleCharacteristicSend(System::PacketBufferHandle data, bool s
mTxLength = static_cast((mTxLength + cursor) - mTxFragmentSize);
}
+ characteristic[0] = headerFlags.Raw();
ChipLogDebugBtpEngine(Ble, ">>> CHIPoBle preparing to send additional fragment:");
PrintBufDebug(mTxBuf);
}
diff --git a/src/ble/BtpEngine.h b/src/ble/BtpEngine.h
index 9b7a6c5c20e2e3..43dda04434ef49 100644
--- a/src/ble/BtpEngine.h
+++ b/src/ble/BtpEngine.h
@@ -87,16 +87,17 @@ class BtpEngine
kState_Error = 3
} State_t; // [READ-ONLY] Current state
- enum
+ // Masks for BTP fragment header flag bits.
+ enum class HeaderFlags : uint8_t
{
- kHeaderFlag_StartMessage = 0x01,
- kHeaderFlag_ContinueMessage = 0x02,
- kHeaderFlag_EndMessage = 0x04,
- kHeaderFlag_FragmentAck = 0x08,
+ kStartMessage = 0x01,
+ kContinueMessage = 0x02,
+ kEndMessage = 0x04,
+ kFragmentAck = 0x08,
#if CHIP_ENABLE_CHIPOBLE_TEST
- kHeaderFlag_CommandMessage = 0x10,
+ kCommandMessage = 0x10,
#endif
- }; // Masks for BTP fragment header flag bits.
+ };
static const uint16_t sDefaultFragmentSize;
static const uint16_t sMaxFragmentSize;
@@ -129,7 +130,10 @@ class BtpEngine
inline SequenceNumber_t SetRxPacketSeq(SequenceNumber_t seq) { return (mRxPacketSeq = seq); }
inline SequenceNumber_t TxPacketSeq() { return mTxPacketSeq; }
inline SequenceNumber_t RxPacketSeq() { return mRxPacketSeq; }
- inline bool IsCommandPacket(const PacketBufferHandle & p) { return GetFlag(*(p->Start()), kHeaderFlag_CommandMessage); }
+ inline bool IsCommandPacket(const PacketBufferHandle & p)
+ {
+ return BitFlags(*(p->Start())).Has(HeaderFlags::kCommandMessage);
+ }
inline void PushPacketTag(const PacketBufferHandle & p, PacketType_t type)
{
p->SetStart(p->Start() - sizeof(type));
diff --git a/src/controller/CHIPClusters.cpp b/src/controller/CHIPClusters.cpp
index f6145a98e38df1..9a339244aeb899 100644
--- a/src/controller/CHIPClusters.cpp
+++ b/src/controller/CHIPClusters.cpp
@@ -114,7 +114,7 @@ CHIP_ERROR BarrierControlCluster::BarrierControlGoToPercent(Callback::Cancelable
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kBarrierControlGoToPercentCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -148,7 +148,7 @@ CHIP_ERROR BarrierControlCluster::BarrierControlStop(Callback::Cancelable * onSu
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kBarrierControlStopCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -227,7 +227,7 @@ CHIP_ERROR BasicCluster::MfgSpecificPing(Callback::Cancelable * onSuccessCallbac
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMfgSpecificPingCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -257,7 +257,7 @@ CHIP_ERROR BasicCluster::ResetToFactoryDefaults(Callback::Cancelable * onSuccess
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kResetToFactoryDefaultsCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -319,7 +319,7 @@ CHIP_ERROR BindingCluster::Bind(Callback::Cancelable * onSuccessCallback, Callba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kBindCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -360,7 +360,7 @@ CHIP_ERROR BindingCluster::Unbind(Callback::Cancelable * onSuccessCallback, Call
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kUnbindCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -416,7 +416,7 @@ CHIP_ERROR ColorControlCluster::MoveColor(Callback::Cancelable * onSuccessCallba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveColorCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -458,7 +458,7 @@ CHIP_ERROR ColorControlCluster::MoveColorTemperature(Callback::Cancelable * onSu
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveColorTemperatureCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -502,7 +502,7 @@ CHIP_ERROR ColorControlCluster::MoveHue(Callback::Cancelable * onSuccessCallback
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveHueCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -542,7 +542,7 @@ CHIP_ERROR ColorControlCluster::MoveSaturation(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveSaturationCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -583,7 +583,7 @@ CHIP_ERROR ColorControlCluster::MoveToColor(Callback::Cancelable * onSuccessCall
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveToColorCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -626,7 +626,7 @@ CHIP_ERROR ColorControlCluster::MoveToColorTemperature(Callback::Cancelable * on
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveToColorTemperatureCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -667,7 +667,7 @@ CHIP_ERROR ColorControlCluster::MoveToHue(Callback::Cancelable * onSuccessCallba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveToHueCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -710,7 +710,7 @@ CHIP_ERROR ColorControlCluster::MoveToHueAndSaturation(Callback::Cancelable * on
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveToHueAndSaturationCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -753,7 +753,7 @@ CHIP_ERROR ColorControlCluster::MoveToSaturation(Callback::Cancelable * onSucces
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveToSaturationCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -794,7 +794,7 @@ CHIP_ERROR ColorControlCluster::StepColor(Callback::Cancelable * onSuccessCallba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStepColorCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -838,7 +838,7 @@ CHIP_ERROR ColorControlCluster::StepColorTemperature(Callback::Cancelable * onSu
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStepColorTemperatureCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -886,7 +886,7 @@ CHIP_ERROR ColorControlCluster::StepHue(Callback::Cancelable * onSuccessCallback
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStepHueCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -929,7 +929,7 @@ CHIP_ERROR ColorControlCluster::StepSaturation(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStepSaturationCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -971,7 +971,7 @@ CHIP_ERROR ColorControlCluster::StopMoveStep(Callback::Cancelable * onSuccessCal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStopMoveStepCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1610,7 +1610,7 @@ CHIP_ERROR ContentLaunchCluster::LaunchContent(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kLaunchContentCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1640,7 +1640,7 @@ CHIP_ERROR ContentLaunchCluster::LaunchURL(Callback::Cancelable * onSuccessCallb
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kLaunchURLCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1687,7 +1687,7 @@ CHIP_ERROR DoorLockCluster::ClearAllPins(Callback::Cancelable * onSuccessCallbac
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kClearAllPinsCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1717,7 +1717,7 @@ CHIP_ERROR DoorLockCluster::ClearAllRfids(Callback::Cancelable * onSuccessCallba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kClearAllRfidsCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1748,7 +1748,7 @@ CHIP_ERROR DoorLockCluster::ClearHolidaySchedule(Callback::Cancelable * onSucces
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kClearHolidayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1781,7 +1781,7 @@ CHIP_ERROR DoorLockCluster::ClearPin(Callback::Cancelable * onSuccessCallback, C
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kClearPinCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1814,7 +1814,7 @@ CHIP_ERROR DoorLockCluster::ClearRfid(Callback::Cancelable * onSuccessCallback,
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kClearRfidCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1847,7 +1847,7 @@ CHIP_ERROR DoorLockCluster::ClearWeekdaySchedule(Callback::Cancelable * onSucces
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kClearWeekdayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1883,7 +1883,7 @@ CHIP_ERROR DoorLockCluster::ClearYeardaySchedule(Callback::Cancelable * onSucces
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kClearYeardayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1919,7 +1919,7 @@ CHIP_ERROR DoorLockCluster::GetHolidaySchedule(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetHolidayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1952,7 +1952,7 @@ CHIP_ERROR DoorLockCluster::GetLogRecord(Callback::Cancelable * onSuccessCallbac
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetLogRecordCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -1985,7 +1985,7 @@ CHIP_ERROR DoorLockCluster::GetPin(Callback::Cancelable * onSuccessCallback, Cal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetPinCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2018,7 +2018,7 @@ CHIP_ERROR DoorLockCluster::GetRfid(Callback::Cancelable * onSuccessCallback, Ca
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetRfidCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2051,7 +2051,7 @@ CHIP_ERROR DoorLockCluster::GetUserType(Callback::Cancelable * onSuccessCallback
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetUserTypeCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2084,7 +2084,7 @@ CHIP_ERROR DoorLockCluster::GetWeekdaySchedule(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetWeekdayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2120,7 +2120,7 @@ CHIP_ERROR DoorLockCluster::GetYeardaySchedule(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetYeardayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2155,7 +2155,7 @@ CHIP_ERROR DoorLockCluster::LockDoor(Callback::Cancelable * onSuccessCallback, C
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kLockDoorCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2189,7 +2189,7 @@ CHIP_ERROR DoorLockCluster::SetHolidaySchedule(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSetHolidayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2229,7 +2229,7 @@ CHIP_ERROR DoorLockCluster::SetPin(Callback::Cancelable * onSuccessCallback, Cal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSetPinCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2269,7 +2269,7 @@ CHIP_ERROR DoorLockCluster::SetRfid(Callback::Cancelable * onSuccessCallback, Ca
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSetRfidCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2309,7 +2309,7 @@ CHIP_ERROR DoorLockCluster::SetUserType(Callback::Cancelable * onSuccessCallback
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSetUserTypeCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2345,7 +2345,7 @@ CHIP_ERROR DoorLockCluster::SetWeekdaySchedule(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSetWeekdayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2391,7 +2391,7 @@ CHIP_ERROR DoorLockCluster::SetYeardaySchedule(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSetYeardayScheduleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2431,7 +2431,7 @@ CHIP_ERROR DoorLockCluster::UnlockDoor(Callback::Cancelable * onSuccessCallback,
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kUnlockDoorCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2464,7 +2464,7 @@ CHIP_ERROR DoorLockCluster::UnlockWithTimeout(Callback::Cancelable * onSuccessCa
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kUnlockWithTimeoutCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2556,7 +2556,7 @@ CHIP_ERROR GeneralCommissioningCluster::ArmFailSafe(Callback::Cancelable * onSuc
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kArmFailSafeCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2594,7 +2594,7 @@ CHIP_ERROR GeneralCommissioningCluster::CommissioningComplete(Callback::Cancelab
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kCommissioningCompleteCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2626,7 +2626,7 @@ CHIP_ERROR GeneralCommissioningCluster::SetFabric(Callback::Cancelable * onSucce
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSetFabricCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2707,7 +2707,7 @@ CHIP_ERROR GroupsCluster::AddGroup(Callback::Cancelable * onSuccessCallback, Cal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kAddGroupCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2742,7 +2742,7 @@ CHIP_ERROR GroupsCluster::AddGroupIfIdentifying(Callback::Cancelable * onSuccess
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kAddGroupIfIdentifyingCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2778,7 +2778,7 @@ CHIP_ERROR GroupsCluster::GetGroupMembership(Callback::Cancelable * onSuccessCal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetGroupMembershipCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2813,7 +2813,7 @@ CHIP_ERROR GroupsCluster::RemoveAllGroups(Callback::Cancelable * onSuccessCallba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRemoveAllGroupsCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2844,7 +2844,7 @@ CHIP_ERROR GroupsCluster::RemoveGroup(Callback::Cancelable * onSuccessCallback,
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRemoveGroupCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2877,7 +2877,7 @@ CHIP_ERROR GroupsCluster::ViewGroup(Callback::Cancelable * onSuccessCallback, Ca
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kViewGroupCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -2996,7 +2996,7 @@ CHIP_ERROR IdentifyCluster::Identify(Callback::Cancelable * onSuccessCallback, C
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kIdentifyCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3028,7 +3028,7 @@ CHIP_ERROR IdentifyCluster::IdentifyQuery(Callback::Cancelable * onSuccessCallba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kIdentifyQueryCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3091,7 +3091,7 @@ CHIP_ERROR LevelControlCluster::Move(Callback::Cancelable * onSuccessCallback, C
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3131,7 +3131,7 @@ CHIP_ERROR LevelControlCluster::MoveToLevel(Callback::Cancelable * onSuccessCall
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveToLevelCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3172,7 +3172,7 @@ CHIP_ERROR LevelControlCluster::MoveToLevelWithOnOff(Callback::Cancelable * onSu
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveToLevelWithOnOffCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3208,7 +3208,7 @@ CHIP_ERROR LevelControlCluster::MoveWithOnOff(Callback::Cancelable * onSuccessCa
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kMoveWithOnOffCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3244,7 +3244,7 @@ CHIP_ERROR LevelControlCluster::Step(Callback::Cancelable * onSuccessCallback, C
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStepCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3286,7 +3286,7 @@ CHIP_ERROR LevelControlCluster::StepWithOnOff(Callback::Cancelable * onSuccessCa
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStepWithOnOffCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3324,7 +3324,7 @@ CHIP_ERROR LevelControlCluster::Stop(Callback::Cancelable * onSuccessCallback, C
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStopCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3358,7 +3358,7 @@ CHIP_ERROR LevelControlCluster::StopWithOnOff(Callback::Cancelable * onSuccessCa
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStopWithOnOffCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3475,7 +3475,7 @@ CHIP_ERROR MediaPlaybackCluster::FastForwardRequest(Callback::Cancelable * onSuc
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kFastForwardRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3505,7 +3505,7 @@ CHIP_ERROR MediaPlaybackCluster::NextRequest(Callback::Cancelable * onSuccessCal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kNextRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3535,7 +3535,7 @@ CHIP_ERROR MediaPlaybackCluster::PauseRequest(Callback::Cancelable * onSuccessCa
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kPauseRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3565,7 +3565,7 @@ CHIP_ERROR MediaPlaybackCluster::PlayRequest(Callback::Cancelable * onSuccessCal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kPlayRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3595,7 +3595,7 @@ CHIP_ERROR MediaPlaybackCluster::PreviousRequest(Callback::Cancelable * onSucces
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kPreviousRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3625,7 +3625,7 @@ CHIP_ERROR MediaPlaybackCluster::RewindRequest(Callback::Cancelable * onSuccessC
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRewindRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3656,7 +3656,7 @@ CHIP_ERROR MediaPlaybackCluster::SkipBackwardRequest(Callback::Cancelable * onSu
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSkipBackwardRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3687,7 +3687,7 @@ CHIP_ERROR MediaPlaybackCluster::SkipForwardRequest(Callback::Cancelable * onSuc
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kSkipForwardRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3718,7 +3718,7 @@ CHIP_ERROR MediaPlaybackCluster::StartOverRequest(Callback::Cancelable * onSucce
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStartOverRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3748,7 +3748,7 @@ CHIP_ERROR MediaPlaybackCluster::StopRequest(Callback::Cancelable * onSuccessCal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStopRequestCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3805,7 +3805,7 @@ CHIP_ERROR NetworkCommissioningCluster::AddThreadNetwork(Callback::Cancelable *
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kAddThreadNetworkCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3844,7 +3844,7 @@ CHIP_ERROR NetworkCommissioningCluster::AddWiFiNetwork(Callback::Cancelable * on
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kAddWiFiNetworkCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3885,7 +3885,7 @@ CHIP_ERROR NetworkCommissioningCluster::DisableNetwork(Callback::Cancelable * on
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kDisableNetworkCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3924,7 +3924,7 @@ CHIP_ERROR NetworkCommissioningCluster::EnableNetwork(Callback::Cancelable * onS
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kEnableNetworkCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3963,7 +3963,7 @@ CHIP_ERROR NetworkCommissioningCluster::GetLastNetworkCommissioningResult(Callba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetLastNetworkCommissioningResultCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -3998,7 +3998,7 @@ CHIP_ERROR NetworkCommissioningCluster::RemoveNetwork(Callback::Cancelable * onS
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRemoveNetworkCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4037,7 +4037,7 @@ CHIP_ERROR NetworkCommissioningCluster::ScanNetworks(Callback::Cancelable * onSu
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kScanNetworksCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4077,7 +4077,7 @@ CHIP_ERROR NetworkCommissioningCluster::UpdateThreadNetwork(Callback::Cancelable
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kUpdateThreadNetworkCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4116,7 +4116,7 @@ CHIP_ERROR NetworkCommissioningCluster::UpdateWiFiNetwork(Callback::Cancelable *
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kUpdateWiFiNetworkCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4172,7 +4172,7 @@ CHIP_ERROR OnOffCluster::Off(Callback::Cancelable * onSuccessCallback, Callback:
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kOffCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4202,7 +4202,7 @@ CHIP_ERROR OnOffCluster::On(Callback::Cancelable * onSuccessCallback, Callback::
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kOnCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4232,7 +4232,7 @@ CHIP_ERROR OnOffCluster::Toggle(Callback::Cancelable * onSuccessCallback, Callba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kToggleCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4301,7 +4301,7 @@ CHIP_ERROR ScenesCluster::AddScene(Callback::Cancelable * onSuccessCallback, Cal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kAddSceneCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4347,7 +4347,7 @@ CHIP_ERROR ScenesCluster::GetSceneMembership(Callback::Cancelable * onSuccessCal
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kGetSceneMembershipCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4380,7 +4380,7 @@ CHIP_ERROR ScenesCluster::RecallScene(Callback::Cancelable * onSuccessCallback,
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRecallSceneCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4418,7 +4418,7 @@ CHIP_ERROR ScenesCluster::RemoveAllScenes(Callback::Cancelable * onSuccessCallba
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRemoveAllScenesCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4451,7 +4451,7 @@ CHIP_ERROR ScenesCluster::RemoveScene(Callback::Cancelable * onSuccessCallback,
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRemoveSceneCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4486,7 +4486,7 @@ CHIP_ERROR ScenesCluster::StoreScene(Callback::Cancelable * onSuccessCallback, C
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kStoreSceneCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
@@ -4521,7 +4521,7 @@ CHIP_ERROR ScenesCluster::ViewScene(Callback::Cancelable * onSuccessCallback, Ca
(void) onFailureCallback;
app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kViewSceneCommandId,
- (chip::app::Command::kCommandPathFlag_EndpointIdValid) };
+ (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();
TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
diff --git a/src/credentials/CHIPCert.cpp b/src/credentials/CHIPCert.cpp
index 90246c40202657..b7800ec9976647 100644
--- a/src/credentials/CHIPCert.cpp
+++ b/src/credentials/CHIPCert.cpp
@@ -143,8 +143,7 @@ void ChipCertificateSet::Clear()
mCertCount = 0;
}
-CHIP_ERROR ChipCertificateSet::LoadCert(const uint8_t * chipCert, uint32_t chipCertLen,
- BitFlags decodeFlags)
+CHIP_ERROR ChipCertificateSet::LoadCert(const uint8_t * chipCert, uint32_t chipCertLen, BitFlags decodeFlags)
{
CHIP_ERROR err;
TLVReader reader;
@@ -161,7 +160,7 @@ CHIP_ERROR ChipCertificateSet::LoadCert(const uint8_t * chipCert, uint32_t chipC
return err;
}
-CHIP_ERROR ChipCertificateSet::LoadCert(TLVReader & reader, BitFlags decodeFlags)
+CHIP_ERROR ChipCertificateSet::LoadCert(TLVReader & reader, BitFlags decodeFlags)
{
CHIP_ERROR err;
ASN1Writer writer; // ASN1Writer is used to encode TBS portion of the certificate for the purpose of signature
@@ -192,8 +191,7 @@ CHIP_ERROR ChipCertificateSet::LoadCert(TLVReader & reader, BitFlagsmCertFlags.Has(CertFlags::kExtPresent_SubjectKeyId) &&
- cert->mCertFlags.Has(CertFlags::kExtPresent_AuthKeyId),
+ VerifyOrExit(cert->mCertFlags.HasAll(CertFlags::kExtPresent_SubjectKeyId, CertFlags::kExtPresent_AuthKeyId),
err = CHIP_ERROR_UNSUPPORTED_CERT_FORMAT);
// Verify the cert was signed with ECDSA-SHA256. This is the only signature algorithm currently supported.
@@ -248,8 +246,7 @@ CHIP_ERROR ChipCertificateSet::LoadCert(TLVReader & reader, BitFlags decodeFlags)
+CHIP_ERROR ChipCertificateSet::LoadCerts(const uint8_t * chipCerts, uint32_t chipCertsLen, BitFlags decodeFlags)
{
CHIP_ERROR err;
TLVReader reader;
@@ -275,7 +272,7 @@ CHIP_ERROR ChipCertificateSet::LoadCerts(const uint8_t * chipCerts, uint32_t chi
return err;
}
-CHIP_ERROR ChipCertificateSet::LoadCerts(TLVReader & reader, BitFlags decodeFlags)
+CHIP_ERROR ChipCertificateSet::LoadCerts(TLVReader & reader, BitFlags decodeFlags)
{
CHIP_ERROR err;
uint8_t initialCertCount = mCertCount;
@@ -463,7 +460,7 @@ CHIP_ERROR ChipCertificateSet::VerifySignature(const ChipCertificateData * cert,
}
CHIP_ERROR ChipCertificateSet::ValidateCert(const ChipCertificateData * cert, ValidationContext & context,
- BitFlags validateFlags, uint8_t depth)
+ BitFlags validateFlags, uint8_t depth)
{
CHIP_ERROR err = CHIP_NO_ERROR;
ChipCertificateData * caCert = nullptr;
@@ -499,19 +496,19 @@ CHIP_ERROR ChipCertificateSet::ValidateCert(const ChipCertificateData * cert, Va
{
// If a set of desired key usages has been specified, verify that the key usage extension exists
// in the certificate and that the corresponding usages are supported.
- if (context.mRequiredKeyUsages.Raw() != 0)
+ if (context.mRequiredKeyUsages.HasAny())
{
VerifyOrExit(cert->mCertFlags.Has(CertFlags::kExtPresent_KeyUsage) &&
- cert->mKeyUsageFlags.Has(context.mRequiredKeyUsages.Raw()),
+ cert->mKeyUsageFlags.HasAll(context.mRequiredKeyUsages),
err = CHIP_ERROR_CERT_USAGE_NOT_ALLOWED);
}
// If a set of desired key purposes has been specified, verify that the extended key usage extension
// exists in the certificate and that the corresponding purposes are supported.
- if (context.mRequiredKeyPurposes.Raw() != 0)
+ if (context.mRequiredKeyPurposes.HasAny())
{
VerifyOrExit(cert->mCertFlags.Has(CertFlags::kExtPresent_ExtendedKeyUsage) &&
- cert->mKeyPurposeFlags.Has(context.mRequiredKeyPurposes.Raw()),
+ cert->mKeyPurposeFlags.HasAll(context.mRequiredKeyPurposes),
err = CHIP_ERROR_CERT_USAGE_NOT_ALLOWED);
}
@@ -577,8 +574,8 @@ CHIP_ERROR ChipCertificateSet::ValidateCert(const ChipCertificateData * cert, Va
}
CHIP_ERROR ChipCertificateSet::FindValidCert(const ChipDN & subjectDN, const CertificateKeyId & subjectKeyId,
- ValidationContext & context, BitFlags validateFlags,
- uint8_t depth, ChipCertificateData *& cert)
+ ValidationContext & context, BitFlags validateFlags, uint8_t depth,
+ ChipCertificateData *& cert)
{
CHIP_ERROR err;
@@ -646,9 +643,9 @@ void ChipCertificateData::Clear()
mPubKeyCurveOID = 0;
mPubKeyAlgoOID = 0;
mSigAlgoOID = 0;
- mCertFlags.SetRaw(0);
- mKeyUsageFlags.SetRaw(0);
- mKeyPurposeFlags.SetRaw(0);
+ mCertFlags.ClearAll();
+ mKeyUsageFlags.ClearAll();
+ mKeyPurposeFlags.ClearAll();
mPathLenConstraint = 0;
mCertType = kCertType_NotSpecified;
mSignature.R = nullptr;
@@ -663,9 +660,9 @@ void ValidationContext::Reset()
mEffectiveTime = 0;
mTrustAnchor = nullptr;
mSigningCert = nullptr;
- mRequiredKeyUsages.SetRaw(0);
- mRequiredKeyPurposes.SetRaw(0);
- mValidateFlags.SetRaw(0);
+ mRequiredKeyUsages.ClearAll();
+ mRequiredKeyPurposes.ClearAll();
+ mValidateFlags.ClearAll();
mRequiredCertType = kCertType_NotSpecified;
}
diff --git a/src/credentials/CHIPCert.h b/src/credentials/CHIPCert.h
index 4774efd31ef2e2..362d8ce825fee2 100644
--- a/src/credentials/CHIPCert.h
+++ b/src/credentials/CHIPCert.h
@@ -241,22 +241,22 @@ struct ChipCertificateData
void Clear();
- ChipDN mSubjectDN; /**< Certificate Subject DN. */
- ChipDN mIssuerDN; /**< Certificate Issuer DN. */
- CertificateKeyId mSubjectKeyId; /**< Certificate Subject public key identifier. */
- CertificateKeyId mAuthKeyId; /**< Certificate Authority public key identifier. */
- uint32_t mNotBeforeTime; /**< Certificate validity: Not Before field. */
- uint32_t mNotAfterTime; /**< Certificate validity: Not After field. */
- const uint8_t * mPublicKey; /**< Pointer to the certificate public key. */
- uint8_t mPublicKeyLen; /**< Certificate public key length. */
- uint16_t mPubKeyCurveOID; /**< Public key Elliptic Curve CHIP OID. */
- uint16_t mPubKeyAlgoOID; /**< Public key algorithm CHIP OID. */
- uint16_t mSigAlgoOID; /**< Certificate signature algorithm CHIP OID. */
- BitFlags mCertFlags; /**< Certificate data flags. */
- BitFlags mKeyUsageFlags; /**< Certificate key usage extensions flags. */
- BitFlags mKeyPurposeFlags; /**< Certificate extended key usage extensions flags. */
- uint8_t mPathLenConstraint; /**< Basic constraint: path length. */
- uint8_t mCertType; /**< Certificate type. */
+ ChipDN mSubjectDN; /**< Certificate Subject DN. */
+ ChipDN mIssuerDN; /**< Certificate Issuer DN. */
+ CertificateKeyId mSubjectKeyId; /**< Certificate Subject public key identifier. */
+ CertificateKeyId mAuthKeyId; /**< Certificate Authority public key identifier. */
+ uint32_t mNotBeforeTime; /**< Certificate validity: Not Before field. */
+ uint32_t mNotAfterTime; /**< Certificate validity: Not After field. */
+ const uint8_t * mPublicKey; /**< Pointer to the certificate public key. */
+ uint8_t mPublicKeyLen; /**< Certificate public key length. */
+ uint16_t mPubKeyCurveOID; /**< Public key Elliptic Curve CHIP OID. */
+ uint16_t mPubKeyAlgoOID; /**< Public key algorithm CHIP OID. */
+ uint16_t mSigAlgoOID; /**< Certificate signature algorithm CHIP OID. */
+ BitFlags mCertFlags; /**< Certificate data flags. */
+ BitFlags mKeyUsageFlags; /**< Certificate key usage extensions flags. */
+ BitFlags mKeyPurposeFlags; /**< Certificate extended key usage extensions flags. */
+ uint8_t mPathLenConstraint; /**< Basic constraint: path length. */
+ uint8_t mCertType; /**< Certificate type. */
struct
{
const uint8_t * R; /**< Pointer to the R element of the signature, encoded as ASN.1 DER Integer. */
@@ -275,16 +275,16 @@ struct ChipCertificateData
*/
struct ValidationContext
{
- uint32_t mEffectiveTime; /**< Current CHIP Epoch UTC time. */
- const ChipCertificateData * mTrustAnchor; /**< Pointer to the Trust Anchor Certificate data structure. */
- const ChipCertificateData * mSigningCert; /**< Pointer to the Signing Certificate data structure. */
- BitFlags mRequiredKeyUsages; /**< Key usage extensions that should be present in the
- validated certificate. */
- BitFlags mRequiredKeyPurposes; /**< Extended Key usage extensions that should be present
- in the validated certificate. */
- BitFlags mValidateFlags; /**< Certificate validation flags, specifying how a certificate
- should be validated. */
- uint8_t mRequiredCertType; /**< Required certificate type. */
+ uint32_t mEffectiveTime; /**< Current CHIP Epoch UTC time. */
+ const ChipCertificateData * mTrustAnchor; /**< Pointer to the Trust Anchor Certificate data structure. */
+ const ChipCertificateData * mSigningCert; /**< Pointer to the Signing Certificate data structure. */
+ BitFlags mRequiredKeyUsages; /**< Key usage extensions that should be present in the
+ validated certificate. */
+ BitFlags mRequiredKeyPurposes; /**< Extended Key usage extensions that should be present
+ in the validated certificate. */
+ BitFlags mValidateFlags; /**< Certificate validation flags, specifying how a certificate
+ should be validated. */
+ uint8_t mRequiredCertType; /**< Required certificate type. */
void Reset();
};
@@ -350,7 +350,7 @@ class DLL_EXPORT ChipCertificateSet
*
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
- CHIP_ERROR LoadCert(const uint8_t * chipCert, uint32_t chipCertLen, BitFlags decodeFlags);
+ CHIP_ERROR LoadCert(const uint8_t * chipCert, uint32_t chipCertLen, BitFlags decodeFlags);
/**
* @brief Load CHIP certificate into set.
@@ -363,7 +363,7 @@ class DLL_EXPORT ChipCertificateSet
*
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
- CHIP_ERROR LoadCert(chip::TLV::TLVReader & reader, BitFlags decodeFlags);
+ CHIP_ERROR LoadCert(chip::TLV::TLVReader & reader, BitFlags decodeFlags);
/**
* @brief Load CHIP certificates into set.
@@ -377,7 +377,7 @@ class DLL_EXPORT ChipCertificateSet
*
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
- CHIP_ERROR LoadCerts(const uint8_t * chipCerts, uint32_t chipCertsLen, BitFlags decodeFlags);
+ CHIP_ERROR LoadCerts(const uint8_t * chipCerts, uint32_t chipCertsLen, BitFlags decodeFlags);
/**
* @brief Load CHIP certificates into set.
@@ -391,7 +391,7 @@ class DLL_EXPORT ChipCertificateSet
*
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
- CHIP_ERROR LoadCerts(chip::TLV::TLVReader & reader, BitFlags decodeFlags);
+ CHIP_ERROR LoadCerts(chip::TLV::TLVReader & reader, BitFlags decodeFlags);
/**
* @brief Add trusted anchor key to the certificate set.
@@ -505,7 +505,7 @@ class DLL_EXPORT ChipCertificateSet
* @return Returns a CHIP_ERROR on validation or other error, CHIP_NO_ERROR otherwise
**/
CHIP_ERROR FindValidCert(const ChipDN & subjectDN, const CertificateKeyId & subjectKeyId, ValidationContext & context,
- BitFlags validateFlags, uint8_t depth, ChipCertificateData *& cert);
+ BitFlags validateFlags, uint8_t depth, ChipCertificateData *& cert);
/**
* @brief Validate CHIP certificate.
@@ -518,7 +518,7 @@ class DLL_EXPORT ChipCertificateSet
* @return Returns a CHIP_ERROR on validation or other error, CHIP_NO_ERROR otherwise
**/
CHIP_ERROR ValidateCert(const ChipCertificateData * cert, ValidationContext & context,
- BitFlags validateFlags, uint8_t depth);
+ BitFlags validateFlags, uint8_t depth);
};
/**
diff --git a/src/credentials/CHIPCertFromX509.cpp b/src/credentials/CHIPCertFromX509.cpp
index 51cdbf863cee3c..4f8854911055c5 100644
--- a/src/credentials/CHIPCertFromX509.cpp
+++ b/src/credentials/CHIPCertFromX509.cpp
@@ -363,8 +363,7 @@ static CHIP_ERROR ConvertExtension(ASN1Reader & reader, TLVWriter & writer)
VerifyOrExit(keyUsageBits <= UINT16_MAX, err = ASN1_ERROR_INVALID_ENCODING);
// Check that only supported flags are set.
- BitFlags keyUsageFlags;
- keyUsageFlags.SetRaw(static_cast(keyUsageBits));
+ BitFlags keyUsageFlags(static_cast(keyUsageBits));
VerifyOrExit(keyUsageFlags.HasOnly(
KeyUsageFlags::kDigitalSignature, KeyUsageFlags::kNonRepudiation, KeyUsageFlags::kKeyEncipherment,
KeyUsageFlags::kDataEncipherment, KeyUsageFlags::kKeyAgreement, KeyUsageFlags::kKeyCertSign,
diff --git a/src/credentials/CHIPCertToX509.cpp b/src/credentials/CHIPCertToX509.cpp
index bb6fe2ccbe4745..3a2c09c2a38edf 100644
--- a/src/credentials/CHIPCertToX509.cpp
+++ b/src/credentials/CHIPCertToX509.cpp
@@ -382,7 +382,6 @@ static CHIP_ERROR DecodeConvertKeyUsageExtension(TLVReader & reader, ASN1Writer
{
CHIP_ERROR err;
uint64_t keyUsageBits;
- BitFlags keyUsageFlags;
certData.mCertFlags.Set(CertFlags::kExtPresent_KeyUsage);
@@ -395,16 +394,18 @@ static CHIP_ERROR DecodeConvertKeyUsageExtension(TLVReader & reader, ASN1Writer
VerifyOrExit(keyUsageBits <= UINT16_MAX, err = CHIP_ERROR_UNSUPPORTED_CERT_FORMAT);
- keyUsageFlags.SetRaw(static_cast(keyUsageBits));
- VerifyOrExit(keyUsageFlags.HasOnly(KeyUsageFlags::kDigitalSignature, KeyUsageFlags::kNonRepudiation,
- KeyUsageFlags::kKeyEncipherment, KeyUsageFlags::kDataEncipherment,
- KeyUsageFlags::kKeyAgreement, KeyUsageFlags::kKeyCertSign, KeyUsageFlags::kCRLSign,
- KeyUsageFlags::kEncipherOnly, KeyUsageFlags::kEncipherOnly),
- err = CHIP_ERROR_UNSUPPORTED_CERT_FORMAT);
+ {
+ BitFlags keyUsageFlags(static_cast(keyUsageBits));
+ VerifyOrExit(keyUsageFlags.HasOnly(KeyUsageFlags::kDigitalSignature, KeyUsageFlags::kNonRepudiation,
+ KeyUsageFlags::kKeyEncipherment, KeyUsageFlags::kDataEncipherment,
+ KeyUsageFlags::kKeyAgreement, KeyUsageFlags::kKeyCertSign, KeyUsageFlags::kCRLSign,
+ KeyUsageFlags::kEncipherOnly, KeyUsageFlags::kEncipherOnly),
+ err = CHIP_ERROR_UNSUPPORTED_CERT_FORMAT);
- ASN1_ENCODE_BIT_STRING(static_cast(keyUsageBits));
+ ASN1_ENCODE_BIT_STRING(static_cast(keyUsageBits));
- certData.mKeyUsageFlags = keyUsageFlags;
+ certData.mKeyUsageFlags = keyUsageFlags;
+ }
exit:
return err;
diff --git a/src/credentials/tests/CHIPCert_test_vectors.cpp b/src/credentials/tests/CHIPCert_test_vectors.cpp
index 36893894ef0d0a..2126f59ea033b1 100644
--- a/src/credentials/tests/CHIPCert_test_vectors.cpp
+++ b/src/credentials/tests/CHIPCert_test_vectors.cpp
@@ -46,7 +46,7 @@ extern const uint8_t gTestCerts[] = {
extern const size_t gNumTestCerts = sizeof(gTestCerts) / sizeof(gTestCerts[0]);
-CHIP_ERROR GetTestCert(uint8_t certType, BitFlags certLoadFlags, const uint8_t *& certData,
+CHIP_ERROR GetTestCert(uint8_t certType, BitFlags certLoadFlags, const uint8_t *& certData,
uint32_t & certDataLen)
{
CHIP_ERROR err;
@@ -103,8 +103,8 @@ const char * GetTestCertName(uint8_t certType)
return nullptr;
}
-CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags certLoadFlags,
- BitFlags decodeFlags)
+CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags certLoadFlags,
+ BitFlags decodeFlags)
{
CHIP_ERROR err;
ChipCertificateData * cert;
diff --git a/src/credentials/tests/CHIPCert_test_vectors.h b/src/credentials/tests/CHIPCert_test_vectors.h
index 3a2169405a9b44..15cd65ffb87cf9 100644
--- a/src/credentials/tests/CHIPCert_test_vectors.h
+++ b/src/credentials/tests/CHIPCert_test_vectors.h
@@ -28,6 +28,7 @@
#include
#include
+#include
#include
namespace chip {
@@ -58,11 +59,11 @@ enum class TestCertLoadFlags : uint8_t
kSetAppDefinedCertType = 0x20,
};
-extern CHIP_ERROR GetTestCert(uint8_t certType, BitFlags certLoadFlags, const uint8_t *& certData,
+extern CHIP_ERROR GetTestCert(uint8_t certType, BitFlags certLoadFlags, const uint8_t *& certData,
uint32_t & certDataLen);
extern const char * GetTestCertName(uint8_t certType);
-extern CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags certLoadFlags,
- BitFlags decodeFlags);
+extern CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags certLoadFlags,
+ BitFlags decodeFlags);
extern const uint8_t gTestCerts[];
extern const size_t gNumTestCerts;
diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp
index deeb94b8b590fb..92ffdc1d9556e0 100644
--- a/src/credentials/tests/TestChipCert.cpp
+++ b/src/credentials/tests/TestChipCert.cpp
@@ -48,59 +48,59 @@ enum
// (in either CHIP or DER form), or to decode the certificates.
};
-static const BitFlags sIgnoreNotBeforeFlag(CertValidateFlags::kIgnoreNotBefore);
-static const BitFlags sIgnoreNotAfterFlag(CertValidateFlags::kIgnoreNotAfter);
-
-static const BitFlags sNullDecodeFlag;
-static const BitFlags sGenTBSHashFlag(CertDecodeFlags::kGenerateTBSHash);
-static const BitFlags sTrustAnchorFlag(CertDecodeFlags::kIsTrustAnchor);
-
-static const BitFlags sNullLoadFlag;
-static const BitFlags sDerFormFlag(TestCertLoadFlags::kDERForm);
-static const BitFlags sSupIsCAFlag(TestCertLoadFlags::kSuppressIsCA);
-static const BitFlags sSupKeyUsageFlag(TestCertLoadFlags::kSuppressKeyUsage);
-static const BitFlags sSupKeyCertSignFlag(TestCertLoadFlags::kSuppressKeyCertSign);
-static const BitFlags sPathLenZeroFlag(TestCertLoadFlags::kSetPathLenConstZero);
-static const BitFlags sAppDefCertTypeFlag(TestCertLoadFlags::kSetAppDefinedCertType);
-
-static const BitFlags sNullKPFlag;
-static const BitFlags sSA(KeyPurposeFlags::kServerAuth);
-static const BitFlags sCA(KeyPurposeFlags::kClientAuth);
-static const BitFlags sCS(KeyPurposeFlags::kCodeSigning);
-static const BitFlags sEP(KeyPurposeFlags::kEmailProtection);
-static const BitFlags sTS(KeyPurposeFlags::kTimeStamping);
-static const BitFlags sOS(KeyPurposeFlags::kOCSPSigning);
-static const BitFlags sSAandCA(sSA.Raw() | sCA.Raw());
-static const BitFlags sSAandCS(sSA.Raw() | sCS.Raw());
-static const BitFlags sSAandEP(sSA.Raw() | sEP.Raw());
-static const BitFlags sSAandTS(sSA.Raw() | sTS.Raw());
-
-static const BitFlags sNullKUFlag;
-static const BitFlags sDS(KeyUsageFlags::kDigitalSignature);
-static const BitFlags sNR(KeyUsageFlags::kNonRepudiation);
-static const BitFlags sKE(KeyUsageFlags::kKeyEncipherment);
-static const BitFlags sDE(KeyUsageFlags::kDataEncipherment);
-static const BitFlags sKA(KeyUsageFlags::kKeyAgreement);
-static const BitFlags sKC(KeyUsageFlags::kKeyCertSign);
-static const BitFlags sCR(KeyUsageFlags::kCRLSign);
-static const BitFlags sEO(KeyUsageFlags::kEncipherOnly);
-static const BitFlags sDO(KeyUsageFlags::kDecipherOnly);
-static const BitFlags sDSandNR(sDS.Raw() | sNR.Raw());
-static const BitFlags sDSandKE(sDS.Raw() | sKE.Raw());
-static const BitFlags sDSandDE(sDS.Raw() | sDE.Raw());
-static const BitFlags sDSandKA(sDS.Raw() | sKA.Raw());
-static const BitFlags sDSandKC(sDS.Raw() | sKC.Raw());
-static const BitFlags sDSandCR(sDS.Raw() | sCR.Raw());
-static const BitFlags sDSandEO(sDS.Raw() | sEO.Raw());
-static const BitFlags sDSandDO(sDS.Raw() | sDO.Raw());
-static const BitFlags sKCandDS(sKC.Raw() | sDS.Raw());
-static const BitFlags sKCandNR(sKC.Raw() | sNR.Raw());
-static const BitFlags sKCandKE(sKC.Raw() | sKE.Raw());
-static const BitFlags sKCandDE(sKC.Raw() | sDE.Raw());
-static const BitFlags sKCandKA(sKC.Raw() | sKA.Raw());
-static const BitFlags sKCandCR(sKC.Raw() | sCR.Raw());
-static const BitFlags sKCandEO(sKC.Raw() | sEO.Raw());
-static const BitFlags sKCandDO(sKC.Raw() | sDO.Raw());
+static const BitFlags sIgnoreNotBeforeFlag(CertValidateFlags::kIgnoreNotBefore);
+static const BitFlags sIgnoreNotAfterFlag(CertValidateFlags::kIgnoreNotAfter);
+
+static const BitFlags sNullDecodeFlag;
+static const BitFlags sGenTBSHashFlag(CertDecodeFlags::kGenerateTBSHash);
+static const BitFlags sTrustAnchorFlag(CertDecodeFlags::kIsTrustAnchor);
+
+static const BitFlags sNullLoadFlag;
+static const BitFlags sDerFormFlag(TestCertLoadFlags::kDERForm);
+static const BitFlags sSupIsCAFlag(TestCertLoadFlags::kSuppressIsCA);
+static const BitFlags sSupKeyUsageFlag(TestCertLoadFlags::kSuppressKeyUsage);
+static const BitFlags sSupKeyCertSignFlag(TestCertLoadFlags::kSuppressKeyCertSign);
+static const BitFlags sPathLenZeroFlag(TestCertLoadFlags::kSetPathLenConstZero);
+static const BitFlags sAppDefCertTypeFlag(TestCertLoadFlags::kSetAppDefinedCertType);
+
+static const BitFlags sNullKPFlag;
+static const BitFlags sSA(KeyPurposeFlags::kServerAuth);
+static const BitFlags sCA(KeyPurposeFlags::kClientAuth);
+static const BitFlags sCS(KeyPurposeFlags::kCodeSigning);
+static const BitFlags sEP(KeyPurposeFlags::kEmailProtection);
+static const BitFlags sTS(KeyPurposeFlags::kTimeStamping);
+static const BitFlags sOS(KeyPurposeFlags::kOCSPSigning);
+static const BitFlags sSAandCA(sSA, sCA);
+static const BitFlags sSAandCS(sSA, sCS);
+static const BitFlags sSAandEP(sSA, sEP);
+static const BitFlags sSAandTS(sSA, sTS);
+
+static const BitFlags sNullKUFlag;
+static const BitFlags sDS(KeyUsageFlags::kDigitalSignature);
+static const BitFlags sNR(KeyUsageFlags::kNonRepudiation);
+static const BitFlags sKE(KeyUsageFlags::kKeyEncipherment);
+static const BitFlags sDE(KeyUsageFlags::kDataEncipherment);
+static const BitFlags sKA(KeyUsageFlags::kKeyAgreement);
+static const BitFlags sKC(KeyUsageFlags::kKeyCertSign);
+static const BitFlags sCR(KeyUsageFlags::kCRLSign);
+static const BitFlags sEO(KeyUsageFlags::kEncipherOnly);
+static const BitFlags sDO(KeyUsageFlags::kDecipherOnly);
+static const BitFlags sDSandNR(sDS, sNR);
+static const BitFlags sDSandKE(sDS, sKE);
+static const BitFlags sDSandDE(sDS, sDE);
+static const BitFlags sDSandKA(sDS, sKA);
+static const BitFlags sDSandKC(sDS, sKC);
+static const BitFlags sDSandCR(sDS, sCR);
+static const BitFlags sDSandEO(sDS, sEO);
+static const BitFlags sDSandDO(sDS, sDO);
+static const BitFlags sKCandDS(sKC, sDS);
+static const BitFlags sKCandNR(sKC, sNR);
+static const BitFlags sKCandKE(sKC, sKE);
+static const BitFlags sKCandDE(sKC, sDE);
+static const BitFlags sKCandKA(sKC, sKA);
+static const BitFlags sKCandCR(sKC, sCR);
+static const BitFlags sKCandEO(sKC, sEO);
+static const BitFlags sKCandDO(sKC, sDO);
static CHIP_ERROR LoadStandardCerts(ChipCertificateSet & certSet)
{
@@ -207,8 +207,8 @@ static void TestChipCert_CertValidation(nlTestSuite * inSuite, void * inContext)
struct
{
uint8_t Type;
- BitFlags DecodeFlags;
- BitFlags LoadFlags;
+ BitFlags DecodeFlags;
+ BitFlags LoadFlags;
} InputCerts[kMaxCertsPerTestCase];
};
@@ -475,8 +475,8 @@ static void TestChipCert_CertUsage(nlTestSuite * inSuite, void * inContext)
struct UsageTestCase
{
uint8_t mCertIndex;
- BitFlags mRequiredKeyUsages;
- BitFlags mRequiredKeyPurposes;
+ BitFlags mRequiredKeyUsages;
+ BitFlags mRequiredKeyPurposes;
CHIP_ERROR mExpectedResult;
};
diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp
index 024d66371424bc..9cde2a4db75aad 100644
--- a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp
+++ b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2019-2020 Google LLC.
* Copyright (c) 2018 Nest Labs, Inc.
*
@@ -50,15 +50,14 @@ namespace Internal {
template
CHIP_ERROR GenericConfigurationManagerImpl::_Init()
{
- mFlags = 0;
-
// Cache flags indicating whether the device is currently service provisioned, is a member of a fabric,
// is paired to an account, and/or provisioned with operational credentials.
- SetFlag(mFlags, kFlag_IsServiceProvisioned, Impl()->ConfigValueExists(ImplClass::kConfigKey_ServiceConfig));
- SetFlag(mFlags, kFlag_IsMemberOfFabric, Impl()->ConfigValueExists(ImplClass::kConfigKey_FabricId));
- SetFlag(mFlags, kFlag_IsPairedToAccount, Impl()->ConfigValueExists(ImplClass::kConfigKey_PairedAccountId));
- SetFlag(mFlags, kFlag_OperationalDeviceCredentialsProvisioned,
- Impl()->ConfigValueExists(ImplClass::kConfigKey_OperationalDeviceCert));
+ mFlags.ClearAll()
+ .Set(Flags::kIsServiceProvisioned, Impl()->ConfigValueExists(ImplClass::kConfigKey_ServiceConfig))
+ .Set(Flags::kIsMemberOfFabric, Impl()->ConfigValueExists(ImplClass::kConfigKey_FabricId))
+ .Set(Flags::kIsPairedToAccount, Impl()->ConfigValueExists(ImplClass::kConfigKey_PairedAccountId))
+ .Set(Flags::kOperationalDeviceCredentialsProvisioned,
+ Impl()->ConfigValueExists(ImplClass::kConfigKey_OperationalDeviceCert));
#if CHIP_ENABLE_ROTATING_DEVICE_ID
mLifetimePersistedCounter.Init(CHIP_CONFIG_LIFETIIME_PERSISTED_COUNTER_KEY);
@@ -524,7 +523,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ClearOperationalDeviceCr
Impl()->ClearConfigValue(ImplClass::kConfigKey_OperationalDeviceICACerts);
Impl()->ClearConfigValue(ImplClass::kConfigKey_OperationalDevicePrivateKey);
- ClearFlag(mFlags, kFlag_OperationalDeviceCredentialsProvisioned);
+ mFlags.Clear(Flags::kOperationalDeviceCredentialsProvisioned);
return CHIP_NO_ERROR;
}
@@ -532,19 +531,19 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ClearOperationalDeviceCr
template
bool GenericConfigurationManagerImpl::_OperationalDeviceCredentialsProvisioned()
{
- return ::chip::GetFlag(mFlags, kFlag_OperationalDeviceCredentialsProvisioned);
+ return mFlags.Has(Flags::kOperationalDeviceCredentialsProvisioned);
}
template
bool GenericConfigurationManagerImpl::UseManufacturerCredentialsAsOperational()
{
- return ::chip::GetFlag(mFlags, kFlag_UseManufacturerCredentialsAsOperational);
+ return mFlags.Has(Flags::kUseManufacturerCredentialsAsOperational);
}
template
void GenericConfigurationManagerImpl::_UseManufacturerCredentialsAsOperational(bool val)
{
- SetFlag(mFlags, kFlag_UseManufacturerCredentialsAsOperational, val);
+ mFlags.Set(Flags::kUseManufacturerCredentialsAsOperational, val);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING
@@ -627,11 +626,11 @@ CHIP_ERROR GenericConfigurationManagerImpl::_StoreFabricId(uint64_t f
{
err = Impl()->WriteConfigValue(ImplClass::kConfigKey_FabricId, fabricId);
SuccessOrExit(err);
- SetFlag(mFlags, kFlag_IsMemberOfFabric);
+ mFlags.Set(Flags::kIsMemberOfFabric);
}
else
{
- ClearFlag(mFlags, kFlag_IsMemberOfFabric);
+ mFlags.Clear(Flags::kIsMemberOfFabric);
err = Impl()->ClearConfigValue(ImplClass::kConfigKey_FabricId);
SuccessOrExit(err);
}
@@ -689,7 +688,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_StorePairedAccountId(con
err = Impl()->WriteConfigValueStr(ImplClass::kConfigKey_PairedAccountId, accountId, accountIdLen);
SuccessOrExit(err);
- SetFlag(mFlags, kFlag_IsPairedToAccount, (accountId != nullptr && accountIdLen != 0));
+ mFlags.Set(Flags::kIsPairedToAccount, (accountId != nullptr && accountIdLen != 0));
exit:
return err;
@@ -712,8 +711,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::_StoreServiceProvisioning
err = _StorePairedAccountId(accountId, accountIdLen);
SuccessOrExit(err);
- SetFlag(mFlags, kFlag_IsServiceProvisioned);
- SetFlag(mFlags, kFlag_IsPairedToAccount, (accountId != nullptr && accountIdLen != 0));
+ mFlags.Set(Flags::kIsServiceProvisioned);
+ mFlags.Set(Flags::kIsPairedToAccount, (accountId != nullptr && accountIdLen != 0));
exit:
if (err != CHIP_NO_ERROR)
@@ -721,8 +720,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::_StoreServiceProvisioning
Impl()->ClearConfigValue(ImplClass::kConfigKey_ServiceId);
Impl()->ClearConfigValue(ImplClass::kConfigKey_ServiceConfig);
Impl()->ClearConfigValue(ImplClass::kConfigKey_PairedAccountId);
- ClearFlag(mFlags, kFlag_IsServiceProvisioned);
- ClearFlag(mFlags, kFlag_IsPairedToAccount);
+ mFlags.Clear(Flags::kIsServiceProvisioned);
+ mFlags.Clear(Flags::kIsPairedToAccount);
}
return err;
}
@@ -757,8 +756,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::_ClearServiceProvisioning
PlatformMgr().PostEvent(&event);
}
- ClearFlag(mFlags, kFlag_IsServiceProvisioned);
- ClearFlag(mFlags, kFlag_IsPairedToAccount);
+ mFlags.Clear(Flags::kIsServiceProvisioned);
+ mFlags.Clear(Flags::kIsPairedToAccount);
return CHIP_NO_ERROR;
}
@@ -851,19 +850,19 @@ GenericConfigurationManagerImpl::_GetBLEDeviceIdentificationInfo(Ble:
template
bool GenericConfigurationManagerImpl::_IsServiceProvisioned()
{
- return ::chip::GetFlag(mFlags, kFlag_IsServiceProvisioned);
+ return mFlags.Has(Flags::kIsServiceProvisioned);
}
template
bool GenericConfigurationManagerImpl::_IsMemberOfFabric()
{
- return ::chip::GetFlag(mFlags, kFlag_IsMemberOfFabric);
+ return mFlags.Has(Flags::kIsMemberOfFabric);
}
template
bool GenericConfigurationManagerImpl::_IsPairedToAccount()
{
- return ::chip::GetFlag(mFlags, kFlag_IsPairedToAccount);
+ return mFlags.Has(Flags::kIsPairedToAccount);
}
template
diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h
index 5632a933a10b32..15fb258d753c5e 100644
--- a/src/include/platform/internal/GenericConfigurationManagerImpl.h
+++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2020 Project CHIP Authors
+ * Copyright (c) 2020-2021 Project CHIP Authors
* Copyright (c) 2019-2020 Google LLC.
* Copyright (c) 2018 Nest Labs, Inc.
*
@@ -25,6 +25,8 @@
#pragma once
+#include
+
#if CHIP_ENABLE_ROTATING_DEVICE_ID
#include
#endif
@@ -125,16 +127,16 @@ class GenericConfigurationManagerImpl
void _LogDeviceConfig();
protected:
- enum
+ enum class Flags : uint8_t
{
- kFlag_IsServiceProvisioned = 0x01,
- kFlag_IsMemberOfFabric = 0x02,
- kFlag_IsPairedToAccount = 0x04,
- kFlag_OperationalDeviceCredentialsProvisioned = 0x08,
- kFlag_UseManufacturerCredentialsAsOperational = 0x10,
+ kIsServiceProvisioned = 0x01,
+ kIsMemberOfFabric = 0x02,
+ kIsPairedToAccount = 0x04,
+ kOperationalDeviceCredentialsProvisioned = 0x08,
+ kUseManufacturerCredentialsAsOperational = 0x10,
};
- uint8_t mFlags;
+ BitFlags